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
10 changed files with 150 additions and 87 deletions

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,63 +1,43 @@
<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/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' );
http_response_code ( 401 );
$response = [
'status' => 200,
'message' => 'URL inserted correctly.',
'last_insert' => $row [ 'last' ],
'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;
}
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
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 ( );
$url = $_POST [ 'url' ];
$database->prepare ( "INSERT INTO `links` ( `URL`, `created_by` ) VALUES ( ?, " . $_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;

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
}