Compare commits

..

No commits in common. "d80f43a1c86760565d0e0a662ceb0de63636c61a" and "b560ea4b7d3da75b5f54633eea6a5fb7472d5bd6" have entirely different histories.

4 changed files with 68 additions and 91 deletions

View file

@ -21,7 +21,6 @@ for details!
* [Ben Harris](mailto:mail@bharr.is) (@bharrisau) * [Ben Harris](mailto:mail@bharr.is) (@bharrisau)
* [Daniel Ziegenberg](mailto:daniel@ziegenberg.at) (@ziegenberg) * [Daniel Ziegenberg](mailto:daniel@ziegenberg.at) (@ziegenberg)
* [Ignacio Serrano](mailto:ignic@ignic.com) (@ignic) * [Ignacio Serrano](mailto:ignic@ignic.com) (@ignic)
* [Ilya Kulakov](mailto:kulakov.ilya@gmail.com) (@Kentzo)
* [Michael Gisbers](mailto:michael@gisbers.de) (@mgisbers) * [Michael Gisbers](mailto:michael@gisbers.de) (@mgisbers)
* [Miquel Bonastre](mailto:mbonastre@yahoo.com) (@mbonastre) * [Miquel Bonastre](mailto:mbonastre@yahoo.com) (@mbonastre)
* @netravnen * @netravnen

View file

