0
0

Website refactored

Prepared the website structure for the new layout
This commit is contained in:
Bryan 2019-05-29 19:01:38 +02:00
parent eeffcd93cf
commit b21dd0518d
No known key found for this signature in database
GPG Key ID: 6CB4C49B61AD50EF
10 changed files with 150 additions and 87 deletions

View File

@ -1,11 +1,11 @@
{
"installed": false,
"website_name": "OpenShorte",
"db": {
"host": "127.0.0.1",
"port": 3306,
"username": "",
"password": "",
"name": ""
},
"installation_path": ""
}
}

View File

@ -1,24 +1,8 @@
<?php
require_once ( 'lib/php/classes/Database.php' );
function split_uri_array ( ) : Array {
$uri = substr ( $_SERVER [ 'REQUEST_URI' ], strlen ( substr ( $_SERVER [ 'REQUEST_URI' ], 0, strrpos ( $_SERVER [ 'REQUEST_URI' ], 'index.php' ) ) ), strlen ( $_SERVER [ 'REQUEST_URI' ] ) - strlen ( substr ( $_SERVER [ 'REQUEST_URI' ], 0, strrpos ( $_SERVER [ 'REQUEST_URI' ], 'index.php' ) ) ) );
$arr = Array ( );
$last_arg_pos = 0;
if ( substr ( $uri, strlen ( $uri ) - 1, 1 ) == "/" ) {
$uri = substr ( $uri, 0, strlen ( $uri ) - 1 );
}
for ( $i = 1; $i < ( strlen ( $uri ) ) - 1; $i ++ ) {
if ( substr ( $uri, $i, 1 ) == "/" && substr ( $uri, $i + 1, 1 ) != "/" && substr ( $uri, $i - 1, 1 ) != "/" ) {
$arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos);
$last_arg_pos = $i + 1;
}
}
$arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos + 1);
return $arr;
}
function load_config ( ) : array {
$config = file_get_contents ( 'config.json' );
$config = json_decode ( $config, true );
$config [ 'installation_path' ] = $_SERVER [ 'DOCUMENT_ROOT' ] . $config [ 'installation_path' ];
$config [ 'installation_path' ] = substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 );
return $config;
}

View File

@ -14,8 +14,8 @@
case "logout":
include ( 'lib/php/logout.php' );
break;
case "insert":
include ( 'lib/php/insert.php' );
case "dashboard":
include ( 'lib/php/dashboard.php' );
break;
default:
http_response_code ( 404 );
@ -24,5 +24,5 @@
}
}
else {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/dashboard" );
}

0
lib/css/dashboard.css Normal file
View File

33
lib/php/dashboard.php Normal file
View File

@ -0,0 +1,33 @@
<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/login" );
}
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) ) {
switch ( $GLOBALS [ 'request_uri' ] [ 1 ] ) {
case "manage":
include ( 'lib/php/manage.php' );
break;
case "insert":
include ( 'lib/php/insert.php' );
break;
default:
http_response_code ( 404 );
include ( 'errors/404.html' );
die ( );
}
}
else {
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
<title>Dashboard Home | <?=$GLOBALS['config']['website_name']?></title>
</head>
<body>
<a href="<?=$GLOBALS['config']['installation_path']?>/dashboard/manage">Open Management Console</a>
</body>
</html>
<?php
}

View File

@ -11,7 +11,9 @@
<!DOCTYPE HTML>
<html>
<head>
<title>BJPHoster URL Shortener | Password Reset</title>
<meta charset="UTF-8">
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
<title>Password Reset | <?=$GLOBALS['config']['website_name']?></title>
</head>
<body>
<center>

View File

