-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathhotspot-to-wpa.capsman.rsc
More file actions
52 lines (47 loc) · 1.68 KB
/
Copy pathhotspot-to-wpa.capsman.rsc
File metadata and controls
52 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!rsc by RouterOS
# RouterOS script: hotspot-to-wpa.capsman
# Copyright (c) 2019-2026 Christian Hesse <mail@eworm.de>
# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.21
# requires device-mode, hotspot
# requires policy, policy=read;write
#
# add private WPA passphrase after hotspot login
# https://rsc.eworm.de/doc/hotspot-to-wpa.md
#
# !! Do not edit this file, it is generated from template!
:local ExitOK false;
:onerror Err {
:local ScriptName [ :jobname ];
:local Address $"address";
:local Interface $"interface";
:local MacAddress $"mac-address";
:local UserName $"username";
: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 . "'.");
:set ExitOK true;
:error false;
}
: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;
}
/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;
:delay 1s;
/ip/dhcp-server/lease/disable $Lease;
} do={
:if ($ExitOK = false) do={ :log error ([ :jobname ] . ": " . $Err); }
}