Compare commits

...

183 commits

Author SHA1 Message Date
Christian Hesse
64fe923c5a DEBUG: fix typo 2025-05-22 10:13:52 +02:00
Christian Hesse
f1396b83aa telegram-chat: support debug output for updates in JSON 2025-05-22 10:13:52 +02:00
Christian Hesse
1b5dd1e1d3 telegram-chat: support trusted group chat ids
But be warned: Adding a person to a trusted group will give
her/him administrative control over the device(s) - without
changes on the device itself!

On the other hand... Removing permissions is easily done by removing
a person from a group.

Closes: https://github.com/eworm-de/routeros-scripts/issues/101
2025-05-22 10:13:52 +02:00
Christian Hesse
e78c71948d mod/notification-telegram: fix indention 2025-05-22 10:13:52 +02:00
Christian Hesse
ce129ee441 fw-addr-lists: for IPv6 the CIDR is always expected 2025-05-22 10:13:52 +02:00
Christian Hesse
2a95687477 mod/notification-email: add the link symbol 2025-05-22 10:13:52 +02:00
Christian Hesse
74dc809b98 mod/notification-email: properly truncate the body
Truned out that the size limit for e-mail message/body is anywhere just
below 64kB... So truncate  at about 62.000 bytes.
2025-05-22 10:13:52 +02:00
Christian Hesse
ff218e4ce5 mod/notification-email: add error handling when sending mail 2025-05-22 10:13:52 +02:00
Christian Hesse
bd3cc3bbd4 mod/inspectvar: replace only when matching 2025-05-22 10:13:52 +02:00
Christian Hesse
36f155ce62 mod/inspectvar: remove CR, replace LF 2025-05-22 10:13:52 +02:00
Christian Hesse
187735f35f mod/inspectvar: print the length for strings 2025-05-22 10:13:52 +02:00
Christian Hesse
3521995dbc mod/inspectvar: use $CharacterMultiply 2025-05-22 10:13:52 +02:00
Christian Hesse
1f4290f4be Merge branch 'onerror' into next 2025-05-22 10:13:52 +02:00
Christian Hesse
205bcce6f9 update-tunnelbroker: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
10ac816348 unattended-lte-firmware-upgrade: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
f22d46da96 telegram-chat: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
d0adf9974e sms-forward: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
fefe59751f netwatch-notify: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
a523f97938 netwatch-dns: :do ... on-error=... -> :onerror ... do=... 2025-05-22 10:13:52 +02:00
Christian Hesse
c757064eb9 mod/ssh-keys-import: :do ... on-error=... -> ... well... - fix condition 🥴 2025-05-22 10:13:47 +02:00
Christian Hesse
9cd4ed08a4 mod/ssh-keys-import: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
9ae21c00bd mod/scriptrunonce: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
314e68e4cd mode-button: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
e01873301f mod/notification-gotify: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
3f092d3477 mod/notification-matrix: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
2a7fd7ea53 mod/notification-ntfy: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
5badafe109 mod/notification-telegram: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
c1e6348bb9 lease-script: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
d5f9ecebfb gps-track: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
5c599beae1 global-functions: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
8b1b73c936 global-functions: $ValidateSyntax: add debug output 2025-05-21 22:12:25 +02:00
Christian Hesse
f5c4378676 global-functions: $ValidateSyntax: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
12926b7c42 global-functions: $ScriptInstallUpdate: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
2317013121 global-functions: $RmFile: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
86a8919ed2 global-functions: $RmDir: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
09f9826760 global-functions: $MkDir: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
7a1fef78a2 global-functions: $GetMacVendor: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
a6b36dde7b global-functions: $FetchHuge: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
5b89f3e425 global-functions: $DownloadPackage: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
a9e7bb0a05 global-config: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:12:25 +02:00
Christian Hesse
b807fc9e90 fw-addr-lists: adopt changes in wording...
... to match the changes from previous commit.
2025-05-21 22:12:10 +02:00
Christian Hesse
142b0760b0 fw-addr-lists: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
79f681b801 check-routeros-update: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
1925d2847c check-lte-firmware-upgrade: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
187aeba78b check-health: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
dc2296d500 backup-upload: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
c3fce37066 backup-partition: :do ... on-error=... -> :onerror ... do=... 2025-05-21 22:05:35 +02:00
Christian Hesse
6691e2e765 global-functions: $DownloadPackage: reverse failure logic...
... and do not retry.
2025-05-21 21:51:16 +02:00
Christian Hesse
01f3cb91e7 sms-forward: add error handling on message removal 2025-05-13 09:22:45 +02:00
Christian Hesse
9085780562 sms-forward: delay after removal...
... to give the SIM card some time to succeed. Removing several messages
one after another fails without this.
2025-05-13 09:22:45 +02:00
Christian Hesse
f095b581e7 global-functions: $ScriptInstallUpdate: set config and functions not ready...
... before reload. This should fix some corner cases where scripts ran
with broken configuration or functions.

