2023-11-14 10:35:17 +01:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: dhcp-lease-comment.wifi
|
2025-01-02 00:04:06 +01:00
|
|
|
# Copyright (c) 2013-2025 Christian Hesse <mail@eworm.de>
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/COPYING.md
|
2023-11-14 10:35:17 +01:00
|
|
|
#
|
|
|
|
# provides: lease-script, order=60
|
2025-02-07 17:39:48 +01:00
|
|
|
# requires RouterOS, version=7.15
|
2023-11-14 10:35:17 +01:00
|
|
|
#
|
|
|
|
# update dhcp-server lease comment with infos from access-list
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/doc/dhcp-lease-comment.md
|
2023-11-14 10:35:17 +01: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 {
|
2025-05-06 14:08:37 +02:00
|
|
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
|
|
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
|
|
|
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
|
2024-03-06 15:28:55 +01:00
|
|
|
:local ScriptName [ :jobname ];
|
2023-11-14 10:35:17 +01:00
|
|
|
|
2024-03-08 12:45:38 +01:00
|
|
|
:global LogPrint;
|
2024-03-04 13:48:00 +01:00
|
|
|
:global ScriptLock;
|
2023-11-14 10:35:17 +01:00
|
|
|
|
2024-03-05 16:12:36 +01:00
|
|
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
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
|
|
|
}
|
2024-03-04 13:48:00 +01:00
|
|
|
|
|
|
|
: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 ([ /interface/wifi/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
|
|
|
|
:if ([ :len $AccessList ] > 0) do={
|
|
|
|
:set NewComment [ /interface/wifi/access-list/get $AccessList comment ];
|
|
|
|
}
|
|
|
|
:if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
|
2024-03-08 12:45:38 +01:00
|
|
|
$LogPrint info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment);
|
2024-03-04 13:48:00 +01:00
|
|
|
/ip/dhcp-server/lease/set comment=$NewComment $Lease;
|
|
|
|
}
|
2023-11-14 10:35:17 +01:00
|
|
|
}
|
2025-05-06 09:44:23 +02:00
|
|
|
} do={
|
|
|
|
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
2024-12-06 10:31:52 +01:00
|
|
|
}
|