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.
202 lines
6.8 KiB
Go
202 lines
6.8 KiB
Go
// Package presence tells who is online: from one look at the tunnels to the next, which devices connected,
|
|
// left or moved to another address. It is the agent's watcher (libexec/agent watch(), dawnline.live) in Go,
|
|
// rule for rule.
|
|
//
|
|
// Online means the device's WireGuard session lives: a handshake within its online window
|
|
// (model.OnlineWindowOf). Traffic silence is no signal; a phone asleep is silent too.
|
|
//
|
|
// A Watcher holds what it saw last; Look is pure given that: the settings, a look at the tunnels and the
|
|
// clock go in, the events and who they concern come out. Whoever runs it publishes them.
|
|
package presence
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
|
"github.com/tickcount/luci-app-dawnline/backend/model"
|
|
)
|
|
|
|
// The events of a look.
|
|
const (
|
|
Connect = "connect"
|
|
Disconnect = "disconnect"
|
|
Roam = "roam"
|
|
)
|
|
|
|
// RestartGrace is how long a device missing from a tunnel that was just set up again keeps what was known
|
|
// of it (seconds). netifd deletes and adds a tunnel's link each time it sets it up: the devices come back
|
|
// only with the sync its hotplug starts, and then with no handshake until each makes a new one. Without
|
|
// the grace, that is a burst of disconnects and connects for everyone online.
|
|
const RestartGrace = 45
|
|
|
|
// Event is a device connecting, leaving or moving.
|
|
type Event struct {
|
|
Type string `json:"type"`
|
|
Person string `json:"person"`
|
|
Device string `json:"device"`
|
|
// Detail is the address it connected from, or "old → new" for a move.
|
|
Detail string `json:"detail,omitempty"`
|
|
}
|
|
|
|
// Watcher is who was online at the last look.
|
|
type Watcher struct {
|
|
// Online and Endpoint are what a page is shown: a device's state and the address it last spoke from.
|
|
Online map[string]bool
|
|
Endpoint map[string]string
|
|
|
|
// Per device: its latest real handshake, kept when the tunnel adds the peer again (its counters and
|
|
// handshake restart from zero), and the key it was seen with (new keys end the old session, whatever
|
|
// its handshake said).
|
|
handshake map[string]int64
|
|
key map[string]string
|
|
// Per tunnel: the link last seen (0 while it is down), and until when its grace lasts.
|
|
link map[string]int
|
|
grace map[string]int64
|
|
}
|
|
|
|
// New starts from what was kept of the last run (nil for nothing), so a restart does not swallow the
|
|
// connects that happened in between.
|
|
func New(online map[string]bool, endpoint map[string]string) *Watcher {
|
|
w := &Watcher{Online: map[string]bool{}, Endpoint: map[string]string{},
|
|
handshake: map[string]int64{}, key: map[string]string{}, link: map[string]int{}, grace: map[string]int64{}}
|
|
for k, v := range online {
|
|
w.Online[k] = v
|
|
}
|
|
for k, v := range endpoint {
|
|
w.Endpoint[k] = v
|
|
}
|
|
return w
|
|
}
|
|
|
|
// Seen is what a look found.
|
|
type Seen struct {
|
|
Events []Event
|
|
// People are those whose pages changed (someone's device came, went or moved), in the order found.
|
|
People []string
|
|
// Addresses are those to locate: a connect's and a move's new one.
|
|
Addresses []string
|
|
// Rekeyed are the devices whose key changed since the last look: what was known of their link is void.
|
|
Rekeyed []string
|
|
}
|
|
|
|
// Link is called for every device of a look, once it is known whether the device is online and before
|
|
// anything is concluded from its address: with its peer (nil when it is not in its tunnel) and whether its
|
|
// key changed since the last look. It is where the link's history is kept (package link); it returns true
|
|
// for a device whose address goes back and forth all the time (one configuration on two devices): that is
|
|
// no roaming, nor a reason to tell anyone.
|
|
type Link func(device string, peer *awg.Peer, online, rekeyed bool) (shared bool)
|
|
|
|
// Look takes one look at the tunnels (link may be nil). A tunnel that could not be read says nothing about
|
|
// its devices, which stay as they were.
|
|
func (w *Watcher) Look(m *model.Model, d awg.Dump, now int64, link Link) Seen {
|
|
var s Seen
|
|
told := map[string]bool{}
|
|
tell := func(person string) {
|
|
if !told[person] {
|
|
told[person] = true
|
|
s.People = append(s.People, person)
|
|
}
|
|
}
|
|
for ifname, read := range d.Reads {
|
|
if read == awg.Failed {
|
|
continue
|
|
}
|
|
index := 0
|
|
if ifc, ok := d.Ifaces[ifname]; ok {
|
|
index = ifc.Ifindex
|
|
}
|
|
if was, seen := w.link[ifname]; seen && was != index {
|
|
w.grace[ifname] = now + RestartGrace
|
|
}
|
|
w.link[ifname] = index
|
|
}
|
|
for ifname := range w.link {
|
|
if _, asked := d.Reads[ifname]; !asked {
|
|
delete(w.link, ifname)
|
|
delete(w.grace, ifname)
|
|
}
|
|
}
|
|
for _, id := range m.DeviceIDs() {
|
|
dev := m.Devices[id]
|
|
var srv *model.Server
|
|
ifname := ""
|
|
if p := m.People[dev.Person]; p != nil {
|
|
if srv = m.Servers[p.Server]; srv != nil {
|
|
ifname = srv.Ifname
|
|
}
|
|
}
|
|
if d.Reads[ifname] == awg.Failed {
|
|
continue
|
|
}
|
|
// New keys: offline until they shake hands.
|
|
rekeyed := false
|
|
if was, known := w.key[id]; !known || was != dev.PublicKey {
|
|
if known {
|
|
w.handshake[id] = 0
|
|
s.Rekeyed = append(s.Rekeyed, id)
|
|
rekeyed = true
|
|
}
|
|
w.key[id] = dev.PublicKey
|
|
}
|
|
endpoint := ""
|
|
peer, there := d.Peers[dev.PublicKey]
|
|
if there {
|
|
w.handshake[id] = max(w.handshake[id], peer.Handshake)
|
|
endpoint = EndpointIP(peer.Endpoint)
|
|
} else if !(w.grace[ifname] > now) {
|
|
// Not in the tunnel (turned off, paused, out of time or data): offline now, and online again
|
|
// only with a new handshake, not the one remembered from before. Unless its tunnel was just
|
|
// set up again and the sync has not brought it back yet.
|
|
w.handshake[id] = 0
|
|
}
|
|
on := w.handshake[id] > 0 && now-w.handshake[id] < int64(model.OnlineWindowOf(srv, dev))
|
|
was := w.Online[id]
|
|
last := w.Endpoint[id]
|
|
shared := false
|
|
if link != nil {
|
|
var p *awg.Peer
|
|
if there {
|
|
p = &peer
|
|
}
|
|
shared = link(id, p, on, rekeyed)
|
|
}
|
|
switch {
|
|
case on && !was:
|
|
s.Events = append(s.Events, Event{Type: Connect, Person: dev.Person, Device: id, Detail: endpoint})
|
|
s.Addresses = append(s.Addresses, endpoint)
|
|
case !on && was:
|
|
s.Events = append(s.Events, Event{Type: Disconnect, Person: dev.Person, Device: id})
|
|
case on && endpoint != "" && last != "" && endpoint != last && !shared:
|
|
s.Events = append(s.Events, Event{Type: Roam, Person: dev.Person, Device: id, Detail: last + " → " + endpoint})
|
|
s.Addresses = append(s.Addresses, endpoint)
|
|
}
|
|
if on != was || (endpoint != "" && endpoint != last && !shared) {
|
|
tell(dev.Person)
|
|
}
|
|
w.Online[id] = on
|
|
if endpoint != "" {
|
|
w.Endpoint[id] = endpoint
|
|
}
|
|
}
|
|
for id := range w.Online {
|
|
if m.Devices[id] == nil {
|
|
delete(w.Online, id)
|
|
delete(w.Endpoint, id)
|
|
delete(w.handshake, id)
|
|
delete(w.key, id)
|
|
}
|
|
}
|
|
return s
|
|
}
|
|
|
|
// "203.0.113.7:41821", "[2001:db8::1]:41821".
|
|
var endpoint = regexp.MustCompile(`^\[?([^\]]+)\]?:[0-9]+$`)
|
|
|
|
// EndpointIP is the address of an endpoint, without its port.
|
|
func EndpointIP(ep string) string {
|
|
if g := endpoint.FindStringSubmatch(ep); g != nil {
|
|
return g[1]
|
|
}
|
|
return ep
|
|
}
|