@ -10,40 +10,30 @@ Initial commands
[⬅️ Go back to main README](README.md) [⬅️ Go back to main README](README.md)
> ⚠️ **Warning**: These commands are intended for initial setup. If you are > ⚠️ **Warning**: These command are inteneded for initial setup. If you are
> not aware of the procedure please follow > not aware of the procedure please follow
> [the long way in detail](README.md#the-long-way-in-detail). > [the long way in detail](README.md#the-long-way-in-detail).
Run the complete base installation: Run the complete base installation:
{ {
:local BaseUrl "https://git.eworm.de/cgit/routeros-scripts/plain/"; /tool/fetch "https://git.eworm.de/cgit/routeros-scripts/plain/certs/ISRG-Root-X2.pem" dst-path="isrg-root-x2.pem" as-value;
:local CertFileName "ISRG-Root-X2.pem";
:local CertFingerprint "69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470";
:put "Importing certificate...";
/tool/fetch ($BaseUrl . "certs/" . $CertFileName) dst-path=$CertFileName as-value;
:delay 1s; :delay 1s;
/certificate/import file-name=$CertFileName passphrase=""; /certificate/import file-name="isrg-root-x2.pem" passphrase="";
:if ([ :len [ /certificate/find where fingerprint=$CertFingerprint ] ] != 1) do={ :if ([ :len [ /certificate/find where fingerprint="69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470" ] ] != 1) do={
:error "Something is wrong with your certificates!"; :error "Something is wrong with your certificates!";
}; };
:delay 1s; :delay 1s;
:put "Renaming global-config-overlay, if exists...";
/system/script/set name=("global-config-overlay-" . [ /system/clock/get date ] . "-" . [ /system/clock/get time ]) [ find where name="global-config-overlay" ]; /system/script/set name=("global-config-overlay-" . [ /system/clock/get date ] . "-" . [ /system/clock/get time ]) [ find where name="global-config-overlay" ];
:foreach Script in={ "global-config"; "global-config-overlay"; "global-functions" } do={ :foreach Script in={ "global-config"; "global-config-overlay"; "global-functions" } do={
:put "Installing $Script...";
/system/script/remove [ find where name=$Script ]; /system/script/remove [ find where name=$Script ];
/system/script/add name=$Script owner=$Script source=([ /tool/fetch check-certificate=yes-without-crl ($BaseUrl . $Script . ".rsc") output=user as-value]->"data"); /system/script/add name=$Script owner=$Script source=([ /tool/fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit/routeros-scripts/plain/" . $Script . ".rsc") output=user as-value]->"data");
}; };
:put "Loading configuration and functions...";
/system/script { run global-config; run global-functions; }; /system/script { run global-config; run global-functions; };
:put "Scheduling to load configuration and functions...";
/system/scheduler/remove [ find where name="global-scripts" ]; /system/scheduler/remove [ find where name="global-scripts" ];
/system/scheduler/add name="global-scripts" start-time=startup on-event="/system/script { run global-config; run global-functions; }"; /system/scheduler/add name="global-scripts" start-time=startup on-event="/system/script { run global-config; run global-functions; }";
:put "Renaming certificate by its common-name...";
:global CertificateNameByCN; :global CertificateNameByCN;
$CertificateNameByCN $CertFingerprint; $CertificateNameByCN "ISRG Root X2";
}; };
Then continue setup with Then continue setup with

102
README.md
View file

@ -214,61 +214,61 @@ There's much more to explore... Have fun!
Available scripts Available scripts
----------------- -----------------
* [Find and remove access list duplicates](doc/accesslist-duplicates.md) (`accesslist-duplicates`) * [Find and remove access list duplicates](doc/accesslist-duplicates.md)
* [Upload backup to Mikrotik cloud](doc/backup-cloud.md) (`backup-cloud`) * [Upload backup to Mikrotik cloud](doc/backup-cloud.md)
* [Send backup via e-mail](doc/backup-email.md) (`backup-email`) * [Send backup via e-mail](doc/backup-email.md)
* [Save configuration to fallback partition](doc/backup-partition.md) (`backup-partition`) * [Save configuration to fallback partition](doc/backup-partition.md)
* [Upload backup to server](doc/backup-upload.md) (`backup-upload`) * [Upload backup to server](doc/backup-upload.md)
* [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md) (`capsman-download-packages`) * [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md)
* [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md) (`capsman-rolling-upgrade`) * [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md)
* [Renew locally issued certificates](doc/certificate-renew-issued.md) (`certificate-renew-issued`) * [Renew locally issued certificates](doc/certificate-renew-issued.md)
* [Renew certificates and notify on expiration](doc/check-certificates.md) (`check-certificates`) * [Renew certificates and notify on expiration](doc/check-certificates.md)
* [Notify about health state](doc/check-health.md) (`check-health`) * [Notify about health state](doc/check-health.md)
* [Notify on LTE firmware upgrade](doc/check-lte-firmware-upgrade.md) (`check-lte-firmware-upgrade`) * [Notify on LTE firmware upgrade](doc/check-lte-firmware-upgrade.md)
* [Check perpetual license on CHR](doc/check-perpetual-license.md) (`check-perpetual-license`) * [Check perpetual license on CHR](doc/check-perpetual-license.md)
* [Notify on RouterOS update](doc/check-routeros-update.md) (`check-routeros-update`) * [Notify on RouterOS update](doc/check-routeros-update.md)
* [Collect MAC addresses in wireless access list](doc/collect-wireless-mac.md) (`collect-wireless-mac`) * [Collect MAC addresses in wireless access list](doc/collect-wireless-mac.md)
* [Use wireless network with daily psk](doc/daily-psk.md) (`daily-psk`) * [Use wireless network with daily psk](doc/daily-psk.md)
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) (`dhcp-lease-comment`) * [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md)
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md) (`dhcp-to-dns`) * [Create DNS records for DHCP leases](doc/dhcp-to-dns.md)
* [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md) (`firmware-upgrade-reboot`) * [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md)
* [Download, import and update firewall address-lists](doc/fw-addr-lists.md) (`fw-addr-lists`) * [Download, import and update firewall address-lists](doc/fw-addr-lists.md)
* [Wait for global functions und modules](doc/global-wait.md) (`global-wait`) * [Wait for global functions und modules](doc/global-wait.md)
* [Send GPS position to server](doc/gps-track.md) (`gps-track`) * [Send GPS position to server](doc/gps-track.md)
* [Use WPA network with hotspot credentials](doc/hotspot-to-wpa.md) (`hotspot-to-wpa` & `hotspot-to-wpa-cleanup`) * [Use WPA network with hotspot credentials](doc/hotspot-to-wpa.md)
* [Create DNS records for IPSec peers](doc/ipsec-to-dns.md) (`ipsec-to-dns`) * [Create DNS records for IPSec peers](doc/ipsec-to-dns.md)
* [Update configuration on IPv6 prefix change](doc/ipv6-update.md) (`ipv6-update`) * [Update configuration on IPv6 prefix change](doc/ipv6-update.md)
* [Manage IP addresses with bridge status](doc/ip-addr-bridge.md) (`ip-addr-bridge`) * [Manage IP addresses with bridge status](doc/ip-addr-bridge.md)
* [Run other scripts on DHCP lease](doc/lease-script.md) (`lease-script`) * [Run other scripts on DHCP lease](doc/lease-script.md)
* [Manage LEDs dark mode](doc/leds-mode.md) (`leds-day-mode`, `leds-night-mode` & `leds-toggle-mode`) * [Manage LEDs dark mode](doc/leds-mode.md)
* [Forward log messages via notification](doc/log-forward.md) (`log-forward`) * [Forward log messages via notification](doc/log-forward.md)
* [Mode button with multiple presses](doc/mode-button.md) (`mode-button`) * [Mode button with multiple presses](doc/mode-button.md)
* [Manage DNS and DoH servers from netwatch](doc/netwatch-dns.md) (`netwatch-dns`) * [Manage DNS and DoH servers from netwatch](doc/netwatch-dns.md)
* [Notify on host up and down](doc/netwatch-notify.md) (`netwatch-notify`) * [Notify on host up and down](doc/netwatch-notify.md)
* [Visualize OSPF state via LEDs](doc/ospf-to-leds.md) (`ospf-to-leds`) * [Visualize OSPF state via LEDs](doc/ospf-to-leds.md)
* [Manage system update](doc/packages-update.md) (`packages-update`) * [Manage system update](doc/packages-update.md)
* [Run scripts on ppp connection](doc/ppp-on-up.md) (`ppp-on-up`) * [Run scripts on ppp connection](doc/ppp-on-up.md)
* [Act on received SMS](doc/sms-action.md) (`sms-action`) * [Act on received SMS](doc/sms-action.md)
* [Forward received SMS](doc/sms-forward.md) (`sms-forward`) * [Forward received SMS](doc/sms-forward.md)
* [Play Super Mario theme](doc/super-mario-theme.md) (`super-mario-theme`) * [Play Super Mario theme](doc/super-mario-theme.md)
* [Chat with your router and send commands via Telegram bot](doc/telegram-chat.md) (`telegram-chat`) * [Chat with your router and send commands via Telegram bot](doc/telegram-chat.md)
* [Install LTE firmware upgrade](doc/unattended-lte-firmware-upgrade.md) (`unattended-lte-firmware-upgrade`) * [Install LTE firmware upgrade](doc/unattended-lte-firmware-upgrade.md)
* [Update GRE configuration with dynamic addresses](doc/update-gre-address.md) (`update-gre-address`) * [Update GRE configuration with dynamic addresses](doc/update-gre-address.md)
* [Update tunnelbroker configuration](doc/update-tunnelbroker.md) (`update-tunnelbroker`) * [Update tunnelbroker configuration](doc/update-tunnelbroker.md)
Available modules Available modules
----------------- -----------------
* [Manage ports in bridge](doc/mod/bridge-port-to.md) (`mod/bridge-port-to`) * [Manage ports in bridge](doc/mod/bridge-port-to.md)
* [Manage VLANs on bridge ports](doc/mod/bridge-port-vlan.md) (`mod/bridge-port-vlan`) * [Manage VLANs on bridge ports](doc/mod/bridge-port-vlan.md)
* [Inspect variables](doc/mod/inspectvar.md) (`mod/inspectvar`) * [Inspect variables](doc/mod/inspectvar.md)
* [IP address calculation](doc/mod/ipcalc.md) (`mod/ipcalc`) * [IP address calculation](doc/mod/ipcalc.md)
* [Send notifications via e-mail](doc/mod/notification-email.md) (`mod/notification-email`) * [Send notifications via e-mail](doc/mod/notification-email.md)
* [Send notifications via Matrix](doc/mod/notification-matrix.md) (`mod/notification-matrix`) * [Send notifications via Matrix](doc/mod/notification-matrix.md)
* [Send notifications via Ntfy](doc/mod/notification-ntfy.md) (`mod/notification-ntfy`) * [Send notifications via Ntfy](doc/mod/notification-ntfy.md)
* [Send notifications via Telegram](doc/mod/notification-telegram.md) (`mod/notification-telegram`) * [Send notifications via Telegram](doc/mod/notification-telegram.md)
* [Download script and run it once](doc/mod/scriptrunonce.md) (`mod/scriptrunonce`) * [Download script and run it once](doc/mod/scriptrunonce.md)
* [Import ssh keys for public key authentication](doc/mod/ssh-keys-import.md) (`mod/ssh-keys-import`) * [Import ssh keys for public key authentication](doc/mod/ssh-keys-import.md)
Installing custom scripts & modules Installing custom scripts & modules
----------------------------------- -----------------------------------

View file

@ -167,8 +167,8 @@
$LogPrint warning $0 ("Failed downloading certificate with CommonName '" . $CommonName . \ $LogPrint warning $0 ("Failed downloading certificate with CommonName '" . $CommonName . \
"' from repository! Trying fallback to mkcert.org..."); "' from repository! Trying fallback to mkcert.org...");
:do { :do {
:if ([ :len [ /certificate/find where common-name="ISRG Root X1" ] ] = 0) do={ :if ([ $CertificateAvailable "ISRG Root X1" ] = false) do={
$LogPrint error $0 ("Required certificate is not available."); $LogPrint error $0 ("Downloading required certificate failed.");
:return false; :return false;
} }
/tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgentStr $0 ] }) \ /tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgentStr $0 ] }) \
@ -203,19 +203,12 @@
# name a certificate by its common-name # name a certificate by its common-name
:set CertificateNameByCN do={ :set CertificateNameByCN do={
:local Match [ :tostr $1 ]; :local CommonName [ :tostr $1 ];
:global CleanName; :global CleanName;
:global LogPrint;
:local Cert ([ /certificate/find where (common-name=$Match or fingerprint=$Match or name=$Match) ]->0); :local Cert [ /certificate/find where common-name=$CommonName ];
:if ([ :len $Cert ] = 0) do={
$LogPrint warning $0 ("No matching certificate found.");
:return false;
}
:local CommonName [ /certificate/get $Cert common-name ];
/certificate/set $Cert name=[ $CleanName $CommonName ]; /certificate/set $Cert name=[ $CleanName $CommonName ];
:return true;
} }
# multiply given character(s) # multiply given character(s)
@ -1395,7 +1388,7 @@
# lock script against multiple invocation # lock script against multiple invocation
:set ScriptLock do={ :set ScriptLock do={
:local Script [ :tostr $1 ]; :local Script [ :tostr $1 ];
:local WaitMax [ :totime $2 ]; :local WaitMax ([ :tonum $3 ] * 10);
:global GetRandom20CharAlNum; :global GetRandom20CharAlNum;
:global IfThenElse; :global IfThenElse;
@ -1484,10 +1477,6 @@
:set ($ScriptLockOrder->$Script) ({}); :set ($ScriptLockOrder->$Script) ({});
} }
:if ([ :typeof $WaitMax ] = "nil" ) do={
:set WaitMax 0s;
}
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrint error $0 ("A script named '" . $Script . "' does not exist!"); $LogPrint error $0 ("A script named '" . $Script . "' does not exist!");
:error false; :error false;
@ -1507,13 +1496,12 @@
:local MyTicket [ $GetRandom20CharAlNum 6 ]; :local MyTicket [ $GetRandom20CharAlNum 6 ];
$AddTicket $Script $MyTicket; $AddTicket $Script $MyTicket;
:local WaitInterval ($WaitMax / 20); :local WaitCount 0;
:local WaitTime $WaitMax; :while ($WaitMax > $WaitCount && \
:while ($WaitTime > 0 && \
([ $IsFirstTicket $Script $MyTicket ] = false || \ ([ $IsFirstTicket $Script $MyTicket ] = false || \
[ $TicketCount $Script ] < [ $JobCount $Script ])) do={ [ $TicketCount $Script ] < [ $JobCount $Script ])) do={
:set WaitTime ($WaitTime - $WaitInterval); :set WaitCount ($WaitCount + 1);
:delay $WaitInterval; :delay 100ms;
} }
:if ([ $IsFirstTicket $Script $MyTicket ] = true && \ :if ([ $IsFirstTicket $Script $MyTicket ] = true && \
@ -1525,7 +1513,7 @@
$RemoveTicket $Script $MyTicket; $RemoveTicket $Script $MyTicket;
$LogPrint debug $0 ("Script '" . $Script . "' started more than once" . \ $LogPrint debug $0 ("Script '" . $Script . "' started more than once" . \
[ $IfThenElse ($WaitTime < $WaitMax) " and timed out waiting for lock" "" ] . "..."); [ $IfThenElse ($WaitCount > 0) " and timed out waiting for lock" "" ] . "...");
:return false; :return false;
} }