--- /dev/null
+#!rsc by Vados
+# RouterOS script: AM-CertsRenew
+# Script comment: Renew locally issued certificates
+# Copyright (c) 2005-2026 Vados <vados@vados.ru>
+#
+#
+# requires RouterOS, version=7.19
+#
+:local ExitOK false;
+:onerror Err {
+ :global GlobalConfReady; :global GlobalFuncReady;
+ :retry { :if ($GlobalConfReady != true || $GlobalFuncReady != true) \
+ do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
+ :local ScriptName [ :jobname ];
+
+ :global CertIssuedExportPass;
+
+ :global LogPrint;
+ :global MkDir;
+ :global ScriptLock;
+
+# Add this Script scheduler
+:if ([ :len [ /system/scheduler/find where name=$ScriptName ] ] = 0) do={
+:log warning ("System Scheduler for script: " . $ScriptName . " is NOT SET! Fix It Now!");
+:local OnEvent "/system/script/run $ScriptName;";
+:local Comment "Every Day Check For Update Local Issued Certificates.";
+#/system/scheduler/add name=$ScriptName comment=$Comment start-time=startup interval=1d on-event=$OnEvent;
+}
+
+ :if ([ $ScriptLock $ScriptName ] = false) do={
+ :set ExitOK true;
+ :error false;
+ }
+
+ :foreach Cert in=[ /certificate/find where issued expires-after<3w ] do={
+ :local CertVal [ /certificate/get $Cert ];
+ /certificate/issued-revoke $Cert;
+ /certificate/set name=($CertVal->"name" . "-revoked-" . [ /system/clock/get date ]) $Cert;
+ /certificate/add name=($CertVal->"name") common-name=($CertVal->"common-name") \
+ key-usage=($CertVal->"key-usage") subject-alt-name=($CertVal->"subject-alt-name");
+ /certificate/sign ($CertVal->"name") ca=($CertVal->"ca");
+ :if ([ :typeof ($CertIssuedExportPass->($CertVal->"common-name")) ] = "str") do={
+ :if ([ $MkDir "cert-issued" ] = true) do={
+ /certificate/export-certificate ($CertVal->"name") type=pkcs12 \
+ file-name=("cert-issued/" . $CertVal->"common-name") \
+ export-passphrase=($CertIssuedExportPass->($CertVal->"common-name"));
+ $LogPrint info $ScriptName ("Issued a new certificate for '" . $CertVal->"common-name" . \
+ "', exported to 'cert-issued/" . $CertVal->"common-name" . ".p12'.");
+ } else={
+ $LogPrint warning $ScriptName ("Failed creating directory, not exporting certificate.");
+ }
+ } else={
+ $LogPrint info $ScriptName ("Issued a new certificate for '" . $CertVal->"common-name" . "'.");
+ }
+ }
+} do={
+ :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
+}
:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/230/32ea8037";
+:global CommitId "main/231/47b67063";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 20:45:02 15.04.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 21:55:02 15.04.2026.";
# The variables are received right here.
:global GlobalConfVersion 138;