Dawnline 0.7.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
- Balanced, a new disguise for AmneziaWG 2.0 apps (AmneziaVPN 4.8.12 and newer): junk packets, padded cookie and data packets and DNS-shaped signature packets, for networks that learned to spot 1.0-style junk; offered when both the tools and the kernel module are 2.0 or newer - The junk count and sizes in a device's configuration are the device's own (shifted a little, deterministically), so two phones of one family do not share one profile; they never require importing again - Components remembers which AmneziaWG build was installed on which kernel; after a firmware upgrade Health says the build was for the old one and offers the build for the new firmware. A SNAPSHOT firmware is told there are no builds for it - Location lookups moved off the agent's 1-second watcher to its minute tick, a few per minute within a time budget; the cache lives in tmpfs and goes to flash hourly, and addresses still shown on the map are never pushed out of it (and looked up again) - The map library from the CDN is checked against its expected hash before it runs inside the LuCI page - The activity log is copied to flash only when something was logged; the person page and the device drawer fetch only that person's events - Admin UI: live updates survive the theme's in-page navigation, pollers stop with their page and sleep while the tab is hidden, the map is freed when leaving the Overview, a router that stops answering is said once (and when it is back), and an update of Dawnline under an open page asks for a reload - Watchdog: no repairs while an update runs; a target that keeps failing keeps its back-off (repairs are forgotten after ten good minutes, not one); the LuCI link is reloaded or restarted three times at most, not every hour for good; the one-click "ifup" fix accepts only Dawnline's own tunnels - Health warns when the router's flash is nearly full (settings would stop saving); the portal runs two processes instead of four on routers with little memory - "Remove their devices" at an end date is never done on a clock that has not been set yet
This commit is contained in:
1 parent
31a2065f05
commit
fd9543ce68
30 files changed
+411
-117
No files matched your search
@@ -11,6 +11,8 @@
|
||||
|
||||
path="${REQUEST_URI%%\?*}"
|
||||
w='[a-z][a-z][a-z][a-z][a-z][a-z]'
|
||||
# The expansion is meant as a pattern (a word of six letters), not literally.
|
||||
# shellcheck disable=SC2254
|
||||
case "$path" in
|
||||
/$w-$w-$w|/$w-$w-$w/*) exec /usr/bin/ucode /usr/share/dawnline/portal/cgi.uc ;;
|
||||
esac
|
||||
|
||||
@@ -247,12 +247,12 @@ export function obf_preset(name) {
|
||||
};
|
||||
if (name == 'off')
|
||||
return { jc: '0', jmin: '0', jmax: '0', s1: '0', s2: '0', h1: '1', h2: '2', h3: '3', h4: '4' };
|
||||
let strong = name == 'strong';
|
||||
let strong = name == 'strong', balanced = name == 'balanced';
|
||||
let o = {};
|
||||
o.jc = `${strong ? rand_int(6, 10) : rand_int(3, 6)}`;
|
||||
let jmin = rand_int(64, strong ? 128 : 96);
|
||||
o.jc = `${strong ? rand_int(6, 10) : balanced ? rand_int(4, 8) : rand_int(3, 6)}`;
|
||||
let jmin = rand_int(64, strong || balanced ? 128 : 96);
|
||||
o.jmin = `${jmin}`;
|
||||
o.jmax = `${jmin + rand_int(strong ? 200 : 32, strong ? 600 : 160)}`;
|
||||
o.jmax = `${jmin + rand_int(strong ? 200 : balanced ? 150 : 32, strong ? 600 : balanced ? 400 : 160)}`;
|
||||
let s1 = rand_int(15, 64), s2 = rand_int(15, 64);
|
||||
while (s1 + 56 == s2)
|
||||
s2 = rand_int(15, 64);
|
||||
@@ -261,9 +261,19 @@ export function obf_preset(name) {
|
||||
let used = {};
|
||||
for (let k in [ 'h1', 'h2', 'h3', 'h4' ])
|
||||
o[k] = rand_h(used);
|
||||
if (balanced) {
|
||||
// AmneziaWG 2.0: padded cookie and data packets (S4 costs MTU, kept
|
||||
// small: core.tunnel_mtu) and DNS-shaped signature packets before each
|
||||
// handshake — what 1.0 traffic lacks and gets recognised by.
|
||||
o.s3 = `${rand_int(8, 48)}`;
|
||||
o.s4 = `${rand_int(4, 16)}`;
|
||||
o.i1 = dns_query();
|
||||
o.i2 = dns_answer();
|
||||
}
|
||||
return o;
|
||||
};
|
||||
|
||||
|
||||
export function obf_errors(o) {
|
||||
let errs = [];
|
||||
for (let k, r in OBF_SPEC) {
|
||||
@@ -345,6 +355,37 @@ function conf_filename(m, p, dev) {
|
||||
return label(dev) + '.conf';
|
||||
}
|
||||
|
||||
/**
|
||||
* The junk a device sends is its own: within the preset's own ranges, the
|
||||
* count and sizes are shifted a little by the device (deterministic, so the
|
||||
* configuration keeps its fingerprint), so two phones of one family do not
|
||||
* share one profile. Server-side values (headers, padding sizes, the header
|
||||
* protection key) stay the server's.
|
||||
*/
|
||||
function client_obf(srv, dev) {
|
||||
let o = { ...srv.obf };
|
||||
if (obf_neutral(o) || !(+o.jc > 0))
|
||||
return o;
|
||||
let key = `${srv.id}/${dev.id}/${srv.obf.h1 ?? ''}`;
|
||||
let seed = 2166136261;
|
||||
for (let i = 0; i < length(key); i++)
|
||||
seed = ((seed ^ ord(key, i)) * 16777619) & 0x7fffffff;
|
||||
let pick = (n) => {
|
||||
seed = (seed * 1103515245 + 12345) & 0x7fffffff;
|
||||
return seed % n;
|
||||
};
|
||||
let jc = +o.jc, jmin = +o.jmin, jmax = +o.jmax;
|
||||
o.jc = `${max(1, min(10, jc + pick(3) - 1))}`;
|
||||
if (jmax > jmin + 32) {
|
||||
let d = pick(17);
|
||||
o.jmin = `${jmin + d}`;
|
||||
o.jmax = `${jmax - pick(17)}`;
|
||||
if (+o.jmax <= +o.jmin)
|
||||
o.jmax = `${+o.jmin + 32}`;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
export function client_config(m, dev) {
|
||||
let p = m.people[dev.person];
|
||||
let srv = p ? m.servers[p.server] : null;
|
||||
@@ -363,10 +404,11 @@ export function client_config(m, dev) {
|
||||
push(lines, `MTU = ${mtu}`);
|
||||
// "Off" is plain WireGuard: neutral values (no junk, H1-H4 = 1-4) are left
|
||||
// out, so any WireGuard app accepts the file.
|
||||
if (!obf_neutral(srv.obf))
|
||||
let obf = client_obf(srv, dev);
|
||||
if (!obf_neutral(obf))
|
||||
for (let k in core.OBF_KEYS)
|
||||
if (srv.obf[k] != null && srv.obf[k] != '')
|
||||
push(lines, `${OBF_CONF[k]} = ${srv.obf[k]}`);
|
||||
if (obf[k] != null && obf[k] != '')
|
||||
push(lines, `${OBF_CONF[k]} = ${obf[k]}`);
|
||||
push(lines, '', '[Peer]');
|
||||
push(lines, `PublicKey = ${srv.public_key}`);
|
||||
if (dev.preshared_key)
|
||||
@@ -396,7 +438,7 @@ export function client_config(m, dev) {
|
||||
psk_key: dev.preshared_key,
|
||||
server_pub_key: srv.public_key,
|
||||
persistent_keep_alive: `${srv.keepalive}`,
|
||||
obfuscation: srv.obf,
|
||||
obfuscation: obf,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -578,10 +620,15 @@ function fnv32(str) {
|
||||
return sprintf('%08x', h);
|
||||
}
|
||||
|
||||
/** What a device holds, minus its private key: changes when it must import again. */
|
||||
/**
|
||||
* What a device holds, minus its private key: changes when it must import
|
||||
* again. The junk count and sizes (Jc, Jmin, Jmax) are the device's own and
|
||||
* never have to match the server, so they are left out: a change there is
|
||||
* no reason to import again.
|
||||
*/
|
||||
export function config_fingerprint(m, dev) {
|
||||
let c = dev ? client_config(m, dev) : null;
|
||||
return c ? fnv32(join('\n', filter(split(c.conf, '\n'), (l) => !match(l, /^PrivateKey/)))) : null;
|
||||
return c ? fnv32(join('\n', filter(split(c.conf, '\n'), (l) => !match(l, /^(PrivateKey|Jc|Jmin|Jmax) /)))) : null;
|
||||
};
|
||||
|
||||
/** Device id → fingerprint of the configuration last shown or downloaded. */
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import { readfile } from 'fs';
|
||||
import { connect } from 'ubus';
|
||||
import { ensure_dir, read_json, write_json, DATA_DIR } from 'dawnline.util';
|
||||
import * as pkg from 'dawnline.pkg';
|
||||
|
||||
export const SOURCES = {
|
||||
@@ -28,7 +29,36 @@ export function firmware() {
|
||||
let arch = rel.arch ?? match(readfile('/etc/openwrt_release') ?? '', /DISTRIB_ARCH='([^']*)'/)?.[1];
|
||||
if (!rel.version || length(target) != 2 || !arch)
|
||||
return null;
|
||||
return { tag: `v${rel.version}`, postfix: `_v${rel.version}_${arch}_${target[0]}_${target[1]}`, ext: pkg.ext() };
|
||||
return { tag: `v${rel.version}`, postfix: `_v${rel.version}_${arch}_${target[0]}_${target[1]}`, ext: pkg.ext(),
|
||||
snapshot: match(rel.version, /SNAPSHOT/) != null };
|
||||
};
|
||||
|
||||
/** What was installed, for whom: /etc/dawnline/awg.json (survives a sysupgrade with the data). */
|
||||
export const RECORD = `${DATA_DIR}/awg.json`;
|
||||
|
||||
/**
|
||||
* Remember which build was installed on which kernel. After a firmware
|
||||
* upgrade the module is gone (it was built for that kernel): Health can then
|
||||
* say so and offer the build for the new one (dawnline.health).
|
||||
*/
|
||||
export function record(source, tag, packages) {
|
||||
ensure_dir(DATA_DIR, 0o700);
|
||||
write_json(RECORD, {
|
||||
osrelease: trim(readfile('/proc/sys/kernel/osrelease') ?? ''),
|
||||
source, tag, packages, installed: time(),
|
||||
}, 0o600);
|
||||
};
|
||||
|
||||
/**
|
||||
* The firmware the recorded AmneziaWG build was for, when it is not this one
|
||||
* (and the module is gone): { was, now, tag, source }, else null.
|
||||
*/
|
||||
export function kernel_changed() {
|
||||
let r = read_json(RECORD, null);
|
||||
let now = trim(readfile('/proc/sys/kernel/osrelease') ?? '');
|
||||
if (!r?.osrelease || r.osrelease == now)
|
||||
return null;
|
||||
return { was: r.osrelease, now, tag: r.tag, source: r.source };
|
||||
};
|
||||
|
||||
/** The file name of a package in a build. */
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
// Dawnline — city-level locations for the admin map.
|
||||
//
|
||||
// Client addresses are looked up once with a third-party service (ipwho.is,
|
||||
// ipapi.co as fallback) and cached in DATA_DIR/geo.json. Only the agent
|
||||
// performs lookups, a few per minute at most; the UI reads the cache.
|
||||
// ipapi.co as fallback) and cached: the live copy in RUN_DIR (tmpfs), put on
|
||||
// flash (DATA_DIR/geo.json) by flush() about hourly, like the usage
|
||||
// counters. Only the agent performs lookups, on its minute tick and within a
|
||||
// time budget, never on the 1-second watcher; the UI reads the cache.
|
||||
|
||||
import { read_json, write_json, sh_out, q, ensure_dir, ip2int, DATA_DIR } from 'dawnline.util';
|
||||
import { stat } from 'fs';
|
||||
import { read_json, write_json, sh_out, q, ensure_dir, ip2int, DATA_DIR, RUN_DIR } from 'dawnline.util';
|
||||
|
||||
const CACHE = `${DATA_DIR}/geo.json`;
|
||||
const CACHE = `${RUN_DIR}/geo.json`;
|
||||
const SAVED = `${DATA_DIR}/geo.json`;
|
||||
const TTL = 30 * 86400;
|
||||
const RETRY = 86400;
|
||||
// Entries kept at least; addresses still shown are never pushed out (resolve).
|
||||
const CAP = 500;
|
||||
|
||||
// [base, prefix] of ranges with no meaningful location (private, CGNAT, multicast, …).
|
||||
const PRIVATE4 = map([ [ '0.0.0.0', 8 ], [ '10.0.0.0', 8 ], [ '100.64.0.0', 10 ], [ '127.0.0.0', 8 ], [ '169.254.0.0', 16 ],
|
||||
@@ -30,16 +36,30 @@ export function is_public(ip) {
|
||||
};
|
||||
|
||||
export function load() {
|
||||
return read_json(CACHE, null) ?? { ips: {}, home: null };
|
||||
return read_json(CACHE, null) ?? read_json(SAVED, null) ?? { ips: {}, home: null };
|
||||
};
|
||||
|
||||
/** The live copy (tmpfs); flush() puts it on flash. */
|
||||
export function save(cache) {
|
||||
ensure_dir(DATA_DIR, 0o700);
|
||||
ensure_dir(RUN_DIR);
|
||||
write_json(CACHE, cache, 0o600);
|
||||
};
|
||||
|
||||
/** Copy the live cache to flash when it is newer (the agent, about hourly and on a clean stop). */
|
||||
export function flush() {
|
||||
let live = stat(CACHE);
|
||||
if (!live || live.mtime <= (stat(SAVED)?.mtime ?? 0))
|
||||
return false;
|
||||
let c = read_json(CACHE, null);
|
||||
if (!c)
|
||||
return false;
|
||||
ensure_dir(DATA_DIR, 0o700);
|
||||
write_json(SAVED, c, 0o600);
|
||||
return true;
|
||||
};
|
||||
|
||||
function fetch_json(url) {
|
||||
let out = sh_out(`uclient-fetch -q -T 8 -O - ${q(url)}`);
|
||||
let out = sh_out(`uclient-fetch -q -T 5 -O - ${q(url)}`);
|
||||
if (!out)
|
||||
return null;
|
||||
try {
|
||||
@@ -79,13 +99,17 @@ export function lookup(provider, ip) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve up to `max` addresses that are missing or stale. Returns true when
|
||||
* the cache changed (the caller saves it).
|
||||
* Resolve up to `max` of `ips` that are missing or stale, within `budget`
|
||||
* seconds (each lookup may wait on the network). Returns true when the cache
|
||||
* changed (the caller saves it). `ips` is also what is still shown: the cache
|
||||
* is kept bounded by dropping other entries only, oldest first, so a lookup
|
||||
* is never repeated for an address that is still on the map.
|
||||
*/
|
||||
export function resolve(settings, cache, ips, max) {
|
||||
export function resolve(settings, cache, ips, max, budget) {
|
||||
let now = time(), changed = false, done = 0;
|
||||
let started = now;
|
||||
for (let ip in ips) {
|
||||
if (done >= max)
|
||||
if (done >= max || (budget != null && time() - started >= budget))
|
||||
break;
|
||||
if (!is_public(ip))
|
||||
continue;
|
||||
@@ -103,12 +127,17 @@ export function resolve(settings, cache, ips, max) {
|
||||
else
|
||||
cache.ips[ip] = { fail: now };
|
||||
}
|
||||
// Keep the cache bounded: drop the oldest entries beyond 500.
|
||||
let shown = {};
|
||||
for (let ip in ips)
|
||||
shown[ip] = true;
|
||||
let all = keys(cache.ips);
|
||||
if (length(all) > 500) {
|
||||
all = sort(all, (a, b) => (cache.ips[a].ts ?? cache.ips[a].fail ?? 0) - (cache.ips[b].ts ?? cache.ips[b].fail ?? 0));
|
||||
for (let i = 0; i < length(all) - 500; i++)
|
||||
delete cache.ips[all[i]];
|
||||
if (length(all) > CAP) {
|
||||
let other = sort(filter(all, (ip) => !shown[ip]),
|
||||
(a, b) => (cache.ips[a].ts ?? cache.ips[a].fail ?? 0) - (cache.ips[b].ts ?? cache.ips[b].fail ?? 0));
|
||||
for (let i = 0; i < length(all) - CAP && i < length(other); i++) {
|
||||
delete cache.ips[other[i]];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
};
|
||||
@@ -132,4 +161,6 @@ export function place(cache, ip) {
|
||||
|
||||
export function clear() {
|
||||
save({ ips: {}, home: null });
|
||||
ensure_dir(DATA_DIR, 0o700);
|
||||
write_json(SAVED, { ips: {}, home: null }, 0o600);
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import * as fw from 'dawnline.fw';
|
||||
import * as loop from 'dawnline.loop';
|
||||
import * as net from 'dawnline.net';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as builds from 'dawnline.awg_builds';
|
||||
import * as lookup from 'dawnline.lookup';
|
||||
import * as pc from 'dawnline.portalcert';
|
||||
|
||||
@@ -253,13 +254,27 @@ function endpoint_check(id, title, srv, host, proto_note) {
|
||||
|
||||
const NO_PROTO = "netifd doesn't know the amneziawg protocol (AmneziaWG missing, or the network wasn't restarted after installing it).";
|
||||
|
||||
/** Free space on the overlay in KB (null when unknown). */
|
||||
function overlay_free_kb() {
|
||||
let out = sh('df -Pk /overlay 2>/dev/null || df -Pk / 2>/dev/null').out;
|
||||
let m = match(out ?? '', /\n\S+\s+[0-9]+\s+[0-9]+\s+([0-9]+)\s/);
|
||||
return m ? +m[1] : null;
|
||||
}
|
||||
|
||||
/** Is AmneziaWG there and usable: packages, kernel module, netifd's protocol handler. */
|
||||
function awg_check() {
|
||||
let st = awg.load();
|
||||
let title = 'AmneziaWG installed';
|
||||
if (length(st.missing ?? []))
|
||||
if (length(st.missing ?? [])) {
|
||||
// The module was built for the kernel of the firmware it was installed on.
|
||||
let kc = builds.kernel_changed();
|
||||
if (kc && index(st.missing, 'kmod-amneziawg') >= 0)
|
||||
return check('awg', title, 'error',
|
||||
`The firmware changed (kernel ${kc.was} → ${kc.now}): the AmneziaWG build installed for it is gone. Install the build for this firmware.`,
|
||||
'install:awg', 'AmneziaWG needs a build for the new firmware');
|
||||
return check('awg', title, 'error', `${join(' and ', st.missing)} ${length(st.missing) == 1 ? 'is' : 'are'} missing.`, 'install:awg',
|
||||
'AmneziaWG isn’t installed');
|
||||
}
|
||||
if (!st.loaded) {
|
||||
// load() tried it: the second modprobe only repeats why.
|
||||
let why = trim(sh('modprobe amneziawg 2>&1; dmesg | grep -i amneziawg | tail -n 3').out);
|
||||
@@ -396,6 +411,15 @@ export function health(m) {
|
||||
push(out, check('agent', 'Background agent running', agent ? 'ok' : 'error',
|
||||
'Counts traffic and enforces end dates and quotas.', agent ? null : 'restart'));
|
||||
|
||||
// A full overlay fails every config write on the router, Dawnline's and
|
||||
// OpenWrt's own; backups and history are what Dawnline adds to it.
|
||||
let free = overlay_free_kb();
|
||||
if (free != null)
|
||||
push(out, check('flash', 'Free space on the router', free < 512 ? 'error' : free < 2048 ? 'warn' : 'ok',
|
||||
free < 2048 ? `${int(free / 1024 * 10) / 10} MB free: settings may stop saving. Remove old backups (Settings → Backups) or shorten the history.`
|
||||
: `${int(free / 1024)} MB free on the overlay.`,
|
||||
null, 'The router is running out of flash'));
|
||||
|
||||
if (!length(m.servers)) {
|
||||
push(out, check('server', 'Server configured', 'warn', 'Run the setup wizard on the Server tab.'));
|
||||
return out;
|
||||
@@ -472,6 +496,10 @@ export function fix(id) {
|
||||
}
|
||||
let m = match(id ?? '', /^ifup:([a-z][a-z0-9_]{0,11})$/);
|
||||
if (m) {
|
||||
// Only Dawnline's own tunnels: never another interface of the router.
|
||||
let mine = filter(values(core.load().servers), (s) => s.ifname == m[1] && s.private_key);
|
||||
if (!length(mine))
|
||||
die(`${m[1]} is not one of Dawnline's tunnels.`);
|
||||
system(`ifup ${q(m[1])}`);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -403,6 +403,10 @@ export function persist_events(pol) {
|
||||
unlink(`${DATA_DIR}/events.json`);
|
||||
return;
|
||||
}
|
||||
// Only when something was logged since the last copy: flash is written rarely.
|
||||
let live_st = stat(`${RUN_DIR}/events.json`);
|
||||
if (!live_st || live_st.mtime <= (stat(`${DATA_DIR}/events.json`)?.mtime ?? 0))
|
||||
return;
|
||||
let ev = read_json(`${RUN_DIR}/events.json`, null);
|
||||
if (ev != null) {
|
||||
ensure_dir(DATA_DIR, 0o700);
|
||||
|
||||
@@ -34,16 +34,21 @@ export function clamp_days(v) {
|
||||
return n >= 1 ? (n > 400 ? 400 : int(n)) : 30;
|
||||
};
|
||||
|
||||
export const METHODS = [ 'off', 'standard', 'strong', 'max' ];
|
||||
export const METHODS = [ 'off', 'standard', 'strong', 'balanced', 'max' ];
|
||||
|
||||
/** A disguise method the installed AmneziaWG can run. */
|
||||
export function check_method(name) {
|
||||
if (index(METHODS, name) < 0)
|
||||
die('Unknown disguise method.');
|
||||
if (name == 'max' && !awg.caps().v3)
|
||||
let c = awg.caps();
|
||||
if (name == 'max' && !c.v3)
|
||||
die(awg.installed()
|
||||
? 'Maximum needs AmneziaWG 3.1 on the router (kmod-amneziawg, amneziawg-tools 3.1): install a 3.1 build in Dawnline → Components.'
|
||||
: 'AmneziaWG is not installed: install it in Dawnline → Components, then choose Maximum.');
|
||||
if (name == 'balanced' && !c.v2)
|
||||
die(awg.installed()
|
||||
? 'Balanced needs AmneziaWG 2.0 or newer on the router: install a current build in Dawnline → Components.'
|
||||
: 'AmneziaWG is not installed: install it in Dawnline → Components, then choose Balanced.');
|
||||
return name;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as net from 'dawnline.net';
|
||||
import * as loop from 'dawnline.loop';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as lookup from 'dawnline.lookup';
|
||||
import { wrap, clamp_days } from 'dawnline.rpc.common';
|
||||
import { wrap, str, clamp_days } from 'dawnline.rpc.common';
|
||||
|
||||
/** Router location plus one point per (device, recent client address). */
|
||||
function geo_view(m, usage, dmp) {
|
||||
@@ -172,9 +172,12 @@ function status(a) {
|
||||
};
|
||||
}
|
||||
|
||||
/** The newest `limit` events; `person` keeps one person's only, `since` only those after a time. */
|
||||
function events_list(a) {
|
||||
// Tunnel down/up events of older versions: the service log tells it better (names, reasons).
|
||||
let ev = filter(live.load_events(), (e) => e.type != 'server_down' && e.type != 'server_up');
|
||||
let person = str(a.person), since = +a.since || 0;
|
||||
let ev = filter(live.load_events(), (e) => e.type != 'server_down' && e.type != 'server_up' &&
|
||||
(!person || e.person == person) && (!since || (e.ts ?? 0) > since));
|
||||
let n = +a.limit || 300;
|
||||
return { events: with_hosts(slice(ev, length(ev) > n ? length(ev) - n : 0)), total: length(ev), policy: live.policy() };
|
||||
}
|
||||
@@ -239,14 +242,15 @@ function usage_clear(a) {
|
||||
}
|
||||
|
||||
/** The live revision (dawnline.live.PRESENCE): pages refresh when it moves; 0 without the agent. */
|
||||
/** The live revision, and the version answering (a page notices an update under it). */
|
||||
function rev() {
|
||||
return { rev: +(live.presence()?.rev ?? 0) };
|
||||
return { rev: +(live.presence()?.rev ?? 0), version: VERSION };
|
||||
}
|
||||
|
||||
export const methods = {
|
||||
rev: { call: wrap(rev) },
|
||||
status: { args: { days: 30 }, call: wrap(status) },
|
||||
events: { args: { limit: 300 }, call: wrap(events_list) },
|
||||
events: { args: { limit: 300, person: '', since: 0 }, call: wrap(events_list) },
|
||||
logs_clear: { args: { person: '', device: '', category: '', older_days: '' }, call: wrap(logs_clear) },
|
||||
usage_clear: { args: { scope: '', id: '' }, call: wrap(usage_clear) },
|
||||
geo_clear: { call: wrap((a) => { geo.clear(); return { ok: true }; }) },
|
||||
|
||||
@@ -52,6 +52,9 @@ export function check(ctx) {
|
||||
if (!fw)
|
||||
return { installed: cur, gen: builds.gen(cur), packages: installed, current: null, ru, sources: {}, update: false, status: '',
|
||||
note: 'Cannot detect the firmware target' };
|
||||
if (fw.snapshot)
|
||||
return { installed: cur, gen: builds.gen(cur), packages: installed, current: null, ru, sources: {}, update: false, status: '',
|
||||
note: 'This is a SNAPSHOT firmware: the AmneziaWG projects publish builds for releases only' };
|
||||
let dir = `${ctx.work}/check`;
|
||||
system(`mkdir -p '${dir}'`);
|
||||
let sources = {};
|
||||
@@ -233,5 +236,6 @@ export function install(ctx, arg) {
|
||||
pkg.remove([ builds.RU ], ctx.log);
|
||||
out.after = builds.installed();
|
||||
settle(ctx, before, out.after);
|
||||
builds.record(id, fw.tag, out.after);
|
||||
return out;
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
|
||||
|
||||
export const VERSION = '0.6.0';
|
||||
export const VERSION = '0.7.0';
|
||||
/** GitHub repository with Dawnline releases (updates and the installer). */
|
||||
export const REPO = 'tickcount/luci-app-dawnline';
|
||||
export const RUN_DIR = '/var/run/dawnline';
|
||||
|
||||
@@ -12,12 +12,16 @@ import * as health from 'dawnline.health';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as nft from 'dawnline.nft';
|
||||
import * as netifd from 'dawnline.netifd';
|
||||
import * as upd from 'dawnline.updates';
|
||||
|
||||
export const STATE = `${RUN_DIR}/watchdog.json`;
|
||||
/** The agent writes the time here on every tick. */
|
||||
export const BEAT = `${RUN_DIR}/agent.beat`;
|
||||
// Seconds before the next repair, by the number of repairs so far.
|
||||
const WAIT = [ 0, 120, 600, 1800, 3600 ];
|
||||
// Good minutes in a row before a repaired target's count of repairs is
|
||||
// forgotten: one good minute between two failures is still flapping.
|
||||
const SETTLED = 10;
|
||||
|
||||
/** Why a tunnel is down (AmneziaWG; kept here for older callers). */
|
||||
export function iface_errors(ifname) {
|
||||
@@ -77,8 +81,10 @@ function probes(m) {
|
||||
id: 'rpc', src: 'dawnline', name: 'LuCI link', who: 'LuCI', ok: system('ubus list luci.dawnline >/dev/null 2>&1') == 0,
|
||||
problem: "can't reach Dawnline (luci.dawnline is missing in rpcd)", back: 'reaches Dawnline again',
|
||||
detail: () => sh_out('logread -l 400 2>/dev/null | grep rpcd | tail -n 4'),
|
||||
// A reload keeps LuCI logins; a restart (second try) signs everyone out.
|
||||
repair: { what: 'reloading rpcd', run: (n) => system(n > 1 ? '/etc/init.d/rpcd restart >/dev/null 2>&1' : '/etc/init.d/rpcd reload >/dev/null 2>&1') },
|
||||
// A reload keeps LuCI logins; a restart (second try) signs everyone out —
|
||||
// and after three it stops: restarting rpcd every hour for good would
|
||||
// sign every admin out for good.
|
||||
repair: { what: 'reloading rpcd', max: 3, run: (n) => system(n > 1 ? '/etc/init.d/rpcd restart >/dev/null 2>&1' : '/etc/init.d/rpcd reload >/dev/null 2>&1') },
|
||||
});
|
||||
return out;
|
||||
}
|
||||
@@ -87,6 +93,9 @@ function probes(m) {
|
||||
export function run(m) {
|
||||
let now = time();
|
||||
let fix = m.settings.watchdog;
|
||||
// An update is replacing packages or restarting tunnels: what looks broken
|
||||
// meanwhile is being worked on; repairs would only get in its way.
|
||||
let busy = upd.busy();
|
||||
let st = read_json(STATE, {});
|
||||
let t = type(st.targets) == 'object' ? st.targets : {};
|
||||
let repairs = filter(st.repairs ?? [], (r) => now - r.ts < 86400);
|
||||
@@ -100,16 +109,30 @@ export function run(m) {
|
||||
if (x.reported)
|
||||
slog(p.src, 'up', p.back + (x.stuck ? ' · restored' : x.tries ? ` (after ${x.tries} repair${x.tries > 1 ? 's' : ''})` : ''), null, p.who);
|
||||
x.bad = 0;
|
||||
x.tries = 0;
|
||||
x.next = 0;
|
||||
x.reported = false;
|
||||
x.stuck = false;
|
||||
// The repairs so far are forgotten only once it has stayed up a while:
|
||||
// a target that fails every other minute keeps its back-off.
|
||||
x.good = (x.good ?? 0) + 1;
|
||||
if (x.good >= SETTLED) {
|
||||
x.tries = 0;
|
||||
x.good = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
x.good = 0;
|
||||
// One bad minute can be a restart in progress.
|
||||
if (++x.bad < 2)
|
||||
continue;
|
||||
if (!fix || !p.repair) {
|
||||
if (busy)
|
||||
continue;
|
||||
if (p.repair?.max && x.tries >= p.repair.max && !x.reported) {
|
||||
slog(p.src, 'error', `${p.problem} — not repaired again (${p.repair.max} repairs didn't help)`, p.detail?.(), p.who);
|
||||
x.reported = true;
|
||||
continue;
|
||||
}
|
||||
if (!fix || !p.repair || (p.repair.max && x.tries >= p.repair.max)) {
|
||||
if (!x.reported)
|
||||
slog(p.src, 'error', p.problem, p.detail?.(), p.who);
|
||||
x.reported = true;
|
||||
|
||||
Reference in new issue
Block a user