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
- A device is renamed where its name stands on its card: a click on the
name, Return or Space on it, or Rename in the ⋯ menu turns it into a
field with the name selected. Return saves, and the words shimmer until
the router answers. Esc or a click elsewhere puts the old name back. The
rename window is gone, and the page no longer redraws under a name being
edited
- Device names take up to 20 characters: letters of any language, digits,
spaces and - _ . The router refuses anything else when a device is added
or renamed, so a name can't carry symbols into configurations, file
names or the AmneziaVPN key. The portal and the admin turn a character
like that away as it is typed: the field shakes, its outline goes red
and a short line says why. Suggested names (a phone's model, "Phone 2")
are stripped of such characters and cut to fit. Names set before this
stay as they are
- LAN Bypass: Add a device, in the portal and in the admin, has a switch
that keeps the device's own local network (printer, TV, NAS) reachable
while it is connected. It is off by default and stays as chosen; the
admin's device drawer shows it. With home and internet access the switch
says which addresses still lead to the home network
- Health warns when a server's home network is on one of the subnets home
routers come with (192.168.0.x, 192.168.1.x and others). People with
home access who connect from a network on the same addresses reach your
home instead of their own, LAN Bypass or not
- The router tells when a device can't connect properly. After the problem
lasts three minutes, the portal card and the admin drawer name it:
can't finish connecting (the network may block it), connected but no
data (an outdated configuration, and the card offers Reconnect), on two
devices at once, or a connection that keeps dropping. Activity lists
these under Problems, one line per device per hour, and says when the
device connects normally again
- The set-up sheet's connection line follows what the device does:
waiting, can't finish, connected, or connected but no data. The sheet
closes by itself only once data comes through. On the device itself and
for a router, the steps regroup to what fixes the problem: "Set it up
again" when the handshake never finishes, "Add the connection again"
("Import the configuration again" for a router) when no data comes
- Set-up in the portal: a QR code too long for a camera to read gives its
place to a code that opens the set-up link (a LAN Bypass configuration
or a long AmneziaVPN key can be that long). A TV, box or NAS added from
a phone gets the steps for setting up from another device. Back from
"Open on the device" keeps the kind, LAN Bypass and the name typed. The
packet-size note under the kinds is gone
- The portal on phones keeps its place: nothing jumps when an access row
opens or folds, a notice comes or goes, or Safari redraws the cards. A
reload, or coming back from the VPN app, opens where the page was. Cards
glide to their new height, and an animation interrupted half-way goes on
from where it is instead of snapping. A double click no longer closes
the sheet it just opened
- In the admin, a device's drawer has its own MTU and keep-alive (empty
means the server's), each with a Change dialog. A change touches only
that device's configuration and restarts nothing on the router. Opening
the drawer no longer counts as handing out the configuration: "Update
config" stays until the new configuration is shown as a QR code,
downloaded or copied ("Show the new configuration"). New keys set the
device up again, as the portal's Reconnect does
- "Speed now" on a server's Overview is live: one point a second over the
last two minutes, all there as soon as the Overview opens. The agent
keeps those two minutes in memory and writes them out only while someone
is looking
- Disguise values that AmneziaWG refuses or crashes on are stopped before
they reach the kernel. That covers overlapping H1-H4, Jmin above Jmax,
broken I1-I5 tags, padding under 12 with header protection, and more.
Import and restore refuse them. After a hand edit in uci, the server's
tunnel stays down and Health and the service log say why and what to do.
Errors are full sentences in the reader's language
- The header protection key no longer shows in the status that read-only
users can see: the Server page says only that the key is set, and each
device's configuration still has it. The server no longer turns off
WireGuard's protection against handshake floods (devices keep
DisableCookies). A device can't be added with a server's own key
- An AmneziaWG update whose kernel module can't be swapped (another
AmneziaWG interface holds the old one) no longer fails. It is installed,
the tunnels come back on the old module, and Health and Components say
the update starts after a reboot. On apk firmware, an install that apk
left at the old version counts as failed. A module installed by hand is
recorded, so after a firmware upgrade Health can tell that it is gone
- Dawnline reads only its own tunnels, each one separately. Another
AmneziaWG interface on the router no longer slows the agent's
once-a-second check, has its keys read or breaks Dawnline's reads. A
portal request reads only that person's server: one process however many
servers there are
- Fewer false disconnects: a tunnel that netifd sets up again no longer
logs everyone as leaving and coming back, and a device with a long
keep-alive stays online between handshakes. One configuration on two
devices isn't logged as roaming every few seconds, and new keys end the
old session at once. A tunnel that is missing devices is synced within a
minute, and traffic across a tunnel restart is no longer undercounted
- Renaming a server no longer restarts its tunnel. If a tunnel's interface
is edited outside Dawnline (LuCI, uci), the watchdog sets it up again
with Dawnline's settings and names only the changed options. The routing
rules for "Internet like a home device" change one at a time, new ones
first, so traffic never falls between them. Health and the Server page
warn when the address's AAAA record isn't this router's, or the router
has no public IPv6: devices that prefer IPv6 fail to connect
- The README screenshots come in English and Russian; the portal's are
taken from its demo. The demo has a switch beside × in the set-up sheet
to show each state of the connection line. In Russian, long labels in
the admin's wide option buttons wrap under their icon. DESIGN.md
describes the switch, renaming on the card, the shimmer, the shake and
how the portal scrolls. New tests cover link states, the meter, access,
Health, firewall rules, network settings and packages
310 lines
11 KiB
Ucode
310 lines
11 KiB
Ucode
// Dawnline rpcd methods: the live revision, the Overview status (servers,
|
|
// people, totals, map, recent activity), the live meter, the activity log and
|
|
// traffic history.
|
|
|
|
import { readfile } from 'fs';
|
|
import { _ } from 'dawnline.i18n';
|
|
import { read_json, write_json, ensure_dir, lock, unlock, admin_log, VERSION, RUN_DIR } from 'dawnline.util';
|
|
import * as core from 'dawnline.core';
|
|
import * as live from 'dawnline.live';
|
|
import * as view from 'dawnline.view';
|
|
import * as geo from 'dawnline.geo';
|
|
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 * as health from 'dawnline.health';
|
|
import * as meter from 'dawnline.meter';
|
|
import { wrap, str, clamp_days } from 'dawnline.rpc.common';
|
|
|
|
/** The router's public IPv4 (null when none or private). */
|
|
function wan_public(m) {
|
|
let w = lookup.router_wan(m);
|
|
return w && health.wan_kind(w) == 'public' ? w : null;
|
|
}
|
|
|
|
/** The router's own public addresses: a device at home that reaches the server through the WAN address (NAT loopback) is not "outside". */
|
|
function own_addresses(m) {
|
|
let own = {};
|
|
for (let id, srv in m.servers) {
|
|
let a = net.wan_address(srv) ?? lookup.wan_ipv4(srv.wan_zone);
|
|
if (a)
|
|
own[a] = true;
|
|
}
|
|
let wan = lookup.wan_ipv4('wan');
|
|
if (wan)
|
|
own[wan] = true;
|
|
return own;
|
|
}
|
|
|
|
/** Router location plus one point per (device, recent client address). */
|
|
function geo_view(m, usage, dmp) {
|
|
if (!m.settings.geo_enabled)
|
|
return { enabled: false, home: null, points: [] };
|
|
let cache = geo.load();
|
|
let points = [];
|
|
let now = time();
|
|
// The router's own public addresses: a device at home that reaches the server through the
|
|
// WAN address (NAT loopback) shows up from there. Home is not a place people connect from.
|
|
let own = {};
|
|
for (let id, srv in m.servers) {
|
|
let a = net.wan_address(srv) ?? lookup.wan_ipv4(srv.wan_zone);
|
|
if (a)
|
|
own[a] = true;
|
|
}
|
|
let wan = lookup.wan_ipv4('wan');
|
|
if (wan)
|
|
own[wan] = true;
|
|
for (let id, d in m.devices) {
|
|
let rec = usage.devices?.[id];
|
|
let peer = dmp.peers[d.public_key];
|
|
let cur = live.endpoint_ip(peer?.endpoint);
|
|
let online = live.online(dmp, id, peer);
|
|
for (let ip, ts in rec?.ips ?? {}) {
|
|
// Local (LAN / CGNAT) client addresses and the router's own are not shown on the map.
|
|
let pl = geo.is_public(ip) && !own[ip] ? geo.place(cache, ip) : null;
|
|
if (!pl)
|
|
continue;
|
|
push(points, {
|
|
person: d.person, device: id, ip, ts,
|
|
online: online && ip == cur,
|
|
lat: pl.lat, lon: pl.lon, city: pl.city, country: pl.country, cc: pl.cc,
|
|
asn: pl.asn ?? 0, org: pl.org ?? '',
|
|
});
|
|
}
|
|
}
|
|
let h = cache.home;
|
|
return {
|
|
enabled: true,
|
|
provider: m.settings.geo_provider,
|
|
cached: length(keys(cache.ips)),
|
|
home: (h && h.lat != null) ? { lat: h.lat, lon: h.lon, city: h.city, country: h.country, cc: h.cc, asn: h.asn ?? 0, org: h.org ?? '' } : null,
|
|
points,
|
|
};
|
|
}
|
|
|
|
/** Older connections from home get the DHCP name their address has now. */
|
|
function with_hosts(ev) {
|
|
let names = null;
|
|
for (let e in ev)
|
|
if ((e.type == 'connect' || e.type == 'roam') && !e.hosts) {
|
|
let h = net.event_hosts(e, names ??= net.lan_names());
|
|
if (h)
|
|
e.hosts = h;
|
|
}
|
|
return ev;
|
|
}
|
|
|
|
function server_view(m, srv, usage, dmp, rates, days) {
|
|
let online = 0, peers = 0;
|
|
let links = map(core.tunnels(srv), (t) => t.ifname);
|
|
let ids = {};
|
|
for (let id, d in m.devices)
|
|
ids[d.public_key] = id;
|
|
for (let k, p in dmp.peers)
|
|
if (index(links, p.ifname) >= 0) {
|
|
peers++;
|
|
if (live.online(dmp, ids[k], p))
|
|
online++;
|
|
}
|
|
let st = srv.private_key ? awg.server_state(srv) : { up: false, uptime: 0 };
|
|
// The newest handshake from a public address that is not the router's own:
|
|
// proof that the port is reachable from the internet.
|
|
let own = own_addresses(m);
|
|
let reached = 0;
|
|
for (let id, d in m.devices)
|
|
if (m.people[d.person]?.server == srv.id)
|
|
for (let ip, ts in usage.devices?.[id]?.ips ?? {})
|
|
if (geo.is_public(ip) && !own[ip] && ts > reached)
|
|
reached = ts;
|
|
return {
|
|
id: srv.id, name: srv.name, ifname: srv.ifname, port: srv.port, subnet: srv.subnet, reached,
|
|
endpoint: core.endpoint_host(m, srv), public_key: srv.public_key, enabled: srv.enabled,
|
|
lan_like: srv.lan_like, device_mesh: srv.device_mesh, mesh: srv.mesh, preset: srv.preset, mtu: srv.mtu, keepalive: srv.keepalive, dns: srv.dns,
|
|
// What devices get now, by kind (mtu 0 = automatic).
|
|
mtus: { computer: core.device_mtu(srv, { kind: 'computer' }), phone: core.device_mtu(srv, { kind: 'phone' }) },
|
|
address: core.server_address(srv), up: !!st.up, uptime: st.uptime ?? 0,
|
|
// Why the tunnel cannot run (its interface name belongs to another network section), or null.
|
|
// Why it can't start, as a whole sentence in the admin's language (stored as a code).
|
|
blocked: awg.blocked_text(srv),
|
|
// Home networks (interfaces) for the per-person picker.
|
|
home: map(net.server_net(srv).home, (h) => ({ dev: h.dev, nets: h.nets })),
|
|
// The header protection key is a secret every device shares: whether there is one.
|
|
peers, online, obf: awg.obf_public(srv.obf), hpk: !!srv.obf.header_protection_key,
|
|
// Bytes per second, one point a minute: [ts, rx, tx] (rx = from devices).
|
|
rate: rates[srv.id] ?? [],
|
|
// Daily traffic of the people on this server (its Overview chart).
|
|
series: live.series(map(filter(keys(m.people), (pid) => m.people[pid].server == srv.id), (pid) => usage.people?.[pid]), days),
|
|
};
|
|
}
|
|
|
|
/*
|
|
* Everything the pages show at once. Readable by read-only users: no personal
|
|
* codes or links here (person_links has them), and no keys but public ones
|
|
* (device_config has the rest).
|
|
*/
|
|
function status(a) {
|
|
let m = core.load();
|
|
let usage = core.load_usage();
|
|
let dmp = live.dump(m);
|
|
let states = view.states(m, usage);
|
|
let days = clamp_days(a.days);
|
|
|
|
let servers = [];
|
|
let rates = read_json(`${RUN_DIR}/rate.json`, {});
|
|
let prates = read_json(`${RUN_DIR}/rate_people.json`, {});
|
|
for (let id, srv in m.servers)
|
|
push(servers, server_view(m, srv, usage, dmp, rates, days));
|
|
|
|
let people = [];
|
|
for (let id, p in m.people) {
|
|
let pv = view.person_view(m, p, usage, dmp, states, { admin: true });
|
|
pv.rate = type(prates[p.id]?.[0]) == 'array' ? prates[p.id] : [];
|
|
push(people, pv);
|
|
}
|
|
people = sort(people, (a, b) => (b.online - a.online) || (b.last_seen - a.last_seen) || (a.name < b.name ? -1 : 1));
|
|
|
|
let totals = { people: length(people), devices: 0, online: 0, active: 0 };
|
|
for (let p in people) {
|
|
totals.devices += length(p.devices);
|
|
totals.online += p.online;
|
|
if (p.state == 'active')
|
|
totals.active++;
|
|
}
|
|
let recs = values(usage.people ?? {});
|
|
let day = live.series(recs, 1)[0];
|
|
totals.today = [ day.rx, day.tx ];
|
|
let mon = [ 0, 0 ];
|
|
for (let r in recs) {
|
|
let v = live.month(r);
|
|
mon[0] += v[0];
|
|
mon[1] += v[1];
|
|
}
|
|
totals.month = mon;
|
|
|
|
let events = live.load_events();
|
|
let s = m.settings;
|
|
return {
|
|
geo: geo_view(m, usage, dmp),
|
|
version: VERSION,
|
|
now: time(),
|
|
hostname: trim(readfile('/proc/sys/kernel/hostname') ?? ''),
|
|
settings: {
|
|
portal_enabled: s.portal_enabled, portal_port: s.portal_port, portal_host: s.portal_host,
|
|
portal_public_port: core.portal_public_port(m),
|
|
default_device_limit: s.default_device_limit, domain: s.domain,
|
|
hostnames: s.hostnames, geo_enabled: s.geo_enabled, home_dns_fallback: s.home_dns_fallback,
|
|
},
|
|
servers,
|
|
people,
|
|
services: values(m.services),
|
|
circles: values(m.circles),
|
|
totals,
|
|
series: live.series(recs, days),
|
|
events: with_hosts(slice(events, length(events) > 60 ? length(events) - 60 : 0)),
|
|
like_home: loop.status(),
|
|
awg: awg.caps(),
|
|
awg_state: awg.state(),
|
|
// The router's public IPv4 (null when none or private): a server whose public address is an old one is told so.
|
|
wan: wan_public(m),
|
|
};
|
|
}
|
|
|
|
|
|
/** 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 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() };
|
|
}
|
|
|
|
/** Remove activity by person, device, category and/or age; nothing given clears it all. */
|
|
function logs_clear(a) {
|
|
let m = core.load();
|
|
let f = {};
|
|
if (a.person) {
|
|
if (!m.people[a.person])
|
|
die(_('Unknown person.'));
|
|
f.person = a.person;
|
|
}
|
|
if (a.device)
|
|
f.device = a.device;
|
|
if (a.category) {
|
|
if (index(live.CATEGORIES, a.category) < 0)
|
|
die(_('Unknown category.'));
|
|
f.category = a.category;
|
|
}
|
|
if (a.older_days) {
|
|
if (!match(a.older_days, /^[1-9][0-9]{0,3}$/))
|
|
die(_('Older than must be a number of days.'));
|
|
f.before = time() - +a.older_days * 86400;
|
|
}
|
|
let removed = live.clear_events(f);
|
|
if (removed)
|
|
admin_log('dawnline', 'cleared', null, 'the activity log',
|
|
join(' · ', filter([ `${removed} event${removed == 1 ? '' : 's'}`, f.category, f.person ? m.people[f.person].name : null,
|
|
a.older_days ? `older than ${a.older_days} days` : null ], (x) => x)));
|
|
return { ok: true, removed };
|
|
}
|
|
|
|
/**
|
|
* Reset traffic history (all | person | device). The agent owns the live
|
|
* counters, so it gets a marker; the tmpfs copy is edited too so the UI
|
|
* shows the result straight away.
|
|
*/
|
|
function usage_clear(a) {
|
|
let m = core.load();
|
|
if (index([ 'all', 'person', 'device' ], a.scope) < 0)
|
|
die(_('Unknown scope.'));
|
|
if (a.scope == 'person' && !m.people[a.id])
|
|
die(_('Unknown person.'));
|
|
if (a.scope == 'device' && !m.devices[a.id])
|
|
die(_('Unknown device.'));
|
|
let req = { scope: a.scope, id: a.id, ts: time() };
|
|
ensure_dir(RUN_DIR);
|
|
let l = lock('usage-reset');
|
|
let pending = read_json(`${RUN_DIR}/usage.reset`, []);
|
|
push(pending, req);
|
|
write_json(`${RUN_DIR}/usage.reset`, pending, 0o600);
|
|
unlock(l);
|
|
let usage = core.load_usage();
|
|
if (usage) {
|
|
live.reset_usage(usage, m, a.scope, a.id);
|
|
write_json(`${RUN_DIR}/usage.json`, usage, 0o600);
|
|
}
|
|
admin_log('dawnline', 'reset traffic history', null,
|
|
a.scope == 'all' ? 'for everyone' : a.scope == 'person' ? `for ${m.people[a.id].name}` : `for ${m.devices[a.id].name} (${m.people[m.devices[a.id].person]?.name})`);
|
|
return { ok: true };
|
|
}
|
|
|
|
/** 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), version: VERSION };
|
|
}
|
|
|
|
/*
|
|
* The live meter (Overview): each call keeps the agent's watcher writing out
|
|
* the points it keeps for meter.WANT_FOR seconds more (a first call finds
|
|
* none yet: the watcher writes the last two minutes within a second) and
|
|
* returns them (dawnline.meter.read), those newer than `since` when given. Read-only users may look: server ids
|
|
* and bytes per second only, no keys or personal codes.
|
|
*/
|
|
function meter_points(a) {
|
|
meter.want();
|
|
return meter.read(+a.since || 0);
|
|
}
|
|
|
|
export const methods = {
|
|
rev: { call: wrap(rev) },
|
|
meter: { args: { since: 0 }, call: wrap(meter_points) },
|
|
status: { args: { days: 30 }, call: wrap(status) },
|
|
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 }; }) },
|
|
};
|