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.
|
||||
|
||||
|
||||
errors/* - js/* - functions.php - index.php:
|
||||
lib/css/* - lib/errors/* - lib/js/* - functions.php - index.php:
|
||||
Copyright © 2019 - Bryan Pedini
|
||||
|
||||
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.
|
||||
|
||||
|
||||
config.php:
|
||||
config.json:
|
||||
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
|
||||
create one? Use it to do whatever you want, it may break
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once ( 'lib/php/classes/Database.php' );
|
||||
function split_uri_array ( string $php_self, string $request_uri ) : 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' ) ) ) );
|
||||
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 ) == "/" ) {
|
||||
@ -22,4 +22,3 @@
|
||||
$config [ 'installation_path' ] = $_SERVER [ 'DOCUMENT_ROOT' ] . $config [ 'installation_path' ];
|
||||
return $config;
|
||||
}
|
||||
?>
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
session_start ( );
|
||||
require_once ( 'functions.php' );
|
||||
$config = load_config ( );
|
||||
$request = split_uri_array ( $_SERVER [ 'SCRIPT_NAME' ], $_SERVER [ 'REQUEST_URI' ] );
|
||||
$GLOBALS [ 'config' ] = load_config ( );
|
||||
$GLOBALS [ 'request_uri' ] = split_uri_array ( );
|
||||
if ( isset ( $request [ 0 ] ) && $request [ 0 ] != "" ) {
|
||||
switch ( $request [ 0 ] ) {
|
||||
case "go":
|
||||
@ -26,4 +26,3 @@
|
||||
else {
|
||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
|
||||
}
|
||||
?>
|
||||
|
@ -10,7 +10,7 @@ function urlinsert() {
|
||||
if ( response [ 'status' ] == 200 ) {
|
||||
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
|
||||
var div = document.createElement ( 'div' );
|
||||
div.innerHTML = response [ 'new_id' ] + " | " + url;
|
||||
div.innerHTML = response [ 'last_insert' ] + " | " + url;
|
||||
document.getElementById ( "urllist" ).appendChild ( div );
|
||||
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
|
||||
myself only, this code may not be modified within the website,
|
||||
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
|
||||
No permissions to do anything against this license is given
|
||||
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;
|
||||
|
||||
public function __construct ( $config ) {
|
||||
if ( $config ) {
|
||||
if ( $config && $config [ 'host' ] && $config [ 'username' ] && $config [ 'password' ] && $config [ 'name' ] && $config [ 'port' ] ) {
|
||||
$this->config = $config;
|
||||
}
|
||||
else {
|
||||
|
@ -1,4 +1,12 @@
|
||||
<?php
|
||||
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||
$database->connect ( );
|
||||
if ( isset ( $_POST [ 'forgot_email' ] ) ) {
|
||||
//...
|
||||
}
|
||||
elseif ( isset ( $_POST [ 'forgot_username' ] ) ) {
|
||||
//...
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
if ( isset ( $request [ 1 ] ) ) {
|
||||
$link_id = $request [ 1 ];
|
||||
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) ) {
|
||||
$link_id = $GLOBALS [ 'request_uri' ] [ 1 ];
|
||||
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" );
|
||||
}
|
||||
$link_id = (int) $link_id;
|
||||
$database = new Database ( $config [ 'db' ] );
|
||||
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||
$database->connect ( );
|
||||
$database->prepare ( "SELECT links.URL FROM links WHERE links.ID = ?" );
|
||||
$parameters = [
|
||||
@ -18,7 +18,7 @@
|
||||
$row = $result->fetch_assoc ( );
|
||||
if ( ! $row ) {
|
||||
http_response_code ( 404 );
|
||||
include ( $config [ 'installation_path' ] . '/lib/errors/404.html' );
|
||||
include ( $GLOBALS [ 'config' ] [ 'installation_path' ] . '/lib/errors/404.html' );
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
@ -55,4 +55,3 @@
|
||||
else {
|
||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) );
|
||||
}
|
||||
?>
|
@ -2,10 +2,10 @@
|
||||
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 = new Database ( $config [ 'db' ] );
|
||||
$database->connect ( );
|
||||
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
|
||||
$parameters = [
|
||||
[ "s" ],
|
||||
@ -13,7 +13,7 @@
|
||||
];
|
||||
$database->bind ( $parameters );
|
||||
$database->execute ( );
|
||||
$database->prepare ( "SELECT COUNT( links.ID ) as `count` FROM links;");
|
||||
$database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
|
||||
$database->execute ( );
|
||||
$result = $database->get_result ( );
|
||||
$row = $result->fetch_assoc ( );
|
||||
@ -21,13 +21,12 @@
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'message' => 'URL inserted correctly.',
|
||||
'new_id' => $row [ 'count' ],
|
||||
'last_insert' => $row [ 'last' ],
|
||||
];
|
||||
echo ( json_encode ( $response ) );
|
||||
exit;
|
||||
}
|
||||
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->execute ( );
|
||||
$result = $database->get_result ( );
|
||||
@ -62,4 +61,3 @@
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
?>
|
@ -23,6 +23,7 @@
|
||||
$row = $result->fetch_assoc ( );
|
||||
if ( ! $row ) {
|
||||
header ( 'Content-Type: application/json' );
|
||||
http_response_code ( 401 );
|
||||
$response = [
|
||||
'status' => 401,
|
||||
'error_message' => 'Username or password not correct.',
|
||||
@ -81,4 +82,3 @@
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
?>
|
@ -1,5 +1,3 @@
|
||||
<?php
|
||||
$_SESSION = array ( );
|
||||
session_destroy ( );
|
||||
$_SESSION [ 'user_id' ] = NULL;
|
||||
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/" );
|
||||
?>
|
Reference in New Issue
Block a user