diff options
author | Erich Eckner <git@eckner.net> | 2022-07-15 13:58:31 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-07-15 13:58:31 +0200 |
commit | cd14afb5d3cf88f8442178846969c2570ca15c2e (patch) | |
tree | 188b46b67f606caa55a3531a9d61021a5063a491 | |
download | colocation-cd14afb5d3cf88f8442178846969c2570ca15c2e.tar.xz |
initial commit
-rw-r--r-- | backend/.gitignore | 1 | ||||
-rw-r--r-- | html/index.php | 52 |
2 files changed, 53 insertions, 0 deletions
diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..c65ee56 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1 @@ +sqlite.db diff --git a/html/index.php b/html/index.php new file mode 100644 index 0000000..0964dc3 --- /dev/null +++ b/html/index.php @@ -0,0 +1,52 @@ +<?php + +$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;'); + +echo '<html>' . "\n"; +echo '<body>' . "\n"; +echo '<table>' . "\n"; +echo ' <tr>' . "\n"; +foreach ($columns as $column) { + echo ' <th>' . $column . '</th>' . "\n"; +} +echo ' </tr>' . "\n"; + +while ($row = $result -> fetchArray()) { + echo ' <tr>' . "\n"; + foreach ($columns as $column) { + echo ' <td>' . $row[$column] . '</td>' . "\n"; + } + echo ' </tr>' . "\n"; +} +echo '</table>' . "\n"; +echo '</body>' . "\n"; +echo '</html>' . "\n"; |