Merge branch 'LogPrint' into next

This commit is contained in:
Christian Hesse 2024-03-08 17:32:12 +01:00
commit ba2df80f07
62 changed files with 574 additions and 517 deletions

View file

@ -22,7 +22,7 @@
:global DeviceInfo; :global DeviceInfo;
:global FormatLine; :global FormatLine;
:global HumanReadableNum; :global HumanReadableNum;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global RandomDelay; :global RandomDelay;
:global ScriptFromTerminal; :global ScriptFromTerminal;
@ -43,7 +43,8 @@
} }
:if ([ $MkDir ("tmpfs/backup-cloud") ] = false) do={ :if ([ $MkDir ("tmpfs/backup-cloud") ] = false) do={
$LogPrintExit2 error $ScriptName ("Failed creating directory!") true; $LogPrint error $ScriptName ("Failed creating directory!");
:error false;
} }
:execute { :execute {
@ -76,7 +77,7 @@
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "floppy-disk,warning-sign" ] . "Cloud backup failed"); \ subject=([ $SymbolForNotification "floppy-disk,warning-sign" ] . "Cloud backup failed"); \
message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) }); message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) });
$LogPrintExit2 error $ScriptName ("Failed uploading backup for " . $Identity . " to cloud!") false; $LogPrint error $ScriptName ("Failed uploading backup for " . $Identity . " to cloud!");
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:error false; :error false;
} }

View file

@ -27,7 +27,7 @@
:global CleanName; :global CleanName;
:global DeviceInfo; :global DeviceInfo;
:global FormatLine; :global FormatLine;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global RandomDelay; :global RandomDelay;
:global ScriptFromTerminal; :global ScriptFromTerminal;
@ -38,12 +38,14 @@
:global WaitFullyConnected; :global WaitFullyConnected;
:if ([ :typeof $SendEMail2 ] = "nothing") do={ :if ([ :typeof $SendEMail2 ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("The module for sending notifications via e-mail is not installed.") true; $LogPrint error $ScriptName ("The module for sending notifications via e-mail is not installed.");
:error false;
} }
:if ($BackupSendBinary != true && \ :if ($BackupSendBinary != true && \
$BackupSendExport != true) do={ $BackupSendExport != true) do={
$LogPrintExit2 error $ScriptName ("Configured to send neither backup nor config export.") true; $LogPrint error $ScriptName ("Configured to send neither backup nor config export.");
:error false;
} }
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -66,7 +68,8 @@
:local Attach ({}); :local Attach ({});
:if ([ $MkDir $DirName ] = false) do={ :if ([ $MkDir $DirName ] = false) do={
$LogPrintExit2 error $ScriptName ("Failed creating directory!") true; $LogPrint error $ScriptName ("Failed creating directory!");
:error false;
} }
# binary backup # binary backup
@ -111,7 +114,7 @@
:local I 0; :local I 0;
:while ([ :len [ /file/find where name ~ ($FilePath . "\\.(backup|rsc)\$") ] ] > 0) do={ :while ([ :len [ /file/find where name ~ ($FilePath . "\\.(backup|rsc)\$") ] ] > 0) do={
:if ($I >= 120) do={ :if ($I >= 120) do={
$LogPrintExit2 warning $ScriptName ("Files are still available, sending e-mail failed.") false; $LogPrint warning $ScriptName ("Files are still available, sending e-mail failed.");
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:error false; :error false;
} }

View file

@ -17,7 +17,7 @@
:global PackagesUpdateBackupFailure; :global PackagesUpdateBackupFailure;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -26,7 +26,7 @@
} }
:if ([ :len [ /partitions/find ] ] < 2) do={ :if ([ :len [ /partitions/find ] ] < 2) do={
$LogPrintExit2 error $ScriptName ("Device does not have a fallback partition.") false; $LogPrint error $ScriptName ("Device does not have a fallback partition.");
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:error false; :error false;
} }
@ -34,7 +34,7 @@
:local ActiveRunning [ /partitions/find where active running ]; :local ActiveRunning [ /partitions/find where active running ];
:if ([ :len $ActiveRunning ] < 1) do={ :if ([ :len $ActiveRunning ] < 1) do={
$LogPrintExit2 error $ScriptName ("Device is not running from active partition.") false; $LogPrint error $ScriptName ("Device is not running from active partition.");
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:error false; :error false;
} }
@ -47,12 +47,10 @@
"[ /partitions/get [ find where running ] name ] . \"'!\")"); "[ /partitions/get [ find where running ] name ] . \"'!\")");
/partitions/save-config-to $FallbackTo; /partitions/save-config-to $FallbackTo;
/system/scheduler/remove "running-from-backup-partition"; /system/scheduler/remove "running-from-backup-partition";
$LogPrintExit2 info $ScriptName ("Saved configuration to partition '" . \ $LogPrint info $ScriptName ("Saved configuration to partition '" . $FallbackTo . "'.");
$FallbackTo . "'.") false;
} on-error={ } on-error={
/system/scheduler/remove [ find where name="running-from-backup-partition" ]; /system/scheduler/remove [ find where name="running-from-backup-partition" ];
$LogPrintExit2 error $ScriptName ("Failed saving configuration to partition '" . \ $LogPrint error $ScriptName ("Failed saving configuration to partition '" . $FallbackTo . "'!");
$FallbackTo . "'!") false;
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
:error false; :error false;
} }

View file

@ -30,7 +30,7 @@
:global CleanName; :global CleanName;
:global DeviceInfo; :global DeviceInfo;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global RandomDelay; :global RandomDelay;
:global ScriptFromTerminal; :global ScriptFromTerminal;
@ -42,7 +42,8 @@
:if ($BackupSendBinary != true && \ :if ($BackupSendBinary != true && \
$BackupSendExport != true) do={ $BackupSendExport != true) do={
$LogPrintExit2 error $ScriptName ("Configured to send neither backup nor config export.") true; $LogPrint error $ScriptName ("Configured to send neither backup nor config export.");
:error false;
} }
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -65,7 +66,8 @@
:local Failed 0; :local Failed 0;
:if ([ $MkDir $DirName ] = false) do={ :if ([ $MkDir $DirName ] = false) do={
$LogPrintExit2 error $ScriptName ("Failed creating directory!") true; $LogPrint error $ScriptName ("Failed creating directory!");
:error false;
} }
# binary backup # binary backup
@ -79,7 +81,7 @@
:set BackupFile [ /file/get ($FilePath . ".backup") ]; :set BackupFile [ /file/get ($FilePath . ".backup") ];
:set ($BackupFile->"name") ($FileName . ".backup"); :set ($BackupFile->"name") ($FileName . ".backup");
} on-error={ } on-error={
$LogPrintExit2 error $ScriptName ("Uploading backup file failed!") false; $LogPrint error $ScriptName ("Uploading backup file failed!");
:set BackupFile "failed"; :set BackupFile "failed";
:set Failed 1; :set Failed 1;
} }
@ -98,7 +100,7 @@
:set ExportFile [ /file/get ($FilePath . ".rsc") ]; :set ExportFile [ /file/get ($FilePath . ".rsc") ];
:set ($ExportFile->"name") ($FileName . ".rsc"); :set ($ExportFile->"name") ($FileName . ".rsc");
} on-error={ } on-error={
$LogPrintExit2 error $ScriptName ("Uploading configuration export failed!") false; $LogPrint error $ScriptName ("Uploading configuration export failed!");
:set ExportFile "failed"; :set ExportFile "failed";
:set Failed 1; :set Failed 1;
} }
@ -119,7 +121,7 @@
:set ConfigFile [ /file/get ($FilePath . ".conf") ]; :set ConfigFile [ /file/get ($FilePath . ".conf") ];
:set ($ConfigFile->"name") ($FileName . ".conf"); :set ($ConfigFile->"name") ($FileName . ".conf");
} on-error={ } on-error={
$LogPrintExit2 error $ScriptName ("Uploading global-config-overlay failed!") false; $LogPrint error $ScriptName ("Uploading global-config-overlay failed!");
:set ConfigFile "failed"; :set ConfigFile "failed";
:set Failed 1; :set Failed 1;
} }

View file

@ -19,7 +19,7 @@
:global CleanFilePath; :global CleanFilePath;
:global DownloadPackage; :global DownloadPackage;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global ScriptLock; :global ScriptLock;
:global WaitFullyConnected; :global WaitFullyConnected;
@ -34,16 +34,18 @@
:local Updated false; :local Updated false;
:if ([ :len $PackagePath ] = 0) do={ :if ([ :len $PackagePath ] = 0) do={
$LogPrintExit2 warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.") true; $LogPrint warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.");
:error false;
} }
:if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={ :if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={
:if ([ $MkDir $PackagePath ] = false) do={ :if ([ $MkDir $PackagePath ] = false) do={
$LogPrintExit2 warning $ScriptName ("Creating directory at CAPsMAN package path (" . \ $LogPrint warning $ScriptName ("Creating directory at CAPsMAN package path (" . \
$PackagePath . ") failed!") true; $PackagePath . ") failed!");
:error false;
} }
$LogPrintExit2 info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \ $LogPrint info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \
"). Please place your packages!") false; "). Please place your packages!");
} }
:foreach Package in=[ /file/find where type=package \ :foreach Package in=[ /file/find where type=package \
@ -60,7 +62,7 @@
} }
:if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={ :if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("No packages available, downloading default set.") false; $LogPrint info $ScriptName ("No packages available, downloading default set.");
:foreach Arch in={ "arm"; "mipsbe" } do={ :foreach Arch in={ "arm"; "mipsbe" } do={
:foreach Package in={ "routeros"; "wireless" } do={ :foreach Package in={ "routeros"; "wireless" } do={
:if ([ $DownloadPackage $Package $InstalledVersion $Arch $PackagePath ] = true) do={ :if ([ $DownloadPackage $Package $InstalledVersion $Arch $PackagePath ] = true) do={

View file

@ -20,7 +20,7 @@
:global CleanFilePath; :global CleanFilePath;
:global DownloadPackage; :global DownloadPackage;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global ScriptLock; :global ScriptLock;
:global WaitFullyConnected; :global WaitFullyConnected;
@ -36,16 +36,18 @@
:local Updated false; :local Updated false;
:if ([ :len $PackagePath ] = 0) do={ :if ([ :len $PackagePath ] = 0) do={
$LogPrintExit2 warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.") true; $LogPrint warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.");
:error false;
} }
:if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={ :if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={
:if ([ $MkDir $PackagePath ] = false) do={ :if ([ $MkDir $PackagePath ] = false) do={
$LogPrintExit2 warning $ScriptName ("Creating directory at CAPsMAN package path (" . \ $LogPrint warning $ScriptName ("Creating directory at CAPsMAN package path (" . \
$PackagePath . ") failed!") true; $PackagePath . ") failed!");
:error false;
} }
$LogPrintExit2 info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \ $LogPrint info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \
"). Please place your packages!") false; "). Please place your packages!");
} }
:foreach Package in=[ /file/find where type=package \ :foreach Package in=[ /file/find where type=package \
@ -62,7 +64,7 @@
} }
:if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={ :if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("No packages available, downloading default set.") false; $LogPrint info $ScriptName ("No packages available, downloading default set.");
# NOT /interface/wifi/ # # NOT /interface/wifi/ #
:foreach Arch in={ "arm"; "mipsbe" } do={ :foreach Arch in={ "arm"; "mipsbe" } do={
:foreach Package in={ "routeros"; "wireless" } do={ :foreach Package in={ "routeros"; "wireless" } do={

View file

@ -19,7 +19,7 @@
:global CleanFilePath; :global CleanFilePath;
:global DownloadPackage; :global DownloadPackage;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global ScriptLock; :global ScriptLock;
:global WaitFullyConnected; :global WaitFullyConnected;
@ -34,16 +34,18 @@
:local Updated false; :local Updated false;
:if ([ :len $PackagePath ] = 0) do={ :if ([ :len $PackagePath ] = 0) do={
$LogPrintExit2 warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.") true; $LogPrint warning $ScriptName ("The CAPsMAN package path is not defined, can not download packages.");
:error false;
} }
:if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={ :if ([ :len [ /file/find where name=$PackagePath type="directory" ] ] = 0) do={
:if ([ $MkDir $PackagePath ] = false) do={ :if ([ $MkDir $PackagePath ] = false) do={
$LogPrintExit2 warning $ScriptName ("Creating directory at CAPsMAN package path (" . \ $LogPrint warning $ScriptName ("Creating directory at CAPsMAN package path (" . \
$PackagePath . ") failed!") true; $PackagePath . ") failed!");
:error false;
} }
$LogPrintExit2 info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \ $LogPrint info $ScriptName ("Created directory at CAPsMAN package path (" . $PackagePath . \
"). Please place your packages!") false; "). Please place your packages!");
} }
:foreach Package in=[ /file/find where type=package \ :foreach Package in=[ /file/find where type=package \
@ -60,7 +62,7 @@
} }
:if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={ :if ([ :len [ /file/find where type=package name~("^" . $PackagePath) ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("No packages available, downloading default set.") false; $LogPrint info $ScriptName ("No packages available, downloading default set.");
:foreach Arch in={ "arm"; "arm64" } do={ :foreach Arch in={ "arm"; "arm64" } do={
:local Packages { "arm"={ "routeros"; "wifi-qcom"; "wifi-qcom-ac" }; :local Packages { "arm"={ "routeros"; "wifi-qcom"; "wifi-qcom-ac" };
"arm64"={ "routeros"; "wifi-qcom" } }; "arm64"={ "routeros"; "wifi-qcom" } };

View file

@ -18,7 +18,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -34,11 +34,11 @@
:foreach RemoteCap in=[ /caps-man/remote-cap/find where version!=$InstalledVersion ] do={ :foreach RemoteCap in=[ /caps-man/remote-cap/find where version!=$InstalledVersion ] do={
:local RemoteCapVal [ /caps-man/remote-cap/get $RemoteCap ]; :local RemoteCapVal [ /caps-man/remote-cap/get $RemoteCap ];
:if ([ :len $RemoteCapVal ] > 1) do={ :if ([ :len $RemoteCapVal ] > 1) do={
$LogPrintExit2 info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \ $LogPrint info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \
" (" . $RemoteCapVal->"identity" . ")...") false; " (" . $RemoteCapVal->"identity" . ")...");
/caps-man/remote-cap/upgrade $RemoteCap; /caps-man/remote-cap/upgrade $RemoteCap;
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Remote CAP vanished, skipping upgrade.") false; $LogPrint warning $ScriptName ("Remote CAP vanished, skipping upgrade.");
} }
:delay ($Delay . "s"); :delay ($Delay . "s");
} }

View file

@ -19,7 +19,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -41,12 +41,12 @@
# NOT /caps-man/ # # NOT /caps-man/ #
:set ($RemoteCapVal->"name") ($RemoteCapVal->"common-name"); :set ($RemoteCapVal->"name") ($RemoteCapVal->"common-name");
# NOT /caps-man/ # # NOT /caps-man/ #
$LogPrintExit2 info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \ $LogPrint info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \
" (" . $RemoteCapVal->"identity" . ")...") false; " (" . $RemoteCapVal->"identity" . ")...");
/caps-man/remote-cap/upgrade $RemoteCap; /caps-man/remote-cap/upgrade $RemoteCap;
/interface/wifi/capsman/remote-cap/upgrade $RemoteCap; /interface/wifi/capsman/remote-cap/upgrade $RemoteCap;
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Remote CAP vanished, skipping upgrade.") false; $LogPrint warning $ScriptName ("Remote CAP vanished, skipping upgrade.");
} }
:delay ($Delay . "s"); :delay ($Delay . "s");
} }

View file

@ -18,7 +18,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -35,11 +35,11 @@
:local RemoteCapVal [ /interface/wifi/capsman/remote-cap/get $RemoteCap ]; :local RemoteCapVal [ /interface/wifi/capsman/remote-cap/get $RemoteCap ];
:if ([ :len $RemoteCapVal ] > 1) do={ :if ([ :len $RemoteCapVal ] > 1) do={
:set ($RemoteCapVal->"name") ($RemoteCapVal->"common-name"); :set ($RemoteCapVal->"name") ($RemoteCapVal->"common-name");
$LogPrintExit2 info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \ $LogPrint info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \
" (" . $RemoteCapVal->"identity" . ")...") false; " (" . $RemoteCapVal->"identity" . ")...");
/interface/wifi/capsman/remote-cap/upgrade $RemoteCap; /interface/wifi/capsman/remote-cap/upgrade $RemoteCap;
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Remote CAP vanished, skipping upgrade.") false; $LogPrint warning $ScriptName ("Remote CAP vanished, skipping upgrade.");
} }
:delay ($Delay . "s"); :delay ($Delay . "s");
} }

View file

@ -16,7 +16,7 @@
:global CertIssuedExportPass; :global CertIssuedExportPass;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global ScriptLock; :global ScriptLock;
@ -36,13 +36,13 @@
/certificate/export-certificate ($CertVal->"name") type=pkcs12 \ /certificate/export-certificate ($CertVal->"name") type=pkcs12 \
file-name=("cert-issued/" . $CertVal->"common-name") \ file-name=("cert-issued/" . $CertVal->"common-name") \
export-passphrase=($CertIssuedExportPass->($CertVal->"common-name")); export-passphrase=($CertIssuedExportPass->($CertVal->"common-name"));
$LogPrintExit2 info $ScriptName ("Issued a new certificate for \"" . $CertVal->"common-name" . \ $LogPrint info $ScriptName ("Issued a new certificate for \"" . $CertVal->"common-name" . \
"\", exported to \"cert-issued/" . $CertVal->"common-name" . ".p12\".") false; "\", exported to \"cert-issued/" . $CertVal->"common-name" . ".p12\".");
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Failed creating directory, not exporting certificate.") false; $LogPrint warning $ScriptName ("Failed creating directory, not exporting certificate.");
} }
} else={ } else={
$LogPrintExit2 info $ScriptName ("Issued a new certificate for \"" . $CertVal->"common-name" . "\".") false; $LogPrint info $ScriptName ("Issued a new certificate for \"" . $CertVal->"common-name" . "\".");
} }
} }
} on-error={ } } on-error={ }

View file

@ -22,7 +22,7 @@
:global CertificateAvailable :global CertificateAvailable
:global EscapeForRegEx; :global EscapeForRegEx;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
@ -39,7 +39,7 @@
:global CertificateNameByCN; :global CertificateNameByCN;
:global EscapeForRegEx; :global EscapeForRegEx;
:global FetchUserAgent; :global FetchUserAgent;
:global LogPrintExit2; :global LogPrint;
:global UrlEncode; :global UrlEncode;
:global WaitForFile; :global WaitForFile;
@ -62,7 +62,7 @@
/file/remove [ find where name=$CertFileName ]; /file/remove [ find where name=$CertFileName ];
:if ($DecryptionFailed = true) do={ :if ($DecryptionFailed = true) do={
$LogPrintExit2 warning $0 ("Decryption failed for certificate file '" . $CertFileName . "'.") false; $LogPrint warning $0 ("Decryption failed for certificate file '" . $CertFileName . "'.");
} }
:foreach CertInChain in=[ /certificate/find where name~("^" . [ $EscapeForRegEx $CertFileName ] . "_[0-9]+\$") \ :foreach CertInChain in=[ /certificate/find where name~("^" . [ $EscapeForRegEx $CertFileName ] . "_[0-9]+\$") \
@ -72,7 +72,7 @@
:set Return true; :set Return true;
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Could not download certificate file '" . $CertFileName . "'.") false; $LogPrint debug $0 ("Could not download certificate file '" . $CertFileName . "'.");
} }
} }
@ -143,9 +143,10 @@
:do { :do {
:if ([ :len $CertRenewUrl ] = 0) do={ :if ([ :len $CertRenewUrl ] = 0) do={
$LogPrintExit2 info $ScriptName ("No CertRenewUrl given.") true; $LogPrint info $ScriptName ("No CertRenewUrl given.");
:error false;
} }
$LogPrintExit2 info $ScriptName ("Attempting to renew certificate '" . ($CertVal->"name") . "'.") false; $LogPrint info $ScriptName ("Attempting to renew certificate '" . ($CertVal->"name") . "'.");
:local ImportSuccess false; :local ImportSuccess false;
:set LastName ($CertVal->"common-name"); :set LastName ($CertVal->"common-name");
@ -159,10 +160,10 @@
:if ($ImportSuccess = false) do={ :error false; } :if ($ImportSuccess = false) do={ :error false; }
:if ([ :len ($CertVal->"fingerprint") ] > 0 && $CertVal->"fingerprint" != [ /certificate/get $Cert fingerprint ]) do={ :if ([ :len ($CertVal->"fingerprint") ] > 0 && $CertVal->"fingerprint" != [ /certificate/get $Cert fingerprint ]) do={
$LogPrintExit2 debug $ScriptName ("Certificate '" . $CertVal->"name" . "' was updated in place.") false; $LogPrint debug $ScriptName ("Certificate '" . $CertVal->"name" . "' was updated in place.");
:set CertVal [ /certificate/get $Cert ]; :set CertVal [ /certificate/get $Cert ];
} else={ } else={
$LogPrintExit2 debug $ScriptName ("Certificate '" . $CertVal->"name" . "' was not updated, but replaced.") false; $LogPrint debug $ScriptName ("Certificate '" . $CertVal->"name" . "' was not updated, but replaced.");
:set CertNew [ /certificate/find where name~("^" . [ $EscapeForRegEx [ $UrlEncode $LastName ] ] . "\\.(p12|pem)_[0-9]+\$") \ :set CertNew [ /certificate/find where name~("^" . [ $EscapeForRegEx [ $UrlEncode $LastName ] ] . "\\.(p12|pem)_[0-9]+\$") \
(common-name=($CertVal->"common-name") or subject-alt-name~("(^|\\W)(DNS|IP):" . [ $EscapeForRegEx $LastName ] . "(\\W|\$)")) \ (common-name=($CertVal->"common-name") or subject-alt-name~("(^|\\W)(DNS|IP):" . [ $EscapeForRegEx $LastName ] . "(\\W|\$)")) \
@ -170,12 +171,13 @@
:local CertNewVal [ /certificate/get $CertNew ]; :local CertNewVal [ /certificate/get $CertNew ];
:if ([ $CertificateAvailable ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") ] = false) do={ :if ([ $CertificateAvailable ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") ] = false) do={
$LogPrintExit2 warning $ScriptName ("The certificate chain is not available!") false; $LogPrint warning $ScriptName ("The certificate chain is not available!");
} }
:if (($CertVal->"private-key") = true && ($CertVal->"private-key") != ($CertNewVal->"private-key")) do={ :if (($CertVal->"private-key") = true && ($CertVal->"private-key") != ($CertNewVal->"private-key")) do={
/certificate/remove $CertNew; /certificate/remove $CertNew;
$LogPrintExit2 warning $ScriptName ("Old certificate '" . ($CertVal->"name") . "' has a private key, new certificate does not. Aborting renew.") true; $LogPrint warning $ScriptName ("Old certificate '" . ($CertVal->"name") . "' has a private key, new certificate does not. Aborting renew.");
:error false;
} }
/ip/service/set certificate=($CertNewVal->"name") [ find where certificate=($CertVal->"name") ]; /ip/service/set certificate=($CertNewVal->"name") [ find where certificate=($CertVal->"name") ];
@ -194,9 +196,9 @@
$SendNotification2 ({ origin=$ScriptName; silent=true; \ $SendNotification2 ({ origin=$ScriptName; silent=true; \
subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed: " . ($CertVal->"name")); \ subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed: " . ($CertVal->"name")); \
message=("A certificate on " . $Identity . " has been renewed.\n\n" . [ $FormatInfo $CertNew ]) }); message=("A certificate on " . $Identity . " has been renewed.\n\n" . [ $FormatInfo $CertNew ]) });
$LogPrintExit2 info $ScriptName ("The certificate '" . ($CertVal->"name") . "' has been renewed.") false; $LogPrint info $ScriptName ("The certificate '" . ($CertVal->"name") . "' has been renewed.");
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Could not renew certificate '" . ($CertVal->"name") . "'.") false; $LogPrint debug $ScriptName ("Could not renew certificate '" . ($CertVal->"name") . "'.");
} }
} }
@ -205,15 +207,15 @@
:local CertVal [ /certificate/get $Cert ]; :local CertVal [ /certificate/get $Cert ];
:if ([ :len [ /certificate/scep-server/find where ca-cert=($CertVal->"ca") ] ] > 0) do={ :if ([ :len [ /certificate/scep-server/find where ca-cert=($CertVal->"ca") ] ] > 0) do={
$LogPrintExit2 debug $ScriptName ("Certificate '" . ($CertVal->"name") . "' is handled by SCEP, skipping.") false; $LogPrint debug $ScriptName ("Certificate '" . ($CertVal->"name") . "' is handled by SCEP, skipping.");
} else={ } else={
:local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ]; :local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ];
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning: " . ($CertVal->"name")); \ subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning: " . ($CertVal->"name")); \
message=("A certificate on " . $Identity . " " . $State . ".\n\n" . [ $FormatInfo $Cert ]) }); message=("A certificate on " . $Identity . " " . $State . ".\n\n" . [ $FormatInfo $Cert ]) });
$LogPrintExit2 info $ScriptName ("The certificate '" . ($CertVal->"name") . "' " . $State . \ $LogPrint info $ScriptName ("The certificate '" . ($CertVal->"name") . "' " . $State . \
", it is invalid after " . ($CertVal->"invalid-after") . ".") false; ", it is invalid after " . ($CertVal->"invalid-after") . ".");
} }
} }
} on-error={ } } on-error={ }

