Files
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

236 lines
7.7 KiB
Go

// Package roster makes the stream's topics from what the watcher knows (package view): the people and their
// devices, the servers, the router's own facts, the traffic, the places and the newest of the activity
// log. Publish puts them on the hub, whole; the hub tells the pages only what changed.
package roster
import (
"encoding/json"
"sort"
"github.com/tickcount/luci-app-dawnline/backend/files"
"github.com/tickcount/luci-app-dawnline/backend/hub"
"github.com/tickcount/luci-app-dawnline/backend/model"
"github.com/tickcount/luci-app-dawnline/backend/usage"
"github.com/tickcount/luci-app-dawnline/backend/view"
)
// RecentKept is how many of the log's newest entries a status carries.
const RecentKept = 60
// Days is how long the router's daily series is.
const Days = 60
// Roster makes the topics.
type Roster struct {
// World is the watcher's (nil until it has looked); Home the home networks a person reaches.
World func() *view.World
Home func(srv *model.Server, p *model.Person) []string
// DataDir holds what was handed out and who was set up again (issued.json, reconnect.json).
DataDir string
Hub *hub.Hub
Log func(format string, args ...any)
// RunDir holds the agent's last minutes of speed by person (rate_people.json), which a person's view carries.
RunDir string
// Own is the router's own addresses, which are no place people connect from.
Own func(m *model.Model) map[string]bool
// Iface is a netifd interface's state; Homes a server's home interfaces.
Iface func(ifname string) (bool, int64)
Homes func(srv *model.Server) []view.HomeNet
// Handler tells whether netifd lists the amneziawg protocol; WAN is the router's WAN address.
Handler func() bool
WAN func(m *model.Model) string
// Recent is the newest entries of the activity log as a page is shown them (the watcher's).
Recent func(n int) []map[string]any
// Keyed makes a list of the status into the stream's keyed form (bridge.Split's own, so both write one shape).
Keyed func(status map[string]any) map[string]any
}
// Publish puts Go's own people on the stream now: called the moment the watcher saw something change, so a
// page is told at once and ucode is not asked for it. False: nothing was put, because the watcher has no
// world yet (it has not read the settings); whoever needs the topics asks again.
func (r *Roster) Publish() bool {
if r.Keyed == nil {
return false
}
w := r.world()
if w == nil {
return false
}
var rates map[string]any
files.ReadJSON(r.RunDir+"/rate_people.json", &rates)
people := make([]view.Person, 0, len(w.M.People))
for _, p := range w.M.People {
people = append(people, w.PersonOf(p, true))
}
// as the status sorts them: who is online first, then who was seen last, then by name
sort.SliceStable(people, func(i, j int) bool {
a, b := people[i], people[j]
if a.Online != b.Online {
return a.Online > b.Online
}
if a.LastSeen != b.LastSeen {
return a.LastSeen > b.LastSeen
}
return a.Name < b.Name
})
raw, _ := json.Marshal(people)
var list []any
json.Unmarshal(raw, &list)
for _, p := range list {
m := p.(map[string]any)
m["rate"] = []any{}
if rate, ok := rates[m["id"].(string)].([]any); ok && len(rate) > 0 {
if _, isList := rate[0].([]any); isList {
m["rate"] = rate
}
}
}
// the router's sums, its days (as long as the bridge asks ucode for) and its last 24 hours
recs := make([]*usage.Record, 0, len(w.Usage.People))
for _, rec := range w.Usage.People {
recs = append(recs, rec)
}
traffic := map[string]any{"totals": w.TotalsOf(people), "series": view.Series(recs, Days, w.Now), "hours": view.LastHours(w.Usage.Hours, w.Now)}
raw, _ = json.Marshal(traffic)
var plain map[string]any
json.Unmarshal(raw, &plain)
plain["people"] = list
// the services and the circles, in the order the settings list them
var services, circles []any
for _, id := range w.M.ServiceIDs() {
services = append(services, w.M.Services[id])
}
for _, id := range w.M.CircleIDs() {
circles = append(circles, w.M.Circles[id])
}
raw, _ = json.Marshal(map[string]any{"services": services, "circles": circles})
var lists map[string]any
json.Unmarshal(raw, &lists)
for _, k := range []string{"services", "circles"} {
if lists[k] == nil {
lists[k] = []any{}
}
plain[k] = lists[k]
}
if r.Recent != nil {
raw, _ = json.Marshal(r.Recent(RecentKept))
var events any
json.Unmarshal(raw, &events)
plain["events"] = events
}
if r.Own != nil {
raw, _ = json.Marshal(r.places(w))
var geo any
json.Unmarshal(raw, &geo)
plain["geo"] = geo
}
owned := []string{"people", "traffic", "services", "circles", "recent", "places"}
if r.Iface != nil && r.Own != nil {
var rates map[string]any
files.ReadJSON(r.RunDir+"/rate.json", &rates)
router := r.router(w)
var servers []any
for _, id := range w.M.ServerIDs() {
raw, _ := json.Marshal(w.ServerOf(w.M.Servers[id], Days, router))
var sv map[string]any
json.Unmarshal(raw, &sv)
// why it is kept down, if it is (Owns: a reason Go can word), and its last minutes of speed (the agent's file)
text, worded := blockedText(w.M.Servers[id])
if !worded {
// a reason kept in a shape nobody here knows: still said, in the plainest words
text = w.M.Servers[id].Name + " is kept down."
}
sv["blocked"] = text
sv["rate"] = []any{}
if rate, ok := rates[id].([]any); ok {
sv["rate"] = rate
}
servers = append(servers, sv)
}
if servers == nil {
servers = []any{}
}
plain["servers"] = servers
owned = append(owned, "servers")
}
if r.Iface != nil && r.Own != nil {
// what could be told is told: a fact that could not be read is better missing than the whole router
if facts, _ := r.routerOf(w.M, w.Now); true {
raw, _ = json.Marshal(facts)
var m map[string]any
json.Unmarshal(raw, &m)
tz := m["tz"]
for k, v := range m {
plain[k] = v
}
plain["now"], plain["tz"] = w.Now, tz
owned = append(owned, "router", "clock")
}
}
docs := r.Keyed(plain)
for _, topic := range owned {
if doc, ok := docs[topic]; ok {
r.Hub.Put(topic, doc)
}
}
return true
}
// router is what a server's view asks of the router, or nil when nobody answers for it.
func (r *Roster) router(w *view.World) *view.Router {
if r.Own == nil || r.Iface == nil {
return nil
}
return &view.Router{Own: r.Own(w.M), Iface: r.Iface, Homes: r.Homes}
}
// places is the map's data as Go makes it.
func (r *Roster) places(w *view.World) view.Places {
var cache view.PlaceCache
if !files.ReadJSON(r.RunDir+"/geo.json", &cache) {
files.ReadJSON(r.DataDir+"/geo.json", &cache)
}
return w.PlacesOf(&cache, r.Own(w.M))
}
// world is the watcher's world with what the watcher does not hold.
func (r *Roster) world() *view.World {
return Complete(r.World(), r.Home, r.DataDir)
}
// Complete gives the watcher's world what a view needs besides: the home networks a person reaches, what
// each device was last given and when each was set up again. nil stays nil.
func Complete(w *view.World, home func(srv *model.Server, p *model.Person) []string, dataDir string) *view.World {
if w == nil {
return nil
}
w.Home = home
w.Issued = issued(dataDir + "/issued.json")
files.ReadJSON(dataDir+"/reconnect.json", &w.Reconnect)
return w
}
// issued reads issued.json as dawnline.awg issued() does: an entry is { fp, ts }, or from before
// timestamps were kept the fingerprint alone.
func issued(path string) map[string]view.Issued {
var raw map[string]json.RawMessage
files.ReadJSON(path, &raw)
out := map[string]view.Issued{}
for id, v := range raw {
var fp string
var e view.Issued
if json.Unmarshal(v, &fp) == nil {
if fp != "" {
out[id] = view.Issued{FP: fp}
}
} else if json.Unmarshal(v, &e) == nil && e.FP != "" {
if e.TS < 0 {
e.TS = 0
}
out[id] = e
}
}
return out
}