]> Git [git.vados.ru] :: Repos - Mikrotiks/ros.vados.ru.git/commitdiff
Autocommit in repo: ros.vados.ru, generated by owner: root, in 23:30:02 24.04.2026.
authorvados-dev <192440777+vados-dev@users.noreply.github.com>
Fri, 24 Apr 2026 20:30:03 +0000 (23:30 +0300)
committervados-dev <192440777+vados-dev@users.noreply.github.com>
Fri, 24 Apr 2026 20:30:03 +0000 (23:30 +0300)
html/.codex [new file with mode: 0644]
html/AM-GlobalFunc.rsc

diff --git a/html/.codex b/html/.codex
new file mode 100644 (file)
index 0000000..e69de29
index de33682c4b9a0d6561e506704c1ed3e007f401d8..c863260cf167e48f62697e28160a6738de4ec5ef 100644 (file)
@@ -17,9 +17,9 @@
 :global GlobalFuncReady false;
 
 # Git commit id & info, expected configuration version
-:global CommitId "main/247/016960a4";
+:global CommitId "main/248/7f4b08f3";
 :global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 03:45:02 16.04.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 23:30:02 24.04.2026.";
 
 # The variables are received right here.
 :global GlobalConfVersion 138;
@@ -71,7 +71,7 @@
 :global runningVersion;
 
 :global devBuildTime;
-#:global ROsVerAvail;
+:global ROsVerAvail;
 :global PkgUpdStatus;
 :global currentUpdateChannel;
 
   :global LogPrint;
   :global updateChannel;
   :global PkgUpdStatus;
+  :global currentUpdateChannel;
+  :global ROsVerAvail;
+  :global arrDeviceInfo;
   $LogPrint debug $0 ("\$isInfo = " . $isInfo); 
   :local CurrentChannel [ /system/package/update/get channel ];