View file

@ -28,7 +28,7 @@
:global FormatLine; :global FormatLine;
:global HumanReadableNum; :global HumanReadableNum;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -77,7 +77,7 @@
} }
:if ([ :len [ /system/health/find ] ] = 0) do={ :if ([ :len [ /system/health/find ] ] = 0) do={
$LogPrintExit2 debug $ScriptName ("Your device does not provide any health values.") false; $LogPrint debug $ScriptName ("Your device does not provide any health values.");
:error true; :error true;
} }
@ -148,7 +148,7 @@
:if ([ :typeof ($CheckHealthLast->$Name) ] != "nothing") do={ :if ([ :typeof ($CheckHealthLast->$Name) ] != "nothing") do={
:if ([ :typeof ($CheckHealthTemperature->$Name) ] != "num" ) do={ :if ([ :typeof ($CheckHealthTemperature->$Name) ] != "num" ) do={
$LogPrintExit2 info $ScriptName ("No threshold given for " . $Name . ", assuming 50C.") false; $LogPrint info $ScriptName ("No threshold given for " . $Name . ", assuming 50C.");
:set ($CheckHealthTemperature->$Name) 50; :set ($CheckHealthTemperature->$Name) 50;
} }
:local Validate [ /system/health/get [ find where name=$Name ] value ]; :local Validate [ /system/health/get [ find where name=$Name ] value ];

View file

@ -35,7 +35,7 @@
:global FormatLine; :global FormatLine;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -47,19 +47,19 @@
:set Firmware [ /interface/lte/firmware-upgrade $Interface once as-value ]; :set Firmware [ /interface/lte/firmware-upgrade $Interface once as-value ];
:set Info [ /interface/lte/monitor $Interface once as-value ]; :set Info [ /interface/lte/monitor $Interface once as-value ];
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Could not get latest LTE firmware version for interface " . \ $LogPrint debug $ScriptName ("Could not get latest LTE firmware version for interface " . \
$IntName . ".") false; $IntName . ".");
:return false; :return false;
} }
:if ([ :len ($Firmware->"latest") ] = 0) do={ :if ([ :len ($Firmware->"latest") ] = 0) do={
$LogPrintExit2 info $ScriptName ("An empty string is not a valid version.") false; $LogPrint info $ScriptName ("An empty string is not a valid version.");
:return false; :return false;
} }
:if (($Firmware->"installed") = ($Firmware->"latest")) do={ :if (($Firmware->"installed") = ($Firmware->"latest")) do={
:if ([ $ScriptFromTerminal $ScriptName ] = true) do={ :if ([ $ScriptFromTerminal $ScriptName ] = true) do={
$LogPrintExit2 info $ScriptName ("No firmware upgrade available for LTE interface " . $IntName . ".") false; $LogPrint info $ScriptName ("No firmware upgrade available for LTE interface " . $IntName . ".");
} }
:return true; :return true;
} }
@ -69,7 +69,7 @@
:put ("Do you want to start unattended lte firmware upgrade for interface " . $IntName . "? [y/N]"); :put ("Do you want to start unattended lte firmware upgrade for interface " . $IntName . "? [y/N]");
:if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={ :if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={
/system/script/run unattended-lte-firmware-upgrade; /system/script/run unattended-lte-firmware-upgrade;
$LogPrintExit2 info $ScriptName ("Scheduled lte firmware upgrade for interface " . $IntName . "...") false; $LogPrint info $ScriptName ("Scheduled lte firmware upgrade for interface " . $IntName . "...");
:return true; :return true;
} else={ } else={
:put "Canceled..."; :put "Canceled...";
@ -77,13 +77,13 @@
} }
:if (($SentLteFirmwareUpgradeNotification->$IntName) = ($Firmware->"latest")) do={ :if (($SentLteFirmwareUpgradeNotification->$IntName) = ($Firmware->"latest")) do={
$LogPrintExit2 debug $ScriptName ("Already sent the LTE firmware upgrade notification for version " . \ $LogPrint debug $ScriptName ("Already sent the LTE firmware upgrade notification for version " . \
($Firmware->"latest") . ".") false; ($Firmware->"latest") . ".");
:return false; :return false;
} }
$LogPrintExit2 info $ScriptName ("A new firmware version " . ($Firmware->"latest") . " is available for " . \ $LogPrint info $ScriptName ("A new firmware version " . ($Firmware->"latest") . " is available for " . \
"LTE interface " . $IntName . ".") false; "LTE interface " . $IntName . ".");
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \ subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \
message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \ message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \

View file

@ -24,7 +24,7 @@
:global DeviceInfo; :global DeviceInfo;
:global EscapeForRegEx; :global EscapeForRegEx;
:global LogPrintExit2; :global LogPrint;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
@ -50,12 +50,12 @@
:error "A reboot for update is already scheduled."; :error "A reboot for update is already scheduled.";
} }
$LogPrintExit2 debug $ScriptName ("Checking for updates...") false; $LogPrint debug $ScriptName ("Checking for updates...");
/system/package/update/check-for-updates without-paging as-value; /system/package/update/check-for-updates without-paging as-value;
:local Update [ /system/package/update/get ]; :local Update [ /system/package/update/get ];
:if ([ $ScriptFromTerminal $ScriptName ] = true && ($Update->"installed-version") = ($Update->"latest-version")) do={ :if ([ $ScriptFromTerminal $ScriptName ] = true && ($Update->"installed-version") = ($Update->"latest-version")) do={
$LogPrintExit2 info $ScriptName ("System is already up to date.") false; $LogPrint info $ScriptName ("System is already up to date.");
:error true; :error true;
} }
@ -64,13 +64,14 @@
:local Link ("https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree"); :local Link ("https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree");
:if ($NumLatest < 117505792) do={ :if ($NumLatest < 117505792) do={
$LogPrintExit2 info $ScriptName ("The version '" . ($Update->"latest-version") . "' is not a valid version.") true; $LogPrint info $ScriptName ("The version '" . ($Update->"latest-version") . "' is not a valid version.");
:error false;
} }
:if ($NumInstalled < $NumLatest) do={ :if ($NumInstalled < $NumLatest) do={
:if ($SafeUpdateAll ~ "^YES,? ?PLEASE!?\$") do={ :if ($SafeUpdateAll ~ "^YES,? ?PLEASE!?\$") do={
$LogPrintExit2 info $ScriptName ("Installing ALL versions automatically, including " . \ $LogPrint info $ScriptName ("Installing ALL versions automatically, including " . \
$Update->"latest-version" . "...") false; $Update->"latest-version" . "...");
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \
message=("Installing ALL versions automatically, including " . $Update->"latest-version" . \ message=("Installing ALL versions automatically, including " . $Update->"latest-version" . \
@ -79,7 +80,7 @@
} }
:if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={ :if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={
$LogPrintExit2 info $ScriptName ("Version " . $Update->"latest-version" . " is a patch release, updating...") false; $LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is a patch release, updating...");
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \
message=("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ message=("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \
@ -92,8 +93,8 @@
version~("^" . [ $EscapeForRegEx ($Update->"latest-version") ] . "\\b") ]; version~("^" . [ $EscapeForRegEx ($Update->"latest-version") ] . "\\b") ];
:if ([ :len $Neighbors ] > 0) do={ :if ([ :len $Neighbors ] > 0) do={
:local Neighbor [ /ip/neighbor/get ($Neighbors->0) identity ]; :local Neighbor [ /ip/neighbor/get ($Neighbors->0) identity ];
$LogPrintExit2 info $ScriptName ("Seen a neighbor (" . $Neighbor . ") running version " . \ $LogPrint info $ScriptName ("Seen a neighbor (" . $Neighbor . ") running version " . \
$Update->"latest-version" . " from " . $Update->"channel" . ", updating...") false; $Update->"latest-version" . " from " . $Update->"channel" . ", updating...");
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \
message=("Seen a neighbor (" . $Neighbor . ") running version " . $Update->"latest-version" . \ message=("Seen a neighbor (" . $Neighbor . ") running version " . $Update->"latest-version" . \
@ -109,10 +110,10 @@
($SafeUpdateUrl . $Update->"channel" . "?installed=" . $Update->"installed-version" . \ ($SafeUpdateUrl . $Update->"channel" . "?installed=" . $Update->"installed-version" . \
"&latest=" . $Update->"latest-version") output=user as-value ]; "&latest=" . $Update->"latest-version") output=user as-value ];
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ".") false; $LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ".");
} }
:if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={ :if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={
$LogPrintExit2 info $ScriptName ("Version " . $Update->"latest-version" . " is considered safe, updating...") false; $LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is considered safe, updating...");
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update: " . $Update->"latest-version"); \
message=("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ message=("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \
@ -131,8 +132,8 @@
} }
:if ($SentRouterosUpdateNotification = $Update->"latest-version") do={ :if ($SentRouterosUpdateNotification = $Update->"latest-version") do={
$LogPrintExit2 info $ScriptName ("Already sent the RouterOS update notification for version " . \ $LogPrint info $ScriptName ("Already sent the RouterOS update notification for version " . \
$Update->"latest-version" . ".") false; $Update->"latest-version" . ".");
:error true; :error true;
} }
@ -146,8 +147,8 @@
:if ($NumInstalled > $NumLatest) do={ :if ($NumInstalled > $NumLatest) do={
:if ($SentRouterosUpdateNotification = $Update->"latest-version") do={ :if ($SentRouterosUpdateNotification = $Update->"latest-version") do={
$LogPrintExit2 info $ScriptName ("Already sent the RouterOS downgrade notification for version " . \ $LogPrint info $ScriptName ("Already sent the RouterOS downgrade notification for version " . \
$Update->"latest-version" . ".") false; $Update->"latest-version" . ".");
:error true; :error true;
} }
@ -156,8 +157,8 @@
message=("A different RouterOS version " . ($Update->"latest-version") . \ message=("A different RouterOS version " . ($Update->"latest-version") . \
" is available for " . $Identity . ", but it is a downgrade.\n\n" . \ " is available for " . $Identity . ", but it is a downgrade.\n\n" . \
[ $DeviceInfo ]); link=$Link; silent=true }); [ $DeviceInfo ]); link=$Link; silent=true });
$LogPrintExit2 info $ScriptName ("A different RouterOS version " . ($Update->"latest-version") . \ $LogPrint info $ScriptName ("A different RouterOS version " . ($Update->"latest-version") . \
" is available for downgrade.") false; " is available for downgrade.");
:set SentRouterosUpdateNotification ($Update->"latest-version"); :set SentRouterosUpdateNotification ($Update->"latest-version");
} }
} on-error={ } } on-error={ }

View file

@ -23,7 +23,7 @@
:global FormatLine; :global FormatLine;
:global FormatMultiLines; :global FormatMultiLines;
:global GetMacVendor; :global GetMacVendor;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -34,7 +34,7 @@
:if ([ :len [ /caps-man/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={ :if ([ :len [ /caps-man/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
/caps-man/access-list/add comment="--- collected above ---" disabled=yes; /caps-man/access-list/add comment="--- collected above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.");
} }
:local PlaceBefore ([ /caps-man/access-list/find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ /caps-man/access-list/find where comment="--- collected above ---" disabled ]->0);
@ -43,14 +43,14 @@
:do { :do {
:set RegVal [ /caps-man/registration-table/get $Reg ]; :set RegVal [ /caps-man/registration-table/get $Reg ];
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Device already gone... Ignoring.") false; $LogPrint debug $ScriptName ("Device already gone... Ignoring.");
} }
:if ([ :len ($RegVal->"mac-address") ] > 0) do={ :if ([ :len ($RegVal->"mac-address") ] > 0) do={
:local AccessList ([ /caps-man/access-list/find where mac-address=($RegVal->"mac-address") ]->0); :local AccessList ([ /caps-man/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
:if ([ :len $AccessList ] > 0) do={ :if ([ :len $AccessList ] > 0) do={
$LogPrintExit2 debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \ $LogPrint debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \
[ /caps-man/access-list/get $AccessList comment ]) false; [ /caps-man/access-list/get $AccessList comment ]);
} }
:if ([ :len $AccessList ] = 0) do={ :if ([ :len $AccessList ] = 0) do={
@ -74,7 +74,7 @@
:local Vendor [ $GetMacVendor ($RegVal->"mac-address") ]; :local Vendor [ $GetMacVendor ($RegVal->"mac-address") ];
:local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \ :local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface"); "first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface");
$LogPrintExit2 info $ScriptName $Message false; $LogPrint info $ScriptName $Message;
/caps-man/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;
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \ subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \
@ -90,7 +90,7 @@
[ $FormatLine "Date" $DateTime ]) }); [ $FormatLine "Date" $DateTime ]) });
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("No mac address available... Ignoring.") false; $LogPrint debug $ScriptName ("No mac address available... Ignoring.");
} }
} }
} on-error={ } } on-error={ }

View file

@ -23,7 +23,7 @@
:global FormatLine; :global FormatLine;
:global FormatMultiLines; :global FormatMultiLines;
:global GetMacVendor; :global GetMacVendor;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -34,7 +34,7 @@
:if ([ :len [ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={ :if ([ :len [ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
/interface/wireless/access-list/add comment="--- collected above ---" disabled=yes; /interface/wireless/access-list/add comment="--- collected above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.");
} }
:local PlaceBefore ([ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ /interface/wireless/access-list/find where comment="--- collected above ---" disabled ]->0);
@ -43,14 +43,14 @@
:do { :do {
:set RegVal [ /interface/wireless/registration-table/get $Reg ]; :set RegVal [ /interface/wireless/registration-table/get $Reg ];
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Device already gone... Ignoring.") false; $LogPrint debug $ScriptName ("Device already gone... Ignoring.");
} }
:if ([ :len ($RegVal->"mac-address") ] > 0) do={ :if ([ :len ($RegVal->"mac-address") ] > 0) do={
:local AccessList ([ /interface/wireless/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={ :if ([ :len $AccessList ] > 0) do={
$LogPrintExit2 debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \ $LogPrint debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \
[ /interface/wireless/access-list/get $AccessList comment ]) false; [ /interface/wireless/access-list/get $AccessList comment ]);
} }
:if ([ :len $AccessList ] = 0) do={ :if ([ :len $AccessList ] = 0) do={
@ -75,7 +75,7 @@
:local Vendor [ $GetMacVendor ($RegVal->"mac-address") ]; :local Vendor [ $GetMacVendor ($RegVal->"mac-address") ];
:local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \ :local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface"); "first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface");
$LogPrintExit2 info $ScriptName $Message false; $LogPrint info $ScriptName $Message;
/interface/wireless/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=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \ subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \
@ -91,7 +91,7 @@
[ $FormatLine "Date" $DateTime ]) }); [ $FormatLine "Date" $DateTime ]) });
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("No mac address available... Ignoring.") false; $LogPrint debug $ScriptName ("No mac address available... Ignoring.");
} }
} }
} on-error={ } } on-error={ }

View file

@ -24,7 +24,7 @@
:global FormatLine; :global FormatLine;
:global FormatMultiLines; :global FormatMultiLines;
:global GetMacVendor; :global GetMacVendor;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -39,7 +39,7 @@
/caps-man/access-list/add comment="--- collected above ---" disabled=yes; /caps-man/access-list/add comment="--- collected above ---" disabled=yes;
/interface/wifi/access-list/add comment="--- collected above ---" disabled=yes; /interface/wifi/access-list/add comment="--- collected above ---" disabled=yes;
/interface/wireless/access-list/add comment="--- collected above ---" disabled=yes; /interface/wireless/access-list/add comment="--- collected above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.");
} }
:local PlaceBefore ([ /caps-man/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/wifi/access-list/find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- collected above ---" disabled ]->0);
@ -54,7 +54,7 @@
:set RegVal [ /interface/wifi/registration-table/get $Reg ]; :set RegVal [ /interface/wifi/registration-table/get $Reg ];
:set RegVal [ /interface/wireless/registration-table/get $Reg ]; :set RegVal [ /interface/wireless/registration-table/get $Reg ];
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Device already gone... Ignoring.") false; $LogPrint debug $ScriptName ("Device already gone... Ignoring.");
} }
:if ([ :len ($RegVal->"mac-address") ] > 0) do={ :if ([ :len ($RegVal->"mac-address") ] > 0) do={
@ -62,10 +62,10 @@
:local AccessList ([ /interface/wifi/access-list/find where mac-address=($RegVal->"mac-address") ]->0); :local AccessList ([ /interface/wifi/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
:local AccessList ([ /interface/wireless/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={ :if ([ :len $AccessList ] > 0) do={
$LogPrintExit2 debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \ $LogPrint debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \
[ /caps-man/access-list/get $AccessList comment ]) false; [ /caps-man/access-list/get $AccessList comment ]);
[ /interface/wifi/access-list/get $AccessList comment ]) false; [ /interface/wifi/access-list/get $AccessList comment ]);
[ /interface/wireless/access-list/get $AccessList comment ]) false; [ /interface/wireless/access-list/get $AccessList comment ]);
} }
:if ([ :len $AccessList ] = 0) do={ :if ([ :len $AccessList ] = 0) do={
@ -90,7 +90,7 @@
:local Vendor [ $GetMacVendor ($RegVal->"mac-address") ]; :local Vendor [ $GetMacVendor ($RegVal->"mac-address") ];
:local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \ :local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface"); "first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface");
$LogPrintExit2 info $ScriptName $Message false; $LogPrint info $ScriptName $Message;
/caps-man/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/wifi/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes; /interface/wifi/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; /interface/wireless/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes;
@ -108,7 +108,7 @@
[ $FormatLine "Date" $DateTime ]) }); [ $FormatLine "Date" $DateTime ]) });
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("No mac address available... Ignoring.") false; $LogPrint debug $ScriptName ("No mac address available... Ignoring.");
} }
} }
} on-error={ } } on-error={ }

View file

