0
0

Completed installer

This commit is contained in:
Bryan 2019-06-02 16:35:02 +02:00
parent 3ad9729947
commit ea4becd52d
No known key found for this signature in database
GPG Key ID: 6CB4C49B61AD50EF

View File

@ -16,6 +16,18 @@
'installation_path' => substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ),
];
file_put_contents ( 'config.json', json_encode ( $config ) );
try {
$database = new PDO ( "mysql:dbname=" . $config [ 'db' ] [ 'name' ] . ";host=" . $config [ 'db' ] [ 'host' ] . ":" . $config [ 'db' ] [ 'port' ], $config [ 'db' ] [ 'username' ], $config [ 'db' ] [ 'password' ] );
}
catch ( PDOException $exception ) {
unlink ( "config.json" );
http_response_code ( 400 );
header ( 'Content-Type: application/json' );
echo ( json_encode ( [ 'status' => 400, 'message' => $exception->getMessage ( ) ] ) );
exit;
}
$query = "CREATE TABLE IF NOT EXISTS `users` ( `ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_bin', `password` VARCHAR(128) NOT NULL COLLATE 'utf8mb4_bin', PRIMARY KEY (`ID`) ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `links` ( `ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `URL` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_bin', `created_by` BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (`ID`), INDEX `links.created_by` (`created_by`), CONSTRAINT `links.created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`ID`) ON UPDATE CASCADE ON DELETE CASCADE ) COLLATE='utf8mb4_bin' ENGINE=InnoDB;";
$database->query ( $query );
header ( 'Content-Type: application/json' );
echo ( json_encode ( [ 'status' => 200, 'message' => 'Installation completed!<br>You will be redirected to the home page in 5 seconds.', 'homelocation' => $config [ 'installation_path' ] ] ) );
exit;
@ -27,6 +39,7 @@
<head>
<meta charset="UTF-8">
<title>Installer | OpenShorte</title>
<link href="./favicon.ico" rel="icon" type="image/x-icon">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.centered-container {
@ -137,6 +150,9 @@
$('#section_complete div').html(data.message);
setInterval(function(){window.location.href=data.homelocation;},5000);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText.message);
}
});
}