Firewall added & some fixes
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"alpine-router/clients"
|
||||
"alpine-router/config"
|
||||
"alpine-router/dhcp"
|
||||
"alpine-router/nat"
|
||||
)
|
||||
|
||||
func HandleClients(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -88,37 +87,6 @@ func updateClient(mac, hostname string, blocked bool, staticIP string) error {
|
||||
return config.Save(cfg)
|
||||
}
|
||||
|
||||
func applyBlockedFirewall() {
|
||||
if !nat.IsInstalled() {
|
||||
return
|
||||
}
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Printf("Warning: load config for blocked firewall: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var blockedIPs []string
|
||||
for _, kd := range cfg.KnownDevices {
|
||||
if kd.Blocked {
|
||||
ip := kd.IP
|
||||
if kd.StaticIP != "" {
|
||||
ip = kd.StaticIP
|
||||
}
|
||||
if ip != "" {
|
||||
blockedIPs = append(blockedIPs, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
natCfg := &nat.Config{Interfaces: cfg.NAT.Interfaces}
|
||||
if err := nat.ApplyRulesWithBlocked(natCfg, blockedIPs); err != nil {
|
||||
log.Printf("Warning: apply blocked firewall rules: %v", err)
|
||||
} else {
|
||||
log.Printf("Applied firewall rules (%d blocked clients)", len(blockedIPs))
|
||||
}
|
||||
}
|
||||
|
||||
func applyDHCPStaticBindings() {
|
||||
if !dhcp.IsInstalled() {
|
||||
|
||||
Reference in New Issue
Block a user