From 81d21c311f48d132201853d75ee21424c3744dfe Mon Sep 17 00:00:00 2001 From: Bryan Date: Sat, 6 Apr 2019 11:57:35 +0200 Subject: [PATCH] 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 --- LICENSE | 4 ++-- functions.php | 5 ++--- index.php | 5 ++--- lib/js/insertnew.js | 2 +- lib/{ => php}/LICENSE | 4 ++-- lib/php/classes/Database.php | 4 ++-- lib/php/forgot.php | 8 ++++++++ lib/php/go.php | 9 ++++----- lib/php/insert.php | 12 +++++------- lib/php/login.php | 2 +- lib/php/logout.php | 4 +--- 11 files changed, 30 insertions(+), 29 deletions(-) rename lib/{ => php}/LICENSE (83%) diff --git a/LICENSE b/LICENSE index 66321ef..810991d 100644 --- a/LICENSE +++ b/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 diff --git a/functions.php b/functions.php index 460626a..c23b72a 100644 --- a/functions.php +++ b/functions.php @@ -1,7 +1,7 @@ diff --git a/index.php b/index.php index c66acf9..f60ec1e 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,8 @@ diff --git a/lib/js/insertnew.js b/lib/js/insertnew.js index efae69d..722e786 100644 --- a/lib/js/insertnew.js +++ b/lib/js/insertnew.js @@ -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 = ""; } diff --git a/lib/LICENSE b/lib/php/LICENSE similarity index 83% rename from lib/LICENSE rename to lib/php/LICENSE index 2cd9da9..200424c 100644 --- a/lib/LICENSE +++ b/lib/php/LICENSE @@ -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. \ No newline at end of file +don't email me asking any permission without providing a valid reason. \ No newline at end of file diff --git a/lib/php/classes/Database.php b/lib/php/classes/Database.php index 92b841c..304ba4c 100644 --- a/lib/php/classes/Database.php +++ b/lib/php/classes/Database.php @@ -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 { @@ -41,4 +41,4 @@ public function get_result ( ) : MySQLi_result { return $this->statement->get_result ( ); } - } \ No newline at end of file + } diff --git a/lib/php/forgot.php b/lib/php/forgot.php index 9d330db..2938cc6 100644 --- a/lib/php/forgot.php +++ b/lib/php/forgot.php @@ -1,4 +1,12 @@ connect ( ); + if ( isset ( $_POST [ 'forgot_email' ] ) ) { + //... + } + elseif ( isset ( $_POST [ 'forgot_username' ] ) ) { + //... + } ?> diff --git a/lib/php/go.php b/lib/php/go.php index bbcbf76..9e0c061 100644 --- a/lib/php/go.php +++ b/lib/php/go.php @@ -1,11 +1,11 @@ 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 ) ); } -?> \ No newline at end of file diff --git a/lib/php/insert.php b/lib/php/insert.php index 41a9b64..64d45eb 100644 --- a/lib/php/insert.php +++ b/lib/php/insert.php @@ -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 @@ \ No newline at end of file diff --git a/lib/php/login.php b/lib/php/login.php index 7e359c7..f268560 100644 --- a/lib/php/login.php +++ b/lib/php/login.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 @@ \ No newline at end of file diff --git a/lib/php/logout.php b/lib/php/logout.php index deb0983..badf89d 100644 --- a/lib/php/logout.php +++ b/lib/php/logout.php @@ -1,5 +1,3 @@ \ No newline at end of file