@ -23,7 +23,7 @@
:global FormatLine; :global FormatLine;
:global FormatMultiLines; :global FormatMultiLines;
:global GetMacVendor; :global GetMacVendor;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -34,7 +34,7 @@
:if ([ :len [ /interface/wifi/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={ :if ([ :len [ /interface/wifi/access-list/find where comment="--- collected above ---" disabled ] ] = 0) do={
/interface/wifi/access-list/add comment="--- collected above ---" disabled=yes; /interface/wifi/access-list/add comment="--- collected above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- collected above ---'.");
} }
:local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- collected above ---" disabled ]->0);
@ -43,14 +43,14 @@
:do { :do {
:set RegVal [ /interface/wifi/registration-table/get $Reg ]; :set RegVal [ /interface/wifi/registration-table/get $Reg ];
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Device already gone... Ignoring.") false; $LogPrint debug $ScriptName ("Device already gone... Ignoring.");
} }
:if ([ :len ($RegVal->"mac-address") ] > 0) do={ :if ([ :len ($RegVal->"mac-address") ] > 0) do={
:local AccessList ([ /interface/wifi/access-list/find where mac-address=($RegVal->"mac-address") ]->0); :local AccessList ([ /interface/wifi/access-list/find where mac-address=($RegVal->"mac-address") ]->0);
:if ([ :len $AccessList ] > 0) do={ :if ([ :len $AccessList ] > 0) do={
$LogPrintExit2 debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \ $LogPrint debug $ScriptName ("MAC address " . $RegVal->"mac-address" . " already known: " . \
[ /interface/wifi/access-list/get $AccessList comment ]) false; [ /interface/wifi/access-list/get $AccessList comment ]);
} }
:if ([ :len $AccessList ] = 0) do={ :if ([ :len $AccessList ] = 0) do={
@ -74,7 +74,7 @@
:local Vendor [ $GetMacVendor ($RegVal->"mac-address") ]; :local Vendor [ $GetMacVendor ($RegVal->"mac-address") ];
:local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \ :local Message ("MAC address " . $RegVal->"mac-address" . " (" . $Vendor . ", " . $HostName . ") " . \
"first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface"); "first seen on " . $DateTime . " connected to SSID " . $RegVal->"ssid" . ", interface " . $RegVal->"interface");
$LogPrintExit2 info $ScriptName $Message false; $LogPrint info $ScriptName $Message;
/interface/wifi/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes; /interface/wifi/access-list/add place-before=$PlaceBefore comment=$Message mac-address=($RegVal->"mac-address") disabled=yes;
$SendNotification2 ({ origin=$ScriptName; \ $SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \ subject=([ $SymbolForNotification "mobile-phone" ] . $RegVal->"mac-address" . " connected to " . $RegVal->"ssid"); \
@ -90,7 +90,7 @@
[ $FormatLine "Date" $DateTime ]) }); [ $FormatLine "Date" $DateTime ]) });
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("No mac address available... Ignoring.") false; $LogPrint debug $ScriptName ("No mac address available... Ignoring.");
} }
} }
} on-error={ } } on-error={ }

View file

@ -22,7 +22,7 @@
:global Identity; :global Identity;
:global FormatLine; :global FormatLine;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -68,12 +68,12 @@
:local Skip 0; :local Skip 0;
:if ($NewPsk != $OldPsk) do={ :if ($NewPsk != $OldPsk) do={
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; $LogPrint info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")");
/caps-man/access-list/set $AccList private-passphrase=$NewPsk; /caps-man/access-list/set $AccList private-passphrase=$NewPsk;
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={ :if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
:if ($Seen->$Ssid = 1) do={ :if ($Seen->$Ssid = 1) do={
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.");
} else={ } else={
:local Link ($DailyPskQrCodeUrl . \ :local Link ($DailyPskQrCodeUrl . \
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);

View file

@ -22,7 +22,7 @@
:global Identity; :global Identity;
:global FormatLine; :global FormatLine;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -67,12 +67,12 @@
:local Skip 0; :local Skip 0;
:if ($NewPsk != $OldPsk) do={ :if ($NewPsk != $OldPsk) do={
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; $LogPrint info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")");
/interface/wireless/access-list/set $AccList private-pre-shared-key=$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 [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
:if ($Seen->$Ssid = 1) do={ :if ($Seen->$Ssid = 1) do={
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.");
} else={ } else={
:local Link ($DailyPskQrCodeUrl . \ :local Link ($DailyPskQrCodeUrl . \
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);

View file

@ -23,7 +23,7 @@
:global Identity; :global Identity;
:global FormatLine; :global FormatLine;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -79,7 +79,7 @@
:local Skip 0; :local Skip 0;
:if ($NewPsk != $OldPsk) do={ :if ($NewPsk != $OldPsk) do={
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; $LogPrint info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")");
/caps-man/access-list/set $AccList private-passphrase=$NewPsk; /caps-man/access-list/set $AccList private-passphrase=$NewPsk;
/interface/wifi/access-list/set $AccList passphrase=$NewPsk; /interface/wifi/access-list/set $AccList passphrase=$NewPsk;
/interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk; /interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
@ -88,7 +88,7 @@
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={ :if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
:if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={ :if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
:if ($Seen->$Ssid = 1) do={ :if ($Seen->$Ssid = 1) do={
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.");
} else={ } else={
:local Link ($DailyPskQrCodeUrl . \ :local Link ($DailyPskQrCodeUrl . \
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);

View file

@ -22,7 +22,7 @@
:global Identity; :global Identity;
:global FormatLine; :global FormatLine;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
:global SymbolForNotification; :global SymbolForNotification;
@ -68,12 +68,12 @@
:local Skip 0; :local Skip 0;
:if ($NewPsk != $OldPsk) do={ :if ($NewPsk != $OldPsk) do={
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; $LogPrint info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")");
/interface/wifi/access-list/set $AccList passphrase=$NewPsk; /interface/wifi/access-list/set $AccList passphrase=$NewPsk;
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={ :if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
:if ($Seen->$Ssid = 1) do={ :if ($Seen->$Ssid = 1) do={
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; $LogPrint debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.");
} else={ } else={
:local Link ($DailyPskQrCodeUrl . \ :local Link ($DailyPskQrCodeUrl . \
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);

View file

@ -17,7 +17,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -32,7 +32,7 @@
:set NewComment [ /caps-man/access-list/get $AccessList comment ]; :set NewComment [ /caps-man/access-list/get $AccessList comment ];
} }
:if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={ :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
$LogPrintExit2 info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false; $LogPrint info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment);
/ip/dhcp-server/lease/set comment=$NewComment $Lease; /ip/dhcp-server/lease/set comment=$NewComment $Lease;
} }
} }

View file

@ -17,7 +17,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -32,7 +32,7 @@
:set NewComment [ /interface/wireless/access-list/get $AccessList comment ]; :set NewComment [ /interface/wireless/access-list/get $AccessList comment ];
} }
:if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={ :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
$LogPrintExit2 info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false; $LogPrint info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment);
/ip/dhcp-server/lease/set comment=$NewComment $Lease; /ip/dhcp-server/lease/set comment=$NewComment $Lease;
} }
} }

View file

@ -18,7 +18,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -37,7 +37,7 @@
:set NewComment [ /interface/wireless/access-list/get $AccessList comment ]; :set NewComment [ /interface/wireless/access-list/get $AccessList comment ];
} }
:if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={ :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
$LogPrintExit2 info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false; $LogPrint info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment);
/ip/dhcp-server/lease/set comment=$NewComment $Lease; /ip/dhcp-server/lease/set comment=$NewComment $Lease;
} }
} }

View file

@ -17,7 +17,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -32,7 +32,7 @@
:set NewComment [ /interface/wifi/access-list/get $AccessList comment ]; :set NewComment [ /interface/wifi/access-list/get $AccessList comment ];
} }
:if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={ :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
$LogPrintExit2 info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment) false; $LogPrint info $ScriptName ("Updating comment for DHCP lease " . $LeaseVal->"active-mac-address" . ": " . $NewComment);
/ip/dhcp-server/lease/set comment=$NewComment $Lease; /ip/dhcp-server/lease/set comment=$NewComment $Lease;
} }
} }

View file

@ -21,7 +21,7 @@
:global CleanName; :global CleanName;
:global EitherOr; :global EitherOr;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -36,7 +36,7 @@
:if ([ :len [ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ] ] = 0) do={ :if ([ :len [ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ] ] = 0) do={
/ip/dns/static/add name=$CommentString type=NXDOMAIN disabled=yes; /ip/dns/static/add name=$CommentString type=NXDOMAIN disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled static dns record with name '" . $CommentString . "'.") false; $LogPrint warning $ScriptName ("Added disabled static dns record with name '" . $CommentString . "'.");
} }
:local PlaceBefore ([ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ]->0); :local PlaceBefore ([ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ]->0);
@ -47,10 +47,10 @@
:if ([ :len [ /ip/dhcp-server/lease/find where active-mac-address=($DnsRecordInfo->"macaddress") \ :if ([ :len [ /ip/dhcp-server/lease/find where active-mac-address=($DnsRecordInfo->"macaddress") \
active-address=($DnsRecordVal->"address") server=($DnsRecordInfo->"server") status=bound ] ] > 0) do={ active-address=($DnsRecordVal->"address") server=($DnsRecordInfo->"server") status=bound ] ] > 0) do={
$LogPrintExit2 debug $ScriptName ("Lease for " . $MacInServer . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting record.") false; $LogPrint debug $ScriptName ("Lease for " . $MacInServer . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting record.");
} else={ } else={
:local Found false; :local Found false;
$LogPrintExit2 info $ScriptName ("Lease expired for " . $MacInServer . ", deleting record (" . $DnsRecordVal->"name" . ").") false; $LogPrint info $ScriptName ("Lease expired for " . $MacInServer . ", deleting record (" . $DnsRecordVal->"name" . ").");
/ip/dns/static/remove $DnsRecord; /ip/dns/static/remove $DnsRecord;
/ip/dns/static/remove [ find where type=CNAME comment=($DnsRecordVal->"comment") ]; /ip/dns/static/remove [ find where type=CNAME comment=($DnsRecordVal->"comment") ];
} }
@ -64,7 +64,7 @@
$LogPrintOnce info $ScriptName ("Multiple bound leases found for mac-address " . ($LeaseVal->"active-mac-address") . "!"); $LogPrintOnce info $ScriptName ("Multiple bound leases found for mac-address " . ($LeaseVal->"active-mac-address") . "!");
} }
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("A lease just vanished, ignoring.") false; $LogPrint debug $ScriptName ("A lease just vanished, ignoring.");
} }
:if ([ :len ($LeaseVal->"active-address") ] > 0) do={ :if ([ :len ($LeaseVal->"active-address") ] > 0) do={
@ -88,9 +88,9 @@
:local DnsRecordVal [ /ip/dns/static/get $DnsRecord ]; :local DnsRecordVal [ /ip/dns/static/get $DnsRecord ];
:if ($DnsRecordVal->"address" = $LeaseVal->"active-address" && $DnsRecordVal->"name" = $FullA) do={ :if ($DnsRecordVal->"address" = $LeaseVal->"active-address" && $DnsRecordVal->"name" = $FullA) do={
$LogPrintExit2 debug $ScriptName ("The A record for " . $MacInServer . " (" . $FullA . ") does not need updating.") false; $LogPrint debug $ScriptName ("The A record for " . $MacInServer . " (" . $FullA . ") does not need updating.");
} else={ } else={
$LogPrintExit2 info $ScriptName ("Updating A record for " . $MacInServer . " (" . $FullA . " -> " . $LeaseVal->"active-address" . ").") false; $LogPrint info $ScriptName ("Updating A record for " . $MacInServer . " (" . $FullA . " -> " . $LeaseVal->"active-address" . ").");
/ip/dns/static/set address=($LeaseVal->"active-address") name=$FullA $DnsRecord; /ip/dns/static/set address=($LeaseVal->"active-address") name=$FullA $DnsRecord;
} }
@ -98,20 +98,20 @@
:if ([ :len $CName ] > 0) do={ :if ([ :len $CName ] > 0) do={
:local CNameVal [ /ip/dns/static/get $CName ]; :local CNameVal [ /ip/dns/static/get $CName ];
:if ($CNameVal->"name" != $FullCN || $CNameVal->"cname" != $FullA) do={ :if ($CNameVal->"name" != $FullCN || $CNameVal->"cname" != $FullA) do={
$LogPrintExit2 info $ScriptName ("Deleting CNAME record with wrong data for " . $MacInServer . ".") false; $LogPrint info $ScriptName ("Deleting CNAME record with wrong data for " . $MacInServer . ".");
/ip/dns/static/remove $CName; /ip/dns/static/remove $CName;
} }
} }
:if ([ :len $HostName ] > 0 && [ :len [ /ip/dns/static/find where name=$FullCN type=CNAME ] ] = 0) do={ :if ([ :len $HostName ] > 0 && [ :len [ /ip/dns/static/find where name=$FullCN type=CNAME ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("Adding CNAME record for " . $MacInServer . " (" . $FullCN . " -> " . $FullA . ").") false; $LogPrint info $ScriptName ("Adding CNAME record for " . $MacInServer . " (" . $FullCN . " -> " . $FullA . ").");
/ip/dns/static/add name=$FullCN type=CNAME cname=$FullA ttl=$Ttl comment=$Comment place-before=$PlaceBefore; /ip/dns/static/add name=$FullCN type=CNAME cname=$FullA ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
} }
} else={ } else={
$LogPrintExit2 info $ScriptName ("Adding A record for " . $MacInServer . " (" . $FullA . " -> " . $LeaseVal->"active-address" . ").") false; $LogPrint info $ScriptName ("Adding A record for " . $MacInServer . " (" . $FullA . " -> " . $LeaseVal->"active-address" . ").");
/ip/dns/static/add name=$FullA type=A address=($LeaseVal->"active-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore; /ip/dns/static/add name=$FullA type=A address=($LeaseVal->"active-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
:if ([ :len $HostName ] > 0 && [ :len [ /ip/dns/static/find where name=$FullCN type=CNAME ] ] = 0) do={ :if ([ :len $HostName ] > 0 && [ :len [ /ip/dns/static/find where name=$FullCN type=CNAME ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("Adding CNAME record for " . $MacInServer . " (" . $FullCN . " -> " . $FullA . ").") false; $LogPrint info $ScriptName ("Adding CNAME record for " . $MacInServer . " (" . $FullCN . " -> " . $FullA . ").");
/ip/dns/static/add name=$FullCN type=CNAME cname=$FullA ttl=$Ttl comment=$Comment place-before=$PlaceBefore; /ip/dns/static/add name=$FullCN type=CNAME cname=$FullA ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
} }
} }
@ -120,7 +120,7 @@
$LogPrintOnce warning $ScriptName ("The name '" . $FullA . "' appeared in more than one A record!"); $LogPrintOnce warning $ScriptName ("The name '" . $FullA . "' appeared in more than one A record!");
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("No address available... Ignoring.") false; $LogPrint debug $ScriptName ("No address available... Ignoring.");
} }
} }
} on-error={ } } on-error={ }

View file

@ -14,7 +14,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global VersionToNum; :global VersionToNum;
@ -24,18 +24,18 @@
:local RouterBoard [ /system/routerboard/get ]; :local RouterBoard [ /system/routerboard/get ];
:if ($RouterBoard->"current-firmware" = $RouterBoard->"upgrade-firmware") do={ :if ($RouterBoard->"current-firmware" = $RouterBoard->"upgrade-firmware") do={
$LogPrintExit2 info $ScriptName ("Current and upgrade firmware match with version " . \ $LogPrint info $ScriptName ("Current and upgrade firmware match with version " . \
$RouterBoard->"current-firmware" . ".") false; $RouterBoard->"current-firmware" . ".");
:error true; :error true;
} }
:if ([ $VersionToNum ($RouterBoard->"current-firmware") ] > [ $VersionToNum ($RouterBoard->"upgrade-firmware") ]) do={ :if ([ $VersionToNum ($RouterBoard->"current-firmware") ] > [ $VersionToNum ($RouterBoard->"upgrade-firmware") ]) do={
$LogPrintExit2 info $ScriptName ("Different firmware version is available, but it is a downgrade. Ignoring.") false; $LogPrint info $ScriptName ("Different firmware version is available, but it is a downgrade. Ignoring.");
:error true; :error true;
} }
:if ([ /system/routerboard/settings/get auto-upgrade ] = false) do={ :if ([ /system/routerboard/settings/get auto-upgrade ] = false) do={
$LogPrintExit2 info $ScriptName ("Firmware version " . $RouterBoard->"upgrade-firmware" . \ $LogPrint info $ScriptName ("Firmware version " . $RouterBoard->"upgrade-firmware" . \
" is available, upgrading.") false; " is available, upgrading.");
/system/routerboard/upgrade; /system/routerboard/upgrade;
} }
@ -49,6 +49,6 @@
:delay $Uptime; :delay $Uptime;
} }
$LogPrintExit2 info $ScriptName ("Firmware upgrade successful, rebooting.") false; $LogPrint info $ScriptName ("Firmware upgrade successful, rebooting.");
/system/reboot; /system/reboot;
} on-error={ } } on-error={ }

View file

@ -20,7 +20,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ScriptLock; :global ScriptLock;
:global WaitFullyConnected; :global WaitFullyConnected;
@ -57,7 +57,7 @@
:if ([ :len ($List->"cert") ] > 0) do={ :if ([ :len ($List->"cert") ] > 0) do={
:set CheckCertificate "yes-without-crl"; :set CheckCertificate "yes-without-crl";
:if ([ $CertificateAvailable ($List->"cert") ] = false) do={ :if ([ $CertificateAvailable ($List->"cert") ] = false) do={
$LogPrintExit2 warning $ScriptName ("Downloading required certificate failed, trying anyway.") false; $LogPrint warning $ScriptName ("Downloading required certificate failed, trying anyway.");
} }
} }
@ -68,7 +68,7 @@
http-header-field=({ $FetchUserAgent }) ($List->"url") as-value ]->"data"); http-header-field=({ $FetchUserAgent }) ($List->"url") as-value ]->"data");
} on-error={ } on-error={
:if ($I < 4) do={ :if ($I < 4) do={
$LogPrintExit2 debug $ScriptName ("Failed downloading, " . $I . ". try: " . $List->"url") false; $LogPrint debug $ScriptName ("Failed downloading, " . $I . ". try: " . $List->"url");
:delay (($I * $I) . "s"); :delay (($I * $I) . "s");
} }
} }
@ -78,7 +78,7 @@
:if ($Data = false) do={ :if ($Data = false) do={
:set Data ""; :set Data "";
:set Failure true; :set Failure true;
$LogPrintExit2 warning $ScriptName ("Failed downloading list from: " . $List->"url") false; $LogPrint warning $ScriptName ("Failed downloading list from: " . $List->"url");
} }
:if ([ :len $Data ] > 63000) do={ :if ([ :len $Data ] > 63000) do={
@ -103,13 +103,13 @@
:foreach Entry in=[ /ip/firewall/address-list/find where list=$FwListName comment=$ListComment ] do={ :foreach Entry in=[ /ip/firewall/address-list/find where list=$FwListName comment=$ListComment ] do={
:local Address [ /ip/firewall/address-list/get $Entry address ]; :local Address [ /ip/firewall/address-list/get $Entry address ];
:if ([ :typeof ($IPv4Addresses->$Address) ] = "time") do={ :if ([ :typeof ($IPv4Addresses->$Address) ] = "time") do={
$LogPrintExit2 debug $ScriptName ("Renewing IPv4 address for " . ($IPv4Addresses->$Address) . ": " . $Address) false; $LogPrint debug $ScriptName ("Renewing IPv4 address for " . ($IPv4Addresses->$Address) . ": " . $Address);
/ip/firewall/address-list/set $Entry timeout=($IPv4Addresses->$Address); /ip/firewall/address-list/set $Entry timeout=($IPv4Addresses->$Address);
:set ($IPv4Addresses->$Address); :set ($IPv4Addresses->$Address);
:set CntRenew ($CntRenew + 1); :set CntRenew ($CntRenew + 1);
} else={ } else={
:if ($Failure = false) do={ :if ($Failure = false) do={
$LogPrintExit2 debug $ScriptName ("Removing IPv4 address: " . $Address) false; $LogPrint debug $ScriptName ("Removing IPv4 address: " . $Address);
/ip/firewall/address-list/remove $Entry; /ip/firewall/address-list/remove $Entry;
:set CntRemove ($CntRemove + 1); :set CntRemove ($CntRemove + 1);
} }
@ -119,13 +119,13 @@
:foreach Entry in=[ /ipv6/firewall/address-list/find where list=$FwListName comment=$ListComment ] do={ :foreach Entry in=[ /ipv6/firewall/address-list/find where list=$FwListName comment=$ListComment ] do={
:local Address [ /ipv6/firewall/address-list/get $Entry address ]; :local Address [ /ipv6/firewall/address-list/get $Entry address ];
:if ([ :typeof ($IPv6Addresses->$Address) ] = "time") do={ :if ([ :typeof ($IPv6Addresses->$Address) ] = "time") do={
$LogPrintExit2 debug $ScriptName ("Renewing IPv6 address for " . ($IPv6Addresses->$Address) . ": " . $Address) false; $LogPrint debug $ScriptName ("Renewing IPv6 address for " . ($IPv6Addresses->$Address) . ": " . $Address);
/ipv6/firewall/address-list/set $Entry timeout=($IPv6Addresses->$Address); /ipv6/firewall/address-list/set $Entry timeout=($IPv6Addresses->$Address);
:set ($IPv6Addresses->$Address); :set ($IPv6Addresses->$Address);
:set CntRenew ($CntRenew + 1); :set CntRenew ($CntRenew + 1);
} else={ } else={
:if ($Failure = false) do={ :if ($Failure = false) do={
$LogPrintExit2 debug $ScriptName ("Removing: " . $Address) false; $LogPrint debug $ScriptName ("Removing: " . $Address);
/ipv6/firewall/address-list/remove $Entry; /ipv6/firewall/address-list/remove $Entry;
:set CntRemove ($CntRemove + 1); :set CntRemove ($CntRemove + 1);
} }
@ -133,27 +133,27 @@
} }
:foreach Address,Timeout in=$IPv4Addresses do={ :foreach Address,Timeout in=$IPv4Addresses do={
$LogPrintExit2 debug $ScriptName ("Adding IPv4 address for " . $Timeout . ": " . $Address) false; $LogPrint debug $ScriptName ("Adding IPv4 address for " . $Timeout . ": " . $Address);
:do { :do {
/ip/firewall/address-list/add list=$FwListName comment=$ListComment address=$Address timeout=$Timeout; /ip/firewall/address-list/add list=$FwListName comment=$ListComment address=$Address timeout=$Timeout;
:set ($IPv4Addresses->$Address); :set ($IPv4Addresses->$Address);
:set CntAdd ($CntAdd + 1); :set CntAdd ($CntAdd + 1);
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Failed to add IPv4 address " . $Address . " to list '" . $FwListName . "'.") false; $LogPrint warning $ScriptName ("Failed to add IPv4 address " . $Address . " to list '" . $FwListName . "'.");
} }
} }
:foreach Address,Timeout in=$IPv6Addresses do={ :foreach Address,Timeout in=$IPv6Addresses do={
$LogPrintExit2 debug $ScriptName ("Adding IPv6 address for " . $Timeout . ": " . $Address) false; $LogPrint debug $ScriptName ("Adding IPv6 address for " . $Timeout . ": " . $Address);
:do { :do {
/ipv6/firewall/address-list/add list=$FwListName comment=$ListComment address=$Address timeout=$Timeout; /ipv6/firewall/address-list/add list=$FwListName comment=$ListComment address=$Address timeout=$Timeout;
:set ($IPv6Addresses->$Address); :set ($IPv6Addresses->$Address);
:set CntAdd ($CntAdd + 1); :set CntAdd ($CntAdd + 1);
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Failed to add IPv6 address " . $Address . " to list '" . $FwListName . "'.") false; $LogPrint warning $ScriptName ("Failed to add IPv6 address " . $Address . " to list '" . $FwListName . "'.");
} }
} }
$LogPrintExit2 info $ScriptName ("list: " . $FwListName . " -- added: " . $CntAdd . " - renewed: " . $CntRenew . " - removed: " . $CntRemove) false; $LogPrint info $ScriptName ("list: " . $FwListName . " -- added: " . $CntAdd . " - renewed: " . $CntRenew . " - removed: " . $CntRemove);
} }
} on-error={ } } on-error={ }

View file

@ -12,7 +12,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
# expected configuration version # expected configuration version
:global ExpectedConfigVersion 122; :global ExpectedConfigVersion 123;
# global variables not to be changed by user # global variables not to be changed by user
:global GlobalFunctionsReady false; :global GlobalFunctionsReady false;
@ -53,6 +53,7 @@
:global IsFullyConnected; :global IsFullyConnected;
:global IsMacLocallyAdministered; :global IsMacLocallyAdministered;
:global IsTimeSync; :global IsTimeSync;
:global LogPrint;
:global LogPrintExit2; :global LogPrintExit2;
:global LogPrintOnce; :global LogPrintOnce;
:global MAX; :global MAX;
@ -101,18 +102,18 @@
:local CommonName [ :tostr $1 ]; :local CommonName [ :tostr $1 ];
:global CertificateDownload; :global CertificateDownload;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:if ([ /system/resource/get free-hdd-space ] < 8388608 && \ :if ([ /system/resource/get free-hdd-space ] < 8388608 && \
[ /certificate/settings/get crl-download ] = true && \ [ /certificate/settings/get crl-download ] = true && \
[ /certificate/settings/get crl-store ] = "system") do={ [ /certificate/settings/get crl-store ] = "system") do={
$LogPrintExit2 warning $0 ("This system has low free flash space but " . \ $LogPrint warning $0 ("This system has low free flash space but " . \
"is configured to download certificate CRLs to system!") false; "is configured to download certificate CRLs to system!");
} }
:if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={ :if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.") false; $LogPrint info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.");
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
@ -121,8 +122,8 @@
:local CertVal [ /certificate/get [ find where common-name=$CommonName ] ]; :local CertVal [ /certificate/get [ find where common-name=$CommonName ] ];
:while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={ :while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={
:if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={ :if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate chain for \"" . $CommonName . \ $LogPrint info $0 ("Certificate chain for \"" . $CommonName . \
"\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".") false; "\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".");
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
@ -141,12 +142,12 @@
:global ScriptUpdatesUrlSuffix; :global ScriptUpdatesUrlSuffix;
:global CertificateNameByCN; :global CertificateNameByCN;
:global LogPrintExit2; :global LogPrint;
:global UrlEncode; :global UrlEncode;
:global WaitForFile; :global WaitForFile;
$LogPrintExit2 info $0 ("Downloading and importing certificate with " . \ $LogPrint info $0 ("Downloading and importing certificate with " . \
"CommonName \"" . $CommonName . "\".") false; "CommonName \"" . $CommonName . "\".");
:do { :do {
:local LocalFileName ($CommonName . ".pem"); :local LocalFileName ($CommonName . ".pem");
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem"); :local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
@ -162,8 +163,7 @@
$CertificateNameByCN [ /certificate/get $Cert common-name ]; $CertificateNameByCN [ /certificate/get $Cert common-name ];
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed importing certificate with " . \ $LogPrint warning $0 ("Failed importing certificate with CommonName \"" . $CommonName . "\"!");
"CommonName \"" . $CommonName . "\"!") false;
:return false; :return false;
} }
:return true; :return true;
@ -308,7 +308,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global CleanFilePath; :global CleanFilePath;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global WaitForFile; :global WaitForFile;
@ -323,23 +323,23 @@
:local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ]; :local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ];
:if ([ $MkDir $PkgDir ] = false) do={ :if ([ $MkDir $PkgDir ] = false) do={
$LogPrintExit2 warning $0 ("Failed creating directory, not downloading package.") false; $LogPrint warning $0 ("Failed creating directory, not downloading package.");
:return false; :return false;
} }
:if ([ :len [ /file/find where name=$PkgDest type="package" ] ] > 0) do={ :if ([ :len [ /file/find where name=$PkgDest type="package" ] ] > 0) do={
$LogPrintExit2 info $0 ("Package file " . $PkgName . " already exists.") false; $LogPrint info $0 ("Package file " . $PkgName . " already exists.");
:return true; :return true;
} }
:if ([ $CertificateAvailable "R3" ] = false) do={ :if ([ $CertificateAvailable "R3" ] = false) do={
$LogPrintExit2 error $0 ("Downloading required certificate failed.") false; $LogPrint error $0 ("Downloading required certificate failed.");
:return false; :return false;
} }
:local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile); :local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile);
$LogPrintExit2 info $0 ("Downloading package file '" . $PkgName . "'...") false; $LogPrint info $0 ("Downloading package file '" . $PkgName . "'...");
$LogPrintExit2 debug $0 ("... from url: " . $Url) false; $LogPrint debug $0 ("... from url: " . $Url);
:local Retry 3; :local Retry 3;
:while ($Retry > 0) do={ :while ($Retry > 0) do={
:do { :do {
@ -350,14 +350,14 @@
:return true; :return true;
} }
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Downloading package file failed.") false; $LogPrint debug $0 ("Downloading package file failed.");
} }
/file/remove [ find where name=$PkgDest ]; /file/remove [ find where name=$PkgDest ];
:set Retry ($Retry - 1); :set Retry ($Retry - 1);
} }
$LogPrintExit2 warning $0 ("Downloading package file '" . $PkgName . "' failed.") false; $LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed.");
:return false; :return false;
} }
@ -443,7 +443,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global IsMacLocallyAdministered; :global IsMacLocallyAdministered;
:global LogPrintExit2; :global LogPrint;
:if ([ $IsMacLocallyAdministered $Mac ] = true) do={ :if ([ $IsMacLocallyAdministered $Mac ] = true) do={
:return "locally administered"; :return "locally administered";
@ -451,7 +451,8 @@
:do { :do {
:if ([ $CertificateAvailable "GTS CA 1P5" ] = false) do={ :if ([ $CertificateAvailable "GTS CA 1P5" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; $LogPrint warning $0 ("Downloading required certificate failed.");
:error false;
} }
:local Vendor ([ /tool/fetch check-certificate=yes-without-crl \ :local Vendor ([ /tool/fetch check-certificate=yes-without-crl \
("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data"); ("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data");
@ -460,9 +461,9 @@
:do { :do {
/tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \ /tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \
output=none as-value; output=none as-value;
$LogPrintExit2 debug $0 ("The mac vendor is not known in database.") false; $LogPrint debug $0 ("The mac vendor is not known in database.");
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed getting mac vendor.") false; $LogPrint warning $0 ("Failed getting mac vendor.");
} }
:return "unknown vendor"; :return "unknown vendor";
} }
@ -609,7 +610,7 @@
:global IsTimeSyncCached; :global IsTimeSyncCached;
:global IsTimeSyncResetNtp; :global IsTimeSyncResetNtp;
:global LogPrintExit2; :global LogPrint;
:if ($IsTimeSyncCached = true) do={ :if ($IsTimeSyncCached = true) do={
:return true; :return true;
@ -638,7 +639,7 @@
:if ([ /system/license/get ]->"level" = "free" || \ :if ([ /system/license/get ]->"level" = "free" || \
[ /system/resource/get ]->"board-name" = "x86") do={ [ /system/resource/get ]->"board-name" = "x86") do={
$LogPrintExit2 debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.") false; $LogPrint debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.");
:return true; :return true;
} }
@ -650,16 +651,15 @@
:return false; :return false;
} }
$LogPrintExit2 debug $0 ("No time source configured! Returning gracefully...") false; $LogPrint debug $0 ("No time source configured! Returning gracefully...");
:return true; :return true;
} }
# log and print with same text, optionally exit # log and print with same text
:set LogPrintExit2 do={ :set LogPrint do={
:local Severity [ :tostr $1 ]; :local Severity [ :tostr $1 ];
:local Name [ :tostr $2 ]; :local Name [ :tostr $2 ];
:local Message [ :tostr $3 ]; :local Message [ :tostr $3 ];
:local Exit [ :tostr $4 ];
:global PrintDebug; :global PrintDebug;
:global PrintDebugOverride; :global PrintDebugOverride;
@ -692,6 +692,19 @@
:if ($Severity != "debug" || $Debug = true) do={ :if ($Severity != "debug" || $Debug = true) do={
:put ([ $PrintSeverity $Severity ] . ": " . $Message); :put ([ $PrintSeverity $Severity ] . ": " . $Message);
} }
}
# log and print with same text, optionally exit
# Deprectated! - TODO: remove later
:set LogPrintExit2 do={
:local Severity [ :tostr $1 ];
:local Name [ :tostr $2 ];
:local Message [ :tostr $3 ];
:local Exit [ :tostr $4 ];
:global LogPrint;
$LogPrint $1 $2 $3;
:if ($Exit = "true") do={ :if ($Exit = "true") do={
:error ("Hard error to exit."); :error ("Hard error to exit.");
@ -704,7 +717,7 @@
:local Name [ :tostr $2 ]; :local Name [ :tostr $2 ];
:local Message [ :tostr $3 ]; :local Message [ :tostr $3 ];
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnceMessages; :global LogPrintOnceMessages;
@ -717,7 +730,7 @@
} }
:set ($LogPrintOnceMessages->$Message) 1; :set ($LogPrintOnceMessages->$Message) 1;
$LogPrintExit2 $Severity $Name $Message false; $LogPrint $Severity $Name $Message;
} }
# get max value # get max value
@ -737,24 +750,24 @@
:local Path [ :tostr $1 ]; :local Path [ :tostr $1 ];
:global CleanFilePath; :global CleanFilePath;
:global LogPrintExit2; :global LogPrint;
:global WaitForFile; :global WaitForFile;
:local MkTmpfs do={ :local MkTmpfs do={
:global LogPrintExit2; :global LogPrint;
:global WaitForFile; :global WaitForFile;
:if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 1) do={ :if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 1) do={
:return true; :return true;
} }
$LogPrintExit2 info $0 ("Creating disk of type tmpfs.") false; $LogPrint info $0 ("Creating disk of type tmpfs.");
/file/remove [ find where name="tmpfs" type="directory" ]; /file/remove [ find where name="tmpfs" type="directory" ];
:do { :do {
/disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3); /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3);
$WaitForFile "tmpfs"; $WaitForFile "tmpfs";
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Creating disk of type tmpfs failed!") false; $LogPrint warning $0 ("Creating disk of type tmpfs failed!");
:return false; :return false;
} }
:return true; :return true;
@ -782,7 +795,7 @@
$WaitForFile $File; $WaitForFile $File;
/file/remove $File; /file/remove $File;
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Making directory '" . $Path . "' failed!") false; $LogPrint warning $0 ("Making directory '" . $Path . "' failed!");
:return false; :return false;
} }
@ -913,18 +926,18 @@
:local Warn [ :tostr $3 ]; :local Warn [ :tostr $3 ];
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global VersionToNum; :global VersionToNum;
:if (!($Required ~ "^\\d+\\.\\d+((alpha|beta|rc|\\.)\\d+|)\$")) do={ :if (!($Required ~ "^\\d+\\.\\d+((alpha|beta|rc|\\.)\\d+|)\$")) do={
$LogPrintExit2 error $0 ("No valid RouterOS version: " . $Required) false; $LogPrint error $0 ("No valid RouterOS version: " . $Required);
:return false; :return false;
} }
:if ([ $VersionToNum $Required ] > [ $VersionToNum [ /system/package/update/get installed-version ] ]) do={ :if ([ $VersionToNum $Required ] > [ $VersionToNum [ /system/package/update/get installed-version ] ]) do={
:if ($Warn = "true") do={ :if ($Warn = "true") do={
$LogPrintExit2 warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \ $LogPrint warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \
" '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!") false; " '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!");
} }
:return false; :return false;
} }
@ -935,7 +948,7 @@
:set ScriptFromTerminal do={ :set ScriptFromTerminal do={
:local Script [ :tostr $1 ]; :local Script [ :tostr $1 ];
:global LogPrintExit2; :global LogPrint;
:foreach Job in=[ /system/script/job/find where script=$Script ] do={ :foreach Job in=[ /system/script/job/find where script=$Script ] do={
:set Job [ /system/script/job/get $Job ]; :set Job [ /system/script/job/get $Job ];
@ -943,11 +956,11 @@
:set Job [ /system/script/job/get [ find where .id=($Job->"parent") ] ]; :set Job [ /system/script/job/get [ find where .id=($Job->"parent") ] ];
} }
:if (($Job->"type") = "login") do={ :if (($Job->"type") = "login") do={
$LogPrintExit2 debug $0 ("Script " . $Script . " started from terminal.") false; $LogPrint debug $0 ("Script " . $Script . " started from terminal.");
:return true; :return true;
} }
} }
$LogPrintExit2 debug $0 ("Script " . $Script . " NOT started from terminal.") false; $LogPrint debug $0 ("Script " . $Script . " NOT started from terminal.");
:return false; :return false;
} }
@ -969,7 +982,7 @@
:global EitherOr; :global EitherOr;
:global Grep; :global Grep;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global RequiredRouterOS; :global RequiredRouterOS;
@ -978,12 +991,12 @@
:global ValidateSyntax; :global ValidateSyntax;
:if ([ $CertificateAvailable "E1" ] = false) do={ :if ([ $CertificateAvailable "E1" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading certificate failed, trying without.") false; $LogPrint warning $0 ("Downloading certificate failed, trying without.");
} }
:foreach Script in=$Scripts do={ :foreach Script in=$Scripts do={
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 info $0 ("Adding new script: " . $Script) false; $LogPrint info $0 ("Adding new script: " . $Script);
/system/script/add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment; /system/script/add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment;
} }
} }
@ -1000,8 +1013,8 @@
:foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={ :foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={
:local SchedulerVal [ /system/scheduler/get $Scheduler ]; :local SchedulerVal [ /system/scheduler/get $Scheduler ];
:if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={ :if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={
$LogPrintExit2 warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \
"' and its scheduler '" . $SchedulerVal->"name" . "'!") false; "' and its scheduler '" . $SchedulerVal->"name" . "'!");
} }
} }
@ -1010,7 +1023,7 @@
:local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ]; :local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ];
:local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ]; :local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ];
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix); :local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
$LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false; $LogPrint debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \ :local Result [ /tool/fetch check-certificate=yes-without-crl \
http-header-field=({ $FetchUserAgent }) $Url output=user as-value ]; http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
@ -1018,11 +1031,11 @@
} }
} on-error={ } on-error={
:if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={ :if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={
$LogPrintExit2 warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \
"', removing dummy. Typo on installation?") false; "', removing dummy. Typo on installation?");
/system/script/remove $Script; /system/script/remove $Script;
} else={ } else={
$LogPrintExit2 warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!") false; $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!");
} }
} }
} }
@ -1033,7 +1046,7 @@
:local Required ([ $ParseKeyValueStore [ $Grep $SourceNew ("\23 requires RouterOS, ") ] ]->"version"); :local Required ([ $ParseKeyValueStore [ $Grep $SourceNew ("\23 requires RouterOS, ") ] ]->"version");
:if ([ $RequiredRouterOS $0 [ $EitherOr $Required "0.0" ] false ] = true) do={ :if ([ $RequiredRouterOS $0 [ $EitherOr $Required "0.0" ] false ] = true) do={
:if ([ $ValidateSyntax $SourceNew ] = true) do={ :if ([ $ValidateSyntax $SourceNew ] = true) do={
$LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; $LogPrint info $0 ("Updating script: " . $ScriptVal->"name");
/system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script; /system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script;
:if ($ScriptVal->"name" = "global-config") do={ :if ($ScriptVal->"name" = "global-config") do={
:set ReloadGlobalConfig true; :set ReloadGlobalConfig true;
@ -1042,48 +1055,48 @@
:set ReloadGlobalFunctions true; :set ReloadGlobalFunctions true;
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \
"' failed! Ignoring!") false; "' failed! Ignoring!");
} }
} else={ } else={
$LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \ $LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \
$Required . ", which is not met by your installation. Ignoring!"); $Required . ", which is not met by your installation. Ignoring!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Looks like new script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Looks like new script '" . $ScriptVal->"name" . \
"' is not valid (missing shebang). Ignoring!") false; "' is not valid (missing shebang). Ignoring!");
} }
} else={ } else={
$LogPrintExit2 debug $0 ("Script '" . $ScriptVal->"name" . "' did not change.") false; $LogPrint debug $0 ("Script '" . $ScriptVal->"name" . "' did not change.");
} }
} else={ } else={
$LogPrintExit2 debug $0 ("No update for script '" . $ScriptVal->"name" . "'.") false; $LogPrint debug $0 ("No update for script '" . $ScriptVal->"name" . "'.");
} }
} }
:if ($ReloadGlobalFunctions = true) do={ :if ($ReloadGlobalFunctions = true) do={
$LogPrintExit2 info $0 ("Reloading global functions.") false; $LogPrint info $0 ("Reloading global functions.");
:do { :do {
/system/script/run global-functions; /system/script/run global-functions;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global functions failed!") false; $LogPrint error $0 ("Reloading global functions failed!");
} }
} }
:if ($ReloadGlobalConfig = true) do={ :if ($ReloadGlobalConfig = true) do={
$LogPrintExit2 info $0 ("Reloading global configuration.") false; $LogPrint info $0 ("Reloading global configuration.");
:do { :do {
/system/script/run global-config; /system/script/run global-config;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global configuration failed!" . \ $LogPrint error $0 ("Reloading global configuration failed!" . \
" Syntax error or missing overlay?") false; " Syntax error or missing overlay?");
} }
} }
:if ($ExpectedConfigVersionBefore > $ExpectedConfigVersion) do={ :if ($ExpectedConfigVersionBefore > $ExpectedConfigVersion) do={
$LogPrintExit2 warning $0 ("The configuration version decreased from " . \ $LogPrint warning $0 ("The configuration version decreased from " . \
$ExpectedConfigVersionBefore . " to " . $ExpectedConfigVersion . \ $ExpectedConfigVersionBefore . " to " . $ExpectedConfigVersion . \
". Installed an older version?") false; ". Installed an older version?");
} }
:if ($ExpectedConfigVersionBefore < $ExpectedConfigVersion) do={ :if ($ExpectedConfigVersionBefore < $ExpectedConfigVersion) do={
@ -1093,14 +1106,14 @@
:do { :do {
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix); :local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
$LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false; $LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \ :local Result [ /tool/fetch check-certificate=yes-without-crl \
http-header-field=({ $FetchUserAgent }) $Url output=user as-value ]; http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data"); :set ChangeLogCode ($Result->"data");
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed fetching news, changes and migration!") false; $LogPrint warning $0 ("Failed fetching news, changes and migration!");
} }
:if ([ :len $ChangeLogCode ] > 0) do={ :if ([ :len $ChangeLogCode ] > 0) do={
@ -1108,10 +1121,10 @@
:do { :do {
[ :parse $ChangeLogCode ]; [ :parse $ChangeLogCode ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("The changelog failed to run!") false; $LogPrint warning $0 ("The changelog failed to run!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false; $LogPrint warning $0 ("The changelog failed syntax validation!");
} }
} }
@ -1120,14 +1133,14 @@
:local Migration ($GlobalConfigMigration->[ :tostr $I ]); :local Migration ($GlobalConfigMigration->[ :tostr $I ]);
:if ([ :typeof $Migration ] = "str") do={ :if ([ :typeof $Migration ] = "str") do={
:if ([ $ValidateSyntax $Migration ] = true) do={ :if ([ $ValidateSyntax $Migration ] = true) do={
$LogPrintExit2 info $0 ("Applying migration for change " . $I . ": " . $Migration) false; $LogPrint info $0 ("Applying migration for change " . $I . ": " . $Migration);
:do { :do {
[ :parse $Migration ]; [ :parse $Migration ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed to run!") false; $LogPrint warning $0 ("Migration code for change " . $I . " failed to run!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed syntax validation!") false; $LogPrint warning $0 ("Migration code for change " . $I . " failed syntax validation!");
} }
} }
} }
@ -1136,7 +1149,7 @@
:local NotificationMessage ("The configuration version on " . $Identity . " increased " . \ :local NotificationMessage ("The configuration version on " . $Identity . " increased " . \
"to " . $ExpectedConfigVersion . ", current configuration may need modification. " . \ "to " . $ExpectedConfigVersion . ", current configuration may need modification. " . \
"Please review and update global-config-overlay, then re-run global-config."); "Please review and update global-config-overlay, then re-run global-config.");
$LogPrintExit2 info $0 ($NotificationMessage) false; $LogPrint info $0 ($NotificationMessage);
:if ([ :len $GlobalConfigChanges ] > 0) do={ :if ([ :len $GlobalConfigChanges ] > 0) do={
:set NotificationMessage ($NotificationMessage . "\n\nChanges:"); :set NotificationMessage ($NotificationMessage . "\n\nChanges:");
@ -1144,7 +1157,7 @@
:local Change ($GlobalConfigChanges->[ :tostr $I ]); :local Change ($GlobalConfigChanges->[ :tostr $I ]);
:set NotificationMessage ($NotificationMessage . "\n " . \ :set NotificationMessage ($NotificationMessage . "\n " . \
[ $SymbolForNotification "pushpin" "*" ] . $Change); [ $SymbolForNotification "pushpin" "*" ] . $Change);
$LogPrintExit2 info $0 ("Change " . $I . ": " . $Change) false; $LogPrint info $0 ("Change " . $I . ": " . $Change);
} }
} else={ } else={
:set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available."); :set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available.");
@ -1178,7 +1191,7 @@
:global GetRandom20CharAlNum; :global GetRandom20CharAlNum;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ScriptLockOrder; :global ScriptLockOrder;
:if ([ :typeof $ScriptLockOrder ] = "nothing") do={ :if ([ :typeof $ScriptLockOrder ] = "nothing") do={
@ -1264,15 +1277,17 @@
} }
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 error $0 ("A script named '" . $Script . "' does not exist!") true; $LogPrint error $0 ("A script named '" . $Script . "' does not exist!");
:error false;
} }
:if ([ $JobCount $Script ] = 0) do={ :if ([ $JobCount $Script ] = 0) do={
$LogPrintExit2 error $0 ("No script '" . $Script . "' is running!") true; $LogPrint error $0 ("No script '" . $Script . "' is running!");
:error false;
} }
:if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={ :if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={
$LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false; $LogPrint error $0 ("More tickets than running scripts '" . $Script . "', resetting!");
:set ($ScriptLockOrder->$Script) ({}); :set ($ScriptLockOrder->$Script) ({});
/system/script/job/remove [ find where script=$Script ]; /system/script/job/remove [ find where script=$Script ];
} }
@ -1293,8 +1308,8 @@
} }
$RemoveTicket $Script $MyTicket; $RemoveTicket $Script $MyTicket;
$LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \ $LogPrint info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \
" and timed out waiting for lock" "" ] . "...") false; " and timed out waiting for lock" "" ] . "...");
:return false; :return false;
} }
@ -1529,10 +1544,10 @@
:do { :do {
/system/script/run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.") false; $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.");
} }
} else={ } else={
$LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.") false; $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.");
} }
} }

View file

@ -17,7 +17,7 @@
:global GpsTrackUrl; :global GpsTrackUrl;
:global Identity; :global Identity;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:global WaitFullyConnected; :global WaitFullyConnected;
@ -38,13 +38,13 @@
"\"lon\":\"" . ($Gps->"longitude") . "\"," . \ "\"lon\":\"" . ($Gps->"longitude") . "\"," . \
"\"identity\":\"" . $Identity . "\"" . \ "\"identity\":\"" . $Identity . "\"" . \
"}") as-value; "}") as-value;
$LogPrintExit2 debug $ScriptName ("Sending GPS data in " . $CoordinateFormat . " format: " . \ $LogPrint debug $ScriptName ("Sending GPS data in " . $CoordinateFormat . " format: " . \
"lat: " . ($Gps->"latitude") . " " . \ "lat: " . ($Gps->"latitude") . " " . \
"lon: " . ($Gps->"longitude")) false; "lon: " . ($Gps->"longitude"));
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Failed sending GPS data!") false; $LogPrint warning $ScriptName ("Failed sending GPS data!");
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("GPS data not valid.") false; $LogPrint debug $ScriptName ("GPS data not valid.");
} }
} on-error={ } } on-error={ }

View file

@ -18,7 +18,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -41,8 +41,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \ :foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \
mac-address=($ClientVal->"mac-address") ] do={ mac-address=($ClientVal->"mac-address") ] do={
:if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={ :if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" connected to WPA, making lease static.") false; " connected to WPA, making lease static.");
/ip/dhcp-server/lease/make-static $Lease; /ip/dhcp-server/lease/make-static $Lease;
/ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease; /ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease;
} }
@ -54,8 +54,8 @@
:local ClientVal [ /caps-man/access-list/get $Client ]; :local ClientVal [ /caps-man/access-list/get $Client ];
:if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \ :if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \
mac-address=($ClientVal->"mac-address") ] ] = 0) do={ mac-address=($ClientVal->"mac-address") ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" did not connect to WPA, removing from access list.") false; " did not connect to WPA, removing from access list.");
/caps-man/access-list/remove $Client; /caps-man/access-list/remove $Client;
} }
} }
@ -64,8 +64,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \ :foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \
server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={ server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={
:local LeaseVal [ /ip/dhcp-server/lease/get $Lease ]; :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \
" was not seen for " . ($LeaseVal->"last-seen") . ", removing.") false; " was not seen for " . ($LeaseVal->"last-seen") . ", removing.");
/caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ /caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \
mac-address=($LeaseVal->"mac-address") ]; mac-address=($LeaseVal->"mac-address") ];
/ip/dhcp-server/lease/remove $Lease; /ip/dhcp-server/lease/remove $Lease;

View file

@ -19,7 +19,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -44,8 +44,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \ :foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \
mac-address=($ClientVal->"mac-address") ] do={ mac-address=($ClientVal->"mac-address") ] do={
:if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={ :if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" connected to WPA, making lease static.") false; " connected to WPA, making lease static.");
/ip/dhcp-server/lease/make-static $Lease; /ip/dhcp-server/lease/make-static $Lease;
/ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease; /ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease;
} }
@ -59,8 +59,8 @@
:local ClientVal [ /interface/wifi/access-list/get $Client ]; :local ClientVal [ /interface/wifi/access-list/get $Client ];
:if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \ :if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \
mac-address=($ClientVal->"mac-address") ] ] = 0) do={ mac-address=($ClientVal->"mac-address") ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" did not connect to WPA, removing from access list.") false; " did not connect to WPA, removing from access list.");
/caps-man/access-list/remove $Client; /caps-man/access-list/remove $Client;
/interface/wifi/access-list/remove $Client; /interface/wifi/access-list/remove $Client;
} }
@ -70,8 +70,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \ :foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \
server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={ server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={
:local LeaseVal [ /ip/dhcp-server/lease/get $Lease ]; :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \
" was not seen for " . ($LeaseVal->"last-seen") . ", removing.") false; " was not seen for " . ($LeaseVal->"last-seen") . ", removing.");
/caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ /caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \
/interface/wifi/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ /interface/wifi/access-list/remove [ find where comment~"^hotspot-to-wpa:" \
mac-address=($LeaseVal->"mac-address") ]; mac-address=($LeaseVal->"mac-address") ];

View file

@ -18,7 +18,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -41,8 +41,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \ :foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \
mac-address=($ClientVal->"mac-address") ] do={ mac-address=($ClientVal->"mac-address") ] do={
:if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={ :if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" connected to WPA, making lease static.") false; " connected to WPA, making lease static.");
/ip/dhcp-server/lease/make-static $Lease; /ip/dhcp-server/lease/make-static $Lease;
/ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease; /ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease;
} }
@ -54,8 +54,8 @@
:local ClientVal [ /interface/wifi/access-list/get $Client ]; :local ClientVal [ /interface/wifi/access-list/get $Client ];
:if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \ :if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \
mac-address=($ClientVal->"mac-address") ] ] = 0) do={ mac-address=($ClientVal->"mac-address") ] ] = 0) do={
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($ClientVal->"mac-address") . \
" did not connect to WPA, removing from access list.") false; " did not connect to WPA, removing from access list.");
/interface/wifi/access-list/remove $Client; /interface/wifi/access-list/remove $Client;
} }
} }
@ -64,8 +64,8 @@
:foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \ :foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \
server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={ server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={
:local LeaseVal [ /ip/dhcp-server/lease/get $Lease ]; :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
$LogPrintExit2 info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \ $LogPrint info $ScriptName ("Client with mac address " . ($LeaseVal->"mac-address") . \
" was not seen for " . ($LeaseVal->"last-seen") . ", removing.") false; " was not seen for " . ($LeaseVal->"last-seen") . ", removing.");
/interface/wifi/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ /interface/wifi/access-list/remove [ find where comment~"^hotspot-to-wpa:" \
mac-address=($LeaseVal->"mac-address") ]; mac-address=($LeaseVal->"mac-address") ];
/ip/dhcp-server/lease/remove $Lease; /ip/dhcp-server/lease/remove $Lease;

View file

@ -17,7 +17,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -29,7 +29,8 @@
} }
:if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; $LogPrint error $ScriptName ("This script is supposed to run from hotspot on login.");
:error false;
} }
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
@ -42,28 +43,28 @@
:if ([ :len [ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={ :if ([ :len [ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={
/caps-man/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes; /caps-man/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.");
} }
:local PlaceBefore ([ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0); :local PlaceBefore ([ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0);
:if ([ :len [ /caps-man/access-list/find where \ :if ([ :len [ /caps-man/access-list/find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={ comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={
/caps-man/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore; /caps-man/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore;
$LogPrintExit2 warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.") false; $LogPrint warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.");
} }
:local Template [ /caps-man/access-list/get ([ find where \ :local Template [ /caps-man/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ]; comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ];
:if ($Template->"action" = "reject") do={ :if ($Template->"action" = "reject") do={
$LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; $LogPrint info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.");
:error true; :error true;
} }
# allow login page to load # allow login page to load
:delay 1s; :delay 1s;
$LogPrintExit2 info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $UserName . ").") false; " (user " . $UserName . ").");
/caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ];
/caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \
mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \ mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \

View file

@ -18,7 +18,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -30,7 +30,8 @@
} }
:if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; $LogPrint error $ScriptName ("This script is supposed to run from hotspot on login.");
:error false;
} }
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
@ -45,7 +46,7 @@
:if ([ :len [ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={ :if ([ :len [ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={
/caps-man/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes; /caps-man/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes;
/interface/wifi/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes; /interface/wifi/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.");
} }
:local PlaceBefore ([ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0); :local PlaceBefore ([ /caps-man/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0);
:local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0); :local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0);
@ -55,22 +56,22 @@
comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={ comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={
/caps-man/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore; /caps-man/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore;
/interface/wifi/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore; /interface/wifi/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore;
$LogPrintExit2 warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.") false; $LogPrint warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.");
} }
:local Template [ /caps-man/access-list/get ([ find where \ :local Template [ /caps-man/access-list/get ([ find where \
:local Template [ /interface/wifi/access-list/get ([ find where \ :local Template [ /interface/wifi/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ]; comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ];
:if ($Template->"action" = "reject") do={ :if ($Template->"action" = "reject") do={
$LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; $LogPrint info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.");
:error true; :error true;
} }
# allow login page to load # allow login page to load
:delay 1s; :delay 1s;
$LogPrintExit2 info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $UserName . ").") false; " (user " . $UserName . ").");
/caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /caps-man/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ];
/interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ];
/caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ /caps-man/access-list/add private-passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \

View file

@ -17,7 +17,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -29,7 +29,8 @@
} }
:if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; $LogPrint error $ScriptName ("This script is supposed to run from hotspot on login.");
:error false;
} }
:local Date [ /system/clock/get date ]; :local Date [ /system/clock/get date ];
@ -42,28 +43,28 @@
:if ([ :len [ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={ :if ([ :len [ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ] ] = 0) do={
/interface/wifi/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes; /interface/wifi/access-list/add comment="--- hotspot-to-wpa above ---" disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.") false; $LogPrint warning $ScriptName ("Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'.");
} }
:local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0); :local PlaceBefore ([ /interface/wifi/access-list/find where comment="--- hotspot-to-wpa above ---" disabled ]->0);
:if ([ :len [ /interface/wifi/access-list/find where \ :if ([ :len [ /interface/wifi/access-list/find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={ comment=("hotspot-to-wpa template " . $Hotspot) disabled ] ] = 0) do={
/interface/wifi/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore; /interface/wifi/access-list/add comment=("hotspot-to-wpa template " . $Hotspot) disabled=yes place-before=$PlaceBefore;
$LogPrintExit2 warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.") false; $LogPrint warning $ScriptName ("Added template in access-list for hotspot '" . $Hotspot . "'.");
} }
:local Template [ /interface/wifi/access-list/get ([ find where \ :local Template [ /interface/wifi/access-list/get ([ find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ]; comment=("hotspot-to-wpa template " . $Hotspot) disabled ]->0) ];
:if ($Template->"action" = "reject") do={ :if ($Template->"action" = "reject") do={
$LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; $LogPrint info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.");
:error true; :error true;
} }
# allow login page to load # allow login page to load
:delay 1s; :delay 1s;
$LogPrintExit2 info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \ $LogPrint info $ScriptName ("Adding/updating access-list entry for mac address " . $MacAddress . \
" (user " . $UserName . ").") false; " (user " . $UserName . ").");
/interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ]; /interface/wifi/access-list/remove [ find where mac-address=$MacAddress comment~"^hotspot-to-wpa: " ];
/interface/wifi/access-list/add passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \ /interface/wifi/access-list/add passphrase=($UserVal->"password") ssid-regexp="-wpa\$" \
mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \ mac-address=$MacAddress comment=("hotspot-to-wpa: " . $UserName . ", " . $MacAddress . ", " . $Date) \

View file

@ -22,7 +22,7 @@
:global CharacterReplace; :global CharacterReplace;
:global EscapeForRegEx; :global EscapeForRegEx;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -38,7 +38,7 @@
:if ([ :len [ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ] ] = 0) do={ :if ([ :len [ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ] ] = 0) do={
/ip/dns/static/add name=$CommentString type=NXDOMAIN disabled=yes; /ip/dns/static/add name=$CommentString type=NXDOMAIN disabled=yes;
$LogPrintExit2 warning $ScriptName ("Added disabled static dns record with name '" . $CommentString . "'.") false; $LogPrint warning $ScriptName ("Added disabled static dns record with name '" . $CommentString . "'.");
} }
:local PlaceBefore ([ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ]->0); :local PlaceBefore ([ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ]->0);
@ -47,10 +47,10 @@
:local PeerId [ $CharacterReplace ($DnsRecordVal->"comment") $CommentPrefix "" ]; :local PeerId [ $CharacterReplace ($DnsRecordVal->"comment") $CommentPrefix "" ];
:if ([ :len [ /ip/ipsec/active-peers/find where id~("^(CN=)?" . [ $EscapeForRegEx $PeerId ] . "\$") \ :if ([ :len [ /ip/ipsec/active-peers/find where id~("^(CN=)?" . [ $EscapeForRegEx $PeerId ] . "\$") \
dynamic-address=($DnsRecordVal->"address") ] ] > 0) do={ dynamic-address=($DnsRecordVal->"address") ] ] > 0) do={
$LogPrintExit2 debug $ScriptName ("Peer " . $PeerId . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting DNS entry.") false; $LogPrint debug $ScriptName ("Peer " . $PeerId . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting DNS entry.");
} else={ } else={
:local Found false; :local Found false;
$LogPrintExit2 info $ScriptName ("Peer " . $PeerId . " (" . $DnsRecordVal->"name" . ") has gone, deleting DNS entry.") false; $LogPrint info $ScriptName ("Peer " . $PeerId . " (" . $DnsRecordVal->"name" . ") has gone, deleting DNS entry.");
/ip/dns/static/remove $DnsRecord; /ip/dns/static/remove $DnsRecord;
} }
} }
@ -66,13 +66,13 @@
:if ([ :len $DnsRecord ] > 0) do={ :if ([ :len $DnsRecord ] > 0) do={
:local DnsIp [ /ip/dns/static/get $DnsRecord address ]; :local DnsIp [ /ip/dns/static/get $DnsRecord address ];
:if ($DnsIp = $PeerVal->"dynamic-address") do={ :if ($DnsIp = $PeerVal->"dynamic-address") do={
$LogPrintExit2 debug $ScriptName ("DNS entry for " . $Fqdn . " does not need updating.") false; $LogPrint debug $ScriptName ("DNS entry for " . $Fqdn . " does not need updating.");
} else={ } else={
$LogPrintExit2 info $ScriptName ("Replacing DNS entry for " . $Fqdn . ", new address is " . $PeerVal->"dynamic-address" . ".") false; $LogPrint info $ScriptName ("Replacing DNS entry for " . $Fqdn . ", new address is " . $PeerVal->"dynamic-address" . ".");
/ip/dns/static/set name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment $DnsRecord; /ip/dns/static/set name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment $DnsRecord;
} }
} else={ } else={
$LogPrintExit2 info $ScriptName ("Adding new DNS entry for " . $Fqdn . ", address is " . $PeerVal->"dynamic-address" . ".") false; $LogPrint info $ScriptName ("Adding new DNS entry for " . $Fqdn . ", address is " . $PeerVal->"dynamic-address" . ".");
/ip/dns/static/add name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore; /ip/dns/static/add name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
} }
} }

View file

@ -14,7 +14,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -25,19 +25,20 @@
} }
:if ([ :typeof $PdPrefix ] = "nothing") do={ :if ([ :typeof $PdPrefix ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from ipv6 dhcp-client.") true; $LogPrint error $ScriptName ("This script is supposed to run from ipv6 dhcp-client.");
:error false;
} }
:local Pool [ /ipv6/pool/get [ find where prefix=$PdPrefix ] name ]; :local Pool [ /ipv6/pool/get [ find where prefix=$PdPrefix ] name ];
:if ([ :len [ /ipv6/firewall/address-list/find where comment=("ipv6-pool-" . $Pool) ] ] = 0) do={ :if ([ :len [ /ipv6/firewall/address-list/find where comment=("ipv6-pool-" . $Pool) ] ] = 0) do={
/ipv6/firewall/address-list/add list=("ipv6-pool-" . $Pool) address=:: comment=("ipv6-pool-" . $Pool); /ipv6/firewall/address-list/add list=("ipv6-pool-" . $Pool) address=:: comment=("ipv6-pool-" . $Pool);
$LogPrintExit2 warning $ScriptName ("Added ipv6 address list entry for ipv6-pool-" . $Pool) false; $LogPrint warning $ScriptName ("Added ipv6 address list entry for ipv6-pool-" . $Pool);
} }
:local AddrList [ /ipv6/firewall/address-list/find where comment=("ipv6-pool-" . $Pool) ]; :local AddrList [ /ipv6/firewall/address-list/find where comment=("ipv6-pool-" . $Pool) ];
:local OldPrefix [ /ipv6/firewall/address-list/get ($AddrList->0) address ]; :local OldPrefix [ /ipv6/firewall/address-list/get ($AddrList->0) address ];
:if ($OldPrefix != $PdPrefix) do={ :if ($OldPrefix != $PdPrefix) do={
$LogPrintExit2 info $ScriptName ("Updating IPv6 address list with new IPv6 prefix " . $PdPrefix) false; $LogPrint info $ScriptName ("Updating IPv6 address list with new IPv6 prefix " . $PdPrefix);
/ipv6/firewall/address-list/set address=$PdPrefix $AddrList; /ipv6/firewall/address-list/set address=$PdPrefix $AddrList;
# give the interfaces a moment to receive their addresses # give the interfaces a moment to receive their addresses
@ -56,12 +57,12 @@
:local Address ($ListEntryVal->"address"); :local Address ($ListEntryVal->"address");
:local Address ($Prefix | ([ :toip6 [ :pick $Address 0 [ :find $Address "/128" ] ] ] & ::ffff:ffff:ffff:ffff)); :local Address ($Prefix | ([ :toip6 [ :pick $Address 0 [ :find $Address "/128" ] ] ] & ::ffff:ffff:ffff:ffff));
$LogPrintExit2 info $ScriptName ("Updating IPv6 address list with new IPv6 host address " . $Address . \ $LogPrint info $ScriptName ("Updating IPv6 address list with new IPv6 host address " . $Address . \
" from interface " . ($Comment->"interface")) false; " from interface " . ($Comment->"interface"));
/ipv6/firewall/address-list/set address=$Address $ListEntry; /ipv6/firewall/address-list/set address=$Address $ListEntry;
} else={ } else={
$LogPrintExit2 info $ScriptName ("Updating IPv6 address list with new IPv6 prefix " . $Prefix . \ $LogPrint info $ScriptName ("Updating IPv6 address list with new IPv6 prefix " . $Prefix . \
" from interface " . ($Comment->"interface")) false; " from interface " . ($Comment->"interface"));
/ipv6/firewall/address-list/set address=$Prefix $ListEntry; /ipv6/firewall/address-list/set address=$Prefix $ListEntry;
} }
} }
@ -77,8 +78,8 @@
:set Prefix ([ :toip6 [ :pick $Prefix 0 [ :find $Prefix "/64" ] ] ] & ffff:ffff:ffff:ffff::); :set Prefix ([ :toip6 [ :pick $Prefix 0 [ :find $Prefix "/64" ] ] ] & ffff:ffff:ffff:ffff::);
:local Address ($Prefix | ([ :toip6 ($RecordVal->"address") ] & ::ffff:ffff:ffff:ffff)); :local Address ($Prefix | ([ :toip6 ($RecordVal->"address") ] & ::ffff:ffff:ffff:ffff));
$LogPrintExit2 info $ScriptName ("Updating DNS record for " . ($RecordVal->"name") . \ $LogPrint info $ScriptName ("Updating DNS record for " . ($RecordVal->"name") . \
($RecordVal->"regexp") . " to " . $Address) false; ($RecordVal->"regexp") . " to " . $Address);
/ip/dns/static/set address=$Address $Record; /ip/dns/static/set address=$Address $Record;
} }
} }

View file

@ -16,7 +16,7 @@
:global Grep; :global Grep;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -24,18 +24,19 @@
[ :typeof $leaseActMAC ] = "nothing" || \ [ :typeof $leaseActMAC ] = "nothing" || \
[ :typeof $leaseServerName ] = "nothing" || \ [ :typeof $leaseServerName ] = "nothing" || \
[ :typeof $leaseBound ] = "nothing") do={ [ :typeof $leaseBound ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from ip dhcp-server.") true; $LogPrint error $ScriptName ("This script is supposed to run from ip dhcp-server.");
:error false;
} }
$LogPrintExit2 debug $ScriptName ("DHCP Server " . $leaseServerName . " " . [ $IfThenElse ($leaseBound = 0) \ $LogPrint debug $ScriptName ("DHCP Server " . $leaseServerName . " " . [ $IfThenElse ($leaseBound = 0) \
"de" "" ] . "assigned lease " . $leaseActIP . " to " . $leaseActMAC) false; "de" "" ] . "assigned lease " . $leaseActIP . " to " . $leaseActMAC);
:if ([ $ScriptLock $ScriptName 10 ] = false) do={ :if ([ $ScriptLock $ScriptName 10 ] = false) do={
:error false; :error false;
} }
:if ([ :len [ /system/script/job/find where script=$ScriptName ] ] > 1) do={ :if ([ :len [ /system/script/job/find where script=$ScriptName ] ] > 1) do={
$LogPrintExit2 debug $ScriptName ("More invocations are waiting, exiting early.") false; $LogPrint debug $ScriptName ("More invocations are waiting, exiting early.");
:error true; :error true;
} }
@ -49,10 +50,10 @@
:foreach Order,Script in=$RunOrder do={ :foreach Order,Script in=$RunOrder do={
:do { :do {
$LogPrintExit2 debug $ScriptName ("Running script with order " . $Order . ": " . $Script) false; $LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script);
/system/script/run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Running script '" . $Script . "' failed!") false; $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed!");
} }
} }
} on-error={ } } on-error={ }

View file

@ -26,7 +26,7 @@
:global HexToNum; :global HexToNum;
:global IfThenElse; :global IfThenElse;
:global LogForwardFilterLogForwarding; :global LogForwardFilterLogForwarding;
:global LogPrintExit2; :global LogPrint;
:global MAX; :global MAX;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
@ -42,7 +42,7 @@
:if ($LogForwardRateLimit > 30) do={ :if ($LogForwardRateLimit > 30) do={
:set LogForwardRateLimit ($LogForwardRateLimit - 1); :set LogForwardRateLimit ($LogForwardRateLimit - 1);
$LogPrintExit2 info $ScriptName ("Rate limit in action, not forwarding logs, if any!") false; $LogPrint info $ScriptName ("Rate limit in action, not forwarding logs, if any!");
:error false; :error false;
} }

View file

@ -12,7 +12,7 @@
:local BridgePortTo [ :tostr $1 ]; :local BridgePortTo [ :tostr $1 ];
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:local InterfaceReEnable ({}); :local InterfaceReEnable ({});
@ -24,21 +24,22 @@
:if ($BridgeDefault = "dhcp-client") do={ :if ($BridgeDefault = "dhcp-client") do={
:if ([ :len $DHCPClient ] != 1) do={ :if ([ :len $DHCPClient ] != 1) do={
$LogPrintExit2 warning $0 ([ $IfThenElse ([ :len $DHCPClient ] = 0) "Missing" "Duplicate" ] . \ $LogPrint warning $0 ([ $IfThenElse ([ :len $DHCPClient ] = 0) "Missing" "Duplicate" ] . \
" dhcp client configuration for interface " . $BridgePortVal->"interface" . "!") true; " dhcp client configuration for interface " . $BridgePortVal->"interface" . "!");
:error false;
} }
:local DHCPClientDisabled [ /ip/dhcp-client/get $DHCPClient disabled ]; :local DHCPClientDisabled [ /ip/dhcp-client/get $DHCPClient disabled ];
:if ($BridgePortVal->"disabled" = false || $DHCPClientDisabled = true) do={ :if ($BridgePortVal->"disabled" = false || $DHCPClientDisabled = true) do={
$LogPrintExit2 info $0 ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.") false; $LogPrint info $0 ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.");
/interface/bridge/port/disable $BridgePort; /interface/bridge/port/disable $BridgePort;
:delay 200ms; :delay 200ms;
/ip/dhcp-client/enable $DHCPClient; /ip/dhcp-client/enable $DHCPClient;
} }
} else={ } else={
:if ($BridgePortVal->"disabled" = true || $BridgeDefault != $BridgePortVal->"bridge") do={ :if ($BridgePortVal->"disabled" = true || $BridgeDefault != $BridgePortVal->"bridge") do={
$LogPrintExit2 info $0 ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", changing to " . $BridgePortTo . \ $LogPrint info $0 ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", changing to " . $BridgePortTo . \
" bridge " . $BridgeDefault . ", disabling dhcp client.") false; " bridge " . $BridgeDefault . ", disabling dhcp client.");
:if ([ :len $DHCPClient ] = 1) do={ :if ([ :len $DHCPClient ] = 1) do={
/ip/dhcp-client/disable $DHCPClient; /ip/dhcp-client/disable $DHCPClient;
:delay 200ms; :delay 200ms;
@ -50,8 +51,8 @@
} }
/interface/bridge/port/set disabled=no bridge=$BridgeDefault $BridgePort; /interface/bridge/port/set disabled=no bridge=$BridgeDefault $BridgePort;
} else={ } else={
$LogPrintExit2 debug $0 ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . \ $LogPrint debug $0 ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . \
" bridge " . $BridgeDefault . ".") false; " bridge " . $BridgeDefault . ".");
} }
} }
} }
@ -59,7 +60,7 @@
} }
:if ([ :len $InterfaceReEnable ] > 0) do={ :if ([ :len $InterfaceReEnable ] > 0) do={
:delay 5s; :delay 5s;
$LogPrintExit2 info $0 ("Re-enabling interfaces...") false; $LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable; /interface/ethernet/enable $InterfaceReEnable;
} }
} }

