Dawnline 0.20.0
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions

- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode.
- **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V).
- **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request.
- **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds.
- **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person.
- **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router.
- **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch.
- **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away.
- **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once.
- **Undo.** An action done from a card or a request is undone from its toast.
- **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own.
- **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name.
- **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking.
- **Check access and Health know the networks behind routers.**
- **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st.
- Extra data lasts until that person's month ends; «Reset usage» starts the month anew.
- A limit is for a month or for the whole term; the admin and the portal show when it resets.
- Charts that said «this month» show the last 30 days.
- After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st.
- **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped.
- **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone.
- **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence.
- **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
This commit is contained in:
Aemeath committed 2026-11-13 09:43:50 +03:00
1 parent f8130e39a8
commit ac90575b0b
788 files changed
+139244 -41720

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# The Go backend's checks, in containers (needs docker):
# scripts/backend-container.sh
# gofmt, go vet and the unit tests with the Go toolchain image, then the tests
# that need a real ubusd in the OpenWrt rootfs containers CI uses.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
GO_IMAGE="${GO_IMAGE:-golang:1.27-alpine}"
ROOTFS="${ROOTFS:-openwrt/rootfs:x86-64-24.10.6 openwrt/rootfs:x86-64-25.12.3}"
OUT="$ROOT/dist/backend-test"
mkdir -p "$OUT"
# The whole repository is mounted: the e2e tests read the package's files.
docker run --rm -v "$ROOT":/repo:ro -v "$OUT":/out -w /repo/backend \
-v dawnline-gocache:/root/.cache/go-build -v dawnline-gomod:/go/pkg/mod \
-e CGO_ENABLED=0 "$GO_IMAGE" sh -ec '
unformatted="$(gofmt -l .)"
[ -z "$unformatted" ] || { echo "gofmt: $unformatted" >&2; exit 1; }
go vet ./...
go vet -tags ubusd ./...
go test ./...
go vet -tags e2e ./...
GOARCH=amd64 go test -c -tags ubusd -o /out/ubus.test ./ubus
GOARCH=amd64 go test -c -tags e2e -o /out/e2e.test ./daemon
'
for image in $ROOTFS; do
echo "== ubusd tests on $image"
docker run --rm --platform linux/amd64 -v "$OUT":/out:ro \
-v "$ROOT/package/luci-app-dawnline/root/usr/share/rpcd/acl.d/luci-app-dawnline.json":/usr/share/rpcd/acl.d/luci-app-dawnline.json:ro \
"$image" sh -ec '
mkdir -p /var/run/ubus
ubusd &
# BusyBox sleep takes whole seconds there.
i=0
while [ ! -S /var/run/ubus/ubus.sock ] && [ "$i" -lt 10 ]; do sleep 1; i=$((i + 1)); done
/out/ubus.test -test.run RealBus -test.v
# The whole path of a page: rpcd with the ACL of the package, and /ubus of uhttpd.
rpcd &
uhttpd -f -p 127.0.0.1:8099 -h /www -u /ubus -t 60 -T 30 &
i=0
while ! ubus list session >/dev/null 2>&1 && [ "$i" -lt 10 ]; do sleep 1; i=$((i + 1)); done
/out/e2e.test -test.run ThroughUhttpd -test.v
'
done
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Build the Go backend (backend/, the program dawnlined) for one router architecture:
# scripts/build-backend.sh <arch> arch: what `uname -m` says on the router (aarch64, armv7l, mips,
# mipsel, x86_64), or a Go name (arm64, arm, mips, mipsle, amd64)
# Output: dist/backend/dawnlined-<goarch>, and its path as the last line. Needs docker (the Go toolchain
# image); nothing of Go is installed here. A static binary: it runs on any OpenWrt of that architecture.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
GO_IMAGE="${GO_IMAGE:-golang:1.27-alpine}"
VERSION="$(cat "$ROOT/package/luci-app-dawnline/root/usr/share/dawnline/version")"
case "${1:-}" in
aarch64 | arm64) GOARCH=arm64 ;;
armv7l | armv7 | arm) GOARCH=arm ;;
mips) GOARCH=mips ;;
mipsel | mipsle) GOARCH=mipsle ;;
x86_64 | amd64) GOARCH=amd64 ;;
*) echo "usage: $0 <aarch64|armv7l|mips|mipsel|x86_64>" >&2; exit 2 ;;
esac
OUT="$ROOT/dist/backend"
mkdir -p "$OUT"
# Routers' MIPS and ARMv7 have no FPU to count on: soft float, and ARMv7's own instructions.
docker run --rm -v "$ROOT/backend":/src:ro -v "$OUT":/out -w /src \
-v dawnline-gocache:/root/.cache/go-build -v dawnline-gomod:/go/pkg/mod \
-e CGO_ENABLED=0 -e GOOS=linux -e "GOARCH=$GOARCH" -e GOMIPS=softfloat -e GOARM=7 "$GO_IMAGE" \
go build -trimpath -ldflags "-s -w -X github.com/tickcount/luci-app-dawnline/backend.Version=$VERSION" \
-o "/out/dawnlined-$GOARCH" ./cmd/dawnlined
echo "$OUT/dawnlined-$GOARCH"
+2 -2
View File
@@ -14,11 +14,11 @@ IPK_SDK="${IPK_SDK:-itdoginfo/openwrt-sdk-ipk:24.10.6}"
APK_SDK="${APK_SDK:-itdoginfo/openwrt-sdk-apk:25.12.3}"
# One version everywhere: the Makefile, the ucode library and the web package.
grep -q "^export const VERSION = '$VERSION';" "$APP/root/usr/share/ucode/dawnline/util.uc" || { echo "util.uc VERSION != $VERSION" >&2; exit 1; }
[ "$(cat "$APP/root/usr/share/dawnline/version")" = "$VERSION" ] || { echo "usr/share/dawnline/version != $VERSION" >&2; exit 1; }
grep -q "\"version\": \"$VERSION\"" "$ROOT/web/package.json" || { echo "web/package.json version != $VERSION" >&2; exit 1; }
# The web bundles are not committed: web/ builds them (npm run build).
for f in htdocs/luci-static/resources/dawnline/app.js root/usr/share/dawnline/portal/assets/portal.js root/usr/share/dawnline/portal/assets/portal.css; do
for f in htdocs/luci-static/resources/dawnline/app.js htdocs/luci-static/resources/dawnline/style.js htdocs/luci-static/resources/dawnline/map.js htdocs/luci-static/resources/dawnline/qr.js root/usr/share/dawnline/portal/assets/portal.js root/usr/share/dawnline/portal/assets/portal.css; do
[ -f "$APP/$f" ] || { echo "$APP/$f is missing: run 'npm run build' in web/" >&2; exit 1; }
done
+12 -5
View File
@@ -9,7 +9,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
APP="$ROOT/package/luci-app-dawnline"
VERSION="$(sed -n "s/^export const VERSION = '\(.*\)';/\1/p" "$APP/root/usr/share/ucode/dawnline/util.uc")"
VERSION="$(cat "$APP/root/usr/share/dawnline/version")"
OUT="$ROOT/dist"
STAGE="$(mktemp -d)"
trap 'rm -rf "$STAGE"' EXIT
@@ -19,13 +19,21 @@ grep -q "\"version\": \"$VERSION\"" "$ROOT/web/package.json" || { echo "web/pack
[ "${SKIP_WEB:-0}" = 1 ] || (cd "$ROOT/web" && npm run --silent ci)
# With SKIP_WEB=1 the bundles come from an earlier build (they are not committed).
for f in htdocs/luci-static/resources/dawnline/app.js root/usr/share/dawnline/portal/assets/portal.js root/usr/share/dawnline/portal/assets/portal.css; do
for f in htdocs/luci-static/resources/dawnline/app.js htdocs/luci-static/resources/dawnline/style.js htdocs/luci-static/resources/dawnline/map.js htdocs/luci-static/resources/dawnline/qr.js root/usr/share/dawnline/portal/assets/portal.js root/usr/share/dawnline/portal/assets/portal.css; do
[ -f "$APP/$f" ] || { echo "$APP/$f is missing: run 'npm run build' in web/" >&2; exit 1; }
done
mkdir -p "$STAGE/www" "$OUT"
cp -R "$APP/root/." "$STAGE/"
cp -R "$APP/htdocs/." "$STAGE/www/"
# The Go backend, for the one router this tarball goes to (BACKEND_ARCH: its `uname -m`; deploy.sh asks it).
# Without it the tarball has none and the pages ask the router themselves, as a release package does
# until the backend is built for every architecture (docs/backend.md).
if [ -n "${BACKEND_ARCH:-}" ]; then
BIN="$("$ROOT/scripts/build-backend.sh" "$BACKEND_ARCH" | tail -n1)"
cp "$BIN" "$STAGE/usr/libexec/dawnline/dawnlined"
chmod 755 "$STAGE/usr/libexec/dawnline/dawnlined"
fi
for po in "$APP"/po/*/dawnline.po; do
l="$(basename "$(dirname "$po")")"
[ "$l" = templates ] && continue
@@ -35,9 +43,8 @@ for po in "$APP"/po/*/dawnline.po; do
case "$l" in ru) name='Русский (Russian)' ;; *) name="$l" ;; esac
printf "uci set luci.languages.%s='%s'; uci commit luci\n" "$l" "$name" > "$STAGE/etc/uci-defaults/luci-i18n-dawnline-$l"
done
chmod 755 "$STAGE/usr/bin/dawnline" "$STAGE/usr/libexec/dawnline/agent" "$STAGE/usr/libexec/dawnline/updater" "$STAGE/usr/libexec/dawnline/resolver" "$STAGE/usr/libexec/dawnline/postupdate" \
"$STAGE/etc/init.d/dawnline" "$STAGE/etc/uci-defaults/90_dawnline" "$STAGE/etc/hotplug.d/iface/95-dawnline" \
"$STAGE/usr/share/dawnline/portal/www/cgi-bin/portal" "$STAGE/usr/share/dawnline/portal/cgi.uc"
chmod 755 "$STAGE/usr/bin/dawnline" "$STAGE/usr/libexec/dawnline/updater" "$STAGE/usr/libexec/dawnline/fetch-backend" "$STAGE/usr/libexec/dawnline/resolver" "$STAGE/usr/libexec/dawnline/postupdate" \
"$STAGE/etc/init.d/dawnline" "$STAGE/etc/uci-defaults/90_dawnline" "$STAGE/etc/hotplug.d/iface/95-dawnline"
find "$STAGE" -name '.DS_Store' -delete
TAR="$OUT/luci-app-dawnline-$VERSION.tar.gz"
+154 -248
View File
@@ -1,294 +1,200 @@
#!/usr/bin/env node
// Capture the raw README screenshots of the admin pages from a live router into
// docs/screenshots/raw/<name>.png (2x PNG); scripts/frame-screenshots.py then
// frames them for the README. The portal's come from its demo instead
// (scripts/capture-portal.mjs): no one's real page, and adding a device there adds none.
// Capture the raw README screenshots of the admin into docs/screenshots/raw/ (2x PNG): People (people.png), a
// person's page (person.png), Places (places.png), a server's core settings (core.png), each cut to the content
// column, and a device's dialog alone on a transparent page (device.png). The Russian ones take a -ru suffix.
// scripts/frame-screenshots.py then frames them for the README.
//
// Drives a headless Chromium (BROWSER=/path/to/chrome, default: Brave or Chrome
// on macOS) over the DevTools protocol (scripts/cdp.mjs). Signs in to LuCI with
// the password from LUCI_PASSWORD or asked on the terminal; the session lives
// only in a throwaway profile (LUCI_USER picks another user than root). Nothing on the router is changed.
// No router is involved, and nothing real can be in a picture: the admin is its demo build (web/dist/admin-demo,
// `npm run build:demo`, built first unless --no-build), the real pages over a router that lives in the page with a
// made-up cast (web/src/admin/demo: eight people, fifteen devices, one fixed day). It is opened at LuCI's own
// addresses on https://router.example and every file is answered over the DevTools protocol (scripts/cdp.mjs).
//
// scripts/capture-screenshots.mjs [--router https://router.lan] [--person id]
// [--mask real=shown ...] [--name real=shown ...]
// [--only overview,people] [--demo] [--lang ru]
// The Outline theme around the pages is not this repository's: its built files (main.css, icons, fonts) are read
// from --theme, by default the luci-theme-outline checkout beside this one (run `pnpm build` in its .dev/ first).
// The theme is shown with its navbar on top. The Places map draws its tiles from the network, as it does on a
// router, so that one shot needs the internet.
//
// --lang asks LuCI for the pages in that language (its catalog, po/<lang>/dawnline.po;
// the router's LuCI language left on auto) and names the captures <name>-<lang>.png
// for that README (README_ru.md); English (the default) keeps <name>.png.
// --mask replaces text on every page before the capture (a domain, a name);
// --name does the same for a person's name in any case, and for their initials.
// Public IPv4 addresses are always swapped for documentation ones (203.0.113.x).
// --demo shows a made-up cast instead of the router's people (scripts/screenshot-demo.mjs):
// the router's answers are rewritten in the headless browser on their way to the page.
// scripts/capture-screenshots.mjs [--lang en,ru] [--only people,core] [--theme <luci-static/outline>] [--no-build]
import { execFileSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, extname, join, resolve, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createInterface } from 'node:readline';
import { die, launch, sleep } from './cdp.mjs';
import { demoRpc } from './screenshot-demo.mjs';
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const WEB = join(ROOT, 'web');
const DEMO = join(WEB, 'dist', 'admin-demo');
const RAW = join(ROOT, 'docs', 'screenshots', 'raw');
const SCALE = 2;
/** The window: wide enough for the theme's content column, and tall, since Outline scrolls #maincontent, not the page. */
const WIDTH = 1400;
const HEIGHT = 2600;
/** Either side of the content column in a page's capture, and under the last thing it shows. */
const SIDE = 48;
const FOOT = 40;
/** Around the dialog in its capture: left, top, right, bottom (frame-screenshots.py FLOW_MARGIN). */
const MARGIN = [56, 40, 56, 72];
const ORIGIN = 'https://router.example';
const LUCI = `${ORIGIN}/cgi-bin/luci/admin/services/dawnline`;
/** The cast's server, the person whose page is shown and the device whose dialog is (web/src/admin/demo/cast.ts). */
const SERVER = 's_home';
const PERSON = 'p_artem';
const DEVICE = 'd_a1';
const args = {
router: 'https://outline.lan',
person: '',
mask: [],
names: [],
langs: ['en', 'ru'],
only: [],
demo: false,
lang: 'en',
build: true,
theme: resolve(ROOT, '..', 'luci-theme-outline', 'htdocs', 'luci-static', 'outline'),
};
for (let i = 2; i < process.argv.length; i++) {
const a = process.argv[i];
const v = () => process.argv[++i] ?? die(`${a} needs a value`);
if (a === '--router') args.router = v().replace(/\/+$/, '');
else if (a === '--person') args.person = v();
else if (a === '--mask') args.mask.push(v().split('=', 2));
else if (a === '--name') args.names.push(v().split('=', 2));
if (a === '--lang') args.langs = v().split(',');
else if (a === '--only') args.only = v().split(',');
else if (a === '--demo') args.demo = true;
else if (a === '--lang') args.lang = v();
else if (a === '--theme') args.theme = resolve(v());
else if (a === '--no-build') args.build = false;
else die(`unknown argument ${a}`);
}
const SUFFIX = args.lang === 'en' ? '' : `-${args.lang}`;
/** The admin's catalog for --lang: msgid -> msgstr, the entries without a context (English: none). */
const CATALOG = (() => {
const out = new Map();
if (args.lang === 'en') return out;
let po;
try {
po = readFileSync(join(ROOT, 'package', 'luci-app-dawnline', 'po', args.lang, 'dawnline.po'), 'utf8');
} catch {
die(`no admin catalog for --lang ${args.lang}`);
}
for (const m of po.matchAll(/^(msgctxt .*\n)?msgid "(.*)"\nmsgstr "(.*)"$/gm)) if (!m[1] && m[3]) out.set(m[2], m[3]);
return out;
})();
/** A button's words as the page shows them in --lang (the pages are clicked by what they say). */
const tr = (id) => CATALOG.get(id) ?? id;
if ([...args.mask, ...args.names].some((m) => m.length !== 2 || !m[0])) die('--mask and --name take real=shown');
/** As shared/format initials(): first letters of the first and last word, or the first two of one word. */
const initials = (name) => {
const p = name.trim().split(/\s+/);
return (p[0][0] + (p.length > 1 ? p[p.length - 1][0] : (p[0][1] ?? ''))).toUpperCase();
};
for (const [real, shown] of args.names)
args.mask.push([real, shown], [real.toLowerCase(), shown.toLowerCase()], [real.toUpperCase(), shown.toUpperCase()]);
const INITIALS = args.names.map(([real, shown]) => [initials(real), initials(shown)]);
const LUCI = `${args.router}/cgi-bin/luci/admin/services/dawnline`;
const USER = process.env.LUCI_USER || 'root';
/*
* Each shot: the page, what must be on it before the capture, what to do
* first (in the page), and the area to keep (in the page, CSS pixels).
* Admin pages keep the theme's header and the content column, 48px either side.
*/
const column = `(() => {
const r = document.querySelector('.dl-root').getBoundingClientRect();
return { x: r.left - 48, w: r.width + 96 };
})()`;
// From the top down to an element; whatever follows it is hidden, not cut through.
const below = (sel) => `(() => {
const c = ${column}, el = document.querySelector(${JSON.stringify(sel)});
for (let e = el; e && !e.classList.contains('dl-root'); e = e.parentElement)
for (let n = e.nextElementSibling; n; n = n.nextElementSibling) n.style.visibility = 'hidden';
return { x: c.x, y: 0, width: c.w, height: el.getBoundingClientRect().bottom + 40 };
})()`;
// In the page: the pages' shadow root and the layer's (what floats: a dialog), and whether the page has been drawn.
const HOST = `document.querySelector('.dl-host')?.shadowRoot`;
const LAYER = `document.querySelector('.dl-layer')?.shadowRoot`;
const has = (sel) => `${HOST}?.querySelector(${JSON.stringify(sel)})`;
/** Each shot: its address, what must stand before it is taken, and how long what it draws takes to come to rest. */
const SHOTS = [
{
name: 'overview',
url: () => `${LUCI}/server`,
width: 1400,
ready: '.dl-srvov .dl-panel.flush .maplibregl-canvas',
// The map shows the last 30 days, not only who is online now.
prep: `(() => {
const b = [...document.querySelectorAll('.dl-srvov .dl-panel.flush button')].find((x) => x.textContent.trim() === ${JSON.stringify(tr('30 days'))});
b?.click();
})()`,
settle: 6000,
clip: below('.dl-srvov .dl-panel.flush'),
},
{
name: 'people',
url: () => `${LUCI}/server?section=people`,
width: 1400,
ready: '.dl-srvbody a[href*="dawnline/person"]',
clip: below('.dl-srvbody'),
},
{
name: 'person',
url: (s) => `${LUCI}/person?id=${encodeURIComponent(s.person)}`,
width: 1400,
ready: '.dl-grid-person .dl-row',
// Where they connected from, on the map.
prep: `(() => {
const b = [...document.querySelectorAll('.dl-grid-person button')].find((x) => x.textContent.trim() === ${JSON.stringify(tr('Show map'))});
b?.click();
})()`,
settle: 6000,
// Down to the end of Access & limits or of the map, whichever is lower; activity rows that would be cut are hidden.
clip: `(() => {
const c = ${column}, cols = document.querySelectorAll('.dl-grid-person > .dl-col');
const places = cols[0].children[2];
const cut = Math.max(cols[1].getBoundingClientRect().bottom, places ? places.getBoundingClientRect().bottom : 0) + 40;
document.querySelectorAll('.dl-grid-person .dl-row').forEach((r) => {
if (r.getBoundingClientRect().bottom > cut - 8) r.style.visibility = 'hidden';
});
// Activity that would start right at the cut goes too, its heading with it.
const act = cols[0].children[3];
if (act && act.getBoundingClientRect().top > cut - 120) act.style.visibility = 'hidden';
return { x: c.x, y: 0, width: c.w, height: cut };
})()`,
},
{ name: 'people', at: `people?server=${SERVER}`, ready: has('.pp-card') },
{ name: 'person', at: `people?server=${SERVER}&id=${PERSON}`, ready: has('.pp-cols') },
// the map's module, then its tiles from the network
{ name: 'places', at: `people?server=${SERVER}&view=map`, ready: has('.maplibregl-canvas'), settle: 7000 },
{ name: 'core', at: `server?server=${SERVER}&p=core`, ready: has('.sv-core') },
{ name: 'device', at: `people?device=${DEVICE}`, ready: `${LAYER}?.querySelector('.sheet[role=dialog]')`, dialog: true },
];
const unknown = args.only.filter((n) => !SHOTS.some((s) => s.name === n));
if (unknown.length) die(`unknown shot ${unknown.join(', ')} (one of ${SHOTS.map((s) => s.name).join(', ')})`);
if (!existsSync(join(args.theme, 'main.css')))
die(
`No build of the Outline theme in ${args.theme}: run \`pnpm build\` in luci-theme-outline/.dev, or point --theme at its luci-static/outline`,
);
const MASK = `((pairs, inits) => {
const doc = new Map();
const isPrivate = (a) => a[0] === 10 || a[0] === 127 || (a[0] === 172 && a[1] >= 16 && a[1] < 32) ||
(a[0] === 192 && a[1] === 168) || (a[0] === 100 && a[1] >= 64 && a[1] < 128) || a[0] === 0 || a[0] >= 224;
const ip = (m) => {
const a = m.split('.').map(Number);
if (a.some((x) => x > 255) || isPrivate(a)) return m;
if (!doc.has(m)) doc.set(m, '203.0.113.' + (24 + doc.size));
return doc.get(m);
};
// IPv6 too, unless link-local or private (fe80::, fc00::/7).
const ip6 = (m) => {
if (/^(fe8|fe9|fea|feb|fc|fd)/i.test(m)) return m;
if (!doc.has(m)) doc.set(m, '2001:db8::' + (24 + doc.size));
return doc.get(m);
};
const swap = (s) =>
pairs
.reduce((t, [a, b]) => t.split(a).join(b), s)
.replace(/\\b\\d{1,3}(?:\\.\\d{1,3}){3}\\b/g, ip)
.replace(/\\b(?:[0-9a-f]{1,4}:){3,7}[0-9a-f]{1,4}\\b/gi, ip6);
const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
for (let n; (n = w.nextNode()); ) {
const ini = inits.find(([a]) => n.nodeValue.trim() === a);
const v = ini ? n.nodeValue.replace(ini[0], ini[1]) : swap(n.nodeValue);
if (v !== n.nodeValue) n.nodeValue = v;
}
document.querySelectorAll('input').forEach((i) => { const v = swap(i.value); if (v !== i.value) i.value = v; });
})(${JSON.stringify(args.mask)}, ${JSON.stringify(INITIALS)})`;
// The content column: the page's host, SIDE either side, from the top of the window (the theme's navbar) down to
// the last thing the page shows (the room it keeps under itself for a dock is not shown).
const PAGE_CLIP = `(() => {
const host = document.querySelector('.dl-host');
const r = host.getBoundingClientRect();
let end = 0;
for (const e of host.shadowRoot.querySelectorAll('*'))
if (!e.firstElementChild && e.getClientRects().length) end = Math.max(end, e.getBoundingClientRect().bottom);
return { x: r.left - ${SIDE}, y: 0, width: r.width + ${2 * SIDE}, height: Math.min(r.bottom, end + 24) + ${FOOT} };
})()`;
async function password() {
if (process.env.LUCI_PASSWORD) return process.env.LUCI_PASSWORD;
if (!process.stdin.isTTY) die('Set LUCI_PASSWORD or run on a terminal');
process.stdout.write(`LuCI password for ${USER}: `);
execFileSync('stty', ['-echo'], { stdio: 'inherit' });
try {
const rl = createInterface({ input: process.stdin });
const line = await new Promise((ok) => rl.once('line', ok));
rl.close();
return line.replace(/\r$/, '');
} finally {
execFileSync('stty', ['echo'], { stdio: 'inherit' });
process.stdout.write('\n');
}
// The dialog alone: the page under it, its scrim and the theme's ground are not drawn, MARGIN around the dialog.
const DIALOG_CLIP = `(() => {
const layer = document.querySelector('.dl-layer');
for (const k of document.body.children) if (k !== layer) k.style.opacity = '0';
document.documentElement.style.background = 'transparent';
document.body.style.background = 'transparent';
const s = document.createElement('style');
s.textContent = '.sheet-root, .sheet-root::before, .sheet-root::after { background: transparent !important; backdrop-filter: none !important; }' +
' .sheet-root > *:not(.sheet) { visibility: hidden !important; }';
layer.shadowRoot.append(s);
const r = layer.shadowRoot.querySelector('.sheet[role=dialog]').getBoundingClientRect();
const [l, t, rr, b] = ${JSON.stringify(MARGIN)};
return { x: r.left - l, y: r.top - t, width: r.width + l + rr, height: r.height + t + b };
})()`;
const TYPES = {
'.html': 'text/html; charset=utf-8',
'.js': 'text/javascript',
'.css': 'text/css',
'.svg': 'image/svg+xml',
'.png': 'image/png',
'.ico': 'image/x-icon',
'.woff2': 'font/woff2',
};
/** The file an address of the made-up router stands for: the demo's page at any LuCI address, its script, the theme's files. */
function fileFor(path, lang) {
if (path.startsWith('/cgi-bin/luci/'))
// the page's language is its <html lang>, which LuCI's server sets
return {
type: TYPES['.html'],
body: Buffer.from(readFileSync(join(DEMO, 'index.html'), 'utf8').replace('<html lang="en"', `<html lang="${lang}"`)),
};
const from = [
['/dawnline-demo/', DEMO],
['/luci-static/outline/', args.theme],
].find(([prefix]) => path.startsWith(prefix));
if (!from) return null;
const file = resolve(from[1], path.slice(from[0].length));
if (!file.startsWith(from[1] + sep) || !existsSync(file)) return null;
return { type: TYPES[extname(file)] ?? 'application/octet-stream', body: readFileSync(file) };
}
async function main() {
const pass = await password();
// The router's certificate is usually for its public name, not router.lan.
const b = await launch(['--ignore-certificate-errors', `--lang=${args.lang}`]);
const { page, evaluate, go, waitSel } = b;
/** Answer everything the page asks of the router's origin; the rest (the map's tiles) goes to the network. */
async function serve(page, lang) {
page.on('Fetch.requestPaused', async (e) => {
const f = fileFor(decodeURIComponent(new URL(e.request.url).pathname), lang);
await page
.send('Fetch.fulfillRequest', {
requestId: e.requestId,
responseCode: f ? 200 : 404,
responseHeaders: f ? [{ name: 'Content-Type', value: f.type }] : [],
body: f ? f.body.toString('base64') : '',
})
.catch(() => {});
});
await page.send('Fetch.enable', { patterns: [{ urlPattern: `${ORIGIN}/*`, requestStage: 'Request' }] });
}
/** What the page complains of goes to the terminal: a question the demo's router does not answer, an error. */
async function listen(page, problems) {
page.on('Runtime.consoleAPICalled', (e) => {
if (e.type === 'warning' || e.type === 'error') problems.push(e.args.map((a) => a.value ?? a.description ?? '').join(' '));
});
page.on('Runtime.exceptionThrown', (e) => problems.push(e.exceptionDetails.exception?.description ?? e.exceptionDetails.text));
await page.send('Runtime.enable');
}
async function capture(lang) {
const suffix = lang === 'en' ? '' : `-${lang}`;
const b = await launch([`--lang=${lang}`]);
const { page, evaluate, go, waitFor } = b;
const problems = [];
try {
// LuCI on auto speaks the browser's language: this one, whatever this computer's is.
await page.send('Network.enable');
await page.send('Network.setExtraHTTPHeaders', { headers: { 'Accept-Language': args.lang } });
await page.send('Emulation.setEmulatedMedia', {
features: [{ name: 'prefers-color-scheme', value: 'dark' }],
});
// The person shown on the Person page; known once People has loaded (or from --person).
const s = { person: args.person };
if (args.demo) {
page.on('Fetch.requestPaused', async (e) => {
try {
const r = await page.send('Fetch.getResponseBody', {
requestId: e.requestId,
});
const body = r.base64Encoded ? Buffer.from(r.body, 'base64').toString('utf8') : r.body;
const out = demoRpc(e.request.postData ?? '', body, s.person);
await page.send('Fetch.fulfillRequest', {
requestId: e.requestId,
responseCode: e.responseStatusCode ?? 200,
responseHeaders: e.responseHeaders ?? [],
body: Buffer.from(out, 'utf8').toString('base64'),
});
} catch {
await page.send('Fetch.continueRequest', { requestId: e.requestId }).catch(() => {});
}
});
await page.send('Fetch.enable', {
patterns: [{ urlPattern: '*ubus*', requestStage: 'Response' }],
});
}
// A tall window: Outline scrolls #maincontent, not the page, so it must hold everything.
const viewport = (width, height = 2600) =>
page.send('Emulation.setDeviceMetricsOverride', {
width,
height,
deviceScaleFactor: SCALE,
mobile: false,
});
await viewport(1400);
await go(`${args.router}/cgi-bin/luci/`);
if (await evaluate(`!!document.querySelector('input[name=luci_password]')`)) {
await evaluate(`(() => {
document.querySelector('input[name=luci_username]').value = ${JSON.stringify(USER)};
document.querySelector('input[name=luci_password]').value = ${JSON.stringify(pass)};
})()`);
const loaded = page.waitFor('Page.loadEventFired');
await evaluate(`document.querySelector('form.login-form, form').submit()`);
await loaded;
if (await evaluate(`!!document.querySelector('input[name=luci_password]')`))
die(
(await evaluate(`!!document.querySelector('.login-error')`))
? `LuCI login failed: wrong password for ${USER} (LUCI_USER sets the user)`
: `LuCI login failed: still on the login page (${await evaluate('location.href')})`,
);
}
// The person to show: the first one on People unless --person.
await go(`${LUCI}/server?section=people`);
await waitSel('.dl-srvbody a[href*="dawnline/person"]');
if (!s.person)
s.person = await evaluate(`new URL(document.querySelector('.dl-srvbody a[href*="dawnline/person"]').href).searchParams.get('id')`);
await page.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'dark' }] });
await page.send('Emulation.setDeviceMetricsOverride', { width: WIDTH, height: HEIGHT, deviceScaleFactor: SCALE, mobile: false });
await listen(page, problems);
await serve(page, lang);
for (const shot of SHOTS) {
if (args.only.length && !args.only.includes(shot.name)) continue;
await viewport(shot.width);
await go(shot.url(s));
await waitSel(shot.ready);
await sleep(2000);
if (shot.prep) await evaluate(shot.prep);
await sleep(shot.settle ?? 1500);
await evaluate(MASK);
const clip = await evaluate(shot.clip);
// Where the page paints nothing (around a dialog taken alone), the capture is transparent.
await page.send('Emulation.setDefaultBackgroundColorOverride', shot.dialog ? { color: { r: 0, g: 0, b: 0, a: 0 } } : {});
await go(`${LUCI}/${shot.at}`);
await waitFor(shot.ready, `the ${shot.name} page`);
await sleep(shot.settle ?? 3000);
const clip = await evaluate(shot.dialog ? DIALOG_CLIP : PAGE_CLIP);
if (shot.dialog) await sleep(400);
const { data } = await page.send('Page.captureScreenshot', {
format: 'png',
clip: { ...clip, scale: 1 },
captureBeyondViewport: true,
});
writeFileSync(join(RAW, `${shot.name}${SUFFIX}.png`), Buffer.from(data, 'base64'));
console.log(`${shot.name}${SUFFIX}: ${Math.round(clip.width)}x${Math.round(clip.height)} (x${SCALE})`);
writeFileSync(join(RAW, `${shot.name}${suffix}.png`), Buffer.from(data, 'base64'));
console.log(`${shot.name}${suffix}: ${Math.round(clip.width)}x${Math.round(clip.height)} (x${SCALE})`);
}
page.close();
} finally {
await b.close();
}
for (const p of new Set(problems)) console.error(` the page (${lang}): ${p}`);
}
async function main() {
if (args.build) execFileSync('npm', ['run', '--silent', 'build:demo'], { cwd: WEB, stdio: 'inherit' });
for (const lang of args.langs) await capture(lang);
}
main().catch((e) => die(e.message));
+9 -8
View File
@@ -1,6 +1,6 @@
// A headless Chromium driven over the DevTools protocol, no npm packages: what
// the README screenshot scripts share (capture-screenshots.mjs from a router,
// capture-portal.mjs from the portal demo). BROWSER=/path/to/chrome picks the
// the README screenshot scripts share (capture-screenshots.mjs from the admin's
// demo, capture-portal.mjs from the portal's). BROWSER=/path/to/chrome picks the
// browser (default: Brave or Chrome on macOS); its profile is a throwaway one.
import { spawn } from 'node:child_process';
@@ -63,8 +63,7 @@ export async function connect(wsUrl) {
/**
* Start the browser headless on a fresh profile and connect to its first page. `flags` go on its command line
* (a language, certificate errors). Returns the page, its helpers, and close() that ends the browser and removes
* the profile.
* (a language). Returns the page, its helpers, and close() that ends the browser and removes the profile.
*/
export async function launch(flags = []) {
const profile = mkdtempSync(join(tmpdir(), 'dawnline-shots-'));
@@ -107,14 +106,16 @@ export async function launch(flags = []) {
await page.send('Page.navigate', { url });
await loaded;
};
const waitSel = async (sel, ms = 20000) => {
// Until an expression is true in the page (what a selector cannot say: something inside a shadow root).
const waitFor = async (expression, what = expression, ms = 20000) => {
for (let t = 0; t < ms; t += 250) {
if (await evaluate(`!!document.querySelector(${JSON.stringify(sel)})`)) return;
if (await evaluate(`!!(${expression})`)) return;
await sleep(250);
}
throw new Error(`timed out waiting for ${sel}`);
throw new Error(`timed out waiting for ${what}`);
};
return { page, evaluate, go, waitSel, close };
const waitSel = (sel, ms) => waitFor(`document.querySelector(${JSON.stringify(sel)})`, sel, ms);
return { page, evaluate, go, waitFor, waitSel, close };
} catch (e) {
await close();
throw e;
-18
View File
@@ -1,18 +0,0 @@
#!/usr/bin/env bash
# Compile-check every ucode file on a router without installing anything:
# the tree is unpacked under /tmp/dlc and scripts/compile-ucode.sh runs there
# (the same check CI runs in an OpenWrt rootfs container, scripts/ucode-container.sh).
# scripts/check-ucode.sh [root@host]
set -euo pipefail
HOST="${1:-root@outline.lan}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)/package/luci-app-dawnline/root"
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
# ucode resolves names at compile time: calling a function declared further
# down a file fails at runtime ("access to undeclared variable"). Catch it here.
python3 "$(dirname "$0")/lint-ucode.py" "$ROOT"
( cd "$ROOT" && COPYFILE_DISABLE=1 tar -czf "$TMP/t.tgz" usr etc )
scp -q "$TMP/t.tgz" "$HOST:/tmp/dl-check.tgz"
ssh "$HOST" 'rm -rf /tmp/dlc && mkdir -p /tmp/dlc && tar -xzf /tmp/dl-check.tgz -C /tmp/dlc && rm /tmp/dl-check.tgz'
# The script goes over stdin (`sh -s`), nothing of it stays on the router.
ssh "$HOST" 'sh -s /tmp/dlc; rc=$?; rm -rf /tmp/dlc; exit $rc' < "$(dirname "$0")/compile-ucode.sh"
-30
View File
@@ -1,30 +0,0 @@
#!/bin/sh
# Compile-check every ucode file of a Dawnline tree without installing it:
# modules are imported by name (dawnline/x.uc is dawnline.x, dawnline/rpc/x.uc
# dawnline.rpc.x) and entry points compiled with `ucode -c`. Needs ucode with
# its fs, uci, ubus and uloop modules, which is any OpenWrt box or an
# openwrt/rootfs container (scripts/ucode-container.sh); check-ucode.sh pipes
# this script to a router.
# scripts/compile-ucode.sh [ROOT] ROOT holds usr/ and etc/ (default: .)
#
# ucode resolves names at compile time and imports are static, so this catches
# a syntax error, a missing module and a named import that nothing exports.
set -eu
ROOT="$(cd "${1:-.}" && pwd)"
cd "$ROOT"
LIB="$ROOT/usr/share/ucode/*.uc"
rc=0
for f in usr/share/ucode/dawnline/*.uc usr/share/ucode/dawnline/rpc/*.uc; do
[ -f "$f" ] || continue
n=$(echo "${f#usr/share/ucode/}" | sed 's/\.uc$//; s#/#.#g')
out=$(ucode -L "$LIB" -e "import * as x from '$n';" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; }
done
# Entry points (ucode scripts outside the module tree); the shell ones live in
# the ShellCheck list of .github/workflows/ci.yml instead.
for f in usr/share/rpcd/ucode/luci.dawnline usr/libexec/dawnline/agent usr/libexec/dawnline/updater usr/bin/dawnline \
usr/share/dawnline/portal/cgi.uc; do
[ -f "$f" ] || { echo "FAIL $f: missing"; rc=1; continue; }
out=$(ucode -L "$LIB" -c -o /dev/null "$f" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; }
done
[ $rc = 0 ] && echo "all ucode files compile"
exit $rc
+19 -3
View File
@@ -1,14 +1,21 @@
#!/usr/bin/env bash
# Dev deploy: build the release tarball and install it on a router over SSH.
# scripts/deploy.sh [root@host]
# PORT=51005 scripts/deploy.sh root@host when its SSH is not on port 22 (from outside the LAN)
# Backs up the configs Dawnline touches to /root/dawnline-predeploy-<ts>/ first.
set -euo pipefail
HOST="${1:-root@outline.lan}"
# ssh and scp name the port each in its own way
SSH=(ssh ${PORT:+-p "$PORT"})
SCP=(scp ${PORT:+-P "$PORT"})
# The Go backend is built for this router's processor.
BACKEND_ARCH="$("${SSH[@]}" "$HOST" uname -m)"
export BACKEND_ARCH
TAR="$("$(dirname "$0")/build-release.sh" | tail -n1)"
scp -q "$TAR" "$HOST:/tmp/luci-app-dawnline.tar.gz"
ssh "$HOST" sh <<'REMOTE'
"${SCP[@]}" -q "$TAR" "$HOST:/tmp/luci-app-dawnline.tar.gz"
"${SSH[@]}" "$HOST" sh <<'REMOTE'
set -e
ts="$(date +%Y%m%d-%H%M%S)"
mkdir -p "/root/dawnline-predeploy-$ts"
@@ -17,14 +24,23 @@ for c in network firewall dhcp dawnline; do
done
# Keep only the five most recent pre-deploy backups.
ls -d /root/dawnline-predeploy-* 2>/dev/null | sort | head -n -5 | xargs -r rm -rf
# The backend that runs is the old file: taken out of procd, so the start below runs the new one.
ubus call service delete '{"name":"dawnline","instance":"backend"}' >/dev/null 2>&1 || true
tar -xozf /tmp/luci-app-dawnline.tar.gz -C /
rm -f /tmp/luci-app-dawnline.tar.gz
sh /etc/uci-defaults/90_dawnline && rm -f /etc/uci-defaults/90_dawnline
for f in /etc/uci-defaults/luci-i18n-dawnline-*; do
if [ -f "$f" ]; then sh "$f" && rm -f "$f"; fi
done
# rpcd reads the access lists once: the backend's object is in the new one.
/etc/init.d/rpcd reload
# The service's instances as the new init script has them (what runs unchanged is left running).
/etc/init.d/dawnline start
# LuCI reads a language's catalogs once per web server: the new ones need a fresh one.
/etc/init.d/uhttpd restart
sleep 1
ubus list luci.dawnline >/dev/null && echo "luci.dawnline registered (backup: /root/dawnline-predeploy-$ts)"
echo "backup: /root/dawnline-predeploy-$ts"
i=0
while ! ubus list dawnline >/dev/null 2>&1 && [ "$i" -lt 10 ]; do sleep 1; i=$((i + 1)); done
ubus list dawnline >/dev/null 2>&1 && echo "backend: $(ubus call dawnline hello | jsonfilter -e '@.version') · pages follow by $(ubus call dawnline hello | jsonfilter -e '@.stream')"
REMOTE
+24 -10
View File
@@ -2,11 +2,13 @@
"""Frame the README screenshots the way the portal draws its own surfaces.
Raw captures live in docs/screenshots/raw/<name>.png at SCALE device pixels
per CSS pixel (scripts/capture-screenshots.mjs takes the admin's from a router,
scripts/capture-portal.mjs the portal's from its demo); the framed images
per CSS pixel (the admin's taken from its pages over made-up answers, in the
Outline theme with its navbar on top; scripts/capture-portal.mjs takes the
portal's from its demo); the framed images
are written to docs/screenshots/<name>.png at the same scale. Each page sits on
a panel like the portal's sheets (#121212, radius 36, 16px around it, the page
inside at radius 20) on the portal's own black. A shot in FLOWS gets its steps
inside at radius 20) on the portal's own black. A shot in ALONE is a dialog
captured by itself: it stands on that black with no panel. A shot in FLOWS gets its steps
in a row in front of the page's lower edge, numbered: sheets captured alone on
a transparent page (raw/<step>.png, FLOW_MARGIN around each). Needs a
Chromium-based browser for the headless render (BROWSER=/path/to/chrome,
@@ -24,13 +26,17 @@ ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
RAW = os.path.join(ROOT, 'docs', 'screenshots', 'raw')
OUT = os.path.join(ROOT, 'docs', 'screenshots')
SHOTS = ['overview', 'people', 'person', 'portal', 'overview-ru', 'people-ru', 'person-ru', 'portal-ru']
SHOTS = ['people', 'person', 'places', 'core', 'device', 'portal',
'people-ru', 'person-ru', 'places-ru', 'core-ru', 'device-ru', 'portal-ru']
# name -> the steps in front of its page, in order (raw captures). The portal's come from its demo
# (scripts/capture-portal.mjs), not a router: adding a device there would add one. -ru: README_ru's.
FLOWS = {
'portal': ['portal-add-1', 'portal-add-2', 'portal-add-3'],
'portal-ru': ['portal-add-1-ru', 'portal-add-2-ru', 'portal-add-3-ru'],
}
# A dialog captured alone (transparent around it, FLOW_MARGIN on each side, as a step is): it stands on the canvas
# as it is, with no panel under it.
ALONE = {'device', 'device-ru'}
PAD_X, PAD_Y, INSET = 96, 80, 16 # canvas around the panel; panel around the page
FLOW_MARGIN = (56, 40, 56, 72) # around a step's sheet in its capture: left, top, right, bottom
STEP_GAP, STEP_OVER, STEP_PAD = 28, 150, 120 # between steps; how far they reach over the page; canvas beside them
@@ -47,15 +53,17 @@ CANDIDATES = [
TEMPLATE = """<!doctype html><html><head><meta charset="utf-8"><style>
html,body{{margin:0;width:{w}px;height:{h}px;overflow:hidden}}
body{{position:relative;background:#080808}}
.panel{{position:absolute;left:{px}px;top:{py}px;width:{pw}px;height:{ph}px;
.panel{{position:absolute;
border-radius:36px;background:#121212;box-shadow:inset 0 0 0 1px rgba(255,255,255,.05),0 30px 80px rgba(0,0,0,.5)}}
.page{{position:absolute;left:{x}px;top:{y}px;width:{iw}px;height:{ih}px;display:block;border-radius:20px;
.page{{position:absolute;display:block;border-radius:20px;
box-shadow:0 0 0 1px rgba(255,255,255,.04)}}
.sheet{{position:absolute;display:block;filter:drop-shadow(0 24px 48px rgba(0,0,0,.6))}}
.n{{position:absolute;width:34px;height:34px;border-radius:50%;display:grid;place-items:center;
font:600 16px system-ui,-apple-system,sans-serif;color:#ededed;background:#232323;
box-shadow:0 0 0 1px rgba(255,255,255,.12),0 6px 16px rgba(0,0,0,.5)}}
</style></head><body><div class="panel"></div><img class="page" src="file://{src}">{steps}</body></html>"""
</style></head><body>{body}</body></html>"""
PAGE = '<div class="panel" style="left:{px}px;top:{py}px;width:{pw}px;height:{ph}px"></div><img class="page" style="left:{x}px;top:{y}px;width:{iw}px;height:{ih}px" src="file://{src}">{steps}'
SHEET = '<img class="sheet" style="left:{x}px;top:{y}px;width:{iw}px;height:{ih}px" src="file://{src}">'
def png_size(path):
@@ -106,11 +114,17 @@ def main():
if not all(os.path.exists(p) for p in flow):
print(f'{name}: a step is missing, the page alone')
flow = []
w, h, x, y, steps = layout(iw, ih, flow)
if name in ALONE:
ml, mt, mr, mb = FLOW_MARGIN
w, h = iw - ml - mr + 2 * PAD_X, ih - mt - mb + 2 * PAD_Y
body = SHEET.format(x=PAD_X - ml, y=PAD_Y - mt, iw=iw, ih=ih, src=src)
else:
w, h, x, y, steps = layout(iw, ih, flow)
body = PAGE.format(x=x, y=y, iw=iw, ih=ih, px=x - INSET, py=y - INSET, pw=iw + 2 * INSET, ph=ih + 2 * INSET,
src=src, steps=steps)
html = os.path.join(tmp, f'{name}.html')
with open(html, 'w', encoding='utf-8') as f:
f.write(TEMPLATE.format(w=w, h=h, x=x, y=y, iw=iw, ih=ih, px=x - INSET, py=y - INSET, pw=iw + 2 * INSET,
ph=ih + 2 * INSET, src=src, steps=steps))
f.write(TEMPLATE.format(w=w, h=h, body=body))
out = os.path.join(OUT, f'{name}.png')
subprocess.run([browser, '--headless=new', '--disable-gpu', '--hide-scrollbars', '--allow-file-access-from-files',
f'--force-device-scale-factor={SCALE}', f'--window-size={w},{h}', f'--screenshot={out}', f'file://{html}'],
-170
View File
@@ -1,170 +0,0 @@
#!/usr/bin/env python3
"""Static checks for the ucode sources that need no router.
ucode resolves names where they are used: calling a function that is declared
further down the same file fails at runtime ("access to undeclared variable").
Also: calls and named imports must match what a Dawnline module exports, the
rpcd methods (dawnline.rpc.*) must match the plugin and its ACL, and regexes
stay POSIX (rules/backend.md). Imports against the module layering are
reported as notes, not failures.
Run: scripts/lint-ucode.py [package root]
"""
import glob
import json
import os
import re
import sys
root = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), '..', 'package', 'luci-app-dawnline', 'root')
MODDIR = f"{root}/usr/share/ucode/dawnline"
PLUGIN = f"{root}/usr/share/rpcd/ucode/luci.dawnline"
ACL = f"{root}/usr/share/rpcd/acl.d/luci-app-dawnline.json"
modules = sorted(glob.glob(f"{MODDIR}/*.uc") + glob.glob(f"{MODDIR}/rpc/*.uc"))
files = modules + [
PLUGIN,
f"{root}/usr/libexec/dawnline/agent",
f"{root}/usr/libexec/dawnline/updater",
f"{root}/usr/bin/dawnline",
f"{root}/usr/share/dawnline/portal/cgi.uc",
]
files = [f for f in files if os.path.exists(f)]
bad = 0
def problem(msg):
global bad
print(msg)
bad = 1
def strip_comments(text):
return re.sub(r'//[^\n]*|/\*.*?\*/', '', text, flags=re.S)
def blank_comments_templates(text):
"""Comments and template literals replaced by their newlines, strings kept:
line numbers stay, and a `}` that starts a line of a template (nft rules)
ends no function. A template inside another one's `${…}` reads as code:
good enough for how Dawnline writes them."""
return re.sub(r"//[^\n]*|/\*.*?\*/|'(?:\\.|[^'\\\n])*'|\"(?:\\.|[^\"\\\n])*\"|`(?:\\.|[^`\\])*`",
lambda m: m.group(0) if m.group(0)[0] in '\'"' else '\n' * m.group(0).count('\n'), text, flags=re.S)
# A regex literal on one line: `/…/` with no slash inside, followed by flags or
# a delimiter (so a division keeps out). Good enough for how Dawnline writes them.
REGEX_LITERAL = re.compile(r'(?<![\w)\]])/((?:\\.|[^/\\\n])+)/[gis]*(?=[,);\s])')
def modname(path):
"""dawnline/rpc/people.uc → 'rpc.people' (as in import … from 'dawnline.rpc.people')."""
rel = os.path.relpath(path, MODDIR)[:-3]
return rel.replace(os.sep, '.')
for f in files:
code = strip_comments(open(f, encoding='utf-8').read())
defs = {m.group(1): m.start() for m in re.finditer(r'^(?:export )?function (\w+)\(', code, re.M)}
for name, pos in defs.items():
for m in re.finditer(r'(?<![\w.\'"`])' + name + r'\(', code[:pos]):
line = code[: m.start()].count('\n') + 1
problem(f"{f}:{line}: {name}() is used before its definition")
# In a module an exported function is an expression statement: its closing
# brace needs a semicolon ("Expecting ';'" breaks the whole module).
lines = blank_comments_templates(open(f, encoding='utf-8').read()).split('\n')
inside = None
for n, text in enumerate(lines, 1):
if inside is None and re.match(r'^export function \w+\(', text):
inside = n
elif inside is not None and re.match(r'^}', text):
if not text.startswith('};'):
problem(f"{f}:{n}: exported function from line {inside} must end with '}};'")
inside = None
# ucode regexes are POSIX: a (?: group fails when the line runs ("Repetition
# not preceded by valid expression"), and let [a, b] = … does not compile.
if re.search(r'/[^/\n]*\(\?[:=!][^/\n]*/', text):
problem(f"{f}:{n}: ucode regexes are POSIX: no (?: (?= (?! groups")
# Lazy quantifiers (*? +? }?) and the [\s\S] class are PCRE: the C
# library's regcomp does something else with them or rejects them.
for m in REGEX_LITERAL.finditer(text):
body = m.group(1)
if re.search(r'(?<!\\)[*+}]\?', body):
problem(f"{f}:{n}: ucode regexes are POSIX: no lazy quantifiers (*? +? }}?) in /{body}/")
if re.search(r'\[\\[sS]\\[sS]\]', body):
problem(f"{f}:{n}: ucode regexes are POSIX: no [\\s\\S] class in /{body}/ (use (.|\\n) or a negated class)")
if re.match(r'\s*(let|const)\s*[\[{]', text):
problem(f"{f}:{n}: ucode has no destructuring")
# Calls into another Dawnline module (alias.fn(...)) and named imports must name
# something it exports: one removed from a module but still used elsewhere only
# fails at runtime.
exports = {}
for f in modules:
text = open(f, encoding='utf-8').read()
exports[modname(f)] = set(re.findall(r'^export (?:function|const|let) (\w+)', text, re.M))
for f in files:
code = strip_comments(open(f, encoding='utf-8').read())
for alias, mod in re.findall(r"import \* as (\w+) from 'dawnline\.([\w.]+)'", code):
if mod not in exports:
problem(f"{f}: imports dawnline.{mod}, which does not exist")
continue
# Calls, and constants (upper case: a lower-case "geo.json" in a string is no access).
for m in re.finditer(r'(?<![\w.])' + alias + r'\.(\w+\(|[A-Z][A-Z0-9_]*\b)', code):
name = m.group(1).rstrip('(')
if name not in exports[mod]:
line = code[: m.start()].count('\n') + 1
problem(f"{f}:{line}: {alias}.{name} is not exported by dawnline.{mod}")
for names, mod in re.findall(r"import \{([^}]*)\} from 'dawnline\.([\w.]+)'", code):
if mod not in exports:
problem(f"{f}: imports dawnline.{mod}, which does not exist")
continue
for name in re.split(r'\s*,\s*', names.strip()):
name = re.split(r'\s+as\s+', name)[0].strip()
if name and name not in exports[mod]:
problem(f"{f}: {name} is not exported by dawnline.{mod}")
# rpcd methods: every rpc module's `methods` is merged by the plugin, no name is
# defined twice (the later one would silently win), and the ACL's read list
# names methods that exist.
methods = {}
for f in glob.glob(f"{MODDIR}/rpc/*.uc"):
text = strip_comments(open(f, encoding='utf-8').read())
m = re.search(r'^export const methods = \{\n(.*?)^\};', text, re.M | re.S)
if not m:
continue
mod = modname(f)
if os.path.exists(PLUGIN) and f"from 'dawnline.{mod}'" not in open(PLUGIN, encoding='utf-8').read():
problem(f"{PLUGIN}: does not import dawnline.{mod}, whose methods would be missing")
for name in re.findall(r"^\t'?(\w+)'?: \{", m.group(1), re.M):
if name in methods:
problem(f"{f}: method {name} is also defined in dawnline.{methods[name]}")
methods[name] = mod
if methods and os.path.exists(ACL):
acl = json.load(open(ACL, encoding='utf-8'))['luci-app-dawnline']
for kind in ('read', 'write'):
for name in acl.get(kind, {}).get('ubus', {}).get('luci.dawnline', []):
if name != '*' and name not in methods:
problem(f"{ACL}: {kind} lists {name}, which no dawnline.rpc module defines")
if 'uci' in acl.get(kind, {}) and 'dawnline' in acl[kind]['uci']:
problem(f"{ACL}: {kind} grants uci 'dawnline' (private keys, no validation): use the rpc methods")
# Layering (rules/backend.md): util, schema → core → store → domain modules →
# apply → entry points. A module importing one from a layer above it is
# reported, not failed, until the existing edges are untangled.
LAYER = {'util': 0, 'i18n': 0, 'schema': 1, 'core': 2, 'store': 3, 'apply': 5}
LAYER_NAME = {0: 'util', 1: 'schema', 2: 'core', 3: 'store', 4: 'domain', 5: 'apply'}
notes = 0
for f in modules:
mod = modname(f)
if mod.startswith('rpc.'):
continue # an entry point: may import anything
mine = LAYER.get(mod, 4)
for dep in re.findall(r"from 'dawnline\.([\w.]+)'", strip_comments(open(f, encoding='utf-8').read())):
theirs = LAYER.get(dep, 4)
if theirs > mine or (theirs == mine and mine < 4 and dep != mod):
print(f"note: {f}: {mod} ({LAYER_NAME[mine]}) imports dawnline.{dep} ({LAYER_NAME[theirs]}), a layer above it")
notes += 1
if notes:
print(f"lint-ucode: {notes} layering notes (not failures)")
print(f"lint-ucode: {len(files)} files checked" + (", problems found" if bad else ", ok"))
sys.exit(bad)
-429
View File
@@ -1,429 +0,0 @@
// Demo data for the README screenshots (scripts/capture-screenshots.mjs --demo):
// the router's own answers (luci.dawnline status, events) with a made-up cast in
// place of its people, devices, places and activity, in the states the
// screenshots should show (online, ending soon, over the limit, paused, ended,
// outside their hours). The router's ids stay, so every page keeps working; it
// is only ever read.
// The admin counts in binary units: "100 GB" is 100 GiB.
const GB = 2 ** 30;
const MIN = 60;
const HOUR = 3600;
const DAY = 86400;
/** Where the cast connects from: [lat, lon, country, cc, network]. */
const CITIES = {
Lisbon: [38.7223, -9.1393, 'Portugal', 'PT', 'MEO'],
Porto: [41.1579, -8.6291, 'Portugal', 'PT', 'NOS'],
Sintra: [38.8029, -9.3817, 'Portugal', 'PT', 'Vodafone Portugal'],
Madrid: [40.4168, -3.7038, 'Spain', 'ES', 'Telefonica de Espana'],
Barcelona: [41.3874, 2.1686, 'Spain', 'ES', 'Orange Espagne'],
Berlin: [52.52, 13.405, 'Germany', 'DE', 'Deutsche Telekom'],
Milan: [45.4642, 9.19, 'Italy', 'IT', 'TIM'],
Amsterdam: [52.3676, 4.9041, 'Netherlands', 'NL', 'KPN'],
Paris: [48.8566, 2.3522, 'France', 'FR', 'Orange'],
London: [51.5072, -0.1276, 'United Kingdom', 'GB', 'BT'],
Stockholm: [59.3293, 18.0686, 'Sweden', 'SE', 'Telia'],
};
/** The router's own place. */
const HOME = 'Lisbon';
/** Shared at home (Access): what a Home-only person can be limited to. */
const SERVICES = [
{ id: 'demo-nas', name: 'NAS', address: '10.0.1.20', ports: ['445', '5000'] },
{
id: 'demo-ha',
name: 'Home Assistant',
address: '10.0.1.30',
ports: ['8123'],
},
];
/** How busy each day of the week is, Monday first. */
const WEEK = [0.9, 1.15, 0.8, 1.05, 1.3, 0.75, 1.1];
/**
* Who the screenshots show, the --person first (the Person page), each with
* their city. A device: [name, kind, when it was last seen, GB this month,
* earlier places as 'City:days ago']; when: 'online', 'mins:N', 'hours:N',
* 'days:N', 'never', 'stale' (settings changed since), 'disabled'. Its last
* place is the person's city unless `at` names another.
*/
export const CAST = [
{
name: 'Lena Ortiz',
city: 'Lisbon',
limit: 4,
quota: 100,
used: 38.6,
note: 'Family',
devices: [
['iPhone 16', 'phone', 'online', 14.2, ['Sintra:3', 'Porto:9', 'Madrid:16']],
['MacBook Pro', 'computer', 'hours:3', 21.9, ['Berlin:12']],
['iPad Air', 'tablet', 'never', 0],
],
added: [['iPad Air', 2, 'portal']],
},
{
name: 'Marco Rossi',
city: 'Milan',
ends: 4,
devices: [
['Pixel 9', 'phone', 'online', 6.4, ['Barcelona:8']],
['ThinkPad X1', 'computer', 'days:1', 12.8],
],
},
{
name: 'Yuki Tanaka',
city: 'Amsterdam',
state: 'quota',
quota: 20,
used: 20.4,
devices: [
['Galaxy S24', 'phone', 'hours:6', 14.1, ['Paris:5']],
['Living room TV', 'other', 'stale', 6.3],
],
},
{
name: 'Sam Okafor',
city: 'London',
state: 'paused',
paused: 3,
devices: [
['Gaming PC', 'computer', 'days:9', 3.1],
['Steam Deck', 'other', 'disabled', 0],
],
},
{
name: 'Nora Lindqvist',
city: 'Stockholm',
state: 'expired',
ends: -3,
devices: [['iPhone 13 mini', 'phone', 'days:4', 1.2]],
},
{
name: 'Mia Ortiz',
city: 'Lisbon',
state: 'hours',
hours: '07:00-21:00',
limit: 1,
devices: [['Fire HD 10', 'tablet', 'hours:11', 2.6]],
},
];
const slug = (s) =>
s
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-|-$/g, '');
const date = (t) => new Date(t * 1000).toISOString().slice(0, 10);
const seen = (when, now) => {
const [k, n] = when.split(':');
const v = +n || 0;
return (
{
online: now - 40,
mins: now - v * MIN,
hours: now - v * HOUR,
days: now - v * DAY,
stale: now - 2 * DAY,
disabled: now - 41 * DAY,
}[k] ?? 0
);
};
/**
* A week of daily [rx, tx] that adds up to about a quarter of the month, today last (nothing before it was first
* seen), rx (from the device) about an eighth.
*/
const week = (gb, last, now) =>
[0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) => {
const b = !gb || now - (6 - i) * DAY < last - DAY ? 0 : Math.round(((gb / 4) * f * GB) / 7);
return [Math.round(b * 0.12), b - Math.round(b * 0.12)];
});
/**
* One second of the cast's traffic through a server (the k-th), [rx, tx] in bytes/s: a few devices streaming,
* their uploads small. The same for a second whichever call asks, so the live chart keeps its shape.
*/
const meterRate = (ts, k) => {
const wave = (a, b) => Math.sin(ts / a + k) * 0.45 + Math.sin(ts / b + 2 * k) * 0.25;
const noise = (((ts * 7919 + k * 104729) % 1000) / 1000 - 0.5) * 0.35;
return [Math.round(Math.max(0, 1.8e5 * (1 + wave(7, 17) + noise))), Math.round(Math.max(0, 1.6e6 * (1 + wave(9, 23) + noise)))];
};
let ipN = 10;
/** A documentation address (the capture swaps public addresses for these anyway). */
const ip = () => `203.0.113.${ipN++}`;
const where = (city) => `${city} · ${CITIES[city][4]}`;
/** What the last status made of the router's ids, for the calls that come after it (events, usage, the meter). */
const demo = { events: [], people: new Map(), days: [], now: 0, servers: [] };
/**
* Daily traffic over `days` (oldest first) for `gb` this month: busier some days of the week, today
* only partly gone. Each day's [rx, tx] in bytes, rx (from the devices) about an eighth.
*/
function daily(days, gb, now) {
const month = days[days.length - 1].slice(0, 7);
const w = days.map((d, i) => {
const wd = (new Date(`${d}T12:00:00Z`).getUTCDay() + 6) % 7;
const today = i === days.length - 1 ? ((now % DAY) / DAY) * 0.9 + 0.1 : 1;
return WEEK[wd] * (0.85 + ((i * 37) % 11) / 30) * today;
});
const inMonth = w.reduce((s, x, i) => s + (days[i].startsWith(month) ? x : 0), 0) || 1;
return w.map((x) => {
const b = (x / inMonth) * gb * GB;
return [Math.round(b * 0.12), Math.round(b * 0.88)];
});
}
const usage = (days, pairs) => days.map((day, i) => ({ day, rx: pairs[i][0], tx: pairs[i][1] }));
/** The places a device was at, oldest first: [city, ts, ip]. */
function trail(c, d, hs, now) {
if (!hs) return [];
const earlier = (d[4] ?? []).map((s) => {
const [city, ago] = s.split(':');
return [city, now - +ago * DAY - 5 * HOUR, ip()];
});
return [...earlier.reverse(), [c.city, hs, ip()]];
}
function demoStatus(st, first) {
const now = st.now;
ipN = 10;
const real = [...st.people].sort((a, b) => (a.id === first ? -1 : b.id === first ? 1 : a.id < b.id ? -1 : 1));
const spare = real.flatMap((p) => p.devices);
const points = [];
const events = [];
const people = CAST.map((c, i) => {
const base = real[i] ?? {
...real[real.length - 1],
id: `demo-${i}`,
devices: [],
};
const state = c.state ?? 'active';
const devices = c.devices.map((cd, j) => {
const [name, kind, when, gb] = cd;
const tpl = base.devices[j] ?? {
...spare[j % spare.length],
id: `${base.id}-demo-${j}`,
address: `10.8.0.${200 + i * 8 + j}`,
};
const hs = when === 'never' ? 0 : seen(when, now);
const online = when === 'online' && !['paused', 'expired', 'hours'].includes(state);
const places = trail(c, cd, hs, now);
places.forEach(([city, ts, addr], k) => {
const [lat, lon, country, cc, org] = CITIES[city];
const current = online && k === places.length - 1;
points.push({
person: base.id,
device: tpl.id,
ip: addr,
ts,
online: current,
lat,
lon,
city,
country,
cc,
asn: 0,
org,
});
const ev = {
person: base.id,
device: tpl.id,
pname: c.name,
dname: name,
dkind: kind,
};
// Online now: connected a while ago (the handshake renews every few minutes); otherwise on for a couple of hours.
events.push({
...ev,
type: 'connect',
detail: addr,
where: where(city),
ts: current ? now - 95 * MIN - j * 13 * MIN : ts - 2 * HOUR,
});
if (!current) events.push({ ...ev, type: 'disconnect', ts });
});
// A phone in hand switches between Wi-Fi and mobile data.
if (online && kind === 'phone') {
const [, , addr] = places[places.length - 1];
events.push({
person: base.id,
device: tpl.id,
pname: c.name,
dname: name,
dkind: kind,
type: 'roam',
detail: `${ip()} → ${addr}`,
ts: now - 25 * MIN,
});
}
return {
...tpl,
name,
kind,
online,
active: online,
handshake: hs,
endpoint: places.length ? places[places.length - 1][2] : '',
config_stale: when === 'stale',
disabled: when === 'disabled',
month: [Math.round(gb * 0.12 * GB), Math.round(gb * 0.88 * GB)],
total: [Math.round(gb * 0.3 * GB), Math.round(gb * 2.2 * GB)],
spark: week(gb, hs, now),
hostname: hs ? `${slug(name)}.${slug(c.name.split(' ')[0])}.lan` : '',
// As set up: nothing failing, its own link values the server's, its data flowing while online.
link: null,
setup: online ? { state: 'flowing', since: hs } : null,
lan_bypass: false,
mtu: 0,
keepalive: null,
};
});
for (const [name, ago, by] of c.added ?? []) {
const d = devices.find((x) => x.name === name);
if (d)
events.push({
person: base.id,
device: d.id,
pname: c.name,
dname: name,
dkind: d.kind,
type: 'device_added',
detail: name,
by,
ts: now - ago * DAY,
});
}
if (c.paused)
events.push({
person: base.id,
pname: c.name,
type: 'paused',
by: 'admin',
ts: now - c.paused * DAY,
});
const month = devices.reduce((s, d) => [s[0] + d.month[0], s[1] + d.month[1]], [0, 0]);
const live = devices.some((d) => d.online);
demo.people.set(base.id, {
devices: devices.map((d, j) => [d.id, c.devices[j][3]]),
});
return {
...base,
name: c.name,
state,
paused: state === 'paused',
hours: c.hours ?? '',
note: c.note ?? '',
expires: c.ends !== undefined ? date(now + c.ends * DAY) : '',
device_limit: c.limit ?? Math.max(3, devices.length),
quota_gb: c.quota ?? 0,
quota_period: 'month',
quota_limit: (c.quota ?? 0) * GB,
quota_used: Math.round((c.used ?? (month[0] + month[1]) / GB) * GB),
bonus_gb: 0,
month,
total: [month[0] * 3, month[1] * 3],
online: devices.filter((d) => d.online).length,
last_seen: Math.max(0, ...devices.map((d) => d.handshake)),
rate: (base.rate ?? []).map(([t], k) => [t, live ? 12000 + ((k * 7919) % 9000) : 0, live ? 120000 + ((k * 104729) % 90000) : 0]),
devices,
};
});
const devices = people.flatMap((p) => p.devices);
const month = people.reduce((s, p) => [s[0] + p.month[0], s[1] + p.month[1]], [0, 0]);
events.sort((a, b) => a.ts - b.ts);
demo.events = events;
points.sort((a, b) => b.ts - a.ts);
demo.now = now;
demo.servers = (st.servers ?? []).map((x) => x.id);
demo.days = (st.series ?? []).map((x) => x.day);
if (!demo.days.length) for (let k = 29; k >= 0; k--) demo.days.push(date(now - k * DAY));
const all = CAST.reduce((s, c) => s + c.devices.reduce((t, d) => t + d[3], 0), 0);
const series = usage(demo.days, daily(demo.days, all, now));
const today = series[series.length - 1];
const [lat, lon, country, cc, org] = CITIES[HOME];
return {
...st,
people,
totals: {
...st.totals,
people: people.length,
devices: devices.length,
online: devices.filter((d) => d.online).length,
active: people.filter((p) => p.state === 'active').length,
today: [today.rx, today.tx],
month,
},
series,
servers: st.servers.map((x) => ({ ...x, series })),
services: st.services?.length ? st.services : SERVICES,
geo: st.geo && {
...st.geo,
home: { lat, lon, city: HOME, country, cc, asn: 0, org },
points,
},
events: events.slice(-60),
};
}
/**
* A ubus JSON-RPC exchange (LuCI batches calls into one request) with the
* luci.dawnline answers made into the demo; anything else as it came.
*/
export function demoRpc(request, response, first) {
let req;
let res;
try {
req = JSON.parse(request);
res = JSON.parse(response);
} catch {
return response;
}
const calls = new Map((Array.isArray(req) ? req : [req]).map((c) => [c.id, c.params ?? []]));
const fix = (r) => {
const [, object, method, args] = calls.get(r?.id) ?? [];
const data = r?.result?.[1];
if (object !== 'luci.dawnline' || !data || typeof data !== 'object') return r;
if (method === 'status' && Array.isArray(data.people)) return { ...r, result: [r.result[0], demoStatus(data, first)] };
if (method === 'person_usage' && demo.people.has(args?.id) && demo.days.length) {
const devs = demo.people.get(args.id).devices ?? [];
const per = Object.fromEntries(devs.map(([id, gb]) => [id, daily(demo.days, gb, demo.now)]));
const sum = demo.days.map((_, i) => devs.reduce((s, [id]) => [s[0] + per[id][i][0], s[1] + per[id][i][1]], [0, 0]));
const devices = Object.fromEntries(devs.map(([id]) => [id, usage(demo.days, per[id])]));
return {
...r,
result: [r.result[0], { ...data, person: usage(demo.days, sum), devices }],
};
}
// Every check passes: the screenshots show Dawnline, not this router's own setup.
if (method === 'health' && Array.isArray(data.checks))
return {
...r,
result: [
r.result[0],
{
...data,
checks: data.checks.map((c) => (c.status === 'warn' || c.status === 'error' ? { ...c, status: 'ok', problem: null } : c)),
},
],
};
// Speed now, live: the last two minutes of the cast's traffic, not the router's.
if (method === 'meter' && Array.isArray(data.points)) {
const ids = demo.servers.length ? demo.servers : [...new Set(data.points.flatMap((p) => Object.keys(p.servers ?? {})))];
const keep = data.keep > 1 ? data.keep : 120;
const since = +args?.since || 0;
const points = [];
for (let ts = data.now - keep + 1; ts <= data.now; ts++)
if (ts > since) points.push({ ts, servers: Object.fromEntries(ids.map((id, k) => [id, meterRate(ts, k)])) });
return { ...r, result: [r.result[0], { ...data, ts: data.now, points }] };
}
if (method === 'events' && Array.isArray(data.events)) {
const mine = demo.events.filter((e) => !args?.person || e.person === args.person);
return {
...r,
result: [r.result[0], { ...data, events: mine, total: mine.length }],
};
}
return r;
};
return JSON.stringify(Array.isArray(res) ? res.map(fix) : fix(res));
}
-51
View File
@@ -1,51 +0,0 @@
#!/usr/bin/env bash
# Run the ucode checks the way CI does: in an OpenWrt rootfs container with the
# release's own ucode and libuci — compile every file (compile-ucode.sh), then
# the unit tests (tests/ucode/run.sh). Needs docker; the repository is mounted
# read-only at /src, the container is thrown away.
# scripts/ucode-container.sh [24.10|25.12|all] [test name filter]
#
# Images are the x86-64 rootfs of the OpenWrt releases the packages are built
# for (build/Dockerfile, scripts/build-packages.sh), pinned by digest so a
# retagged image cannot change what CI runs. To move to a new release change
# the tag and the digest together (docker buildx imagetools inspect <image>).
set -euo pipefail
REPO="$(cd "$(dirname "$0")/.." && pwd)"
image_for() {
case "$1" in
24.10) echo 'openwrt/rootfs:x86-64-24.10.6@sha256:fd76f3afb9c390ef2915618b6e3d7187698c03ecc6c23d3a13f12b62d9c6209e' ;;
25.12) echo 'openwrt/rootfs:x86-64-25.12.3@sha256:af882e0583954fc2ceac6b081a9d214fc739cfea36a29b48795a5f15563aa3b5' ;;
*) echo "unknown release $1 (24.10 or 25.12)" >&2; exit 2 ;;
esac
}
releases="${1:-all}"
[ "$releases" = all ] && releases='24.10 25.12'
rc=0
for rel in $releases; do
image="$(image_for "$rel")"
echo "== OpenWrt $rel ($image)"
# The checks run from this stdin script (`sh -s`): ucode-mod-uloop is not in
# the 24.10 rootfs, so what is missing is installed from the release's feeds.
docker run --rm -i --platform linux/amd64 -v "$REPO:/src:ro" -e "FILTER=${2:-}" "$image" sh -s <<-'INNER' || rc=1
set -eu
missing=''
command -v ucode >/dev/null || missing='ucode'
for m in fs uci ubus uloop; do
[ -e "/usr/lib/ucode/$m.so" ] || missing="$missing ucode-mod-$m"
done
if [ -n "$missing" ]; then
echo "installing:$missing"
if command -v apk >/dev/null; then
# shellcheck disable=SC2086
apk add --quiet $missing
else
mkdir -p /var/lock
# shellcheck disable=SC2086
opkg update >/dev/null && opkg install $missing >/dev/null
fi
fi
sh /src/scripts/compile-ucode.sh /src/package/luci-app-dawnline/root
sh /src/tests/ucode/run.sh /src "$FILTER"
INNER
done
exit $rc