Compare commits

..

4 commits

Author SHA1 Message Date
Christian Hesse
f2bffb1c68 FIXUP 2026-07-31 23:38:04 +02:00
Christian Hesse
8678792837 FIXUP 2026-07-31 21:47:46 +02:00
Christian Hesse
94ea51da09 FIXUP 2026-07-31 21:37:45 +02:00
Christian Hesse
1927330c88 hotspot-to-wpa: rework for RouterOS 7.24 compatibility 2026-07-31 21:10:37 +02:00
6 changed files with 47 additions and 29 deletions

View file

@ -43,10 +43,13 @@
:continue; :continue;
} }
:local MacAddress $"mac-address";
:local UserName $username;
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
:local UserVal ({}); :local UserVal ({});
:if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={
:set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ];
} }
:local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ];
@ -58,15 +61,15 @@
:local Template [ /caps-man/access-list/get ([ find where \ :local Template [ /caps-man/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ];
$LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $LeaseVal->"username" . ")."); " (user " . $UserName . ").");
/caps-man/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; /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\$" \ /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \
mac-address=($LeaseVal->"mac-address") comment=("hotspot-to-wpa: " . $LeaseVal->"username" . \ mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \
", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; action=reject place-before=$PlaceBefore;
:local Entry [ /caps-man/access-list/find where mac-address=($LeaseVal->"mac-address") \ :local Entry [ /caps-man/access-list/find where mac-address=$MacAddress \
comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ];
:local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ]; :local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ];
:if ([ :len $PrivatePassphrase ] > 0) do={ :if ([ :len $PrivatePassphrase ] > 0) do={
:if ($PrivatePassphrase = "ignore") do={ :if ($PrivatePassphrase = "ignore") do={

View file

@ -47,10 +47,13 @@
:continue; :continue;
} }
:local MacAddress $"mac-address";
:local UserName $username;
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
:local UserVal ({}); :local UserVal ({});
:if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={
:set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ];
} }
:local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ];
@ -65,18 +68,18 @@
:local Template [ /interface/wifi/access-list/get ([ find where \ :local Template [ /interface/wifi/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ];
$LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $LeaseVal->"username" . ")."); " (user " . $UserName . ").");
/caps-man/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; /caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ];
/interface/wifi/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") 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\$" \ /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \
/interface/wifi/access-list/add 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" . \ mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \
", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; action=reject place-before=$PlaceBefore;
:local Entry [ /caps-man/access-list/find where mac-address=($LeaseVal->"mac-address") \ :local Entry [ /caps-man/access-list/find where mac-address=$MacAddress \
:local Entry [ /interface/wifi/access-list/find where mac-address=($LeaseVal->"mac-address") \ :local Entry [ /interface/wifi/access-list/find where mac-address=$MacAddress \
comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ];
# NOT /caps-man/ # # NOT /caps-man/ #
:set ($Template->"private-passphrase") ($Template->"passphrase"); :set ($Template->"private-passphrase") ($Template->"passphrase");
# NOT /caps-man/ # # NOT /caps-man/ #

View file

@ -43,10 +43,13 @@
:continue; :continue;
} }
:local MacAddress $"mac-address";
:local UserName $username;
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
:local UserVal ({}); :local UserVal ({});
:if ([ :len [ /ip/hotspot/user/find where name=($LeaseVal->"username") ] ] > 0) do={ :if ([ :len [ /ip/hotspot/user/find where name=$UserName ] ] > 0) do={
:set UserVal [ /ip/hotspot/user/get [ find where name=($LeaseVal->"username") ] ]; :set UserVal [ /ip/hotspot/user/get [ find where name=$UserName ] ];
} }
:local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ]; :local UserInfo [ $ParseKeyValueStore ($UserVal->"comment") ];
@ -58,15 +61,15 @@
:local Template [ /interface/wifi/access-list/get ([ find where \ :local Template [ /interface/wifi/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ]; comment=("hotspot-to-wpa template " . $LeaseVal->"hotspot") disabled ]->0) ];
$LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $LeaseVal->"mac-address" . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $LeaseVal->"username" . ")."); " (user " . $UserName . ").");
/interface/wifi/access-list/remove [ find where mac-address=($LeaseVal->"mac-address") comment~"^hotspot-to-wpa: " ]; /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\$" \ /interface/wifi/access-list/add passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \
mac-address=($LeaseVal->"mac-address") comment=("hotspot-to-wpa: " . $LeaseVal->"username" . \ mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \
", " . $LeaseVal->"mac-address" . ", " . $Date) action=reject place-before=$PlaceBefore; action=reject place-before=$PlaceBefore;
:local Entry [ /interface/wifi/access-list/find where mac-address=($LeaseVal->"mac-address") \ :local Entry [ /interface/wifi/access-list/find where mac-address=$MacAddress \
comment=("hotspot-to-wpa: " . $LeaseVal->"username" . ", " . $LeaseVal->"mac-address" . ", " . $Date) ]; comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) ];
:set ($Template->"private-passphrase") ($Template->"passphrase"); :set ($Template->"private-passphrase") ($Template->"passphrase");
:local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ]; :local PrivatePassphrase [ $EitherOr ($UserInfo->"private-passphrase") ($Template->"private-passphrase") ];
:if ([ :len $PrivatePassphrase ] > 0) do={ :if ([ :len $PrivatePassphrase ] > 0) do={

View file

@ -30,12 +30,15 @@
} }
:local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ];
:if ([ :len $Lease ] != 1) do={ :if ([ :len $Lease ] != 1) do={
:log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!");
:set ExitOK true; :set ExitOK true;
:error false; :error false;
} }
:local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ];
/ip/dhcp-server/lease/set \ /ip/dhcp-server/lease/set \
comment=[ :serialize to=json ({ \ comment=[ :serialize to=json ({ \
"hotspot-to-wpa"=true; \ "hotspot-to-wpa"=true; \

View file

@ -32,12 +32,15 @@
} }
:local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ];
:if ([ :len $Lease ] != 1) do={ :if ([ :len $Lease ] != 1) do={
:log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!");
:set ExitOK true; :set ExitOK true;
:error false; :error false;
} }
:local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ];
/ip/dhcp-server/lease/set \ /ip/dhcp-server/lease/set \
comment=[ :serialize to=json ({ \ comment=[ :serialize to=json ({ \
"hotspot-to-wpa"=true; \ "hotspot-to-wpa"=true; \

View file

@ -30,12 +30,15 @@
} }
:local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ]; :local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ];
:if ([ :len $Lease ] != 1) do={ :if ([ :len $Lease ] != 1) do={
:log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!"); :log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!");
:set ExitOK true; :set ExitOK true;
:error false; :error false;
} }
:local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ];
/ip/dhcp-server/lease/set \ /ip/dhcp-server/lease/set \
comment=[ :serialize to=json ({ \ comment=[ :serialize to=json ({ \
"hotspot-to-wpa"=true; \ "hotspot-to-wpa"=true; \