-  :if ($CurrentChannel != $updateChannel) do={
+  :if ([ :len $updateChannel ] > 0 && $CurrentChannel != $updateChannel) do={
     :retry command={/system/package/update set channel=$updateChannel}  delay=300ms max=5 on-error={};
     $LogPrint debug $0 ("Set updates channel to: $updateChannel");
   }
 
   :local Update [ /system/package/update/get ];
-  :local Channel ($Update->"channel");
+  :local Channel [ :tostr ($Update->"channel") ];
+  :set currentUpdateChannel $Channel;
   $LogPrint debug $0 ("Update Channel: " . $Channel . ".");
 
   :local StatusPkg "undefined";
    delay=300ms max=5 on-error={};
   $LogPrint debug $0 ("\$StatusPkg = " . $StatusPkg);
   :if ($StatusPkg = "New version is available") do={ :set PkgUpdStatus true; } else={ :set PkgUpdStatus false; }
+  :set ROsVerAvail [ :tostr [ /system/package/update/get latest-version ] ];
   $LogPrint debug $0 ("\$PkgUpdStatus = " . $PkgUpdStatus);
   :if ($isInfo != false || $PkgUpdStatus = true) do={
     $LogPrint debug $0 ("\$PkgUpdStatus = " . $PkgUpdStatus);
-    :if ([:len $arrDeviceInfo] = 0) do={
-    :global arrDeviceInfo ({});
-    :local arrDeviceInfo ({"section":{"key":""; "value":"";};});
+    :if ([ :typeof $arrDeviceInfo ] != "array") do={
+      :set arrDeviceInfo [:toarray {}];
     }
-    # else={:local arrDeviceInfo ({})}
-    :retry command={:set ($arrDeviceInfo->"devUpdates") [[ :parse "/system/package/update/get" ]]} delay=500ms max=5 on-error={:log error ("Error")};
-    #:set ($arrDeviceInfo->"devUpdates") {"devCurrentChannel"; $CurrentChannel;};
-    #:set ($arrDeviceInfo->"devUpdates") {"devCurrentVersion"; ($Update->"installed-version");};
-    #:set ($arrDeviceInfo->"devUpdates") {"devCurrentChannelVersion"; [/system/resource/get version];};
-    #:set ($arrDeviceInfo->"devUpdates") {"devUpdateChannel"; [$updateChannel];};
-    #:set ($arrDeviceInfo->"devUpdates") {"devUpdateVersion"; ($Update->"latest-version");};
+    :retry command={:set ($arrDeviceInfo->"devUpdates") [ /system/package/update/get ]} delay=500ms max=5 on-error={:log error ("Error")};
+    :return true;
+  } else={
+    :return $PkgUpdStatus;
+  }
+}
+
+:set WaitCheckUpdates do={
+  :global IsCheckUpdates;
+  :global PkgUpdStatus;
+  :global currentUpdateChannel;
+  :global ROsVerAvail;
+  :global arrDeviceInfo;
+
+  :local Status "";
+  :local Update;
+  :local WaitCount 0;
+
+  :if ([ $IsCheckUpdates true ] = false) do={
+    :return false;
+  }
+
+  :set Status [ :tostr [ /system/package/update/get status ] ];
+  :while (($Status = "" || $Status = "finding out latest version...") && $WaitCount < 60) do={
+    :delay 1s;
+    :set WaitCount ($WaitCount + 1);
+    :set Status [ :tostr [ /system/package/update/get status ] ];
+   }
+
+  :set Update [ /system/package/update/get ];
+  :set currentUpdateChannel [ :tostr ($Update->"channel") ];
+  :set ROsVerAvail [ :tostr ($Update->"latest-version") ];
+  :if (($Update->"status") = "New version is available") do={
+    :set PkgUpdStatus true;
   } else={
-  :return $PkgUpdStatus;
+    :set PkgUpdStatus false;
+  }
+  :if ([ :typeof $arrDeviceInfo ] != "array") do={
+    :set arrDeviceInfo [:toarray {}];
+  }
+  :set ($arrDeviceInfo->"devUpdates") $Update;
+
+  :if ($Status = "" || $Status = "finding out latest version...") do={
+    :return false;
   }
+  :return true;
 }
 
 :set WaitArrDeviceInfo do={
 
 :set GetArrDeviceInfo do={
    :global LogPrint;
+   :global arrDeviceInfo;
 
    :global devBoardName;
    :global devModel;
-
-   :global arrDeviceInfo [:toarray {"section"={"key"=""; "value"="";} }];
-   #:do {:set ($arrDeviceInfo->"Updates") [[ :parse "/system/package/update/get" ]]} on-error={}
-   :global devRbRevision;
-   :global devRbSerialNumber;
-   :global devRbCurrentFw;
-   :global devRbUpgradeFw;
-
    :global devRunning;
    :global devCurArch;
-   :global ROsVerCurrent;
-   :global ROsChannelCurrent;
-   :global ROsVerAvail;
-
-   :global ParseCustom;
+   :global devRbRevision;
+   :global devRbSerialNumber;
+   :global devBuildTime;
    :global runningChannelVersion;
    :global runningChannel;
    :global runningVersion;
-   :global devBuildTime;
-   :global GetPubIp;
+   :global currentUpdateChannel;
+   :global ROsVerAvail;
 
-   :local License [/system/license/get];
+   :local DeviceInfo [:toarray {}];
    :local Resource [/system/resource/get];
-   :set devBuildTime ($Resource->"build-time");
-   :set runningChannelVersion ($Resource->"version");
-   :set runningChannel [$ParseCustom $runningChannelVersion "(" ")" 1];
-   :set runningVersion [$ParseCustom $runningChannelVersion " "];
+   :local Update [ /system/package/update/get ];
+   :local VersionString [ :tostr ($Resource->"version") ];
+   :local ChannelStart [ :find $VersionString " (" ];
+   :local RouterBoard [:toarray {}];
+   :local IsRouterBoard false;
+   :local RunningMode "";
+
+   :set devBoardName [ :tostr ($Resource->"board-name") ];
+   :set devCurArch [ :tostr ($Resource->"architecture-name") ];
+   :set devBuildTime [ :tostr ($Resource->"build-time") ];
+   :set runningChannelVersion $VersionString;
+   :set runningVersion $VersionString;
+   :set runningChannel "";
+
+   :if ([ :typeof $ChannelStart ] = "num" && $ChannelStart >= 0) do={
+     :set runningVersion [ :pick $VersionString 0 $ChannelStart ];
+     :local ChannelRest [ :pick $VersionString ($ChannelStart + 2) [ :len $VersionString ] ];
+     :local ChannelEnd [ :find $ChannelRest ")" ];
+     :if ([ :typeof $ChannelEnd ] = "num" && $ChannelEnd >= 0) do={
+       :set runningChannel [ :pick $ChannelRest 0 $ChannelEnd ];
+     }
+   }
 
    :do {
-   :if ([:pick $devBoardName 0 3] != "CHR" or [:pick $devBoardName 0 3] != "x86") do={
-      :local RouterBoard;
-      :do {:set RouterBoard [[ :parse "/system/routerboard/get" ]]} on-error={}
-      :set devModel ($RouterBoard->"model");
-      :set devRbRevision ($RouterBoard->"revision");
-      :set devRbSerialNumber ($RouterBoard->"serial-number");
-      #:set devRbCurrentFw ($RouterBoard->"current-firmware");
-      #:set devRbUpgradeFw ($RouterBoard->"upgrade-firmware");
-      :if ($devCurArch = "mipsbe" || $devCurArch = "arm") do={
-         :global devRunning [ /system/device-mode/get mode ];
-         } else={
-          :global devRunning [/system/device-mode/get running];}
-    } else={
-    :set devModel $devBoardName;
-
-    :set devRbRevision false;
-    :set devRbSerialNumber false;
-#    :set devRbCurrentFw false;
-#    :set devRbUpgradeFw false;
-    #:set devCurrentFw $runningVersion;#:set devUpgradeFw $ROsVerAvail;
-    :set devRunning [/system/device-mode/get running];
-    }
+     :set RouterBoard [ /system/routerboard/get ];
+     :if (($RouterBoard->"routerboard") = true) do={
+       :set IsRouterBoard true;
+     }
+   } on-error={}
+
+   :do {
+     :set RunningMode [ /system/device-mode/get mode ];
    } on-error={
-    $LogPrint error $0 ("Error in Function getDevice!");
-    :return false;
+     :do {
+       :set RunningMode [ /system/device-mode/get running ];
+     } on-error={
+       :set RunningMode "";
+     }
    }
-:return true;
+   :set devRunning $RunningMode;
+
+   :if ($IsRouterBoard = true) do={
+     :set devModel [ :tostr ($RouterBoard->"model") ];
+     :set devRbRevision [ :tostr ($RouterBoard->"revision") ];
+     :set devRbSerialNumber [ :tostr ($RouterBoard->"serial-number") ];
+   } else={
+     :set devModel $devBoardName;
+     :set devRbRevision "";
+     :set devRbSerialNumber "";
+   }
+
+   :set currentUpdateChannel [ :tostr ($Update->"channel") ];
+   :set ROsVerAvail [ :tostr ($Update->"latest-version") ];
+
+   :set ($DeviceInfo->"board-name") $devBoardName;
+   :set ($DeviceInfo->"architecture-name") $devCurArch;
+   :set ($DeviceInfo->"model") $devModel;
+   :set ($DeviceInfo->"revision") $devRbRevision;
+   :set ($DeviceInfo->"serial-number") $devRbSerialNumber;
+   :set ($DeviceInfo->"running-mode") $devRunning;
+   :set ($DeviceInfo->"build-time") $devBuildTime;
+   :set ($DeviceInfo->"running-channel-version") $runningChannelVersion;
+   :set ($DeviceInfo->"running-version") $runningVersion;
+   :set ($DeviceInfo->"running-channel") $runningChannel;
+   :set ($DeviceInfo->"routerboard") $IsRouterBoard;
+   :set ($DeviceInfo->"current-firmware") [ :tostr ($RouterBoard->"current-firmware") ];
+   :set ($DeviceInfo->"upgrade-firmware") [ :tostr ($RouterBoard->"upgrade-firmware") ];
+   :set ($DeviceInfo->"package-channel") $currentUpdateChannel;
+   :set ($DeviceInfo->"installed-version") [ :tostr ($Update->"installed-version") ];
+   :set ($DeviceInfo->"latest-version") $ROsVerAvail;
+   :set ($DeviceInfo->"update-status") [ :tostr ($Update->"status") ];
+
+   :set arrDeviceInfo $DeviceInfo;
+   :return $DeviceInfo;
 }
 
 :set DeviceInfo do={
-  :global WaitArrDeviceInfo;
-  # $WaitDeviceInfo;
-  :global devBoardName;
-  :global devCurArch;
-  :global devModel;
-  :global devRunning;
-  :global devRbRevision;
-  :global devRbSerialNumber;
-  :global PiblicIpAddress;
-
+  :global GetArrDeviceInfo;
   :global GlobalConfVersion;
   :global Identity;
   :global IfThenElse;
   :global FormatLine;
-  :local Return;
+  :global CommitBrief;
+
   :local License [/system/license/get];
-  :local Resource [/system/resource/get];
   :local Snmp [ /snmp/get ];
-  :local Update [ /system/package/update/get ];
+  :local Info [ $GetArrDeviceInfo ];
+
+  :if ([ :typeof $Info ] != "array") do={
+    :return false;
+  }
 
-  :set Return ([ $FormatLine "Hostname:" $Identity ] . "\n" . \
+  :return ( \
+    [ $FormatLine "Hostname" $Identity ] . "\n" . \
     [ $IfThenElse ([ :len ($Snmp->"location") ] > 0) \
-      ([ $FormatLine "Location:" ($Snmp->"location") ] . "\n") ] . \
+      ([ $FormatLine "Location" ($Snmp->"location") ] . "\n") ] . \
     [ $IfThenElse ([ :len ($Snmp->"contact") ] > 0) \
-      ([ $FormatLine "Contact:" ($Snmp->"contact") ] . "\n") ] . \
-      "Hardware:\n" . \
-    [ $FormatLine "    Board:" . $devBoardName ] . "\n" . \
-    [ $FormatLine "    Arch:" . $devCurArch ] . "\n" . \
-    [ $FormatLine "    Model:" $devModel ] . \
-      [ $IfThenElse ([ :len $devRbRevision ] > 0) \
-      (" " . $devRbRevision) ] . "\n" . \
-      [ $IfThenElse ([ :len $devRbSerialNumber ] > 0) \
-       ([ $FormatLine "    Serial:" . $devRbSerialNumber ] . "\n") ] .  \
+      ([ $FormatLine "Contact" ($Snmp->"contact") ] . "\n") ] . \
+    "Hardware:\n" . \
+    [ $FormatLine "    Board" ($Info->"board-name") ] . "\n" . \
+    [ $FormatLine "    Arch" ($Info->"architecture-name") ] . "\n" . \
+    [ $FormatLine "    Model" ($Info->"model") ] . \
+    [ $IfThenElse ([ :len ($Info->"revision") ] > 0) \
+      (" " . ($Info->"revision")) ] . "\n" . \
+    [ $IfThenElse ([ :len ($Info->"serial-number") ] > 0) \
+      ([ $FormatLine "    Serial" ($Info->"serial-number") ] . "\n") ] . \
     [ $IfThenElse ([ :len ($License->"nlevel") ] > 0) \
-      ([ $FormatLine "    License:" ("level " . ($License->"nlevel")) ] . "\n") ] . "RouterOS:\n" . \
+      ([ $FormatLine "    License" ("level " . ($License->"nlevel")) ] . "\n") ] . \
+    "RouterOS:\n" . \
     [ $IfThenElse ([ :len ($License->"level") ] > 0) \
-      ([ $FormatLine "    License:" ("level " . ($License->"level")) ] . "\n") ] . \
-    [ $FormatLine "Running Channel" $runningChannel ] . "\n" . \
-    [ $FormatLine "    Installed:" ($Update->"installed-version") ] . "\n" . \
-    [ $IfThenElse ([ :typeof ($Update->"latest-version") ] != "nothing" && \
-        $Update->"installed-version" != $Update->"latest-version") \
-      ([ $FormatLine "    Available" ($Update->"latest-version") ] . "\n") ] . \
-    [ $IfThenElse ($RouterBoard->"routerboard" = true && \
-        $RouterBoard->"current-firmware" != $RouterBoard->"upgrade-firmware") \
-      ([ $FormatLine "    Firmware" ($RouterBoard->"current-firmware") ] . "\n") ] . \ 
-      "RouterOS-Scripts:\n" . \
-      [ $FormatLine "    Commit" [ $CommitBrief ] ] . "\n" . \
-      [ $FormatLine "    Version" $GlobalConfVersion ]);
+      ([ $FormatLine "    License" ("level " . ($License->"level")) ] . "\n") ] . \
+    [ $FormatLine "    Channel" ($Info->"package-channel") ] . "\n" . \
+    [ $FormatLine "    Installed" ($Info->"installed-version") ] . "\n" . \
+    [ $IfThenElse ([ :len ($Info->"running-channel") ] > 0) \
+      ([ $FormatLine "    Running" (($Info->"running-version") . " (" . ($Info->"running-channel") . ")") ] . "\n") \
+      ([ $FormatLine "    Running" ($Info->"running-version") ] . "\n") ] . \
+    [ $IfThenElse ([ :len ($Info->"latest-version") ] > 0 && \
+        ($Info->"installed-version") != ($Info->"latest-version")) \
+      ([ $FormatLine "    Available" ($Info->"latest-version") ] . "\n") ] . \
+    [ $IfThenElse (($Info->"routerboard") = true && \
+        ($Info->"current-firmware") != ($Info->"upgrade-firmware")) \
+      ([ $FormatLine "    Firmware" (($Info->"current-firmware") . " -> " . ($Info->"upgrade-firmware")) ] . "\n") ] . \
+    "RouterOS-Scripts:\n" . \
+    [ $FormatLine "    Commit" [ $CommitBrief ] ] . "\n" . \
+    [ $FormatLine "    Version" $GlobalConfVersion ]);
 }
 
 :if ([ :typeof $NotificationFunctions ] != "array") do={:set NotificationFunctions ({})}