mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-03-05 05:29:37 +00:00
Compare commits
No commits in common. "b3c2b67461497f5a110821a56c683d5e4c1cdeeb" and "2cc47f56b95b36eb73ed9bbe3e74f28b4f37dccd" have entirely different histories.
b3c2b67461
...
2cc47f56b9
3 changed files with 16 additions and 37 deletions
|
|
@ -21,7 +21,6 @@ for details!
|
|||
* [Ben Harris](mailto:mail@bharr.is) (@bharrisau)
|
||||
* [Daniel Ziegenberg](mailto:daniel@ziegenberg.at) (@ziegenberg)
|
||||
* [Ignacio Serrano](mailto:ignic@ignic.com) (@ignic)
|
||||
* [Ilya Kulakov](mailto:kulakov.ilya@gmail.com) (@Kentzo)
|
||||
* [Michael Gisbers](mailto:michael@gisbers.de) (@mgisbers)
|
||||
* [Miquel Bonastre](mailto:mbonastre@yahoo.com) (@mbonastre)
|
||||
* @netravnen
|
||||
|
|
|
|||
|
|
@ -17,33 +17,23 @@ Initial commands
|
|||
Run the complete base installation:
|
||||
|
||||
{
|
||||
:local BaseUrl "https://git.eworm.de/cgit/routeros-scripts/plain/";
|
||||
:local CertFileName "ISRG-Root-X2.pem";
|
||||
:local CertFingerprint "69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470";
|
||||
|
||||
:put "Importing certificate...";
|
||||
/tool/fetch ($BaseUrl . "certs/" . $CertFileName) dst-path=$CertFileName as-value;
|
||||
/tool/fetch "https://git.eworm.de/cgit/routeros-scripts/plain/certs/ISRG-Root-X2.pem" dst-path="isrg-root-x2.pem" as-value;
|
||||
:delay 1s;
|
||||
/certificate/import file-name=$CertFileName passphrase="";
|
||||
:if ([ :len [ /certificate/find where fingerprint=$CertFingerprint ] ] != 1) do={
|
||||
/certificate/import file-name="isrg-root-x2.pem" passphrase="";
|
||||
:if ([ :len [ /certificate/find where fingerprint="69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470" ] ] != 1) do={
|
||||
:error "Something is wrong with your certificates!";
|
||||
};
|
||||
:delay 1s;
|
||||
:put "Renaming global-config-overlay, if exists...";
|
||||
/system/script/set name=("global-config-overlay-" . [ /system/clock/get date ] . "-" . [ /system/clock/get time ]) [ find where name="global-config-overlay" ];
|
||||
:foreach Script in={ "global-config"; "global-config-overlay"; "global-functions" } do={
|
||||
:put "Installing $Script...";
|
||||
/system/script/remove [ find where name=$Script ];
|
||||
/system/script/add name=$Script owner=$Script source=([ /tool/fetch check-certificate=yes-without-crl ($BaseUrl . $Script . ".rsc") output=user as-value]->"data");
|
||||
/system/script/add name=$Script owner=$Script source=([ /tool/fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit/routeros-scripts/plain/" . $Script . ".rsc") output=user as-value]->"data");
|
||||
};
|
||||
:put "Loading configuration and functions...";
|
||||
/system/script { run global-config; run global-functions; };
|
||||
:put "Scheduling to load configuration and functions...";
|
||||
/system/scheduler/remove [ find where name="global-scripts" ];
|
||||
/system/scheduler/add name="global-scripts" start-time=startup on-event="/system/script { run global-config; run global-functions; }";
|
||||
:put "Renaming certificate by its common-name...";
|
||||
:global CertificateNameByCN;
|
||||
$CertificateNameByCN $CertFingerprint;
|
||||
$CertificateNameByCN "ISRG Root X2";
|
||||
};
|
||||
|
||||
Then continue setup with
|
||||
|
|
|
|||
|
|
@ -167,8 +167,8 @@
|
|||
$LogPrint warning $0 ("Failed downloading certificate with CommonName '" . $CommonName . \
|
||||
"' from repository! Trying fallback to mkcert.org...");
|
||||
:do {
|
||||
:if ([ :len [ /certificate/find where common-name="ISRG Root X1" ] ] = 0) do={
|
||||
$LogPrint error $0 ("Required certificate is not available.");
|
||||
:if ([ $CertificateAvailable "ISRG Root X1" ] = false) do={
|
||||
$LogPrint error $0 ("Downloading required certificate failed.");
|
||||
:return false;
|
||||
}
|
||||
/tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgentStr $0 ] }) \
|
||||
|
|
@ -203,17 +203,12 @@
|
|||
|
||||
# name a certificate by its common-name
|
||||
:set CertificateNameByCN do={
|
||||
:local Match [ :tostr $1 ];
|
||||
:local CommonName [ :tostr $1 ];
|
||||
|
||||
:global CleanName;
|
||||
|
||||
:local Cert ([ /certificate/find where (common-name=$Match or fingerprint=$Match or name=$Match) ]->0);
|
||||
:if ([ :len $Cert ] = 0) do={
|
||||
:return false;
|
||||
}
|
||||
:local CommonName [ /certificate/get $Cert common-name ];
|
||||
:local Cert [ /certificate/find where common-name=$CommonName ];
|
||||
/certificate/set $Cert name=[ $CleanName $CommonName ];
|
||||
:return true;
|
||||
}
|
||||
|
||||
# multiply given character(s)
|
||||
|
|
@ -1392,8 +1387,8 @@
|
|||
|
||||
# lock script against multiple invocation
|
||||
:set ScriptLock do={
|
||||
:local Script [ :tostr $1 ];
|
||||
:local WaitMax [ :totime $2 ];
|
||||
:local Script [ :tostr $1 ];
|
||||
:local WaitMax ([ :tonum $3 ] * 10);
|
||||
|
||||
:global GetRandom20CharAlNum;
|
||||
:global IfThenElse;
|
||||
|
|
@ -1482,10 +1477,6 @@
|
|||
:set ($ScriptLockOrder->$Script) ({});
|
||||
}
|
||||
|
||||
:if ([ :typeof $WaitMax ] = "nil" ) do={
|
||||
:set WaitMax 0s;
|
||||
}
|
||||
|
||||
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
|
||||
$LogPrint error $0 ("A script named '" . $Script . "' does not exist!");
|
||||
:error false;
|
||||
|
|
@ -1505,13 +1496,12 @@
|
|||
:local MyTicket [ $GetRandom20CharAlNum 6 ];
|
||||
$AddTicket $Script $MyTicket;
|
||||
|
||||
:local WaitInterval ($WaitMax / 20);
|
||||
:local WaitTime $WaitMax;
|
||||
:while ($WaitTime > 0 && \
|
||||
:local WaitCount 0;
|
||||
:while ($WaitMax > $WaitCount && \
|
||||
([ $IsFirstTicket $Script $MyTicket ] = false || \
|
||||
[ $TicketCount $Script ] < [ $JobCount $Script ])) do={
|
||||
:set WaitTime ($WaitTime - $WaitInterval);
|
||||
:delay $WaitInterval;
|
||||
:set WaitCount ($WaitCount + 1);
|
||||
:delay 100ms;
|
||||
}
|
||||
|
||||
:if ([ $IsFirstTicket $Script $MyTicket ] = true && \
|
||||
|
|
@ -1523,7 +1513,7 @@
|
|||
|
||||
$RemoveTicket $Script $MyTicket;
|
||||
$LogPrint debug $0 ("Script '" . $Script . "' started more than once" . \
|
||||
[ $IfThenElse ($WaitTime < $WaitMax) " and timed out waiting for lock" "" ] . "...");
|
||||
[ $IfThenElse ($WaitCount > 0) " and timed out waiting for lock" "" ] . "...");
|
||||
:return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue