diff --git a/ddns-hetzner.rsc b/ddns-hetzner.rsc index a51b5e5..135956a 100644 --- a/ddns-hetzner.rsc +++ b/ddns-hetzner.rsc @@ -1,6 +1,6 @@ #!rsc by RouterOS # RouterOS script: ddns-hetzner -# Version 2.0.2 +# Version 2.0.1 # Copyright (c) 2024-2026 Philip 'ShokiNN' Henning # https://git.s1q.dev/phg/routeros-scripts-custom/about/COPYING.md # @@ -48,8 +48,10 @@ onerror Err { :onerror GetAnnouncedIPErr in={ $LogPrint debug $ScriptName ("GetAnnouncedIP - started"); + [/system/script/run "JParseFunctions"; global JSONLoad; global JSONLoads; global JSONUnload]; + $LogPrint debug $ScriptName ("GetAnnouncedIP - JParseFunctions loaded"); - :set Records ([:deserialize from=json ([/tool/fetch "$APIUrl/zones/$ZoneName/rrsets/$RecordName/$RecordType" http-method=get http-header-field="Authorization: Bearer $APIToken" output=user as-value]->"data")]->"rrset"->"records"); + :set Records ([$JSONLoads ([/tool/fetch "$APIUrl/zones/$ZoneName/rrsets/$RecordName/$RecordType" http-method=get http-header-field="Authorization: Bearer $APIToken" output=user as-value]->"data")]->"rrset"->"records"); $LogPrint debug $ScriptName ("GetAnnouncedIP - Records received: " . [:len $Records]); foreach rec in=$Records do={ $LogPrint debug $ScriptName ("GetAnnouncedIP - Record: Name: \"" . $RecordName . "\", Type: \"" . $RecordType . "\", Value: \"" . ($rec->"value") . "\", Comment: \"" . ($rec->"comment") . "\""); @@ -82,13 +84,15 @@ onerror Err { :onerror APISetRecordErr in={ $LogPrint debug $ScriptName ("APISetRecord - started"); + [/system/script/run "JParseFunctions"; global JSONLoad; global JSONLoads; global JSONUnload]; + $LogPrint debug $ScriptName ("APISetRecord - JParseFunctions loaded"); :local Records; :local Record; :local Payload; :onerror GetRecordsErr in={ - :set Records ([:deserialize from=json ([/tool/fetch "$APIUrl/zones/$ZoneName/rrsets/$RecordName/$RecordType" http-method=get http-header-field="Authorization: Bearer $APIToken" output=user as-value]->"data")]->"rrset"->"records"); + :set Records ([$JSONLoads ([/tool/fetch "$APIUrl/zones/$ZoneName/rrsets/$RecordName/$RecordType" http-method=get http-header-field="Authorization: Bearer $APIToken" output=user as-value]->"data")]->"rrset"->"records"); } do={ :if ([:find "$GetRecordsErr" "status 404";] >= 1) do={ :set Records [:toarray ""]; @@ -132,6 +136,8 @@ onerror Err { } $LogPrint debug $ScriptName ("APISetRecord - APIResponse: " . $APIResponse); + $JSONUnload; + $LogPrint debug $ScriptName ("APISetRecord - JSONUnload done"); $LogPrint debug $ScriptName ("APISetRecord - finished"); :return $APIResponse; } do={ diff --git a/doc/ddns-hetzner.md b/doc/ddns-hetzner.md index a60e1df..107c9d4 100644 --- a/doc/ddns-hetzner.md +++ b/doc/ddns-hetzner.md @@ -11,6 +11,8 @@ - [Table of Contents](#table-of-contents) - [Description](#description) - [Requirements and installation](#requirements-and-installation) + - [Dependencies](#dependencies) + - [JSON parser Installation](#json-parser-installation) - [Pre requisites](#pre-requisites) - [Script Installation](#script-installation) - [Configuration](#configuration) @@ -28,6 +30,18 @@ RouterOS 6 isn't and won't be supported! ## Requirements and installation +### Dependencies + +This script requires [Winand](https://github.com/Winand)'s [mikrotik-json-parser](https://github.com/Winand/mikrotik-json-parser) to be installed. + +#### JSON parser Installation + +Create another new script: + + 1. Name: `JParseFunctions` + 2. Policy: `read`, `write`, `test` uncheck everything else + 3. Source: The content of [mikrotik-json-parser](https://github.com/Winand/mikrotik-json-parser/blob/master/JParseFunctions) + ### Pre requisites > [!IMPORTANT] diff --git a/global-functions.d/phg.rsc b/global-functions.d/phg.rsc index b79db4b..df1adc2 100644 --- a/global-functions.d/phg.rsc +++ b/global-functions.d/phg.rsc @@ -1,12 +1,12 @@ #!rsc by RouterOS -# RouterOS script: global-functions.d/phg.rsc -# Copyright (c) 2025-2026 Philip 'ShokiNN' Henning +# RouterOS script: global-functions-custom-phg +# Copyright (c) 2025 Philip 'ShokiNN' Henning # https://git.s1q.dev/phg/routeros-scripts-custom/about/COPYING.md # # requires RouterOS, version=7.14 # # global functions for my custom scripts -# https://git.s1q.dev/phg/routeros-scripts-custom +# https://git.s1q.dev/phg/routeros-scripts-custom/about :local ScriptName [ :jobname ];