Also do reload both - configuration and functions - to simplify the
function.
2025-05-12 12:09:24 +02:00
Christian Hesse
661aad522b global-config: add another visual hint 2025-05-12 12:09:24 +02:00
Christian Hesse
4561b17dbf global-config: add another comment with visual hint 2025-05-12 12:09:24 +02:00
Christian Hesse
39295b4954 Merge branch 'global-config-ready' into next 2025-05-08 09:51:08 +02:00
Christian Hesse
0f58cecc0f global-wait: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
f2dbb9eff3 update-tunnelbroker: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
b4d80d3b17 update-gre-address: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
9b5419b939 telegram-chat: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
15248ffd39 sms-forward: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
6270ac45d8 sms-action: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
194698f53f ppp-on-up: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
38ec392a5f packages-update: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
aaecd1b457 ospf-to-leds: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
5b40380cd2 netwatch-notify: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
2d39dbdf7c netwatch-dns: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
bc1c238158 mode-button: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
160effd91b log-forward: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
10bd9a1cb5 lease-script: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
59f9a1187f ipv6-update: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
ce29fcf49e ipsec-to-dns: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
6a9fced721 hotspot-to-wpa: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
713e63da87 hotspot-to-wpa-cleanup: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
148892694f gps-track: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
9e70bca30b fw-addr-lists: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
a68763c4dd firmware-upgrade-reboot: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
857993cf90 dhcp-to-dns: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
ad6ad5bfcc dhcp-lease-comment: check for global config to be ready 2025-05-08 09:51:08 +02:00
Christian Hesse
be0e9be1ba Merge branch 'global-functions-fail' into next 2025-05-08 09:51:07 +02:00
Christian Hesse
b19c448f78 daily-psk: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
2afe734bc3 Merge branch 'onerror-for-outer-block' into next 2025-05-08 09:51:07 +02:00
Christian Hesse
6040f70b19 update-tunnelbroker: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
286ed96cc3 collect-wireless-mac: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
af40ae82ed mod/ssh-keys-import: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
87edd0bd29 update-gre-address: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
59c66de690 check-routeros-update: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
5958851bd7 mod/scriptrunonce: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
35bce7c5eb telegram-chat: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
78463f469b check-perpetual-license: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
f7ba78702f mod/notification-telegram: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
24ea16cf91 sms-forward: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
506acb748b check-lte-firmware-upgrade: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
e3a15cc6b8 mod/notification-ntfy: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
0ef8888412 sms-action: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
1936dcb563 check-health: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
d865deb8a8 mod/notification-matrix: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
7b624faaa1 ppp-on-up: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
4954a88695 check-certificates: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9d845d40f0 mod/notification-gotify: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
4358dabb19 packages-update: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
ef1a402c4e certificate-renew-issued: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
862830b341 mod/notification-email: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
ff812dd192 ospf-to-leds: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
40b19a179d capsman-rolling-upgrade: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
8cddc63767 mod/ipcalc: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
446aa3d7ff netwatch-notify: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
12037ff6e6 capsman-download-packages: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9b558ff8a1 mod/inspectvar: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
2374be9a21 netwatch-dns: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
27fc07e940 backup-upload: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
d5141f43e5 mod/bridge-port-vlan: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
63606ad25c mode-button: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
200167fa38 backup-partition: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
02986eb77a mod/bridge-port-to: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
a6ab95ccef log-forward: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
37a6d4cc43 backup-email: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
d2af793683 update-tunnelbroker: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
829fce789b lease-script: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
d57916fc26 backup-cloud: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
fe3d9f8418 update-gre-address: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
41b705aa5a ipv6-update: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
60c5e84401 accesslist-duplicates: check for global config to be ready 2025-05-08 09:51:07 +02:00
Christian Hesse
3ad8cafc7a telegram-chat: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
83cf003f62 ipsec-to-dns: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
bcdb74f31d global-config: introduce a state variable 2025-05-08 09:51:07 +02:00
Christian Hesse
aae9b4d4e3 sms-forward: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
057bbb8481 hotspot-to-wpa: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
3eec13b8b5 sms-action: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
76778f0431 hotspot-to-wpa-cleanup: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
aeccd36f16 ppp-on-up: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
925e7f869e gps-track: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9a5a2aec4f packages-update: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
4b92181f2e fw-addr-lists: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
c720eadd2c ospf-to-leds: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
4d1349125d firmware-upgrade-reboot: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
0df4170a2e netwatch-notify: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
a308d4269e dhcp-to-dns: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
2d41ad718d netwatch-dns: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
a556f4c398 dhcp-lease-comment: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
ff03f49724 mode-button: use :onerror for outer block 2025-05-08 09:51:07 +02:00
Christian Hesse
8418d58ff0 daily-psk: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
2712bcb44d collect-wireless-mac: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
69b2af4bd7 check-routeros-update: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
08d78224a0 check-perpetual-license: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
8f1ac6fa17 check-lte-firmware-upgrade: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
96cbb32a4f check-health: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9b811e1ed2 check-certificates: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
b4188ab1a2 certificate-renew-issued: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
de5aab12ae capsman-rolling-upgrade: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
33393798b1 capsman-download-packages: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9423d8019a backup-upload: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
bf1b3e3c5e backup-partition: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
64ec962bb6 backup-email: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
7d4e4ec273 backup-cloud: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
9acf9781cb accesslist-duplicates: fail if global functions do not become ready 2025-05-08 09:51:07 +02:00
Christian Hesse
c643069b3e log-forward: use :onerror for outer block 2025-05-06 09:55:07 +02:00
Christian Hesse
da93138017 lease-script: use :onerror for outer block 2025-05-06 09:55:04 +02:00
Christian Hesse
39ab19b272 ipv6-update: use :onerror for outer block 2025-05-06 09:55:01 +02:00
Christian Hesse
1075b6b24e ipsec-to-dns: use :onerror for outer block 2025-05-06 09:54:57 +02:00
Christian Hesse
9ae733a167 hotspot-to-wpa: use :onerror for outer block 2025-05-06 09:54:53 +02:00
Christian Hesse
143b8a8ddc hotspot-to-wpa-cleanup: use :onerror for outer block 2025-05-06 09:54:48 +02:00
Christian Hesse
d609da0041 gps-track: use :onerror for outer block 2025-05-06 09:54:45 +02:00
Christian Hesse
0e93d8ca66 fw-addr-lists: use :onerror for outer block 2025-05-06 09:54:42 +02:00
Christian Hesse
d99380443b firmware-upgrade-reboot: use :onerror for outer block 2025-05-06 09:54:38 +02:00
Christian Hesse
8ed83a311d dhcp-to-dns: use :onerror for outer block 2025-05-06 09:54:35 +02:00
Christian Hesse
5dc6b712e1 dhcp-lease-comment: use :onerror for outer block 2025-05-06 09:54:29 +02:00
Christian Hesse
55e07a8a42 daily-psk: use :onerror for outer block 2025-05-06 09:54:24 +02:00
Christian Hesse
7d8e9fda29 collect-wireless-mac: use :onerror for outer block 2025-05-06 09:54:18 +02:00
Christian Hesse
472dc9289d check-routeros-update: use :onerror for outer block 2025-05-06 09:54:14 +02:00
Christian Hesse
f5c33a9cfb check-perpetual-license: use :onerror for outer block 2025-05-06 09:54:10 +02:00
Christian Hesse
b959f2d941 check-lte-firmware-upgrade: use :onerror for outer block 2025-05-06 09:54:06 +02:00
Christian Hesse
051a1d95e5 check-health: use :onerror for outer block 2025-05-06 09:54:02 +02:00
Christian Hesse
e44a5384b7 check-certificates: use :onerror for outer block 2025-05-06 09:53:59 +02:00
Christian Hesse
009516dbd4 certificate-renew-issued: use :onerror for outer block 2025-05-06 09:53:54 +02:00
Christian Hesse
54a3012e89 capsman-rolling-upgrade: use :onerror for outer block 2025-05-06 09:53:46 +02:00
Christian Hesse
e0ba2c8282 capsman-download-packages: use :onerror for outer block 2025-05-06 09:53:37 +02:00
Christian Hesse
0a9acab040 backup-upload: use :onerror for outer block 2025-05-06 09:53:34 +02:00
Christian Hesse
34c052c5f1 backup-partition: use :onerror for outer block 2025-05-06 09:53:31 +02:00
Christian Hesse
953daca8ac backup-email: use :onerror for outer block 2025-05-06 09:53:28 +02:00
Christian Hesse
02a205b14e backup-cloud: use :onerror for outer block 2025-05-06 09:53:24 +02:00
Christian Hesse
b9faeb86b9 accesslist-duplicates: use :onerror for outer block 2025-05-06 09:53:19 +02:00
Christian Hesse
41bf9677db global-functions: use :onerror for outer block 2025-05-06 09:50:20 +02:00
Christian Hesse
90f61d3d75 global-functions: $ExitError: support to pass in error message 2025-05-06 09:43:57 +02:00
Christian Hesse
ccfe1a781e check-routeros-update: log and print info with scheduler 2025-05-06 09:43:57 +02:00
73 changed files with 708 additions and 658 deletions

View file

@ -42,7 +42,7 @@ Other actions (`disk`, `email`, `remote` or `support`) can be used as
well. I do not recommend using `echo` - use [debug output](#debug-output)
instead.
Disable or remote that setting to restore regular logging.
Disable or remove that setting to restore regular logging.
## Verbose output

View file

@ -10,11 +10,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:local Seen ({});
@ -32,6 +32,6 @@
}
:set ($Seen->$Mac) 1;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -10,11 +10,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:local Seen ({});
@ -32,6 +32,6 @@
}
:set ($Seen->$Mac) 1;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:local Seen ({});
@ -41,6 +41,6 @@
}
:set ($Seen->$Mac) 1;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -10,11 +10,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:local Seen ({});
@ -32,6 +32,6 @@
}
:set ($Seen->$Mac) 1;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# upload backup to MikroTik cloud
# https://rsc.eworm.de/doc/backup-cloud.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupRandomDelay;
@ -99,6 +99,6 @@
:set PackagesUpdateBackupFailure true;
}
$RmDir "tmpfs/backup-cloud";
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# create and email backup and config file
# https://rsc.eworm.de/doc/backup-email.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupPassword;
@ -135,6 +135,6 @@
:delay 1s;
:set I ($I + 1);
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -10,11 +10,11 @@
# save configuration to fallback partition
# https://rsc.eworm.de/doc/backup-partition.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupPartitionCopyBeforeFeatureUpdate;
@ -32,14 +32,15 @@
:global LogPrint;
:do {
:onerror Err {
/partitions/copy-to $FallbackTo;
$LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackToName . "'.");
:return true;
} on-error={
$LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . $FallbackToName . "'!");
} do={
$LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . \
$FallbackToName . "': " . $Err);
:return false;
}
:return true;
}
:if ([ $ScriptLock $ScriptName ] = false) do={
@ -107,20 +108,21 @@
}
}
:do {
:onerror Err {
/system/scheduler/add start-time=startup name="running-from-backup-partition" \
on-event=(":log warning (\"Running from partition '\" . " . \
"[ /partitions/get [ find where running ] name ] . \"'!\")");
/partitions/save-config-to $FallbackTo;
/system/scheduler/remove "running-from-backup-partition";
$LogPrint info $ScriptName ("Saved configuration to partition '" . $FallbackToName . "'.");
} on-error={
} do={
/system/scheduler/remove [ find where name="running-from-backup-partition" ];
$LogPrint error $ScriptName ("Failed saving configuration to partition '" . $FallbackToName . "'!");
$LogPrint error $ScriptName ("Failed saving configuration to partition '" . \
$FallbackToName . "': " . $Err);
:set PackagesUpdateBackupFailure true;
:set ExitOK true;
:error false;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -10,11 +10,11 @@
# create and upload backup and config file
# https://rsc.eworm.de/doc/backup-upload.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupPassword;
@ -90,13 +90,13 @@
/system/backup/save encryption=aes-sha256 name=$FilePath password=$BackupPassword;
$WaitForFile ($FilePath . ".backup");
:do {
:onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".backup") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".backup");
:set BackupFile [ /file/get ($FilePath . ".backup") ];
:set ($BackupFile->"name") ($FileName . ".backup");
} on-error={
$LogPrint error $ScriptName ("Uploading backup file failed!");
} do={
$LogPrint error $ScriptName ("Uploading backup file failed: " . $Err);
:set BackupFile "failed";
:set Failed 1;
}
@ -109,13 +109,13 @@
/export terse show-sensitive file=$FilePath;
$WaitForFile ($FilePath . ".rsc");
:do {
:onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".rsc") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".rsc");
:set ExportFile [ /file/get ($FilePath . ".rsc") ];
:set ($ExportFile->"name") ($FileName . ".rsc");
} on-error={
$LogPrint error $ScriptName ("Uploading configuration export failed!");
} do={
$LogPrint error $ScriptName ("Uploading configuration export failed: " . $Err);
:set ExportFile "failed";
:set Failed 1;
}
@ -130,13 +130,13 @@
file=($FilePath . ".conf\00");
$WaitForFile ($FilePath . ".conf");
:do {
:onerror Err {
/tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".conf") \
user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".conf");
:set ConfigFile [ /file/get ($FilePath . ".conf") ];
:set ($ConfigFile->"name") ($FileName . ".conf");
} on-error={
$LogPrint error $ScriptName ("Uploading global-config-overlay failed!");
} do={
$LogPrint error $ScriptName ("Uploading global-config-overlay failed: " . $Err);
:set ConfigFile "failed";
:set Failed 1;
}
@ -173,6 +173,6 @@
:set PackagesUpdateBackupFailure true;
}
$RmDir $DirName;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CleanFilePath;
@ -87,6 +87,6 @@
/caps-man/remote-cap/upgrade [ find where version!=$InstalledVersion ];
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CleanFilePath;
@ -98,6 +98,6 @@
/interface/wifi/capsman/remote-cap/upgrade [ find where version!=$InstalledVersion ];
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CleanFilePath;
@ -89,6 +89,6 @@
/interface/wifi/capsman/remote-cap/upgrade [ find where version!=$InstalledVersion ];
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -45,6 +45,6 @@
:delay ($Delay . "s");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -13,11 +13,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -53,6 +53,6 @@
:delay ($Delay . "s");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -46,6 +46,6 @@
:delay ($Delay . "s");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# renew locally issued certificates
# https://rsc.eworm.de/doc/certificate-renew-issued.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CertIssuedExportPass;
@ -47,6 +47,6 @@
$LogPrint info $ScriptName ("Issued a new certificate for '" . $CertVal->"common-name" . "'.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# check for certificate validity
# https://rsc.eworm.de/doc/check-certificates.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CertRenewTime;
@ -237,6 +237,6 @@
", it is invalid after " . ($CertVal->"invalid-after") . ".");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# check for RouterOS health state
# https://rsc.eworm.de/doc/check-health.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CheckHealthCPUUtilization;
@ -89,10 +89,10 @@
:foreach Plugin in=$Plugins do={
:local PluginVal [ /system/script/get $Plugin ];
:if ([ $ValidateSyntax ($PluginVal->"source") ] = true) do={
:do {
:onerror Err {
/system/script/run $Plugin;
} on-error={
$LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run.");
} do={
$LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run: " . $Err);
}
} else={
$LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed syntax validation, skipping.");
@ -105,6 +105,6 @@
}
:set CheckHealthPlugins;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# check for LTE firmware upgrade, send notification
# https://rsc.eworm.de/doc/check-lte-firmware-upgrade.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global SentLteFirmwareUpgradeNotification;
@ -45,12 +45,12 @@
:local IntName [ /interface/lte/get $Interface name ];
:local Firmware;
:local Info;
:do {
:onerror Err {
:set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ];
:set Info [ /interface/lte/monitor $Interface once as-value ];
} on-error={
} do={
$LogPrint debug $ScriptName ("Could not get latest LTE firmware version for interface " . \
$IntName . ".");
$IntName . ": " . $Err);
:return false;
}
@ -102,6 +102,6 @@
:foreach Interface in=[ /interface/lte/find ] do={
$CheckInterface $ScriptName $Interface;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# check perpetual license on CHR
# https://rsc.eworm.de/doc/check-perpetual-license.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -73,6 +73,6 @@
". It is now valid until " . ($License->"deadline-at") . ".") });
:set SentCertificateNotification;
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# check for RouterOS update, send notification and/or install
# https://rsc.eworm.de/doc/check-routeros-update.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -62,8 +62,9 @@
$WaitFullyConnected;
:if ([ :len [ /system/scheduler/find where name="_RebootForUpdate" ] ] > 0) do={
$LogPrint info $ScriptName ("A reboot for update is already scheduled.");
:set ExitOK true;
:error "A reboot for update is already scheduled.";
:error false;
}
$LogPrint debug $ScriptName ("Checking for updates...");
@ -140,13 +141,13 @@
:if ([ :len $SafeUpdateUrl ] > 0) do={
:local Result;
:do {
:onerror Err {
:set Result [ /tool/fetch check-certificate=yes-without-crl \
($SafeUpdateUrl . $Update->"channel" . "?installed=" . $Update->"installed-version" . \
"&latest=" . $Update->"latest-version") http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) \
output=user as-value ];
} on-error={
$LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ".");
} do={
$LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ": " . $Err);
}
:if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={
$LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is considered safe, updating...");
@ -213,6 +214,6 @@
" is available for downgrade.");
:set SentRouterosUpdateNotification ($Update->"latest-version");
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -95,6 +95,6 @@
$LogPrint debug $ScriptName ("No mac address available... Ignoring.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -96,6 +96,6 @@
$LogPrint debug $ScriptName ("No mac address available... Ignoring.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -113,6 +113,6 @@
$LogPrint debug $ScriptName ("No mac address available... Ignoring.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -95,6 +95,6 @@
$LogPrint debug $ScriptName ("No mac address available... Ignoring.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global DailyPskMatchComment;
@ -91,6 +91,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global DailyPskMatchComment;
@ -90,6 +90,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global DailyPskMatchComment;
@ -106,6 +106,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global DailyPskMatchComment;
@ -91,6 +91,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -38,6 +38,6 @@
/ip/dhcp-server/lease/set comment=$NewComment $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -38,6 +38,6 @@
/ip/dhcp-server/lease/set comment=$NewComment $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -43,6 +43,6 @@
/ip/dhcp-server/lease/set comment=$NewComment $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -38,6 +38,6 @@
/ip/dhcp-server/lease/set comment=$NewComment $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# check DHCP leases and add/remove/update DNS entries
# https://rsc.eworm.de/doc/dhcp-to-dns.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Domain;
@ -125,6 +125,6 @@
$LogPrint debug $ScriptName ("No address available... Ignoring.");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# install firmware upgrade, and reboot
# https://rsc.eworm.de/doc/firmware-upgrade-reboot.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -55,6 +55,6 @@
$LogPrint info $ScriptName ("Firmware upgrade successful, rebooting.");
/system/reboot;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# download, import and update firewall address-lists
# https://rsc.eworm.de/doc/fw-addr-lists.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global FwAddrLists;
@ -114,8 +114,8 @@
:error true;
}
:if ($Address ~ "^[0-9a-zA-Z]*:[0-9a-zA-Z:\\.]+(/[0-9]{1,3})?\$") do={
:if ($Address ~ "/128\$") do={
:set Address [ :pick $Address 0 ([ :len $Address ] - 4) ];
:if ([ :typeof [ :find $Address "/" ] ] = "nil") do={
:set Address ($Address . "/128");
}
:set ($IPv6Addresses->$Branch->$Address) $TimeOut;
:error true;
@ -135,15 +135,15 @@
:local Branch [ $GetBranch $Address ];
:local TimeOut ($IPv4Addresses->$Branch->$Address);
:if ([ :typeof $TimeOut ] = "time") do={
$LogPrintVerbose debug $ScriptName ("Renewing IPv4 address in list '" . $FwListName . \
"' with " . $TimeOut . ": " . $Address);
$LogPrintVerbose debug $ScriptName ("Renewing IPv4 address " . $Address . \
" in list '" . $FwListName . "' with " . $TimeOut . ".");
/ip/firewall/address-list/set $Entry timeout=$TimeOut;
:set ($IPv4Addresses->$Branch->$Address);
:set CntRenew ($CntRenew + 1);
} else={
:if ($Failure = false) do={
$LogPrintVerbose debug $ScriptName ("Removing IPv4 address from list '" . $FwListName . \
"': " . $Address);
$LogPrintVerbose debug $ScriptName ("Removing IPv4 address " . $Address . \
" from list '" . $FwListName . ".");
/ip/firewall/address-list/remove $Entry;
:set CntRemove ($CntRemove + 1);
}
@ -156,15 +156,15 @@
:local Branch [ $GetBranch $Address ];
:local TimeOut ($IPv6Addresses->$Branch->$Address);
:if ([ :typeof $TimeOut ] = "time") do={
$LogPrintVerbose debug $ScriptName ("Renewing IPv6 address in list '" . $FwListName . \
"' with " . $TimeOut . ": " . $Address);
$LogPrintVerbose debug $ScriptName ("Renewing IPv6 address " . $Address . \
" in list '" . $FwListName . "' with " . $TimeOut . ".");
/ipv6/firewall/address-list/set $Entry timeout=$TimeOut;
:set ($IPv6Addresses->$Branch->$Address);
:set CntRenew ($CntRenew + 1);
} else={
:if ($Failure = false) do={
$LogPrintVerbose debug $ScriptName ("Removing IPv6 address from list '" . $FwListName . \
"': " . $Address);
$LogPrintVerbose debug $ScriptName ("Removing IPv6 address " . $Address . \
" from list '" . $FwListName .".");
/ipv6/firewall/address-list/remove $Entry;
:set CntRemove ($CntRemove + 1);
}
@ -174,15 +174,15 @@
:foreach BranchName,Branch in=$IPv4Addresses do={
$LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName);
:foreach Address,Timeout in=$Branch do={
$LogPrintVerbose debug $ScriptName ("Adding IPv4 address to list '" . $FwListName . \
"' with " . $Timeout . ": " . $Address);
:do {
$LogPrintVerbose debug $ScriptName ("Adding IPv4 address " . $Address . \
" to list '" . $FwListName . "' with " . $Timeout . ".");
:onerror Err {
/ip/firewall/address-list/add list=$FwListName comment=$ListComment \
address=$Address timeout=$Timeout;
:set CntAdd ($CntAdd + 1);
} on-error={
$LogPrint warning $ScriptName ("Failed to add IPv4 address to list '" . $FwListName . \
"': " . $Address);
} do={
$LogPrint warning $ScriptName ("Failed to add IPv4 address " . $Address . \
" to list '" . $FwListName . "': " . $Err);
}
}
}
@ -190,15 +190,15 @@
:foreach BranchName,Branch in=$IPv6Addresses do={
$LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName);
:foreach Address,Timeout in=$Branch do={
$LogPrintVerbose debug $ScriptName ("Adding IPv6 address to list '" . $FwListName . \
"' with " . $Timeout . ": " . $Address);
:do {
$LogPrintVerbose debug $ScriptName ("Adding IPv6 address " . $Address . \
" to list '" . $FwListName . "' with " . $Timeout . ".");
:onerror Err {
/ipv6/firewall/address-list/add list=$FwListName comment=$ListComment \
address=$Address timeout=$Timeout;
:set CntAdd ($CntAdd + 1);
} on-error={
$LogPrint warning $ScriptName ("Failed to add IPv6 address to list '" . $FwListName . \
"': " . $Address);
} do={
$LogPrint warning $ScriptName ("Failed to add IPv6 address " . $Address . \
" to list '" . $FwListName . "': " . $Err);
}
}
}
@ -209,6 +209,6 @@
" - renewed: " . [ $HumanReadableNum $CntRenew 1000 ] . \
" - removed: " . [ $HumanReadableNum $CntRemove 1000 ]);
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -6,6 +6,12 @@
# global configuration
# https://rsc.eworm.de/
# Warning: Do *NOT* copy this line to overlay!
:global GlobalConfigReady false;
# || ... but
# \||/ start
# \/ here!
# Set this to 'true' to disable news and change notifications.
:global NoNewsAndChangesNotification false;
@ -264,14 +270,20 @@
"cert2-cn"="4n0th3r-s3cr3t";
};
# /\ Warning: Do *NOT* copy
# /\7\ the code below to overlay!
# /_()_\ Things *will* break!
#
# load custom settings from overlay and snippets
# Warning: Do *NOT* copy this code to overlay!
:foreach Script in=([ /system/script/find where name="global-config-overlay" ], \
[ /system/script/find where name~"^global-config-overlay.d/" ]) do={
:do {
:onerror Err {
/system/script/run $Script;
} on-error={
} do={
:log error ("Loading configuration from overlay or snippet " . \
[ /system/script/get $Script name ] . " failed!");
[ /system/script/get $Script name ] . " failed: " . $Err);
}
}
# signal we are ready
:set GlobalConfigReady true;

View file

@ -391,25 +391,22 @@
:local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile);
$LogPrint info $0 ("Downloading package file '" . $PkgName . "'...");
$LogPrint debug $0 ("... from url: " . $Url);
:local Retry 3;
:while ($Retry > 0) do={
:do {
/tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest;
$WaitForFile $PkgDest;
:if ([ /file/get [ find where name=$PkgDest ] type ] = "package") do={
:return true;
}
} on-error={
$LogPrint debug $0 ("Downloading package file failed.");
}
$RmFile $PkgDest;
:set Retry ($Retry - 1);
:onerror Err {
/tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest;
$WaitForFile $PkgDest;
} do={
$LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed: " . $Err);
:return false;
}
$LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed.");
:return false;
:if ([ /file/get [ find where name=$PkgDest ] type ] != "package") do={
$LogPrint warning $0 ("Downloaded file is not a package, removing.");
$RmFile $PkgDest;
:return false;
}
:return true;
}
# return either first (if "true") or second
@ -452,13 +449,15 @@
:set ExitError do={
:local ExitOK [ :tostr $1 ];
:local Name [ :tostr $2 ];
:local Error [ :tostr $3 ];
:global IfThenElse;
:global LogPrint;
:if ($ExitOK = "false") do={
$LogPrint error $Name ([ $IfThenElse ([ :pick $Name 0 1 ] = "\$") \
"Function" "Script" ] . " '" . $Name . "' exited with error.");
"Function" "Script" ] . " '" . $Name . "' exited with error" . \
[ $IfThenElse (!($Error ~ "^(|true|false)\$")) (": " . $Error) "." ]);
}
}
@ -487,14 +486,14 @@
}
:local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
:do {
:onerror Err {
/tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) as-value;
} on-error={
} do={
:if ([ $WaitForFile $FileName 500ms ] = true) do={
$RmFile $FileName;
}
$LogPrint debug $0 ("Failed downloading from: " . $Url);
$LogPrint debug $0 ("Failed downloading from " . $Url . " - " . $Err);
$RmDir $DirName;
:return false;
}
@ -587,12 +586,12 @@
("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data");
:return $Vendor;
} on-error={
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \
output=none as-value;
$LogPrint debug $0 ("The mac vendor is not known in database.");
} on-error={
$LogPrint warning $0 ("Failed getting mac vendor.");
} do={
$LogPrint warning $0 ("Failed getting mac vendor: " . $Err);
}
:return "unknown vendor";
}
@ -895,11 +894,11 @@
$LogPrint info $0 ("Creating disk of type tmpfs.");
$RmDir "tmpfs";
:do {
:onerror Err {
/disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3);
$WaitForFile "tmpfs";
} on-error={
$LogPrint warning $0 ("Creating disk of type tmpfs failed!");
} do={
$LogPrint warning $0 ("Creating disk of type tmpfs failed: " . $Err);
:return false;
}
:return true;
@ -924,11 +923,11 @@
}
}
:do {
:onerror Err {
/file/add type="directory" name=$Path;
$WaitForFile $Path;
} on-error={
$LogPrint warning $0 ("Making directory '" . $Path . "' failed!");
} do={
$LogPrint warning $0 ("Making directory '" . $Path . "' failed: " . $Err);
:return false;
}
@ -1053,10 +1052,10 @@
:return true;
}
:do {
:onerror Err {
/file/remove $Dir;
} on-error={
$LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed.");
} do={
$LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed: " . $Err);
:return false;
}
:return true;
@ -1081,10 +1080,10 @@
:return true;
}
:do {
:onerror Err {
/file/remove $File;
} on-error={
$LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed.");
} do={
$LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed: " . $Err);
:return false;
}
:return true;
@ -1117,13 +1116,15 @@
}
# install new scripts, update existing scripts
:set ScriptInstallUpdate do={ :do {
:set ScriptInstallUpdate do={ :onerror Err {
:local Scripts [ :toarray $1 ];
:local NewComment [ :tostr $2 ];
:global CommitId;
:global CommitInfo;
:global ExpectedConfigVersion;
:global GlobalConfigReady;
:global GlobalFunctionsReady;
:global Identity;
:global IDonate;
:global NoNewsAndChangesNotification;
@ -1157,8 +1158,7 @@
:local CommitIdBefore $CommitId;
:local ExpectedConfigVersionBefore $ExpectedConfigVersion;
:local ReloadGlobalFunctions false;
:local ReloadGlobalConfig false;
:local ReloadGlobal false;
:local DeviceMode [ /system/device-mode/get ];
:local CheckSums ({});
@ -1201,7 +1201,7 @@
}
}
:do {
:onerror Err {
:local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ];
:local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ];
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
@ -1211,13 +1211,11 @@
:if ($Result->"status" = "finished") do={
:set SourceNew [ :tolf ($Result->"data") ];
}
} on-error={
} do={
$LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . . "': " . $Err);
:if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={
$LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \
"', removing dummy. Typo on installation?");
$LogPrint warning $0 ("Removing dummy. Typo on installation?");
/system/script/remove $Script;
} else={
$LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!");
}
:error false;
}
@ -1267,31 +1265,25 @@
$LogPrint info $0 ("Updating script: " . $ScriptVal->"name");
/system/script/set owner=($ScriptVal->"name") \
source=[ $IfThenElse ($ScriptUpdatesCRLF = true) $SourceCRLF $SourceNew ] $Script;
:if ($ScriptVal->"name" = "global-config") do={
:set ReloadGlobalConfig true;
}
:if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={
:set ReloadGlobalFunctions true;
:if ($ScriptVal->"name" = "global-config" || \
$ScriptVal->"name" = "global-functions" || \
$ScriptVal->"name" ~ ("^mod/.")) do={
:set ReloadGlobal true;
}
} on-error={ }
}
:if ($ReloadGlobalFunctions = true) do={
$LogPrint info $0 ("Reloading global functions.");
:do {
/system/script/run global-functions;
} on-error={
$LogPrint error $0 ("Reloading global functions failed!");
}
}
:if ($ReloadGlobal = true) do={
$LogPrint info $0 ("Reloading global configuration and functions.");
:set GlobalConfigReady false;
:set GlobalFunctionsReady false;
:delay 1s;
:if ($ReloadGlobalConfig = true) do={
$LogPrint info $0 ("Reloading global configuration.");
:do {
:onerror Err {
/system/script/run global-config;
} on-error={
$LogPrint error $0 ("Reloading global configuration failed!" . \
" Syntax error or missing overlay?");
/system/script/run global-functions;
} do={
$LogPrint error $0 ("Reloading global configuration and functions failed! " . $Err);
}
}
@ -1310,7 +1302,7 @@
:global GlobalConfigMigration;
:local ChangeLogCode;
:do {
:onerror Err {
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
$LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \
@ -1318,16 +1310,16 @@
:if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data");
}
} on-error={
$LogPrint warning $0 ("Failed fetching news, changes and migration!");
} do={
$LogPrint warning $0 ("Failed fetching news, changes and migration: " . $Err);
}
:if ([ :len $ChangeLogCode ] > 0) do={
:if ([ $ValidateSyntax $ChangeLogCode ] = true) do={
:do {
:onerror Err {
[ :parse $ChangeLogCode ];
} on-error={
$LogPrint warning $0 ("The changelog failed to run!");
} do={
$LogPrint warning $0 ("The changelog failed to run: " . $Err);
}
} else={
$LogPrint warning $0 ("The changelog failed syntax validation!");
@ -1349,10 +1341,10 @@
}
$LogPrint info $0 ("Applying migration for change " . $I . ": " . $Migration);
:do {
:onerror Err {
[ :parse $Migration ];
} on-error={
$LogPrint warning $0 ("Migration code for change " . $I . " failed to run!");
} do={
$LogPrint warning $0 ("Migration code for change " . $I . " failed to run: " . $Err);
}
} on-error={ }
}
@ -1394,8 +1386,8 @@
:set GlobalConfigChanges;
:set GlobalConfigMigration;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# lock script against multiple invocation
@ -1536,12 +1528,12 @@
}
# send notification via NotificationFunctions - expects at least two string arguments
:set SendNotification do={ :do {
:set SendNotification do={ :onerror Err {
:global SendNotification2;
$SendNotification2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via NotificationFunctions - expects one array argument
@ -1660,9 +1652,12 @@
:set ValidateSyntax do={
:local Code [ :tostr $1 ];
:do {
:global LogPrint;
:onerror Err {
[ :parse (":local Validate do={\n" . $Code . "\n}") ];
} on-error={
} do={
$LogPrint debug $0 ("Valdation failed: " . $Err);
:return false;
}
:return true;
@ -1776,10 +1771,10 @@
:foreach Script in=[ /system/script/find where name ~ "^mod/." ] do={
:local ScriptVal [ /system/script/get $Script ];
:if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={
:do {
:onerror Err {
/system/script/run $Script;
} on-error={
$LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.");
} do={
$LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run: " . $Err);
}
} else={
$LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.");

View file

@ -8,5 +8,6 @@
# wait for global-functions to finish
# https://rsc.eworm.de/doc/global-wait.md
:global GlobalConfigReady;
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:while ($GlobalConfigReady != true || $GlobalFunctionsReady != true) do={ :delay 500ms; }

View file

@ -9,11 +9,11 @@
# track gps data by sending json data to http server
# https://rsc.eworm.de/doc/gps-track.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global GpsTrackUrl;
@ -34,7 +34,7 @@
:local Gps [ /system/gps/monitor once as-value ];
:if ($Gps->"valid" = true) do={
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=({ [ $FetchUserAgentStr $ScriptName ]; "Content-Type: application/json" }) \
http-data=[ :serialize to=json { "identity"=$Identity; \
@ -42,12 +42,12 @@
$LogPrint debug $ScriptName ("Sending GPS data in " . $CoordinateFormat . " format: " . \
"lat: " . ($Gps->"latitude") . " " . \
"lon: " . ($Gps->"longitude"));
} on-error={
$LogPrint warning $ScriptName ("Failed sending GPS data!");
} do={
$LogPrint warning $ScriptName ("Failed sending GPS data: " . $Err);
}
} else={
$LogPrint debug $ScriptName ("GPS data not valid.");
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -75,6 +75,6 @@
/ip/dhcp-server/lease/remove $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -13,11 +13,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -82,6 +82,6 @@
/ip/dhcp-server/lease/remove $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -75,6 +75,6 @@
/ip/dhcp-server/lease/remove $Lease;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -100,6 +100,6 @@
:delay 2s;
/caps-man/access-list/set $Entry action=accept;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,11 +12,11 @@
# !! This is just a template to generate the real script!
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -120,6 +120,6 @@
:delay 2s;
/caps-man/access-list/set $Entry action=accept;
/interface/wifi/access-list/set $Entry action=accept;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
#
# !! Do not edit this file, it is generated from template!
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global EitherOr;
@ -97,6 +97,6 @@
:delay 2s;
/interface/wifi/access-list/set $Entry action=accept;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# and add/remove/update DNS entries from IPSec mode-config
# https://rsc.eworm.de/doc/ipsec-to-dns.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Domain;
@ -79,6 +79,6 @@
/ip/dns/static/add name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# update firewall and dns settings on IPv6 prefix change
# https://rsc.eworm.de/doc/ipv6-update.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -102,6 +102,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# run scripts on DHCP lease
# https://rsc.eworm.de/doc/lease-script.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Grep;
@ -53,13 +53,13 @@
}
:foreach Order,Script in=$RunOrder do={
:do {
:onerror Err {
$LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script);
/system/script/run $Script;
} on-error={
$LogPrint warning $ScriptName ("Running script '" . $Script . "' failed!");
} do={
$LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err);
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# forward log messages via notification
# https://rsc.eworm.de/doc/log-forward.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -108,6 +108,6 @@
:local LogAll [ /log/find ];
:set LogForwardLast ($LogAll->([ :len $LogAll ] - 1) );
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -10,7 +10,7 @@
:global BridgePortTo;
:set BridgePortTo do={ :do {
:set BridgePortTo do={ :onerror Err {
:local BridgePortTo [ :tostr $1 ];
:global IfThenElse;
@ -65,6 +65,6 @@
$LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }

View file

@ -10,7 +10,7 @@
:global BridgePortVlan;
:global BridgePortVlan do={ :do {
:global BridgePortVlan do={ :onerror Err {
:local ConfigTo [ :tostr $1 ];
:global IfThenElse;
@ -74,6 +74,6 @@
$LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }

View file

@ -12,12 +12,12 @@
:global InspectVarReturn;
# inspect variable and print on terminal
:set InspectVar do={ :do {
:set InspectVar do={ :onerror Err {
:global InspectVarReturn;
:put [ :tocrlf [ $InspectVarReturn $1 ] ];
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# inspect variable and return formatted string
@ -25,6 +25,7 @@
:local Input $1;
:local Level (0 + [ :tonum $2 ]);
:global CharacterReplace;
:global IfThenElse;
:global InspectVarReturn;
@ -33,14 +34,13 @@
:local Value [ :tostr $2 ];
:local Level [ :tonum $3 ];
:local Indent "";
:for I from=1 to=$Level step=1 do={
:set Indent ($Indent . " ");
}
:return ($Indent . "-" . $Prefix . "-> " . $Value);
:global CharacterMultiply;
:return ([ $CharacterMultiply " " $Level ] . "-" . $Prefix . "-> " . $Value);
}
:local TypeOf [ :typeof $Input ];
:local Len [ :len $Input ];
:local Return [ $IndentReturn "type" $TypeOf $Level ];
:if ($TypeOf = "array") do={
@ -50,6 +50,16 @@
[ $InspectVarReturn $Value ($Level + 2) ]);
}
} else={
:if ($TypeOf = "str") do={
:set $Return ($Return . "\n" . \
[ $IndentReturn "len" $Len $Level ]);
:if ([ :typeof [ :find $Input ("\r") ] ] = "num") do={
:set Input [ $CharacterReplace $Input ("\r") "" ];
}
:if ([ :typeof [ :find $Input ("\n") ] ] = "num") do={
:set Input [ $CharacterReplace $Input ("\n") " " ];
}
}
:if ($TypeOf != "nothing") do={
:set $Return ($Return . "\n" . \
[ $IndentReturn "value" [ $IfThenElse ([ :len $Input ] > 80) \

View file

@ -12,7 +12,7 @@
:global IPCalcReturn;
# print netmask, network, min host, max host and broadcast
:set IPCalc do={ :do {
:set IPCalc do={ :onerror Err {
:local Input [ :tostr $1 ];
:global FormatLine;
@ -27,8 +27,8 @@
[ $FormatLine "HostMin" ($Values->"hostmin") ] . "\n" . \
[ $FormatLine "HostMax" ($Values->"hostmax") ] . "\n" . \
[ $FormatLine "Broadcast" ($Values->"broadcast") ]) ];
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# calculate and return netmask, network, min host, max host and broadcast

View file

@ -35,7 +35,7 @@
}
# flush e-mail queue
:set FlushEmailQueue do={ :do {
:set FlushEmailQueue do={ :onerror Err {
:global EmailQueue;
:global EitherOr;
@ -89,35 +89,40 @@
:foreach Id,Message in=$EmailQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:local Attach ({});
:while ([ /tool/e-mail/get last-status ] = "in-progress") do={ :delay 1s; }
:foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={
:if ([ :len [ /file/find where name=$File ] ] = 1) do={
:set Attach ($Attach, $File);
} else={
$LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach.");
}
}
/tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \
subject=($Message->"subject") body=($Message->"body") file=$Attach;
:local Wait true;
:do {
:delay 1s;
:local Status [ /tool/e-mail/get last-status ];
:if ($Status = "succeeded") do={
:set ($EmailQueue->$Id);
:set Wait false;
:if (($Message->"remove-attach") = true) do={
:foreach File in=$Attach do={
/file/remove $File;
}
:onerror Err {
:local Attach ({});
:foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={
:if ([ :len [ /file/find where name=$File ] ] = 1) do={
:set Attach ($Attach, $File);
} else={
$LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach.");
}
}
:if ($Status = "failed") do={
:set AllDone false;
:set Wait false;
}
} while=($Wait = true);
/tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \
subject=($Message->"subject") body=($Message->"body") file=$Attach;
:local Wait true;
:do {
:delay 1s;
:local Status [ /tool/e-mail/get last-status ];
:if ($Status = "succeeded") do={
:set ($EmailQueue->$Id);
:set Wait false;
:if (($Message->"remove-attach") = true) do={
:foreach File in=$Attach do={
/file/remove $File;
}
}
}
:if ($Status = "failed") do={
:set AllDone false;
:set Wait false;
}
} while=($Wait = true);
} do={
$LogPrint warning $0 ("Sending queued mail failed: " . $Err);
:set AllDone false;
}
}
}
@ -135,8 +140,8 @@
/system/scheduler/set interval=(($SchedVal->"run-count") . "m") \
comment="Waiting for retry..." $Scheduler;
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# generate filter for log-forward
@ -176,6 +181,7 @@
:global IfThenElse;
:global NotificationEMailSignature;
:global NotificationEMailSubject;
:global SymbolForNotification;
:local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ];
:local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ];
@ -188,13 +194,23 @@
:if ([ :typeof $EmailQueue ] = "nothing") do={
:set EmailQueue ({});
}
:local Truncated false;
:local Body ($Notification->"message");
:if ([ :len $Body ] > 62000) do={
:set Body ([ :pick $Body 0 62000 ] . "...");
:set Truncated true;
}
:local Signature [ $EitherOr [ $NotificationEMailSignature ] [ /system/note/get note ] ];
:set Body ($Body . "\n" . \
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) \
("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ] . \
[ $IfThenElse ($Truncated = true) ("\n" . [ $SymbolForNotification "scissors" ] . \
"The message was too long and has been truncated!") ] . \
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]);
:set ($EmailQueue->[ :len $EmailQueue ]) {
to=$To; cc=$Cc;
subject=[ $NotificationEMailSubject ($Notification->"subject") ];
body=(($Notification->"message") . \
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \
body=$Body; \
attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") };
:if ([ :len [ /system/scheduler/find where name="_FlushEmailQueue" ] ] = 0) do={
/system/scheduler/add name="_FlushEmailQueue" interval=1s start-time=startup \
@ -248,12 +264,12 @@
}
# send notification via e-mail - expects at least two string arguments
:set SendEMail do={ :do {
:set SendEMail do={ :onerror Err {
:global SendEMail2;
$SendEMail2 ({ origin=$0; subject=$1; message=$2; link=$3 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via e-mail - expects one array argument

View file

@ -17,7 +17,7 @@
:global SendGotify2;
# flush Gotify queue
:set FlushGotifyQueue do={ :do {
:set FlushGotifyQueue do={ :onerror Err {
:global GotifyQueue;
:global IsFullyConnected;
@ -37,13 +37,13 @@
:foreach Id,Message in=$GotifyQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=($Message->"headers") http-data=[ :serialize to=json ($Message->"message") ] \
($Message->"url") as-value;
:set ($GotifyQueue->$Id);
} on-error={
$LogPrint debug $0 ("Sending queued Gotify message failed.");
} do={
$LogPrint debug $0 ("Sending queued Gotify message failed: " . $Err);
:set AllDone false;
}
}
@ -53,8 +53,8 @@
/system/scheduler/remove [ find where name="_FlushGotifyQueue" ];
:set GotifyQueue;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via Gotify - expects one array argument
@ -91,11 +91,11 @@
("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ]); \
"priority"=[ :tonum [ $IfThenElse ($Notification->"silent") 2 5 ] ] });
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=$Headers http-data=[ :serialize to=json $Message ] $Url as-value;
} on-error={
$LogPrint info $0 ("Failed sending Gotify notification! Queuing...");
} do={
$LogPrint info $0 ("Failed sending Gotify notification: " . $Err . " - Queuing...");
:if ([ :typeof $GotifyQueue ] = "nothing") do={
:set GotifyQueue ({});
@ -121,12 +121,12 @@
}
# send notification via Gotify - expects at least two string arguments
:set SendGotify do={ :do {
:set SendGotify do={ :onerror Err {
:global SendGotify2;
$SendGotify2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via Gotify - expects one array argument

View file

@ -19,7 +19,7 @@
:global SetupMatrixJoinRoom;
# flush Matrix queue
:set FlushMatrixQueue do={ :do {
:set FlushMatrixQueue do={ :onerror Err {
:global MatrixQueue;
:global IsFullyConnected;
@ -39,7 +39,7 @@
:foreach Id,Message in=$MatrixQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none \
http-header-field=($Message->"headers") http-method=post \
http-data=[ :serialize to=json { "msgtype"="m.text"; "body"=($Message->"plain");
@ -47,8 +47,8 @@
("https://" . $Message->"homeserver" . "/_matrix/client/r0/rooms/" . $Message->"room" . \
"/send/m.room.message?access_token=" . $Message->"accesstoken") as-value;
:set ($MatrixQueue->$Id);
} on-error={
$LogPrint debug $0 ("Sending queued Matrix message failed.");
} do={
$LogPrint debug $0 ("Sending queued Matrix message failed: " . $Err);
:set AllDone false;
}
}
@ -58,8 +58,8 @@
/system/scheduler/remove [ find where name="_FlushMatrixQueue" ];
:set MatrixQueue;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via Matrix - expects one array argument
@ -129,15 +129,15 @@
[ $PrepareText $Label ] . "</a>");
}
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none \
http-header-field=$Headers http-method=post \
http-data=[ :serialize to=json { "msgtype"="m.text"; "body"=$Plain;
"format"="org.matrix.custom.html"; "formatted_body"=$Formatted } ] \
("https://" . $HomeServer . "/_matrix/client/r0/rooms/" . $Room . \
"/send/m.room.message?access_token=" . $AccessToken) as-value;
} on-error={
$LogPrint info $0 ("Failed sending Matrix notification! Queuing...");
} do={
$LogPrint info $0 ("Failed sending Matrix notification: " . $Err . " - Queuing...");
:if ([ :typeof $MatrixQueue ] = "nothing") do={
:set MatrixQueue ({});
@ -167,12 +167,12 @@
}
# send notification via Matrix - expects at least two string arguments
:set SendMatrix do={ :do {
:set SendMatrix do={ :onerror Err {
:global SendMatrix2;
$SendMatrix2 ({ origin=$0; subject=$1; message=$2; link=$3 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via Matrix - expects one array argument
@ -196,14 +196,14 @@
:global MatrixHomeServer;
:local Domain [ :pick $User ([ :find $User ":" ] + 1) [ :len $User] ];
:do {
:onerror Err {
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
http-header-field=({ [ $FetchUserAgentStr $0 ] }) \
("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data");
:set MatrixHomeServer ([ :deserialize from=json value=$Data ]->"m.homeserver"->"base_url");
$LogPrint debug $0 ("Home server is: " . $MatrixHomeServer);
} on-error={
$LogPrint error $0 ("Failed getting home server!");
} do={
$LogPrint error $0 ("Failed getting home server: " . $Err);
:return false;
}
@ -211,27 +211,27 @@
:set MatrixHomeServer [ :pick $MatrixHomeServer 8 [ :len $MatrixHomeServer ] ];
}
:do {
:onerror Err {
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
http-header-field=({ [ $FetchUserAgentStr $0 ] }) http-method=post \
http-data=[ :serialize to=json { "type"="m.login.password"; "user"=$User; "password"=$Pass } ] \
("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data");
:set MatrixAccessToken ([ :deserialize from=json value=$Data ]->"access_token");
$LogPrint debug $0 ("Access token is: " . $MatrixAccessToken);
} on-error={
$LogPrint error $0 ("Failed logging in (and getting access token)!");
} do={
$LogPrint error $0 ("Failed logging in (and getting access token): " . $Err);
:return false;
}
:do {
:onerror Err {
/system/script/remove [ find where name="global-config-overlay.d/mod/notification-matrix" ];
/system/script/add name="global-config-overlay.d/mod/notification-matrix" source=( \
"# configuration snippet: mod/notification-matrix\n\n" . \
":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \
":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n");
$LogPrint info $0 ("Added configuration snippet. Now create and join a room, please!");
} on-error={
$LogPrint error $0 ("Failed adding configuration snippet!");
} do={
$LogPrint error $0 ("Failed adding configuration snippet: " . $Err);
:return false;
}
}
@ -248,24 +248,24 @@
:global MatrixHomeServer;
:global MatrixRoom;
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none \
http-header-field=({ [ $FetchUserAgentStr $0 ] }) http-method=post http-data="" \
("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \
"/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value;
$LogPrint debug $0 ("Joined the room.");
} on-error={
$LogPrint error $0 ("Failed joining the room!");
} do={
$LogPrint error $0 ("Failed joining the room: " . $Err);
:return false;
}
:do {
:onerror Err {
:local Snippet [ /system/script/find where name="global-config-overlay.d/mod/notification-matrix" ];
/system/script/set $Snippet source=([ get $Snippet source ] . \
":global MatrixRoom \"" . $MatrixRoom . "\";\n");
$LogPrint info $0 ("Appended configuration to configuration snippet. Please review!");
} on-error={
$LogPrint error $0 ("Failed appending configuration to snippet!");
} do={
$LogPrint error $0 ("Failed appending configuration to snippet: " . $Err);
:return false;
}
}

View file

@ -16,7 +16,7 @@
:global SendNtfy2;
# flush ntfy queue
:set FlushNtfyQueue do={ :do {
:set FlushNtfyQueue do={ :onerror Err {
:global NtfyQueue;
:global IsFullyConnected;
@ -36,13 +36,13 @@
:foreach Id,Message in=$NtfyQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
:onerror Err {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=($Message->"headers") http-data=($Message->"text") \
($Message->"url") as-value;
:set ($NtfyQueue->$Id);
} on-error={
$LogPrint debug $0 ("Sending queued Ntfy message failed.");
} do={
$LogPrint debug $0 ("Sending queued Ntfy message failed: " . $Err);
:set AllDone false;
}
}
@ -52,8 +52,8 @@
/system/scheduler/remove [ find where name="_FlushNtfyQueue" ];
:set NtfyQueue;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via ntfy - expects one array argument
@ -107,7 +107,7 @@
:set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . ($Notification->"link"));
}
:do {
:onerror Err {
:if ($Server = "ntfy.sh") do={
:if ([ $CertificateAvailable "ISRG Root X1" ] = false) do={
$LogPrint warning $0 ("Downloading required certificate failed.");
@ -116,8 +116,8 @@
}
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=$Headers http-data=$Text $Url as-value;
} on-error={
$LogPrint info $0 ("Failed sending ntfy notification! Queuing...");
} do={
$LogPrint info $0 ("Failed sending ntfy notification: " . $Err . " - Queuing...");
:if ([ :typeof $NtfyQueue ] = "nothing") do={
:set NtfyQueue ({});
@ -143,12 +143,12 @@
}
# send notification via ntfy - expects at least two string arguments
:set SendNtfy do={ :do {
:set SendNtfy do={ :onerror Err {
:global SendNtfy2;
$SendNtfy2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via ntfy - expects one array argument

View file

@ -17,7 +17,7 @@
:global SendTelegram2;
# flush telegram queue
:set FlushTelegramQueue do={ :do {
:set FlushTelegramQueue do={ :onerror Err {
:global TelegramQueue;
:global TelegramMessageIDs;
@ -38,14 +38,14 @@
:foreach Id,Message in=$TelegramQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
:onerror Err {
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \
("https://api.telegram.org/bot" . ($Message->"tokenid") . "/sendMessage") \
http-data=($Message->"http-data") as-value ]->"data");
:set ($TelegramQueue->$Id);
:set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1;
} on-error={
$LogPrint debug $0 ("Sending queued Telegram message failed.");
} do={
$LogPrint debug $0 ("Sending queued Telegram message failed: " . $Err);
:set AllDone false;
}
}
@ -55,12 +55,12 @@
/system/scheduler/remove [ find where name="_FlushTelegramQueue" ];
:set TelegramQueue;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# get the chat id
:set GetTelegramChatId do={ :do {
:set GetTelegramChatId do={ :onerror Err {
:global TelegramTokenId;
:global CertificateAvailable;
@ -72,12 +72,12 @@
}
:local Data;
:do {
:onerror Err {
:set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=0" . \
"&allowed_updates=%5B%22message%22%5D") as-value ]->"data");
} on-error={
$LogPrint warning $0 ("Fetching data failed!");
} do={
$LogPrint warning $0 ("Fetching data failed: " . $Err);
:return false;
}
@ -94,8 +94,8 @@
:if (($Message->"is_topic_message") = true) do={
$LogPrint info $0 ("The thread id is: " . ($Message->"message_thread_id"));
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via telegram - expects one array argument
@ -189,8 +189,8 @@
:local HTTPData ("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \
"&reply_to_message_id=" . ($Notification->"replyto") . "&message_thread_id=" . $ThreadId . \
"&disable_web_page_preview=true&parse_mode=MarkdownV2");
:do {
"&disable_web_page_preview=true&parse_mode=MarkdownV2");
:onerror Err {
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" ] = false) do={
$LogPrint warning $0 ("Downloading required certificate failed.");
:error false;
@ -199,8 +199,8 @@
("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \
http-data=($HTTPData . "&text=" . [ $UrlEncode $Text ]) as-value ]->"data");
:set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1;
} on-error={
$LogPrint info $0 ("Failed sending Telegram notification! Queuing...");
} do={
$LogPrint info $0 ("Failed sending Telegram notification: " . $Err . " - Queuing...");
:if ([ :typeof $TelegramQueue ] = "nothing") do={
:set TelegramQueue ({});
@ -226,12 +226,12 @@
}
# send notification via telegram - expects at least two string arguments
:set SendTelegram do={ :do {
:set SendTelegram do={ :onerror Err {
:global SendTelegram2;
$SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# send notification via telegram - expects one array argument

View file

@ -11,7 +11,7 @@
:global ScriptRunOnce;
# fetch and run script(s) once
:set ScriptRunOnce do={ :do {
:set ScriptRunOnce do={ :onerror Err {
:local Scripts [ :toarray $1 ];
:global ScriptRunOnceBaseUrl;
@ -41,16 +41,16 @@
:return false;
}
:do {
:onerror Err {
$LogPrint info $0 ("Running script '" . $Script . "' now.");
[ :parse $Source ];
} on-error={
$LogPrint warning $0 ("The script '" . $Script . "' failed to run!");
} do={
$LogPrint warning $0 ("The script '" . $Script . "' failed to run: " . $Err);
:return false;
}
:return true;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }

View file

@ -12,7 +12,7 @@
:global SSHKeysImportFile;
# import single key passed as string
:set SSHKeysImport do={ :do {
:set SSHKeysImport do={ :onerror Err {
:local Key [ :tostr $1 ];
:local User [ :tostr $2 ];
@ -55,22 +55,22 @@
/file/add name=$FileName contents=($Key . ", md5=" . $FingerPrintMD5);
$WaitForFile $FileName;
:do {
:onerror Err {
/user/ssh-keys/import public-key-file=$FileName user=$User;
$LogPrint info $0 ("Imported ssh public key (" . $KeyVal->2 . ", " . $KeyVal->0 . ", " . \
"MD5:" . $FingerPrintMD5 . ") for user '" . $User . "'.");
$RmDir "tmpfs/ssh-keys-import";
} on-error={
$LogPrint warning $0 ("Failed importing key.");
} do={
$LogPrint warning $0 ("Failed importing key: " . $Err);
$RmDir "tmpfs/ssh-keys-import";
:return false;
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
# import keys from a file
:set SSHKeysImportFile do={ :do {
:set SSHKeysImportFile do={ :onerror Err {
:local FileName [ :tostr $1 ];
:local User [ :tostr $2 ];
@ -94,9 +94,7 @@
:foreach KeyVal in=[ :deserialize $Keys delimiter=" " from=dsv options=dsv.plain ] do={
:local Continue false;
:if ($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa") do={
:do {
$SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User;
} on-error={
:if ([ $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User ] = false) do={
$LogPrint warning $0 ("Failed importing key for user '" . $User . "'.");
}
:set Continue true;
@ -109,6 +107,6 @@
$LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.");
}
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }

View file

@ -9,11 +9,11 @@
# act on multiple mode and reset button presses
# https://rsc.eworm.de/doc/mode-button.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global ModeButton;
@ -26,7 +26,7 @@
:if ([ :len $Scheduler ] = 0) do={
$LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...");
:global ModeButtonScheduler do={ :do {
:global ModeButtonScheduler do={ :onerror Err {
:local FuncName $0;
:global ModeButton;
@ -69,11 +69,11 @@
:delay 200ms;
}
:do {
:onerror Err {
[ :parse $Code ];
} on-error={
} do={
$LogPrint warning $FuncName \
("The code for " . $Count . " mode-button presses failed with runtime error!");
("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err);
}
} else={
$LogPrint warning $FuncName \
@ -82,8 +82,8 @@
} else={
$LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses.");
}
} on-error={
:global ExitError; $ExitError false $0;
} do={
:global ExitError; $ExitError false $0 $Err;
} }
/system/scheduler/add name="_ModeButtonScheduler" \
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
@ -91,6 +91,6 @@
$LogPrint debug $ScriptName ("Updating scheduler _ModeButtonScheduler...");
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# monitor and manage dns/doh with netwatch
# https://rsc.eworm.de/doc/netwatch-dns.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CertificateAvailable;
@ -118,15 +118,15 @@
}
:local Data false;
:do {
:onerror Err {
:set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
http-header-field=({ "accept: application/dns-message" }) \
url=(($DohServer->"doh-url") . "?dns=" . [ :convert to=base64 ([ :rndstr length=2 ] . \
"\01\00" . "\00\01" . "\00\00" . "\00\00" . "\00\00" . "\09doh-check\05eworm\02de\00" . \
"\00\10" . "\00\01") ]) as-value ]->"data");
} on-error={
$LogPrint warning $ScriptName ("Request to DoH server failed (network or certificate issue): " . \
($DohServer->"doh-url"));
} do={
$LogPrint warning $ScriptName ("Request to DoH server " . ($DohServer->"doh-url") . \
" failed: " . $Err);
}
:if ($Data != false) do={
@ -145,6 +145,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# monitor netwatch and send notifications
# https://rsc.eworm.de/doc/netwatch-notify.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global NetwatchNotify;
@ -38,10 +38,10 @@
:global ValidateSyntax;
:if ([ $ValidateSyntax $Hook ] = true) do={
:do {
onerror Err {
[ :parse $Hook ];
} on-error={
$LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run.");
} do={
$LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run: " . $Err);
:return ("The hook failed to run.");
}
} else={
@ -107,7 +107,7 @@
:if ([ :typeof ($HostInfo->"resolve") ] = "str") do={
:if ([ $IsDNSResolving ] = true) do={
:do {
:onerror Err {
:local Resolve [ :resolve type=[ $IfThenElse ([ :typeof ($HostVal->"host") ] = "ip") \
"ipv4" "ipv6" ] ($HostInfo->"resolve") ];
:if ($Resolve != $HostVal->"host") do={
@ -121,13 +121,13 @@
:set ($HostVal->"status") "unknown";
}
}
} on-error={
} do={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
:if ($Metric->"resolve-failcnt" = 3) do={
$LogPrint [ $IfThenElse ($HostInfo->"no-resolve-fail" != true) warning debug ] \
$ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
$HostInfo->"name") "" ] . "' failed.");
$HostInfo->"name") "" ] . "' failed: " . $Err);
}
}
}
@ -224,6 +224,6 @@
"since"=($Metric->"since") };
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# visualize ospf instance state via leds
# https://rsc.eworm.de/doc/ospf-to-leds.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -44,6 +44,6 @@
/system/leds/set type=off [ find where leds=$LED ];
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# download packages and reboot for installation
# https://rsc.eworm.de/doc/packages-update.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global BackupRandomDelay;
@ -163,6 +163,6 @@
$LogPrint info $ScriptName ("Rebooting for update.");
:delay 1s;
/system/reboot;
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# run scripts on ppp up
# https://rsc.eworm.de/doc/ppp-on-up.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
@ -39,6 +39,6 @@
$LogPrint warning $ScriptName ("Running script '" . $ScriptName . "' failed!");
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -8,11 +8,11 @@
# run action on received SMS
# https://rsc.eworm.de/doc/sms-action.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global SmsAction;
@ -36,6 +36,6 @@
} else={
$LogPrint warning $ScriptName ("The code for action '" . $Action . "' failed syntax validation!");
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# forward SMS to e-mail
# https://rsc.eworm.de/doc/sms-forward.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -61,7 +61,12 @@
:if ($Phone = $Settings->"allowed-number" && \
($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={
$LogPrint debug $ScriptName ("Removing SMS, which started a script.");
/tool/sms/inbox/remove $Sms;
:onerror Err {
/tool/sms/inbox/remove $Sms;
:delay 50ms;
} do={
$LogPrint warning $ScriptName ("Failed to remove message: " . $Err);
}
} else={
:set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \
" type " . $SmsVal->"type" . ":\n" . $SmsVal->"message");
@ -69,12 +74,12 @@
:if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={
:if ([ $ValidateSyntax ($Hook->"command") ] = true) do={
$LogPrint info $ScriptName ("Running hook '" . $Hook->"match" . "': " . $Hook->"command");
:do {
:onerror Err {
:local Command [ :parse ($Hook->"command") ];
$Command Phone=$Phone Message=($SmsVal->"message");
:set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . $Hook->"command");
} on-error={
$LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run!");
} do={
$LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run: " . $Err);
}
} else={
$LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed syntax validation!");
@ -92,10 +97,15 @@
message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \
" by " . $Identity . " from " . $Phone . ":" . $Messages) });
:foreach Sms in=$Delete do={
/tool/sms/inbox/remove $Sms;
:onerror Err {
/tool/sms/inbox/remove $Sms;
:delay 50ms;
} do={
$LogPrint warning $ScriptName ("Failed to remove message: " . $Err);
}
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -9,11 +9,11 @@
# use Telegram to chat with your Router and send commands
# https://rsc.eworm.de/doc/telegram-chat.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global Identity;
@ -33,6 +33,7 @@
:global GetRandom20CharAlNum;
:global IfThenElse;
:global LogPrint;
:global LogPrintVerbose;
:global MAX;
:global MIN;
:global MkDir;
@ -70,14 +71,14 @@
:local Data false;
:for I from=1 to=4 do={
:if ($Data = false) do={
:do {
:onerror Err {
:set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=" . \
$TelegramChatOffset->0 . "&allowed_updates=%5B%22message%22%5D") as-value ]->"data");
:set TelegramRandomDelay [ $MAX 0 ($TelegramRandomDelay - 1) ];
} on-error={
} do={
:if ($I < 4) do={
$LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try.");
$LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try: " . $Err);
:set TelegramRandomDelay [ $MIN 15 ($TelegramRandomDelay + 5) ];
:delay (($I * $I) . "s");
}
@ -96,6 +97,8 @@
:local Uptime [ /system/resource/get uptime ];
:foreach Update in=($JSON->"result") do={
:set UpdateID ($Update->"update_id");
$LogPrintVerbose debug $ScriptName ("Update " . $UpdateID . ": " . [ :serialize to=json $Update ]);
:local Message ($Update->"message");
:local IsReply ([ :typeof ($Message->"reply_to_message") ] = "string");
:local IsMyReply ($TelegramMessageIDs->[ :tostr ($Message->"reply_to_message"->"message_id") ]);
@ -107,7 +110,9 @@
:local ThreadId [ $IfThenElse ($Message->"is_topic_message") ($Message->"message_thread_id") "" ];
:foreach IdsTrusted in=($TelegramChatId, $TelegramChatIdsTrusted) do={
:if ($From->"id" = $IdsTrusted || $From->"username" = $IdsTrusted) do={
:if ($From->"id" = $IdsTrusted || \
$From->"username" = $IdsTrusted || \
$Chat->"id" = $IdsTrusted) do={
:set Trusted true;
}
}
@ -190,6 +195,6 @@
}
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -12,10 +12,10 @@
:foreach Interface in=[ /interface/lte/find where running ] do={
:local Firmware;
:local IntName [ /interface/lte/get $Interface name ];
:do {
:onerror Err {
:set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ];
} on-error={
:log debug ("Could not get latest LTE firmware version for interface " . $IntName . ".");
} do={
:log debug ("Could not get latest LTE firmware version for interface " . $IntName . ": " . $Err);
}
:if ([ :typeof $Firmware ] = "array") do={
@ -27,7 +27,7 @@
:set LTEFirmwareUpgrade;
/system/scheduler/remove ($1 . "-firmware-upgrade");
:do {
:onerror Err {
/interface/lte/firmware-upgrade $1 upgrade=yes;
:log info ("LTE firmware upgrade on '" . $1 . "' finished, waiting for reset.");
:delay 240s;
@ -36,8 +36,8 @@
($Firmware->"installed") != ($Firmware->"latest")) do={
:log warning ("LTE firmware versions still differ. Upgrade failed anyway?");
}
} on-error={
:log error ("LTE firmware upgrade on '" . $1 . "' failed.");
} do={
:log error ("LTE firmware upgrade on '" . $1 . "' failed: " . $Err);
}
}

View file

@ -9,11 +9,11 @@
# ipsec remote peer
# https://rsc.eworm.de/doc/update-gre-address.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CharacterReplace;
@ -41,6 +41,6 @@
}
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}

View file

@ -11,11 +11,11 @@
# update local address of tunnelbroker interface
# https://rsc.eworm.de/doc/update-tunnelbroker.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:local ExitOK false;
:do {
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global CertificateAvailable;
@ -41,12 +41,12 @@
:for I from=2 to=0 do={
:if ($Data = false) do={
:do {
:onerror Err {
:set Data ([ /tool/fetch check-certificate=yes-without-crl \
("https://ipv4.tunnelbroker.net/nic/update?hostname=" . $Comment->"id") \
user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data");
} on-error={
$LogPrint debug $ScriptName ("Failed downloading, " . $I . " retries pending.");
} do={
$LogPrint debug $ScriptName ("Failed downloading: " . $Err . " - " . $I . " retries pending.");
:delay 2s;
}
}
@ -69,6 +69,6 @@
/interface/6to4/set $Interface local-address=$PublicAddress;
}
}
} on-error={
:global ExitError; $ExitError $ExitOK [ :jobname ];
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}