View file

@ -12,7 +12,7 @@
:local ConfigTo [ :tostr $1 ]; :local ConfigTo [ :tostr $1 ];
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:local InterfaceReEnable ({}); :local InterfaceReEnable ({});
@ -24,13 +24,14 @@
:if ($Vlan = "dhcp-client") do={ :if ($Vlan = "dhcp-client") do={
:if ([ :len $DHCPClient ] != 1) do={ :if ([ :len $DHCPClient ] != 1) do={
$LogPrintExit2 warning $0 ([ $IfThenElse ([ :len $DHCPClient ] = 0) "Missing" "Duplicate" ] . \ $LogPrint warning $0 ([ $IfThenElse ([ :len $DHCPClient ] = 0) "Missing" "Duplicate" ] . \
" dhcp client configuration for interface " . $BridgePortVal->"interface" . "!") true; " dhcp client configuration for interface " . $BridgePortVal->"interface" . "!");
:error false;
} }
:local DHCPClientDisabled [ /ip/dhcp-client/get $DHCPClient disabled ]; :local DHCPClientDisabled [ /ip/dhcp-client/get $DHCPClient disabled ];
:if ($BridgePortVal->"disabled" = false || $DHCPClientDisabled = true) do={ :if ($BridgePortVal->"disabled" = false || $DHCPClientDisabled = true) do={
$LogPrintExit2 info $0 ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.") false; $LogPrint info $0 ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.");
/interface/bridge/port/disable $BridgePort; /interface/bridge/port/disable $BridgePort;
:delay 200ms; :delay 200ms;
/ip/dhcp-client/enable $DHCPClient; /ip/dhcp-client/enable $DHCPClient;
@ -41,12 +42,13 @@
:do { :do {
:set $Vlan ([ /interface/bridge/vlan/get [ find where comment=$Vlan ] vlan-ids ]->0); :set $Vlan ([ /interface/bridge/vlan/get [ find where comment=$Vlan ] vlan-ids ]->0);
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Could not find VLAN '" . $Vlan . "' for interface " . $BridgePortVal->"interface" . "!") true; $LogPrint warning $0 ("Could not find VLAN '" . $Vlan . "' for interface " . $BridgePortVal->"interface" . "!");
:error false;
} }
} }
:if ($BridgePortVal->"disabled" = true || $Vlan != $BridgePortVal->"pvid") do={ :if ($BridgePortVal->"disabled" = true || $Vlan != $BridgePortVal->"pvid") do={
$LogPrintExit2 info $0 ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", changing to " . $ConfigTo . \ $LogPrint info $0 ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", changing to " . $ConfigTo . \
" vlan " . $Vlan . [ $IfThenElse ($Vlan != $VlanName) (" (" . $VlanName . ")") ] . ", disabling dhcp client.") false; " vlan " . $Vlan . [ $IfThenElse ($Vlan != $VlanName) (" (" . $VlanName . ")") ] . ", disabling dhcp client.");
:if ([ :len $DHCPClient ] = 1) do={ :if ([ :len $DHCPClient ] = 1) do={
/ip/dhcp-client/disable $DHCPClient; /ip/dhcp-client/disable $DHCPClient;
:delay 200ms; :delay 200ms;
@ -58,8 +60,8 @@
} }
/interface/bridge/port/set disabled=no pvid=$Vlan $BridgePort; /interface/bridge/port/set disabled=no pvid=$Vlan $BridgePort;
} else={ } else={
$LogPrintExit2 debug $0 ("Interface " . $BridgePortVal->"interface" . " already connected to " . $ConfigTo . \ $LogPrint debug $0 ("Interface " . $BridgePortVal->"interface" . " already connected to " . $ConfigTo . \
" vlan " . $Vlan . ".") false; " vlan " . $Vlan . ".");
} }
} }
} }
@ -67,7 +69,7 @@
} }
:if ([ :len $InterfaceReEnable ] > 0) do={ :if ([ :len $InterfaceReEnable ] > 0) do={
:delay 5s; :delay 5s;
$LogPrintExit2 info $0 ("Re-enabling interfaces...") false; $LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable; /interface/ethernet/enable $InterfaceReEnable;
} }
} }

View file

@ -24,7 +24,7 @@
:global EitherOr; :global EitherOr;
:global IsDNSResolving; :global IsDNSResolving;
:global IsTimeSync; :global IsTimeSync;
:global LogPrintExit2; :global LogPrint;
:local AllDone true; :local AllDone true;
:local QueueLen [ :len $EmailQueue ]; :local QueueLen [ :len $EmailQueue ];
@ -35,23 +35,23 @@
} }
:if ([ /tool/e-mail/get last-status ] = "in-progress") do={ :if ([ /tool/e-mail/get last-status ] = "in-progress") do={
$LogPrintExit2 debug $0 ("Sending mail is currently in progress, not flushing.") false; $LogPrint debug $0 ("Sending mail is currently in progress, not flushing.");
:return false; :return false;
} }
:if ([ $IsTimeSync ] = false) do={ :if ([ $IsTimeSync ] = false) do={
$LogPrintExit2 debug $0 ("Time is not synced, not flushing.") false; $LogPrint debug $0 ("Time is not synced, not flushing.");
:return false; :return false;
} }
:local EMailSettings [ /tool/e-mail/get ]; :local EMailSettings [ /tool/e-mail/get ];
:if ([ :typeof [ :toip ($EMailSettings->"server") ] ] != "ip" && [ $IsDNSResolving ] = false) do={ :if ([ :typeof [ :toip ($EMailSettings->"server") ] ] != "ip" && [ $IsDNSResolving ] = false) do={
$LogPrintExit2 debug $0 ("Server address is a DNS name and resolving fails, not flushing.") false; $LogPrint debug $0 ("Server address is a DNS name and resolving fails, not flushing.");
:return false; :return false;
} }
:if ([ :len $Scheduler ] > 0 && $QueueLen = 0) do={ :if ([ :len $Scheduler ] > 0 && $QueueLen = 0) do={
$LogPrintExit2 warning $0 ("Flushing E-Mail messages from scheduler, but queue is empty.") false; $LogPrint warning $0 ("Flushing E-Mail messages from scheduler, but queue is empty.");
} }
/system/scheduler/set interval=([ $EitherOr $QueueLen 1 ] . "m") comment="Sending..." $Scheduler; /system/scheduler/set interval=([ $EitherOr $QueueLen 1 ] . "m") comment="Sending..." $Scheduler;
@ -64,7 +64,7 @@
:if ([ :len [ /file/find where name=$File ] ] = 1) do={ :if ([ :len [ /file/find where name=$File ] ] = 1) do={
:set Attach ($Attach, $File); :set Attach ($Attach, $File);
} else={ } else={
$LogPrintExit2 warning $0 ("File '" . $File . "' does not exist, can not attach.") false; $LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach.");
} }
} }
/tool/e-mail/send to=($Message->"to") cc=($Message->"cc") subject=($Message->"subject") \ /tool/e-mail/send to=($Message->"to") cc=($Message->"cc") subject=($Message->"subject") \

View file

@ -20,10 +20,10 @@
:global MatrixQueue; :global MatrixQueue;
:global IsFullyConnected; :global IsFullyConnected;
:global LogPrintExit2; :global LogPrint;
:if ([ $IsFullyConnected ] = false) do={ :if ([ $IsFullyConnected ] = false) do={
$LogPrintExit2 debug $0 ("System is not fully connected, not flushing.") false; $LogPrint debug $0 ("System is not fully connected, not flushing.");
:return false; :return false;
} }
@ -31,7 +31,7 @@
:local QueueLen [ :len $MatrixQueue ]; :local QueueLen [ :len $MatrixQueue ];
:if ([ :len [ /system/scheduler/find where name="_FlushMatrixQueue" ] ] > 0 && $QueueLen = 0) do={ :if ([ :len [ /system/scheduler/find where name="_FlushMatrixQueue" ] ] > 0 && $QueueLen = 0) do={
$LogPrintExit2 warning $0 ("Flushing Matrix messages from scheduler, but queue is empty.") false; $LogPrint warning $0 ("Flushing Matrix messages from scheduler, but queue is empty.");
} }
:foreach Id,Message in=$MatrixQueue do={ :foreach Id,Message in=$MatrixQueue do={
@ -45,7 +45,7 @@
$Message->"formatted" . "\" }") as-value; $Message->"formatted" . "\" }") as-value;
:set ($MatrixQueue->$Id); :set ($MatrixQueue->$Id);
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Sending queued Matrix message failed.") false; $LogPrint debug $0 ("Sending queued Matrix message failed.");
:set AllDone false; :set AllDone false;
} }
} }
@ -72,7 +72,7 @@
:global MatrixRoomOverride; :global MatrixRoomOverride;
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global SymbolForNotification; :global SymbolForNotification;
:local PrepareText do={ :local PrepareText do={
@ -134,7 +134,7 @@
"\"format\": \"org.matrix.custom.html\", \"formatted_body\": \"" . \ "\"format\": \"org.matrix.custom.html\", \"formatted_body\": \"" . \
$Formatted . "\" }") as-value; $Formatted . "\" }") as-value;
} on-error={ } on-error={
$LogPrintExit2 info $0 ("Failed sending Matrix notification! Queuing...") false; $LogPrint info $0 ("Failed sending Matrix notification! Queuing...");
:if ([ :typeof $MatrixQueue ] = "nothing") do={ :if ([ :typeof $MatrixQueue ] = "nothing") do={
:set MatrixQueue ({}); :set MatrixQueue ({});
@ -184,7 +184,7 @@
:local Pass [ :tostr $2 ]; :local Pass [ :tostr $2 ];
:global CharacterReplace; :global CharacterReplace;
:global LogPrintExit2; :global LogPrint;
:global ParseJson; :global ParseJson;
:global MatrixAccessToken; :global MatrixAccessToken;
@ -195,9 +195,10 @@
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data"); ("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data");
:set MatrixHomeServer ([ $ParseJson ([ $ParseJson [ $CharacterReplace $Data " " "" ] ]->"m.homeserver") ]->"base_url"); :set MatrixHomeServer ([ $ParseJson ([ $ParseJson [ $CharacterReplace $Data " " "" ] ]->"m.homeserver") ]->"base_url");
$LogPrintExit2 debug $0 ("Home server is: " . $MatrixHomeServer) false; $LogPrint debug $0 ("Home server is: " . $MatrixHomeServer);
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Failed getting home server!") true; $LogPrint error $0 ("Failed getting home server!");
:error false;
} }
:if ([ :pick $MatrixHomeServer 0 8 ] = "https://") do={ :if ([ :pick $MatrixHomeServer 0 8 ] = "https://") do={
@ -209,18 +210,20 @@
http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \ http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \
("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data"); ("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data");
:set MatrixAccessToken ([ $ParseJson $Data ]->"access_token"); :set MatrixAccessToken ([ $ParseJson $Data ]->"access_token");
$LogPrintExit2 debug $0 ("Access token is: " . $MatrixAccessToken) false; $LogPrint debug $0 ("Access token is: " . $MatrixAccessToken);
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Failed logging in (and getting access token)!") true; $LogPrint error $0 ("Failed logging in (and getting access token)!");
:error false;
} }
:do { :do {
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \ /system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \ ":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \
":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n"); ":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n");
$LogPrintExit2 info $0 ("Appended configuration to global-config-overlay. Now create and join a room, please!") false; $LogPrint info $0 ("Appended configuration to global-config-overlay. Now create and join a room, please!");
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Failed appending configuration to global-config-overlay!") true; $LogPrint error $0 ("Failed appending configuration to global-config-overlay!");
:error false;
} }
} }
@ -228,7 +231,7 @@
:set SetupMatrixJoinRoom do={ :set SetupMatrixJoinRoom do={
:global MatrixRoom [ :tostr $1 ]; :global MatrixRoom [ :tostr $1 ];
:global LogPrintExit2; :global LogPrint;
:global UrlEncode; :global UrlEncode;
:global MatrixAccessToken; :global MatrixAccessToken;
@ -240,16 +243,18 @@
http-method=post http-data="" \ http-method=post http-data="" \
("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \ ("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \
"/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value; "/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value;
$LogPrintExit2 debug $0 ("Joined the room.") false; $LogPrint debug $0 ("Joined the room.");
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Failed joining the room!") true; $LogPrint error $0 ("Failed joining the room!");
:error false;
} }
:do { :do {
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \ /system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
":global MatrixRoom \"" . $MatrixRoom . "\";\n"); ":global MatrixRoom \"" . $MatrixRoom . "\";\n");
$LogPrintExit2 info $0 ("Appended configuration to global-config-overlay. Please review and cleanup!") false; $LogPrint info $0 ("Appended configuration to global-config-overlay. Please review and cleanup!");
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Failed appending configuration to global-config-overlay!") true; $LogPrint error $0 ("Failed appending configuration to global-config-overlay!");
:error false;
} }
} }

View file

