deleted config.json - no more need of it, added installer to create config.json
This commit is contained in:
parent
312d03599f
commit
8abf2c5e8a
11
config.json
11
config.json
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"installed": false,
|
|
||||||
"website_name": "OpenShorte",
|
|
||||||
"db": {
|
|
||||||
"host": "127.0.0.1",
|
|
||||||
"port": 3306,
|
|
||||||
"username": "",
|
|
||||||
"password": "",
|
|
||||||
"name": ""
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,5 @@
|
|||||||
function load_config ( ) : array {
|
function load_config ( ) : array {
|
||||||
$config = file_get_contents ( 'config.json' );
|
$config = file_get_contents ( 'config.json' );
|
||||||
$config = json_decode ( $config, true );
|
$config = json_decode ( $config, true );
|
||||||
$config [ 'installation_path' ] = substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 );
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
13
index.php
13
index.php
@ -1,8 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start ( );
|
session_start ( );
|
||||||
|
$GLOBALS [ 'request_uri' ] = explode ( "/", $_GET [ 'URI' ] );
|
||||||
|
if ( ! file_exists ( 'config.json' ) ) {
|
||||||
|
if ( $GLOBALS[ 'request_uri' ] [ 0 ] !== "install" ) {
|
||||||
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/install" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $GLOBALS [ 'request_uri' ] [ 0 ] == "install" ) {
|
||||||
|
include ( 'lib/php/install.php' );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
require_once ( 'functions.php' );
|
require_once ( 'functions.php' );
|
||||||
$GLOBALS [ 'config' ] = load_config ( );
|
$GLOBALS [ 'config' ] = load_config ( );
|
||||||
$GLOBALS [ 'request_uri' ] = explode ( "/", $_GET [ 'URI' ] );
|
|
||||||
if ( isset ( $GLOBALS [ 'request_uri' ] [ 0 ] ) && $GLOBALS [ 'request_uri' ] [ 0 ] != "" ) {
|
if ( isset ( $GLOBALS [ 'request_uri' ] [ 0 ] ) && $GLOBALS [ 'request_uri' ] [ 0 ] != "" ) {
|
||||||
switch ( $GLOBALS [ 'request_uri' ] [ 0 ] ) {
|
switch ( $GLOBALS [ 'request_uri' ] [ 0 ] ) {
|
||||||
case "go":
|
case "go":
|
||||||
@ -24,5 +33,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/dashboard" );
|
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/login" );
|
||||||
}
|
}
|
||||||
|
148
lib/php/install.php
Normal file
148
lib/php/install.php
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
if ( file_exists ( 'config.json' ) ) {
|
||||||
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/" );
|
||||||
|
}
|
||||||
|
if ( isset ( $_POST [ 'site_name' ] ) && isset ( $_POST [ 'db_host' ] ) && isset ( $_POST [ 'db_port' ] ) && isset ( $_POST [ 'db_username' ] ) && isset ( $_POST [ 'db_password' ] ) && isset ( $_POST [ 'db_name' ] ) ) {
|
||||||
|
$config = [
|
||||||
|
'installed' => true,
|
||||||
|
'website_name' => $_POST [ 'site_name' ],
|
||||||
|
'db' => [
|
||||||
|
'host' => $_POST [ 'db_host' ],
|
||||||
|
'port' => (integer) $_POST [ 'db_port' ],
|
||||||
|
'username' => $_POST [ 'db_username' ],
|
||||||
|
'password' => $_POST [ 'db_password' ],
|
||||||
|
'name' => $_POST [ 'db_name' ],
|
||||||
|
],
|
||||||
|
'installation_path' => substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ),
|
||||||
|
];
|
||||||
|
file_put_contents ( 'config.json', json_encode ( $config ) );
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
?>
|
||||||
|
<DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Installer | OpenShorte</title>
|
||||||
|
<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 {
|
||||||
|
border: solid;
|
||||||
|
border-radius: 25px;
|
||||||
|
border-color: #ABABAB;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="mx-auto my-5 col-sm-8 col-md-6 col-xl-4 centered-container">
|
||||||
|
<div class="my-2"></div>
|
||||||
|
<section id="section_welcome">
|
||||||
|
<p>
|
||||||
|
Welcome to the OpenShorte installer.<br>
|
||||||
|
Since it seems that there are no installation found for this website, we'll proceed now with creating one.<br>
|
||||||
|
Please click 'Next' and provide all the necessary informations for the database and the site name in order to let this website work correctly.
|
||||||
|
</p>
|
||||||
|
<button id="btn_next_sitename" class="btn btn-secondary">Next</button>
|
||||||
|
</section>
|
||||||
|
<section id="section_sitename">
|
||||||
|
<form class="form form-inline">
|
||||||
|
<div class="input-group col-sm-7 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="sitename_label">Website Name:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" aria-describedby="sitename_label" id="site_name" required>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<button id="btn_next_dbdata" class="btn btn-secondary">Next</button>
|
||||||
|
</section>
|
||||||
|
<section id="section_dbdata">
|
||||||
|
<form class="form form-inline">
|
||||||
|
<div class="input-group col-sm-7 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-1">Host:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" aria-describedby="dbdata_label-1" id="db_host" required>
|
||||||
|
</div>
|
||||||
|
<div class="input-group col-sm-5 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-2">Port:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" aria-describedby="dbdata_label-2" id="db_port" required>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form class="form">
|
||||||
|
<div class="input-group col-sm-12 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-3">Username:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" aria-describedby="dbdata_label-3" id="db_username" required>
|
||||||
|
</div>
|
||||||
|
<div class="input-group col-sm-12 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-5">Password:</span>
|
||||||
|
</div>
|
||||||
|
<input type="password" class="form-control" aria-describedby="dbdata_label-5" id="db_password" required>
|
||||||
|
</div>
|
||||||
|
<div class="input-group col-sm-12 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-6">Repeat Password:</span>
|
||||||
|
</div>
|
||||||
|
<input type="password" class="form-control" aria-describedby="dbdata_label-6" id="db_confirmpassword" required>
|
||||||
|
</div>
|
||||||
|
<div class="input-group col-sm-12 mx-auto">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="dbdata_label-4">Database Name:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" aria-describedby="dbdata_label-4" id="db_name" required>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<button id="btn_next_complete" class="btn btn-secondary">Next</button>
|
||||||
|
</section>
|
||||||
|
<section id="section_complete">
|
||||||
|
<div class="mx-auto"></div>
|
||||||
|
</section>
|
||||||
|
<div class="my-2"></div>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
|
||||||
|
<script>
|
||||||
|
$('section:not(#section_welcome)').hide();
|
||||||
|
$('#btn_next_sitename').click(function() {
|
||||||
|
$('section').hide();
|
||||||
|
$('#section_sitename').show();
|
||||||
|
});
|
||||||
|
$('#btn_next_dbdata').click(function() {
|
||||||
|
$('section').hide();
|
||||||
|
$('#section_dbdata').show();
|
||||||
|
});
|
||||||
|
$('#btn_next_complete').click(function() {
|
||||||
|
if ( $('#db_password').val() == $('#db_confirmpassword').val() ) {
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
datatype: "JSON",
|
||||||
|
data: {
|
||||||
|
site_name: $('#site_name').val(),
|
||||||
|
db_host: $('#db_host').val(),
|
||||||
|
db_port: $('#db_port').val(),
|
||||||
|
db_username: $('#db_username').val(),
|
||||||
|
db_password: $('#db_password').val(),
|
||||||
|
db_name: $('#db_name').val(),
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data.status == 200) {
|
||||||
|
$('section').hide();
|
||||||
|
$('#section_complete').show();
|
||||||
|
$('#section_complete div').html(data.message);
|
||||||
|
setInterval(function(){window.location.href=data.homelocation;},5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<?php
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
|
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
|
||||||
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/insert" );
|
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/dashboard" );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) && $GLOBALS [ 'request_uri' ] [ 1 ] == "forgot" ) {
|
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) && $GLOBALS [ 'request_uri' ] [ 1 ] == "forgot" ) {
|
||||||
|
Reference in New Issue
Block a user