Dawnline 0.4.0
Build packages / Version (push) Waiting to run

- Components tab replaces Updates: Dawnline, the AmneziaWG build for this
  firmware (Slava-Shchipunov 2.0 or 2Grey 3.1, Russian translation) and
  the system packages Dawnline adds, each checked, installed, reinstalled
  or rolled back in place, with What's new, versions and an activity log
- Automatic updates: daily check, install at a set time or right away,
  per component; AmneziaWG is left out by default and an automatic run
  never switches its build or generation
- Downloads verified against GitHub's sha256; mirrors are used only when
  GitHub is unreachable and the hash is known
- New installer: checks firmware, clock, space and DNS, lets you pick a
  release, shows the plan and asks first; --dry-run
- New uninstaller removes everything Dawnline added (cron, nft, firewall,
  routing, interfaces, packages it installed); --dry-run
- Works without AmneziaWG on the router: Overview, the setup wizard,
  Health and Components say what is missing and offer to install it
- Overview shows failed health checks as notices with their fix
- People list no longer reads the config from the browser: private keys
  stay on the router; personal links are fetched on demand
- Config changes are serialized under one lock, the nft table loads
  atomically and fails closed, and Dawnline never touches network
  sections it did not create
- The portal never opens system ports, keeps disabled devices disabled,
  rate-limits per address and counts days by the router's clock
- Settings and Diagnostics load their heavy parts in the background
- Release notes are written from the commits since the previous release
- Backend and admin UI split into small single-purpose modules
This commit is contained in:
Aemeath committed 2026-10-16 02:14:15 +03:00
1 parent 70a932b8ea
commit 34293fb8e5
158 files changed
+17418 -10022

No files matched your search

@@ -0,0 +1,150 @@
// Dawnline rpcd methods: the Settings page (the portal, defaults, logs and
// history, updates). What may be saved is dawnline.schema's.
import { stat } from 'fs';
import { q, sh_out, admin_log, RUN_DIR, DATA_DIR } from 'dawnline.util';
import * as core from 'dawnline.core';
import * as live from 'dawnline.live';
import * as apply from 'dawnline.apply';
import * as geo from 'dawnline.geo';
import * as store from 'dawnline.store';
import * as schema from 'dawnline.schema';
import * as health from 'dawnline.health';
import * as pc from 'dawnline.portalcert';
import { wrap, check_portal } from 'dawnline.rpc.common';
/** The portal's own checks from Health, shown next to its settings. */
const PORTAL_CHECKS = [ 'portal', 'portal_dns', 'portal_reply', 'portal_http', 'cert' ];
function file_size(path) {
return stat(path)?.size ?? 0;
}
/** What the log and traffic history hold right now (Settings → Logs & history). */
function logs_info(m) {
let ev = live.load_events();
let by = {};
for (let cat in live.CATEGORIES)
by[cat] = 0;
for (let e in ev)
by[live.category_of(e.type)]++;
let usage = core.load_usage();
let days = {};
for (let grp in [ usage?.devices ?? {}, usage?.people ?? {} ])
for (let id, rec in grp)
for (let k in keys(rec.days ?? {}))
days[k] = true;
let dk = sort(keys(days));
return {
policy: live.policy(m.settings.retention),
events: length(ev),
oldest: length(ev) ? ev[0].ts : 0,
by_category: by,
log_ram: file_size(`${RUN_DIR}/events.json`),
log_flash: file_size(`${DATA_DIR}/events.json`),
usage_flash: file_size(`${DATA_DIR}/usage.json`),
usage_since: length(dk) ? dk[0] : '',
usage_days: length(dk),
geo_flash: file_size(`${DATA_DIR}/geo.json`),
};
}
function settings_get(a) {
let c = core.open_cursor();
let raw = c.get_all(core.CONFIG, 'settings') ?? {};
let m = core.load(c);
let out = {};
for (let k in keys(schema.SETTINGS))
out[k] = raw[k] ?? '';
out.log_category = live.policy(m.settings.retention).categories;
let cert = m.settings.portal_enabled ? pc.portal_cert(m.settings) : null;
return {
settings: out,
needs: health.needs(),
effective: m.settings,
services: values(m.services),
cert: cert ? { path: cert.cert, self_signed: cert.self_signed,
expires: sh_out(`openssl x509 -enddate -noout -in ${q(cert.cert)} 2>/dev/null | cut -d= -f2`) } : null,
port_owners: m.settings.portal_enabled ? [] : health.tcp_port_owners(m.settings.portal_port),
portal_public_port: core.portal_public_port(m),
geo_cached: length(keys(geo.load().ips)),
logs: logs_info(m),
};
}
/*
* The slow part of the portal settings (DNS lookups and the Health checks),
* fetched after the page shows.
*/
function portal_info(a) {
let m = core.load();
return {
candidates: pc.portal_candidates(m),
checks: filter(health.health(m), (x) => index(PORTAL_CHECKS, x.id) >= 0),
};
}
function same(a, b) {
return (type(a) == 'array' ? join('\n', a) : a ?? '') == (type(b) == 'array' ? join('\n', b) : b ?? '');
}
/** Save settings (`values`: key → value, '' back to the default); the portal is checked as it will be. */
function settings_update(a) {
let v = a.values ?? {};
if (type(v) != 'object')
die('Nothing to save.');
let res = store.transact((c, m) => {
let restart = false;
c.set(core.CONFIG, 'settings', 'settings');
for (let k, val in v) {
if (k == 'log_category') {
let lst = filter(type(val) == 'array' ? val : [], (x) => index(live.CATEGORIES, x) >= 0);
c.set(core.CONFIG, 'settings', 'log_category', length(lst) ? lst : [ '' ]);
// Superseded by the category list.
c.delete(core.CONFIG, 'settings', 'log_connections');
continue;
}
let nv = schema.validate(k, val);
if (schema.SETTINGS[k].restart && !same(nv, c.get(core.CONFIG, 'settings', k)))
restart = true;
if (nv == null)
c.delete(core.CONFIG, 'settings', k);
else
c.set(core.CONFIG, 'settings', k, nv);
}
check_portal(core.load(c), m);
return { restart, was: m.settings };
});
if (res.restart)
system('/etc/init.d/dawnline reload >/dev/null 2>&1');
else
apply.sync();
// The changes worth a line: the portal and the watchdog (other settings are housekeeping).
let now = core.load().settings, was = res.was;
if (now.portal_enabled != was.portal_enabled)
admin_log('portal', now.portal_enabled ? 'turned on' : 'turned off', null, 'the personal portal', now.portal_enabled ? `port ${now.portal_port}` : null);
else if (now.portal_enabled) {
let what = [];
if (now.portal_port != was.portal_port)
push(what, `port ${now.portal_port}`);
if (now.portal_host != was.portal_host)
push(what, `address ${now.portal_host}`);
if (join(' ', now.portal_alt) != join(' ', was.portal_alt))
push(what, 'other addresses');
if (now.portal_cert != was.portal_cert || now.portal_key != was.portal_key)
push(what, 'certificate');
if (now.portal_redirect != was.portal_redirect)
push(what, 'redirect');
if (length(what))
admin_log('portal', 'changed', null, 'the personal portal', join(', ', what));
}
if (now.watchdog != was.watchdog)
admin_log('dawnline', now.watchdog ? 'turned on' : 'turned off', null, 'the watchdog', now.watchdog ? null : 'problems are only logged, nothing is repaired');
return settings_get({});
}
export const methods = {
settings_get: { call: wrap(settings_get) },
portal_info: { call: wrap(portal_info) },
settings_update: { args: { values: {} }, call: wrap(settings_update) },
};