Christian Hesse
38760d05b0
global-functions: add $IPCalc
...
[admin@MikroTik] > $IPCalc 192.168.88.188/20
Address: 192.168.88.188
Netmask: 255.255.240.0
Network: 192.168.80.0/20
HostMin: 192.168.80.1
HostMax: 192.168.95.254
Broadcast: 192.168.95.255
2020-06-23 13:19:27 +02:00
Christian Hesse
71ad56aacc
explicitly name the license
...
Copyright (C) 2013-2020 Christian Hesse <mail@eworm.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
https://www.gnu.org/licenses/#GPL
https://www.gnu.org/licenses/gpl.html
https://www.gnu.org/licenses/gpl.md
2020-06-19 22:17:42 +02:00
Christian Hesse
12015af855
global-functions: $GetRandomNumber: use $GetRandomSha256
2020-06-18 12:52:59 +02:00
Christian Hesse
529dbbe4f8
global-functions: rename $GetRandom -> $GetRandomNumber
2020-06-18 12:49:52 +02:00
Christian Hesse
a1d05f93c6
global-functions: add $GetRandomSha256
2020-06-18 12:23:50 +02:00
Christian Hesse
e871cb5a69
global-functions: add $WaitFullyConnected
2020-05-26 23:35:24 +02:00
Christian Hesse
4166bf91c3
global-functions: add $WaitDNSResolving
2020-05-26 23:34:58 +02:00
Christian Hesse
b7172b69ce
global-functions: add $DNSIsResolving
2020-05-26 23:33:49 +02:00
Christian Hesse
83a8743879
global-functions: $WaitTimeSync: replace comment with debug output
2020-05-17 23:41:54 +02:00
Christian Hesse
3179994017
global-functions: $DownloadPackage: replace comment with debug output
2020-05-17 23:40:59 +02:00
Christian Hesse
255b2a8244
global-functions: $MailServerIsUp: handle resolve errors
2020-05-15 20:34:33 +02:00
Christian Hesse
215bf78ce1
global-functions: $MailServerIsUp: remove duplicate define
2020-05-15 20:31:54 +02:00
Christian Hesse
77338563b7
global-functions: $MailServerIsUp: use prepared value
2020-05-15 20:29:15 +02:00
Christian Hesse
b5d1e7aa83
global-functions: $WaitTimeSync: run rotate-ntp less frequently
2020-05-15 20:23:14 +02:00
Christian Hesse
12a29d076f
global-functions: $WaitTimeSync: failing rotate-ntp is not fatal
...
Resolving ntp servers fais if internet connectivity is not established.
So this is not fatal, we want to catch error and fall through, then
continue.
2020-05-13 14:07:12 +02:00
Christian Hesse
378a1785f4
global-functions: $ScriptInstallUpdate: log when reloading code
2020-05-04 11:06:02 +02:00
Christian Hesse
ce4d332f55
global-functions: $DownloadPackage: support downloading bundle
2020-05-04 09:21:23 +02:00
Christian Hesse
14dd16ef5a
global-functions: $CertificateNameByCN: replace apostrophe
2020-04-24 11:09:02 +02:00
Christian Hesse
b67712cfe4
global-functions: add $WaitDefaultRouteReachable
2020-04-22 22:21:06 +02:00
Christian Hesse
999763a263
global-functions: add $DefaultRouteIsReachable
2020-04-22 22:20:42 +02:00
Christian Hesse
d6ce774fd8
global-functions: $TimeIsSync: unbreak with bundled ntp client
2020-04-22 10:08:23 +02:00
Christian Hesse
96598b2d34
global-functions: $DownloadPackage: do not re-download
2020-04-07 12:54:46 +02:00
Christian Hesse
df177212d1
global-functions: $SendTelegram: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
af77645174
global-functions: $SendEMail: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
6f354c8bb0
global-functions: $ScriptFromTerminal: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
9c3ce55ee4
global-functions: $MailServerIsUp: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
596fb5f835
global-functions: $CertificateDownload: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
7cdeb9185e
global-functions: $CertificateAvailable: use $LogPrintExit
2020-04-03 16:59:10 +02:00
Christian Hesse
324f5b0ba4
global-functions: $SendTelegram: check status of certificate download
2020-04-03 15:03:27 +02:00
Christian Hesse
e963e09114
global-functions: $GetMacVendor: check status of certificate download
2020-04-03 15:03:27 +02:00
Christian Hesse
abb97601ce
global-functions: $DownloadPackage: check status of certificate download
2020-04-03 15:03:27 +02:00
Christian Hesse
dfeaa1ed41
global-functions: $Certificate{Available,Download}: return and check status
2020-04-03 14:24:24 +02:00
Christian Hesse
afd33b8e25
global-functions: $ScriptInstallUpdate: log and print changes
2020-04-01 11:38:25 +02:00
Christian Hesse
a598cca2da
global-functions: $SendTelegram: always return a value
...
... overwise it opens a prompt "value:".
2020-03-31 13:35:59 +02:00
Christian Hesse
40970fb738
global-functions: $SendEMail: always return a value
...
... overwise it opens a prompt "value:".
2020-03-31 13:34:30 +02:00
Christian Hesse
e33b4af433
global-functions: $ScriptInstallUpdate: ignore empty scripts
...
Now that script-updates is gone we support installing new scripts with
$ScriptInstallUpdate only.
2020-03-31 12:58:13 +02:00
Christian Hesse
2363f75e7f
ask for GitHub and GitLab stars
2020-03-27 22:19:33 +01:00
Christian Hesse
1d93e92dcd
Notify about new documentation!
2020-03-27 22:12:49 +01:00
Christian Hesse
070ae8ecb5
link global-{config,config-overlay,functions} to main README
2020-03-27 22:12:49 +01:00
Christian Hesse
5f46ef7635
completely replace script-updates with $ScriptInstallUpdate
2020-03-23 14:01:20 +01:00
Christian Hesse
f50e416e49
global-functions: introduce $MkDir
...
This is a dirty hack... RouterOS does not support creating directories,
so we mis-use http server and fetch tool.
2020-03-20 09:26:12 +01:00
Christian Hesse
98585afe1c
add script 'global-wait'
...
Run this in schedulers that fire on startup without interval. Schedulers
should look something like this:
/ system scheduler {
add name=global-scripts on-event="/ system script { run global-config; run global-config-overlay; run global-functions; }" start-time=startup;
add name=bridge-port-to-default on-event="/ system script { run global-wait; run bridge-port-to-default; }" start-time=startup;
}
2020-03-12 08:40:29 +01:00
Christian Hesse
8992b18166
global-functions: $DeviceInfo: more indention
2020-03-09 09:29:36 +01:00
Christian Hesse
3d07ebde05
global-functions: $SendEMail: invert condition
2020-03-05 11:00:36 +01:00
Christian Hesse
227151e189
global-functions: $SendTelegram: invert condition
2020-03-05 11:00:36 +01:00
Christian Hesse
34db2e34db
global-functions: $SendTelegram: allow to override chatid
...
This allows to send Telegram messages to different contact or group.
Use something like this:
/system scheduler add name=netwatch-notify interval=1m start-time=startup \
on-event=":global TelegramChatIdOverride \"-1234\"; / system script run netwatch-notify; :set TelegramChatIdOverride;"
2020-03-05 10:54:48 +01:00
Christian Hesse
bf41a8d48a
always use severity 'warning', not just 'warn'
2020-03-05 09:18:23 +01:00
Christian Hesse
792eba8465
global-functions: $LogPrintExit: add debugging option
2020-03-05 08:11:17 +01:00
Christian Hesse
628ae1bd70
bridge-port-to-default: use $ParseKeyValueStore...
...
... and unbreak last commit removing delay (69352c90
).
This requires a change in configuration syntax. Change this...
comment="default:br-local, alt:br-guest"
to...
comment="default=br-local, alt=br-guest"
2020-03-03 13:32:00 +01:00
Christian Hesse
001e7eeb39
global-functions: sort alphabetically
2020-02-28 15:26:26 +01:00
Christian Hesse
3db752bc97
global-functions: $ScriptLock: use $LogPrintExit
2020-02-27 13:51:27 +01:00
Christian Hesse
ceaa83b83e
global-functions: merge $LogAnd{Error,Put} to $LogPrintExit ...
...
... and fix logging.
Logging with severity from variable (:log $severity ...) is not
possible, this is considered a syntax error. Also the 'workaround' with
parsing code failed with missing message in log.
The reliable code is a lot longer, so merge the two functions to save a
lot of duplicate code.
2020-02-26 14:19:54 +01:00
Christian Hesse
312caf3f90
global-functions: introduce $LogAndPut
2020-02-26 12:11:50 +01:00
Christian Hesse
3ebf68a08c
global-functions: $LogAndError: add severity
2020-02-26 12:09:19 +01:00
Christian Hesse
556fc2d0d3
global-functions: introduce $LogAndError
2020-02-24 19:53:15 +01:00
Christian Hesse
19b80ee063
global-functions: $WaitTimeSync: rotate ntp servers minutely
...
Signed-off-by: Christian Hesse <mail@eworm.de>
2020-02-24 13:01:45 +01:00
Christian Hesse
5fab77abad
global-functions: introduce $WaitTimeSync
2020-02-24 12:55:18 +01:00
Christian Hesse
77ec3293f0
global-functions: introduce $TimeIsSync
2020-02-24 11:06:17 +01:00
Christian Hesse
7d2239f24e
global-functions: introduce $MailServerIsUp
2020-02-24 10:48:04 +01:00
Christian Hesse
e376845b12
global-functions: introduce and use $CertificateNameByCN
2020-02-06 18:18:56 +01:00
Christian Hesse
b5f4c2c87e
global-config: drop $ScriptUpdatesConfigChangesIgnore
...
Comment or remove $GlobalConfigVersion in global-config-overlay
to disable change notifications.
2020-02-04 20:19:46 +01:00
Christian Hesse
03af7d6d9c
global-functions: $CharacterReplace: do not limit string length
...
I've tried something like this to update a device:
/ system script set source=[ $CharacterReplace [ get global-config-overlay source ] "GlobalConfigVersion 10" "GlobalConfigVersion 11" ] global-config-overlay;
This broke with global-config-overlay longer than 999 characters. So makes
sure there is no limit for string length.
2020-02-03 21:29:21 +01:00
Christian Hesse
7f81734006
global-functions: $CertificateAvailable: simplify loop
2020-02-02 15:16:36 +01:00
Christian Hesse
1e72f03e5e
README: update instructions to use $ScriptInstallUpdate
2020-01-29 22:14:56 +01:00
Christian Hesse
c500243c97
global-functions: add $ScriptInstallUpdate
...
Just call without parameters to update scripts:
[admin@MikroTik] > $InstallAndUpdate
Add comma separated list of scripts to install and update:
[admin@MikroTik] > $InstallAndUpdate cloud-backup[,upload-backup][,...]
2020-01-29 21:44:41 +01:00
Christian Hesse
352818ea48
global-functions: $CertificateAvailable: check whole chain
...
The root certificate is a self-signed certificate. Check for the issue
certificate until we find the self-signed one.
2020-01-29 21:08:10 +01:00
Christian Hesse
801dce05fa
global-functions: $CertificateAvailable: warn about crl download to flash
...
Downloading certificate crls to flash can fill up all available space.
So warn about it!
2020-01-29 09:27:00 +01:00
Christian Hesse
5741924cf9
global-functions: replace deprecated keep-result=no with output=none
2020-01-28 21:51:27 +01:00
Christian Hesse
b3a76c7e4b
global-functions: $CertificateDownload: properly name new certificates
2020-01-06 10:20:19 +01:00
Christian Hesse
cf79e6c473
global-functions: do not encode dash, dot, slash and underscore
2020-01-03 11:24:12 +01:00
Christian Hesse
b1b7ed83ed
global-functions: $Certificate*: add quoting around CN
2020-01-03 10:15:34 +01:00
Christian Hesse
cb1e520965
global-functions: split $CertificateAvailable to $CertificateDownload
...
This allows to force download even if certificate is available. We need
this for a clean update path with Let's Encrypt.
2020-01-03 10:07:55 +01:00
Christian Hesse
afb9839073
update copyright for 2020
2020-01-01 17:00:39 +01:00
Christian Hesse
d064bd349e
global-functions: define first, set later
2019-12-10 14:45:35 +01:00
Christian Hesse
64341690bf
global-functions: $DownloadPackage: retry on error
2019-12-05 13:20:26 +01:00
Christian Hesse
ebd5ff9bfe
global-functions: introduce $ScriptFromTerminal
...
Checking whether or not started from terminal is tricky... We have to find
the job for the script, find its top most parent and get its type.
2019-12-03 23:45:55 +01:00
Christian Hesse
ac6c132ea0
global-functions: $DeviceInfo: append revision to model
2019-11-28 10:49:21 +01:00
Christian Hesse
7c0c27c03f
global-functions: add architecture in device info
2019-10-28 13:15:10 +01:00
Christian Hesse
f40bb2c8c8
check-health: make threshold for voltage configurable
2019-10-14 19:13:31 +02:00
Christian Hesse
1cee36a911
introduce global-config-overlay
2019-09-12 21:29:41 +02:00
Michael Gisbers
2258087aab
global-functions: $DeviceInfo: handle configuration version
2019-09-12 21:29:41 +02:00
Christian Hesse
94581741f4
global-functions: introduce and use $DeviceInfo
2019-09-12 21:29:41 +02:00
Christian Hesse
166bbffe1d
script-updates: add donation hint in configuration warning notification
2019-08-30 14:10:58 +02:00
Christian Hesse
29dc1b8841
add script 'check-health'
...
This may be incomplete... Please report if you have missing PSUs,
ttemperature sensors, whatever.
2019-08-27 12:01:32 +02:00
Christian Hesse
06b93ca6c2
global-functions: support sending silent telegram notifications
2019-08-18 21:30:59 +02:00
Christian Hesse
d457421e1e
global-functions: split off $SendEMail and $SendTelegram
2019-08-18 21:30:59 +02:00
Christian Hesse
ab4aef4dfb
global-functions: $DownloadPackage: re-introduce check for valid package
...
Even if fetch tool does its job right now... Chances are that the
download servers have corrupted or empty files.
2019-08-01 18:45:54 +02:00
Christian Hesse
acce2322c3
global-functions: add $RandomDelay
2019-07-26 18:14:33 +02:00
Christian Hesse
f49b67f5e7
global-functions: add $GetRandom
2019-07-26 18:13:59 +02:00
Christian Hesse
229dc539cc
global-functions: $DownloadPackage: fix downloading for CHR / x86_64
2019-07-19 15:37:01 +02:00
Christian Hesse
8d1313f588
add script 'upload-backup'
2019-07-19 11:46:29 +02:00
Christian Hesse
f79ba55637
global-functions: add $ParseKeyValueStore
2019-07-17 16:27:21 +02:00
Christian Hesse
16f04ee7ee
global-functions: $CharacterReplace: use same condition in loop
2019-07-16 12:46:33 +02:00
Christian Hesse
b1b53e3d0d
global-functions: append system note in e-mail signature
2019-07-16 12:42:40 +02:00
Christian Hesse
5101d57d52
backup: split off cloud-backup
...
Currently backup to MikroTik cloud is pretty unreliable and script can
not catch errors at runtime. Looks like this does not change any time
soon (Ticket#2019052022003204).
So let's just split off the cloud backup to make sure email backup works
as expected.
2019-06-14 15:13:41 +02:00
Christian Hesse
42834e9de1
global-functions: $CertificateAvailable: fetch by CommonName
...
Now that we have a proper $UrlEncode function... Fetch certificates
by CommonName.
Also remove the PEM after import.
2019-04-30 16:52:53 +02:00
Christian Hesse
7f96e5c966
global-functions: add $WaitForFile, wait for file on fetch
...
The fetch command is asynchronous, the file is not guaranteed to be
available when command terminates.
I opened an issue at Mikrotik support (Ticket#2019041722004999),
their answer:
> You should perform a check in a loop.
> :delay until file exist
>
> That can happen also with any configuration not just files.
So add a function to wait for a file with given name.
I have not seen this with other configuration, though.
2019-04-30 16:52:53 +02:00
Christian Hesse
b93d4d40bc
drop deprecated mode= for fetch
2019-04-09 18:01:44 +02:00
Christian Hesse
ea73505ecc
script-updates: send global-config changes notification just once
2019-04-03 08:30:28 +02:00
Christian Hesse
7b1c275cc2
script-updates: add option to ignore global-config changes
2019-04-02 08:48:35 +02:00
Christian Hesse
594aef2aab
check-certificates: support multiple passphrases
2019-04-01 22:45:38 +02:00
Christian Hesse
26ccf41298
global-functions: prevent infinite loop
2019-03-28 12:36:12 +01:00
Christian Hesse
72d7050423
global-functions: encode all non-alphanumeric characters
2019-03-20 22:42:16 +01:00
Christian Hesse
99a23f99e5
global-functions: remove extra check in $DownloadPackage
...
Should be fixed in RouterOS 6.44rc1 with changelog:
*) fetch - improved file downloading to slow memory;
2019-02-28 14:41:44 +01:00
Christian Hesse
fe1d234025
global-functions: add $ScriptLock
2019-02-21 18:35:08 +01:00
Christian Hesse
04025da9b8
global-functions: drop $Read, use :return directly
2019-02-21 00:03:57 +01:00
Christian Hesse
f127e3b7ef
global-functions: detect failed package downloads
2019-02-14 20:35:13 +01:00
Christian Hesse
c361caee5b
global-functions: introduce and use $CleanFilePath
2019-02-13 09:44:15 +01:00
Christian Hesse
8537bbe19d
global-functions: remove file on failed download
2019-02-13 09:22:20 +01:00
Christian Hesse
900820b519
global-functions: add missing colon
2019-02-11 15:14:23 +01:00
Christian Hesse
db2c4fbf39
global-functions: prevent infinite loop in $CharacterReplace
2019-02-08 20:15:49 +01:00
Christian Hesse
fc2547c137
global-functions: add $CharacterReplace
2019-02-08 12:54:54 +01:00
Christian Hesse
870f00bb36
global: variable names are CamelCase
...
___ _ ___ __
/ _ )(_)__ _ / _/__ _/ /_
/ _ / / _ `/ / _/ _ `/ __/
/____/_/\_, / /_/ \_,_/\__/
_ __ /___/ _ __
| | / /___ __________ (_)___ ____ _/ /
| | /| / / __ `/ ___/ __ \/ / __ \/ __ `/ /
| |/ |/ / /_/ / / / / / / / / / / /_/ /_/
|__/|__/\__,_/_/ /_/ /_/_/_/ /_/\__, (_)
/____/
RouterOS has some odd behavior when it comes to variable names. Let's
have a look at the interfaces:
[admin@MikroTik] > / interface print where name=en1
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE ACTUAL-MTU L2MTU
0 RS en1 ether 1500 1598
That looks ok. Now we use a script:
{ :local interface "en1";
/ interface print where name=$interface; }
And the result...
[admin@MikroTik] > { :local interface "en1";
{... / interface print where name=$interface; }
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE ACTUAL-MTU L2MTU
0 RS en1 ether 1500 1598
... still looks ok.
We make a little modification to the script:
{ :local name "en1";
/ interface print where name=$name; }
And the result:
[admin@MikroTik] > { :local name "en1";
{... / interface print where name=$name; }
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE ACTUAL-MTU L2MTU
0 RS en1 ether 1500 1598
1 S en2 ether 1500 1598
2 S en3 ether 1500 1598
3 S en4 ether 1500 1598
4 S en5 ether 1500 1598
5 R br-local bridge 1500 1598
Ups! The filter has no effect!
That happens whenever the variable name ($name) matches the property
name (name=).
And another modification:
{ :local type "en1";
/ interface print where name=$type; }
And the result:
[admin@MikroTik] > { :local type "en1";
{... / interface print where name=$type; }
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE ACTUAL-MTU L2MTU
Ups! Nothing?
Even if the variable name ($type) matches whatever property name (type=)
things go wrong.
The answer from MikroTik support (in Ticket#2019010222000454):
> This is how scripting works in RouterOS and we will not fix it.
To get around this we use variable names in CamelCase. Let's hope
Mikrotik never ever introduces property names in CamelCase...
*fingers crossed*
2019-01-04 12:35:34 +01:00
Christian Hesse
7d06a7e8c2
global-{config,functions}: move variables, make independent
2019-01-03 16:09:03 +01:00
Christian Hesse
6e03a3b935
script-updates: add configuration versioning
2019-01-03 15:36:26 +01:00
Christian Hesse
472cd3d905
update copyright for 2019
2019-01-02 09:38:34 +01:00
Christian Hesse
3cdd0fb94b
global-functions: properly define global functions
2018-12-28 22:56:29 +01:00
Christian Hesse
ea55464434
global-functions: update comment in $SendNotification
2018-12-28 22:56:29 +01:00
Christian Hesse
ac2e6cfc61
global-functions: add $DownloadPackage
...
... and make script 'capsman-download-packages' use it.
2018-12-28 22:56:07 +01:00
Christian Hesse
ee5eefefc3
global-functions: add $GetMacVendor
2018-12-27 00:48:56 +01:00
Christian Hesse
f4673928ef
global-functions: make $CertificateAvailable work on CommonName
...
This should prevent endless certificate switching for Let's Encrypt
cross-signed intermediate certificates.
2018-12-20 22:21:00 +01:00
Christian Hesse
a0fb616715
remove extra dollar sign
2018-12-12 21:57:17 +01:00
Christian Hesse
6e4d715937
global-functions: add identity tag in $SendNotification
...
... and send subject in telegram message.
2018-11-28 21:19:39 +01:00
Christian Hesse
ec2f976be0
global-functions: use 'print count-only'
2018-11-09 21:38:56 +01:00
Christian Hesse
ecf75697ba
global-functions: add function to read user input
2018-11-09 21:13:18 +01:00
Christian Hesse
d81e1bf195
global-functions: import certificates if required
...
Signed-off-by: Christian Hesse <mail@eworm.de>
2018-10-16 16:06:25 +02:00
Christian Hesse
bfca11c9ad
global-functions: fix missing colon
2018-10-15 09:57:13 +02:00
Christian Hesse
c9175d8e5e
global-functions: make sure parameters are strings
2018-10-12 14:07:47 +02:00
Christian Hesse
92bb1d107c
daily-psk: move function GeneratePSK from global-functions
2018-10-10 20:45:00 +02:00
Christian Hesse
cec61183eb
global-functions: add UrlEncode and use in SendNotification
2018-10-09 16:56:29 +02:00
Christian Hesse
5e4ef0ab8f
global-functions: add function to notify via e-mail and telegram
2018-10-09 15:46:39 +02:00
Christian Hesse
977a5d5f5e
global-functions: move daily psk secrets to global-config
2018-10-09 14:17:19 +02:00
Christian Hesse
7b4bef1a1e
make GeneratePSK a global function
2018-10-09 14:15:34 +02:00
Christian Hesse
9c3f3b9f20
add global-functions
2018-10-09 14:15:34 +02:00