Dawnline 0.10.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 / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
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 / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
- Portal redesigned from scratch. No header bar: the page opens with the server's name and the person's and fades under the edges. Device cards show the status, the last 7 days (hover a day for its figures) and a Connect or Update button; "Your access" folds into rows: what they can reach (with the names at home), data this month day by day, and when access ends. The page follows the system's light or dark theme - Adding a device: pick the kind (PC, Mobile, Router, Other) and a name, or add it from the device itself with the page's QR code. The set-up sheet then shows the app for that system and the connection, waits for the first connection, says "<device> connected" and closes on its own - Switching apps in the set-up sheet changes only what differs: the old words blur into the new ones, and the menu path is shown for iOS and Android in one line. Names, numbers and statuses that change on the page morph in place - Dialogs open in the middle on a computer, on the same spring as the menu; buttons that wait for the router show a spinner at once - A paused account gets one card that says so; the page's messages are short and no longer send people to the admin. A QR code of the page sits beside the breadcrumb, to open it on another device - Allowed hours are shown in the visitor's own time zone - The portal's Title setting is gone: the page and its tab take the server's name. A title set before is removed on upgrade - The admin names .conf files after the server too, as the portal does (Outline-Home.conf); its device menu says "Download AmneziaWG config" and "Copy AmneziaVPN config", and its QR codes use the portal's round look in the admin's light or dark colours - README rewritten, with screenshots made from a demo cast (scripts/capture-screenshots.mjs --demo)
This commit is contained in:
1 parent
edeb1506fd
commit
4f12ca19e7
94 files changed
+8076
-5009
No files matched your search
@@ -10,11 +10,13 @@
|
||||
//
|
||||
// scripts/capture-screenshots.mjs [--router https://router.lan] [--person id]
|
||||
// [--mask real=shown ...] [--name real=shown ...]
|
||||
// [--only overview,people]
|
||||
// [--only overview,people] [--demo]
|
||||
//
|
||||
// --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.
|
||||
|
||||
import { execFileSync, spawn } from 'node:child_process';
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
@@ -22,12 +24,20 @@ import { tmpdir } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createInterface } from 'node:readline';
|
||||
import { demoRpc } from './screenshot-demo.mjs';
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const RAW = join(ROOT, 'docs', 'screenshots', 'raw');
|
||||
const SCALE = 2;
|
||||
|
||||
const args = { router: 'https://outline.lan', person: '', mask: [], names: [], only: [] };
|
||||
const args = {
|
||||
router: 'https://outline.lan',
|
||||
person: '',
|
||||
mask: [],
|
||||
names: [],
|
||||
only: [],
|
||||
demo: false,
|
||||
};
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
const a = process.argv[i];
|
||||
const v = () => process.argv[++i] ?? die(`${a} needs a value`);
|
||||
@@ -36,6 +46,7 @@ for (let i = 2; i < process.argv.length; i++) {
|
||||
else if (a === '--mask') args.mask.push(v().split('=', 2));
|
||||
else if (a === '--name') args.names.push(v().split('=', 2));
|
||||
else if (a === '--only') args.only = v().split(',');
|
||||
else if (a === '--demo') args.demo = true;
|
||||
else die(`unknown argument ${a}`);
|
||||
}
|
||||
if ([...args.mask, ...args.names].some((m) => m.length !== 2 || !m[0])) die('--mask and --name take real=shown');
|
||||
@@ -100,31 +111,26 @@ const SHOTS = [
|
||||
url: (s) => `${LUCI}/person?id=${encodeURIComponent(s.person)}`,
|
||||
width: 1400,
|
||||
ready: '.dl-grid-person .dl-row',
|
||||
// Down to the end of Access & limits; activity rows that would be cut are hidden.
|
||||
// Where they connected from, on the map.
|
||||
prep: `(() => {
|
||||
const b = [...document.querySelectorAll('.dl-grid-person button')].find((x) => x.textContent.trim() === '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}, cut = document.querySelector('.dl-grid-person > .dl-col:last-child').getBoundingClientRect().bottom + 40;
|
||||
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: 'access',
|
||||
url: () => `${LUCI}/server?section=access`,
|
||||
width: 1400,
|
||||
ready: 'section.dl-ifcard details',
|
||||
// The home network card alone, its folded lists closed.
|
||||
prep: `(() => {
|
||||
const card = [...document.querySelectorAll('section.dl-ifcard')].find((s) => s.querySelector('details'));
|
||||
card.querySelectorAll('details[open]').forEach((d) => (d.open = false));
|
||||
card.setAttribute('data-shot', '');
|
||||
})()`,
|
||||
clip: `(() => {
|
||||
const r = document.querySelector('[data-shot]').getBoundingClientRect();
|
||||
return { x: r.left - 12, y: r.top - 12, width: r.width + 24, height: r.height + 24 };
|
||||
})()`,
|
||||
},
|
||||
{
|
||||
name: 'portal',
|
||||
url: (s) => s.portal,
|
||||
@@ -156,7 +162,17 @@ const MASK = `((pairs, inits) => {
|
||||
if (!doc.has(m)) doc.set(m, '203.0.113.' + (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);
|
||||
// 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);
|
||||
@@ -203,6 +219,7 @@ async function connect(wsUrl) {
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
const waiters = [];
|
||||
const listeners = [];
|
||||
ws.onmessage = (m) => {
|
||||
const msg = JSON.parse(m.data);
|
||||
if (msg.id && pending.has(msg.id)) {
|
||||
@@ -210,6 +227,7 @@ async function connect(wsUrl) {
|
||||
pending.delete(msg.id);
|
||||
msg.error ? fail(new Error(msg.error.message)) : ok(msg.result);
|
||||
} else if (msg.method) {
|
||||
for (const l of listeners.filter((x) => x.method === msg.method)) l.fn(msg.params);
|
||||
for (const w of waiters.filter((x) => x.method === msg.method)) {
|
||||
waiters.splice(waiters.indexOf(w), 1);
|
||||
w.ok(msg.params);
|
||||
@@ -222,7 +240,8 @@ async function connect(wsUrl) {
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
const waitFor = (method) => new Promise((ok) => waiters.push({ method, ok }));
|
||||
return { send, waitFor, close: () => ws.close() };
|
||||
const on = (method, fn) => listeners.push({ method, fn });
|
||||
return { send, waitFor, on, close: () => ws.close() };
|
||||
}
|
||||
|
||||
const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
||||
@@ -255,10 +274,40 @@ async function main() {
|
||||
const pages = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
|
||||
const page = await connect(pages.find((p) => p.type === 'page').webSocketDebuggerUrl);
|
||||
await page.send('Page.enable');
|
||||
await page.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'dark' }] });
|
||||
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, portal: '' };
|
||||
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' }],
|
||||
});
|
||||
}
|
||||
|
||||
const evaluate = async (expression) => {
|
||||
const r = await page.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
||||
const r = await page.send('Runtime.evaluate', {
|
||||
expression,
|
||||
awaitPromise: true,
|
||||
returnByValue: true,
|
||||
});
|
||||
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text);
|
||||
return r.result.value;
|
||||
};
|
||||
@@ -276,7 +325,12 @@ async function main() {
|
||||
};
|
||||
// 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 });
|
||||
page.send('Emulation.setDeviceMetricsOverride', {
|
||||
width,
|
||||
height,
|
||||
deviceScaleFactor: SCALE,
|
||||
mobile: false,
|
||||
});
|
||||
|
||||
await viewport(1400);
|
||||
await go(`${args.router}/cgi-bin/luci/`);
|
||||
@@ -297,13 +351,10 @@ async function main() {
|
||||
}
|
||||
|
||||
// The person to show (the first one on People unless --person) and their personal link.
|
||||
const s = { person: args.person, portal: '' };
|
||||
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')`,
|
||||
);
|
||||
s.person = await evaluate(`new URL(document.querySelector('.dl-srvbody a[href*="dawnline/person"]').href).searchParams.get('id')`);
|
||||
s.portal = await evaluate(`L.require('rpc').then((rpc) =>
|
||||
rpc.declare({ object: 'luci.dawnline', method: 'person_links', params: ['id'] })(${JSON.stringify(s.person)}))
|
||||
.then((r) => r.link ?? r.links?.[0] ?? '')`);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Put the README screenshots into a browser window on a dawn gradient.
|
||||
"""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 them); the framed images
|
||||
are written to docs/screenshots/<name>.png at the same scale. Needs a
|
||||
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
|
||||
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,
|
||||
default: Brave or Chrome on macOS).
|
||||
Run: scripts/frame-screenshots.py
|
||||
Run: scripts/frame-screenshots.py [name ...] (all of them when no name is given)
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
@@ -18,16 +22,18 @@ import tempfile
|
||||
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')
|
||||
FONT = os.path.join(ROOT, 'package', 'luci-app-dawnline', 'root', 'usr', 'share', 'dawnline', 'portal', 'assets',
|
||||
'geist-latin-wght-normal.woff2')
|
||||
|
||||
# name -> what the address bar shows
|
||||
SHOTS = {
|
||||
'overview': 'router.lan · Dawnline',
|
||||
'people': 'router.lan · Dawnline · People',
|
||||
'person': 'router.lan · Dawnline · Myata',
|
||||
'portal': 'vpn.example.com/kamiro-telosu-bavine',
|
||||
'access': 'router.lan · Dawnline · Home · Access',
|
||||
SHOTS = ['overview', 'people', 'person', 'portal']
|
||||
# name -> the steps in front of its page, in order (raw captures). Taken with demo data, not on a router:
|
||||
# adding a device there would add one.
|
||||
FLOWS = {
|
||||
'portal': ['portal-add-1', 'portal-add-2', 'portal-add-3'],
|
||||
}
|
||||
PAD_X, PAD_Y, BAR = 120, 96, 40
|
||||
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
|
||||
SCALE = 2
|
||||
|
||||
CANDIDATES = [
|
||||
@@ -39,26 +45,18 @@ CANDIDATES = [
|
||||
]
|
||||
|
||||
TEMPLATE = """<!doctype html><html><head><meta charset="utf-8"><style>
|
||||
@font-face{{font-family:Geist;src:url('file://{font}') format('woff2');font-weight:100 900}}
|
||||
html,body{{margin:0;width:{w}px;height:{h}px;overflow:hidden}}
|
||||
body{{display:flex;align-items:center;justify-content:center;
|
||||
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
|
||||
background:
|
||||
radial-gradient({gw}px {gh}px at 50% 118%, rgba(255,140,70,.55), rgba(255,140,70,0) 70%),
|
||||
radial-gradient({gw2}px {gh2}px at 50% 100%, rgba(250,90,120,.30), rgba(250,90,120,0) 70%),
|
||||
linear-gradient(180deg,#070a14 0%,#0c1226 55%,#1a1430 100%)}}
|
||||
.win{{width:{iw}px;border-radius:14px;overflow:hidden;background:#000;
|
||||
box-shadow:0 0 0 1px rgba(255,255,255,.08),0 40px 120px rgba(0,0,0,.65),0 10px 30px rgba(0,0,0,.4)}}
|
||||
.bar{{height:{bar}px;background:#15171c;display:flex;align-items:center;gap:8px;padding:0 16px;
|
||||
border-bottom:1px solid rgba(255,255,255,.06);position:relative}}
|
||||
.dot{{width:12px;height:12px;border-radius:50%}}
|
||||
.url{{position:absolute;left:50%;transform:translateX(-50%);height:24px;padding:0 14px;border-radius:7px;
|
||||
background:#0d0f13;color:#8b8f98;font-size:13px;display:flex;align-items:center;gap:6px;white-space:nowrap}}
|
||||
.url svg{{width:11px;height:11px;fill:none;stroke:#8b8f98;stroke-width:2}}
|
||||
img{{display:block;width:{iw}px;height:{ih}px}}
|
||||
</style></head><body><div class="win"><div class="bar">
|
||||
<span class="dot" style="background:#ff5f57"></span><span class="dot" style="background:#febc2e"></span><span class="dot" style="background:#28c840"></span>
|
||||
<span class="url"><svg viewBox="0 0 24 24"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>{url}</span>
|
||||
</div><img src="file://{src}"></div></body></html>"""
|
||||
body{{position:relative;background:#080808}}
|
||||
.panel{{position:absolute;left:{px}px;top:{py}px;width:{pw}px;height:{ph}px;
|
||||
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;
|
||||
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 Geist,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>"""
|
||||
|
||||
|
||||
def png_size(path):
|
||||
@@ -67,22 +65,53 @@ def png_size(path):
|
||||
return struct.unpack('>II', head[16:24])
|
||||
|
||||
|
||||
def layout(iw, ih, flow):
|
||||
"""Where the page goes and its steps in a row in front of its lower edge: (width, height, page x, page y, steps)."""
|
||||
w, h = iw + 2 * (INSET + PAD_X), ih + 2 * (INSET + PAD_Y)
|
||||
x, y = PAD_X + INSET, PAD_Y + INSET
|
||||
if not flow:
|
||||
return w, h, x, y, ''
|
||||
ml, mt, mr, mb = FLOW_MARGIN
|
||||
sizes = [tuple(v // SCALE for v in png_size(src)) for src in flow]
|
||||
row = sum(pw - ml - mr for pw, _ in sizes) + STEP_GAP * (len(sizes) - 1)
|
||||
w = max(w, row + 2 * STEP_PAD)
|
||||
x = (w - iw) // 2
|
||||
top = y + ih - STEP_OVER
|
||||
h = top + max(ph - mt - mb for _, ph in sizes) + PAD_Y
|
||||
out, sx = [], (w - row) // 2
|
||||
for i, (src, (pw, ph)) in enumerate(zip(flow, sizes)):
|
||||
out.append(f'<img class="sheet" src="file://{src}" style="left:{sx - ml}px;top:{top - mt}px;width:{pw}px;height:{ph}px">')
|
||||
out.append(f'<span class="n" style="left:{sx - 14}px;top:{top - 14}px">{i + 1}</span>')
|
||||
sx += pw - ml - mr + STEP_GAP
|
||||
return w, h, x, y, ''.join(out)
|
||||
|
||||
|
||||
def main():
|
||||
browser = next((b for b in CANDIDATES if b and os.path.exists(b)), None)
|
||||
if not browser:
|
||||
sys.exit('No Chromium-based browser found; set BROWSER=/path/to/chrome')
|
||||
only = sys.argv[1:]
|
||||
unknown = [n for n in only if n not in SHOTS]
|
||||
if unknown:
|
||||
sys.exit(f'unknown screenshot {", ".join(unknown)} (one of {", ".join(SHOTS)})')
|
||||
tmp = tempfile.mkdtemp()
|
||||
for name, url in SHOTS.items():
|
||||
for name in SHOTS:
|
||||
if only and name not in only:
|
||||
continue
|
||||
src = os.path.join(RAW, f'{name}.png')
|
||||
if not os.path.exists(src):
|
||||
print(f'skip {name}: no raw capture')
|
||||
continue
|
||||
iw, ih = (v // SCALE for v in png_size(src))
|
||||
w, h = iw + 2 * PAD_X, ih + BAR + 2 * PAD_Y
|
||||
flow = [os.path.join(RAW, f'{step}.png') for step in FLOWS.get(name, [])]
|
||||
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)
|
||||
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, iw=iw, ih=ih, bar=BAR, url=url, src=src,
|
||||
gw=int(w * .8), gh=int(h * .5), gw2=int(w * .6), gh2=int(h * .45)))
|
||||
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, font=FONT, steps=steps))
|
||||
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}'],
|
||||
|
||||
@@ -0,0 +1,397 @@
|
||||
// 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 totals that adds up to about a quarter of the month, today last (nothing before it was first seen). */
|
||||
const week = (gb, last, now) =>
|
||||
[0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) => (!gb || now - (6 - i) * DAY < last - DAY ? 0 : Math.round(((gb / 4) * f * GB) / 7)));
|
||||
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). */
|
||||
const demo = { events: [], people: new Map(), days: [], now: 0 };
|
||||
|
||||
/**
|
||||
* 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` : '',
|
||||
};
|
||||
});
|
||||
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.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)),
|
||||
},
|
||||
],
|
||||
};
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user