diff options
Diffstat (limited to 'html/maintenance.php')
-rw-r--r-- | html/maintenance.php | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/html/maintenance.php b/html/maintenance.php index 3eaf640..b5cc742 100644 --- a/html/maintenance.php +++ b/html/maintenance.php @@ -6,17 +6,19 @@ if ($_SERVER['REMOTE_ADDR'] !== $_SERVER['SERVER_ADDR']) { $db = new SQLite3('/srv/http/vhosts/eckner.net/colocation.eckner.net/backend/sqlite.db'); +$states = array('running', 'ping', 'power'); + if (array_key_exists('drop',$_GET) && ($_GET['drop']=='DROP')) { $db -> exec('DROP TABLE machines'); $db -> exec('DROP TABLE keys'); $db -> exec('DROP TABLE permissions'); $db -> exec('DROP TABLE granted_permissions'); - $db -> exec('CREATE TABLE machines (id integer primary key AUTOINCREMENT, name varchar(32) not null unique, online int not null default 0, last_update TIMESTAMP default CURRENT_TIMESTAMP);'); + $db -> exec('CREATE TABLE machines (id integer primary key AUTOINCREMENT, name varchar(32) not null unique, ' . implode(' int not null default 0, ', $states) . ' int not null default 0, last_update TIMESTAMP default CURRENT_TIMESTAMP);'); $db -> exec('CREATE TABLE keys (id integer primary key AUTOINCREMENT, key varchar(128) not null unique);'); $db -> exec('CREATE TABLE permissions (id integer primary key AUTOINCREMENT, name varchar(32) not null unique)'); $db -> exec('CREATE TABLE granted_permissions (key_id integer not null, machine_id integer not null, permission_id integer not null)'); $stm = $db -> prepare('INSERT INTO permissions (name) VALUES (:permission)'); - foreach (array('running', 'ping', 'power') as $permission) { + foreach ($states as $permission) { $stm -> bindValue('permission', $permission); $stm -> execute(); } @@ -33,7 +35,7 @@ if (array_key_exists('machine',$_GET)) { if ($result[0] == 0) { $key = bin2hex(random_bytes(64)); - $stm = $db -> prepare('INSERT INTO machines (name,online) VALUES (:machine,0)'); + $stm = $db -> prepare('INSERT INTO machines (name) VALUES (:machine)'); $stm -> bindValue('machine', $_GET['machine']); $stm -> execute(); $machine_id = $db -> lastInsertRowID(); |