Files
dawnline/package/luci-app-dawnline/root/etc/init.d/dawnline
T
Aemeath ac90575b0b
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 / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
Dawnline 0.20.0
- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode.
- **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V).
- **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request.
- **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds.
- **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person.
- **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router.
- **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch.
- **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away.
- **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once.
- **Undo.** An action done from a card or a request is undone from its toast.
- **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own.
- **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name.
- **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking.
- **Check access and Health know the networks behind routers.**
- **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st.
- Extra data lasts until that person's month ends; «Reset usage» starts the month anew.
- A limit is for a month or for the whole term; the admin and the portal show when it resets.
- Charts that said «this month» show the last 30 days.
- After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st.
- **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped.
- **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone.
- **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence.
- **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
2026-11-13 09:43:50 +03:00

133 lines
5.7 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# shellcheck shell=dash disable=SC2034 # START/STOP/USE_PROCD are read by /etc/rc.common
# Dawnline: AmneziaWG access server — its backend (which also serves the personal portal) and the
# resolver for Home-only devices.
START=95
STOP=10
USE_PROCD=1
# A line in syslog as the backend writes them: "dawnline: [info] [service] …" at the
# matching priority, when the admin's level (settings.log_level: error|warn|info|debug) takes it.
log() {
local lvl="$1" want rank prio
shift
want="$(uci -q get dawnline.settings.log_level)"
case "$lvl" in error) rank=0 prio=err ;; warn) rank=1 prio=warning ;; debug) rank=3 prio=debug ;; *) rank=2 prio=info ;; esac
case "$want" in error) want=0 ;; warn) want=1 ;; debug) want=3 ;; *) want=2 ;; esac
[ "$rank" -le "$want" ] || return 0
logger -t dawnline -p "daemon.$prio" "[$lvl] [service] $*"
}
# What the portal runs with, worked out once for whoever serves it: P_PORT (empty: no portal, said in the
# log), P_CERT, P_KEY, P_HPORT (plain HTTP for links with an IP address, or empty), P_PROCS.
portal_plan() {
local enabled certs mem
P_PORT='' P_CERT='' P_KEY='' P_HPORT=''
config_get_bool enabled settings portal_enabled 0
if [ "$enabled" != 1 ]; then
log info "personal portal is off"
return 0
fi
certs="$(/usr/bin/dawnline portal-cert 2>/dev/null)"
P_CERT="${certs% *}"
P_KEY="${certs#* }"
if ! [ -f "$P_CERT" ] || ! [ -f "$P_KEY" ]; then
log warn "personal portal not started: no certificate (${P_CERT:-none}): choose one in Settings, or save the portal settings again"
return 0
fi
config_get P_PORT settings portal_port 8443
# IP addresses in links get plain HTTP on the next port (names stay HTTPS-only).
P_HPORT="$(/usr/bin/dawnline portal-http-port 2>/dev/null)"
return 0
}
start_portal() {
[ -n "$P_PORT" ] || return 0
local until
until="$(openssl x509 -enddate -noout -in "$P_CERT" 2>/dev/null | sed 's/^notAfter=/ until /')"
log info "personal portal on port $P_PORT (HTTPS${P_HPORT:+, plain HTTP on $P_HPORT for links with an IP address}) · certificate $P_CERT$until · served by the backend"
}
# Plain DNS for Home-only tunnel devices (config written by `dawnline apply`).
start_resolver() {
if ! [ -f /var/etc/dawnline-dns.conf ]; then
log debug "no DNS for Home-only devices (nobody needs it)"
return 0
fi
procd_open_instance dns
procd_set_param command /usr/libexec/dawnline/resolver
procd_set_param file /var/etc/dawnline-dns.conf
# A new config kills it (the backend's apply): back within a second, not five.
procd_set_param respawn 3600 1 0
procd_close_instance
log info "DNS for Home-only devices started (/var/etc/dawnline-dns.conf)"
}
# The backend (dawnlined, docs/backend.md): it looks at the tunnels, keeps the router to the settings,
# answers the pages and their stream, and serves the personal portal.
start_backend() {
local bin=/usr/libexec/dawnline/dawnlined stream=poll built portal=''
# No binary here (a fresh install with no network, a download that failed): fetched in the background,
# once a boot, and the service started again with it.
if [ ! -x "$bin" ] && [ ! -e /var/run/dawnline/backend.asked ]; then
: > /var/run/dawnline/backend.asked
( /usr/libexec/dawnline/fetch-backend && [ -x "$bin" ] && /etc/init.d/dawnline restart ) </dev/null >/dev/null 2>&1 &
fi
if ! [ -x "$bin" ] || ! "$bin" -version >/dev/null 2>&1; then
log error "the backend is not on this router ($bin): Dawnline does not run until it is · /usr/libexec/dawnline/fetch-backend puts it in place"
return 0
fi
# uhttpd holds an event stream without losing its connection only since 2026-08-03 (an older one stops
# serving after a hundred of them): before that the pages follow by a held call.
built="$({ apk list -I uhttpd-mod-ubus 2>/dev/null || opkg list-installed uhttpd-mod-ubus 2>/dev/null; } |
sed -n 's/.*uhttpd-mod-ubus[- ]*\([0-9]\{4\}\)[.-]\([0-9]\{2\}\)[.-]\([0-9]\{2\}\).*/\1\2\3/p' | head -n 1)"
[ -n "$built" ] && [ "$built" -ge 20260803 ] && stream=sse
# The portal: its certificate is read again when it is renewed, so no restart follows a renewal.
[ -n "$P_PORT" ] && portal="-portal-port $P_PORT -portal-cert $P_CERT -portal-key $P_KEY${P_HPORT:+ -portal-http $P_HPORT}"
procd_open_instance backend
# shellcheck disable=SC2086 # the portal's options are words on purpose
procd_set_param command "$bin" -stream "$stream" $portal
procd_set_param respawn 3600 5 0
procd_set_param stderr 1
procd_close_instance
log info "backend started · the pages follow by $stream"
}
start_service() {
config_load dawnline
mkdir -p /var/run/dawnline
log info "starting"
# The apply writes its own lines: what it came to and how long it took (each step at debug).
/usr/bin/dawnline apply >/dev/null 2>&1 || log error "applying the configuration failed: run \"dawnline apply\" to see why"
portal_plan
start_backend
start_portal
start_resolver
log info "started"
}
# Noted for the service log: the backend's next start is a restart, not a crash or a boot.
stop_service() {
log info "stopping"
mkdir -p /var/run/dawnline
date +%s > /var/run/dawnline/agent.stopped
# An agent left by a version from before the backend did its work goes too.
pgrep -f '^/usr/bin/ucode /usr/libexec/dawnline/agent' | xargs -r kill 2>/dev/null
}
reload_service() {
log info "reloading: settings changed"
/usr/bin/dawnline apply >/dev/null 2>&1 || log error "applying the configuration failed: run \"dawnline apply\" to see why"
start
}
service_triggers() {
procd_add_reload_trigger dawnline
# A certificate issued for the first time changes what the portal is served with: the service is
# planned again (a renewed one the backend reads by itself).
procd_add_raw_trigger acme.issue 5000 /etc/init.d/dawnline reload
procd_add_raw_trigger acme.renew 5000 /etc/init.d/dawnline reload
}