mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-22 17:15:05 +00:00
b5fd864320
* feat: optional per-device ip address tracking via periodic arp scan Adds a per-device "Track IP address" toggle (disabled by default) and a global cron interval setting. When enabled, upsnap periodically arp-scans the local subnets of opted-in devices with nmap and updates a device's ip address whenever its mac address is found at a different one. Subnets are skipped unless directly attached to the host, so routed devices are never scanned. Uses the same nmap + CAP_NET_RAW requirements as the existing network scan feature; no new privileges needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test: cover ip tracking subnet helpers and nmap xml parsing Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor: extract ip tracking into its own package and expand test coverage Move the arp scan sweep out of cronjobs into a new iptracking package with two entry points: TrackAllSubnets (the cron sweep) and TrackOneSubnet (a single validated scan). Device lookup is now by mac address across all tracked devices, with updates constrained to the device's own subnet. The scannability check becomes networking.ValidateScannableSubnet, which reports why a subnet can't be scanned and accepts any subnet overlapping a directly attached network, so sub-blocks of an attached prefix are now scannable. The mac-to-ip mapping moves to networking as Nmaprun.MacToIP. Cover the subnet guard, mac normalization, skip paths, and sweep orchestration with tests against a stubbed scanner and a real migrated schema. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: pause tracking sweeps while nobody is connected With lazy_ping turned on, the periodic tracking sweep now skips its tick while no realtime clients are connected, just like the ping cron, and owes a catch-up sweep to the next client that connects: the realtime connect hook runs one sweep only when a tick was actually skipped (or none has run since boot), so page reloads during active use trigger nothing. This extends lazy_ping's meaning from "pause pings when idle" to "pause periodic network activity when idle"; the setting's description is updated accordingly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ui: move lazy ping section below ip tracking in settings Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * disable toggle when tracking is disabled * fix: load private store --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Maxi Quoß <maxi@quoss.org>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
//go:build linux
|
|
|
|
package networking
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"kernel.org/pub/linux/libs/security/libcap/cap"
|
|
)
|
|
|
|
func NmapScan(scanRange string) (Nmaprun, error) {
|
|
orig := cap.GetProc()
|
|
defer orig.SetProc() // restore original caps on exit.
|
|
|
|
c, err := orig.Dup()
|
|
if err != nil {
|
|
return Nmaprun{}, fmt.Errorf("Failed to dup existing capabilities: %v", err)
|
|
}
|
|
|
|
if on, _ := c.GetFlag(cap.Permitted, cap.NET_RAW); !on {
|
|
return Nmaprun{}, fmt.Errorf("unable to get NET_RAW permissions")
|
|
}
|
|
|
|
if err := c.SetFlag(cap.Effective, true, cap.NET_RAW); err != nil {
|
|
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability effective")
|
|
}
|
|
|
|
if err := c.SetFlag(cap.Inheritable, true, cap.NET_RAW); err != nil {
|
|
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability inheritable")
|
|
}
|
|
|
|
if err := c.SetProc(); err != nil {
|
|
return Nmaprun{}, fmt.Errorf("unable to raise NET_RAW capability")
|
|
}
|
|
|
|
if err := cap.SetAmbient(true, cap.NET_RAW); err != nil {
|
|
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability ambient")
|
|
}
|
|
|
|
return runNmap(scanRange)
|
|
}
|