setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $tables = [ 'nodes' => "CREATE TABLE nodes ( node_id INTEGER PRIMARY KEY AUTOINCREMENT, hostname TEXT NOT NULL UNIQUE, ipaddr TEXT NOT NULL, cpu_cores INTEGER, total_memory INTEGER, disk_space INTEGER, sshport INTEGER, loc TEXT, sshuser TEXT, sshkey TEXT, uptime TEXT, memused TEXT, disksys TEXT, diskclnt TEXT, load TEXT, make TEXT, model TEXT, cpu TEXT, vms INTEGER, lastvnc INTEGER, lastws INTEGER, lastvm INTEGER, os_version TEXT, kernel_version TEXT, libvirt_version TEXT, status INTEGER, last_updated DATETIME )", 'last_run' => "CREATE TABLE IF NOT EXISTS last_run ( id INTEGER PRIMARY KEY AUTOINCREMENT, script_name TEXT NOT NULL, last_run_time INTEGER )", 'ostemplates' => "CREATE TABLE IF NOT EXISTS ostemplates ( templateid INTEGER PRIMARY KEY AUTOINCREMENT, filename TEXT NOT NULL, friendlyname TEXT NOT NULL, type TEXT NOT NULL, variant TEXT NOT NULL, status TEXT NOT NULL, added DATETIME )", 'ipv4' => "CREATE TABLE IF NOT EXISTS ipv4 ( ipid INTEGER PRIMARY KEY AUTOINCREMENT, ipaddress TEXT NOT NULL, gwip TEXT NOT NULL, vmid INTEGER, reserved INTEGER, node INTEGER, loc TEXT, notes TEXT, status INTEGER, last_updated DATETIME )", 'ipv6' => "CREATE TABLE IF NOT EXISTS ipv6 ( ipid INTEGER PRIMARY KEY AUTOINCREMENT, ipaddress TEXT NOT NULL, gwip TEXT NOT NULL, vmid INTEGER, reserved INTEGER, node INTEGER, loc TEXT, notes TEXT, status INTEGER, last_updated DATETIME )", 'staff' => "CREATE TABLE staff ( staff_id INTEGER PRIMARY KEY AUTOINCREMENT, staff_username TEXT NOT NULL DEFAULT '', staff_email TEXT NOT NULL DEFAULT '', staff_password TEXT NOT NULL DEFAULT 0, staff_active INTEGER NOT NULL DEFAULT 0, staff_rememberme_token TEXT NOT NULL DEFAULT 0, staff_mfa TEXT NOT NULL DEFAULT '', staff_ip TEXT NOT NULL DEFAULT 0, staff_lastlogin TEXT NULL DEFAULT NULL, staff_failed_logins INTEGER NOT NULL DEFAULT 0, staff_locked DATETIME NOT NULL DEFAULT '1970-01-01 00:00:01' )", 'vms' => "CREATE TABLE vms ( vm_id INTEGER PRIMARY KEY AUTOINCREMENT, node_id INTEGER NOT NULL, name TEXT NOT NULL, hostname TEXT NOT NULL, ip_address TEXT, status INTEGER, protected INTEGER, loc TEXT, cpu_cores INTEGER, memory INTEGER, disk1 TEXT, disk_space1 INTEGER, disk2 TEXT, disk_space2 INTEGER, disk3 TEXT, disk_space3 INTEGER, disk4 TEXT, disk_space4 INTEGER, ipv4 INTEGER, ipv6 INTEGER, mac_address TEXT, os_template TEXT, os_type TEXT, nic INTEGER, iow INTEGER, notes TEXT, vncpw TEXT, vncport INTEGER, vncexpire INTEGER, websockify INTEGER, netdriver TEXT, network TEXT, diskdriver TEXT, bootorder TEXT, created_at DATETIME, last_updated DATETIME )", 'clusters' => "CREATE TABLE IF NOT EXISTS clusters ( clusterid INTEGER PRIMARY KEY AUTOINCREMENT, loc TEXT NOT NULL, friendlyname TEXT NOT NULL, notes TEXT, status INTEGER, last_updated DATETIME )" ]; foreach ($tables as $name => $sql) { $stmt = $conn->prepare($sql); $stmt->execute(); } $stmt = $conn->prepare("INSERT INTO staff (staff_username, staff_password, staff_active) VALUES (:username, :password, :active)"); $stmt->bindValue(':username', "$username", SQLITE3_TEXT); $stmt->bindValue(':password', "$hashedPassword", SQLITE3_TEXT); $stmt->bindValue(':active', '1', SQLITE3_INTEGER); $stmt->execute(); //Create the SSH key $privateKey = EC::createKey('Ed25519'); $publicKey = $privateKey->getPublicKey(); $privateKeyString = $privateKey->toString('OpenSSH'); $publicKeyString = $publicKey->toString('OpenSSH'); file_put_contents($sshkeypriv, $privateKeyString); file_put_contents($sshkeypub, $publicKeyString); $success = "Database has been deployed and the tables have been successfully created.
An SSH key has been generated for internal use."; } catch(PDOException $e) { $error = $e->getMessage(); } $file = fopen('LOCKED', 'w'); if ($file == false) { $lock = "Unable to lock the directory to prevent the install.php script from being run again. Either manually create a file named LOCKED in this directory or delete the install.php to be safe."; } else { $lock = "Lock file created to prevent the install.php file from being run again. You can delete the install.php file just to safe."; fclose($file); } ?> KontrolVM
KontrolVM Logo

Install Fail


Install Success



The following user was created:
Username:
Password:
Write these down, they will not be displayed again and cannot be recovered at this time.


LOGIN



Powered by KontrolVM