diff options
author | Erich Eckner <git@eckner.net> | 2022-07-28 11:37:34 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-07-28 11:37:34 +0200 |
commit | 2b4d629419f4d9d82d736050e943793b5a778ea9 (patch) | |
tree | 8ab2d4ef9321d942726142b4b1be8b0f1a55ddde | |
parent | df0ace6fac9927e9d35182b07f97731de1ffe976 (diff) | |
download | colocation-2b4d629419f4d9d82d736050e943793b5a778ea9.tar.xz |
use old ddns key if available
-rw-r--r-- | html/db.php | 7 | ||||
-rw-r--r-- | html/maintenance.php | 15 |
2 files changed, 17 insertions, 5 deletions
diff --git a/html/db.php b/html/db.php index 9830c5b..fee5ef6 100644 --- a/html/db.php +++ b/html/db.php @@ -36,9 +36,12 @@ class MyDB extends SQLite3 { die(); return $result['state_id']; } - function add_key($comment) { + function add_key($comment, $key = NULL) { $stm = $this -> prepare('INSERT INTO keys (key, comment) VALUES (:key, :comment)'); - $stm -> bindValue('key', bin2hex(random_bytes(64))); + if ($key == NULL) + $stm -> bindValue('key', bin2hex(random_bytes(64))); + else + $stm -> bindValue('key', $key); $stm -> bindValue('comment', $comment); $stm -> execute(); $key_id = $this -> lastInsertRowID(); diff --git a/html/maintenance.php b/html/maintenance.php index 39b0724..b45b731 100644 --- a/html/maintenance.php +++ b/html/maintenance.php @@ -96,9 +96,18 @@ if (array_key_exists('ddns', $_GET)) { ' WHERE keys.comment = ' . "'" . 'ddns' . "'" ); $row = $result -> fetchArray(); - if (! $row) - $key_id = $db -> add_key('ddns'); - else + if (! $row) { + unset($key); + if (file_exists('/srv/http/vhosts/eckner.net/ddns/colocation-token')) { + $key = trim(file_get_contents('/srv/http/vhosts/eckner.net/ddns/colocation-token')); + if (strlen($key) != 128) + unset($key); + } + if (isset($key)) + $key_id = $db -> add_key('ddns', $key); + else + $key_id = $db -> add_key('ddns'); + } else $key_id = $row['id']; $stm = $db -> prepare('INSERT INTO permissions (key_id, value_id) VALUES (:key_id, :value_id)'); |