Commit 870f00bb authored by Christian Hesse's avatar Christian Hesse

global: variable names are CamelCase

            ___  _         ___     __
           / _ )(_)__ _   / _/__ _/ /_
          / _  / / _ `/  / _/ _ `/ __/
         /____/_/\_, /  /_/ \_,_/\__/
 _       __     /___/       _             __
| |     / /___ __________  (_)___  ____ _/ /
| | /| / / __ `/ ___/ __ \/ / __ \/ __ `/ /
| |/ |/ / /_/ / /  / / / / / / / / /_/ /_/
|__/|__/\__,_/_/  /_/ /_/_/_/ /_/\__, (_)
                                /____/

RouterOS has some odd behavior when it comes to variable names. Let's
have a look at the interfaces:

[[email protected]] > / interface print where name=en1
Flags: D - dynamic, X - disabled, R - running, S - slave
 #     NAME                                TYPE       ACTUAL-MTU L2MTU
 0  RS en1                                 ether            1500  1598

That looks ok. Now we use a script:

{ :local interface "en1";
  / interface print where name=$interface; }

And the result...

[[email protected]] > { :local interface "en1";
{...   / interface print where name=$interface; }
Flags: D - dynamic, X - disabled, R - running, S - slave
 #     NAME                                TYPE       ACTUAL-MTU L2MTU
 0  RS en1                                 ether            1500  1598

... still looks ok.
We make a little modification to the script:

{ :local name "en1";
  / interface print where name=$name; }

And the result:

[[email protected]] > { :local name "en1";
{...   / interface print where name=$name; }
Flags: D - dynamic, X - disabled, R - running, S - slave
 #     NAME                                TYPE       ACTUAL-MTU L2MTU
 0  RS en1                                 ether            1500  1598
 1   S en2                                 ether            1500  1598
 2   S en3                                 ether            1500  1598
 3   S en4                                 ether            1500  1598
 4   S en5                                 ether            1500  1598
 5  R  br-local                            bridge           1500  1598

Ups! The filter has no effect!
That happens whenever the variable name ($name) matches the property
name (name=).

And another modification:

{ :local type "en1";
  / interface print where name=$type; }

And the result:

[[email protected]] > { :local type "en1";
{...   / interface print where name=$type; }
Flags: D - dynamic, X - disabled, R - running, S - slave
 #     NAME                                TYPE       ACTUAL-MTU L2MTU

Ups! Nothing?
Even if the variable name ($type) matches whatever property name (type=)
things go wrong.

The answer from MikroTik support (in Ticket#2019010222000454):

> This is how scripting works in RouterOS and we will not fix it.

To get around this we use variable names in CamelCase. Let's hope
Mikrotik never ever introduces property names in CamelCase...

*fingers crossed*
parent 7d06a7e8
......@@ -78,7 +78,7 @@ crap and a good example how to *not* do it.
Now let's download the main scripts and add them in configuration on the fly.
[[email protected]] > :foreach script in={ "global-config"; "global-functions"; "script-updates" } do={ / system script add name=$script source=([ / tool fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit.cgi/routeros-scripts/plain/" . $script) output=user as-value]->"data"); }
[[email protected]] > :foreach Script in={ "global-config"; "global-functions"; "script-updates" } do={ / system script add name=$Script source=([ / tool fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit.cgi/routeros-scripts/plain/" . $Script) output=user as-value]->"data"); }
The configuration needs to be tweaked for your needs. Make sure not to send
your mails to `[email protected]`!
......
......@@ -6,31 +6,31 @@
#
# !! Do not edit this file, it is generated from template!
:local seen [ :toarray "" ];
:local shown [ :toarray "" ];
:global Read;
:foreach acclist in=[ / caps-man access-list find where mac-address!="00:00:00:00:00:00" ] do={
:local mac [ / caps-man access-list get $acclist mac-address ];
:foreach "seen-mac" in=$seen do={
:if ($"seen-mac" = $mac) do={
:local skip 0;
:foreach "shown-mac" in=$shown do={
:if ($"shown-mac" = $mac) do={ :set skip 1; }
:local Seen [ :toarray "" ];
:local Shown [ :toarray "" ];
:foreach AccList in=[ / caps-man access-list find where mac-address!="00:00:00:00:00:00" ] do={
:local Mac [ / caps-man access-list get $AccList mac-address ];
:foreach SeenMac in=$Seen do={
:if ($SeenMac = $Mac) do={
:local Skip 0;
:foreach ShownMac in=$Shown do={
:if ($ShownMac = $Mac) do={ :set Skip 1; }
}
:if ($skip = 0) do={
/ caps-man access-list print where mac-address=$mac;
:set shown ( $shown , $mac );
:if ($Skip = 0) do={
/ caps-man access-list print where mac-address=$Mac;
:set Shown ($Shown, $Mac);
:put "\nEnter to skip, numeric id to remove!";
:local remove [ $Read ];
:if ($remove != "") do={
:put ("Removing numeric id " . $remove . "...\n");
/ caps-man access-list remove $remove;
:local Remove [ $Read ];
:if ($Remove != "") do={
:put ("Removing numeric id " . $Remove . "...\n");
/ caps-man access-list remove $Remove;
}
}
}
}
:set seen ( $seen , $mac );
:set Seen ($Seen, $Mac);
}
......@@ -6,31 +6,31 @@
#
# !! Do not edit this file, it is generated from template!
:local seen [ :toarray "" ];
:local shown [ :toarray "" ];
:global Read;
:foreach acclist in=[ / interface wireless access-list find where mac-address!="00:00:00:00:00:00" ] do={
:local mac [ / interface wireless access-list get $acclist mac-address ];
:foreach "seen-mac" in=$seen do={
:if ($"seen-mac" = $mac) do={
:local skip 0;
:foreach "shown-mac" in=$shown do={
:if ($"shown-mac" = $mac) do={ :set skip 1; }
:local Seen [ :toarray "" ];
:local Shown [ :toarray "" ];
:foreach AccList in=[ / interface wireless access-list find where mac-address!="00:00:00:00:00:00" ] do={
:local Mac [ / interface wireless access-list get $AccList mac-address ];
:foreach SeenMac in=$Seen do={
:if ($SeenMac = $Mac) do={
:local Skip 0;
:foreach ShownMac in=$Shown do={
:if ($ShownMac = $Mac) do={ :set Skip 1; }
}
:if ($skip = 0) do={
/ interface wireless access-list print where mac-address=$mac;
:set shown ( $shown , $mac );
:if ($Skip = 0) do={
/ interface wireless access-list print where mac-address=$Mac;
:set Shown ($Shown, $Mac);
:put "\nEnter to skip, numeric id to remove!";
:local remove [ $Read ];
:if ($remove != "") do={
:put ("Removing numeric id " . $remove . "...\n");
/ interface wireless access-list remove $remove;
:local Remove [ $Read ];
:if ($Remove != "") do={
:put ("Removing numeric id " . $Remove . "...\n");
/ interface wireless access-list remove $Remove;
}
}
}
}
:set seen ( $seen , $mac );
:set Seen ($Seen, $Mac);
}
......@@ -7,31 +7,31 @@
# !! This is just a template! Replace '%PATH%' with 'caps-man'
# !! or 'interface wireless'!
:local seen [ :toarray "" ];
:local shown [ :toarray "" ];
:global Read;
: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 "seen-mac" in=$seen do={
:if ($"seen-mac" = $mac) do={
:local skip 0;
:foreach "shown-mac" in=$shown do={
:if ($"shown-mac" = $mac) do={ :set skip 1; }
:local Seen [ :toarray "" ];
:local Shown [ :toarray "" ];
: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 SeenMac in=$Seen do={
:if ($SeenMac = $Mac) do={
:local Skip 0;
:foreach ShownMac in=$Shown do={
:if ($ShownMac = $Mac) do={ :set Skip 1; }
}
:if ($skip = 0) do={
/ %PATH% access-list print where mac-address=$mac;
:set shown ( $shown , $mac );
:if ($Skip = 0) do={
/ %PATH% access-list print where mac-address=$Mac;
:set Shown ($Shown, $Mac);
:put "\nEnter to skip, numeric id to remove!";
:local remove [ $Read ];
:if ($remove != "") do={
:put ("Removing numeric id " . $remove . "...\n");
/ %PATH% access-list remove $remove;
:local Remove [ $Read ];
:if ($Remove != "") do={
:put ("Removing numeric id " . $Remove . "...\n");
/ %PATH% access-list remove $Remove;
}
}
}
}
:set seen ( $seen , $mac );
:set Seen ($Seen, $Mac);
}
......@@ -4,27 +4,27 @@
#
# reset bridge ports to default bridge
:global "bridge-port-to";
:global BridgePortTo;
:local "len" ([ :len $"bridge-port-to" ] + 1);
:local Len ([ :len $BridgePortTo ] + 1);
:if ($"len" = 1) do={
:if ($Len = 1) do={
:delay 1s;
:set "len" ([ :len $"bridge-port-to" ] + 1);
:set Len ([ :len $BridgePortTo ] + 1);
}
:foreach interface in=[ / interface bridge port find where comment!="" ] do={
:foreach comment in=[ :toarray [ / interface bridge port get $interface comment ] ] do={
:if ([ :pick $comment 0 $len ] = ($"bridge-port-to" . ":")) do={
:local "interface-name" [ / interface bridge port get $interface interface ];
:local "bridge-default" [ :pick $comment $len [ :len $comment ] ];
:local "bridge-current" [ / interface bridge port get $interface bridge ];
:if ($"bridge-default" != $"bridge-current") do={
:log info ("Changing interface " . $"interface-name" . " to " . $"bridge-port-to" . " bridge " . $"bridge-default");
/ interface bridge port set bridge=$"bridge-default" $interface;
/ ip dhcp-client renew [ find where interface=$"bridge-default" ];
:foreach Interface in=[ / interface bridge port find where comment!="" ] do={
:foreach Comment in=[ :toarray [ / interface bridge port get $Interface comment ] ] do={
:if ([ :pick $Comment 0 $Len ] = ($BridgePortTo . ":")) do={
:local InterfaceName [ / interface bridge port get $Interface interface ];
:local BridgeDefault [ :pick $Comment $Len [ :len $Comment ] ];
:local BridgeCurrent [ / interface bridge port get $Interface bridge ];
:if ($BridgeDefault != $BridgeCurrent) do={
:log info ("Changing interface " . $InterfaceName . " to " . $BridgePortTo . " bridge " . $BridgeDefault);
/ interface bridge port set bridge=$BridgeDefault $Interface;
/ ip dhcp-client renew [ find where interface=$BridgeDefault ];
} else={
:log debug ("Interface " . $"interface-name" . " already connected to " . $"bridge-port-to" . " bridge " . $"bridge-default");
:log debug ("Interface " . $InterfaceName . " already connected to " . $BridgePortTo . " bridge " . $BridgeDefault);
}
}
}
......
......@@ -4,12 +4,12 @@
#
# toggle bridge ports between default and alt bridge
:global "bridge-port-to";
:global BridgePortTo;
:if ($"bridge-port-to" != "default") do={
:set "bridge-port-to" "default";
:if ($BridgePortTo != "default") do={
:set BridgePortTo "default";
} else={
:set "bridge-port-to" "alt";
:set BridgePortTo "alt";
}
/ system script run bridge-port-to-default;
......@@ -9,29 +9,29 @@
:global DownloadPackage;
:local "package-path" [ / caps-man manager get package-path ];
:if ([ :pick $"package-path" 0 ] = "/") do={
:set "package-path" [ :pick $"package-path" 1 [ :len $"package-path" ] ];
:local PackagePath [ / caps-man manager get package-path ];
:if ([ :pick $PackagePath 0 ] = "/") do={
:set PackagePath [ :pick $PackagePath 1 [ :len $PackagePath ] ];
}
:local "installed-version" [ / system package update get installed-version ];
:local updated false;
:local InstalledVersion [ / system package update get installed-version ];
:local Updated false;
:foreach package in=[ / file find where type=package \
package-version!=$"installed-version" name~("^" . $"package-path") ] do={
:local "package-name" [ / file get $package package-name ];
:local "package-architecture" [ / file get $package package-architecture ];
:if ($"package-architecture" = "mips") do={
:set "package-architecture" "mipsbe";
:foreach Package in=[ / file find where type=package \
package-version!=$InstalledVersion name~("^" . $PackagePath) ] do={
:local PackageName [ / file get $Package package-name ];
:local PackageArchitecture [ / file get $Package package-architecture ];
:if ($PackageArchitecture = "mips") do={
:set PackageArchitecture "mipsbe";
}
:if ($"package-name" = "[email protected]") do={
:set "package-name" "wireless";
:if ($PackageName = "[email protected]") do={
:set PackageName "wireless";
}
:if ([ $DownloadPackage $"package-name" $"installed-version" $"package-architecture" $"package-path" ] = true) do={
:set updated true;
/ file remove $package;
:if ([ $DownloadPackage $PackageName $InstalledVersion $PackageArchitecture $PackagePath ] = true) do={
:set Updated true;
/ file remove $Package;
}
}
:if ($updated = true) do={
/ caps-man remote-cap upgrade [ find where version!=$"installed-version" ];
:if ($Updated = true) do={
/ caps-man remote-cap upgrade [ find where version!=$InstalledVersion ];
}
......@@ -4,83 +4,82 @@
#
# check for certificate validity
:global "identity";
:global "cert-renew-url";
:global "cert-renew-pass";
:global Identity;
:global CertRenewUrl;
:global CertRenewPass;
:global SendNotification;
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local Months { "jan"; "feb"; "mar"; "apr"; "may"; "jun";
"jul"; "aug"; "sep"; "oct"; "nov"; "dec" };
:local currentdate [ / system clock get date ];
:local CurrentDate [ / system clock get date ];
:local currentmonthstr [ :pick $currentdate 0 3 ];
:local currentday [ :pick $currentdate 4 6 ];
:local currentyear [ :pick $currentdate 7 11 ];
:local currentmonth ([ :find $months $currentmonthstr -1 ] + 1);
:local currentstamp ($currentyear * 365 + $currentmonth * 30 + $currentday);
:local CurrentDay [ :pick $CurrentDate 4 6 ];
:local CurrentYear [ :pick $CurrentDate 7 11 ];
:local CurrentMonth ([ :find $Months [ :pick $CurrentDate 0 3 ] ] + 1);
:local CurrentStamp ($CurrentYear * 365 + $CurrentMonth * 30 + $CurrentDay);
:foreach cert in=[ / certificate find where !revoked ] do={
:local certname [ / certificate get $cert name ];
:local invaliddate [ / certificate get $cert invalid-after ];
:foreach Cert in=[ / certificate find where !revoked ] do={
:local CertName [ / certificate get $Cert name ];
:local InvalidDate [ / certificate get $Cert invalid-after ];
:if ([ :len $invaliddate ] > 0) do={
:local invalidmonthstr [ :pick $invaliddate 0 3 ];
:local invalidday [ :pick $invaliddate 4 6 ];
:local invalidyear [ :pick $invaliddate 7 11 ];
:local invalidmonth ([ :find $months $invalidmonthstr -1 ] + 1);
:local invalidstamp ($invalidyear * 365 + invalidmonth * 30 + invalidday);
:if ([ :len $InvalidDate ] > 0) do={
:local InvalidDay [ :pick $InvalidDate 4 6 ];
:local InvalidYear [ :pick $InvalidDate 7 11 ];
:local InvalidMonth ([ :find $Months [ :pick $InvalidDate 0 3 ] ] + 1);
:local InvalidStamp ($InvalidYear * 365 + $InvalidMonth * 30 + $InvalidDay);
:local remaining ($invalidstamp - $currentstamp);
:local Remaining ($InvalidStamp - $CurrentStamp);
:if ($remaining < 15) do={
:local commonname [ / certificate get $cert common-name ];
:local fprint [ / certificate get $cert fingerprint ];
:if ($Remaining < 15) do={
:local CommonName [ / certificate get $Cert common-name ];
:local FingerPrint [ / certificate get $Cert fingerprint ];
:do {
:if ([ :len $"cert-renew-url" ] = 0) do={
:error "No renew-url given.";
:if ([ :len $CertRenewUrl ] = 0) do={
:error "No CertRenewUrl given.";
}
/ tool fetch mode=https check-certificate=yes-without-crl url=($"cert-renew-url" . $commonname . ".pem");
/ certificate import file-name=($commonname . ".pem") passphrase=$"cert-renew-pass";
/ file remove [ find where name=($commonname . ".pem") ];
/ tool fetch mode=https check-certificate=yes-without-crl url=($CertRenewUrl . $CommonName . ".pem");
/ certificate import file-name=($CommonName . ".pem") passphrase=$CertRenewPass;
/ file remove [ find where name=($CommonName . ".pem") ];
:local certnew [ / certificate find where common-name=$commonname fingerprint!=$fprint ];
:local certnamenew [ / certificate get $certnew name ];
:local CertNew [ / certificate find where common-name=$CommonName fingerprint!=$FingerPrint ];
:local CertNameNew [ / certificate get $CertNew name ];
:foreach ipservice in=[ / ip service find where certificate=$certname ] do={
/ ip service set $ipservice certificate=$certnamenew;
:foreach IpService in=[ / ip service find where certificate=$CertName ] do={
/ ip service set $IpService certificate=$CertNameNew;
}
:do {
:foreach hotspot in=[ / ip hotspot profile find where ssl-certificate=$certname ] do={
/ ip hotspot profile set $hotspot ssl-certificate=$certnamenew;
:foreach Hotspot in=[ / ip hotspot profile find where ssl-certificate=$CertName ] do={
/ ip hotspot profile set $Hotspot ssl-certificate=$CertNameNew;
}
} on-error={
:log debug ("Setting hotspot certificates failed. Hotspot package not installed?");
}
/ certificate remove $cert;
/ certificate set $certnew name=$certname;
/ certificate remove $Cert;
/ certificate set $CertNew name=$CertName;
} on-error={
:log warning ("Failed to auto-update certificate " . $certname);
:log warning ("Failed to auto-update certificate " . $CertName);
:local invalidbefore [ / certificate get $cert invalid-before ];
:local invalidafter [ / certificate get $cert invalid-after ];
:local InvalidBefore [ / certificate get $Cert invalid-before ];
:local InvalidAfter [ / certificate get $Cert invalid-after ];
$SendNotification ("Certificate warning!") \
("A certificate on " . $identity . " is about to expire.\n\n" . \
"Certificate Name: " . $certname . "\n" . \
"Common Name: " . $commonname . "\n" . \
"Fingerprint: " . $fprint . "\n" . \
"Validity: " . $invalidbefore . " to " . $invalidafter);
:log warning ("A certificate is about to expire within " . $remaining . " days: " . $certname);
("A certificate on " . $Identity . " is about to expire.\n\n" . \
"Certificate Name: " . $CertName . "\n" . \
"Common Name: " . $CommonName . "\n" . \
"Fingerprint: " . $FingerPrint . "\n" . \
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
:log warning ("A certificate is about to expire within " . $Remaining . " days: " . $CertName);
}
} else={
:log debug ("The certificate " . $certname . " expires in " . $remaining . " days.");
:log debug ("The certificate " . $CertName . " expires in " . $Remaining . " days.");
}
} else={
:log debug ("The certificate " . $certname . " is just a template.");
:log debug ("The certificate " . $CertName . " is just a template.");
}
}
......@@ -4,31 +4,31 @@
#
# check for LTE firmware upgrade, send notification e-mails
:global "identity";
:global "sent-lte-firmware-upgrade-notification";
:global Identity;
:global SentLteFirmwareUpgradeNotification;
:global SendNotification;
:foreach interface in=[ / interface lte find ] do={
:local intname [ / interface lte get $interface name ];
:foreach Interface in=[ / interface lte find ] do={
:local IntName [ / interface lte get $Interface name ];
:do {
:local firmware [ / interface lte firmware-upgrade $interface once as-value ];
:local Firmware [ / interface lte firmware-upgrade $Interface once as-value ];
# strip the extra line break (TODO: remove when fixed upstream)
:set ($firmware->"latest") [ :pick ($firmware->"latest") 0 [ :find ($firmware->"latest") "\n" ] ];
:set ($Firmware->"latest") [ :pick ($Firmware->"latest") 0 [ :find ($Firmware->"latest") "\n" ] ];
:if ($"sent-lte-firmware-upgrade-notification" = ($firmware->"latest")) do={
:if ($SentLteFirmwareUpgradeNotification = ($Firmware->"latest")) do={
:log debug ("Already sent the LTE firmware upgrade notification for version " . \
($firmware->"latest") . ".");
($Firmware->"latest") . ".");
} else={
:if (($firmware->"installed") != ($firmware->"latest")) do={
:if (($Firmware->"installed") != ($Firmware->"latest")) do={
$SendNotification ("LTE firmware upgrade notification") \
("A new firmware version " . ($firmware->"latest") . " is available for " . \
"LTE interface " . $intname . " on " . $identity . ".");
:set "sent-lte-firmware-upgrade-notification" ($firmware->"latest");
("A new firmware version " . ($Firmware->"latest") . " is available for " . \
"LTE interface " . $IntName . " on " . $Identity . ".");
:set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
}
}
} on-error={
:log debug ("Could not get latest LTE firmware version for interface " . \
$intname . ".");
$IntName . ".");
}
}
......@@ -4,9 +4,9 @@
#
# check for RouterOS update, send notification e-mails
:global "identity";
:global "safe-update-url";
:global "sent-routeros-update-notification";
:global Identity;
:global SafeUpdateUrl;
:global SentRouterosUpdateNotification;
:global SendNotification;
......@@ -18,45 +18,45 @@
}
/ system package update check-for-updates without-paging;
:local installedversion [ / system package update get installed-version ];
:local latestversion [ / system package update get latest-version ];
:local InstalledVersion [ / system package update get installed-version ];
:local LatestVersion [ / system package update get latest-version ];
:if ($installedversion != $latestversion) do={
:local channel [ / system package update get channel ];
:local model [ / system routerboard get model ];
:local serialnumber [ / system routerboard get serial-number ];
:if ($InstalledVersion != $LatestVersion) do={
:local Channel [ / system package update get channel ];
:local Model [ / system routerboard get model ];
:local SerialNumber [ / system routerboard get serial-number ];
:if ([ :len $"safe-update-url" ] > 0) do={
:local result;
:if ([ :len $SafeUpdateUrl ] > 0) do={
:local Result;
:do {
:set result [ / tool fetch check-certificate=yes-without-crl \
($"safe-update-url" . $channel . "?installed=" . $installedversion . \
"&latest=" . $latestversion) output=user as-value ];
:set Result [ / tool fetch check-certificate=yes-without-crl \
($SafeUpdateUrl . $Channel . "?installed=" . $InstalledVersion . \
"&latest=" . $LatestVersion) output=user as-value ];
} on-error={
:log warning ("Failed receiving safe version for " . $channel . ".");
:log warning ("Failed receiving safe version for " . $Channel . ".");
}
:if ($result->"status" = "finished" && $result->"data" = $latestversion) do={
:log info ("Version " . $latestversion . " is assumed safe, updating...");
:if ($Result->"status" = "finished" && $Result->"data" = $LatestVersion) do={
:log info ("Version " . $LatestVersion . " is considered safe, updating...");
$SendNotification ("RouterOS update notification") \
("Version " . $latestversion . " is assumed safe for " . $channel . \
", updating on " . $identity . "...");
("Version " . $LatestVersion . " is considered safe for " . $Channel . \
", updating on " . $Identity . "...");
/ system package update install;
:error "Waiting for system to reboot.";
}
}
:if ($"sent-routeros-update-notification" = $latestversion) do={
:if ($SentRouterosUpdateNotification = $LatestVersion) do={
:error ("Already sent the RouterOS update notification for version " . \
$latestversion . ".");
$LatestVersion . ".");
}
$SendNotification ("RouterOS update notification") \
("There is a RouterOS update available\n\n" . \
"Routerboard: " . $model . "\n" . \
"Serial number: " . $serialnumber . "\n" . \
"Hostname: " . $identity . "\n" . \
"Channel: " . $channel . "\n" . \
"Installed: " . $installedversion . "\n" . \
"Available: " . $latestversion);
:set "sent-routeros-update-notification" $latestversion;
"Routerboard: " . $Model . "\n" . \
"Serial number: " . $SerialNumber . "\n" . \
"Hostname: " . $Identity . "\n" . \
"Channel: " . $Channel . "\n" . \
"Installed: " . $InstalledVersion . "\n" . \
"Available: " . $LatestVersion);
:set SentRouterosUpdateNotification $LatestVersion;
}
......@@ -6,54 +6,54 @@
#
# !! Do not edit this file, it is generated from template!
:global "identity";
:global Identity;
:global GetMacVendor;
:global SendNotification;
:local "place-before" [ / caps-man access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $"place-before" ] = 0) do={
:local PlaceBefore [ / caps-man access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $PlaceBefore ] = 0) do={
:error "Missing disabled access-list entry with comment '--- collected above ---'";
}
:foreach regtbl in=[ / caps-man registration-table find ] do={
:local mac [ / caps-man registration-table get $regtbl mac-address ];
:local acclst [ :pick [ / caps-man access-list find where mac-address=$mac ] 0 ];
:if ( [ :len $acclst ] = 0 ) do={
:local hostname "no dhcp lease";
:local address "no dhcp lease";
:local lease [ / ip dhcp-server lease find where mac-address=$mac ];
:if ( [ :len $lease ] > 0 ) do={
:set hostname [ / ip dhcp-server lease get $lease host-name ];
:set address [ / ip dhcp-server lease get $lease address ];
:foreach RegTbl in=[ / caps-man registration-table find ] do={
:local Mac [ / caps-man registration-table get $RegTbl mac-address ];
:local AccessList [ :pick [ / caps-man access-list find where mac-address=$Mac ] 0 ];
:if ([ :len $AccessList ] = 0) do={
:local HostName "no dhcp lease";
:local Address "no dhcp lease";
:local Lease [ / ip dhcp-server lease find where mac-address=$Mac ];
:if ([ :len $Lease ] > 0) do={
:set HostName [ / ip dhcp-server lease get $Lease host-name ];
:set Address [ / ip dhcp-server lease get $Lease address ];
}
:if ( [ :len $hostname ] = 0 ) do={
:set hostname "no hostname";
:if ([ :len $HostName ] = 0) do={
:set HostName "no hostname";
}
:if ( [ :len $address ] = 0 ) do={
:set address "no address";
:if ([ :len $Address ] = 0) do={
:set Address "no address";
}
:local regentry [ / caps-man registration-table find where mac-address=$mac ];
:local interface [ / caps-man registration-table get $regentry interface ];
:local ssid [ / caps-man registration-table get $regentry ssid ];
:local datetime ([ / system clock get date ] . " " . [ / system clock get time ]);
:local vendor [ $GetMacVendor $mac ];
:local message ("unknown MAC address " . $mac . " (" . $vendor . ", " . $hostname . ") " . \
"first seen on " . $datetime . " connected to SSID " . $ssid . ", interface " . $interface);
/ log info $message;
/ caps-man access-list add place-before=$"place-before" comment=$message mac-address=$mac disabled=yes;
$SendNotification ($mac . " connected to " . $ssid) \
("A device with unknown MAC address connected to " . $ssid . " on " . $identity . ".\n\n" . \
"Controller: " . $identity . "\n" . \
"Interface: " . $interface . "\n" . \
"SSID: " . $ssid . "\n" . \
"MAC: " . $mac . "\n" . \
"Vendor: " . $vendor . "\n" . \
"Hostname: " . $hostname . "\n" . \
"Address: " . $address . "\n" . \
"Date: " . $datetime);
:local RegEntry [ / caps-man registration-table find where mac-address=$Mac ];
:local Interface [ / caps-man registration-table get $RegEntry interface ];
:local Ssid [ / caps-man registration-table get $RegEntry ssid ];
:local DateTime ([ / system clock get date ] . " " . [ / system clock get time ]);
:local Vendor [ $GetMacVendor $Mac ];
:local Message ("unknown MAC address " . $Mac . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
/ log info $Message;
/ caps-man access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
$SendNotification ($Mac . " connected to " . $Ssid) \
("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \
"Controller: " . $Identity . "\n" . \
"Interface: " . $Interface . "\n" . \
"SSID: " . $Ssid . "\n" . \
"MAC: " . $Mac . "\n" . \
"Vendor: " . $Vendor . "\n" . \
"Hostname: " . $HostName . "\n" . \
"Address: " . $Address . "\n" . \
"Date: " . $DateTime);
} else={
:local comment [ / caps-man access-list get $acclst comment ];
:log debug ("MAC address " . $mac . " already known: " . $comment);
:local Comment [ / caps-man access-list get $AccessList comment ];
:log debug ("MAC address " . $Mac . " already known: " . $Comment);
}
}
......@@ -6,54 +6,54 @@
#
# !! Do not edit this file, it is generated from template!
:global "identity";
:global Identity;
:global GetMacVendor;
:global SendNotification;
:local "place-before" [ / interface wireless access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $"place-before" ] = 0) do={
:local PlaceBefore [ / interface wireless access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $PlaceBefore ] = 0) do={
:error "Missing disabled access-list entry with comment '--- collected above ---'";
}
:foreach regtbl in=[ / interface wireless registration-table find ] do={
:local mac [ / interface wireless registration-table get $regtbl mac-address ];
:local acclst [ :pick [ / interface wireless access-list find where mac-address=$mac ] 0 ];
:if ( [ :len $acclst ] = 0 ) do={
:local hostname "no dhcp lease";
:local address "no dhcp lease";
:local lease [ / ip dhcp-server lease find where mac-address=$mac ];
:if ( [ :len $lease ] > 0 ) do={
:set hostname [ / ip dhcp-server lease get $lease host-name ];
:set address [ / ip dhcp-server lease get $lease address ];
:foreach RegTbl in=[ / interface wireless registration-table find ] do={
:local Mac [ / interface wireless registration-table get $RegTbl mac-address ];
:local AccessList [ :pick [ / interface wireless access-list find where mac-address=$Mac ] 0 ];
:if ([ :len $AccessList ] = 0) do={
:local HostName "no dhcp lease";
:local Address "no dhcp lease";
:local Lease [ / ip dhcp-server lease find where mac-address=$Mac ];
:if ([ :len $Lease ] > 0) do={
:set HostName [ / ip dhcp-server lease get $Lease host-name ];
:set Address [ / ip dhcp-server lease get $Lease address ];
}
:if ( [ :len $hostname ] = 0 ) do={
:set hostname "no hostname";
:if ([ :len $HostName ] = 0) do={
:set HostName "no hostname";
}
:if ( [ :len $address ] = 0 ) do={
:set address "no address";
:if ([ :len $Address ] = 0) do={
:set Address "no address";
}
:local regentry [ / interface wireless registration-table find where mac-address=$mac ];
:local interface [ / interface wireless registration-table get $regentry interface ];
:local ssid [ / interface wireless get [ find where name=$interface ] ssid ];
:local datetime ([ / system clock get date ] . " " . [ / system clock get time ]);
:local vendor [ $GetMacVendor $mac ];
:local message ("unknown MAC address " . $mac . " (" . $vendor . ", " . $hostname . ") " . \
"first seen on " . $datetime . " connected to SSID " . $ssid . ", interface " . $interface);
/ log info $message;
/ interface wireless access-list add place-before=$"place-before" comment=$message mac-address=$mac disabled=yes;
$SendNotification ($mac . " connected to " . $ssid) \
("A device with unknown MAC address connected to " . $ssid . " on " . $identity . ".\n\n" . \
"Controller: " . $identity . "\n" . \
"Interface: " . $interface . "\n" . \
"SSID: " . $ssid . "\n" . \
"MAC: " . $mac . "\n" . \
"Vendor: " . $vendor . "\n" . \
"Hostname: " . $hostname . "\n" . \
"Address: " . $address . "\n" . \
"Date: " . $datetime);
:local RegEntry [ / interface wireless registration-table find where mac-address=$Mac ];
:local Interface [ / interface wireless registration-table get $RegEntry interface ];
:local Ssid [ / interface wireless get [ find where name=$Interface ] ssid ];
:local DateTime ([ / system clock get date ] . " " . [ / system clock get time ]);
:local Vendor [ $GetMacVendor $Mac ];
:local Message ("unknown MAC address " . $Mac . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
/ log info $Message;
/ interface wireless access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
$SendNotification ($Mac . " connected to " . $Ssid) \
("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \
"Controller: " . $Identity . "\n" . \
"Interface: " . $Interface . "\n" . \
"SSID: " . $Ssid . "\n" . \
"MAC: " . $Mac . "\n" . \
"Vendor: " . $Vendor . "\n" . \
"Hostname: " . $HostName . "\n" . \
"Address: " . $Address . "\n" . \
"Date: " . $DateTime);
} else={
:local comment [ / interface wireless access-list get $acclst comment ];
:log debug ("MAC address " . $mac . " already known: " . $comment);
:local Comment [ / interface wireless access-list get $AccessList comment ];
:log debug ("MAC address " . $Mac . " already known: " . $Comment);
}
}
......@@ -7,55 +7,55 @@
# !! This is just a template! Replace '%PATH%' with 'caps-man'
# !! or 'interface wireless'!
:global "identity";
:global Identity;
:global GetMacVendor;
:global SendNotification;
:local "place-before" [ / %PATH% access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $"place-before" ] = 0) do={
:local PlaceBefore [ / %PATH% access-list find where comment="--- collected above ---" disabled ];
:if ([ :len $PlaceBefore ] = 0) do={
:error "Missing disabled access-list entry with comment '--- collected above ---'";
}
:foreach regtbl in=[ / %PATH% registration-table find ] do={
:local mac [ / %PATH% registration-table get $regtbl mac-address ];
:local acclst [ :pick [ / %PATH% access-list find where mac-address=$mac ] 0 ];
:if ( [ :len $acclst ] = 0 ) do={
:local hostname "no dhcp lease";
:local address "no dhcp lease";
:local lease [ / ip dhcp-server lease find where mac-address=$mac ];
:if ( [ :len $lease ] > 0 ) do={
:set hostname [ / ip dhcp-server lease get $lease host-name ];
:set address [ / ip dhcp-server lease get $lease address ];