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.
133 lines
4.5 KiB
Go
133 lines
4.5 KiB
Go
package methods
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/tickcount/luci-app-dawnline/backend/files"
|
|
"github.com/tickcount/luci-app-dawnline/backend/i18n"
|
|
"github.com/tickcount/luci-app-dawnline/backend/view"
|
|
)
|
|
|
|
var ifupFix = regexp.MustCompile(`^ifup:([a-z][a-z0-9_]{0,11})$`)
|
|
|
|
// healthFix runs a fix a check named and answers Health again with what the fix came to
|
|
// (dawnline.health fix): apply and sync are still the ucode backend's, the rest the service's own.
|
|
func healthFix(w *view.World, t *i18n.Catalog, d Deps, id, lang string) (map[string]any, error) {
|
|
var result any
|
|
switch {
|
|
case id == "apply":
|
|
if d.Apply != nil {
|
|
result = d.Apply(lang)
|
|
}
|
|
case id == "sync":
|
|
var warning any
|
|
if d.Sync != nil {
|
|
warning = d.Sync(lang)
|
|
}
|
|
result = map[string]any{"warning": warning}
|
|
case id == "restart":
|
|
if d.Background != nil {
|
|
d.Background("sleep 1; /etc/init.d/dawnline restart")
|
|
}
|
|
result = map[string]any{"code": 0}
|
|
// netifd learns protocol handlers (amneziawg) only when it starts; the answer goes out before the network blinks
|
|
case id == "netrestart":
|
|
if d.Background != nil {
|
|
d.Background("sleep 1; /etc/init.d/network restart")
|
|
}
|
|
result = map[string]any{"ok": true, "background": true}
|
|
case ifupFix.MatchString(id):
|
|
name := ifupFix.FindStringSubmatch(id)[1]
|
|
// only Dawnline's own tunnels: never another interface of the router
|
|
mine := false
|
|
for _, s := range w.M.Servers {
|
|
mine = mine || (s.Ifname == name && s.PrivateKey != "")
|
|
}
|
|
if !mine {
|
|
return nil, said{"%s is not one of Dawnline's tunnels.", []any{name}}
|
|
}
|
|
if d.Ifup != nil {
|
|
d.Ifup(name)
|
|
}
|
|
result = map[string]any{"ok": true}
|
|
default:
|
|
return nil, errors.New("Unknown fix.")
|
|
}
|
|
out := serviceLog(w, t, d.RunDir, d.DataDir)
|
|
out["checks"] = healthChecks(w, t, d)
|
|
out["result"] = result
|
|
return out, nil
|
|
}
|
|
|
|
// check[:app|amneziawg|packages] | app[@tag|:reinstall|:rollback|:lang:<code>|:nolang]
|
|
// | amneziawg[:auto|slava|grey[:ru]|:rollback] | pkgs:<name,…> (only packages Dawnline manages)
|
|
var updateTarget = regexp.MustCompile(`^(check(:(app|amneziawg|packages))?|app(@v?[0-9][0-9A-Za-z.+~-]{0,40}|:reinstall|:rollback|:lang:[a-z]{2,3}(_[A-Za-z]{2,4})?|:nolang)?|amneziawg(:rollback|:(auto|slava|grey)(:ru)?)?|pkgs:[a-z0-9][a-z0-9.+,-]*)$`)
|
|
|
|
// The packages Dawnline manages besides its own and AmneziaWG's.
|
|
var managedPackages = []string{"ip-full", "kmod-veth", "libustream-openssl", "openssl-util", "acme", "acme-acmesh-dnsapi", "luci-app-acme"}
|
|
|
|
// updatesRun starts an update job: the updater does the work in the background. It answers the new job
|
|
// once its worker has written it (a quick check may be over by then), else none (the page follows
|
|
// updates_status); never an older job. It waits two seconds at most.
|
|
func updatesRun(d Deps, what, lang string) (map[string]any, error) {
|
|
if what == "" {
|
|
what = "check"
|
|
}
|
|
if len(what) > 400 || !updateTarget.MatchString(what) {
|
|
return nil, errors.New("Unknown update target.")
|
|
}
|
|
// checked here too, so a wrong name never becomes a failed job in the history
|
|
if names, isPkgs := strings.CutPrefix(what, "pkgs:"); isPkgs {
|
|
for _, n := range strings.Split(names, ",") {
|
|
known := false
|
|
for _, p := range managedPackages {
|
|
known = known || p == n
|
|
}
|
|
if n == "" {
|
|
return nil, errors.New("Unknown update target.")
|
|
}
|
|
if !known {
|
|
return nil, said{"%s is not a package Dawnline manages", []any{n}}
|
|
}
|
|
}
|
|
}
|
|
if updating(d.RunDir) {
|
|
return nil, errors.New("Another component action is already running")
|
|
}
|
|
type job struct {
|
|
ID any `json:"id"`
|
|
Started float64 `json:"started"`
|
|
}
|
|
var prev job
|
|
files.ReadJSON(d.RunDir+"/update-job.json", &prev)
|
|
began := clock()
|
|
args := []string{"install", what}
|
|
if rest, isCheck := strings.CutPrefix(what, "check"); isCheck {
|
|
args = []string{"check"}
|
|
if rest != "" {
|
|
args = append(args, strings.TrimPrefix(rest, ":"))
|
|
}
|
|
}
|
|
// the job speaks the admin's language, when its catalog is installed
|
|
speak := ""
|
|
if i18n.Use(d.Catalogs, lang) != nil {
|
|
speak = strings.ToLower(strings.ReplaceAll(lang, "_", "-"))
|
|
}
|
|
if d.Updater != nil {
|
|
d.Updater(speak, args)
|
|
}
|
|
for i := 0; i < 20; i++ {
|
|
var j job
|
|
var whole map[string]any
|
|
if files.ReadJSON(d.RunDir+"/update-job.json", &j) && j.ID != prev.ID && j.Started >= float64(began) {
|
|
files.ReadJSON(d.RunDir+"/update-job.json", &whole)
|
|
return map[string]any{"started": true, "job": whole}, nil
|
|
}
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
return map[string]any{"started": true, "job": nil}, nil
|
|
}
|