@ -18,10 +18,10 @@
:global NtfyMessageIDs; :global NtfyMessageIDs;
:global IsFullyConnected; :global IsFullyConnected;
:global LogPrintExit2; :global LogPrint;
:if ([ $IsFullyConnected ] = false) do={ :if ([ $IsFullyConnected ] = false) do={
$LogPrintExit2 debug $0 ("System is not fully connected, not flushing.") false; $LogPrint debug $0 ("System is not fully connected, not flushing.");
:return false; :return false;
} }
@ -29,7 +29,7 @@
:local QueueLen [ :len $NtfyQueue ]; :local QueueLen [ :len $NtfyQueue ];
:if ([ :len [ /system/scheduler/find where name="_FlushNtfyQueue" ] ] > 0 && $QueueLen = 0) do={ :if ([ :len [ /system/scheduler/find where name="_FlushNtfyQueue" ] ] > 0 && $QueueLen = 0) do={
$LogPrintExit2 warning $0 ("Flushing Ntfy messages from scheduler, but queue is empty.") false; $LogPrint warning $0 ("Flushing Ntfy messages from scheduler, but queue is empty.");
} }
:foreach Id,Message in=$NtfyQueue do={ :foreach Id,Message in=$NtfyQueue do={
@ -39,7 +39,7 @@
($Message->"url") http-header-field=($Message->"headers") http-data=($Message->"text") as-value; ($Message->"url") http-header-field=($Message->"headers") http-data=($Message->"text") as-value;
:set ($NtfyQueue->$Id); :set ($NtfyQueue->$Id);
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Sending queued Ntfy message failed.") false; $LogPrint debug $0 ("Sending queued Ntfy message failed.");
:set AllDone false; :set AllDone false;
} }
} }
@ -66,7 +66,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global EitherOr; :global EitherOr;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global SymbolForNotification; :global SymbolForNotification;
:global UrlEncode; :global UrlEncode;
@ -88,13 +88,14 @@
:do { :do {
:if ($NtfyServer = "ntfy.sh") do={ :if ($NtfyServer = "ntfy.sh") do={
:if ([ $CertificateAvailable "R3" ] = false) do={ :if ([ $CertificateAvailable "R3" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; $LogPrint warning $0 ("Downloading required certificate failed.");
:error false;
} }
} }
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \ /tool/fetch check-certificate=yes-without-crl output=none http-method=post \
$Url http-header-field=$Headers http-data=$Text as-value; $Url http-header-field=$Headers http-data=$Text as-value;
} on-error={ } on-error={
$LogPrintExit2 info $0 ("Failed sending ntfy notification! Queuing...") false; $LogPrint info $0 ("Failed sending ntfy notification! Queuing...");
:if ([ :typeof $NtfyQueue ] = "nothing") do={ :if ([ :typeof $NtfyQueue ] = "nothing") do={
:set NtfyQueue ({}); :set NtfyQueue ({});

View file

@ -18,12 +18,12 @@
:global TelegramMessageIDs; :global TelegramMessageIDs;
:global IsFullyConnected; :global IsFullyConnected;
:global LogPrintExit2; :global LogPrint;
:global ParseJson; :global ParseJson;
:global UrlEncode; :global UrlEncode;
:if ([ $IsFullyConnected ] = false) do={ :if ([ $IsFullyConnected ] = false) do={
$LogPrintExit2 debug $0 ("System is not fully connected, not flushing.") false; $LogPrint debug $0 ("System is not fully connected, not flushing.");
:return false; :return false;
} }
@ -31,7 +31,7 @@
:local QueueLen [ :len $TelegramQueue ]; :local QueueLen [ :len $TelegramQueue ];
:if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] > 0 && $QueueLen = 0) do={ :if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] > 0 && $QueueLen = 0) do={
$LogPrintExit2 warning $0 ("Flushing Telegram messages from scheduler, but queue is empty.") false; $LogPrint warning $0 ("Flushing Telegram messages from scheduler, but queue is empty.");
} }
:foreach Id,Message in=$TelegramQueue do={ :foreach Id,Message in=$TelegramQueue do={
@ -45,7 +45,7 @@
:set ($TelegramQueue->$Id); :set ($TelegramQueue->$Id);
:set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1; :set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1;
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Sending queued Telegram message failed.") false; $LogPrint debug $0 ("Sending queued Telegram message failed.");
:set AllDone false; :set AllDone false;
} }
} }
@ -74,7 +74,7 @@
:global CharacterReplace; :global CharacterReplace;
:global EitherOr; :global EitherOr;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ParseJson; :global ParseJson;
:global SymbolForNotification; :global SymbolForNotification;
:global UrlEncode; :global UrlEncode;
@ -136,7 +136,8 @@
:do { :do {
:if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={ :if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; $LogPrint warning $0 ("Downloading required certificate failed.");
:error false;
} }
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \
("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \
@ -145,7 +146,7 @@
"&parse_mode=MarkdownV2&text=" . [ $UrlEncode $Text ]) as-value ]->"data"); "&parse_mode=MarkdownV2&text=" . [ $UrlEncode $Text ]) as-value ]->"data");
:set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1; :set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1;
} on-error={ } on-error={
$LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false; $LogPrint info $0 ("Failed sending telegram notification! Queuing...");
:if ([ :typeof $TelegramQueue ] = "nothing") do={ :if ([ :typeof $TelegramQueue ] = "nothing") do={
:set TelegramQueue ({}); :set TelegramQueue ({});

View file

@ -15,13 +15,14 @@
:global ScriptRunOnceBaseUrl; :global ScriptRunOnceBaseUrl;
:global ScriptRunOnceUrlSuffix; :global ScriptRunOnceUrlSuffix;
:global LogPrintExit2; :global LogPrint;
:global ValidateSyntax; :global ValidateSyntax;
:foreach Script in=$Scripts do={ :foreach Script in=$Scripts do={
:if (!($Script ~ "^(ftp|https?|sftp)://")) do={ :if (!($Script ~ "^(ftp|https?|sftp)://")) do={
:if ([ :len $ScriptRunOnceBaseUrl ] = 0) do={ :if ([ :len $ScriptRunOnceBaseUrl ] = 0) do={
$LogPrintExit2 warning $0 ("Script '" . $Script . "' is not an url and base url is not available.") true; $LogPrint warning $0 ("Script '" . $Script . "' is not an url and base url is not available.");
:error false;
} }
:set Script ($ScriptRunOnceBaseUrl . $Script . ".rsc" . $ScriptRunOnceUrlSuffix); :set Script ($ScriptRunOnceBaseUrl . $Script . ".rsc" . $ScriptRunOnceUrlSuffix);
} }
@ -30,19 +31,19 @@
:do { :do {
:set Source ([ /tool/fetch check-certificate=yes-without-crl $Script output=user as-value ]->"data"); :set Source ([ /tool/fetch check-certificate=yes-without-crl $Script output=user as-value ]->"data");
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed fetching script '" . $Script . "'!") false; $LogPrint warning $0 ("Failed fetching script '" . $Script . "'!");
} }
:if ([ :len $Source ] > 0) do={ :if ([ :len $Source ] > 0) do={
:if ([ $ValidateSyntax $Source ] = true) do={ :if ([ $ValidateSyntax $Source ] = true) do={
:do { :do {
$LogPrintExit2 info $0 ("Running script '" . $Script . "' now.") false; $LogPrint info $0 ("Running script '" . $Script . "' now.");
[ :parse $Source ]; [ :parse $Source ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("The script '" . $Script . "' failed to run!") false; $LogPrint warning $0 ("The script '" . $Script . "' failed to run!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("The script '" . $Script . "' failed syntax validation!") false; $LogPrint warning $0 ("The script '" . $Script . "' failed syntax validation!");
} }
} }
} }

View file

@ -18,32 +18,36 @@
:global CharacterReplace; :global CharacterReplace;
:global GetRandom20CharAlNum; :global GetRandom20CharAlNum;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global WaitForFile; :global WaitForFile;
:if ([ :len $Key ] = 0 || [ :len $User ] = 0) do={ :if ([ :len $Key ] = 0 || [ :len $User ] = 0) do={
$LogPrintExit2 warning $0 ("Missing argument(s), please pass key and user!") true; $LogPrint warning $0 ("Missing argument(s), please pass key and user!");
:error false;
} }
:if ([ :len [ /user/find where name=$User ] ] = 0) do={ :if ([ :len [ /user/find where name=$User ] ] = 0) do={
$LogPrintExit2 warning $0 ("User '" . $User . "' does not exist.") true; $LogPrint warning $0 ("User '" . $User . "' does not exist.");
:error false;
} }
:local KeyVal [ :toarray [ $CharacterReplace $Key " " "," ] ]; :local KeyVal [ :toarray [ $CharacterReplace $Key " " "," ] ];
:if (!($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa")) do={ :if (!($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa")) do={
$LogPrintExit2 warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.") true; $LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.");
:error false;
} }
:if ([ $MkDir "tmpfs/ssh-keys-import" ] = false) do={ :if ([ $MkDir "tmpfs/ssh-keys-import" ] = false) do={
$LogPrintExit2 warning $0 ("Creating directory 'tmpfs/ssh-keys-import' failed!") true; $LogPrint warning $0 ("Creating directory 'tmpfs/ssh-keys-import' failed!");
:error false;
} }
:local FingerPrintMD5 [ :convert from=base64 transform=md5 to=hex ($KeyVal->1) ]; :local FingerPrintMD5 [ :convert from=base64 transform=md5 to=hex ($KeyVal->1) ];
:if ([ :len [ /user/ssh-keys/find where user=$User key-owner~("\\bmd5=" . $FingerPrintMD5 . "\\b") ] ] > 0) do={ :if ([ :len [ /user/ssh-keys/find where user=$User key-owner~("\\bmd5=" . $FingerPrintMD5 . "\\b") ] ] > 0) do={
$LogPrintExit2 warning $0 ("The ssh public key (MD5:" . $FingerPrintMD5 . \ $LogPrint warning $0 ("The ssh public key (MD5:" . $FingerPrintMD5 . \
") is already available for user '" . $User . "'.") false; ") is already available for user '" . $User . "'.");
:return false; :return false;
} }
@ -53,10 +57,11 @@
:do { :do {
/user/ssh-keys/import public-key-file=$FileName user=$User; /user/ssh-keys/import public-key-file=$FileName user=$User;
$LogPrintExit2 info $0 ("Imported ssh public key (" . $KeyVal->2 . ", " . $KeyVal->0 . ", " . \ $LogPrint info $0 ("Imported ssh public key (" . $KeyVal->2 . ", " . $KeyVal->0 . ", " . \
"MD5:" . $FingerPrintMD5 . ") for user '" . $User . "'.") false; "MD5:" . $FingerPrintMD5 . ") for user '" . $User . "'.");
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed importing key.") true; $LogPrint warning $0 ("Failed importing key.");
:error false;
} }
} }
@ -67,17 +72,19 @@
:global CharacterReplace; :global CharacterReplace;
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global SSHKeysImport; :global SSHKeysImport;
:if ([ :len $FileName ] = 0 || [ :len $User ] = 0) do={ :if ([ :len $FileName ] = 0 || [ :len $User ] = 0) do={
$LogPrintExit2 warning $0 ("Missing argument(s), please pass file name and user!") true; $LogPrint warning $0 ("Missing argument(s), please pass file name and user!");
:error false;
} }
:local File [ /file/find where name=$FileName ]; :local File [ /file/find where name=$FileName ];
:if ([ :len $File ] = 0) do={ :if ([ :len $File ] = 0) do={
$LogPrintExit2 warning $0 ("File '" . $FileName . "' does not exist.") true; $LogPrint warning $0 ("File '" . $FileName . "' does not exist.");
:error false;
} }
:local Keys ([ /file/get $FileName contents ] . "\n"); :local Keys ([ /file/get $FileName contents ] . "\n");
@ -90,7 +97,7 @@
:do { :do {
$SSHKeysImport $Line $User; $SSHKeysImport $Line $User;
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed importing key for user '" . $User . "'.") false; $LogPrint warning $0 ("Failed importing key for user '" . $User . "'.");
} }
:set Continue true; :set Continue true;
} }
@ -99,7 +106,7 @@
:set Continue true; :set Continue true;
} }
:if ($Continue = false && [ :len ($KeyVal->0) ] > 0) do={ :if ($Continue = false && [ :len ($KeyVal->0) ] > 0) do={
$LogPrintExit2 warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.") false; $LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.");
} }
} while=([ :len $Keys ] > 0); } while=([ :len $Keys ] > 0);
} }

View file

@ -16,18 +16,18 @@
:global ModeButton; :global ModeButton;
:global LogPrintExit2; :global LogPrint;
:set ($ModeButton->"count") ($ModeButton->"count" + 1); :set ($ModeButton->"count") ($ModeButton->"count" + 1);
:local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ]; :local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ];
:if ([ :len $Scheduler ] = 0) do={ :if ([ :len $Scheduler ] = 0) do={
$LogPrintExit2 info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...") false; $LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...");
:global ModeButtonScheduler do={ :global ModeButtonScheduler do={
:global ModeButton; :global ModeButton;
:global LogPrintExit2; :global LogPrint;
:global ModeButtonScheduler; :global ModeButtonScheduler;
:global ValidateSyntax; :global ValidateSyntax;
@ -52,7 +52,7 @@
:if ([ :len $Code ] > 0) do={ :if ([ :len $Code ] > 0) do={
:if ([ $ValidateSyntax $Code ] = true) do={ :if ([ $ValidateSyntax $Code ] = true) do={
$LogPrintExit2 info $ScriptName ("Acting on " . $Count . " mode-button presses: " . $Code) false; $LogPrint info $ScriptName ("Acting on " . $Count . " mode-button presses: " . $Code);
:for I from=1 to=$Count do={ :for I from=1 to=$Count do={
$LEDInvert; $LEDInvert;
@ -66,16 +66,16 @@
[ :parse $Code ]; [ :parse $Code ];
} else={ } else={
$LogPrintExit2 warning $ScriptName ("The code for " . $Count . " mode-button presses failed syntax validation!") false; $LogPrint warning $ScriptName ("The code for " . $Count . " mode-button presses failed syntax validation!");
} }
} else={ } else={
$LogPrintExit2 info $ScriptName ("No action defined for " . $Count . " mode-button presses.") false; $LogPrint info $ScriptName ("No action defined for " . $Count . " mode-button presses.");
} }
} }
/system/scheduler/add name="_ModeButtonScheduler" \ /system/scheduler/add name="_ModeButtonScheduler" \
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s; on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
} else={ } else={
$LogPrintExit2 debug $ScriptName ("Updating scheduler _ModeButtonScheduler...") false; $LogPrint debug $ScriptName ("Updating scheduler _ModeButtonScheduler...");
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ]; /system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
} }
} on-error={ } } on-error={ }

View file

@ -16,7 +16,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -26,7 +26,7 @@
:local SettleTime (5m30s - [ /system/resource/get uptime ]); :local SettleTime (5m30s - [ /system/resource/get uptime ]);
:if ($SettleTime > 0s) do={ :if ($SettleTime > 0s) do={
$LogPrintExit2 info $ScriptName ("System just booted, giving netwatch " . $SettleTime . " to settle.") false; $LogPrint info $ScriptName ("System just booted, giving netwatch " . $SettleTime . " to settle.");
:error true; :error true;
} }
@ -50,15 +50,14 @@
:if ([ :len $DnsServers ] > 0) do={ :if ([ :len $DnsServers ] > 0) do={
:if ($DnsServers != $DnsCurrent) do={ :if ($DnsServers != $DnsCurrent) do={
$LogPrintExit2 info $ScriptName ("Updating DNS servers: " . [ :tostr $DnsServers ]) false; $LogPrint info $ScriptName ("Updating DNS servers: " . [ :tostr $DnsServers ]);
/ip/dns/set servers=$DnsServers; /ip/dns/set servers=$DnsServers;
/ip/dns/cache/flush; /ip/dns/cache/flush;
} }
} else={ } else={
:if ([ :len $DnsFallback ] > 0) do={ :if ([ :len $DnsFallback ] > 0) do={
:if ($DnsFallback != $DnsCurrent) do={ :if ($DnsFallback != $DnsCurrent) do={
$LogPrintExit2 info $ScriptName ("Updating DNS servers to fallback: " . \ $LogPrint info $ScriptName ("Updating DNS servers to fallback: " . [ :tostr $DnsFallback ]);
[ :tostr $DnsFallback ]) false;
/ip/dns/set servers=$DnsFallback; /ip/dns/set servers=$DnsFallback;
/ip/dns/cache/flush; /ip/dns/cache/flush;
} }
@ -83,7 +82,7 @@
} }
:if ($DohCurrent = $HostInfo->"doh-url") do={ :if ($DohCurrent = $HostInfo->"doh-url") do={
$LogPrintExit2 debug $ScriptName ("Current DoH server is still up: " . $DohCurrent) false; $LogPrint debug $ScriptName ("Current DoH server is still up: " . $DohCurrent);
:error true; :error true;
} }
@ -92,7 +91,7 @@
} }
:if ([ :len $DohCurrent ] > 0) do={ :if ([ :len $DohCurrent ] > 0) do={
$LogPrintExit2 info $ScriptName ("Current DoH server is down, disabling: " . $DohCurrent) false; $LogPrint info $ScriptName ("Current DoH server is down, disabling: " . $DohCurrent);
/ip/dns/set use-doh-server=""; /ip/dns/set use-doh-server="";
/ip/dns/cache/flush; /ip/dns/cache/flush;
} }
@ -100,7 +99,7 @@
:foreach DohServer in=$DohServers do={ :foreach DohServer in=$DohServers do={
:if ([ :len ($DohServer->"doh-cert") ] > 0) do={ :if ([ :len ($DohServer->"doh-cert") ] > 0) do={
:if ([ $CertificateAvailable ($DohServer->"doh-cert") ] = false) do={ :if ([ $CertificateAvailable ($DohServer->"doh-cert") ] = false) do={
$LogPrintExit2 warning $ScriptName ("Downloading certificate failed, trying without.") false; $LogPrint warning $ScriptName ("Downloading certificate failed, trying without.");
} }
} }
@ -112,19 +111,19 @@
"\01\00" . "\00\01" . "\00\00" . "\00\00" . "\00\00" . "\09doh-check\05eworm\02de\00" . \ "\01\00" . "\00\01" . "\00\00" . "\00\00" . "\00\00" . "\09doh-check\05eworm\02de\00" . \
"\00\10" . "\00\01") ]) as-value ]->"data"); "\00\10" . "\00\01") ]) as-value ]->"data");
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Request to DoH server failed (network or certificate issue): " . \ $LogPrint warning $ScriptName ("Request to DoH server failed (network or certificate issue): " . \
($DohServer->"doh-url")) false; ($DohServer->"doh-url"));
} }
:if ($Data != false) do={ :if ($Data != false) do={
:if ([ :typeof [ :find $Data "doh-check-OK" ] ] = "num") do={ :if ([ :typeof [ :find $Data "doh-check-OK" ] ] = "num") do={
/ip/dns/set use-doh-server=($DohServer->"doh-url") verify-doh-cert=yes; /ip/dns/set use-doh-server=($DohServer->"doh-url") verify-doh-cert=yes;
/ip/dns/cache/flush; /ip/dns/cache/flush;
$LogPrintExit2 info $ScriptName ("Setting DoH server: " . ($DohServer->"doh-url")) false; $LogPrint info $ScriptName ("Setting DoH server: " . ($DohServer->"doh-url"));
:error true; :error true;
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Received unexpected response from DoH server: " . \ $LogPrint warning $ScriptName ("Received unexpected response from DoH server: " . \
($DohServer->"doh-url")) false; ($DohServer->"doh-url"));
} }
} }
} }

View file

@ -19,7 +19,7 @@
:global EitherOr; :global EitherOr;
:global IfThenElse; :global IfThenElse;
:global IsDNSResolving; :global IsDNSResolving;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global ScriptLock; :global ScriptLock;
@ -32,25 +32,22 @@
:local State [ :tostr $3 ]; :local State [ :tostr $3 ];
:local Hook [ :tostr $4 ]; :local Hook [ :tostr $4 ];
:global LogPrintExit2; :global LogPrint;
:global ValidateSyntax; :global ValidateSyntax;
:if ([ $ValidateSyntax $Hook ] = true) do={ :if ([ $ValidateSyntax $Hook ] = true) do={
:do { :do {
[ :parse $Hook ]; [ :parse $Hook ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("The " . $State . "-hook for " . $Type . " '" . $Name . \ $LogPrint warning $0 ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run.");
"' failed to run.") false;
:return ("The hook failed to run."); :return ("The hook failed to run.");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("The " . $State . "-hook for " . $Type . " '" . $Name . \ $LogPrint warning $0 ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed syntax validation.");
"' failed syntax validation.") false;
:return ("The hook failed syntax validation."); :return ("The hook failed syntax validation.");
} }
$LogPrintExit2 info $0 ("Ran hook on " . $Type . " '" . $Name . "' " . $State . ": " . \ $LogPrint info $0 ("Ran hook on " . $Type . " '" . $Name . "' " . $State . ": " . $Hook);
$Hook) false;
:return ("Ran hook:\n" . $Hook); :return ("Ran hook:\n" . $Hook);
} }
@ -106,10 +103,10 @@
:local Resolve [ :resolve ($HostInfo->"resolve") ]; :local Resolve [ :resolve ($HostInfo->"resolve") ];
:if ($Resolve != $HostVal->"host") do={ :if ($Resolve != $HostVal->"host") do={
:if ([ $ResolveExpected ($HostInfo->"resolve") ($HostVal->"host") ] = false) do={ :if ([ $ResolveExpected ($HostInfo->"resolve") ($HostVal->"host") ] = false) do={
$LogPrintExit2 info $ScriptName ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \ $LogPrint info $ScriptName ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
$HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \ $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
", updating.") false; ", updating.");
/tool/netwatch/set host=$Resolve $Host; /tool/netwatch/set host=$Resolve $Host;
:set ($Metric->"resolve-failcnt") 0; :set ($Metric->"resolve-failcnt") 0;
:set ($HostVal->"status") "unknown"; :set ($HostVal->"status") "unknown";
@ -118,9 +115,9 @@
} on-error={ } on-error={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1); :set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
:if ($Metric->"resolve-failcnt" = 3) do={ :if ($Metric->"resolve-failcnt" = 3) do={
$LogPrintExit2 warning $ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \ $LogPrint warning $ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
$HostInfo->"name") "" ] . "' failed.") false; $HostInfo->"name") "" ] . "' failed.");
} }
} }
} }
@ -129,8 +126,8 @@
:if ($HostVal->"status" = "up") do={ :if ($HostVal->"status" = "up") do={
:local CountDown ($Metric->"count-down"); :local CountDown ($Metric->"count-down");
:if ($CountDown > 0) do={ :if ($CountDown > 0) do={
$LogPrintExit2 info $ScriptName \ $LogPrint info $ScriptName \
("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is up.") false; ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is up.");
:set ($Metric->"count-down") 0; :set ($Metric->"count-down") 0;
} }
:set ($Metric->"count-up") ($Metric->"count-up" + 1); :set ($Metric->"count-up") ($Metric->"count-up" + 1);
@ -178,11 +175,11 @@
} }
:if ($Metric->"notified" = false || $Metric->"count-down" % 120 = 0 || \ :if ($Metric->"notified" = false || $Metric->"count-down" % 120 = 0 || \
$ScriptFromTerminalCached = true) do={ $ScriptFromTerminalCached = true) do={
$LogPrintExit2 [ $IfThenElse ($HostInfo->"no-down-notification" != true) info debug ] $ScriptName \ $LogPrint [ $IfThenElse ($HostInfo->"no-down-notification" != true) info debug ] $ScriptName \
("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is down for " . \ ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is down for " . \
$Metric->"count-down" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \ $Metric->"count-down" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \
($Metric->"notified" = true) ("already notified.") ($CountDown - $Metric->"count-down" . \ ($Metric->"notified" = true) ("already notified.") ($CountDown - $Metric->"count-down" . \
" to go.") ] ("parent " . $Type . " " . $Parent . " is down.") ]) false; " to go.") ] ("parent " . $Type . " " . $Parent . " is down.") ]);
} }
:if ((($CountDown * 2) - ($Metric->"count-down" * 3)) / 2 = 0 && \ :if ((($CountDown * 2) - ($Metric->"count-down" * 3)) / 2 = 0 && \
[ :typeof ($HostInfo->"pre-down-hook") ] = "str") do={ [ :typeof ($HostInfo->"pre-down-hook") ] = "str") do={

View file

@ -47,6 +47,7 @@
120="Implemented a workaround in 'backup-cloud'. Now script should no longer just crash, but send notification with error."; 120="Implemented a workaround in 'backup-cloud'. Now script should no longer just crash, but send notification with error.";
121="The 'wifiwave2' scripts are finally gone. Development continues with 'wifi' in RouterOS 7.13 and later."; 121="The 'wifiwave2' scripts are finally gone. Development continues with 'wifi' in RouterOS 7.13 and later.";
122="The global configuration was enhanced to support loading snippets. Configuration can be split off to scripts where name starts with 'global-config-overlay.d/'."; 122="The global configuration was enhanced to support loading snippets. Configuration can be split off to scripts where name starts with 'global-config-overlay.d/'.";
123="Introduced new function '\$LogPrint', and deprecated '\$LogPrintExit2'. Please update custom scripts if you use it.";
}; };
# Migration steps to be applied on script updates # Migration steps to be applied on script updates

View file

@ -14,7 +14,7 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -34,11 +34,11 @@
} }
:if ($NeighborCount > 0 && $LEDType = "off") do={ :if ($NeighborCount > 0 && $LEDType = "off") do={
$LogPrintExit2 info $ScriptName ("OSPF instance " . $InstanceVal->"name" . " has " . $NeighborCount . " neighbors, led on!") false; $LogPrint info $ScriptName ("OSPF instance " . $InstanceVal->"name" . " has " . $NeighborCount . " neighbors, led on!");
/system/leds/set type=on [ find where leds=$LED ]; /system/leds/set type=on [ find where leds=$LED ];
} }
:if ($NeighborCount = 0 && $LEDType = "on") do={ :if ($NeighborCount = 0 && $LEDType = "on") do={
$LogPrintExit2 info $ScriptName ("OSPF instance " . $InstanceVal->"name" . " has no neighbors, led off!") false; $LogPrint info $ScriptName ("OSPF instance " . $InstanceVal->"name" . " has no neighbors, led off!");
/system/leds/set type=off [ find where leds=$LED ]; /system/leds/set type=off [ find where leds=$LED ];
} }
} }

