open('meowboard.db'); } } // This creates the database file on the system automatically. $db = new Store(); // Initialise tables in the database. $db->exec('CREATE TABLE users(uuid TEXT UNIQUE PRIMARY KEY NOT NULL, username TEXT UNIQUE NOT NULL, password TEXT NOT NULL, pepper TEXT NOT NULL, admin INTEGER DEFAULT 0)'); $db->exec('CREATE TABLE images(id INTEGER PRIMARY KEY AUTOINCREMENT, location TEXT NOT NULL, uploader TEXT NOT NULL, tags TEXT)'); $db->exec('CREATE TABLE settings(key TEXT PRIMARY KEY UNIQUE NOT NULL, value TEXT DEFAULT NULL)'); $db->exec('CREATE TABLE tokens(hash TEXT PRIMARY KEY NOT NULL, uuid TEXT NOT NULL, expiry INTEGER)'); // Create UUID and place it into binding to add for the admin user. $uuidBinding = genUuid4(); // Add the admin user to the database. $insert_user_query = $db->prepare('INSERT INTO users (uuid, username, password, pepper, admin) VALUES (?, ?, ?, ?, 1)'); $insert_user_query->bindParam(1, $uuidBinding, SQLITE3_TEXT); $insert_user_query->bindParam(2, $username, SQLITE3_TEXT); $insert_user_query->bindParam(3, $passwordFinal, SQLITE3_TEXT); $insert_user_query->bindParam(4, $pepperHex, SQLITE3_TEXT); $result = $insert_user_query->execute(); // Add the salt into the database otherwise it will be impossible to login. // Also add site name in. $insert_salt_query = $db->prepare('INSERT INTO settings (key, value) VALUES ("salt", ?)'); $insert_salt_query->bindParam(1, $saltHex, SQLITE3_TEXT); $result = $insert_salt_query->execute(); $insert_sitename_query = $db->prepare('INSERT INTO settings (key, value) VALUES ("sitename", ?)'); $insert_sitename_query->bindParam(1, $sitename, SQLITE3_TEXT); $result = $insert_sitename_query->execute(); die("Install complete."); } else { showHeader(1); echo '

Install meowboard

'; echo '

Admin account credentials

'; echo '


'; echo '

'; echo '

Site settings

'; echo '

'; echo '
'; echo $footer; } ?>