From 94812edab3824a339b7b7c28681e341a7ae988b9 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 23 Jul 2026 20:35:45 +0700 Subject: [PATCH] feat(api): improve token generation in mikrotik-install script - Updated the token generation logic in `mikrotik-install.rsc` to use a portable random string method, ensuring compatibility with RouterOS 7+. - Enhanced the token format to include a random number for better uniqueness, improving security and reliability during agent installation. These changes enhance the robustness of the installation process for agents, ensuring more reliable token generation. --- apps/api/src/agent-scripts/mikrotik-install.rsc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/api/src/agent-scripts/mikrotik-install.rsc b/apps/api/src/agent-scripts/mikrotik-install.rsc index 4199e97..038aed5 100644 --- a/apps/api/src/agent-scripts/mikrotik-install.rsc +++ b/apps/api/src/agent-scripts/mikrotik-install.rsc @@ -24,9 +24,10 @@ } on-error={} :if ($already = 0) do={ - :local token ("evofw_" . [/certificate scep-server nonce generate]) + # Portable token: :rndstr is RouterOS 7+; avoid /certificate scep-server nonce (often missing). + :local token ("evofw_" . [:rndstr length=32 from="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]) :if ([:len $token] < 20) do={ - :set token ("evofw_" . [:tostr [/system clock get time]] . [:tostr [/system resource get cpu-load]] . [:tostr [/system resource get free-memory]]) + :set token ("evofw_" . [:tostr [/system clock get time]] . [:tostr [/system resource get cpu-load]] . [:tostr [/system resource get free-memory]] . [:tostr [:rndnum from=100000 to=999999]]) } :local body ("{\"name\":\"" . $EvofwName . "\",\"hostname\":\"" . [/system identity get name] . "\",\"platform\":\"mikrotik\",\"token\":\"" . $token . "\",\"client_version\":\"rsc/1\"")