From a1ab2a173cd8876996af6ca1827177a2d379a714 Mon Sep 17 00:00:00 2001 From: Bofh Date: Thu, 8 Dec 2022 16:41:08 +0100 Subject: [PATCH] Added feature to add new instances to the config --- api/v1/config/instances/add/index.php | 29 +++++++++++++++ api/v1/network/resolve-instance/index.php | 21 +---------- api/v1/network/resolve-instance/mod.php | 23 ++++++++++++ css/base.php | 45 +++++++++++++++-------- views/add.php | 35 ++++++++++++++++++ views/home.php | 29 +++++++++------ 6 files changed, 135 insertions(+), 47 deletions(-) create mode 100644 api/v1/config/instances/add/index.php create mode 100644 api/v1/network/resolve-instance/mod.php create mode 100644 views/add.php diff --git a/api/v1/config/instances/add/index.php b/api/v1/config/instances/add/index.php new file mode 100644 index 0000000..9720710 --- /dev/null +++ b/api/v1/config/instances/add/index.php @@ -0,0 +1,29 @@ + + + ' given is not supported yet']); + +$_GET['hostname'] = $_GET['instance']; +$data = apimod('api/v1/network/resolve-instance'); +if (isset($data['error'])) + apiresult(['error' => ' could not be resolved. Make sure you\'ve entered it correctly']); + +$software = trim($_GET['software']); +$instance = trim($_GET['instance']); + +$instances_dir = $GLOBALS['appconf']['data_dir'].'/instances'; +if (!file_exists($instances_dir)) + mkdir($instances_dir); +$instances_dir = $instances_dir.'/'.$software; +if (!file_exists($instances_dir)) + mkdir($instances_dir); + +$instance_dir = $instances_dir.'/'.$instance; +if (!file_exists($instance_dir)) + mkdir($instance_dir); + +touch($instance_dir.'/config'); +$uri = preg_replace('#api/v1/config/instances.*#', '', $_SERVER['REQUEST_URI']); +header('Location: '.$uri.'#home'); diff --git a/api/v1/network/resolve-instance/index.php b/api/v1/network/resolve-instance/index.php index 48bbdc0..f803b52 100644 --- a/api/v1/network/resolve-instance/index.php +++ b/api/v1/network/resolve-instance/index.php @@ -1,22 +1,3 @@ - 'Could not find /.well-known/webfinger URL in instance given XML' - ]); -} -apiresult([ - 'instance' => 'https://'.parse_url($m[0], PHP_URL_HOST), -]); + diff --git a/api/v1/network/resolve-instance/mod.php b/api/v1/network/resolve-instance/mod.php new file mode 100644 index 0000000..d8e7442 --- /dev/null +++ b/api/v1/network/resolve-instance/mod.php @@ -0,0 +1,23 @@ + 'Could not find /.well-known/webfinger URL in instance given XML' + ]); + } + return apiresult([ + 'instance' => 'https://'.parse_url($m[0], PHP_URL_HOST), + ]); +} +_main(); diff --git a/css/base.php b/css/base.php index 9f2f504..ecdae76 100644 --- a/css/base.php +++ b/css/base.php @@ -66,8 +66,14 @@ body > .toast-container { .w100 { width: 100% } .h100 { height: 100% } .card { + background: #fff; border-radius: .5em; box-shadow: 0px 0px .5em #0000004f; + padding: 1em; +} +.noborder { + border: none !important; + box-shadow: none !important; } .gray { color: gray } .btn { @@ -89,6 +95,9 @@ body > .toast-container { .btn:focus { filter: brightness(85%); } +.white { + background: #fff; +} .red { background: #ffb5b5; color: #9d0202; @@ -129,6 +138,21 @@ a { color: inherit; } +main input[type=text], +main textarea { + padding: 1em; +} +main input[type=number] { + padding: .5em 1em; + max-width: 8em; +} +main select { + padding: .5em; +} +main .input { + margin-bottom: 1em; +} + .software .only { display: none; } @@ -199,6 +223,11 @@ table.fields tr.verified td .fa.fa-check::before { } +#window-add { + background: ; +} + + #window-instance #tabs { background: #fff; position: relative; @@ -239,23 +268,7 @@ table.fields tr.verified td .fa.fa-check::before { margin: 0 auto; padding: 1em; } -#window-instance #container input[type=text], -#window-instance #container textarea { - padding: 1em; -} -#window-instance #container input[type=number] { - padding: .5em 1em; - max-width: 8em; -} -#window-instance #container select { - padding: .5em; -} -#window-instance #container .input { - margin-bottom: 1em; -} #window-instance #container .card { - background: #fff; - padding: 1em; margin-bottom: 1em; max-width: 40em; } diff --git a/views/add.php b/views/add.php new file mode 100644 index 0000000..2402034 --- /dev/null +++ b/views/add.php @@ -0,0 +1,35 @@ +
+
+ +
+

Add new instance

+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + diff --git a/views/home.php b/views/home.php index 14fc2ae..dbcbd26 100644 --- a/views/home.php +++ b/views/home.php @@ -1,15 +1,22 @@
-
-
-
- - @@ -21,9 +28,9 @@ function load__home() { E.template('instances', function(TPL) { var html = ''; for (var i = 0; i < window.vars.instance_config['supported_ap_software'].length; i++) { - var tpl = TPL; const soft = window.vars.instance_config['supported_ap_software'][i]; for (var j = 0; j < window.vars.instance_config['hosts'][soft].length; j++) { + var tpl = TPL; const hostcfg = window.vars.instance_config['hosts'][soft][j]; tpl = tpl.replaceAll('{software}', soft); tpl = tpl.replaceAll('{software:cap}', capitalize(soft));