Minor changes
Moved config into $GLOBALS Moved request_uri into $GLOBALS Modified all files accordingly Modified logout page for future improvements (not deleting the entire $_SESSION) Fixed LICENSEs, moved LICENSE for PHP files in /lib/php subfolder instead of /lib
This commit is contained in:
parent
18dc9b18d3
commit
81d21c311f
4
LICENSE
4
LICENSE
@ -6,7 +6,7 @@ please read carefully every LICENSE file provided
|
|||||||
to fully understand what you can do and what not.
|
to fully understand what you can do and what not.
|
||||||
|
|
||||||
|
|
||||||
errors/* - js/* - functions.php - index.php:
|
lib/css/* - lib/errors/* - lib/js/* - functions.php - index.php:
|
||||||
Copyright © 2019 - Bryan Pedini
|
Copyright © 2019 - Bryan Pedini
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -22,7 +22,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
config.php:
|
config.json:
|
||||||
It's a stupid config file, do you really think I want to
|
It's a stupid config file, do you really think I want to
|
||||||
beat my head to decide what license is it under or to
|
beat my head to decide what license is it under or to
|
||||||
create one? Use it to do whatever you want, it may break
|
create one? Use it to do whatever you want, it may break
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once ( 'lib/php/classes/Database.php' );
|
require_once ( 'lib/php/classes/Database.php' );
|
||||||
function split_uri_array ( string $php_self, string $request_uri ) : Array {
|
function split_uri_array ( ) : Array {
|
||||||
$uri = substr ( $request_uri, strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ), strlen ( $request_uri ) - strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ) );
|
$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 ( );
|
$arr = Array ( );
|
||||||
$last_arg_pos = 0;
|
$last_arg_pos = 0;
|
||||||
if ( substr ( $uri, strlen ( $uri ) - 1, 1 ) == "/" ) {
|
if ( substr ( $uri, strlen ( $uri ) - 1, 1 ) == "/" ) {
|
||||||
@ -22,4 +22,3 @@
|
|||||||
$config [ 'installation_path' ] = $_SERVER [ 'DOCUMENT_ROOT' ] . $config [ 'installation_path' ];
|
$config [ 'installation_path' ] = $_SERVER [ 'DOCUMENT_ROOT' ] . $config [ 'installation_path' ];
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start ( );
|
session_start ( );
|
||||||
require_once ( 'functions.php' );
|
require_once ( 'functions.php' );
|
||||||
$config = load_config ( );
|
$GLOBALS [ 'config' ] = load_config ( );
|
||||||
$request = split_uri_array ( $_SERVER [ 'SCRIPT_NAME' ], $_SERVER [ 'REQUEST_URI' ] );
|
$GLOBALS [ 'request_uri' ] = split_uri_array ( );
|
||||||
if ( isset ( $request [ 0 ] ) && $request [ 0 ] != "" ) {
|
if ( isset ( $request [ 0 ] ) && $request [ 0 ] != "" ) {
|
||||||
switch ( $request [ 0 ] ) {
|
switch ( $request [ 0 ] ) {
|
||||||
case "go":
|
case "go":
|
||||||
@ -26,4 +26,3 @@
|
|||||||
else {
|
else {
|
||||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -10,7 +10,7 @@ function urlinsert() {
|
|||||||
if ( response [ 'status' ] == 200 ) {
|
if ( response [ 'status' ] == 200 ) {
|
||||||
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
|
||||||
var div = document.createElement ( 'div' );
|
var div = document.createElement ( 'div' );
|
||||||
div.innerHTML = response [ 'new_id' ] + " | " + url;
|
div.innerHTML = response [ 'last_insert' ] + " | " + url;
|
||||||
document.getElementById ( "urllist" ).appendChild ( div );
|
document.getElementById ( "urllist" ).appendChild ( div );
|
||||||
document.getElementById ( "form-url" ).value = "";
|
document.getElementById ( "form-url" ).value = "";
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ working purposes, and is proprietary software.
|
|||||||
Such this code may not be copied without explicit permission from
|
Such this code may not be copied without explicit permission from
|
||||||
myself only, this code may not be modified within the website,
|
myself only, this code may not be modified within the website,
|
||||||
you may not copy, edit, share, clone or do anything else but
|
you may not copy, edit, share, clone or do anything else but
|
||||||
use the code as is without explicit permission to do so.
|
use the code as is, without explicit permission to do so.
|
||||||
|
|
||||||
Such permissions can be requested at copyright@bryanpedini.it
|
Such permissions can be requested at copyright@bryanpedini.it
|
||||||
No permissions to do anything against this license is given
|
No permissions to do anything against this license is given
|
||||||
without an explicit and valid motivation to do so, so please
|
without an explicit and valid motivation to do so, so please
|
||||||
don't email me asking to do so or so without providing why.
|
don't email me asking any permission without providing a valid reason.
|
@ -5,7 +5,7 @@
|
|||||||
private $statement;
|
private $statement;
|
||||||
|
|
||||||
public function __construct ( $config ) {
|
public function __construct ( $config ) {
|
||||||
if ( $config ) {
|
if ( $config && $config [ 'host' ] && $config [ 'username' ] && $config [ 'password' ] && $config [ 'name' ] && $config [ 'port' ] ) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -41,4 +41,4 @@
|
|||||||
public function get_result ( ) : MySQLi_result {
|
public function get_result ( ) : MySQLi_result {
|
||||||
return $this->statement->get_result ( );
|
return $this->statement->get_result ( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||||
|
$database->connect ( );
|
||||||
|
if ( isset ( $_POST [ 'forgot_email' ] ) ) {
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
elseif ( isset ( $_POST [ 'forgot_username' ] ) ) {
|
||||||
|
//...
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( isset ( $request [ 1 ] ) ) {
|
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) ) {
|
||||||
$link_id = $request [ 1 ];
|
$link_id = $GLOBALS [ 'request_uri' ] [ 1 ];
|
||||||
if ( ! ctype_digit ( $link_id ) ) {
|
if ( ! ctype_digit ( $link_id ) ) {
|
||||||
die ( "You can't be forwarded to a non numerical URL link ID. If you think this is incorrect, please send an email to shorte@dev.bryanpedini.it with this URL: https://sh.bjphoster.com/?go=" . $link_id . " for more investigations" );
|
die ( "You can't be forwarded to a non numerical URL link ID. If you think this is incorrect, please send an email to shorte@dev.bryanpedini.it with this URL: https://sh.bjphoster.com/?go=" . $link_id . " for more investigations" );
|
||||||
}
|
}
|
||||||
$link_id = (int) $link_id;
|
$link_id = (int) $link_id;
|
||||||
$database = new Database ( $config [ 'db' ] );
|
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||||
$database->connect ( );
|
$database->connect ( );
|
||||||
$database->prepare ( "SELECT links.URL FROM links WHERE links.ID = ?" );
|
$database->prepare ( "SELECT links.URL FROM links WHERE links.ID = ?" );
|
||||||
$parameters = [
|
$parameters = [
|
||||||
@ -18,7 +18,7 @@
|
|||||||
$row = $result->fetch_assoc ( );
|
$row = $result->fetch_assoc ( );
|
||||||
if ( ! $row ) {
|
if ( ! $row ) {
|
||||||
http_response_code ( 404 );
|
http_response_code ( 404 );
|
||||||
include ( $config [ 'installation_path' ] . '/lib/errors/404.html' );
|
include ( $GLOBALS [ 'config' ] [ 'installation_path' ] . '/lib/errors/404.html' );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -55,4 +55,3 @@
|
|||||||
else {
|
else {
|
||||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
|
||||||
}
|
}
|
||||||
?>
|
|
@ -2,10 +2,10 @@
|
|||||||
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
|
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
|
||||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
|
||||||
}
|
}
|
||||||
|
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||||
|
$database->connect ( );
|
||||||
if ( isset ( $_POST [ 'url' ] ) ) {
|
if ( isset ( $_POST [ 'url' ] ) ) {
|
||||||
$url = $_POST [ 'url' ];
|
$url = $_POST [ 'url' ];
|
||||||
$database = new Database ( $config [ 'db' ] );
|
|
||||||
$database->connect ( );
|
|
||||||
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
|
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
|
||||||
$parameters = [
|
$parameters = [
|
||||||
[ "s" ],
|
[ "s" ],
|
||||||
@ -13,7 +13,7 @@
|
|||||||
];
|
];
|
||||||
$database->bind ( $parameters );
|
$database->bind ( $parameters );
|
||||||
$database->execute ( );
|
$database->execute ( );
|
||||||
$database->prepare ( "SELECT COUNT( links.ID ) as `count` FROM links;");
|
$database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
|
||||||
$database->execute ( );
|
$database->execute ( );
|
||||||
$result = $database->get_result ( );
|
$result = $database->get_result ( );
|
||||||
$row = $result->fetch_assoc ( );
|
$row = $result->fetch_assoc ( );
|
||||||
@ -21,13 +21,12 @@
|
|||||||
$response = [
|
$response = [
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
'message' => 'URL inserted correctly.',
|
'message' => 'URL inserted correctly.',
|
||||||
'new_id' => $row [ 'count' ],
|
'last_insert' => $row [ 'last' ],
|
||||||
];
|
];
|
||||||
echo ( json_encode ( $response ) );
|
echo ( json_encode ( $response ) );
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$database = new Database ( $config [ 'db' ] );
|
|
||||||
$database->connect ( );
|
|
||||||
$database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
|
$database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
|
||||||
$database->execute ( );
|
$database->execute ( );
|
||||||
$result = $database->get_result ( );
|
$result = $database->get_result ( );
|
||||||
@ -62,4 +61,3 @@
|
|||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
|
@ -23,6 +23,7 @@
|
|||||||
$row = $result->fetch_assoc ( );
|
$row = $result->fetch_assoc ( );
|
||||||
if ( ! $row ) {
|
if ( ! $row ) {
|
||||||
header ( 'Content-Type: application/json' );
|
header ( 'Content-Type: application/json' );
|
||||||
|
http_response_code ( 401 );
|
||||||
$response = [
|
$response = [
|
||||||
'status' => 401,
|
'status' => 401,
|
||||||
'error_message' => 'Username or password not correct.',
|
'error_message' => 'Username or password not correct.',
|
||||||
@ -81,4 +82,3 @@
|
|||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
|
@ -1,5 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$_SESSION = array ( );
|
$_SESSION [ 'user_id' ] = NULL;
|
||||||
session_destroy ( );
|
|
||||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/" );
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/" );
|
||||||
?>
|
|
Reference in New Issue
Block a user