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
- **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.
175 lines
5.5 KiB
Go
175 lines
5.5 KiB
Go
// What follows from the settings about time and tunnels: a device's keep-alive, how long it may go
|
|
// between two handshakes, how long after one it still counts as online, and which tunnel a server has.
|
|
// As dawnline.core, dawnline.awg and dawnline.live work them out (tests/ucode/awg.test.uc has the cases
|
|
// these are held to). Pure: the settings in, numbers out.
|
|
|
|
package model
|
|
|
|
import (
|
|
"net/netip"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// OnlineWindow is how long after its handshake a device counts as online, at the least: a WireGuard
|
|
// session is dropped 180 s after its handshake and a device that is there renews it every 2 minutes
|
|
// (a little slack for a renewal that needs a retry).
|
|
OnlineWindow = 190
|
|
// SleepWindow is the same for a phone or a tablet: asleep, its system holds the tunnel's timers and its
|
|
// session lapses for minutes and comes back by itself. That silence is sleep, not leaving.
|
|
SleepWindow = 600
|
|
// A device's own keep-alive is taken within this range (seconds; 0 is off).
|
|
keepaliveMax = 600
|
|
)
|
|
|
|
// DeviceKeepalive is the keep-alive a device's configuration carries, in seconds (0: off): its own when the
|
|
// admin set one, else the server's.
|
|
func DeviceKeepalive(srv *Server, dev *Device) int {
|
|
if dev != nil && dev.Keepalive != nil && *dev.Keepalive >= 0 && *dev.Keepalive <= keepaliveMax {
|
|
return *dev.Keepalive
|
|
}
|
|
return srv.Keepalive
|
|
}
|
|
|
|
// KeepaliveRange is that keep-alive as the device sends it, lo to hi seconds; ok is false when it is off.
|
|
// With header protection (AmneziaWG 3.1, whose apps take ranges) it is jittered over ten seconds, since a
|
|
// fixed beat would be the one regular thing left.
|
|
func KeepaliveRange(srv *Server, dev *Device) (lo, hi int, ok bool) {
|
|
k := DeviceKeepalive(srv, dev)
|
|
if k <= 0 {
|
|
return 0, 0, false
|
|
}
|
|
if srv.Obf["header_protection_key"] != "" {
|
|
return k, k + 10, true
|
|
}
|
|
return k, k, true
|
|
}
|
|
|
|
// IdleHandshake is the longest an idle device goes between two handshakes, in seconds; ok is false when
|
|
// its keep-alive is off (an idle device then sends nothing at all). Its keep-alives are what it sends, and
|
|
// the first one after its key's rekey time (WireGuard's 120 s; past 180 s the key is refused anyway)
|
|
// starts a handshake: up to one keep-alive past that time, or each keep-alive once they are further apart.
|
|
func IdleHandshake(srv *Server, dev *Device) (int, bool) {
|
|
lo, hi, ok := KeepaliveRange(srv, dev)
|
|
if !ok {
|
|
return 0, false
|
|
}
|
|
rekey := 120
|
|
if _, top, given := uintRange(srv.Obf["rekey_after_time"], 65535); given && top != 0 {
|
|
rekey = top
|
|
}
|
|
rekey = min(rekey, 180)
|
|
if lo > rekey {
|
|
return hi, true
|
|
}
|
|
return rekey + hi, true
|
|
}
|
|
|
|
// OnlineWindowOf is how long after its last handshake a device still counts as online, in seconds:
|
|
// OnlineWindow, or 30 s more than an idle device goes between handshakes when that is longer (it renews
|
|
// its session only with its keep-alive, and a fixed window would see it leave and come back between two).
|
|
// A phone or a tablet never less than SleepWindow.
|
|
func OnlineWindowOf(srv *Server, dev *Device) int {
|
|
w := OnlineWindow
|
|
if srv != nil {
|
|
if h, ok := IdleHandshake(srv, dev); ok {
|
|
w = max(w, h+30)
|
|
}
|
|
}
|
|
if dev != nil && has(MobileKinds, dev.Kind) {
|
|
w = max(w, SleepWindow)
|
|
}
|
|
return w
|
|
}
|
|
|
|
// uintOf is a whole number as AmneziaWG writes one, up to top.
|
|
func uintOf(s string, top int) (int, bool) {
|
|
if s == "" || len(s) > 10 {
|
|
return 0, false
|
|
}
|
|
for i := 0; i < len(s); i++ {
|
|
if s[i] < '0' || s[i] > '9' {
|
|
return 0, false
|
|
}
|
|
}
|
|
n, err := strconv.Atoi(s)
|
|
return n, err == nil && n <= top
|
|
}
|
|
|
|
// uintRange is a number or a range as AmneziaWG writes them ("5", "5-15"), each end up to top.
|
|
func uintRange(v string, top int) (lo, hi int, ok bool) {
|
|
p := strings.Split(strings.TrimSpace(v), "-")
|
|
if len(p) > 2 {
|
|
return 0, 0, false
|
|
}
|
|
lo, ok = uintOf(p[0], top)
|
|
if !ok {
|
|
return 0, 0, false
|
|
}
|
|
hi = lo
|
|
if len(p) == 2 {
|
|
if hi, ok = uintOf(p[1], top); !ok {
|
|
return 0, 0, false
|
|
}
|
|
}
|
|
return lo, hi, lo <= hi
|
|
}
|
|
|
|
// Tunnel is a server's link.
|
|
type Tunnel struct {
|
|
Ifname string
|
|
Subnet string
|
|
// Address is the router's own in the tunnel: the subnet's first.
|
|
Address string
|
|
}
|
|
|
|
var ifname = regexp.MustCompile(`^[a-z][a-z0-9_]{0,11}$`)
|
|
|
|
// ValidIfname tells a server's interface name: also a netifd section and an nftables string, so nothing else.
|
|
func ValidIfname(s string) bool { return ifname.MatchString(s) }
|
|
|
|
// TunnelOf is the server's tunnel: it has one when it has its keys, is not kept down, and its interface's
|
|
// name and subnet are usable.
|
|
func TunnelOf(srv *Server) (Tunnel, bool) {
|
|
if srv == nil || srv.PrivateKey == "" || srv.Blocked != nil || !ValidIfname(srv.Ifname) {
|
|
return Tunnel{}, false
|
|
}
|
|
p, ok := parseCIDR(srv.Subnet)
|
|
if !ok {
|
|
return Tunnel{}, false
|
|
}
|
|
return Tunnel{Ifname: srv.Ifname, Subnet: srv.Subnet, Address: p.Masked().Addr().Next().String()}, true
|
|
}
|
|
|
|
// TunnelIfnames is the interfaces of the servers that run: turned on, with a tunnel that is Dawnline's.
|
|
// What the tunnels' reader is asked for.
|
|
func (m *Model) TunnelIfnames() []string {
|
|
out := []string{}
|
|
for _, id := range m.serverIDs {
|
|
srv := m.Servers[id]
|
|
if !srv.Enabled {
|
|
continue
|
|
}
|
|
if t, ok := TunnelOf(srv); ok {
|
|
out = append(out, t.Ifname)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
var cidr = regexp.MustCompile(`^[0-9.]+/[0-9]+$`)
|
|
|
|
// parseCIDR reads "a.b.c.d/len" with a prefix a tunnel can have (8 to 30).
|
|
func parseCIDR(s string) (netip.Prefix, bool) {
|
|
if !cidr.MatchString(s) {
|
|
return netip.Prefix{}, false
|
|
}
|
|
p, err := netip.ParsePrefix(s)
|
|
if err != nil || !p.Addr().Is4() || p.Bits() < 8 || p.Bits() > 30 {
|
|
return netip.Prefix{}, false
|
|
}
|
|
return p, true
|
|
}
|