Dawnline 0.20.0
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
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.
This commit is contained in:
1 parent
f8130e39a8
commit
ac90575b0b
788 files changed
+139244
-41720
No files matched your search
@@ -0,0 +1,235 @@
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package roster
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
backend "github.com/tickcount/luci-app-dawnline/backend"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/disguise"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/files"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/ipnet"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/zone"
|
||||
)
|
||||
|
||||
// The links of the path that makes tunnel devices look like home devices (dawnline.loop).
|
||||
const transit, inner = "dlx0", "dll0"
|
||||
|
||||
func exists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// LikeHome is the home-like path's last applied state, as dawnline.loop status() tells it. ok is false
|
||||
// when it holds a reason only ucode can word yet (a refusal with its values).
|
||||
func LikeHome(run string) (map[string]any, bool) {
|
||||
var s struct {
|
||||
Plan *struct {
|
||||
Dev any `json:"dev"`
|
||||
Address any `json:"address"`
|
||||
DNS any `json:"dns"`
|
||||
Gateway any `json:"gateway"`
|
||||
TxNS any `json:"tx_ns"`
|
||||
} `json:"plan"`
|
||||
Off any `json:"off"`
|
||||
Error any `json:"error"`
|
||||
}
|
||||
files.ReadJSON(run+"/loop.json", &s)
|
||||
if s.Plan != nil {
|
||||
master, _ := os.Readlink("/sys/class/net/" + inner + "/master")
|
||||
dev, _ := s.Plan.Dev.(string)
|
||||
return map[string]any{
|
||||
"active": exists("/sys/class/net/"+transit) && exists("/sys/class/net/"+inner),
|
||||
"dev": s.Plan.Dev, "address": s.Plan.Address, "dns": s.Plan.DNS, "gateway": s.Plan.Gateway, "transit": s.Plan.TxNS,
|
||||
"bridged": master != "" && filepath.Base(master) == dev,
|
||||
}, true
|
||||
}
|
||||
if e, coded := s.Error.(map[string]any); coded {
|
||||
s.Error = likeHomeError(e)
|
||||
}
|
||||
off := s.Off != nil && s.Off != false && s.Off != float64(0) && s.Off != ""
|
||||
return map[string]any{"active": false, "off": off, "error": s.Error}, true
|
||||
}
|
||||
|
||||
// likeHomeError says why the home-like path could not be set up (dawnline.loop error_text), in English as
|
||||
// the stream's reader is given it.
|
||||
func likeHomeError(e map[string]any) string {
|
||||
switch e["code"] {
|
||||
case "no_lan":
|
||||
return "No LAN detected."
|
||||
case "not_bridge":
|
||||
return fmt.Sprintf("%v is not a bridge, so Dawnline cannot join the LAN as a device.", e["dev"])
|
||||
case "no_ipv4":
|
||||
return fmt.Sprintf("%v has no IPv4 address.", e["dev"])
|
||||
case "no_address":
|
||||
return fmt.Sprintf("No free address on %v.", e["net"])
|
||||
case "no_transit":
|
||||
return "No free link-local range for the internal link."
|
||||
case "no_table":
|
||||
return "No free routing table."
|
||||
}
|
||||
return fmt.Sprintf("Setup failed: %v", e["detail"])
|
||||
}
|
||||
|
||||
// blockedText says why a server is kept down (dawnline.awg blocked_text), or nil when it is not. ok is false
|
||||
// for a reason kept in a shape Go does not know.
|
||||
func blockedText(srv *model.Server) (text any, ok bool) {
|
||||
switch r := srv.Blocked.(type) {
|
||||
case nil:
|
||||
return nil, true
|
||||
case string:
|
||||
return srv.Name + " " + r + ".", true
|
||||
case map[string]any:
|
||||
switch r["code"] {
|
||||
case "ifname":
|
||||
return fmt.Sprintf("%s has an invalid interface name \"%v\".", srv.Name, r["ifname"]), true
|
||||
case "taken":
|
||||
return fmt.Sprintf("%s can't use the network interface %v: it exists and isn't Dawnline's.", srv.Name, r["ifname"]), true
|
||||
case "disguise":
|
||||
if in, _ := r["installed"].(string); in != "" {
|
||||
return fmt.Sprintf("%s is kept down: its disguise needs AmneziaWG %v (installed: %s).", srv.Name, r["need"], in), true
|
||||
}
|
||||
return fmt.Sprintf("%s is kept down: its disguise needs AmneziaWG %v (installed: none).", srv.Name, r["need"]), true
|
||||
case "disguise_invalid":
|
||||
// which values, from the server's own
|
||||
return strings.Trim(fmt.Sprintf("%s is kept down: its disguise has values AmneziaWG cannot take. %s", srv.Name, strings.Join(disguise.Unsafe(srv.Obf), " ")), " \t\r\n\v\f"), true
|
||||
}
|
||||
return srv.Name + " is kept down.", true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AwgState is what of AmneziaWG is on the router (dawnline.awg state()); handler: netifd lists its protocol.
|
||||
func AwgState(handler func() bool) map[string]any {
|
||||
tools := exists("/usr/bin/awg") && exists("/lib/netifd/proto/amneziawg.sh")
|
||||
loaded := exists("/sys/module/amneziawg")
|
||||
rel, _ := os.ReadFile("/proc/sys/kernel/osrelease")
|
||||
r := strings.TrimSpace(string(rel))
|
||||
kmod := loaded || (r != "" && exists("/lib/modules/"+r+"/amneziawg.ko"))
|
||||
has := tools && handler != nil && handler()
|
||||
missing := []any{}
|
||||
if !kmod {
|
||||
missing = append(missing, "kmod-amneziawg")
|
||||
}
|
||||
if !tools {
|
||||
missing = append(missing, "amneziawg-tools")
|
||||
}
|
||||
return map[string]any{"tools": tools, "kmod": kmod, "loaded": loaded, "handler": has, "missing": missing, "ok": len(missing) == 0 && loaded && has}
|
||||
}
|
||||
|
||||
// publicWAN is the router's public IPv4, or nil when it has none or a private one.
|
||||
func publicWAN(wan string) any {
|
||||
n, ok := ipnet.IP(wan)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
for _, p := range []string{"100.64.0.0/10", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"} {
|
||||
if r, _ := ipnet.Any(p); r.Holds(n) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return wan
|
||||
}
|
||||
|
||||
// shown is what of the settings every page is shown.
|
||||
func shown(set model.Settings) map[string]any {
|
||||
return map[string]any{
|
||||
"portal_enabled": set.PortalEnabled, "portal_port": set.PortalPort, "portal_host": set.PortalHost,
|
||||
"portal_public_port": set.PortalPort, "default_device_limit": set.DefaultDeviceLimit, "domain": set.Domain,
|
||||
"hostnames": set.Hostnames, "geo_enabled": set.GeoEnabled, "home_dns_fallback": set.HomeDNSFallback,
|
||||
}
|
||||
}
|
||||
|
||||
// routerOf is the `router` and `clock` parts of a status that Go can tell, and whether that is all of them:
|
||||
// a part it cannot tell yet is left out.
|
||||
func (r *Roster) routerOf(m *model.Model, now int64) (map[string]any, bool) {
|
||||
host, _ := os.ReadFile("/proc/sys/kernel/hostname")
|
||||
_, off := time.Unix(now, 0).In(zone.Local()).Zone()
|
||||
out := map[string]any{
|
||||
"version": backend.Version, "hostname": strings.TrimSpace(string(host)), "tz": off / 60,
|
||||
"awg_state": AwgState(r.Handler), "settings": shown(m.Settings),
|
||||
}
|
||||
all := r.Handler != nil && r.WAN != nil
|
||||
if lh, ok := LikeHome(r.RunDir); ok {
|
||||
out["like_home"] = lh
|
||||
} else {
|
||||
all = false
|
||||
}
|
||||
out["awg"] = awg.SystemCaps(r.DataDir)
|
||||
if r.WAN != nil {
|
||||
out["wan"] = publicWAN(r.WAN(m))
|
||||
}
|
||||
return out, all
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package roster
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
)
|
||||
|
||||
func TestBlockedText(t *testing.T) {
|
||||
srv := func(why any) *model.Server {
|
||||
return &model.Server{Name: "Home", Blocked: why, Obf: map[string]string{"jmin": "9", "jmax": "3"}}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
why any
|
||||
text any
|
||||
ok bool
|
||||
}{
|
||||
{nil, nil, true},
|
||||
{"another tunnel has its name", "Home another tunnel has its name.", true},
|
||||
{map[string]any{"code": "ifname", "ifname": "bad name"}, `Home has an invalid interface name "bad name".`, true},
|
||||
{map[string]any{"code": "taken", "ifname": "wg0"}, "Home can't use the network interface wg0: it exists and isn't Dawnline's.", true},
|
||||
{map[string]any{"code": "disguise", "need": "3.1", "installed": "2.0"}, "Home is kept down: its disguise needs AmneziaWG 3.1 (installed: 2.0).", true},
|
||||
{map[string]any{"code": "disguise", "need": "2.0", "installed": nil}, "Home is kept down: its disguise needs AmneziaWG 2.0 (installed: none).", true},
|
||||
{map[string]any{"code": "later"}, "Home is kept down.", true},
|
||||
{map[string]any{"code": "disguise_invalid"}, "Home is kept down: its disguise has values AmneziaWG cannot take. Jmin must not be larger than Jmax.", true},
|
||||
{7.0, nil, false},
|
||||
} {
|
||||
if text, ok := blockedText(srv(c.why)); text != c.text || ok != c.ok {
|
||||
t.Errorf("%v: %v %v", c.why, text, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLikeHome(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
for _, c := range []struct {
|
||||
file string
|
||||
want map[string]any
|
||||
}{
|
||||
{``, map[string]any{"active": false, "off": false, "error": nil}},
|
||||
{`{"off":true}`, map[string]any{"active": false, "off": true, "error": nil}},
|
||||
{`{"error":"An older version's own words."}`, map[string]any{"active": false, "off": false, "error": "An older version's own words."}},
|
||||
{`{"error":{"code":"not_bridge","dev":"eth1"}}`, map[string]any{"active": false, "off": false, "error": "eth1 is not a bridge, so Dawnline cannot join the LAN as a device."}},
|
||||
{`{"error":{"code":"failed","detail":"ip: no such device"}}`, map[string]any{"active": false, "off": false, "error": "Setup failed: ip: no such device"}},
|
||||
// set up, but its links are not on this machine: not active, not in the bridge
|
||||
{`{"plan":{"dev":"br-lan","address":"192.168.1.9","dns":"192.168.1.1","gateway":"192.168.1.1","tx_ns":"169.254.7.2"}}`,
|
||||
map[string]any{"active": false, "dev": "br-lan", "address": "192.168.1.9", "dns": "192.168.1.1", "gateway": "192.168.1.1", "transit": "169.254.7.2", "bridged": false}},
|
||||
} {
|
||||
os.Remove(dir + "/loop.json")
|
||||
if c.file != "" {
|
||||
os.WriteFile(dir+"/loop.json", []byte(c.file), 0o600)
|
||||
}
|
||||
if got, ok := LikeHome(dir); !ok || !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("%s: %v", c.file, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicWAN(t *testing.T) {
|
||||
for wan, want := range map[string]any{"": nil, "192.168.1.2": nil, "100.72.0.9": nil, "10.0.0.1": nil, "172.20.1.1": nil, "203.0.113.7": "203.0.113.7"} {
|
||||
if got := publicWAN(wan); got != want {
|
||||
t.Errorf("%q: %v", wan, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user