- Where people connect from is a globe map now: live arcs from each
person to the server, grey ones for the last 24 h, 7 or 30 days, avatars
instead of dots, the server's own marker, and a light map in light mode;
it zooms to fit the people shown and follows them as they come and go
- Markers that overlap move apart with a pointer to their spot; people
next to the server fold into a count on it; a click zooms in and opens a
floating card (never clipped by the map), closing flies back
- The person page maps where they connected from, older places fading;
the device panel lists its places in order, and connections from the LAN
or through the router's own address stay off the maps ("LAN" in grey)
- Setup and new servers check the UDP port (taken by another program, a
forward or another server) and the subnet (three numbers + .x, a private
range not in use) as you type; the default port is 4500
- The personal portal can share the server's port number (TCP beside UDP);
its port is checked against forwards and other services
- A new server comes up at once: the kernel module is loaded and the
network restarted when OpenWrt doesn't know AmneziaWG yet
- A turned-off server is a state of its own: no "tunnel down" or DNS
warnings, "Turned off" in yellow, a white Turn on, and people on it are
not shown as paused
- Pause everyone is removed: turning a server off does the same (a router
left paused keeps its servers off after the update)
- People: a stopped person's card fades and says why across its bottom,
with the one action that lifts it (Resume, +10 GB, Extend 1 month);
people held by a limit or end date sort below the others, paused last
- The person page shows the state as text ("Paused") with a Resume
button, also while their server is off
- The portal tells a paused or ended person just that, even with the
server off, and lets them change nothing until the admin lifts it (the
router refuses too); its notices look like Overview's
- Automatic MTU: with the field empty the tunnel, computers and routers
get 1380 minus AmneziaWG S4 (1368 on Maximum), phones and tablets 1280;
a typed MTU still caps phones and tablets at 1280, and servers on the
old default 1380 move to automatic (phones and tablets get "Update
config", their old files keep working)
- Only procd's agent runs: a second copy (started by hand or left over)
refuses to start or is ended within 5 minutes, so no more stray paused
and resumed events; a device that leaves the tunnel is offline at once
- The installer picks the newest release (it took the lowest), DNS
lookups can't hang, and tooltips and floating cards close on scroll and
on leaving the page
This commit is contained in:
1 parent
29b1d7dfd7
commit
972e522518
60 files changed
+1966
-636
No files matched your search
@@ -11,9 +11,9 @@ import * as view from 'dawnline.view';
|
||||
import * as awg from 'dawnline.awg';
|
||||
|
||||
const STATE_TEXT = {
|
||||
no_server: 'their server is turned off',
|
||||
no_server: 'they have no server',
|
||||
server_off: 'their server is turned off',
|
||||
paused: 'they are paused',
|
||||
paused_all: 'everyone is paused',
|
||||
expired: 'their access has ended',
|
||||
quota: 'they used up their data',
|
||||
hours: 'it is outside their allowed hours',
|
||||
|
||||
@@ -54,6 +54,18 @@ export function state() {
|
||||
return { tools, kmod, loaded, handler, missing, ok: !length(missing) && loaded && handler };
|
||||
};
|
||||
|
||||
/**
|
||||
* state(), after loading an installed module that isn't loaded yet: nothing loads
|
||||
* it before the first tunnel comes up, so "not loaded" alone is no fault.
|
||||
*/
|
||||
export function load() {
|
||||
let s = state();
|
||||
if (!s.kmod || s.loaded)
|
||||
return s;
|
||||
system('modprobe amneziawg >/dev/null 2>&1');
|
||||
return state();
|
||||
};
|
||||
|
||||
/** The kernel module and the awg tool are on the router. */
|
||||
export function installed() {
|
||||
let s = state();
|
||||
@@ -249,12 +261,13 @@ export function client_config(m, dev) {
|
||||
let ep = match(host, /:/) && !match(host, /^\[/) ? `[${host}]` : host;
|
||||
let allowed = allowed_ips(m, srv, p);
|
||||
let dns = core.client_dns(m, srv, p);
|
||||
let mtu = core.device_mtu(srv, dev);
|
||||
let lines = [ '[Interface]' ];
|
||||
push(lines, `PrivateKey = ${dev.private_key || '<private key stays on your device>'}`);
|
||||
push(lines, `Address = ${dev.address}/32`);
|
||||
if (length(dns))
|
||||
push(lines, `DNS = ${join(', ', dns)}`);
|
||||
push(lines, `MTU = ${srv.mtu}`);
|
||||
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))
|
||||
@@ -279,7 +292,7 @@ export function client_config(m, dev) {
|
||||
amnezia: {
|
||||
host,
|
||||
port: srv.port,
|
||||
mtu: `${srv.mtu}`,
|
||||
mtu: `${mtu}`,
|
||||
dns,
|
||||
allowed_ips: allowed,
|
||||
client_ip: dev.address,
|
||||
@@ -307,7 +320,7 @@ export function netifd_options(srv) {
|
||||
private_key: srv.private_key,
|
||||
listen_port: srv.port,
|
||||
addresses: [ `${addr}/${prefix}` ],
|
||||
mtu: srv.mtu,
|
||||
mtu: core.tunnel_mtu(srv),
|
||||
};
|
||||
for (let k in core.OBF_KEYS)
|
||||
o[`awg_${k}`] = srv.obf[k];
|
||||
|
||||
@@ -20,6 +20,8 @@ export const CONFIG = 'dawnline';
|
||||
export const BLOCKED = `${RUN_DIR}/netifd-blocked.json`;
|
||||
export const ACCESS = [ 'lan', 'internet', 'both' ];
|
||||
export const KINDS = [ 'computer', 'phone', 'tablet', 'router', 'other' ];
|
||||
/** Kinds that mostly live on mobile networks: their configurations carry a smaller MTU. */
|
||||
export const MOBILE_KINDS = [ 'phone', 'tablet' ];
|
||||
/** Devices of different people reaching each other: never, everyone with home access, or within a circle. */
|
||||
export const MESH = [ 'off', 'all', 'circles' ];
|
||||
/** Circle colours (index into the admin palette). */
|
||||
@@ -78,7 +80,6 @@ export function load(c) {
|
||||
portal_title: s.portal_title ?? 'Dawnline',
|
||||
// Where unknown portal links go instead of a bare 404 (empty = 404).
|
||||
portal_redirect: s.portal_redirect ?? '',
|
||||
paused_all: bool(s.paused_all, false),
|
||||
default_device_limit: toint(s.default_device_limit, 3),
|
||||
geo_enabled: bool(s.geo_enabled, true),
|
||||
geo_provider: s.geo_provider == 'ipapi.co' ? 'ipapi.co' : 'ipwho.is',
|
||||
@@ -115,7 +116,8 @@ export function load(c) {
|
||||
port: toint(r.port, 51820),
|
||||
subnet: r.subnet ?? '',
|
||||
endpoint: r.endpoint ?? '',
|
||||
mtu: toint(r.mtu, 1380),
|
||||
// 0 = automatic (tunnel_mtu, device_mtu).
|
||||
mtu: toint(r.mtu, 0),
|
||||
dns: list(r.dns),
|
||||
keepalive: toint(r.keepalive, 25),
|
||||
private_key: r.private_key ?? '',
|
||||
@@ -262,19 +264,11 @@ export function person_expired(p, ts) {
|
||||
return end != null && (ts ?? time()) > end;
|
||||
};
|
||||
|
||||
/**
|
||||
* Effective state of a person: 'active', or why they are off:
|
||||
* 'paused' (admin), 'paused_all', 'expired', 'quota', 'hours', 'no_server'.
|
||||
*/
|
||||
export function person_state(m, p, usage, ts) {
|
||||
/** The person's state whatever their server is doing (paused, expired, …, or 'active'). */
|
||||
export function own_state(m, p, usage, ts) {
|
||||
ts ??= time();
|
||||
let srv = m.servers[p.server];
|
||||
if (!srv || !srv.enabled)
|
||||
return 'no_server';
|
||||
if (p.paused)
|
||||
return 'paused';
|
||||
if (m.settings.paused_all)
|
||||
return 'paused_all';
|
||||
// "notify" keeps access after the end date (shown in Overview and People).
|
||||
if (person_expired(p, ts) && p.expire_action != 'notify')
|
||||
return 'expired';
|
||||
@@ -287,6 +281,20 @@ export function person_state(m, p, usage, ts) {
|
||||
return 'active';
|
||||
};
|
||||
|
||||
/**
|
||||
* Effective state of a person: 'active', or why they are off:
|
||||
* 'paused' (admin), 'expired', 'quota', 'hours', 'no_server',
|
||||
* 'server_off' (their server is turned off: about the server, not the person).
|
||||
*/
|
||||
export function person_state(m, p, usage, ts) {
|
||||
let srv = m.servers[p.server];
|
||||
if (!srv)
|
||||
return 'no_server';
|
||||
if (!srv.enabled)
|
||||
return 'server_off';
|
||||
return own_state(m, p, usage, ts);
|
||||
};
|
||||
|
||||
export function load_usage() {
|
||||
return read_json(`${RUN_DIR}/usage.json`, null) ?? read_json(`${DATA_DIR}/usage.json`, { devices: {}, people: {} });
|
||||
};
|
||||
@@ -344,6 +352,27 @@ export function alloc_address(m, srv) {
|
||||
|
||||
/* ---------- what clients get ---------- */
|
||||
|
||||
/*
|
||||
* Automatic MTU. A path is assumed to carry 1460 bytes (1500 less PPPoE,
|
||||
* 464XLAT or DS-Lite), the tunnel's own headers take 80 over IPv6, and
|
||||
* AmneziaWG's S4 adds its bytes to every data packet (its padding and random
|
||||
* trailers stay within the largest packet already seen, so they cost
|
||||
* nothing). Phones and tablets get 1280, the IPv6 minimum: mobile paths vary.
|
||||
*/
|
||||
const AUTO_MTU = 1380;
|
||||
const MOBILE_MTU = 1280;
|
||||
|
||||
/** The server's tunnel MTU: the one set, or automatic for its disguise. */
|
||||
export function tunnel_mtu(srv) {
|
||||
return srv.mtu || max(MOBILE_MTU, AUTO_MTU - toint(srv.obf?.s4, 0));
|
||||
};
|
||||
|
||||
/** The MTU a device's configuration carries: the tunnel's, at most 1280 for phones and tablets. */
|
||||
export function device_mtu(srv, dev) {
|
||||
let mtu = tunnel_mtu(srv);
|
||||
return index(MOBILE_KINDS, dev.kind) >= 0 ? min(mtu, MOBILE_MTU) : mtu;
|
||||
};
|
||||
|
||||
export function endpoint_host(m, srv) {
|
||||
return srv.endpoint || m.settings.portal_host || '';
|
||||
};
|
||||
@@ -690,6 +719,16 @@ export function delete_person(c, m, id) {
|
||||
c.delete(CONFIG, id);
|
||||
};
|
||||
|
||||
const PRIVATE_NETS = map([ '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16' ], parse_cidr);
|
||||
|
||||
/** The parsed subnet lies inside one of the private ranges. */
|
||||
export function private_cidr(c) {
|
||||
for (let p in PRIVATE_NETS)
|
||||
if (c.net >= p.net && c.net + c.size <= p.net + p.size)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
/** Validate a server definition (as loaded) against the rest of the router. */
|
||||
export function server_errors(m, srv, others_subnets) {
|
||||
let errs = [];
|
||||
@@ -711,21 +750,28 @@ export function server_errors(m, srv, others_subnets) {
|
||||
return errs;
|
||||
};
|
||||
|
||||
/** Someone else already forwards this TCP port from outside (a port forward we must not take over). */
|
||||
export function wan_port_taken(port) {
|
||||
/**
|
||||
* Port forwards from `zone` for `proto` that aren't Dawnline's: [{ from, to, name }].
|
||||
* A forwarded port never reaches the router itself, so nothing here can listen on it.
|
||||
*/
|
||||
export function wan_forwards(zone, proto) {
|
||||
let c = cursor();
|
||||
c.load('firewall');
|
||||
let taken = false;
|
||||
let out = [];
|
||||
c.foreach('firewall', 'redirect', (r) => {
|
||||
if (match(r['.name'], /^dawnline_/) || r.enabled == '0' || (r.target ?? 'DNAT') != 'DNAT')
|
||||
if (match(r['.name'], /^dawnline_/) || r.enabled == '0' || (r.target ?? 'DNAT') != 'DNAT' || r.src != zone)
|
||||
return;
|
||||
// fw4's default is "tcp udp".
|
||||
let protos = split(type(r.proto) == 'array' ? join(' ', r.proto) : r.proto ?? 'tcp udp', /[ ,]+/);
|
||||
if (index(protos, proto) < 0 && index(protos, 'all') < 0 && index(protos, 'any') < 0)
|
||||
return;
|
||||
for (let p in split(`${r.src_dport ?? ''}`, /[ ,]+/)) {
|
||||
let m = match(p, /^(\d+)([-:](\d+))?$/);
|
||||
if (m && +m[1] <= port && port <= +(m[3] || m[1]))
|
||||
taken = true;
|
||||
if (m)
|
||||
push(out, { from: +m[1], to: +(m[3] || m[1]), name: r.name ?? r['.name'] });
|
||||
}
|
||||
});
|
||||
return taken;
|
||||
return out;
|
||||
};
|
||||
|
||||
/** Every address the links use, the main one first. */
|
||||
|
||||
@@ -42,12 +42,51 @@ export function needs() {
|
||||
};
|
||||
};
|
||||
|
||||
export function udp_listening(port) {
|
||||
let hex = sprintf(':%04X ', port);
|
||||
/** UDP ports an unconnected socket is bound to (IPv4 and IPv6): nothing else can listen there. */
|
||||
export function udp_bound() {
|
||||
let out = {};
|
||||
for (let f in [ '/proc/net/udp', '/proc/net/udp6' ])
|
||||
if (index(readfile(f) ?? '', hex) >= 0)
|
||||
return true;
|
||||
return false;
|
||||
for (let line in split(readfile(f) ?? '', '\n')) {
|
||||
// " 12: 00000000:1194 00000000:0000 07 …": local address, then the remote one (none).
|
||||
let m = match(line, /^ *[0-9]+: [0-9A-F]+:([0-9A-F]{4}) [0-9A-F]+:0000 /);
|
||||
if (m)
|
||||
out[hex(m[1])] = true;
|
||||
}
|
||||
return map(keys(out), (k) => +k);
|
||||
};
|
||||
|
||||
/**
|
||||
* Programs on 'tcp' or 'udp' ports, our portal left out: { port: "dnsmasq" }.
|
||||
* Kernel sockets (a tunnel's) have no name.
|
||||
*/
|
||||
function port_programs(proto) {
|
||||
let out = {};
|
||||
for (let line in split(sh_out(`netstat -ln${proto == 'tcp' ? 't' : 'u'}p 2>/dev/null`) ?? '', '\n')) {
|
||||
let f = split(trim(line), /[ \t]+/);
|
||||
if (f[0] != proto && f[0] != `${proto}6`)
|
||||
continue;
|
||||
let m = match(f[3] ?? '', /:([0-9]+)$/);
|
||||
let owner = split(f[length(f) - 1], '/');
|
||||
if (!m || !owner[1] || out[m[1]])
|
||||
continue;
|
||||
// Our own portal runs as a dedicated uhttpd instance.
|
||||
if (index(readfile(`/proc/${+owner[0]}/cmdline`) ?? '', '/usr/share/dawnline/portal') >= 0)
|
||||
continue;
|
||||
out[m[1]] = owner[1];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function udp_port_programs() {
|
||||
return port_programs('udp');
|
||||
};
|
||||
|
||||
export function tcp_port_programs() {
|
||||
return port_programs('tcp');
|
||||
};
|
||||
|
||||
export function udp_listening(port) {
|
||||
return index(udp_bound(), +port) >= 0;
|
||||
};
|
||||
|
||||
export function tcp_listening(port) {
|
||||
@@ -116,6 +155,11 @@ function other_subnets(srv_id) {
|
||||
};
|
||||
|
||||
/** Subnets in use on the router except the given server's (null: all of them). */
|
||||
/** The router's IPv4 networks, Dawnline's tunnels included: [{ iface, cidr }]. */
|
||||
export function networks() {
|
||||
return other_subnets(null);
|
||||
};
|
||||
|
||||
export function used_subnets(except_srv) {
|
||||
return map(other_subnets(except_srv), (x) => x.cidr);
|
||||
};
|
||||
@@ -211,12 +255,13 @@ const NO_PROTO = "netifd doesn't know the amneziawg protocol (AmneziaWG missing,
|
||||
|
||||
/** Is AmneziaWG there and usable: packages, kernel module, netifd's protocol handler. */
|
||||
function awg_check() {
|
||||
let st = awg.state();
|
||||
let st = awg.load();
|
||||
let title = 'AmneziaWG installed';
|
||||
if (length(st.missing ?? []))
|
||||
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);
|
||||
return check('awg', title, 'error',
|
||||
`The kernel module doesn't load${why ? `: ${why}` : '.'} Reinstall a build for this kernel in Components.`, 'updates',
|
||||
@@ -385,10 +430,16 @@ export function health(m) {
|
||||
}
|
||||
}
|
||||
|
||||
if (length(filter(values(m.servers), (x) => x.private_key))) {
|
||||
// While every server is off the resolver only idles on loopback: nothing to check.
|
||||
if (length(filter(values(m.servers), (x) => x.enabled && x.private_key))) {
|
||||
let rt = loop.resolver_target();
|
||||
let ok = stat(loop.RESOLVER.conf) != null && loop.resolver_running();
|
||||
let conf = stat(loop.RESOLVER.conf);
|
||||
let running = conf != null && loop.resolver_running();
|
||||
// A new config (a server turned on, the home link up) restarts it: give it a few seconds.
|
||||
let restarting = !running && conf != null && time() - conf.mtime < 10;
|
||||
let ok = running || restarting;
|
||||
push(out, check('resolver', 'DNS for Home-only devices', ok ? 'ok' : 'warn',
|
||||
restarting ? 'Restarting with the new settings.' :
|
||||
ok ? (rt.mode == 'ns' ? `Plain resolver running next to the LAN (${rt.address}).` : `Plain resolver on port ${rt.port}.`)
|
||||
: 'The resolver is not running; Home-only devices cannot resolve names.', ok ? null : 'apply'));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export const CATEGORY = {
|
||||
device_added: 'people', device_removed: 'people', devices_removed: 'people',
|
||||
device_changed: 'people', device_keys: 'people', link_changed: 'people',
|
||||
person_added: 'people', person_removed: 'people', person_changed: 'people',
|
||||
paused: 'people', resumed: 'people', paused_all: 'people', resumed_all: 'people',
|
||||
paused: 'people', resumed: 'people',
|
||||
server_down: 'problems', server_up: 'problems', portal_blocked: 'problems',
|
||||
};
|
||||
export const CATEGORIES = [ 'connections', 'people', 'problems' ];
|
||||
|
||||
@@ -55,7 +55,8 @@ export function resolve_all(hosts) {
|
||||
let cmds = [];
|
||||
for (let i = 0; i < length(todo); i++)
|
||||
for (let j = 0; j < length(SERVERS); j++)
|
||||
push(cmds, `( timeout ${TIMEOUT} nslookup ${q(todo[i])} ${SERVERS[j]} 2>/dev/null | awk '/^Address/ && NR>2 {print $NF}' > ${dir}/${i}.${j} ) &`);
|
||||
// nslookup's own timeout: some firmware builds BusyBox without `timeout`.
|
||||
push(cmds, `( nslookup -type=a -timeout=${TIMEOUT} -retry=1 ${q(todo[i])} ${SERVERS[j]} 2>/dev/null | awk '/^Address/ && NR>2 {print $NF}' > ${dir}/${i}.${j} ) &`);
|
||||
sh(`mkdir -p ${dir}; ${join(' ', cmds)} wait`);
|
||||
for (let i = 0; i < length(todo); i++) {
|
||||
let ips = [];
|
||||
|
||||
@@ -57,8 +57,29 @@ export function uhttpd() {
|
||||
store.transact((w, m) => w.delete('dawnline', 'settings', 'portal_443'));
|
||||
};
|
||||
|
||||
/** 1380 was every server's stored MTU before it became automatic (by device type and disguise). */
|
||||
function auto_mtu() {
|
||||
let c = cursor();
|
||||
c.load('dawnline');
|
||||
let any = false;
|
||||
c.foreach('dawnline', 'server', (s) => {
|
||||
if (s.mtu == '1380')
|
||||
any = true;
|
||||
});
|
||||
if (!any)
|
||||
return;
|
||||
store.transact((w, m) => {
|
||||
w.foreach('dawnline', 'server', (s) => {
|
||||
if (s.mtu == '1380')
|
||||
w.delete('dawnline', s['.name'], 'mtu');
|
||||
});
|
||||
});
|
||||
slog('dawnline', 'info', 'MTU is now automatic', null, 'Servers');
|
||||
}
|
||||
|
||||
/** All of them, in order. */
|
||||
export function run() {
|
||||
word_codes();
|
||||
uhttpd();
|
||||
auto_mtu();
|
||||
};
|
||||
@@ -54,6 +54,12 @@ const SECURITY_HEADERS = {
|
||||
|
||||
const NOT_READY = "Adding devices isn't available right now: the VPN server isn't ready. Ask whoever sent you this link.";
|
||||
|
||||
// States the admin stopped the person in: the portal only shows, it changes nothing.
|
||||
const LOCKED = {
|
||||
paused: 'Your access is paused by the admin.',
|
||||
expired: 'Your access has ended. Ask the admin to extend it.',
|
||||
};
|
||||
|
||||
function html_escape(s) {
|
||||
return replace(`${s}`, /[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
||||
}
|
||||
@@ -263,11 +269,38 @@ function reload(r) {
|
||||
not_found(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* The person's state for the page: a stop by the admin (pause, end of access)
|
||||
* wins over their server being off, so they learn that their access is stopped.
|
||||
*/
|
||||
function person_state(m, p, usage) {
|
||||
let st = core.person_state(m, p, usage);
|
||||
if (st == 'server_off') {
|
||||
let own = core.own_state(m, p, usage);
|
||||
if (LOCKED[own])
|
||||
return own;
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
/** Why the person can't change anything right now, or null. */
|
||||
function locked(r) {
|
||||
return LOCKED[person_state(r.m, r.person, core.load_usage())] ?? null;
|
||||
}
|
||||
|
||||
/** Refuses a change (or a config) while the person is stopped. */
|
||||
function need_open(r) {
|
||||
let why = locked(r);
|
||||
if (why)
|
||||
fail(r, '403 Forbidden', why);
|
||||
}
|
||||
|
||||
/** Everything the page shows. */
|
||||
function state(r) {
|
||||
let m = r.m, person = r.person;
|
||||
let usage = core.load_usage();
|
||||
let v = view.person_view(m, person, usage, live.dump(m), view.states(m, usage));
|
||||
v.state = person_state(m, person, usage);
|
||||
let srv = m.servers[person.server];
|
||||
// The device this page was opened from, when it came through the tunnel.
|
||||
let here = null;
|
||||
@@ -284,6 +317,7 @@ function state(r) {
|
||||
awg_disguise: srv ? !awg.obf_neutral(srv.obf) : false,
|
||||
},
|
||||
can_add: length(person.devices) < person.device_limit,
|
||||
locked: LOCKED[v.state] != null,
|
||||
kinds: core.KINDS,
|
||||
// The router's day: access ends and usage days follow its clock, not the browser's.
|
||||
today: today(),
|
||||
@@ -304,6 +338,7 @@ function api_state(r) {
|
||||
}
|
||||
|
||||
function api_add(r) {
|
||||
need_open(r);
|
||||
let b = body(r);
|
||||
if (!devices.ready())
|
||||
fail(r, '503 Service Unavailable', NOT_READY);
|
||||
@@ -314,6 +349,7 @@ function api_add(r) {
|
||||
|
||||
function api_config(r, id) {
|
||||
let d = own_device(r, id);
|
||||
need_open(r);
|
||||
awg.mark_issued(r.m, d.id);
|
||||
send_json(r, '200 OK', awg.client_config(r.m, d));
|
||||
}
|
||||
@@ -338,6 +374,7 @@ const ACTIONS = {
|
||||
|
||||
function api_device(r, id) {
|
||||
let d = own_device(r, id);
|
||||
need_open(r);
|
||||
let b = body(r);
|
||||
let act = ACTIONS[b.action];
|
||||
if (!act)
|
||||
|
||||
@@ -54,10 +54,12 @@ export function running() {
|
||||
*/
|
||||
export function sync(m, target, lan) {
|
||||
ensure_dir('/var/etc');
|
||||
// Servers that are on: with none, the resolver idles on loopback.
|
||||
let ifs = [];
|
||||
for (let id, s in m.servers)
|
||||
for (let t in core.tunnels(s))
|
||||
push(ifs, t.ifname);
|
||||
if (s.enabled)
|
||||
for (let t in core.tunnels(s))
|
||||
push(ifs, t.ifname);
|
||||
let lines = [
|
||||
`# mode=${target.mode}`,
|
||||
'# Generated by Dawnline: plain DNS for Home-only tunnel clients.',
|
||||
@@ -76,7 +78,7 @@ export function sync(m, target, lan) {
|
||||
push(lines, `server=${a}@${target.address}`);
|
||||
}
|
||||
else {
|
||||
// No tunnel yet: loopback only (without any interface= line dnsmasq would answer everywhere).
|
||||
// No tunnel on: loopback only (without any interface= line dnsmasq would answer everywhere).
|
||||
push(lines, 'bind-dynamic', ...(length(ifs) ? map(ifs, (i) => `interface=${i}`) : [ 'listen-address=127.0.0.1' ]), `resolv-file=${RESOLV}`);
|
||||
let resolv = join('', map(wan_dns(), (a) => `nameserver ${a}\n`));
|
||||
if ((readfile(RESOLV) ?? '') != resolv) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as core from 'dawnline.core';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as health from 'dawnline.health';
|
||||
import * as schema from 'dawnline.schema';
|
||||
import { uniq } from 'dawnline.util';
|
||||
|
||||
/**
|
||||
* An rpcd handler from fn(args): an object result is passed on, anything else
|
||||
@@ -52,6 +53,36 @@ export function check_method(name) {
|
||||
* addresses use plain HTTP, the next port too — both get a WAN ACCEPT rule.
|
||||
* Neither may be 22, 53, 80 or 443, beyond 65535, or taken by another program.
|
||||
*/
|
||||
/** TCP port forwards from the servers' WAN zones: [{ from, to, name }]. */
|
||||
function tcp_forwards(m) {
|
||||
let out = [];
|
||||
for (let z in uniq([ 'wan', ...map(values(m.servers), (s) => s.wan_zone) ]))
|
||||
push(out, ...core.wan_forwards(z, 'tcp'));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* TCP ports the portal can't take, and who holds them: [{ from, to, who }].
|
||||
* The router's own (22, 53, 80, 443), other programs and port forwards from WAN.
|
||||
*/
|
||||
export function tcp_taken(m) {
|
||||
let out = [];
|
||||
let held = {};
|
||||
let hold = (p, who) => {
|
||||
if (!held[p]) {
|
||||
held[p] = true;
|
||||
push(out, { from: p, to: p, who });
|
||||
}
|
||||
};
|
||||
for (let p in schema.RESERVED_PORTS)
|
||||
hold(p, 'the router itself');
|
||||
for (let p, name in health.tcp_port_programs())
|
||||
hold(+p, `${name} on this router`);
|
||||
for (let f in tcp_forwards(m))
|
||||
push(out, { from: f.from, to: f.to, who: `port forward “${f.name}”` });
|
||||
return out;
|
||||
};
|
||||
|
||||
export function check_portal(m, was) {
|
||||
let s = m.settings;
|
||||
if (!s.portal_enabled)
|
||||
@@ -80,4 +111,9 @@ export function check_portal(m, was) {
|
||||
if (length(owners))
|
||||
die(`TCP ${p} is already used by ${join(', ', owners)}.${p != port ? ' Links on IP addresses use plain HTTP on the port after the portal\'s.' : ''} Choose another portal port.`);
|
||||
}
|
||||
// A forwarded port never reaches the router: the portal would be unreachable.
|
||||
for (let p in ports)
|
||||
for (let f in tcp_forwards(m))
|
||||
if (f.from <= p && p <= f.to)
|
||||
die(`TCP ${p} is sent on by port forward “${f.name}”. Choose another portal port.`);
|
||||
};
|
||||
@@ -111,15 +111,6 @@ function person_usage(a) {
|
||||
return { person: live.series([ usage.people?.[a.id] ], days), devices: devs };
|
||||
}
|
||||
|
||||
function pause_all(a) {
|
||||
store.transact((c, m) => {
|
||||
c.set(core.CONFIG, 'settings', 'settings');
|
||||
c.set(core.CONFIG, 'settings', 'paused_all', a.paused ? '1' : '0');
|
||||
});
|
||||
live.add_event({ type: a.paused ? 'paused_all' : 'resumed_all', by: 'admin' });
|
||||
return apply.sync();
|
||||
}
|
||||
|
||||
/* ---------- devices ---------- */
|
||||
|
||||
function device_create(a) {
|
||||
@@ -155,7 +146,6 @@ export const methods = {
|
||||
person_links: { args: { id: '' }, call: wrap(person_links) },
|
||||
person_delete: { args: { id: '' }, call: wrap(person_delete) },
|
||||
person_usage: { args: { id: '', days: 30 }, call: wrap(person_usage) },
|
||||
pause_all: { args: { paused: false }, call: wrap(pause_all) },
|
||||
device_create: { args: { person: '', name: '', kind: '' }, call: wrap(device_create) },
|
||||
device_config: { args: { id: '' }, call: wrap(device_config) },
|
||||
device_update: { args: { id: '', name: '', disabled: false }, call: wrap(device_update) },
|
||||
|
||||
@@ -14,7 +14,7 @@ import * as schema from 'dawnline.schema';
|
||||
import * as health from 'dawnline.health';
|
||||
import * as backup from 'dawnline.backup';
|
||||
import * as devices from 'dawnline.devices';
|
||||
import { wrap, str, check_method, check_portal } from 'dawnline.rpc.common';
|
||||
import { wrap, str, check_method, check_portal, tcp_taken } from 'dawnline.rpc.common';
|
||||
|
||||
/** Server ids that would shadow a portal path. */
|
||||
const PORTAL_PATHS = [ 'api', 'assets', 'cgi-bin' ];
|
||||
@@ -23,19 +23,54 @@ const MESH_WORDS = { off: 'devices kept apart', all: 'devices reach each other',
|
||||
|
||||
/* ---------- free names, ports and subnets ---------- */
|
||||
|
||||
function free_port(m) {
|
||||
let used = {};
|
||||
/**
|
||||
* UDP ports a server can't listen on, and who holds them: [{ from, to, who }].
|
||||
* Other servers, tunnel interfaces, programs on the router and port forwards
|
||||
* from its WAN zone. `srv` is the server being edited: its own port isn't counted.
|
||||
*/
|
||||
function udp_taken(m, srv, wan_zone) {
|
||||
let out = [];
|
||||
let held = {};
|
||||
let hold = (p, who) => {
|
||||
if (p > 0 && !held[p]) {
|
||||
held[p] = true;
|
||||
push(out, { from: p, to: p, who });
|
||||
}
|
||||
};
|
||||
for (let id, o in m.servers)
|
||||
if (id != srv?.id)
|
||||
hold(o.port, `server “${o.name}”`);
|
||||
let nc = cursor();
|
||||
nc.load('network');
|
||||
nc.foreach('network', 'interface', (s) => {
|
||||
if (s.listen_port)
|
||||
used[+s.listen_port] = true;
|
||||
if (s.listen_port && s['.name'] != srv?.ifname)
|
||||
hold(+s.listen_port, `interface ${s['.name']}`);
|
||||
});
|
||||
for (let id, srv in m.servers)
|
||||
used[srv.port] = true;
|
||||
let progs = health.udp_port_programs();
|
||||
for (let p in health.udp_bound())
|
||||
if (p != srv?.port)
|
||||
hold(p, progs[`${p}`] ? `${progs[`${p}`]} on this router` : 'another program on this router');
|
||||
for (let f in core.wan_forwards(wan_zone, 'udp'))
|
||||
push(out, { from: f.from, to: f.to, who: `port forward “${f.name}”` });
|
||||
return out;
|
||||
}
|
||||
|
||||
function check_udp_port(port, taken) {
|
||||
for (let t in taken)
|
||||
if (t.from <= port && port <= t.to)
|
||||
die(`UDP ${port} is used by ${t.who}. Choose another port.`);
|
||||
}
|
||||
|
||||
/** The usual AmneziaWG port when free, otherwise a random high one. */
|
||||
const DEFAULT_PORT = 4500;
|
||||
|
||||
function free_port(taken) {
|
||||
let used = (p) => length(filter(taken, (t) => t.from <= p && p <= t.to)) > 0;
|
||||
if (!used(DEFAULT_PORT))
|
||||
return DEFAULT_PORT;
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let p = rand_int(40000, 60000);
|
||||
if (!used[p])
|
||||
if (!used(p))
|
||||
return p;
|
||||
}
|
||||
return 51830;
|
||||
@@ -58,9 +93,14 @@ function free_subnet(taken) {
|
||||
return '10.77.0.0/24';
|
||||
}
|
||||
|
||||
function free_portal_port(cur) {
|
||||
for (let p in uniq([ cur || 8443, 8443, 9443, 10443, 7443, 4443 ]))
|
||||
if (!length(health.tcp_port_owners(p)) && !length(health.tcp_port_owners(p + 1)))
|
||||
/**
|
||||
* A portal port free together with the next one (plain HTTP for IP links):
|
||||
* `first` (the server's UDP number, TCP is another port) before the usual ones.
|
||||
*/
|
||||
function free_portal_port(first, cur, taken) {
|
||||
let used = (p) => length(filter(taken, (t) => t.from <= p && p <= t.to)) > 0;
|
||||
for (let p in uniq([ first, cur || 8443, 8443, 9443, 10443, 7443, 4443 ]))
|
||||
if (!used(p) && !used(p + 1))
|
||||
return p;
|
||||
return 9443;
|
||||
}
|
||||
@@ -97,19 +137,29 @@ function free_server_id(m) {
|
||||
return `server${n}`;
|
||||
}
|
||||
|
||||
/** Subnets a new server must not overlap: the router's networks and the other servers. */
|
||||
function taken_subnets(m) {
|
||||
let taken = health.used_subnets(null);
|
||||
/** Networks a new server must not overlap, by name: the router's and the other servers'. */
|
||||
function taken_networks(m) {
|
||||
let out = [];
|
||||
let seen = {};
|
||||
let add = (name, cidr) => {
|
||||
let c = parse_cidr(cidr);
|
||||
if (c && !seen[cidr_str(c)]) {
|
||||
seen[cidr_str(c)] = true;
|
||||
push(out, { name, cidr: cidr_str(c) });
|
||||
}
|
||||
};
|
||||
for (let n in health.networks())
|
||||
add(n.iface, n.cidr);
|
||||
for (let id, s in m.servers)
|
||||
push(taken, s.subnet);
|
||||
return taken;
|
||||
add(s.name, s.subnet);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ---------- setup ---------- */
|
||||
|
||||
function setup_defaults(a) {
|
||||
let m = core.load();
|
||||
let taken = taken_subnets(m);
|
||||
let networks = taken_networks(m);
|
||||
let zones = [];
|
||||
let fc = cursor();
|
||||
fc.load('firewall');
|
||||
@@ -128,35 +178,40 @@ function setup_defaults(a) {
|
||||
if (!host)
|
||||
host = live.iface_status('wan')?.['ipv4-address']?.[0]?.address ?? '';
|
||||
}
|
||||
let wan_zone = index(zones, 'wan') >= 0 ? 'wan' : zones[1];
|
||||
let udp = udp_taken(m, null, wan_zone);
|
||||
let tcp = tcp_taken(m);
|
||||
let port = free_port(udp);
|
||||
return {
|
||||
id: free_server_id(m),
|
||||
name: length(m.servers) ? `Server ${length(m.servers) + 1}` : 'Home',
|
||||
ifname: free_ifname(m),
|
||||
port: free_port(m),
|
||||
subnet: free_subnet(taken),
|
||||
port,
|
||||
subnet: free_subnet(map(networks, (n) => n.cidr)),
|
||||
endpoint: host,
|
||||
mtu: 1380,
|
||||
// Automatic.
|
||||
mtu: 0,
|
||||
zones,
|
||||
lan_zone: index(zones, 'lan') >= 0 ? 'lan' : zones[0],
|
||||
wan_zone: index(zones, 'wan') >= 0 ? 'wan' : zones[1],
|
||||
portal_port: free_portal_port(m.settings.portal_port),
|
||||
wan_zone,
|
||||
// A portal already on keeps its port; a new one takes the server's number when it can.
|
||||
portal_port: m.settings.portal_enabled ? m.settings.portal_port : free_portal_port(port, m.settings.portal_port, tcp),
|
||||
awg: awg.caps(),
|
||||
awg_state: awg.state(),
|
||||
taken,
|
||||
awg_state: awg.load(),
|
||||
networks,
|
||||
udp_taken: udp,
|
||||
tcp_taken: tcp,
|
||||
};
|
||||
}
|
||||
|
||||
/** AmneziaWG can run a server: installed, and its kernel module loads. */
|
||||
function need_awg_loaded() {
|
||||
devices.need_awg();
|
||||
if (awg.state().loaded)
|
||||
return;
|
||||
system('modprobe amneziawg >/dev/null 2>&1');
|
||||
if (!awg.state().loaded)
|
||||
if (!awg.load().loaded)
|
||||
die("AmneziaWG's kernel module doesn't load on this firmware: reinstall a build for this kernel in Components.");
|
||||
}
|
||||
|
||||
/** An MTU as typed: '' (the default) or 1280-1500. */
|
||||
/** An MTU as typed: '' (automatic) or 1280-1500. */
|
||||
function check_mtu(v) {
|
||||
let s = str(v);
|
||||
if (s != '' && (!match(s, /^[0-9]{1,4}$/) || +s < 1280 || +s > 1500))
|
||||
@@ -180,21 +235,24 @@ function server_create(a) {
|
||||
let ifname = str(a.ifname) || free_ifname(m);
|
||||
if (!ifname_free(m, nc, ifname))
|
||||
die(`Network interface ${ifname} already exists.`);
|
||||
let port = free_port(m);
|
||||
let udp = udp_taken(m, null, str(a.wan_zone) || 'wan');
|
||||
let port = free_port(udp);
|
||||
if (a.port != null && str(a.port) != '' && str(a.port) != '0') {
|
||||
if (!schema.valid_port(a.port))
|
||||
die('UDP port must be 1-65535.');
|
||||
port = +str(a.port);
|
||||
}
|
||||
for (let sid, o in m.servers)
|
||||
if (o.port == port)
|
||||
die(`UDP ${port} is used by ${o.name}.`);
|
||||
let mtu = check_mtu(a.mtu == 0 ? '' : a.mtu) || '1380';
|
||||
check_udp_port(port, udp);
|
||||
let mtu = check_mtu(a.mtu == 0 ? '' : a.mtu);
|
||||
let preset = str(a.preset) || 'standard';
|
||||
let srv = { id, ifname, port, subnet: str(a.subnet), endpoint: str(a.endpoint), obf: awg.obf_preset(check_method(preset)) };
|
||||
let pc = parse_cidr(srv.subnet);
|
||||
if (pc)
|
||||
srv.subnet = cidr_str(pc);
|
||||
// Public addresses inside the tunnel would hide the real hosts behind them.
|
||||
// New servers only: a restored backup keeps what it had.
|
||||
if (pc && !core.private_cidr(pc))
|
||||
die('Use a private range: 10.x.x.x, 172.16–31.x.x or 192.168.x.x.');
|
||||
let taken = [ ...router_subnets ];
|
||||
for (let sid, o in m.servers)
|
||||
push(taken, o.subnet);
|
||||
@@ -212,7 +270,8 @@ function server_create(a) {
|
||||
set('subnet', srv.subnet);
|
||||
if (srv.endpoint)
|
||||
set('endpoint', srv.endpoint);
|
||||
set('mtu', mtu);
|
||||
if (mtu)
|
||||
set('mtu', mtu);
|
||||
set('keepalive', '25');
|
||||
let kp = awg.server_keys();
|
||||
set('private_key', kp.private_key);
|
||||
@@ -249,8 +308,11 @@ function server_create(a) {
|
||||
system('/etc/init.d/dawnline enabled || /etc/init.d/dawnline enable');
|
||||
let made = core.load().servers[id];
|
||||
admin_log('dawnline', 'created', 'server', made?.name ?? id, made ? `UDP ${made.port}` : null);
|
||||
sh_bg('/etc/init.d/dawnline restart');
|
||||
return { id, applied: r };
|
||||
// netifd reads its protocol handlers when it starts: AmneziaWG installed
|
||||
// after that (by hand, or by an older installer) needs a network restart.
|
||||
let network_restart = !awg.state().handler;
|
||||
sh_bg(network_restart ? '/etc/init.d/network restart; /etc/init.d/dawnline restart' : '/etc/init.d/dawnline restart');
|
||||
return { id, applied: r, network_restart };
|
||||
}
|
||||
|
||||
/* ---------- interfaces ---------- */
|
||||
@@ -416,9 +478,8 @@ function server_update(a) {
|
||||
if (!schema.valid_port(v.port))
|
||||
die('UDP port must be 1-65535.');
|
||||
let n = +str(v.port);
|
||||
for (let id, o in m.servers)
|
||||
if (id != srv.id && o.port == n)
|
||||
die(`UDP ${n} is used by ${o.name}.`);
|
||||
if (n != srv.port)
|
||||
check_udp_port(n, udp_taken(m, srv, srv.wan_zone));
|
||||
set('port', `${n}`);
|
||||
}
|
||||
if (v.enabled != null)
|
||||
@@ -451,7 +512,7 @@ function server_update(a) {
|
||||
for (let k, label in labels) {
|
||||
if (v[k] == null)
|
||||
continue;
|
||||
let was = k == 'dns' ? join(' ', srv.dns ?? []) : `${srv[k] ?? ''}`;
|
||||
let was = k == 'dns' ? join(' ', srv.dns ?? []) : k == 'mtu' && !srv.mtu ? '' : `${srv[k] ?? ''}`;
|
||||
let now = k == 'dns' ? join(' ', dns_list(v.dns)) : str(v[k]);
|
||||
if (trim(was) != trim(now))
|
||||
push(what, label);
|
||||
|
||||
@@ -11,7 +11,7 @@ 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';
|
||||
import { wrap, check_portal, tcp_taken } 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' ];
|
||||
@@ -65,7 +65,7 @@ function settings_get(a) {
|
||||
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),
|
||||
tcp_taken: tcp_taken(m),
|
||||
portal_public_port: core.portal_public_port(m),
|
||||
geo_cached: length(keys(geo.load().ips)),
|
||||
logs: logs_info(m),
|
||||
|
||||
@@ -10,6 +10,7 @@ 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 { wrap, clamp_days } from 'dawnline.rpc.common';
|
||||
|
||||
/** Router location plus one point per (device, recent client address). */
|
||||
@@ -19,14 +20,25 @@ function geo_view(m, usage, dmp) {
|
||||
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 are not shown on the map.
|
||||
let pl = geo.is_public(ip) ? geo.place(cache, ip) : null;
|
||||
// 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, {
|
||||
@@ -76,6 +88,8 @@ function server_view(m, srv, usage, dmp, rates, days) {
|
||||
id: srv.id, name: srv.name, ifname: srv.ifname, port: srv.port, subnet: srv.subnet,
|
||||
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.
|
||||
blocked: srv.blocked ?? null,
|
||||
@@ -142,7 +156,7 @@ function status(a) {
|
||||
settings: {
|
||||
portal_enabled: s.portal_enabled, portal_port: s.portal_port, portal_host: s.portal_host,
|
||||
portal_public_port: core.portal_public_port(m),
|
||||
paused_all: s.paused_all, default_device_limit: s.default_device_limit, domain: s.domain,
|
||||
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,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
|
||||
|
||||
export const VERSION = '0.4.2';
|
||||
export const VERSION = '0.5.0';
|
||||
/** GitHub repository with Dawnline releases (updates and the installer). */
|
||||
export const REPO = 'tickcount/luci-app-dawnline';
|
||||
export const RUN_DIR = '/var/run/dawnline';
|
||||
@@ -273,19 +273,31 @@ const INTENT = `${RUN_DIR}/iface-intent.json`;
|
||||
|
||||
export function iface_intent(ifname, reason, name) {
|
||||
let all = read_json(INTENT, {});
|
||||
all[ifname] = { reason, name, ts: time() };
|
||||
let now = time();
|
||||
for (let k, v in all)
|
||||
if (now - v.ts >= 120)
|
||||
delete all[k];
|
||||
all[ifname] = { reason, name, ts: now };
|
||||
ensure_dir(RUN_DIR);
|
||||
write_json(INTENT, all, 0o600);
|
||||
};
|
||||
|
||||
/**
|
||||
* The note for a stop of `ifname`, or null. netifd may report one stop more
|
||||
* than once (the interface, then its device): the note covers every report
|
||||
* within 15 s of the first, then it is spent.
|
||||
*/
|
||||
export function take_iface_intent(ifname) {
|
||||
let all = read_json(INTENT, {});
|
||||
let it = all[ifname];
|
||||
if (!it)
|
||||
let now = time();
|
||||
if (!it || now - it.ts >= 120 || (it.used && now - it.used >= 15))
|
||||
return null;
|
||||
delete all[ifname];
|
||||
write_json(INTENT, all, 0o600);
|
||||
return time() - it.ts < 120 ? it : null;
|
||||
if (!it.used) {
|
||||
it.used = now;
|
||||
write_json(INTENT, all, 0o600);
|
||||
}
|
||||
return it;
|
||||
};
|
||||
|
||||
/** Newest first. */
|
||||
|
||||
@@ -65,7 +65,8 @@ function probes(m) {
|
||||
repair: { what: 'restarting it', run: restart_services },
|
||||
});
|
||||
|
||||
if (stat(loop.RESOLVER.conf))
|
||||
// Only while a server is on: with all of them off it idles on loopback.
|
||||
if (stat(loop.RESOLVER.conf) && length(filter(values(m.servers), (x) => x.enabled && x.private_key)))
|
||||
push(out, {
|
||||
id: 'resolver', src: 'dawnline', name: 'Resolver', who: 'DNS for Home-only devices', ok: loop.resolver_running(),
|
||||
problem: "isn't running", back: 'runs again',
|
||||
|
||||
Reference in new issue
Block a user