From a3ba9ed45e67ffa1a98d5ae67056d45d2b5764cd Mon Sep 17 00:00:00 2001 From: Bart van Halder Date: Thu, 25 Jul 2024 15:32:03 +0200 Subject: [PATCH 1/2] Add a way to load templates from json files --- includes/misc.inc.php | 21 +++++++++++++++++++++ templates.d/template.json.example | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 templates.d/template.json.example diff --git a/includes/misc.inc.php b/includes/misc.inc.php index 88cb2a1..a57cea4 100644 --- a/includes/misc.inc.php +++ b/includes/misc.inc.php @@ -253,6 +253,27 @@ function jtable_respond($records, $method = 'multiple', $msg = 'Undefined errorm function user_template_list() { global $templates; + if (is_dir("templates.d")) { + if ($templdir=opendir("templates.d")) { + while ($entry = readdir($templdir)) { + if (!str_ends_with($entry, ".json")) { + continue; + } + $f=file_get_contents("templates.d/$entry"); + if ($f === false) { + error_log("Error reading file templates.d/$entry", 0); + continue; + } + $t = json_decode($f, true); + if ($t === null) { + error_log("Error decoding templates.d/$entry", 0); + continue; + } + array_push($templates, $t); + } + } + } + $templatelist = array(); foreach ($templates as $template) { if (is_adminuser() diff --git a/templates.d/template.json.example b/templates.d/template.json.example new file mode 100644 index 0000000..0113ecb --- /dev/null +++ b/templates.d/template.json.example @@ -0,0 +1,28 @@ +{ + "name": "Example Template", + "owner": "public", + "records": [ + { + "name": "", + "type": "NS", + "content": "ns1.example.com.", + "label": "ns1" + }, + { + "name": "", + "type": "NS", + "content": "ns2.example.com.", + "label": "ns2" + }, + { + "name": "example-txt", + "type": "TXT", + "content": "This is an example txt record" + }, + { + "name": "localhost", + "type": "A", + "content": "127.0.0.1" + } + ] +} From 8e1d0035d3f099aae1e20c4a1eb522479a7be2e1 Mon Sep 17 00:00:00 2001 From: Bart van Halder Date: Thu, 25 Jul 2024 15:38:00 +0200 Subject: [PATCH 2/2] [.gitignore] ignore json files in templates.d/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 62b9b11..8c80a71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ includes/config.inc.php nsedit.sublime* etc +templates.d/*.json