feat(routers): integrate Banana Pi Client API and onboard LibreSpeed measurements
Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
This commit is contained in:
@@ -25,13 +25,48 @@ type verification struct {
|
||||
}
|
||||
|
||||
func validCommand(c Command) bool {
|
||||
if c.Action == "" {
|
||||
return c.Mode == "" && len(c.Slots) == 0 && len(c.Username) > 0 && len(c.Username) <= 64 && len(c.Password) > 0 && len(c.Password) <= 256
|
||||
if c.Speedtest != nil || c.SpeedtestCancel != "" || c.Action == "speedtest" || c.Action == "speedtest_cancel" {
|
||||
return validSpeedtest(c)
|
||||
}
|
||||
if c.Username != "" || c.Password != "" {
|
||||
if c.Query != nil || c.Action == "inspect" {
|
||||
return validEvidence(c)
|
||||
}
|
||||
if c.Settings != nil {
|
||||
return validSettings(c)
|
||||
}
|
||||
|
||||
if c.Action == "" {
|
||||
if c.ExpectedBootID != "" || c.ExpectedRevision != "" {
|
||||
return false
|
||||
}
|
||||
if c.Policy != nil || c.Recovery != "" || c.SIM != "" || c.Mode != "" || len(c.Slots) != 0 {
|
||||
return false
|
||||
}
|
||||
if c.ClientAPI != nil {
|
||||
return (c.ModelID == "" || c.ModelID == bananaPiModel) && c.Username == "" && c.Password == "" && len(c.ClientAPI.Token) > 0 && len(c.ClientAPI.Token) <= 4096 && len(c.ClientAPI.CA) > 0 && len(c.ClientAPI.CA) <= 8192
|
||||
}
|
||||
return c.ModelID == "" && len(c.Username) > 0 && len(c.Username) <= 64 && len(c.Password) > 0 && len(c.Password) <= 256
|
||||
}
|
||||
if c.Username != "" || c.Password != "" || c.ClientAPI != nil || c.ModelID != "" {
|
||||
return false
|
||||
}
|
||||
if c.Action == "reboot" {
|
||||
if c.Action == "policy" || c.Action == "recovery" || c.Action == "diagnostics" || (c.Action == "reboot" && c.ExpectedBootID != "") {
|
||||
if c.ExpectedBootID == "" || len(c.ExpectedBootID) > 128 || !revisionIdentifier.MatchString(c.ExpectedRevision) {
|
||||
return false
|
||||
}
|
||||
} else if c.ExpectedBootID != "" || c.ExpectedRevision != "" {
|
||||
return false
|
||||
}
|
||||
if c.Action == "policy" {
|
||||
return c.Mode == "" && len(c.Slots) == 0 && c.Policy != nil && c.Policy.valid() && c.Recovery == "" && c.SIM == ""
|
||||
}
|
||||
if c.Action == "recovery" {
|
||||
return c.Mode == "" && len(c.Slots) == 0 && c.Policy == nil && ((c.Recovery == "wan_reconnect" && simSlot(c.SIM) != 0) || ((c.Recovery == "vpn_reconnect" || c.Recovery == "dns_restart") && c.SIM == ""))
|
||||
}
|
||||
if c.Policy != nil || c.Recovery != "" || c.SIM != "" {
|
||||
return false
|
||||
}
|
||||
if c.Action == "reboot" || c.Action == "diagnostics" {
|
||||
return c.Mode == "" && len(c.Slots) == 0
|
||||
}
|
||||
if c.Action != "mode" || (c.Mode != "direct" && c.Mode != "aggregation") || len(c.Slots) < 1 || len(c.Slots) > 3 || (c.Mode == "direct" && len(c.Slots) != 1) {
|
||||
@@ -126,7 +161,7 @@ func controlForm(cmd Command, manual map[string]any) (url.Values, string, error)
|
||||
|
||||
func (c *Collector) setControlResult(cmd Command, state, reason string) {
|
||||
c.mu.Lock()
|
||||
c.results[cmd.ID] = Result{ID: cmd.ID, DeviceID: cmd.DeviceID, Action: cmd.Action, State: state, Error: reason}
|
||||
c.results[cmd.ID] = Result{At: time.Now().Unix(), ID: cmd.ID, DeviceID: cmd.DeviceID, Action: cmd.Action, State: state, Error: reason}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -148,6 +183,15 @@ func (c *Collector) applyControl(parent context.Context, cmd Command) {
|
||||
if !ok || r.Access == nil || r.Rejected || r.Device.State != "ready" {
|
||||
return
|
||||
}
|
||||
if r.Access.ClientAPI != nil {
|
||||
c.applyClientControl(ctx, cmd, r)
|
||||
sent = true
|
||||
return
|
||||
}
|
||||
if cmd.Action != "mode" && cmd.Action != "reboot" {
|
||||
result = "command_rejected"
|
||||
return
|
||||
}
|
||||
for _, candidate := range c.candidates(ctx) {
|
||||
if c.neighbor(candidate.Interface, candidate.Address) != r.MAC {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user