mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-18 19:59:30 +03:00
Add a way to load templates from json files
This commit is contained in:
parent
65d58cfd92
commit
a3ba9ed45e
2 changed files with 49 additions and 0 deletions
|
@ -253,6 +253,27 @@ function jtable_respond($records, $method = 'multiple', $msg = 'Undefined errorm
|
||||||
function user_template_list() {
|
function user_template_list() {
|
||||||
global $templates;
|
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();
|
$templatelist = array();
|
||||||
foreach ($templates as $template) {
|
foreach ($templates as $template) {
|
||||||
if (is_adminuser()
|
if (is_adminuser()
|
||||||
|
|
28
templates.d/template.json.example
Normal file
28
templates.d/template.json.example
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue