remove external dependency to parse json
This commit is contained in:
parent
57c64a8899
commit
572a2407d0
2 changed files with 3 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: ddns-hetzner
|
||||
# Version 2.0.1
|
||||
# Version 2.0.2
|
||||
# Copyright (c) 2024-2026 Philip 'ShokiNN' Henning <mail@philip-henning.com>
|
||||
# https://git.s1q.dev/phg/routeros-scripts-custom/about/COPYING.md
|
||||
#
|
||||
|
|
@ -48,10 +48,8 @@ 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 ([$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");
|
||||
: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");
|
||||
$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") . "\"");
|
||||
|
|
@ -84,15 +82,13 @@ 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 ([$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");
|
||||
: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");
|
||||
} do={
|
||||
:if ([:find "$GetRecordsErr" "status 404";] >= 1) do={
|
||||
:set Records [:toarray ""];
|
||||
|
|
@ -136,8 +132,6 @@ onerror Err {
|
|||
}
|
||||
$LogPrint debug $ScriptName ("APISetRecord - APIResponse: " . $APIResponse);
|
||||
|
||||
$JSONUnload;
|
||||
$LogPrint debug $ScriptName ("APISetRecord - JSONUnload done");
|
||||
$LogPrint debug $ScriptName ("APISetRecord - finished");
|
||||
:return $APIResponse;
|
||||
} do={
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
- [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)
|
||||
|
|
@ -30,18 +28,6 @@ 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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue