feat: Urutau 1.0.0, lightweight threat intelligence and web analytics
Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 1m29s
CI / Tests (Linux, race detector) (push) Failing after 1m48s
CI / Dependency audit (push) Successful in 21s
Release / ci (push) Failing after 1m50s
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Skipped
Release / Gitea release (push) Skipped
Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 1m29s
CI / Tests (Linux, race detector) (push) Failing after 1m48s
CI / Dependency audit (push) Successful in 21s
Release / ci (push) Failing after 1m50s
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Skipped
Release / Gitea release (push) Skipped
Always-on Go service (stdlib only) that follows the Traefik JSON access log, the sshd log and the fail2ban log of a host, classifies attacks, scores sources, keeps bounded aggregates with snapshots, and serves an embedded dashboard with live updates, offline geolocation (DB-IP Lite), privacy-friendly traffic analytics, an exportable blocklist and token-authenticated federation between instances. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b4a2c2c9ec
99 files changed
+15403
No files matched your search
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env node
|
||||
// Verifies the dashboard translations: both dictionaries (en, pt-BR) must have
|
||||
// exactly the same keys, every key used by the HTML and the JS must exist, and
|
||||
// the HTML must not carry visible text outside a data-i18n element.
|
||||
//
|
||||
// Usage: node scripts/check-ui-i18n.mjs
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const root = join(fileURLToPath(new URL('.', import.meta.url)), '..');
|
||||
const web = join(root, 'internal/server/web');
|
||||
const read = (f) => readFileSync(join(web, f), 'utf8');
|
||||
|
||||
const sandbox = { window: {} };
|
||||
vm.runInNewContext(read('i18n.js'), sandbox);
|
||||
const dict = sandbox.window.URUTAU_I18N;
|
||||
const langs = Object.keys(dict);
|
||||
const errors = [];
|
||||
|
||||
// duplicate keys silently collapse in an object literal: look at the source
|
||||
for (const lang of langs) {
|
||||
const block = read('i18n.js').split(new RegExp(`\\n\\s*['"]?${lang}['"]?:\\s*\\{`))[1] ?? '';
|
||||
const seen = new Set();
|
||||
for (const m of block.split(/\n\s*\},?\s*\n/)[0].matchAll(/^\s*'([^']+)':/gm)) {
|
||||
if (seen.has(m[1])) errors.push(`duplicate key in ${lang}: ${m[1]}`);
|
||||
seen.add(m[1]);
|
||||
}
|
||||
}
|
||||
|
||||
const all = new Set(langs.flatMap((l) => Object.keys(dict[l])));
|
||||
for (const lang of langs) {
|
||||
for (const k of all) if (!(k in dict[lang])) errors.push(`missing in ${lang}: ${k}`);
|
||||
for (const [k, v] of Object.entries(dict[lang])) if (typeof v !== 'string' || !v.trim()) errors.push(`empty in ${lang}: ${k}`);
|
||||
}
|
||||
// placeholders must match across languages
|
||||
for (const k of all) {
|
||||
const ph = langs.map((l) => (dict[l][k]?.match(/\{n\}/g) ?? []).length);
|
||||
if (new Set(ph).size > 1) errors.push(`placeholder mismatch: ${k}`);
|
||||
}
|
||||
|
||||
// keys used
|
||||
const used = new Set();
|
||||
for (const f of ['index.html', 'login.html']) {
|
||||
for (const m of read(f).matchAll(/data-i18n(?:-ph|-aria|-title)?="([^"]+)"/g)) used.add(m[1]);
|
||||
}
|
||||
for (const f of ['app.js', 'login.js']) {
|
||||
for (const m of read(f).matchAll(/\bt\(\s*'([^']+)'/g)) used.add(m[1]);
|
||||
for (const m of read(f).matchAll(/\[\s*'((?:host|kpi)\.[a-z]+)'\s*,/g)) used.add(m[1]);
|
||||
}
|
||||
// keys built at runtime
|
||||
const families = {
|
||||
'cat.': ['ok', 'notfound', 'scanner', 'exploit', 'bruteforce', 'ssh-fail', 'ssh-probe', 'ssh-ok', 'ban'],
|
||||
'level.': ['all', 'hostile', 'suspicious', 'low'],
|
||||
'device.': ['desktop', 'mobile', 'tablet', 'bot', 'tool', 'unknown'],
|
||||
'state.': ['following', 'waiting', 'backfill', 'error', 'disabled'],
|
||||
};
|
||||
for (const [p, names] of Object.entries(families)) for (const n of names) used.add(p + n);
|
||||
for (const k of used) if (!k.endsWith('.') && !all.has(k)) errors.push(`used but not defined: ${k}`);
|
||||
for (const k of all) if (!used.has(k) && !k.startsWith('ago.') && !['live.on', 'live.off', 'feed.unban', 'yes', 'never', 'blocklist.copied', 'blocklist.failed', 'pager.count'].includes(k)) {
|
||||
errors.push(`defined but unused: ${k}`);
|
||||
}
|
||||
|
||||
// no visible text outside data-i18n in the HTML
|
||||
for (const f of ['index.html', 'login.html']) {
|
||||
const html = read(f).replace(/<script[\s\S]*?<\/script>/g, '').replace(/<!--[\s\S]*?-->/g, '').replace(/<title>[\s\S]*?<\/title>/g, '');
|
||||
for (const m of html.matchAll(/<([a-z0-9]+)([^>]*)>([^<]+)</gi)) {
|
||||
const text = m[3].replace(/&[a-z#0-9]+;/g, '').trim();
|
||||
if (!/[A-Za-zÀ-ÿ]{2,}/.test(text)) continue;
|
||||
if (/data-i18n="/.test(m[2])) continue;
|
||||
if (['h1', 'button'].includes(m[1]) && /^(Urutau|EN|PT)$/.test(text)) continue;
|
||||
if (m[1] === 'span' && /id="(ver|live-text)"/.test(m[2])) continue;
|
||||
errors.push(`${f}: hard-coded text <${m[1]}>${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error('UI i18n problems:\n ' + errors.join('\n '));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`ui i18n ok: ${all.size} keys in ${langs.join(', ')}`);
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
# Local verification: runs the same checks as CI before pushing. Anything the
|
||||
# machine lacks (go, node, docker, govulncheck) is skipped with a warning.
|
||||
#
|
||||
# scripts/check.sh fast: gofmt, go vet, i18n, scripts, workflows, compose
|
||||
# scripts/check.sh --full also runs go test -race and govulncheck
|
||||
#
|
||||
# CI takes minutes per run; almost everything that breaks it is caught here
|
||||
# in seconds.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
full=0
|
||||
[ "${1:-}" = "--full" ] && full=1
|
||||
failures=()
|
||||
step() { # step "name" command...
|
||||
local name="$1"; shift
|
||||
printf '\n\033[1m== %s\033[0m\n' "$name"
|
||||
if "$@"; then printf '\033[32mok\033[0m %s\n' "$name"; else printf '\033[31mFAILED\033[0m %s\n' "$name"; failures+=("$name"); fi
|
||||
}
|
||||
skip() { printf '\n\033[33mskipped\033[0m %s (%s)\n' "$1" "$2"; }
|
||||
|
||||
if command -v go >/dev/null; then
|
||||
step "formatting (gofmt)" bash -c 'out=$(gofmt -l .); [ -z "$out" ] || { echo "$out"; exit 1; }'
|
||||
step "go vet" go vet ./...
|
||||
else
|
||||
skip "gofmt and go vet" "go not installed"
|
||||
fi
|
||||
|
||||
if command -v node >/dev/null; then
|
||||
step "UI translation coverage" node scripts/check-ui-i18n.mjs
|
||||
else
|
||||
skip "UI translation coverage" "node not installed"
|
||||
fi
|
||||
|
||||
step "bash script syntax" bash -c 'for f in scripts/*.sh .githooks/*; do bash -n "$f" || exit 1; done'
|
||||
|
||||
if python3 -c 'import yaml' 2>/dev/null; then
|
||||
step "workflows and templates (valid YAML)" python3 -c "
|
||||
import glob, yaml
|
||||
for f in glob.glob('.gitea/**/*.yml', recursive=True):
|
||||
yaml.safe_load(open(f))
|
||||
"
|
||||
else
|
||||
skip "workflows and templates (valid YAML)" "PyYAML missing: pip install pyyaml"
|
||||
fi
|
||||
|
||||
step "brand assets" test -s logo.png
|
||||
|
||||
if command -v docker >/dev/null && docker compose version >/dev/null 2>&1; then
|
||||
step "docker compose config" docker compose config --quiet
|
||||
else
|
||||
skip "docker compose config" "docker compose not available"
|
||||
fi
|
||||
|
||||
if [ "$full" = 1 ]; then
|
||||
if command -v go >/dev/null; then
|
||||
step "tests (go test -race)" go test -race ./...
|
||||
if command -v govulncheck >/dev/null; then
|
||||
step "dependency audit (govulncheck)" govulncheck ./...
|
||||
else
|
||||
skip "govulncheck" "install: go install golang.org/x/vuln/cmd/govulncheck@latest"
|
||||
fi
|
||||
else
|
||||
skip "tests and govulncheck" "go not installed"
|
||||
fi
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
if [ ${#failures[@]} -eq 0 ]; then
|
||||
printf '\033[32mall checks passed\033[0m: ready to push.\n'
|
||||
else
|
||||
printf '\033[31mfailed:\033[0m %s\n' "${failures[*]}"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
// Regenerates internal/server/web/world.js (simplified world map, one SVG path
|
||||
// per country, plus country centroids) from the public-domain Natural Earth data
|
||||
// shipped in the npm package "world-atlas" and a REST Countries style JSON
|
||||
// (cca2, ccn3, latlng). Only needed when the map should change.
|
||||
//
|
||||
// node scripts/gen-world.mjs countries-110m.json countries.json > internal/server/web/world.js
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const [topoFile, cFile] = process.argv.slice(2);
|
||||
const topo = JSON.parse(readFileSync(topoFile, 'utf8'));
|
||||
const countries = JSON.parse(readFileSync(cFile, 'utf8'));
|
||||
const byNum = new Map(countries.map((c) => [String(c.ccn3).padStart(3, '0'), c]));
|
||||
|
||||
const W = 2000, LAT_TOP = 84, LAT_BOTTOM = -58;
|
||||
const H = Math.round((W * (LAT_TOP - LAT_BOTTOM)) / 360);
|
||||
const px = (lon) => ((lon + 180) / 360) * W;
|
||||
const py = (lat) => ((LAT_TOP - Math.max(LAT_BOTTOM, Math.min(LAT_TOP, lat))) / (LAT_TOP - LAT_BOTTOM)) * H;
|
||||
|
||||
const { scale, translate } = topo.transform;
|
||||
const arcs = topo.arcs.map((arc) => {
|
||||
let x = 0, y = 0;
|
||||
return arc.map(([dx, dy]) => { x += dx; y += dy; return [x * scale[0] + translate[0], y * scale[1] + translate[1]]; });
|
||||
});
|
||||
const arcPts = (i) => (i >= 0 ? arcs[i] : arcs[~i].slice().reverse());
|
||||
const ring = (idx) => {
|
||||
const pts = [];
|
||||
for (const i of idx) { const a = arcPts(i); pts.push(...(pts.length ? a.slice(1) : a)); }
|
||||
return pts;
|
||||
};
|
||||
|
||||
const paths = {}, cent = {};
|
||||
for (const g of topo.objects.countries.geometries) {
|
||||
const c = byNum.get(String(g.id).padStart(3, '0'));
|
||||
if (!c || c.cca2 === 'AQ') continue;
|
||||
const polys = g.type === 'Polygon' ? [g.arcs] : g.type === 'MultiPolygon' ? g.arcs : [];
|
||||
let d = '';
|
||||
for (const poly of polys) {
|
||||
for (const r of poly) {
|
||||
const pts = ring(r).map(([lo, la]) => [Math.round(px(lo)), Math.round(py(la))]);
|
||||
const out = [];
|
||||
for (const p of pts) { const l = out[out.length - 1]; if (!l || l[0] !== p[0] || l[1] !== p[1]) out.push(p); }
|
||||
if (out.length < 4) continue;
|
||||
let s = `M${out[0][0]} ${out[0][1]}`, px0 = out[0][0], py0 = out[0][1];
|
||||
for (const [x, y] of out.slice(1)) {
|
||||
// a ring crossing the antimeridian jumps across the map: start a new subpath instead of drawing a line over it
|
||||
s += Math.abs(x - px0) > W / 2 ? `M${x} ${y}` : `l${x - px0} ${y - py0}`;
|
||||
px0 = x; py0 = y;
|
||||
}
|
||||
d += s + 'z';
|
||||
}
|
||||
}
|
||||
if (d) paths[c.cca2] = d;
|
||||
}
|
||||
for (const c of countries) if (c.latlng?.length === 2) cent[c.cca2] = [Math.round(px(c.latlng[1])), Math.round(py(c.latlng[0]))];
|
||||
process.stdout.write(`/* Generated by scripts/gen-world.mjs from Natural Earth (public domain). */\nwindow.URUTAU_WORLD = ${JSON.stringify({ w: W, h: H, paths, centroids: cent })};\n`);
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Enables the repository Git hooks (.githooks/pre-push and .githooks/commit-msg).
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
git config core.hooksPath .githooks
|
||||
echo "hooks enabled: git commit validates Conventional Commits in English and git push runs scripts/check.sh (disable with: git config --unset core.hooksPath)"
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Prints release notes for a given tag: extracts the matching CHANGELOG.md
|
||||
# section, or falls back to the commit log since the previous tag.
|
||||
#
|
||||
# scripts/release-notes.sh v1.2.3
|
||||
set -euo pipefail
|
||||
|
||||
tag=${1:?usage: release-notes.sh <tag>}
|
||||
version=${tag#v}
|
||||
|
||||
section=""
|
||||
if [ -f CHANGELOG.md ]; then
|
||||
section=$(awk -v head="## [$version]" '
|
||||
index($0, head) == 1 { found = 1; next }
|
||||
found && /^## \[/ { exit }
|
||||
found && /^\[[^]]+\]: / { next }
|
||||
found { print }
|
||||
' CHANGELOG.md)
|
||||
fi
|
||||
|
||||
if [ -n "$(printf '%s' "$section" | tr -d '[:space:]')" ]; then
|
||||
printf '%s\n' "$section"
|
||||
else
|
||||
previous=$(git describe --tags --abbrev=0 "$tag^" 2>/dev/null || true)
|
||||
echo "## Changes${previous:+ since $previous}"
|
||||
echo
|
||||
git log --no-merges --format='- %s (%h)' "${previous:+$previous..}$tag"
|
||||
fi
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
# Smoke-tests an Urutau image: the HEALTHCHECK command works, the API is closed
|
||||
# without a token and open with it, the peer token only opens the export, the
|
||||
# dashboard is served, urutau doctor reports a version, the daemon is not root
|
||||
# and SIGTERM stops it cleanly with exit 0.
|
||||
# The image has no curl: HTTP checks use the BusyBox wget that Alpine ships.
|
||||
# Everything runs through `docker exec`, so no port has to be reachable from the
|
||||
# CI job container. The container is always removed.
|
||||
#
|
||||
# scripts/smoke-image.sh <image-ref>
|
||||
set -euo pipefail
|
||||
|
||||
image=${1:?usage: smoke-image.sh <image-ref>}
|
||||
name="urutau-smoke-$$-$RANDOM"
|
||||
token=$(head -c 40 /dev/urandom | base64 | tr -d '=+/\n')
|
||||
peer=$(head -c 40 /dev/urandom | base64 | tr -d '=+/\n')
|
||||
trap 'docker rm -f "$name" >/dev/null 2>&1 || true' EXIT
|
||||
fail() { echo "smoke: $*" >&2; docker logs "$name" >&2 2>&1 || true; exit 1; }
|
||||
base=http://127.0.0.1:8790
|
||||
# status <url> [header]: HTTP status code of a GET (wget -S prints the response headers)
|
||||
status() {
|
||||
local url=$1; shift
|
||||
docker exec "$name" wget -S -q -O /dev/null "$@" "$url" 2>&1 | awk '/^ *HTTP\//{c=$2} END{print c}'
|
||||
}
|
||||
get() { local url=$1; shift; docker exec "$name" wget -q -O - "$@" "$url"; }
|
||||
|
||||
# No log files are mounted: the sources wait for them. docker create + start
|
||||
# instead of a bind mount, which the daemon may not see from a CI job.
|
||||
docker create --name "$name" -e URUTAU_TOKEN="$token" -e URUTAU_PEER_TOKEN="$peer" -e URUTAU_GEO_UPDATE=0 "$image" >/dev/null
|
||||
docker start "$name" >/dev/null
|
||||
for _ in $(seq 1 30); do
|
||||
docker exec "$name" urutau healthcheck >/dev/null 2>&1 && break
|
||||
sleep 1
|
||||
done
|
||||
docker exec "$name" urutau healthcheck || fail "urutau healthcheck failed"
|
||||
out=$(get "$base/api/health") || fail "/api/health did not answer"
|
||||
grep -q '"status":"ok"' <<<"$out" || fail "/api/health is not ok"
|
||||
grep -q '"version"' <<<"$out" && fail "/api/health must not expose the version"
|
||||
[ "$(status "$base/api/v1/summary")" = 401 ] || fail "/api/v1/summary without a token must answer 401"
|
||||
[ "$(status "$base/api/v1/summary" --header "Authorization: Bearer $peer")" = 403 ] || fail "the peer token on /api/v1/summary must answer 403"
|
||||
out=$(get "$base/api/v1/summary" --header "Authorization: Bearer $token") || fail "authenticated summary failed"
|
||||
grep -q '"totals"' <<<"$out" || fail "summary has no totals"
|
||||
out=$(get "$base/api/v1/peer/export?range=1h" --header "Authorization: Bearer $peer") || fail "peer export failed"
|
||||
grep -q '"summary"' <<<"$out" || fail "peer export has no summary"
|
||||
[ "$(status "$base/api/v1/peer/export" --header "Authorization: Bearer $token")" = 401 ] || fail "the user token must not open the peer export"
|
||||
out=$(get "$base/login") || fail "login page did not answer"
|
||||
grep -qi '<!doctype html' <<<"$out" || fail "login page is not served"
|
||||
out=$(get "$base/" --header "Authorization: Bearer $token") || fail "dashboard did not answer"
|
||||
grep -qi '<!doctype html' <<<"$out" || fail "dashboard is not served"
|
||||
out=$(docker exec "$name" urutau doctor --json) || { echo "$out" >&2; fail "urutau doctor --json failed"; }
|
||||
grep -q '"version"' <<<"$out" || fail "urutau doctor --json has no version"
|
||||
[ "$(docker inspect -f '{{if .Config.Healthcheck}}yes{{end}}' "$name")" = yes ] || fail "image has no HEALTHCHECK"
|
||||
[ "$(docker exec "$name" id -u)" != 0 ] || fail "daemon runs as root"
|
||||
docker exec "$name" sh -c 'command -v curl' >/dev/null 2>&1 && fail "the image must not ship curl"
|
||||
docker stop -t 10 "$name" >/dev/null
|
||||
code=$(docker inspect -f '{{.State.ExitCode}}' "$name")
|
||||
[ "$code" = 0 ] || fail "exit code $code after SIGTERM (expected 0: SIGTERM must stop serve)"
|
||||
echo "smoke: $image ok"
|
||||
Reference in new issue
Block a user