aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-08-07 14:37:52 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-08-07 22:10:44 +0200
commit1b947f445bfffb099b0f0fdc2011672ae716aa51 (patch)
tree26089caffb01073a386bb6498b3781268de2c596
parentc37739c2f6b050c965e0fa734309e1ecbed90add (diff)
Makefile: drop path rewriting, use pattern to filter
-rw-r--r--Makefile4
-rw-r--r--accesslist-duplicates.template.rsc16
-rw-r--r--collect-wireless-mac.template.rsc28
-rw-r--r--daily-psk.template.rsc19
-rw-r--r--dhcp-lease-comment.template.rsc10
5 files changed, 46 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 8c9bcf5..0179c6f 100644
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,12 @@ all: $(CAPSMAN) $(LOCAL) $(HTML)
markdown $< | sed 's/href="\([-_\./[:alnum:]]*\)\.md"/href="\1.html"/g' > $@
%.local.rsc: %.template.rsc Makefile
- sed -e '/\/caps-man/d' -e 's|%PATH%|interface\/wireless|' -e 's|%TEMPL%|.local|' \
+ sed -e '/\/caps-man/d' -e 's|%TEMPL%|.local|' \
-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
< $< > $@
%.capsman.rsc: %.template.rsc Makefile
- sed -e '/\/interface\/wireless/d' -e 's|%PATH%|caps-man|' -e 's|%TEMPL%|.capsman|' \
+ sed -e '/\/interface\/wireless/d' -e 's|%TEMPL%|.capsman|' \
-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
< $< > $@
diff --git a/accesslist-duplicates.template.rsc b/accesslist-duplicates.template.rsc
index 80c47a9..b01c90d 100644
--- a/accesslist-duplicates.template.rsc
+++ b/accesslist-duplicates.template.rsc
@@ -6,8 +6,8 @@
# print duplicate antries in wireless access list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/accesslist-duplicates.md
#
-# !! This is just a template! Replace '%PATH%' with 'caps-man'
-# !! or 'interface wireless'!
+# !! This is just a template to generate the real script!
+# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:local 0 "accesslist-duplicates%TEMPL%";
:global GlobalFunctionsReady;
@@ -18,8 +18,10 @@
:local Seen ({});
:local Shown ({});
-:foreach AccList in=[ /%PATH%/access-list/find where mac-address!="00:00:00:00:00:00" ] do={
- :local Mac [ /%PATH%/access-list/get $AccList mac-address ];
+:foreach AccList in=[ /caps-man/access-list/find where mac-address!="00:00:00:00:00:00" ] do={
+:foreach AccList in=[ /interface/wireless/access-list/find where mac-address!="00:00:00:00:00:00" ] do={
+ :local Mac [ /caps-man/access-list/get $AccList mac-address ];
+ :local Mac [ /interface/wireless/access-list/get $AccList mac-address ];
:foreach SeenMac in=$Seen do={
:if ($SeenMac = $Mac) do={
:local Skip 0;
@@ -27,14 +29,16 @@
:if ($ShownMac = $Mac) do={ :set Skip 1; }
}
:if ($Skip = 0) do={
- /%PATH%/access-list/print where mac-address=$Mac;
+ /caps-man/access-list/print where mac-address=$Mac;
+ /interface/wireless/access-list/print where mac-address=$Mac;
:set Shown ($Shown, $Mac);
:put "\nNumeric id to remove, any key to skip!";
:local Remove [ :tonum [ $Read ] ];
:if ([ :typeof $Remove ] = "num") do={
:put ("Removing numeric id " . $Remove . "...\n");
- /%PATH%/access-list/remove $Remove;
+ /caps-man/access-list/remove $Remove;
+ /interface/wireless/access-list/remove $Remove;
}
}
}
diff --git a/collect-wireless-mac.template.rsc b/collect-wireless-mac.template.rsc
index 6f9efc5..eb92270 100644
--- a/collect-wireless-mac.template.rsc
+++ b/collect-wireless-mac.template.rsc
@@ -8,8 +8,8 @@
#
# provides: lease-script, order=40
#
-# !! This is just a template! Replace '%PATH%' with 'caps-man'
-# !! or 'interface wireless'!
+# !! This is just a template to generate the real script!
+# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:local 0 "collect-wireless-mac%TEMPL%";
:global GlobalFunctionsReady;
@@ -27,25 +27,32 @@
$ScriptLock $0 false 10;
-:if ([ :len [ /%PATH%/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
- /%PATH%/access-list/add comment="--- collected above ---" disabled=yes;
+:if ([ :len [ /caps-man/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
+:if ([ :len [ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
+ /caps-man/access-list/add comment="--- collected above ---" disabled=yes;
+ /interface/wireless/access-list/add comment="--- collected above ---" disabled=yes;
$LogPrintExit2 warning $0 ("Added disabled access-list entry with comment '--- collected above ---'.") false;
}
-:local PlaceBefore ([ /%PATH%/access-list/find where comment="--- collected above ---" disabled ]->0);
+:local PlaceBefore ([ /caps-man/access-list/find where comment="--- collected above ---" disabled ]->0);
+:local PlaceBefore ([ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ]->0);
-:foreach Reg in=[ /%PATH%/registration-table/find ] do={
+:foreach Reg in=[ /caps-man/registration-table/find ] do={
+:foreach Reg in=[ /interface/wireless/registration-table/find ] do={
:local RegVal;
:do {
- :set RegVal [ /%PATH%/registration-table/get $Reg ];
+ :set RegVal [ /caps-man/registration-table/get $Reg ];
+ :set RegVal [ /interface/wireless/registration-table/get $Reg ];
} on-error={
$LogPrintExit2 debug $0 ("Device already gone... Ignoring.") false;
}
:if ([ :len ($RegVal->"mac-address") ] > 0) do={
- :local AccessList ([ /%PATH%/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
+ :local AccessList ([ /caps-man/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
+ :local AccessList ([ /interface/wireless/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
:if ([ :len $AccessList ] > 0) do={
$LogPrintExit2 debug $0 ("MAC address " . $RegVal->"mac-address" . " already known: " . \
- [ /%PATH%/access-list/get $AccessList comment ]) false;
+ [ /caps-man/access-list/get $AccessList comment ]) false;
+ [ /interface/wireless/access-list/get $AccessList comment ]) false;
}
:if ([ :len $AccessList ] = 0) do={
@@ -68,7 +75,8 @@ $ScriptLock $0 false 10;
:local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface");
$LogPrintExit2 info $0 $Message false;
- /%PATH%/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes;
+ /caps-man/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes;
+ /interface/wireless/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes;
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \
message=("A device with unknown MAC address connected to " . $RegVal->"ssid" . " on " . $Identity . ".\n\n" . \
diff --git a/daily-psk.template.rsc b/daily-psk.template.rsc
index 777f6c0..ea0fb46 100644
--- a/daily-psk.template.rsc
+++ b/daily-psk.template.rsc
@@ -7,8 +7,8 @@
# update daily PSK (pre shared key)
# https://git.eworm.de/cgit/routeros-scripts/about/doc/daily-psk.md
#
-# !! This is just a template! Replace '%PATH%' with 'caps-man'
-# !! or 'interface wireless'!
+# !! This is just a template to generate the real script!
+# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:local 0 "daily-psk%TEMPL%";
:global GlobalFunctionsReady;
@@ -55,24 +55,25 @@ $WaitFullyConnected;
:local Date [ /system/clock/get date ];
:local NewPsk [ $GeneratePSK $Date ];
-:foreach AccList in=[ /%PATH%/access-list/find where comment~$DailyPskMatchComment ] do={
- :local IntName [ /interface/wireless/access-list/get $AccList interface ];
- :local Ssid [ /interface/wireless/get $IntName ssid ];
- :local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
- # /interface/wireless above - /caps-man below
+:foreach AccList in=[ /caps-man/access-list/find where comment~$DailyPskMatchComment ] do={
+:foreach AccList in=[ /interface/wireless/access-list/find where comment~$DailyPskMatchComment ] do={
:local SsidRegExp [ /caps-man/access-list/get $AccList ssid-regexp ];
:local Configuration ([ /caps-man/configuration/find where ssid~$SsidRegExp ]->0);
:local Ssid [ /caps-man/configuration/get $Configuration ssid ];
:local OldPsk [ /caps-man/access-list/get $AccList private-passphrase ];
+ # /caps-man above - /interface/wireless below
+ :local IntName [ /interface/wireless/access-list/get $AccList interface ];
+ :local Ssid [ /interface/wireless/get $IntName ssid ];
+ :local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
:local Skip 0;
:if ($NewPsk != $OldPsk) do={
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
- /interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
/caps-man/access-list/set $AccList private-passphrase=$NewPsk;
+ /interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
- :if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
+ :if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
:foreach SeenSsid in=$Seen do={
:if ($SeenSsid = $Ssid) do={
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
diff --git a/dhcp-lease-comment.template.rsc b/dhcp-lease-comment.template.rsc
index be28cfd..3fe9b64 100644
--- a/dhcp-lease-comment.template.rsc
+++ b/dhcp-lease-comment.template.rsc
@@ -8,8 +8,8 @@
# update dhcp-server lease comment with infos from access-list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-lease-comment.md
#
-# !! This is just a template! Replace '%PATH%' with 'caps-man'
-# !! or 'interface wireless'!
+# !! This is just a template to generate the real script!
+# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:local 0 "dhcp-lease-comment%TEMPL%";
:global GlobalFunctionsReady;
@@ -23,9 +23,11 @@ $ScriptLock $0;
: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 ([ /%PATH%/access-list/find where mac-address=($LeaseVal->"active-mac-address") ]->0);
+ :local AccessList ([ /caps-man/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 [ /%PATH%/access-list/get $AccessList comment ];
+ :set NewComment [ /caps-man/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;