diff --git a/hotspot-to-wpa-lease.capsman.rsc b/hotspot-to-wpa-lease.capsman.rsc index ae04e7f1..da86b9d5 100644 --- a/hotspot-to-wpa-lease.capsman.rsc +++ b/hotspot-to-wpa-lease.capsman.rsc @@ -43,10 +43,13 @@ :continue; } + :local MacAddress $"mac-address"; + :local UserName $username; + :local Date [ /system/clock/get date ]; :local UserVal ({}); - :if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ - :set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; + :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={ + :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ]; } :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; @@ -58,15 +61,15 @@ :local Template [ /caps-man/access-list/get ([ find where \ comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; - $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ - " (user " . $LeaseVal->"username" . ")."); - /caps-man/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; + $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ + " (user " . $UserName . ")."); + /caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ - mac-address=($LeaseVal->"mac-address") comment=("hotspot-to-wpa: " . $LeaseVal->"username" . \ - ", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; + mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \ + action=reject place-before=$PlaceBefore; - :local Entry [ /caps-man/access-list/find where mac-address=($LeaseVal->"mac-address") \ - comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; + :local Entry [ /caps-man/access-list/find where mac-address=$MacAddress \ + comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ]; :local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ]; :if ([ :len $PrivatePassphrase ] > 0) do={ :if ($PrivatePassphrase = "ignore") do={ diff --git a/hotspot-to-wpa-lease.template.rsc b/hotspot-to-wpa-lease.template.rsc index 2ad5198b..4f02a3db 100644 --- a/hotspot-to-wpa-lease.template.rsc +++ b/hotspot-to-wpa-lease.template.rsc @@ -47,10 +47,13 @@ :continue; } + :local MacAddress $"mac-address"; + :local UserName $username; + :local Date [ /system/clock/get date ]; :local UserVal ({}); - :if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ - :set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; + :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={ + :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ]; } :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; @@ -65,18 +68,18 @@ :local Template [ /interface/wifi/access-list/get ([ find where \ comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; - $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ - " (user " . $LeaseVal->"username" . ")."); - /caps-man/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; - /interface/wifi/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; + $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ + " (user " . $UserName . ")."); + /caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; + /interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ /interface/wifi/access-list/add passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ - mac-address=($LeaseVal->"mac-address") comment=("hotspot-to-wpa: " . $LeaseVal->"username" . \ - ", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; + mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \ + action=reject place-before=$PlaceBefore; - :local Entry [ /caps-man/access-list/find where mac-address=($LeaseVal->"mac-address") \ - :local Entry [ /interface/wifi/access-list/find where mac-address=($LeaseVal->"mac-address") \ - comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; + :local Entry [ /caps-man/access-list/find where mac-address=$MacAddress \ + :local Entry [ /interface/wifi/access-list/find where mac-address=$MacAddress \ + comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ]; # NOT /caps-man/ # :set ($Template->"private-passphrase") ($Template->"passphrase"); # NOT /caps-man/ # diff --git a/hotspot-to-wpa-lease.wifi.rsc b/hotspot-to-wpa-lease.wifi.rsc index 969937a4..89a33836 100644 --- a/hotspot-to-wpa-lease.wifi.rsc +++ b/hotspot-to-wpa-lease.wifi.rsc @@ -43,10 +43,13 @@ :continue; } + :local MacAddress $"mac-address"; + :local UserName $username; + :local Date [ /system/clock/get date ]; :local UserVal ({}); - :if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ - :set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; + :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={ + :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ]; } :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; @@ -58,15 +61,15 @@ :local Template [ /interface/wifi/access-list/get ([ find where \ comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; - $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ - " (user " . $LeaseVal->"username" . ")."); - /interface/wifi/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; + $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ + " (user " . $UserName . ")."); + /interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /interface/wifi/access-list/add passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ - mac-address=($LeaseVal->"mac-address") comment=("hotspot-to-wpa: " . $LeaseVal->"username" . \ - ", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; + mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \ + action=reject place-before=$PlaceBefore; - :local Entry [ /interface/wifi/access-list/find where mac-address=($LeaseVal->"mac-address") \ - comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; + :local Entry [ /interface/wifi/access-list/find where mac-address=$MacAddress \ + comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ]; :set ($Template->"private-passphrase") ($Template->"passphrase"); :local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ]; :if ([ :len $PrivatePassphrase ] > 0) do={ diff --git a/hotspot-to-wpa.capsman.rsc b/hotspot-to-wpa.capsman.rsc index 0b6d1af9..938d0042 100644 --- a/hotspot-to-wpa.capsman.rsc +++ b/hotspot-to-wpa.capsman.rsc @@ -30,12 +30,15 @@ } :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; + :if ([ :len $Lease ] != 1) do={ :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :set ExitOK true; :error false; } + :local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ]; + /ip/dhcp-server/lease/set \ comment=[ :serialize to=json ({ \ "hotspot-to-wpa"=true; \ diff --git a/hotspot-to-wpa.template.rsc b/hotspot-to-wpa.template.rsc index 3a96294a..84bb4181 100644 --- a/hotspot-to-wpa.template.rsc +++ b/hotspot-to-wpa.template.rsc @@ -32,12 +32,15 @@ } :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; + :if ([ :len $Lease ] != 1) do={ :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :set ExitOK true; :error false; } + :local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ]; + /ip/dhcp-server/lease/set \ comment=[ :serialize to=json ({ \ "hotspot-to-wpa"=true; \ diff --git a/hotspot-to-wpa.wifi.rsc b/hotspot-to-wpa.wifi.rsc index 762a3af6..db6a44b2 100644 --- a/hotspot-to-wpa.wifi.rsc +++ b/hotspot-to-wpa.wifi.rsc @@ -30,12 +30,15 @@ } :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; + :if ([ :len $Lease ] != 1) do={ :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :set ExitOK true; :error false; } + :local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ]; + /ip/dhcp-server/lease/set \ comment=[ :serialize to=json ({ \ "hotspot-to-wpa"=true; \