View file

@ -16,7 +16,7 @@
:global DownloadPackage; :global DownloadPackage;
:global Grep; :global Grep;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptFromTerminal; :global ScriptFromTerminal;
:global ScriptLock; :global ScriptLock;
@ -29,7 +29,7 @@
:local ScriptName [ :tostr $1 ]; :local ScriptName [ :tostr $1 ];
:global GetRandomNumber; :global GetRandomNumber;
:global LogPrintExit2; :global LogPrint;
:global RebootForUpdate do={ :global RebootForUpdate do={
/system/reboot; /system/reboot;
@ -39,8 +39,8 @@
/system/scheduler/add name="_RebootForUpdate" start-time=$StartTime interval=1d \ /system/scheduler/add name="_RebootForUpdate" start-time=$StartTime interval=1d \
on-event=("/system/scheduler/remove \"_RebootForUpdate\"; " . \ on-event=("/system/scheduler/remove \"_RebootForUpdate\"; " . \
":global RebootForUpdate; \$RebootForUpdate;"); ":global RebootForUpdate; \$RebootForUpdate;");
$LogPrintExit2 info $ScriptName ("Scheduled reboot for update at " . $StartTime . \ $LogPrint info $ScriptName ("Scheduled reboot for update at " . $StartTime . \
" local time (" . [ /system/clock/get time-zone-name ] . ").") false; " local time (" . [ /system/clock/get time-zone-name ] . ").");
:return true; :return true;
} }
@ -51,11 +51,12 @@
:local Update [ /system/package/update/get ]; :local Update [ /system/package/update/get ];
:if ([ :typeof ($Update->"latest-version") ] = "nothing") do={ :if ([ :typeof ($Update->"latest-version") ] = "nothing") do={
$LogPrintExit2 warning $ScriptName ("Latest version is not known.") true; $LogPrint warning $ScriptName ("Latest version is not known.");
:error false;
} }
:if ($Update->"installed-version" = $Update->"latest-version") do={ :if ($Update->"installed-version" = $Update->"latest-version") do={
$LogPrintExit2 info $ScriptName ("Version " . $Update->"latest-version" . " is already installed.") false; $LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is already installed.");
:error true; :error true;
} }
@ -63,8 +64,9 @@
:local NumLatest [ $VersionToNum ($Update->"latest-version") ]; :local NumLatest [ $VersionToNum ($Update->"latest-version") ];
:if ($NumInstalled < 0x070d0000 && $NumLatest > 0x070d0000) do={ :if ($NumInstalled < 0x070d0000 && $NumLatest > 0x070d0000) do={
$LogPrintExit2 error $ScriptName ("Migration to wireless/wifi package in RouterOS " . \ $LogPrint error $ScriptName ("Migration to wireless/wifi package in RouterOS " . \
($Update->"latest-version") . " is pending. Please update manually!") true; ($Update->"latest-version") . " is pending. Please update manually!");
:error false;
} }
:local DoDowngrade false; :local DoDowngrade false;
@ -77,14 +79,16 @@
:put "Canceled..."; :put "Canceled...";
} }
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Not installing downgrade automatically.") true; $LogPrint warning $ScriptName ("Not installing downgrade automatically.");
:error false;
} }
} }
:foreach Package in=[ /system/package/find where !bundle ] do={ :foreach Package in=[ /system/package/find where !bundle ] do={
:local PkgName [ /system/package/get $Package name ]; :local PkgName [ /system/package/get $Package name ];
:if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={ :if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={
$LogPrintExit2 error $ScriptName ("Download for package " . $PkgName . " failed, update aborted.") true; $LogPrint error $ScriptName ("Download for package " . $PkgName . " failed, update aborted.");
:error false;
} }
} }
@ -99,29 +103,31 @@
:foreach Order,Script in=$RunOrder do={ :foreach Order,Script in=$RunOrder do={
:set PackagesUpdateBackupFailure false; :set PackagesUpdateBackupFailure false;
:do { :do {
$LogPrintExit2 info $ScriptName ("Running backup script " . $Script . " before update.") false; $LogPrint info $ScriptName ("Running backup script " . $Script . " before update.");
/system/script/run $Script; /system/script/run $Script;
} on-error={ } on-error={
:set PackagesUpdateBackupFailure true; :set PackagesUpdateBackupFailure true;
} }
:if ($PackagesUpdateBackupFailure = true) do={ :if ($PackagesUpdateBackupFailure = true) do={
$LogPrintExit2 warning $ScriptName ("Running backup script " . $Script . " before update failed!") false; $LogPrint warning $ScriptName ("Running backup script " . $Script . " before update failed!");
:if ([ $ScriptFromTerminal $ScriptName ] = true) do={ :if ([ $ScriptFromTerminal $ScriptName ] = true) do={
:put "Do you want to continue anyway? [y/N]"; :put "Do you want to continue anyway? [y/N]";
:if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={ :if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={
$LogPrintExit2 info $ScriptName ("User requested to continue anyway.") false; $LogPrint info $ScriptName ("User requested to continue anyway.");
} else={ } else={
$LogPrintExit2 info $ScriptName ("Canceled update...") true; $LogPrint info $ScriptName ("Canceled update...");
:error false;
} }
} else={ } else={
$LogPrintExit2 warning $ScriptName ("Canceled non-interactive update.") true; $LogPrint warning $ScriptName ("Canceled non-interactive update.");
:error false;
} }
} }
} }
:if ($DoDowngrade = true) do={ :if ($DoDowngrade = true) do={
$LogPrintExit2 info $ScriptName ("Rebooting for downgrade.") false; $LogPrint info $ScriptName ("Rebooting for downgrade.");
:delay 1s; :delay 1s;
/system/package/downgrade; /system/package/downgrade;
} }
@ -137,7 +143,7 @@
} }
} }
$LogPrintExit2 info $ScriptName ("Rebooting for update.") false; $LogPrint info $ScriptName ("Rebooting for update.");
:delay 1s; :delay 1s;
/system/reboot; /system/reboot;
} on-error={ } } on-error={ }

View file

@ -14,26 +14,27 @@
:do { :do {
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global LogPrintExit2; :global LogPrint;
:local Interface $interface; :local Interface $interface;
:if ([ :typeof $Interface ] = "nothing") do={ :if ([ :typeof $Interface ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from ppp on-up script hook.") true; $LogPrint error $ScriptName ("This script is supposed to run from ppp on-up script hook.");
:error false;
} }
:local IntName [ /interface/get $Interface name ]; :local IntName [ /interface/get $Interface name ];
$LogPrintExit2 info $ScriptName ("PPP interface " . $IntName . " is up.") false; $LogPrint info $ScriptName ("PPP interface " . $IntName . " is up.");
/ipv6/dhcp-client/release [ find where interface=$IntName !disabled ]; /ipv6/dhcp-client/release [ find where interface=$IntName !disabled ];
:foreach Script in=[ /system/script/find where source~("\n# provides: ppp-on-up\n") ] do={ :foreach Script in=[ /system/script/find where source~("\n# provides: ppp-on-up\n") ] do={
:local ScriptName [ /system/script/get $Script name ]; :local ScriptName [ /system/script/get $Script name ];
:do { :do {
$LogPrintExit2 debug $ScriptName ("Running script: " . $ScriptName) false; $LogPrint debug $ScriptName ("Running script: " . $ScriptName);
/system/script/run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("Running script '" . $ScriptName . "' failed!") false; $LogPrint warning $ScriptName ("Running script '" . $ScriptName . "' failed!");
} }
} }
} on-error={ } } on-error={ }

View file

@ -16,13 +16,14 @@
:global SmsAction; :global SmsAction;
:global LogPrintExit2; :global LogPrint;
:global ValidateSyntax; :global ValidateSyntax;
:local Action $action; :local Action $action;
:if ([ :typeof $Action ] = "nothing") do={ :if ([ :typeof $Action ] = "nothing") do={
$LogPrintExit2 error $ScriptName ("This script is supposed to run from SMS hook with action=...") true; $LogPrint error $ScriptName ("This script is supposed to run from SMS hook with action=...");
:error false;
} }
:local Code ($SmsAction->$Action); :local Code ($SmsAction->$Action);
@ -31,6 +32,6 @@
:delay 1s; :delay 1s;
[ :parse $Code ]; [ :parse $Code ];
} else={ } else={
$LogPrintExit2 warning $ScriptName ("The code for action '" . $Action . "' failed syntax validation!") false; $LogPrint warning $ScriptName ("The code for action '" . $Action . "' failed syntax validation!");
} }
} on-error={ } } on-error={ }

View file

@ -19,7 +19,7 @@
:global SmsForwardHooks; :global SmsForwardHooks;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
@ -41,7 +41,7 @@
:local Settings [ /tool/sms/get ]; :local Settings [ /tool/sms/get ];
:if ([ /interface/lte/get ($Settings->"port") running ] != true) do={ :if ([ /interface/lte/get ($Settings->"port") running ] != true) do={
$LogPrintExit2 info $ScriptName ("The LTE interface is not in running state, skipping.") false; $LogPrint info $ScriptName ("The LTE interface is not in running state, skipping.");
:error true; :error true;
} }
@ -56,7 +56,7 @@
:if ($Phone = $Settings->"allowed-number" && \ :if ($Phone = $Settings->"allowed-number" && \
($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={
$LogPrintExit2 debug $ScriptName ("Removing SMS, which started a script.") false; $LogPrint debug $ScriptName ("Removing SMS, which started a script.");
/tool/sms/inbox/remove $Sms; /tool/sms/inbox/remove $Sms;
} else={ } else={
:set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \
@ -64,20 +64,16 @@
:foreach Hook in=$SmsForwardHooks do={ :foreach Hook in=$SmsForwardHooks do={
:if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={ :if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={
:if ([ $ValidateSyntax ($Hook->"command") ] = true) do={ :if ([ $ValidateSyntax ($Hook->"command") ] = true) do={
$LogPrintExit2 info $ScriptName ("Running hook '" . $Hook->"match" . "': " . \ $LogPrint info $ScriptName ("Running hook '" . $Hook->"match" . "': " . $Hook->"command");
$Hook->"command") false;
:do { :do {
:local Command [ :parse ($Hook->"command") ]; :local Command [ :parse ($Hook->"command") ];
$Command Phone=$Phone Message=($SmsVal->"message"); $Command Phone=$Phone Message=($SmsVal->"message");
:set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . \ :set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . $Hook->"command");
$Hook->"command");
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("The code for hook '" . $Hook->"match" . \ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run!");
"' failed to run!") false;
} }
} else={ } else={
$LogPrintExit2 warning $ScriptName ("The code for hook '" . $Hook->"match" . \ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed syntax validation!");
"' failed syntax validation!") false;
} }
} }
} }

View file

@ -30,7 +30,7 @@
:global EscapeForRegEx; :global EscapeForRegEx;
:global GetRandom20CharAlNum; :global GetRandom20CharAlNum;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global MAX; :global MAX;
:global MIN; :global MIN;
:global MkDir; :global MkDir;
@ -57,7 +57,8 @@
} }
:if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={ :if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 warning $ScriptName ("Downloading required certificate failed.") true; $LogPrint warning $ScriptName ("Downloading required certificate failed.");
:error false;
} }
$RandomDelay $TelegramRandomDelay; $RandomDelay $TelegramRandomDelay;
@ -72,7 +73,7 @@
:set TelegramRandomDelay [ $MAX 0 ($TelegramRandomDelay - 1) ]; :set TelegramRandomDelay [ $MAX 0 ($TelegramRandomDelay - 1) ];
} on-error={ } on-error={
:if ($I < 4) do={ :if ($I < 4) do={
$LogPrintExit2 debug $ScriptName ("Fetch failed, " . $I . ". try.") false; $LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try.");
:set TelegramRandomDelay [ $MIN 15 ($TelegramRandomDelay + 5) ]; :set TelegramRandomDelay [ $MIN 15 ($TelegramRandomDelay + 5) ];
:delay (($I * $I) . "s"); :delay (($I * $I) . "s");
} }
@ -81,7 +82,8 @@
} }
:if ($Data = false) do={ :if ($Data = false) do={
$LogPrintExit2 warning $ScriptName ("Failed getting updates from Telegram.") true; $LogPrint warning $ScriptName ("Failed getting updates from Telegram.");
:error false;
} }
:local UpdateID 0; :local UpdateID 0;
@ -106,7 +108,7 @@
:if ($Trusted = true) do={ :if ($Trusted = true) do={
:local Done false; :local Done false;
:if ($Message->"text" = "?") do={ :if ($Message->"text" = "?") do={
$LogPrintExit2 info $ScriptName ("Sending notice for update " . $UpdateID . ".") false; $LogPrint info $ScriptName ("Sending notice for update " . $UpdateID . ".");
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; replyto=($Message->"message_id"); \ $SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; replyto=($Message->"message_id"); \
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \ subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
message=("Online, awaiting your commands!") }); message=("Online, awaiting your commands!") });
@ -118,8 +120,8 @@
} else={ } else={
:set TelegramChatActive false; :set TelegramChatActive false;
} }
$LogPrintExit2 info $ScriptName ("Now " . [ $IfThenElse $TelegramChatActive "active" "passive" ] . \ $LogPrint info $ScriptName ("Now " . [ $IfThenElse $TelegramChatActive "active" "passive" ] . \
" from update " . $UpdateID . "!") false; " from update " . $UpdateID . "!");
:set Done true; :set Done true;
} }
:if ($Done = false && ($IsMyReply = 1 || ($IsReply = 0 && $TelegramChatActive = true)) && [ :len ($Message->"text") ] > 0) do={ :if ($Done = false && ($IsMyReply = 1 || ($IsReply = 0 && $TelegramChatActive = true)) && [ :len ($Message->"text") ] > 0) do={
@ -127,9 +129,10 @@
:local State ""; :local State "";
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]); :local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={ :if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
$LogPrintExit2 error $ScriptName ("Failed creating directory!") true; $LogPrint error $ScriptName ("Failed creating directory!");
:error false;
} }
$LogPrintExit2 info $ScriptName ("Running command from update " . $UpdateID . ": " . $Message->"text") false; $LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Message->"text");
:execute script=(":do {\n" . $Message->"text" . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \ :execute script=(":do {\n" . $Message->"text" . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \
"/file/add name=\"" . $File . ".done\"") file=($File . "\00"); "/file/add name=\"" . $File . ".done\"") file=($File . "\00");
:if ([ $WaitForFile ($File . ".done") [ $EitherOr $TelegramChatRunTime 20s ] ] = false) do={ :if ([ $WaitForFile ($File . ".done") [ $EitherOr $TelegramChatRunTime 20s ] ] = false) do={
@ -146,7 +149,7 @@
("Output exceeds file read size.") ("No output.") ] ]) }); ("Output exceeds file read size.") ("No output.") ] ]) });
/file/remove "tmpfs/telegram-chat"; /file/remove "tmpfs/telegram-chat";
} else={ } else={
$LogPrintExit2 info $ScriptName ("The command from update " . $UpdateID . " failed syntax validation!") false; $LogPrint info $ScriptName ("The command from update " . $UpdateID . " failed syntax validation!");
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \ $SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \ subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
message=("Command:\n" . $Message->"text" . "\n\nThe command failed syntax validation!") }); message=("Command:\n" . $Message->"text" . "\n\nThe command failed syntax validation!") });
@ -157,16 +160,16 @@
[ $IfThenElse ([ :len ($From->"username") ] = 0) "without username" ("'" . $From->"username" . "'") ] . \ [ $IfThenElse ([ :len ($From->"username") ] = 0) "without username" ("'" . $From->"username" . "'") ] . \
" (ID " . $From->"id" . ") in update " . $UpdateID . "!"); " (ID " . $From->"id" . ") in update " . $UpdateID . "!");
:if ($Message->"text" ~ ("^! *" . [ $EscapeForRegEx $Identity ] . "\$")) do={ :if ($Message->"text" ~ ("^! *" . [ $EscapeForRegEx $Identity ] . "\$")) do={
$LogPrintExit2 warning $ScriptName $MessageText false; $LogPrint warning $ScriptName $MessageText;
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \ $SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \ subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
message=("You are not trusted.") }); message=("You are not trusted.") });
} else={ } else={
$LogPrintExit2 info $ScriptName $MessageText false; $LogPrint info $ScriptName $MessageText;
} }
} }
} else={ } else={
$LogPrintExit2 debug $ScriptName ("Already handled update " . $UpdateID . ".") false; $LogPrint debug $ScriptName ("Already handled update " . $UpdateID . ".");
} }
} }
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \ :set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \

View file

@ -16,7 +16,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global CharacterReplace; :global CharacterReplace;
:global LogPrintExit2; :global LogPrint;
:global ScriptLock; :global ScriptLock;
:if ([ $ScriptLock $ScriptName ] = false) do={ :if ([ $ScriptLock $ScriptName ] = false) do={
@ -33,7 +33,7 @@
:if ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \ :if ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \
($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \ ($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \
$GreIntVal->"disabled" = true)) do={ $GreIntVal->"disabled" = true)) do={
$LogPrintExit2 info $ScriptName ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address") false; $LogPrint info $ScriptName ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address");
/interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where remote-address=$PeerVal->"dynamic-address" name!=$GreIntVal->"name" ]; /interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where remote-address=$PeerVal->"dynamic-address" name!=$GreIntVal->"name" ];
/interface/gre/set $GreInt remote-address=($PeerVal->"dynamic-address") disabled=no; /interface/gre/set $GreInt remote-address=($PeerVal->"dynamic-address") disabled=no;
} }

View file

@ -17,7 +17,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global CertificateAvailable; :global CertificateAvailable;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global ScriptLock; :global ScriptLock;
@ -26,7 +26,8 @@
} }
:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={ :if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 error $ScriptName ("Downloading required certificate failed.") true; $LogPrint error $ScriptName ("Downloading required certificate failed.");
:error false;
} }
:foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={ :foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={
@ -41,24 +42,25 @@
("https://ipv4.tunnelbroker.net/nic/update?hostname=" . $Comment->"id") \ ("https://ipv4.tunnelbroker.net/nic/update?hostname=" . $Comment->"id") \
user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data"); user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data");
} on-error={ } on-error={
$LogPrintExit2 debug $ScriptName ("Failed downloading, " . $I . " retries pending.") false; $LogPrint debug $ScriptName ("Failed downloading, " . $I . " retries pending.");
:delay 2s; :delay 2s;
} }
} }
} }
:if (!($Data ~ "^(good|nochg) ")) do={ :if (!($Data ~ "^(good|nochg) ")) do={
$LogPrintExit2 error $ScriptName ("Failed sending the local address to tunnelbroker or unexpected response!") true; $LogPrint error $ScriptName ("Failed sending the local address to tunnelbroker or unexpected response!");
:error false;
} }
:local PublicAddress [ :pick $Data ([ :find $Data " " ] + 1) [ :find $Data "\n" ] ]; :local PublicAddress [ :pick $Data ([ :find $Data " " ] + 1) [ :find $Data "\n" ] ];
:if ($PublicAddress != $InterfaceVal->"local-address") do={ :if ($PublicAddress != $InterfaceVal->"local-address") do={
:if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={ :if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={
$LogPrintExit2 warning $ScriptName ("The address " . $PublicAddress . " is not configured on your device. NAT by ISP?") false; $LogPrint warning $ScriptName ("The address " . $PublicAddress . " is not configured on your device. NAT by ISP?");
} }
$LogPrintExit2 info $ScriptName ("Local address changed, updating tunnel configuration with address: " . $PublicAddress) false; $LogPrint info $ScriptName ("Local address changed, updating tunnel configuration with address: " . $PublicAddress);
/interface/6to4/set $Interface local-address=$PublicAddress; /interface/6to4/set $Interface local-address=$PublicAddress;
} }
} }