aboutsummaryrefslogtreecommitdiffstats
path: root/dhcp-lease-comment.template.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-03-04 17:53:35 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-03-04 21:40:34 +0100
commit771ca341b040fdf1a6dc9828deec16bbbe42d797 (patch)
tree6a9e9cdffbdabdae623636509ae2f06bd76f00ef /dhcp-lease-comment.template.rsc
parent64aa6ef1249be378f02b8c211f53a7f12da4f695 (diff)
parent698360f03757cefc08b27c9beac9fe16af7c1d7e (diff)
Merge branch 'main-function' into next
Diffstat (limited to 'dhcp-lease-comment.template.rsc')
-rw-r--r--dhcp-lease-comment.template.rsc45
1 files changed, 25 insertions, 20 deletions
diff --git a/dhcp-lease-comment.template.rsc b/dhcp-lease-comment.template.rsc
index 02bc18c..9f79d06 100644
--- a/dhcp-lease-comment.template.rsc
+++ b/dhcp-lease-comment.template.rsc
@@ -12,30 +12,35 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
-:local 0 [ :jobname ];
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-:global LogPrintExit2;
-:global ScriptLock;
+:local Main do={
+ :local ScriptName [ :tostr $1 ];
-$ScriptLock $0;
+ :global LogPrintExit2;
+ :global ScriptLock;
-:foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic=yes status=bound ] do={
- :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
- :local NewComment;
- :local AccessList ([ /caps-man/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
- :local AccessList ([ /interface/wifi/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
- :local AccessList ([ /interface/wifiwave2/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
- :local AccessList ([ /interface/wireless/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
- :if ([ :len $AccessList ] > 0) do={
- :set NewComment [ /caps-man/access-list/get $AccessList comment ];
- :set NewComment [ /interface/wifi/access-list/get $AccessList comment ];
- :set NewComment [ /interface/wifiwave2/access-list/get $AccessList comment ];
- :set NewComment [ /interface/wireless/access-list/get $AccessList comment ];
- }
- :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
- $LogPrintExit2 info $0 ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false;
- /ip/dhcp-server/lease/set comment=$NewComment $Lease;
+ $ScriptLock $ScriptName;
+
+ :foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic=yes status=bound ] do={
+ :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
+ :local NewComment;
+ :local AccessList ([ /caps-man/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
+ :local AccessList ([ /interface/wifi/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
+ :local AccessList ([ /interface/wifiwave2/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
+ :local AccessList ([ /interface/wireless/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
+ :if ([ :len $AccessList ] > 0) do={
+ :set NewComment [ /caps-man/access-list/get $AccessList comment ];
+ :set NewComment [ /interface/wifi/access-list/get $AccessList comment ];
+ :set NewComment [ /interface/wifiwave2/access-list/get $AccessList comment ];
+ :set NewComment [ /interface/wireless/access-list/get $AccessList comment ];
+ }
+ :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
+ $LogPrintExit2 info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false;
+ /ip/dhcp-server/lease/set comment=$NewComment $Lease;
+ }
}
}
+
+$Main [ :jobname ];