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,551 @@
|
||||
// Package access is "Check access": it walks the same rules the access table and a device's configuration
|
||||
// apply, and says in words where a connection stops, each step a whole sentence in the reader's language
|
||||
// (dawnline.access). Held to ucode's own output on a made-up household (testdata, scripts/ucode-golden.sh).
|
||||
package access
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/handout"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/i18n"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/ipnet"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/netview"
|
||||
)
|
||||
|
||||
// Step is one step of the walk.
|
||||
type Step struct {
|
||||
OK bool `json:"ok"`
|
||||
Title string `json:"title"`
|
||||
Detail string `json:"detail"`
|
||||
}
|
||||
|
||||
// Ctx is what the walk reads besides the settings: each person's state, the tunnels' peers, who is online
|
||||
// and the router's interfaces.
|
||||
type Ctx struct {
|
||||
States map[string]string
|
||||
Peers map[string]awg.Peer
|
||||
Online func(d *model.Device, peer awg.Peer) bool
|
||||
Snap *netview.Snapshot
|
||||
T *i18n.Catalog
|
||||
}
|
||||
|
||||
// Said is a refusal to check at all, as a sentence to translate and what goes into it.
|
||||
type Said struct {
|
||||
Msg string
|
||||
Args []any
|
||||
}
|
||||
|
||||
func (s Said) Error() string { return fmt.Sprintf(s.Msg, s.Args...) }
|
||||
|
||||
type walk struct {
|
||||
Ctx
|
||||
m *model.Model
|
||||
}
|
||||
|
||||
func (w *walk) f(msg string, args ...any) string { return fmt.Sprintf(w.T.T(msg), args...) }
|
||||
|
||||
// inNets is the first of nets that holds ip, or "".
|
||||
func inNets(ip string, nets []string) string {
|
||||
n, ok := ipnet.IP(ip)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
for _, s := range nets {
|
||||
if c, ok := ipnet.Any(s); ok && c.Holds(n) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (w *walk) cantConnect(name, st string) string {
|
||||
switch st {
|
||||
case "no_server":
|
||||
return w.f("%s can't connect: they have no server", name)
|
||||
case "server_off":
|
||||
return w.f("%s can't connect: their server is turned off", name)
|
||||
case "paused":
|
||||
return w.f("%s can't connect: they are paused", name)
|
||||
case "expired":
|
||||
return w.f("%s can't connect: their access has ended", name)
|
||||
case "quota":
|
||||
return w.f("%s can't connect: they used up their data", name)
|
||||
}
|
||||
return w.f("%s can't connect: %s", name, st)
|
||||
}
|
||||
|
||||
func (w *walk) cantReach(who string, disabled bool, st string) string {
|
||||
switch {
|
||||
case disabled:
|
||||
return w.f("%s can't be reached: it is turned off", who)
|
||||
case st == "no_server":
|
||||
return w.f("%s can't be reached: they have no server", who)
|
||||
case st == "server_off":
|
||||
return w.f("%s can't be reached: their server is turned off", who)
|
||||
case st == "paused":
|
||||
return w.f("%s can't be reached: they are paused", who)
|
||||
case st == "expired":
|
||||
return w.f("%s can't be reached: their access has ended", who)
|
||||
case st == "quota":
|
||||
return w.f("%s can't be reached: they used up their data", who)
|
||||
}
|
||||
return w.f("%s can't be reached: %s", who, st)
|
||||
}
|
||||
|
||||
func (w *walk) accessText(a string) string {
|
||||
switch a {
|
||||
case "lan":
|
||||
return w.T.T("Home only")
|
||||
case "internet":
|
||||
return w.T.T("Internet only")
|
||||
case "both":
|
||||
return w.T.T("Home and Internet")
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (w *walk) hasAccess(name, a string) string {
|
||||
switch a {
|
||||
case "lan":
|
||||
return w.f("%s has Home only", name)
|
||||
case "internet":
|
||||
return w.f("%s has Internet only", name)
|
||||
}
|
||||
return w.f("%s has Home and Internet", name)
|
||||
}
|
||||
|
||||
func (w *walk) reaches(name string, devs []string) string {
|
||||
if len(devs) > 0 {
|
||||
return w.f("%s reaches %s.", name, strings.Join(devs, ", "))
|
||||
}
|
||||
return w.f("%s reaches no home network.", name)
|
||||
}
|
||||
|
||||
// tunnelOf is a server's tunnel network when it runs one of Dawnline's own, else "".
|
||||
func tunnelOf(srv *model.Server) string {
|
||||
if srv == nil || srv.PrivateKey == "" || srv.Blocked != nil || !model.ValidIfname(srv.Ifname) {
|
||||
return ""
|
||||
}
|
||||
if _, ok := ipnet.Subnet(srv.Subnet); !ok {
|
||||
return ""
|
||||
}
|
||||
return srv.Subnet
|
||||
}
|
||||
|
||||
// inTunnels is the tunnel network (of any server) that holds ip: never home, whatever routes cover it.
|
||||
func (w *walk) inTunnels(ip string) string {
|
||||
var nets []string
|
||||
for _, id := range w.m.ServerIDs() {
|
||||
if t := tunnelOf(w.m.Servers[id]); t != "" {
|
||||
nets = append(nets, t)
|
||||
}
|
||||
}
|
||||
return inNets(ip, nets)
|
||||
}
|
||||
|
||||
type target struct {
|
||||
dev *model.Device
|
||||
ip string
|
||||
port int // 0: none
|
||||
// net: the address is a host in this network behind dev (a router): the rules see it as they see the router
|
||||
net string
|
||||
}
|
||||
|
||||
var address = regexp.MustCompile(`^([0-9.]+)(:([0-9]{1,5}))?$`)
|
||||
|
||||
// parse reads "10.0.1.20:445" or a device id.
|
||||
func (w *walk) parse(s string) (target, bool) {
|
||||
s = strings.Trim(s, " \t\r\n\v\f")
|
||||
if d := w.m.Devices[s]; d != nil {
|
||||
return target{dev: d, ip: d.Address}, true
|
||||
}
|
||||
mm := address.FindStringSubmatch(s)
|
||||
if mm == nil {
|
||||
return target{}, false
|
||||
}
|
||||
if _, ok := ipnet.IP(mm[1]); !ok {
|
||||
return target{}, false
|
||||
}
|
||||
t := target{ip: mm[1]}
|
||||
if mm[3] != "" {
|
||||
t.port, _ = strconv.Atoi(mm[3])
|
||||
}
|
||||
for _, id := range w.m.DeviceIDs() {
|
||||
if d := w.m.Devices[id]; d.Address == t.ip {
|
||||
t.dev = d
|
||||
break
|
||||
}
|
||||
}
|
||||
// a host behind someone's router: the networks in effect on this router, as the access table has them
|
||||
if t.dev == nil {
|
||||
behind := w.Snap.Behind(w.m)
|
||||
for _, id := range w.m.DeviceIDs() {
|
||||
if n := inNets(t.ip, behind[id]); n != "" {
|
||||
t.dev, t.net = w.m.Devices[id], n
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return t, true
|
||||
}
|
||||
|
||||
// behindStep says that an address is a host behind a router, which the rest of the walk is then about.
|
||||
func (w *walk) behindStep(t target) Step {
|
||||
who := t.dev.Name
|
||||
if p := w.m.People[t.dev.Person]; p != nil {
|
||||
who = p.Name + " · " + t.dev.Name
|
||||
}
|
||||
return Step{true, w.f("%s is behind %s", t.ip, who), w.f("%s: the tunnel carries this network, and the rules see a host there as they see the router.", t.net)}
|
||||
}
|
||||
|
||||
// personHome is the home networks a person reaches: all of the server's, or the interfaces ticked on their page.
|
||||
func (w *walk) personHome(srv *model.Server, p *model.Person) (all bool, nets, devs []string) {
|
||||
_, home, every, _ := w.Snap.ServerNet(srv)
|
||||
if len(p.HomeNets) == 0 {
|
||||
for _, h := range home {
|
||||
devs = append(devs, h.Dev)
|
||||
}
|
||||
return true, every, devs
|
||||
}
|
||||
var picked []string
|
||||
for _, h := range home {
|
||||
for _, want := range p.HomeNets {
|
||||
if want == h.Dev {
|
||||
picked = append(picked, h.Nets...)
|
||||
devs = append(devs, h.Dev)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, ipnet.Collapse(picked), devs
|
||||
}
|
||||
|
||||
// homeDevOf is the home network (interface) of a server that holds an address.
|
||||
func (w *walk) homeDevOf(srv *model.Server, ip string) string {
|
||||
_, home, _, _ := w.Snap.ServerNet(srv)
|
||||
for _, h := range home {
|
||||
if inNets(ip, h.Nets) != "" {
|
||||
return h.Dev
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (w *walk) routerHas(ip string) bool {
|
||||
for _, d := range w.Snap.Devices {
|
||||
for _, a := range d.Addrs {
|
||||
if strings.SplitN(a, "/", 2)[0] == ip {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (w *walk) state(p *model.Person) string {
|
||||
if st := w.States[p.ID]; st != "" {
|
||||
return st
|
||||
}
|
||||
return "active"
|
||||
}
|
||||
|
||||
func (w *walk) personOK(p *model.Person, d *model.Device) Step {
|
||||
if d.Disabled {
|
||||
return Step{false, w.f("%s is turned off", d.Name), w.T.T("Turn the device on again on its page.")}
|
||||
}
|
||||
if st := w.state(p); st != "active" {
|
||||
return Step{false, w.cantConnect(p.Name, st), ""}
|
||||
}
|
||||
return Step{true, w.f("%s is active", p.Name), w.accessText(p.Access)}
|
||||
}
|
||||
|
||||
func (w *walk) connected(d *model.Device, who string) Step {
|
||||
peer, has := w.Peers[d.PublicKey]
|
||||
if !has || peer.Handshake <= 0 {
|
||||
return Step{false, w.f("%s has never connected", who), w.T.T("There is no session the router could reach.")}
|
||||
}
|
||||
if w.Online == nil || !w.Online(d, peer) {
|
||||
return Step{false, w.f("%s isn't connected right now", who), w.T.T("The router reaches it only while its VPN is on.")}
|
||||
}
|
||||
return Step{true, w.f("%s is connected", who), ""}
|
||||
}
|
||||
|
||||
func (w *walk) circle(p *model.Person) *model.Circle {
|
||||
if c := w.m.Circles[p.Circle]; c != nil && c.Server == p.Server {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// fromDevice: a device to somewhere, the router, home, another device or the internet.
|
||||
func (w *walk) fromDevice(d *model.Device, t target) []Step {
|
||||
m, T := w.m, w.T
|
||||
p := m.People[d.Person]
|
||||
var srv *model.Server
|
||||
if p != nil {
|
||||
srv = m.Servers[p.Server]
|
||||
}
|
||||
if p == nil || srv == nil {
|
||||
return []Step{{false, w.f("%s has no server", d.Name), ""}}
|
||||
}
|
||||
steps := []Step{w.personOK(p, d)}
|
||||
if !steps[0].OK {
|
||||
return steps
|
||||
}
|
||||
all, homeNets, homeDevs := w.personHome(srv, p)
|
||||
allowed := handout.AllowedIPs(m, srv, p, d, homeNets)
|
||||
via := func(ip string) Step {
|
||||
// the configuration's own words: the option and its value
|
||||
var v4 []string
|
||||
for _, x := range allowed {
|
||||
if !strings.Contains(x, ":") {
|
||||
v4 = append(v4, x)
|
||||
}
|
||||
}
|
||||
what := "AllowedIPs " + strings.Join(v4, ", ")
|
||||
if inNets(ip, allowed) != "" {
|
||||
return Step{true, T.T("Its configuration sends it to the router"), what}
|
||||
}
|
||||
return Step{false, T.T("Its configuration doesn't send it to the router"), w.f("%s: the device's own network handles it.", what)}
|
||||
}
|
||||
// another device
|
||||
if t.dev != nil {
|
||||
q := m.People[t.dev.Person]
|
||||
qname := "?"
|
||||
if q != nil {
|
||||
qname = q.Name
|
||||
}
|
||||
who := qname + " · " + t.dev.Name
|
||||
if t.dev.ID == d.ID {
|
||||
// its own network: a router reaches what is behind it without the tunnel
|
||||
if t.net != "" {
|
||||
return []Step{{false, w.f("%s is behind this device", t.ip), T.T("A router reaches its own network without the tunnel.")}}
|
||||
}
|
||||
return []Step{{false, T.T("That is the same device"), ""}}
|
||||
}
|
||||
if q == nil || q.Server != p.Server {
|
||||
return append(steps, Step{false, w.f("%s is on another server", who), T.T("Devices of different servers never reach each other.")})
|
||||
}
|
||||
if !p.HomeAccess() {
|
||||
return append(steps, Step{false, w.hasAccess(p.Name, p.Access), T.T("Only people with home access reach other devices.")})
|
||||
}
|
||||
if !q.HomeAccess() {
|
||||
return append(steps, Step{false, w.hasAccess(q.Name, q.Access), T.T("Only devices of people with home access can be reached.")})
|
||||
}
|
||||
if srv.Mesh == "off" {
|
||||
return append(steps, Step{false, w.f(`"Devices reach each other" is off on %s`, srv.Name), T.T("Server → Access → Home network.")})
|
||||
}
|
||||
if srv.Mesh == "circles" && q.ID != p.ID {
|
||||
a, b := w.circle(p), w.circle(q)
|
||||
if a == nil || b == nil || a.ID != b.ID {
|
||||
name := func(c *model.Circle) string {
|
||||
if c == nil {
|
||||
return T.T("no circle")
|
||||
}
|
||||
return c.Name
|
||||
}
|
||||
return append(steps, Step{false, w.f("%s and %s are not in one circle", p.Name, q.Name), p.Name + ": " + name(a) + " · " + q.Name + ": " + name(b)})
|
||||
}
|
||||
steps = append(steps, Step{true, w.f("Both are in %s", a.Name), T.T("Devices in one circle reach each other.")})
|
||||
} else if q.ID == p.ID {
|
||||
steps = append(steps, Step{true, w.f("Both are %s's devices", p.Name), ""})
|
||||
} else {
|
||||
steps = append(steps, Step{true, T.T("Devices reach each other on this server"), ""})
|
||||
}
|
||||
if st := w.state(q); st != "active" || t.dev.Disabled {
|
||||
return append(steps, Step{false, w.cantReach(who, t.dev.Disabled, st), ""})
|
||||
}
|
||||
return append(steps, via(t.ip), w.connected(t.dev, who))
|
||||
}
|
||||
// a device that keeps its own local network out of the tunnel sends a private address there, router or
|
||||
// home address alike: it never reaches this router's rules
|
||||
if d.LanBypass && p.Access != "lan" && inNets(t.ip, allowed) == "" {
|
||||
return append(steps, via(t.ip))
|
||||
}
|
||||
// the router itself
|
||||
if w.routerHas(t.ip) {
|
||||
s := m.Settings
|
||||
plain := false
|
||||
for _, h := range append([]string{s.PortalHost}, s.PortalAlt...) {
|
||||
if _, ip := ipnet.IP(h); ip {
|
||||
plain = true
|
||||
}
|
||||
}
|
||||
portal := s.PortalEnabled && t.port != 0 && (t.port == s.PortalPort || (plain && t.port == s.PortalPort+1))
|
||||
switch {
|
||||
case t.port == 53:
|
||||
steps = append(steps, Step{true, w.f("%s is this router: DNS is open to everyone", t.ip), ""})
|
||||
case portal:
|
||||
steps = append(steps, Step{true, w.f("%s is this router: the personal portal is open to everyone", t.ip), ""})
|
||||
case !p.HomeAccess():
|
||||
detail := w.f("%s has Internet only: only DNS and the portal on the router.", p.Name)
|
||||
if p.Access == "lan" {
|
||||
detail = w.f("%s has Home only: only DNS and the portal on the router.", p.Name)
|
||||
}
|
||||
return append(steps, Step{false, w.f("%s is this router", t.ip), detail})
|
||||
default:
|
||||
// like any home address: only on the networks the person reaches
|
||||
if !all && inNets(t.ip, homeNets) == "" {
|
||||
return append(steps, Step{false, w.f("%s is this router on a network %s doesn't reach", t.ip, p.Name), w.reaches(p.Name, homeDevs)})
|
||||
}
|
||||
detail := w.f("On one of the networks %s reaches.", p.Name)
|
||||
if all {
|
||||
detail = T.T("Home access includes the router.")
|
||||
}
|
||||
steps = append(steps, Step{true, w.f("%s is this router", t.ip), detail})
|
||||
}
|
||||
return append(steps, via(t.ip))
|
||||
}
|
||||
// a tunnel address no device has
|
||||
if tn := w.inTunnels(t.ip); tn != "" {
|
||||
return append(steps, Step{false, w.f("No device uses %s", t.ip), w.f("It is in the tunnel network %s.", tn)})
|
||||
}
|
||||
// home
|
||||
wan, _, _, zones := w.Snap.ServerNet(srv)
|
||||
if hdev := w.homeDevOf(srv, t.ip); hdev != "" {
|
||||
if p.Access == "internet" {
|
||||
return append(steps, Step{false, w.f("%s is at home (%s)", t.ip, hdev), w.f("%s has Internet only.", p.Name)})
|
||||
}
|
||||
if p.Access == "lan" && len(p.Services) > 0 {
|
||||
var hit *model.Service
|
||||
var names []string
|
||||
for _, sid := range p.Services {
|
||||
s := m.Services[sid]
|
||||
if s == nil {
|
||||
continue
|
||||
}
|
||||
names = append(names, s.Name)
|
||||
open := len(s.Ports) == 0 || t.port == 0
|
||||
for _, port := range s.Ports {
|
||||
open = open || port == strconv.Itoa(t.port)
|
||||
}
|
||||
if s.Address == t.ip && open {
|
||||
hit = s
|
||||
}
|
||||
}
|
||||
if hit == nil {
|
||||
what := t.ip
|
||||
if t.port != 0 {
|
||||
what += ":" + strconv.Itoa(t.port)
|
||||
}
|
||||
return append(steps, Step{false, w.f("%s is not one of %s's home services", what, p.Name), w.f("Allowed: %s", strings.Join(names, ", "))})
|
||||
}
|
||||
detail := T.T("All ports")
|
||||
if len(hit.Ports) > 0 {
|
||||
detail = w.f("Ports %s", strings.Join(hit.Ports, ", "))
|
||||
}
|
||||
steps = append(steps, Step{true, w.f("%s is %s, one of %s's home services", t.ip, hit.Name, p.Name), detail})
|
||||
} else {
|
||||
if inNets(t.ip, homeNets) == "" {
|
||||
return append(steps, Step{false, w.f("%s is in %s, which %s doesn't reach", t.ip, hdev, p.Name), w.reaches(p.Name, homeDevs)})
|
||||
}
|
||||
detail := w.f("One of the networks %s reaches.", p.Name)
|
||||
if all {
|
||||
detail = T.T("Home access reaches every home network.")
|
||||
}
|
||||
steps = append(steps, Step{true, w.f("%s is in home network %s", t.ip, hdev), detail})
|
||||
}
|
||||
to := strings.Join(zones, ", ")
|
||||
if to == "" {
|
||||
to = T.T("home")
|
||||
}
|
||||
return append(steps, via(t.ip), Step{true, T.T("The firewall lets it through"), srv.Ifname + " → " + to})
|
||||
}
|
||||
// another private address, or the internet
|
||||
if inNets(t.ip, []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10", "169.254.0.0/16"}) != "" {
|
||||
return append(steps, Step{false, w.f("%s isn't in %s's home network", t.ip, srv.Name), T.T("Private addresses outside the home network are blocked.")})
|
||||
}
|
||||
if p.Access == "lan" {
|
||||
return append(steps, Step{true, w.f("%s is on the internet", t.ip), w.f("%s has Home only: their device's own internet reaches it, not the tunnel.", p.Name)})
|
||||
}
|
||||
leaves := T.T("It leaves through the WAN.")
|
||||
if srv.LanLike {
|
||||
leaves = T.T("It leaves like a home device would.")
|
||||
} else if wan.Dev != "" {
|
||||
leaves = w.f("It leaves through %s.", wan.Dev)
|
||||
}
|
||||
return append(steps, via(t.ip), Step{true, w.f("%s is on the internet", t.ip), leaves})
|
||||
}
|
||||
|
||||
// toDevice: a home address to a device.
|
||||
func (w *walk) toDevice(ip string, d *model.Device) []Step {
|
||||
m, T := w.m, w.T
|
||||
p := m.People[d.Person]
|
||||
var srv *model.Server
|
||||
if p != nil {
|
||||
srv = m.Servers[p.Server]
|
||||
}
|
||||
if p == nil || srv == nil {
|
||||
return []Step{{false, w.f("%s has no server", d.Name), ""}}
|
||||
}
|
||||
who := p.Name + " · " + d.Name
|
||||
hdev := ""
|
||||
if w.inTunnels(ip) == "" {
|
||||
hdev = w.homeDevOf(srv, ip)
|
||||
}
|
||||
if hdev == "" {
|
||||
return []Step{{false, w.f("%s isn't in %s's home network", ip, srv.Name), T.T("Only home devices reach people's devices.")}}
|
||||
}
|
||||
steps := []Step{{true, w.f("%s is at home (%s)", ip, hdev), ""}}
|
||||
if !p.HomeAccess() {
|
||||
title := w.hasAccess(p.Name, p.Access)
|
||||
if p.Access == "lan" {
|
||||
title = w.f("%s has only some home services", p.Name)
|
||||
}
|
||||
return append(steps, Step{false, title, T.T("Home devices reach only people with home access.")})
|
||||
}
|
||||
if _, nets, _ := w.personHome(srv, p); inNets(ip, nets) == "" {
|
||||
return append(steps, Step{false, w.f("%s doesn't reach %s", p.Name, hdev), T.T("Networks a person does not reach cannot reach them either.")})
|
||||
}
|
||||
steps = append(steps, w.personOK(p, d))
|
||||
if !steps[len(steps)-1].OK {
|
||||
return steps
|
||||
}
|
||||
_, _, _, zones := w.Snap.ServerNet(srv)
|
||||
from := strings.Join(zones, ", ")
|
||||
if from == "" {
|
||||
from = T.T("home")
|
||||
}
|
||||
return append(steps, Step{true, T.T("The firewall lets it through"), from + " → " + srv.Ifname}, w.connected(d, who))
|
||||
}
|
||||
|
||||
// Check walks from one side to the other: each a device's id, or an IPv4 address (with a port when given).
|
||||
// ok tells whether every step passed.
|
||||
func Check(m *model.Model, from, to string, ctx Ctx) (ok bool, steps []Step, err error) {
|
||||
w := &walk{ctx, m}
|
||||
a, aok := w.parse(from)
|
||||
if !aok {
|
||||
return false, nil, Said{`"%s" is not a device or an IPv4 address.`, []any{from}}
|
||||
}
|
||||
b, bok := w.parse(to)
|
||||
if !bok {
|
||||
return false, nil, Said{`"%s" is not a device or an IPv4 address.`, []any{to}}
|
||||
}
|
||||
switch {
|
||||
case a.dev != nil:
|
||||
steps = w.fromDevice(a.dev, b)
|
||||
case b.dev != nil:
|
||||
steps = w.toDevice(a.ip, b.dev)
|
||||
default:
|
||||
return false, nil, errors.New("Choose a device on at least one side.")
|
||||
}
|
||||
// a side that is a host behind a router: said first, for each such side
|
||||
var lead []Step
|
||||
for _, t := range []target{a, b} {
|
||||
if t.net != "" {
|
||||
lead = append(lead, w.behindStep(t))
|
||||
}
|
||||
}
|
||||
steps = append(lead, steps...)
|
||||
ok = true
|
||||
for _, s := range steps {
|
||||
ok = ok && s.OK
|
||||
}
|
||||
return ok, steps, nil
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/netview"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
)
|
||||
|
||||
// Every connection of the made-up household, step for step and sentence for sentence as ucode says it
|
||||
// (testdata/trace.uc on testdata/access.uci, on the router netview's golden is taken from).
|
||||
func TestHouseholdAsUcode(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/trace.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var trace struct {
|
||||
States map[string]string `json:"states"`
|
||||
Peers map[string]awg.Peer `json:"peers"`
|
||||
Online map[string]bool `json:"online"`
|
||||
Cases []struct {
|
||||
From, To string
|
||||
OK bool `json:"ok"`
|
||||
Steps []Step `json:"steps"`
|
||||
Error string `json:"error"`
|
||||
} `json:"cases"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &trace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
text, _ := os.ReadFile("testdata/access.uci")
|
||||
c, err := uci.Parse(string(text))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := model.Load(c, nil)
|
||||
// the router: what the golden's container said of itself
|
||||
raw, err = os.ReadFile("../netview/testdata/trace.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var router struct {
|
||||
Routes json.RawMessage `json:"routes"`
|
||||
Addrs json.RawMessage `json:"addrs"`
|
||||
Firewall string `json:"firewall"`
|
||||
Links map[string]netview.Link `json:"links"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &router); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fw, _ := uci.Parse(router.Firewall)
|
||||
snap := netview.Take(netview.Sources{Routes: func() []byte { return router.Routes }, Addrs: func() []byte { return router.Addrs },
|
||||
Links: func() map[string]netview.Link { return router.Links }, Zones: func() netview.Zones { return netview.ZonesOf(fw) }})
|
||||
ctx := Ctx{States: trace.States, Peers: trace.Peers, Snap: snap, Online: func(d *model.Device, _ awg.Peer) bool { return trace.Online[d.ID] }}
|
||||
if len(trace.Cases) < 500 {
|
||||
t.Fatalf("only %d cases", len(trace.Cases))
|
||||
}
|
||||
passed, stopped, refused, titles, bad := 0, 0, 0, map[string]bool{}, 0
|
||||
for _, want := range trace.Cases {
|
||||
ok, steps, err := Check(m, want.From, want.To, ctx)
|
||||
if want.Error != "" {
|
||||
refused++
|
||||
if err == nil || err.Error() != want.Error {
|
||||
t.Errorf("%s → %s: %v, ucode refuses with %q", want.From, want.To, err, want.Error)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ok {
|
||||
passed++
|
||||
} else {
|
||||
stopped++
|
||||
}
|
||||
for _, s := range steps {
|
||||
titles[s.Title] = true
|
||||
}
|
||||
if err != nil || ok != want.OK || !reflect.DeepEqual(steps, want.Steps) {
|
||||
if bad++; bad <= 12 {
|
||||
g, _ := json.Marshal(steps)
|
||||
u, _ := json.Marshal(want.Steps)
|
||||
t.Errorf("%s → %s (%v)\n go: %v %s\n ucode: %v %s", want.From, want.To, err, ok, g, want.OK, u)
|
||||
}
|
||||
}
|
||||
}
|
||||
if bad > 0 {
|
||||
t.Errorf("%d of %d cases differ", bad, len(trace.Cases))
|
||||
}
|
||||
if passed < 30 || stopped < 100 || refused < 3 || len(titles) < 60 {
|
||||
t.Fatalf("the household exercises too little: %d pass, %d stop, %d refused, %d different steps", passed, stopped, refused, len(titles))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/netview"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
)
|
||||
|
||||
// A host behind someone's router is checked as the router is: the household on the golden's router, with
|
||||
// Boris's router in Anna's circle (192.168.2.0/24 behind it) and Kira's where everyone reaches everyone.
|
||||
func TestAHostBehindARouter(t *testing.T) {
|
||||
text, _ := os.ReadFile("testdata/access.uci")
|
||||
c, err := uci.Parse(string(text))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for id, net := range map[string]string{"bphone": "192.168.2.0/24", "kphone": "192.168.3.0/24"} {
|
||||
c.Set(id, "kind", "router")
|
||||
c.SetList(id, "behind_net", []string{net})
|
||||
}
|
||||
c.Set("laptop", "lan_bypass", "1")
|
||||
m := model.Load(c, nil)
|
||||
raw, err := os.ReadFile("../netview/testdata/trace.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var router struct {
|
||||
Routes json.RawMessage `json:"routes"`
|
||||
Addrs json.RawMessage `json:"addrs"`
|
||||
Firewall string `json:"firewall"`
|
||||
Links map[string]netview.Link `json:"links"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &router); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fw, _ := uci.Parse(router.Firewall)
|
||||
snap := netview.Take(netview.Sources{Routes: func() []byte { return router.Routes }, Addrs: func() []byte { return router.Addrs },
|
||||
Links: func() map[string]netview.Link { return router.Links }, Zones: func() netview.Zones { return netview.ZonesOf(fw) }})
|
||||
states := map[string]string{}
|
||||
for _, id := range m.PersonIDs() {
|
||||
states[id] = "active"
|
||||
}
|
||||
// every device has a session and is connected now: what stops a connection here is the rules alone
|
||||
peers := map[string]awg.Peer{}
|
||||
for _, id := range m.DeviceIDs() {
|
||||
peers[m.Devices[id].PublicKey] = awg.Peer{Handshake: 1700000000}
|
||||
}
|
||||
ctx := Ctx{States: states, Peers: peers, Snap: snap, Online: func(*model.Device, awg.Peer) bool { return true }}
|
||||
said := func(steps []Step) string {
|
||||
var out []string
|
||||
for _, s := range steps {
|
||||
out = append(out, s.Title)
|
||||
}
|
||||
return strings.Join(out, " | ")
|
||||
}
|
||||
for _, c := range []struct {
|
||||
from, to string
|
||||
ok bool
|
||||
has string
|
||||
}{
|
||||
// Anna's laptop (it keeps its own local network outside, so its configuration names the network) to a host behind Boris's router, in her circle
|
||||
{"laptop", "192.168.2.10", true, "192.168.2.10 is behind Boris · Bphone"},
|
||||
// and back: the host has Boris's access, so it reaches what his router reaches
|
||||
{"192.168.2.10", "laptop", true, "192.168.2.10 is behind Boris · Bphone"},
|
||||
// Fedor is in another circle
|
||||
{"fphone", "192.168.2.10", false, "are not in one circle"},
|
||||
// a home address reaches it as it reaches the router, and it reaches home
|
||||
{"192.168.77.20", "192.168.2.10", true, "192.168.77.20 is at home"},
|
||||
{"192.168.2.10", "192.168.77.20", true, "192.168.2.10 is behind Boris · Bphone"},
|
||||
// the router itself and what is behind it need no tunnel between them
|
||||
{"bphone", "192.168.2.10", false, "192.168.2.10 is behind this device"},
|
||||
// two hosts behind one router likewise
|
||||
{"192.168.2.10", "192.168.2.20", false, "192.168.2.20 is behind this device"},
|
||||
// another server's network is another server's
|
||||
{"phone", "192.168.3.10", false, "is on another server"},
|
||||
// an address behind nobody is what it always was
|
||||
{"phone", "192.168.9.10", false, ""},
|
||||
} {
|
||||
ok, steps, err := Check(m, c.from, c.to, ctx)
|
||||
if err != nil || ok != c.ok || !strings.Contains(said(steps), c.has) {
|
||||
t.Errorf("%s → %s: %v %v, want %v with %q\n %s", c.from, c.to, ok, err, c.ok, c.has, said(steps))
|
||||
}
|
||||
}
|
||||
// a router that waits for the admin's answer stands for nothing yet
|
||||
m.Devices["bphone"].Waiting = true
|
||||
if _, steps, _ := Check(m, "laptop", "192.168.2.10", ctx); strings.Contains(said(steps), "is behind") {
|
||||
t.Errorf("a waiting router's network is checked as its own: %s", said(steps))
|
||||
}
|
||||
}
|
||||
Vendored
+214
@@ -0,0 +1,214 @@
|
||||
config settings 'settings'
|
||||
option portal_enabled '1'
|
||||
option portal_port '4500'
|
||||
option portal_host 'vpn.example.org'
|
||||
list portal_alt '203.0.113.7'
|
||||
|
||||
config server 'home'
|
||||
option name 'Home'
|
||||
option ifname 'dawn0'
|
||||
option port '4500'
|
||||
option subnet '10.77.0.0/24'
|
||||
option private_key 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaA='
|
||||
option public_key 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbA='
|
||||
option auto_lan '0'
|
||||
list lan_device 'dlhome'
|
||||
list lan_device 'br-lan'
|
||||
option mesh 'circles'
|
||||
option lan_like '0'
|
||||
|
||||
config server 'cabin'
|
||||
option name 'Cabin'
|
||||
option ifname 'dawn1'
|
||||
option port '4600'
|
||||
option subnet '10.78.0.0/24'
|
||||
option private_key 'ccccccccccccccccccccccccccccccccccccccccccA='
|
||||
option public_key 'ddddddddddddddddddddddddddddddddddddddddddA='
|
||||
option auto_lan '0'
|
||||
list lan_device 'dlhome'
|
||||
option mesh 'off'
|
||||
|
||||
config server 'open'
|
||||
option name 'Open'
|
||||
option ifname 'dawn2'
|
||||
option port '4700'
|
||||
option subnet '10.79.0.0/24'
|
||||
option private_key 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeA='
|
||||
option public_key 'ffffffffffffffffffffffffffffffffffffffffffA='
|
||||
option auto_lan '0'
|
||||
list lan_device 'br-lan'
|
||||
option mesh 'all'
|
||||
|
||||
config circle 'fam'
|
||||
option server 'home'
|
||||
option name 'Family'
|
||||
|
||||
config circle 'work'
|
||||
option server 'home'
|
||||
option name 'Work'
|
||||
|
||||
config service 'nas'
|
||||
option name 'NAS'
|
||||
option address '192.168.77.5'
|
||||
list ports '445'
|
||||
list ports '139'
|
||||
|
||||
config service 'cam'
|
||||
option name 'Camera'
|
||||
option address '192.168.50.30'
|
||||
|
||||
config person 'anna'
|
||||
option server 'home'
|
||||
option name 'Anna'
|
||||
option access 'both'
|
||||
option circle 'fam'
|
||||
|
||||
config person 'boris'
|
||||
option server 'home'
|
||||
option name 'Boris'
|
||||
option access 'both'
|
||||
option circle 'fam'
|
||||
|
||||
config person 'clara'
|
||||
option server 'home'
|
||||
option name 'Clara'
|
||||
option access 'internet'
|
||||
|
||||
config person 'dima'
|
||||
option server 'home'
|
||||
option name 'Dima'
|
||||
option access 'lan'
|
||||
list home_net 'dlhome'
|
||||
|
||||
config person 'eva'
|
||||
option server 'home'
|
||||
option name 'Eva'
|
||||
option access 'lan'
|
||||
list service 'nas'
|
||||
list service 'cam'
|
||||
|
||||
config person 'fedor'
|
||||
option server 'home'
|
||||
option name 'Fedor'
|
||||
option access 'both'
|
||||
option circle 'work'
|
||||
|
||||
config person 'gleb'
|
||||
option server 'home'
|
||||
option name 'Gleb'
|
||||
option access 'both'
|
||||
option paused '1'
|
||||
|
||||
config person 'hana'
|
||||
option server 'cabin'
|
||||
option name 'Hana'
|
||||
option access 'both'
|
||||
|
||||
config person 'ivan'
|
||||
option server 'cabin'
|
||||
option name 'Ivan'
|
||||
option access 'both'
|
||||
|
||||
config person 'kira'
|
||||
option server 'open'
|
||||
option name 'Kira'
|
||||
option access 'both'
|
||||
|
||||
config person 'lev'
|
||||
option server 'open'
|
||||
option name 'Lev'
|
||||
option access 'both'
|
||||
|
||||
config person 'nora'
|
||||
option server 'home'
|
||||
option name 'Nora'
|
||||
option access 'both'
|
||||
option circle 'fam'
|
||||
list home_net 'br-lan'
|
||||
|
||||
config device 'phone'
|
||||
option person 'anna'
|
||||
option name 'Phone'
|
||||
option address '10.77.0.2'
|
||||
option public_key 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBA='
|
||||
|
||||
config device 'laptop'
|
||||
option person 'anna'
|
||||
option name 'Laptop'
|
||||
option address '10.77.0.3'
|
||||
option public_key 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCA='
|
||||
option lan_bypass '1'
|
||||
option kind 'computer'
|
||||
|
||||
config device 'old'
|
||||
option person 'anna'
|
||||
option name 'Old'
|
||||
option address '10.77.0.4'
|
||||
option public_key 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA='
|
||||
option disabled '1'
|
||||
|
||||
config device 'bphone'
|
||||
option person 'boris'
|
||||
option name 'Bphone'
|
||||
option address '10.77.0.5'
|
||||
option public_key 'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA='
|
||||
|
||||
config device 'cphone'
|
||||
option person 'clara'
|
||||
option name 'Cphone'
|
||||
option address '10.77.0.6'
|
||||
option public_key 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA='
|
||||
|
||||
config device 'dphone'
|
||||
option person 'dima'
|
||||
option name 'Dphone'
|
||||
option address '10.77.0.7'
|
||||
option public_key 'GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGA='
|
||||
|
||||
config device 'ephone'
|
||||
option person 'eva'
|
||||
option name 'Ephone'
|
||||
option address '10.77.0.8'
|
||||
option public_key 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHA='
|
||||
|
||||
config device 'fphone'
|
||||
option person 'fedor'
|
||||
option name 'Fphone'
|
||||
option address '10.77.0.9'
|
||||
option public_key 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIA='
|
||||
|
||||
config device 'gphone'
|
||||
option person 'gleb'
|
||||
option name 'Gphone'
|
||||
option address '10.77.0.10'
|
||||
option public_key 'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJA='
|
||||
|
||||
config device 'hphone'
|
||||
option person 'hana'
|
||||
option name 'Hphone'
|
||||
option address '10.78.0.2'
|
||||
option public_key 'KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKA='
|
||||
|
||||
config device 'iphone'
|
||||
option person 'ivan'
|
||||
option name 'Iphone'
|
||||
option address '10.78.0.3'
|
||||
option public_key 'LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLA='
|
||||
|
||||
config device 'kphone'
|
||||
option person 'kira'
|
||||
option name 'Kphone'
|
||||
option address '10.79.0.2'
|
||||
option public_key 'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMA='
|
||||
|
||||
config device 'lphone'
|
||||
option person 'lev'
|
||||
option name 'Lphone'
|
||||
option address '10.79.0.3'
|
||||
option public_key 'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNA='
|
||||
|
||||
config device 'nphone'
|
||||
option person 'nora'
|
||||
option name 'Nphone'
|
||||
option address '10.77.0.11'
|
||||
option public_key 'OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOA='
|
||||
Vendored
+10583
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user