summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-07-15 14:00:27 +0200
committerErich Eckner <git@eckner.net>2022-07-15 14:00:27 +0200
commitf1562e898743c2d45042ed728ec1feb176e5aa48 (patch)
treed324ad643a8a19d4efc02b559eec685ba3d96cfa
parentcd14afb5d3cf88f8442178846969c2570ca15c2e (diff)
downloadcolocation-f1562e898743c2d45042ed728ec1feb176e5aa48.tar.xz
split off maintenance.php
-rw-r--r--html/index.php25
-rw-r--r--html/maintenance.php30
2 files changed, 30 insertions, 25 deletions
diff --git a/html/index.php b/html/index.php
index 0964dc3..5021124 100644
--- a/html/index.php
+++ b/html/index.php
@@ -2,31 +2,6 @@
$db = new SQLite3('/srv/http/vhosts/eckner.net/colocation.eckner.net/backend/sqlite.db');
-if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) {
- if (array_key_exists('new',$_GET)) {
- $stm = $db -> prepare('SELECT COUNT(1) FROM machines WHERE machines.name=:name');
- $stm -> bindValue('name', $_GET['new']);
- $result = $stm -> execute();
- $result = $result -> fetchArray();
- $stm -> close();
-
- if ($result[0] == 0) {
- $stm = $db -> prepare('INSERT INTO machines (name,key,online) VALUES (:name,:key,0)');
- $stm -> bindValue('name', $_GET['new']);
- $stm -> bindValue('key', bin2hex(random_bytes(64)));
- $stm -> execute();
- $stm -> close();
- }
-
- $stm = $db -> prepare('SELECT machines.key FROM machines WHERE machines.name=:name');
- $stm -> bindValue('name', $_GET['new']);
- $result = $stm -> execute();
- $result = $result -> fetchArray();
- echo 'key = ' . $result['key'] . "\n";
- die();
- }
-}
-
$columns = array('name', 'online', 'last_update');
$result = $db -> query('SELECT machines.name,machines.online,machines.last_update FROM machines;');
diff --git a/html/maintenance.php b/html/maintenance.php
new file mode 100644
index 0000000..8b93f5f
--- /dev/null
+++ b/html/maintenance.php
@@ -0,0 +1,30 @@
+<?php
+
+if ($_SERVER['REMOTE_ADDR'] !== $_SERVER['SERVER_ADDR']) {
+ die();
+}
+
+$db = new SQLite3('/srv/http/vhosts/eckner.net/colocation.eckner.net/backend/sqlite.db');
+
+if (array_key_exists('new',$_GET)) {
+ $stm = $db -> prepare('SELECT COUNT(1) FROM machines WHERE machines.name=:name');
+ $stm -> bindValue('name', $_GET['new']);
+ $result = $stm -> execute();
+ $result = $result -> fetchArray();
+ $stm -> close();
+
+ if ($result[0] == 0) {
+ $stm = $db -> prepare('INSERT INTO machines (name,key,online) VALUES (:name,:key,0)');
+ $stm -> bindValue('name', $_GET['new']);
+ $stm -> bindValue('key', bin2hex(random_bytes(64)));
+ $stm -> execute();
+ $stm -> close();
+ }
+
+ $stm = $db -> prepare('SELECT machines.key FROM machines WHERE machines.name=:name');
+ $stm -> bindValue('name', $_GET['new']);
+ $result = $stm -> execute();
+ $result = $result -> fetchArray();
+ echo 'key = ' . $result['key'] . "\n";
+ die();
+}