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.
211 lines
4.5 KiB
Go
211 lines
4.5 KiB
Go
package portal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/tickcount/luci-app-dawnline/backend/files"
|
|
"github.com/tickcount/luci-app-dawnline/backend/model"
|
|
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
|
)
|
|
|
|
// What rang.
|
|
type What int
|
|
|
|
const (
|
|
// Changed: something the page shows changed (a device came or went, the admin changed something).
|
|
Changed What = iota
|
|
// Counters: only the traffic counters moved, as they do every minute.
|
|
Counters
|
|
)
|
|
|
|
// Sub is one stream's ear.
|
|
type Sub struct {
|
|
C chan What
|
|
person string
|
|
}
|
|
|
|
func (s *Sub) drain() {
|
|
for {
|
|
select {
|
|
case <-s.C:
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// Bell tells the streams that something changed for their person.
|
|
type Bell struct {
|
|
mu sync.Mutex
|
|
subs map[*Sub]struct{}
|
|
}
|
|
|
|
// Listen gives an ear for one person's changes.
|
|
func (b *Bell) Listen(person string) *Sub {
|
|
s := &Sub{C: make(chan What, 4), person: person}
|
|
b.mu.Lock()
|
|
if b.subs == nil {
|
|
b.subs = map[*Sub]struct{}{}
|
|
}
|
|
b.subs[s] = struct{}{}
|
|
b.mu.Unlock()
|
|
return s
|
|
}
|
|
|
|
// Forget takes an ear away.
|
|
func (b *Bell) Forget(s *Sub) {
|
|
b.mu.Lock()
|
|
delete(b.subs, s)
|
|
b.mu.Unlock()
|
|
}
|
|
|
|
// Ring tells a person's streams (everyone's for ""). A stream that has not heard its last rings yet
|
|
// misses nothing: it asks for the whole state when it does.
|
|
func (b *Bell) Ring(person string, what What) {
|
|
b.mu.Lock()
|
|
for s := range b.subs {
|
|
if person == "" || s.person == person {
|
|
select {
|
|
case s.C <- what:
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
b.mu.Unlock()
|
|
}
|
|
|
|
// Heard tells whether anyone listens.
|
|
func (b *Bell) Heard() bool {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return len(b.subs) > 0
|
|
}
|
|
|
|
// Watch rings the bell from the files the state is made of, looked at every second while someone listens:
|
|
// presence.json holds each person's revision (it moves with their devices' connections, their links'
|
|
// trouble and what the agent tells of them); the settings, the configurations handed out and a set-up's
|
|
// state concern whoever they show for; the counters move for everyone.
|
|
func Watch(ctx context.Context, b *Bell, run, data, config string) {
|
|
sig := func(path string) string {
|
|
st, err := os.Stat(path)
|
|
if err != nil {
|
|
return "-"
|
|
}
|
|
return fmt.Sprintf("%d/%d", st.ModTime().UnixNano(), st.Size())
|
|
}
|
|
everyone := []string{config, data + "/issued.json", run + "/setup.json", run + "/link.json", run + "/netifd-blocked.json"}
|
|
last := map[string]string{}
|
|
revs := map[string]int64{}
|
|
idle := true
|
|
tick := time.NewTicker(time.Second)
|
|
defer tick.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-tick.C:
|
|
}
|
|
if !b.Heard() {
|
|
idle = true
|
|
continue
|
|
}
|
|
// what changed while nobody listened is no news: a stream opens on the whole state
|
|
quiet := idle
|
|
idle = false
|
|
all := false
|
|
for _, p := range everyone {
|
|
if s := sig(p); s != last[p] {
|
|
last[p] = s
|
|
all = true
|
|
}
|
|
}
|
|
presence := run + "/presence.json"
|
|
if s := sig(presence); s != last[presence] {
|
|
last[presence] = s
|
|
var kept struct {
|
|
People map[string]int64 `json:"people"`
|
|
}
|
|
files.ReadJSON(presence, &kept)
|
|
for id, rev := range kept.People {
|
|
if revs[id] != rev && !quiet && !all {
|
|
b.Ring(id, Changed)
|
|
}
|
|
}
|
|
revs = kept.People
|
|
if revs == nil {
|
|
revs = map[string]int64{}
|
|
}
|
|
}
|
|
usage := run + "/usage.json"
|
|
counters := false
|
|
if s := sig(usage); s != last[usage] {
|
|
last[usage] = s
|
|
counters = true
|
|
}
|
|
if quiet {
|
|
continue
|
|
}
|
|
if all {
|
|
b.Ring("", Changed)
|
|
} else if counters {
|
|
b.Ring("", Counters)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Settings reads the settings file for the server, again when it changed.
|
|
type Settings struct {
|
|
Path string
|
|
|
|
mu sync.Mutex
|
|
sig string
|
|
codes map[string]string
|
|
redirect string
|
|
}
|
|
|
|
func (s *Settings) load() {
|
|
sig := "-"
|
|
if st, err := os.Stat(s.Path); err == nil {
|
|
sig = fmt.Sprintf("%d/%d", st.ModTime().UnixNano(), st.Size())
|
|
}
|
|
if sig == s.sig && s.codes != nil {
|
|
return
|
|
}
|
|
text, err := os.ReadFile(s.Path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
c, err := uci.Parse(string(text))
|
|
if err != nil {
|
|
return
|
|
}
|
|
m := model.Load(c, nil)
|
|
s.codes = map[string]string{}
|
|
for id, p := range m.People {
|
|
if p.Code != "" {
|
|
s.codes[p.Code] = id
|
|
}
|
|
}
|
|
s.redirect, s.sig = m.Settings.PortalRedirect, sig
|
|
}
|
|
|
|
// PersonByCode is the id of the person a code is the link of, or "".
|
|
func (s *Settings) PersonByCode(code string) string {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.load()
|
|
return s.codes[code]
|
|
}
|
|
|
|
// Redirect is where a path that is no link is sent.
|
|
func (s *Settings) Redirect() string {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.load()
|
|
return s.redirect
|
|
}
|