Files
dawnline/package/luci-app-dawnline/root/usr/share/ucode/dawnline/resolver.uc
T
Aemeath 972e522518
Build packages / Version (push) Waiting to run
Dawnline 0.5.0
- 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
2026-10-17 01:03:23 +03:00

102 lines
3.5 KiB
Ucode

// Dawnline — the plain resolver for people with Home-only access: real
// addresses from the WAN's DNS, home names from the LAN DNS. Their internet
// does not use the tunnel, so fake-IP answers would break it. dawnline.loop
// says where it runs (inside the netns while it exists, otherwise on the
// tunnel interfaces); procd runs dnsmasq through /usr/libexec/dawnline/resolver.
import { readfile, writefile, stat } from 'fs';
import { cursor } from 'uci';
import { ensure_dir, iface_status, uniq } from 'dawnline.util';
import * as net from 'dawnline.net';
import * as core from 'dawnline.core';
/** Port on the tunnel addresses while it runs on the router itself. */
export const PORT = 5354;
export const CONF = '/var/etc/dawnline-dns.conf';
const RESOLV = '/var/etc/dawnline-dns.resolv';
const PID = '/var/run/dawnline-dns.pid';
const FALLBACK_DNS = [ '1.1.1.1', '8.8.8.8' ];
function wan_dns() {
let out = [];
let snap = net.snapshot();
let wan = snap.devices[snap.wan]?.logical;
for (let name in uniq([ wan, 'wan', 'wan6' ])) {
if (!name)
continue;
for (let a in iface_status(name)?.['dns-server'] ?? [])
if (match(a, /^[0-9.]+$/))
push(out, a);
}
return length(out) ? uniq(out) : FALLBACK_DNS;
}
/** Local domain of the LAN DNS (dnsmasq `domain`, else the Dawnline hostname domain). */
function lan_domain(m) {
let c = cursor();
c.load('dhcp');
let d = null;
c.foreach('dhcp', 'dnsmasq', (s) => { d ??= s.domain; });
return uniq(filter([ d, m.settings.domain ], (x) => x));
}
/** True when the resolver process is alive. */
export function running() {
let pid = trim(readfile(PID) ?? '');
return match(pid, /^[0-9]+$/) != null && stat(`/proc/${pid}`) != null;
};
/**
* Write the config for `target` (dawnline.loop resolver_target) with home
* names from `lan` (the LAN's DNS); returns true when it changed (the running
* instance is then restarted by procd's respawn after a kill). The first line
* tells /usr/libexec/dawnline/resolver where to run it.
*/
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)
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.',
`port=${target.port}`,
'no-hosts',
'bogus-priv',
'cache-size=1000',
`pid-file=${PID}`,
'user=dnsmasq',
'group=dnsmasq',
];
if (target.mode == 'ns') {
push(lines, `listen-address=${target.address}`, 'bind-interfaces', 'no-resolv');
// Upstream from the transit address: forwarded through the router to the WAN.
for (let a in wan_dns())
push(lines, `server=${a}@${target.address}`);
}
else {
// 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) {
writefile(RESOLV, resolv);
system(`chmod 644 ${RESOLV}`);
}
}
if (lan)
for (let d in lan_domain(m))
push(lines, `server=/${d}/${lan}`);
let conf = join('\n', lines) + '\n';
if ((readfile(CONF) ?? '') == conf)
return false;
writefile(CONF, conf);
system(`chmod 644 ${CONF}`);
let pid = trim(readfile(PID) ?? '');
if (match(pid, /^[0-9]+$/))
system(`kill ${pid} 2>/dev/null`);
return true;
};