From ff5cdc30193ba69944f6772f213e63ea00678861 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 26 Aug 2020 09:23:56 +0200 Subject: [ ... print count-only ...] -> [ :len [ ... find ... ] ] Using 'print count-only' always prints a number to terminal, even if the value is evaluated in a condition or assigned to a variable. This can be quite annoying. Behavior will not chance (SUP-25503), so replacing the code... --- INITIAL-COMMANDS.md | 2 +- capsman-download-packages | 4 ++-- capsman-rolling-upgrade | 2 +- check-certificates | 2 +- check-routeros-update | 6 +++--- cloud-backup | 4 ++-- collect-wireless-mac.capsman | 2 +- collect-wireless-mac.local | 2 +- collect-wireless-mac.template | 2 +- daily-psk.capsman | 2 +- daily-psk.local | 2 +- daily-psk.template | 4 ++-- dhcp-to-dns | 4 ++-- global-functions | 24 ++++++++++++------------ hotspot-to-wpa | 2 +- ip-addr-bridge | 4 ++-- learn-mac-based-vlan | 2 +- lease-script | 2 +- ppp-on-up | 2 +- sms-forward | 2 +- 20 files changed, 38 insertions(+), 38 deletions(-) diff --git a/INITIAL-COMMANDS.md b/INITIAL-COMMANDS.md index e9889d2..597ddb6 100644 --- a/INITIAL-COMMANDS.md +++ b/INITIAL-COMMANDS.md @@ -10,7 +10,7 @@ procedure please follow [the long way in detail](README.md#the-long-way-in-detai / tool fetch "https://git.eworm.de/cgit/routeros-scripts/plain/certs/Let%27s%20Encrypt%20Authority%20X3.pem" dst-path="letsencrypt.pem"; :delay 1s; / certificate import file-name=letsencrypt.pem passphrase=""; - :if ([ / certificate print count-only where fingerprint="96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6" or fingerprint="731d3d9cfaa061487a1d71445a42f67df0afca2a6c2d2f98ff7b3ce112b1f568" or fingerprint="0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739" ] != 3) do={ + :if ([ :len [ / certificate find where fingerprint="96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6" or fingerprint="731d3d9cfaa061487a1d71445a42f67df0afca2a6c2d2f98ff7b3ce112b1f568" or fingerprint="0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739" ] ] != 3) do={ :error "Something is wrong with your certificates!"; } / file remove "letsencrypt.pem"; diff --git a/capsman-download-packages b/capsman-download-packages index 88aac0e..a314163 100644 --- a/capsman-download-packages +++ b/capsman-download-packages @@ -21,7 +21,7 @@ $WaitFullyConnected; :local InstalledVersion [ / system package update get installed-version ]; :local Updated false; -:if ([ / file print count-only where name=$PackagePath type="directory" ] = 0) do={ +:if ([ :len [ / file find where name=$PackagePath type="directory" ] ] = 0) do={ $MkDir $PackagePath; $LogPrintExit info ("Created directory at package path (" . $PackagePath . \ "). Please place your packages!") false; @@ -43,7 +43,7 @@ $WaitFullyConnected; } :if ($Updated = true) do={ - :if ([ / system script print count-only where name="capsman-rolling-upgrade" ] > 0) do={ + :if ([ :len [ / system script find where name="capsman-rolling-upgrade" ] ] > 0) do={ / system script run capsman-rolling-upgrade; } else={ / caps-man remote-cap upgrade [ find where version!=$InstalledVersion ]; diff --git a/capsman-rolling-upgrade b/capsman-rolling-upgrade index 698ff93..61552f5 100644 --- a/capsman-rolling-upgrade +++ b/capsman-rolling-upgrade @@ -14,7 +14,7 @@ $ScriptLock "capsman-rolling-upgrade"; :local InstalledVersion [ / system package update get installed-version ]; -:local RemoteCapCount [ /caps-man remote-cap print count-only ]; +:local RemoteCapCount [ :len [ / caps-man remote-cap find ] ]; :if ($RemoteCapCount > 0) do={ :local Delay (600 / $RemoteCapCount); :if ($Delay > 120) do={ :set Delay 120; } diff --git a/check-certificates b/check-certificates index a0e5bce..5ac8a18 100644 --- a/check-certificates +++ b/check-certificates @@ -101,7 +101,7 @@ $WaitFullyConnected; :foreach Cert in=[ / certificate find where !revoked !scep-url expires-after<2w fingerprint~"." ] do={ :local CertVal [ / certificate get $Cert ]; - :if ([ / certificate scep-server print count-only where ca-cert=($CertVal->"ca") ] > 0) do={ + :if ([ :len [ / certificate scep-server find where ca-cert=($CertVal->"ca") ] ] > 0) do={ $LogPrintExit debug ("Certificate \"" . ($CertVal->"name") . "\" is handled by SCEP, skipping.") false; } else={ :local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ]; diff --git a/check-routeros-update b/check-routeros-update index b1e40e4..073ed96 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -19,7 +19,7 @@ :global VersionToNum; :local DoUpdate do={ - :if ([ / system script print count-only where name="packages-update" ] > 0) do={ + :if ([ :len [ / system script find where name="packages-update" ] ] > 0) do={ / system script run packages-update; } else={ / system package update install without-paging; @@ -27,14 +27,14 @@ :error "Waiting for system to reboot."; } -:if ([ / system package print count-only where name="wireless" disabled=no ] > 0) do={ +:if ([ :len [ / system package find where name="wireless" disabled=no ] ] > 0) do={ :if ([ / interface wireless cap get enabled ] = true && \ [ / caps-man manager get enabled ] = false) do={ $LogPrintExit error "System is managed by CAPsMAN, not checking." true; } } -:if ([ / system scheduler print count-only where name="reboot-for-update" ] > 0) do={ +:if ([ :len [ / system scheduler find where name="reboot-for-update" ] ] > 0) do={ :error "A reboot for update is already scheduled."; } diff --git a/cloud-backup b/cloud-backup index b85a467..1511062 100644 --- a/cloud-backup +++ b/cloud-backup @@ -15,10 +15,10 @@ :global SymbolForNotification; :do { - # we are not interested in output, but print without count-only is + # we are not interested in output, but print is # required to fetch information from cloud / system backup cloud print as-value; - :if ([ / system backup cloud print count-only ] > 0) do={ + :if ([ :len [ / system backup cloud find ] ] > 0) do={ / system backup cloud upload-file action=create-and-upload \ password=$BackupPassword replace=[ get ([ find ]->0) name ]; } else={ diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman index 5979156..e44f387 100644 --- a/collect-wireless-mac.capsman +++ b/collect-wireless-mac.capsman @@ -17,7 +17,7 @@ $ScriptLock "collect-wireless-mac.capsman"; -:if ([ / caps-man access-list print count-only 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; $LogPrintExit warning "Added disabled access-list entry with comment '--- collected above ---'." false; } diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local index 3b86d72..8d23317 100644 --- a/collect-wireless-mac.local +++ b/collect-wireless-mac.local @@ -17,7 +17,7 @@ $ScriptLock "collect-wireless-mac.local"; -:if ([ / interface wireless access-list print count-only 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; $LogPrintExit warning "Added disabled access-list entry with comment '--- collected above ---'." false; } diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index f644f47..655fd47 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -18,7 +18,7 @@ $ScriptLock "collect-wireless-mac%TEMPL%"; -:if ([ / %PATH% access-list print count-only where comment="--- collected above ---" disabled ] = 0) do={ +:if ([ :len [ / %PATH% access-list find where comment="--- collected above ---" disabled ] ] = 0) do={ / %PATH% access-list add comment="--- collected above ---" disabled=yes; $LogPrintExit warning "Added disabled access-list entry with comment '--- collected above ---'." false; } diff --git a/daily-psk.capsman b/daily-psk.capsman index f8cbb20..5ae2f5e 100644 --- a/daily-psk.capsman +++ b/daily-psk.capsman @@ -64,7 +64,7 @@ $WaitFullyConnected; $LogPrintExit info ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; / caps-man access-list set $AccList private-passphrase=$NewPsk; - :if ([ / caps-man interface print count-only where configuration=$Configuration ] > 0) do={ + :if ([ :len [ / caps-man interface find where configuration=$Configuration ] ] > 0) do={ :foreach SeenSsid in=$Seen do={ :if ($SeenSsid = $Ssid) do={ $LogPrintExit debug ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; diff --git a/daily-psk.local b/daily-psk.local index a878940..4cc728c 100644 --- a/daily-psk.local +++ b/daily-psk.local @@ -64,7 +64,7 @@ $WaitFullyConnected; $LogPrintExit info ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false; / interface wireless access-list set $AccList private-pre-shared-key=$NewPsk; - :if ([ / interface wireless print count-only where name=$IntName disabled=no ] = 1) do={ + :if ([ :len [ / interface wireless find where name=$IntName disabled=no ] ] = 1) do={ :foreach SeenSsid in=$Seen do={ :if ($SeenSsid = $Ssid) do={ $LogPrintExit debug ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; diff --git a/daily-psk.template b/daily-psk.template index 5c691e6..3c23139 100644 --- a/daily-psk.template +++ b/daily-psk.template @@ -69,8 +69,8 @@ $WaitFullyConnected; / interface wireless access-list set $AccList private-pre-shared-key=$NewPsk; / caps-man access-list set $AccList private-passphrase=$NewPsk; - :if ([ / interface wireless print count-only where name=$IntName disabled=no ] = 1) do={ - :if ([ / caps-man interface print count-only where configuration=$Configuration ] > 0) do={ + :if ([ :len [ / interface wireless find where name=$IntName disabled=no ] ] = 1) do={ + :if ([ :len [ / caps-man interface find where configuration=$Configuration ] ] > 0) do={ :foreach SeenSsid in=$Seen do={ :if ($SeenSsid = $Ssid) do={ $LogPrintExit debug ("Already sent a mail for SSID " . $Ssid . ", skipping.") false; diff --git a/dhcp-to-dns b/dhcp-to-dns index 4e2c7f2..3a95eb6 100644 --- a/dhcp-to-dns +++ b/dhcp-to-dns @@ -22,7 +22,7 @@ :local Ttl 5m; :local CommentPrefix "managed by dhcp-to-dns for "; -:if ([ / ip dns static print count-only where comment="--- dhcp-to-dns above ---" name=- type=NXDOMAIN disabled ] = 0) do={ +:if ([ :len [ / ip dns static find where comment="--- dhcp-to-dns above ---" name=- type=NXDOMAIN disabled ] ] = 0) do={ / ip dns static add comment="--- dhcp-to-dns above ---" name=- type=NXDOMAIN disabled=yes; $LogPrintExit warning "Added disabled static dns record with comment '--- dhcp-to-dns above ---'." false; } @@ -31,7 +31,7 @@ :foreach DnsRecord in=[ / ip dns static find where comment ~ $CommentPrefix ] do={ :local DnsRecordVal [ / ip dns static get $DnsRecord ]; :local MacAddress [ $CharacterReplace ($DnsRecordVal->"comment") $CommentPrefix "" ]; - :if ([ / ip dhcp-server lease print count-only where mac-address=$MacAddress address=($DnsRecordVal->"address") dynamic=yes status=bound ] > 0) do={ + :if ([ :len [ / ip dhcp-server lease find where mac-address=$MacAddress address=($DnsRecordVal->"address") dynamic=yes status=bound ] ] > 0) do={ $LogPrintExit debug ("Lease for " . $MacAddress . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting DNS entry.") false; } else={ :local Found false; diff --git a/global-functions b/global-functions index 7483f11..67c4882 100644 --- a/global-functions +++ b/global-functions @@ -66,7 +66,7 @@ "is configured to download certificate CRLs to system!") false; } - :if ([ / certificate print count-only where common-name=$CommonName ] = 0) do={ + :if ([ :len [ / certificate find where common-name=$CommonName ] ] = 0) do={ $LogPrintExit info ("Certificate with CommonName \"" . $CommonName . "\" not available.") false; :if ([ $CertificateDownload $CommonName ] = false) do={ :return false; @@ -76,7 +76,7 @@ :local CertVal; :local Issuer $CommonName; :do { - :if ([ / certificate print count-only where common-name=$Issuer ] = 0) do={ + :if ([ :len [ / certificate find where common-name=$Issuer ] ] = 0) do={ $LogPrintExit info ("Certificate chain for \"" . $CommonName . \ "\" is incomplete, missing \"" . $Issuer . "\".") false; :if ([ $CertificateDownload $CommonName ] = false) do={ @@ -176,7 +176,7 @@ # default route is reachable :set DefaultRouteIsReachable do={ - :if ([ / ip route print count-only where dst-address=0.0.0.0/0 !unreachable active !routing-mark ] > 0) do={ + :if ([ :len [ / ip route find where dst-address=0.0.0.0/0 !unreachable active !routing-mark ] ] > 0) do={ :return true; } :return false; @@ -249,7 +249,7 @@ } :local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ]; - :if ([ / file print count-only where name=$PkgDest type="package" ] > 0) do={ + :if ([ :len [ / file find where name=$PkgDest type="package" ] ] > 0) do={ $LogPrintExit info ("Package file alreasy exists.") false; :return true; } @@ -383,7 +383,7 @@ :global LogPrintExit; - :if ([ / tool netwatch print count-only where comment=$MailServer ] = 0) do={ + :if ([ :len [ / tool netwatch find where comment=$MailServer ] ] = 0) do={ $LogPrintExit warning ("Adding netwatch entry for mail server.") false; :local MailHost $MailServer; :if ([ :typeof [ :toip $MailHost ] ] != "ip" ) do={ @@ -418,7 +418,7 @@ :global WaitForFile; - :if ([ / file print count-only where name=$Dir type="directory" ] = 0) do={ + :if ([ :len [ / file find where name=$Dir type="directory" ] ] = 0) do={ :local WwwVal [ / ip service get www ]; / ip service set www address=127.0.0.1/32 disabled=no port=80; / tool fetch http://127.0.0.1/ dst-path=($Dir . "/tmp"); @@ -495,7 +495,7 @@ :global SymbolForNotification; :foreach Script in=$Scripts do={ - :if ([ / system script print count-only where name=$Script ] = 0) do={ + :if ([ :len [ / system script find where name=$Script ] ] = 0) do={ $LogPrintExit info ("Adding new script: " . $Script) false; / system script add name=$Script source="#!rsc"; } @@ -569,7 +569,7 @@ / system script set owner=($ScriptVal->"name") source=$SourceNew \ dont-require-permissions=$DontRequirePermissions $Script; :if ($ScriptVal->"name" = "global-config" && \ - [ / system script print count-only where name="global-config-overlay" ] > 0) do={ + [ :len [ / system script find where name="global-config-overlay" ] ] > 0) do={ $LogPrintExit info ("Reloading global configuration and overlay.") false; / system script { run global-config; run global-config-overlay; } } @@ -593,7 +593,7 @@ :global GlobalConfigChanges; :local ChangeLogCode; :local ConfigScript "global-config"; - :if ([ /system script print count-only where name="global-config-overlay" ] > 0) do={ + :if ([ :len [ / system script find where name="global-config-overlay" ] ] > 0) do={ :set ConfigScript "global-config-overlay"; } :local NotificationMessage ("Current configuration on " . $Identity . \ @@ -645,7 +645,7 @@ :local Script [ :tostr $1 ]; - :if ([ / system script job print count-only where script=$Script ] > 1) do={ + :if ([ :len [ / system script job find where script=$Script ] ] > 1) do={ $LogPrintExit info ("Script " . $Script . " started more than once... Aborting.") true; } } @@ -868,7 +868,7 @@ :local FileName [ $CleanFilePath [ :tostr $1 ] ]; :local I 0; - :while ([ file print count-only where name=$FileName ] = 0) do={ + :while ([ :len [ / file find where name=$FileName ] ] = 0) do={ :if ($I > 20) do={ :return false; } @@ -895,7 +895,7 @@ :global TimeIsSync; :while ([ $TimeIsSync ] = false) do={ - :if ([ / system script print count-only where name="rotate-ntp" ] > 0 && \ + :if ([ :len [ / system script find where name="rotate-ntp" ] ] > 0 && \ [ :tostr [ / system resource get uptime ] ] ~ "[369]:00\$") do={ :do { / system script run rotate-ntp; diff --git a/hotspot-to-wpa b/hotspot-to-wpa index a9fa7d9..8603d56 100644 --- a/hotspot-to-wpa +++ b/hotspot-to-wpa @@ -13,7 +13,7 @@ :local Date [ / system clock get date ]; :local PassWord [ / ip hotspot user get [ find where name=$UserName ] password ]; -:if ([ / caps-man access-list print count-only 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; $LogPrintExit warning "Added disabled access-list entry with comment '--- hotspot-to-wpa above ---'." false; } diff --git a/ip-addr-bridge b/ip-addr-bridge index ec403f5..9bc7ef8 100644 --- a/ip-addr-bridge +++ b/ip-addr-bridge @@ -8,8 +8,8 @@ :foreach Bridge in=[ / interface bridge find ] do={ :local BrName [ / interface bridge get $Bridge name ]; - :if ([ / interface bridge port print count-only where bridge=$BrName ] > 0) do={ - :if ([ / interface bridge port print count-only where bridge=$BrName and inactive=no ] = 0) do={ + :if ([ :len [ / interface bridge port find where bridge=$BrName ] ] > 0) do={ + :if ([ :len [ / interface bridge port find where bridge=$BrName and inactive=no ] ] = 0) do={ / ip address disable [ find where !dynamic interface=$BrName ]; } else={ / ip address enable [ find where !dynamic interface=$BrName ]; diff --git a/learn-mac-based-vlan b/learn-mac-based-vlan index 14261c0..690bec4 100644 --- a/learn-mac-based-vlan +++ b/learn-mac-based-vlan @@ -7,7 +7,7 @@ :local NewVlanId 33; -:if ( [ / interface ethernet switch mac-based-vlan print count-only where src-mac-address=$leaseActMAC ] = 0 ) do={ +:if ([ :len [ / interface ethernet switch mac-based-vlan find where src-mac-address=$leaseActMAC ] ] = 0 ) do={ :log info ("MAC-based-VLAN: learning MAC address " . $leaseActMAC . " for VLAN " . $NewVlanId . "."); / interface ethernet switch mac-based-vlan add src-mac-address=$leaseActMAC new-customer-vid=$NewVlanId; } diff --git a/lease-script b/lease-script index 701994e..2b097c4 100644 --- a/lease-script +++ b/lease-script @@ -42,7 +42,7 @@ :delay ((1 + $leaseBound) . "s"); :foreach Script in=$Scripts do={ - :if ([ / system script print count-only where name=$Script ] > 0) do={ + :if ([ :len [ / system script find where name=$Script ] ] > 0) do={ :log debug ("Running script from lease-script: " . $Script); / system script run $Script; } diff --git a/ppp-on-up b/ppp-on-up index a207e47..5de980d 100644 --- a/ppp-on-up +++ b/ppp-on-up @@ -24,7 +24,7 @@ } :foreach Script in=$Scripts do={ - :if ([ / system script print count-only where name=$Script ] > 0) do={ + :if ([ :len [ / system script find where name=$Script ] ] > 0) do={ :log debug ("Running script from ppp-on-up: " . $Script); / system script run $Script; } diff --git a/sms-forward b/sms-forward index 8f38a4a..13ba8bd 100644 --- a/sms-forward +++ b/sms-forward @@ -27,7 +27,7 @@ $WaitFullyConnected; :local Settings [ / tool sms get ]; # forward SMS in a loop -:while ([ / tool sms inbox print count-only ] > 0) do={ +:while ([ :len [ / tool sms inbox find ] ] > 0) do={ :local Phone [ / tool sms inbox get ([ find ]->0) phone ]; :local Messages ""; :local Delete [ :toarray "" ]; -- cgit v1.2.3-54-g00ecf