@ -26,8 +26,9 @@
<!DOCTYPE html>
<html>
<head>
<title id="title">Redirect in 5 seconds</title>
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
<meta charset="UTF-8">
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
<title>Redirect in 5 seconds | <?=$GLOBALS['config']['website_name']?></title>
</head>
<body>
<center>
@ -37,7 +38,7 @@
window.onload = function() {
var seconds = 5;
function update_timeout (interval) {
document.getElementById("title").innerHTML = "Redirect in "+seconds+" seconds";
document.getElementById("title").innerHTML = "Redirect in " + seconds +" seconds | <?=$GLOBALS['config']['website_name']?>";
document.getElementById("body-timeout").innerHTML = seconds;
if (seconds == 0) {
window.location.href = "<?=$row['URL']?>";

View File

@ -1,12 +1,28 @@
<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
header ( 'Content-Type: application/json' );
http_response_code ( 401 );
$response = [
'status' => 401,
'error_message' => 'You either are not logged in or you do not have permissions to insert new URLs.'
];
echo ( json_encode ( $response ) );
exit;
}
if ( ! isset ( $_POST [ 'url' ] ) ) {
header ( 'Content-Type: application/json' );
http_response_code ( 400 );
$response = [
'status' => 400,
'error_message' => 'You either did not provide a URL or you provided an invalid one.'
];
echo ( json_encode ( $response ) );
exit;
}
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
if ( isset ( $_POST [ 'url' ] ) ) {
$url = $_POST [ 'url' ];
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
$database->prepare ( "INSERT INTO `links` ( `URL`, `created_by` ) VALUES ( ?, " . $_SESSION [ 'user_id' ] . " );" );
$parameters = [
[ "s" ],
[ &$url ],
@ -25,39 +41,3 @@
];
echo ( json_encode ( $response ) );
exit;
}
else {
$database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
$database->execute ( );
$result = $database->get_result ( );
$row = $result->fetch_assoc ( );
?>
<!DOCTYPE html>
<html>
<head>
<title>BJPHoster URL Shortener | Control Panel</title>
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<button onclick="logout()">Logout</button>
<div id="urllist">
<?php
if ( ! $row ) {
echo ( "You have not created any URL yet.<br>" );
}
else {
do {
echo ( "\t\t\t" . '<div>' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "</div>\n" );
} while ( $row = $result->fetch_assoc ( ) );
}
?>
</div>
<input type="text" id="form-url" placeholder="URL:">
<button onclick="urlinsert()">Insert new URL</button><br>
<div id="responsetext"></div>
<script src="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/js/insertnew.js"></script>
<script>var script_name = "<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>";</script>
</body>
</html>
<?php
}

View File

@ -1,6 +1,6 @@
<?php
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/insert" );
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/insert" );
exit;
}
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) && $GLOBALS [ 'request_uri' ] [ 1 ] == "forgot" ) {
@ -47,10 +47,10 @@
<!DOCTYPE html>
<html>
<head>
<title>BJPHoster URL Shortener | Login</title>
<title>Redirect in 5 seconds | <?=$GLOBALS['config']['website_name']?></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/css/login.css" rel="stylesheet">
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
<link href="<?=$GLOBALS['config']['installation_path']?>/lib/css/login.css" rel="stylesheet">
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<div class="container login-container">
@ -75,9 +75,9 @@
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/js/sha512.min.js"></script>
<script src="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/js/login.js"></script>
<script>var script_name = "<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>";</script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/sha512.min.js"></script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/login.js"></script>
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
</body>
</html>
<?php

63
lib/php/manage.php Normal file
View File

@ -0,0 +1,63 @@
<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/login" );
}
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
if ( isset ( $_POST [ 'url' ] ) ) {
$url = $_POST [ 'url' ];
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
$parameters = [
[ "s" ],
[ &$url ],
];
$database->bind ( $parameters );
$database->execute ( );
$database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
$database->execute ( );
$result = $database->get_result ( );
$row = $result->fetch_assoc ( );
header ( 'Content-Type: application/json' );
$response = [
'status' => 200,
'message' => 'URL inserted correctly.',
'last_insert' => $row [ 'last' ],
];
echo ( json_encode ( $response ) );
exit;
}
else {
$database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
$database->execute ( );
$result = $database->get_result ( );
$row = $result->fetch_assoc ( );
?>
<!DOCTYPE html>
<html>
<head>
<title>BJPHoster URL Shortener | Control Panel</title>
<link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<button onclick="logout()">Logout</button>
<div id="urllist">
<?php
if ( ! $row ) {
echo ( "You have not created any URL yet.<br>" );
}
else {
do {
echo ( "\t\t\t" . '<div>' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "</div>\n" );
} while ( $row = $result->fetch_assoc ( ) );
}
?>
</div>
<input type="text" id="form-url" placeholder="URL:">
<button onclick="urlinsert()">Insert new URL</button><br>
<div id="responsetext"></div>
<script src="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/js/insertnew.js"></script>
<script>var script_name = "<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>";</script>
</body>
</html>
<?php
}