2023-08-09 00:55:30 +02:00
|
|
|
#!rsc by RouterOS
|
|
|
|
|
# RouterOS script: hotspot-to-wpa.capsman
|
2026-01-01 13:47:40 +01:00
|
|
|
# Copyright (c) 2019-2026 Christian Hesse <mail@eworm.de>
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/COPYING.md
|
2023-08-09 00:55:30 +02:00
|
|
|
#
|
2026-05-13 17:42:43 +02:00
|
|
|
# requires RouterOS, version=7.21
|
2025-01-29 10:35:31 +01:00
|
|
|
# requires device-mode, hotspot
|
2026-07-23 12:47:15 +02:00
|
|
|
# requires policy, policy=read;write
|
2023-11-15 21:31:18 +01:00
|
|
|
#
|
2023-08-09 00:55:30 +02:00
|
|
|
# add private WPA passphrase after hotspot login
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/doc/hotspot-to-wpa.md
|
2023-08-09 00:55:30 +02:00
|
|
|
#
|
|
|
|
|
# !! Do not edit this file, it is generated from template!
|
|
|
|
|
|
2024-12-06 10:31:52 +01:00
|
|
|
:local ExitOK false;
|
2025-05-06 09:44:23 +02:00
|
|
|
:onerror Err {
|
2024-03-06 15:28:55 +01:00
|
|
|
:local ScriptName [ :jobname ];
|
2023-08-09 00:55:30 +02:00
|
|
|
|
2026-07-23 12:47:15 +02:00
|
|
|
:local Address $"address";
|
|
|
|
|
:local Interface $"interface";
|
2024-03-06 15:28:55 +01:00
|
|
|
:local MacAddress $"mac-address";
|
2026-07-23 12:47:15 +02:00
|
|
|
:local UserName $"username";
|
2024-03-06 15:28:55 +01:00
|
|
|
|
2026-07-23 12:47:15 +02:00
|
|
|
:local Hotspot [ /ip/hotspot/host/get [ find where mac-address=$MacAddress authorized ] server ];
|
|
|
|
|
:if ([ :len [ /caps-man/access-list/find where \
|
|
|
|
|
comment=("hotspot-to-wpa template " . $Hotspot) disabled action="reject" ] ] > 0) do={
|
|
|
|
|
:log info ($ScriptName . ": Ignoring login for " . $MacAddress . " on hotspot '" . $Hotspot . "'.");
|
2024-12-06 10:31:52 +01:00
|
|
|
:set ExitOK true;
|
2024-03-06 15:28:55 +01:00
|
|
|
:error false;
|
2024-03-05 16:12:36 +01:00
|
|
|
}
|
2023-08-09 00:55:30 +02:00
|
|
|
|
2026-07-23 12:47:15 +02:00
|
|
|
: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 . "!");
|
2024-12-06 10:31:52 +01:00
|
|
|
:set ExitOK true;
|
2024-03-08 12:45:38 +01:00
|
|
|
:error false;
|
2024-03-04 13:48:01 +01:00
|
|
|
}
|
2023-08-09 00:55:30 +02:00
|
|
|
|
2026-07-23 12:47:15 +02:00
|
|
|
/ip/dhcp-server/lease/set \
|
|
|
|
|
comment=[ :serialize to=json ({ \
|
|
|
|
|
"hotspot-to-wpa"=true; \
|
|
|
|
|
"hotspot"=$Hotspot; \
|
|
|
|
|
"address"=$Address; \
|
|
|
|
|
"interface"=$Interface; \
|
|
|
|
|
"mac-address"=$MacAddress; \
|
|
|
|
|
"username"=$UserName }) ] $Lease;
|
|
|
|
|
/ip/dhcp-server/lease/make-static $Lease;
|
2024-03-04 13:48:01 +01:00
|
|
|
:delay 1s;
|
2026-07-23 12:47:15 +02:00
|
|
|
/ip/dhcp-server/lease/disable $Lease;
|
2025-05-06 09:44:23 +02:00
|
|
|
} do={
|
2026-07-23 12:47:15 +02:00
|
|
|
:if ($ExitOK = false) do={ :log error ([ :jobname ] . ": " . $Err); }
|
2024-12-06 10:31:52 +01:00
|
|
|
}
|