mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-04-23 05:29:36 +00:00
Compare commits
5 commits
66764ed0b2
...
31c0716d69
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31c0716d69 | ||
|
|
cf0607837c | ||
|
|
1de4bdb909 | ||
|
|
7c318e144f | ||
|
|
309d17e81a |
4 changed files with 21 additions and 34 deletions
|
|
@ -4,7 +4,7 @@ Import ssh keys for public key authentication
|
||||||
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/network)
|
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||||
[](https://mikrotik.com/download/changelogs/)
|
[](https://mikrotik.com/download/changelogs/)
|
||||||
[](https://t.me/routeros_scripts)
|
[](https://t.me/routeros_scripts)
|
||||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||||
|
|
||||||
|
|
@ -38,9 +38,8 @@ import that key:
|
||||||
$SSHKeysImport "ssh-rsa AAAAB3Nza...QYZk8= user" admin;
|
$SSHKeysImport "ssh-rsa AAAAB3Nza...QYZk8= user" admin;
|
||||||
|
|
||||||
The third part of the key (`user` in this example) is inherited as
|
The third part of the key (`user` in this example) is inherited as
|
||||||
`info` in RouterOS (or `key-owner` with RouterOS 7.20.x and before). Also
|
`info` in RouterOS. Also the `MD5` fingerprint is recorded, this helps
|
||||||
the `MD5` fingerprint is recorded, this helps to audit and verify the
|
to audit and verify the available keys.
|
||||||
available keys.
|
|
||||||
|
|
||||||
> ℹ️️ **Info**: Use `ssh-keygen` to show a fingerprint of an existing public
|
> ℹ️️ **Info**: Use `ssh-keygen` to show a fingerprint of an existing public
|
||||||
> key file: `ssh-keygen -l -E md5 -f ~/.ssh/id_ed25519.pub`
|
> key file: `ssh-keygen -l -E md5 -f ~/.ssh/id_ed25519.pub`
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# Copyright (c) 2020-2026 Christian Hesse <mail@eworm.de>
|
# Copyright (c) 2020-2026 Christian Hesse <mail@eworm.de>
|
||||||
# https://rsc.eworm.de/COPYING.md
|
# https://rsc.eworm.de/COPYING.md
|
||||||
#
|
#
|
||||||
# requires RouterOS, version=7.17
|
# requires RouterOS, version=7.21
|
||||||
#
|
#
|
||||||
# import ssh keys for public key authentication
|
# import ssh keys for public key authentication
|
||||||
# https://rsc.eworm.de/doc/mod/ssh-keys-import.md
|
# https://rsc.eworm.de/doc/mod/ssh-keys-import.md
|
||||||
|
|
@ -40,9 +40,8 @@
|
||||||
|
|
||||||
:local FingerPrintMD5 [ :convert from=base64 transform=md5 to=hex ($KeyVal->1) ];
|
:local FingerPrintMD5 [ :convert from=base64 transform=md5 to=hex ($KeyVal->1) ];
|
||||||
|
|
||||||
:local RegEx ("\\bmd5=" . $FingerPrintMD5 . "\\b");
|
|
||||||
:if ([ :len [ /user/ssh-keys/find where user=$User \
|
:if ([ :len [ /user/ssh-keys/find where user=$User \
|
||||||
(key-owner~$RegEx or info~$RegEx) ] ] > 0) do={
|
info~("\\bmd5=" . $FingerPrintMD5 . "\\b") ] ] > 0) do={
|
||||||
$LogPrint warning $0 ("The ssh public key (MD5:" . $FingerPrintMD5 . \
|
$LogPrint warning $0 ("The ssh public key (MD5:" . $FingerPrintMD5 . \
|
||||||
") is already available for user '" . $User . "'.");
|
") is already available for user '" . $User . "'.");
|
||||||
:return false;
|
:return false;
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
# Copyright (c) 2022-2026 Christian Hesse <mail@eworm.de>
|
# Copyright (c) 2022-2026 Christian Hesse <mail@eworm.de>
|
||||||
# https://rsc.eworm.de/COPYING.md
|
# https://rsc.eworm.de/COPYING.md
|
||||||
#
|
#
|
||||||
# requires RouterOS, version=7.17
|
# requires RouterOS, version=7.22beta1
|
||||||
# requires device-mode, fetch
|
# requires device-mode, fetch
|
||||||
#
|
#
|
||||||
# monitor and manage dns/doh with netwatch
|
# monitor and manage dns/doh with netwatch
|
||||||
# https://rsc.eworm.de/doc/netwatch-dns.md
|
# https://rsc.eworm.de/doc/netwatch-dns.md
|
||||||
|
|
||||||
:local ExitOK false;
|
|
||||||
:onerror Err {
|
:onerror Err {
|
||||||
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
||||||
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
||||||
|
|
@ -25,15 +24,13 @@
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
|
|
||||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:local SettleTime (5m30s - [ /system/resource/get uptime ]);
|
:local SettleTime (5m30s - [ /system/resource/get uptime ]);
|
||||||
:if ($SettleTime > 0s) do={
|
:if ($SettleTime > 0s) do={
|
||||||
$LogPrint info $ScriptName ("System just booted, giving netwatch " . $SettleTime . " to settle.");
|
$LogPrint info $ScriptName ("System just booted, giving netwatch " . $SettleTime . " to settle.");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:local DnsServers ({});
|
:local DnsServers ({});
|
||||||
|
|
@ -88,8 +85,7 @@
|
||||||
|
|
||||||
:if ($DohCurrent = $HostInfo->"doh-url" && [ $IsDNSResolving ] = true) do={
|
:if ($DohCurrent = $HostInfo->"doh-url" && [ $IsDNSResolving ] = true) do={
|
||||||
$LogPrint debug $ScriptName ("Current DoH server is still up and resolving: " . $DohCurrent);
|
$LogPrint debug $ScriptName ("Current DoH server is still up and resolving: " . $DohCurrent);
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:set ($DohServers->[ :len $DohServers ]) $HostInfo;
|
:set ($DohServers->[ :len $DohServers ]) $HostInfo;
|
||||||
|
|
@ -132,8 +128,7 @@
|
||||||
}
|
}
|
||||||
/ip/dns/cache/flush;
|
/ip/dns/cache/flush;
|
||||||
$LogPrint info $ScriptName ("Setting DoH server: " . ($DohServer->"doh-url"));
|
$LogPrint info $ScriptName ("Setting DoH server: " . ($DohServer->"doh-url"));
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error true;
|
|
||||||
} else={
|
} else={
|
||||||
$LogPrint warning $ScriptName ("Received unexpected response from DoH server: " . \
|
$LogPrint warning $ScriptName ("Received unexpected response from DoH server: " . \
|
||||||
($DohServer->"doh-url"));
|
($DohServer->"doh-url"));
|
||||||
|
|
@ -141,5 +136,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} do={
|
} do={
|
||||||
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
:global ExitError; $ExitError true [ :jobname ] $Err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
# Copyright (c) 2023-2026 Christian Hesse <mail@eworm.de>
|
# Copyright (c) 2023-2026 Christian Hesse <mail@eworm.de>
|
||||||
# https://rsc.eworm.de/COPYING.md
|
# https://rsc.eworm.de/COPYING.md
|
||||||
#
|
#
|
||||||
# requires RouterOS, version=7.17
|
# requires RouterOS, version=7.22beta1
|
||||||
# requires device-mode, fetch
|
# requires device-mode, fetch
|
||||||
#
|
#
|
||||||
# use Telegram to chat with your Router and send commands
|
# use Telegram to chat with your Router and send commands
|
||||||
# https://rsc.eworm.de/doc/telegram-chat.md
|
# https://rsc.eworm.de/doc/telegram-chat.md
|
||||||
|
|
||||||
:local ExitOK false;
|
|
||||||
:onerror Err {
|
:onerror Err {
|
||||||
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
||||||
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
||||||
|
|
@ -48,8 +47,7 @@
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$WaitFullyConnected;
|
$WaitFullyConnected;
|
||||||
|
|
@ -63,8 +61,7 @@
|
||||||
|
|
||||||
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
|
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
|
||||||
$LogPrint warning $ScriptName ("Downloading required certificate failed.");
|
$LogPrint warning $ScriptName ("Downloading required certificate failed.");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$RandomDelay $TelegramRandomDelay;
|
$RandomDelay $TelegramRandomDelay;
|
||||||
|
|
@ -89,8 +86,7 @@
|
||||||
|
|
||||||
:if ($Data = false) do={
|
:if ($Data = false) do={
|
||||||
$LogPrint warning $ScriptName ("Failed getting updates.");
|
$LogPrint warning $ScriptName ("Failed getting updates.");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:local JSON [ :deserialize from=json value=$Data ];
|
:local JSON [ :deserialize from=json value=$Data ];
|
||||||
|
|
@ -119,7 +115,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ($Trusted = true) do={
|
:if ($Trusted = true) do={
|
||||||
:local Done false;
|
|
||||||
:if ($Command = "?") do={
|
:if ($Command = "?") do={
|
||||||
$LogPrint info $ScriptName ("Sending notice for update " . $UpdateID . ".");
|
$LogPrint info $ScriptName ("Sending notice for update " . $UpdateID . ".");
|
||||||
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; \
|
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; \
|
||||||
|
|
@ -127,9 +122,9 @@
|
||||||
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
|
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
|
||||||
message=([ $IfThenElse ([ :len ($From->"first_name") ] > 0) ("Hello " . ($From->"first_name") . "!\n\n") ] . \
|
message=([ $IfThenElse ([ :len ($From->"first_name") ] > 0) ("Hello " . ($From->"first_name") . "!\n\n") ] . \
|
||||||
"Online" . [ $IfThenElse $TelegramChatActive " (and active!)" ] . ", awaiting your commands!") });
|
"Online" . [ $IfThenElse $TelegramChatActive " (and active!)" ] . ", awaiting your commands!") });
|
||||||
:set Done true;
|
:continue;
|
||||||
}
|
}
|
||||||
:if ($Done = false && [ :pick $Command 0 1 ] = "!") do={
|
:if ([ :pick $Command 0 1 ] = "!") do={
|
||||||
:if ($Command ~ ("^! *(" . [ $EscapeForRegEx $Identity ] . "|@" . $TelegramChatGroups . ")\$")) do={
|
:if ($Command ~ ("^! *(" . [ $EscapeForRegEx $Identity ] . "|@" . $TelegramChatGroups . ")\$")) do={
|
||||||
:set TelegramChatActive true;
|
:set TelegramChatActive true;
|
||||||
} else={
|
} else={
|
||||||
|
|
@ -137,17 +132,16 @@
|
||||||
}
|
}
|
||||||
$LogPrint info $ScriptName ("Now " . [ $IfThenElse $TelegramChatActive "active" "passive" ] . \
|
$LogPrint info $ScriptName ("Now " . [ $IfThenElse $TelegramChatActive "active" "passive" ] . \
|
||||||
" from update " . $UpdateID . "!");
|
" from update " . $UpdateID . "!");
|
||||||
:set Done true;
|
:continue;
|
||||||
}
|
}
|
||||||
:if ($Done = false && ($IsMyReply = 1 || ($IsAnyReply = false && \
|
:if (($IsMyReply = 1 || ($IsAnyReply = false && \
|
||||||
$TelegramChatActive = true)) && [ :len $Command ] > 0) do={
|
$TelegramChatActive = true)) && [ :len $Command ] > 0) do={
|
||||||
:if ([ $ValidateSyntax $Command ] = true) do={
|
:if ([ $ValidateSyntax $Command ] = true) do={
|
||||||
:local State "";
|
:local State "";
|
||||||
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
|
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
|
||||||
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
|
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
|
||||||
$LogPrint error $ScriptName ("Failed creating directory!");
|
$LogPrint error $ScriptName ("Failed creating directory!");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
$LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command);
|
$LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command);
|
||||||
:execute script=(":do {\n" . $Command . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \
|
:execute script=(":do {\n" . $Command . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \
|
||||||
|
|
@ -197,5 +191,5 @@
|
||||||
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
|
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
|
||||||
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
|
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
|
||||||
} do={
|
} do={
|
||||||
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
:global ExitError; $ExitError true [ :jobname ] $Err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue