diff --git a/.htaccess b/.htaccess index 57648c9..36c1a8b 100644 --- a/.htaccess +++ b/.htaccess @@ -10,7 +10,7 @@ ErrorDocument 403 /403 ErrorDocument 500 /500 # File security - + Order allow,deny Deny from all \ No newline at end of file diff --git a/.version b/.version index 4c2ef5f..6511134 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -{ "BRANCH": "main", "VERSION":"1.1.9" } \ No newline at end of file +{ "BRANCH": "main", "VERSION":"1.1.10" } diff --git a/LICENSE b/LICENSE index 9006be8..74546cf 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Axtonprice, QuickBlaze +Copyright (c) 2022 axtonprice, QuickBlaze Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Modules/Functions.php b/Modules/functions.php similarity index 58% rename from Modules/Functions.php rename to Modules/functions.php index 2fbb071..737b40f 100644 --- a/Modules/Functions.php +++ b/Modules/functions.php @@ -1,4 +1,7 @@ "$TEMP_STORAGE_METHOD", "LANGUAGE" => "$TEMP_LANGUAGE", "INSTALLATION_PATH" => "$path"))); // Set contents of new config file - } - if (strtolower($configuration["LANGUAGE"]) == "") { - require "./Public/Error/ServerConfiguration.php"; // throw error page if no language is provided - die(); - } - if (strtolower($configuration["STORAGE_METHOD"]) == "mysql") { - if (!file_exists("./Modules/Database.env")) { - touch("./Modules/Database.env"); // Create file - require "./Public/Error/DatabaseConfig.php"; - die(); + if ($configuration["DEBUG_MODE"] == "") { + $TEMP_DEBUGMODE = "false"; // Reset configuration to default value } else { - $json = json_decode(file_get_contents("./Modules/Database.env", true), true); - if ($json["DATABASE"] == "" || $json["HOSTNAME"] == "") { - require "./Public/Error/DatabaseConfig.php"; + $TEMP_DEBUGMODE = $configuration["DEBUG_MODE"]; + } + + /* Config File If Empty Validation*/ + if ($configuration["STORAGE_METHOD"] == "") { + file_put_contents("./.config", json_encode(array("STORAGE_METHOD" => "$TEMP_STORAGE_METHOD", "LANGUAGE" => "$TEMP_LANGUAGE", "INSTALLATION_PATH" => "$TEMP_PATH", "DEBUG_MODE" => "$TEMP_DEBUGMODE"))); // Set contents of new config file + } + if ($configuration["INSTALLATION_PATH"] == "") { + file_put_contents("./.config", json_encode(array("STORAGE_METHOD" => "$TEMP_STORAGE_METHOD", "LANGUAGE" => "$TEMP_LANGUAGE", "INSTALLATION_PATH" => "$TEMP_PATH", "DEBUG_MODE" => "$TEMP_DEBUGMODE"))); // Set contents of new config file + } + if ($configuration["LANGUAGE"] == "") { + file_put_contents("./.config", json_encode(array("STORAGE_METHOD" => "$TEMP_STORAGE_METHOD", "LANGUAGE" => "$TEMP_LANGUAGE", "INSTALLATION_PATH" => "$TEMP_PATH", "DEBUG_MODE" => "$TEMP_DEBUGMODE"))); // Set contents of new config file + } + if ($configuration["DEBUG_MODE"] == "") { + file_put_contents("./.config", json_encode(array("STORAGE_METHOD" => "$TEMP_STORAGE_METHOD", "LANGUAGE" => "$TEMP_LANGUAGE", "INSTALLATION_PATH" => "$TEMP_PATH", "DEBUG_MODE" => "$TEMP_DEBUGMODE"))); // Set contents of new config file + } + } + function setupStorageMethod() + { + $cache = json_decode(file_get_contents("./local-storage/.cache", true), true); + $configuration = json_decode(file_get_contents("./.config", true), true); + + if (strtolower($configuration["STORAGE_METHOD"]) == "mysql") { + if (!file_exists("./Modules/Database.env")) { + touch("./Modules/Database.env"); // Create database configuration file + require "./Public/error_docs/DatabaseConfig.php"; die(); - } else { // Test database connection - $conn = new mysqli($json["HOSTNAME"], $json["USERNAME"], $json["PASSWORD"], $json["DATABASE"]); - if ($conn->connect_error) { - require "./Public/Error/DatabaseCredentials.php"; // throw error page if invalid credentials + } else { + $json = json_decode(file_get_contents("./Modules/Database.env", true), true); + if ($json["DATABASE"] == "" || $json["HOSTNAME"] == "") { + require "./Public/error_docs/DatabaseConfig.php"; die(); - } else { - if (!is_dir("./local-storage/")) mkdir("./local-storage/"); - if (!file_exists("./local-storage/.cache")) file_put_contents("./local-storage/.cache", '{"DO-NOT-TOUCH:database_installation_status": "false"}');; - $cache = json_decode(file_get_contents("./local-storage/.cache"), true); - if ($cache["DO-NOT-TOUCH:database_installation_status"] == "false") { - $tableCreateSQL = "CREATE TABLE IF NOT EXISTS `quickblaze_records` (`record_id` int(11) NOT NULL, `encrypted_contents` longtext NOT NULL, `encryption_token` varchar(128) NOT NULL, `source_ip` varchar(100) NOT NULL, `record_date` timestamp(5) NOT NULL DEFAULT current_timestamp(5)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - $addPrimaryKeySQL = "ALTER TABLE `quickblaze_records` ADD PRIMARY KEY (`record_id`);"; - if ($conn->query($tableCreateSQL)) { - if ($conn->query($addPrimaryKeySQL)) { - file_put_contents("./local-storage/.cache", '{"DO-NOT-TOUCH:database_installation_status": "true"}'); + } else { // Test database connection + $conn = new mysqli($json["HOSTNAME"], $json["USERNAME"], $json["PASSWORD"], $json["DATABASE"]); + if ($conn->connect_error) { + require "./Public/error_docs/DatabaseCredentials.php"; // throw error page if invalid credentials + die(); + } else { + $cache = json_decode(file_get_contents("./local-storage/.cache"), true); + if ($cache["DO-NOT-TOUCH:database_installation_status"] == "false") { + $tableCreateSQL = "CREATE TABLE IF NOT EXISTS `quickblaze_records` (`record_id` int(11) NOT NULL, `encrypted_contents` longtext NOT NULL, `encryption_token` varchar(128) NOT NULL, `source_ip` varchar(100) NOT NULL, `record_date` timestamp(5) NOT NULL DEFAULT current_timestamp(5)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + $addPrimaryKeySQL = "ALTER TABLE `quickblaze_records` ADD PRIMARY KEY (`record_id`);"; + if ($conn->query($tableCreateSQL)) { + if ($conn->query($addPrimaryKeySQL)) { + file_put_contents("./local-storage/.cache", '{"DO-NOT-TOUCH:database_installation_status": "true"}'); + } + } else { + require "./Public/error_docs/DatabaseCredentials.php"; // throw error page if invalid credentials + die(); } - } else { - require "./Public/Error/DatabaseCredentials.php"; // throw error page if invalid credentials + } + // Always reset auto-increment + if (!$conn->query("ALTER TABLE `quickblaze_records` MODIFY `record_id` int(11) NOT NULL AUTO_INCREMENT;")) { + require "./Public/error_docs/DatabaseConfig.php"; // throw error page if invalid credentials die(); } } - // Always reset auto-increment - if (!$conn->query("ALTER TABLE `quickblaze_records` MODIFY `record_id` int(11) NOT NULL AUTO_INCREMENT;")) { - require "./Public/Error/DatabaseConfig.php"; // throw error page if invalid credentials - die(); - } + $conn->close(); } - $conn->close(); } + } else if (strtolower($configuration["STORAGE_METHOD"]) == "filetree") { + $baseStorageFolder = "./local-storage"; + if (!is_dir("$baseStorageFolder/")) mkdir("$baseStorageFolder/"); + if (!is_dir("$baseStorageFolder/encryptions/")) mkdir("$baseStorageFolder/encryptions/"); + } else { // Server storage method not set + require "./Public/error_docs/ServerConfiguration.php"; // throw error page if invalid configuration + die(); } - } elseif (strtolower($configuration["STORAGE_METHOD"]) == "filetree") { - $baseStorageFolder = "./local-storage"; - if (!is_dir("$baseStorageFolder/")) mkdir("$baseStorageFolder/"); - if (!is_dir("$baseStorageFolder/encryptions/")) mkdir("$baseStorageFolder/encryptions/"); - } else { // Server storage method not set - require "./Public/Error/ServerConfiguration.php"; // throw error page if invalid configuration - die(); } - error_reporting(E_ALL); // enable error reporting + + /* Call Functions */ + createStorageMethodEndpoints(); // Setup files and folders the system will store data. + checkConfigValues(); // Validate if configuration values are correct & present. + setupStorageMethod(); // Setup how the system will store the data via the configured method. + /* End Functions */ } + +/* Database Interaction Functions */ function insertRecord($encrypted_contents, $encryption_token) { - error_reporting(0); $configuration = json_decode(file_get_contents("./.config", true), true); $json = json_decode(file_get_contents("./Modules/Database.env", true), true); if ($_SERVER['HTTP_CF_CONNECTING_IP'] == "" || !isset($_SERVER['HTTP_CF_CONNECTING_IP'])) $_SERVER['HTTP_CF_CONNECTING_IP'] = $_SERVER["REMOTE_ADDR"]; if (strtolower($configuration["STORAGE_METHOD"]) == "mysql") { $mysqli = new mysqli($json["HOSTNAME"], $json["USERNAME"], $json["PASSWORD"], $json["DATABASE"]); if ($mysqli->connect_errno) { - require "./Public/Error/DatabaseCredentials.php"; + require "./Public/error_docs/DatabaseCredentials.php"; die(); } $source_ip = filter_var($_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP) ?? filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); @@ -177,7 +210,8 @@ function insertRecord($encrypted_contents, $encryption_token) $source_ip = filter_var($_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP) ?? filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); $record_date = date("Y-m-d H:i:s"); file_put_contents("$baseStorageFolder/encryptions/$uniqueIdentifier/data.json", '{"filestore_id": "' . $uniqueIdentifier . '", "encrypted_contents": "' . $encrypted_contents . '", "encryption_token": "' . $encryption_token . '", "source_ip": "' . $source_ip . '", "record_date": "' . $record_date . '"}'); // Set data file encryption data - require "./Public/Error/ServerConfiguration.php"; // throw error page if invalid configuration + } else { + require "./Public/error_docs/ServerConfiguration.php"; // throw error page if invalid configuration die(); } } @@ -188,7 +222,7 @@ function destroyRecord($token) if (strtolower($configuration["STORAGE_METHOD"]) == "mysql") { $mysqli = new mysqli($json["HOSTNAME"], $json["USERNAME"], $json["PASSWORD"], $json["DATABASE"]); if ($mysqli->connect_errno) { - require "./Public/Error/DatabaseCredentials.php"; + require "./Public/error_docs/DatabaseCredentials.php"; die(); } $token = filter_var($token, FILTER_SANITIZE_FULL_SPECIAL_CHARS); @@ -219,7 +253,7 @@ function rmdir_recursive($dir) } } } else { // Server storage method not set - require "./Public/Error/ServerConfiguration.php"; // throw error page if invalid configuration + require "./Public/error_docs/ServerConfiguration.php"; // throw error page if invalid configuration die(); } } @@ -230,7 +264,7 @@ function getRecord($dataToFetch, $encryption_token) if (strtolower($configuration["STORAGE_METHOD"]) == "mysql") { $mysqli = new mysqli($json["HOSTNAME"], $json["USERNAME"], $json["PASSWORD"], $json["DATABASE"]); if ($mysqli->connect_errno) { - require "./Public/Error/DatabaseCredentials.php"; + require "./Public/error_docs/DatabaseCredentials.php"; die(); } $encryption_token = filter_var($encryption_token, FILTER_SANITIZE_FULL_SPECIAL_CHARS); @@ -255,7 +289,7 @@ function getRecord($dataToFetch, $encryption_token) } } } else { // Server storage method not set - require "./Public/Error/ServerConfiguration.php"; // throw error page if invalid configuration + require "./Public/error_docs/ServerConfiguration.php"; // throw error page if invalid configuration die(); } } @@ -267,12 +301,10 @@ function translate($q) $configuration = json_decode(file_get_contents("./.config", true), true); if ($configuration["LANGUAGE"] == "auto") { $tl = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); + } else if ($configuration["LANGUAGE"] != "") { + $tl = $configuration["LANGUAGE"]; } else { - if ($configuration["LANGUAGE"] != "") { - $tl = $configuration["LANGUAGE"]; - } else { - $tl = "en"; - } + $tl = "en"; } $res = file_get_contents("https://translate.googleapis.com/translate_a/single?client=gtx&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&sl=" . $lang . "&tl=" . $tl . "&hl=hl&q=" . urlencode($q), $_SERVER['DOCUMENT_ROOT'] . "/transes.html"); $res = json_decode($res); diff --git a/Public/assets/css/style.css b/Public/assets/css/style.css index 7c21e79..561b3c6 100644 --- a/Public/assets/css/style.css +++ b/Public/assets/css/style.css @@ -123,13 +123,4 @@ textarea { bottom: 0; opacity: 0; } -} - -#subheading_moto { - opacity: 0; - transition: opacity 1000ms; -} - -#subheading_moto.show { - opacity: 1; } \ No newline at end of file diff --git a/Public/assets/js/buttonCopyURL.js b/Public/assets/js/buttonCopyURL.js index 7d4169b..3f3892f 100644 --- a/Public/assets/js/buttonCopyURL.js +++ b/Public/assets/js/buttonCopyURL.js @@ -1,19 +1,16 @@ function copyToClipboard(element) { - var $temp = $(""); - $("body").append($temp); + let $temp = $(''); + $('body').append($temp); $temp.val($(element).text()).select(); - document.execCommand("copy"); + document.execCommand('copy'); + showSnackBar('snackbar'); // show snackbar notification log(`Copied text to clipboard`); $temp.remove(); - showSnackBar('snackbar'); // show snackbar notification } function showSnackBar(snackbarId) { - var x = document.getElementById(snackbarId); - x.className = "show"; - var time = 3000; - log(`Displaying snackbar for ${time}ms`); - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, time); + var element = document.getElementById(`${snackbarId}`); + element.className = element.className.replace('', 'show'); + log(`Displaying snackbar for ${3000}ms`); + setTimeout(function () { element.className = element.className.replace("show", ""); }, 3000); } \ No newline at end of file diff --git a/Public/assets/js/formContentUpdate.js b/Public/assets/js/formContentUpdate.js index 0cb7fc2..6ae3357 100644 --- a/Public/assets/js/formContentUpdate.js +++ b/Public/assets/js/formContentUpdate.js @@ -1,34 +1,53 @@ function updateFormDisplay() { - const formvalue = document.getElementById("inputtextbot").value; // Assign variable to the current value of the textbox - $('#form_input').fadeOut('fast'); log(`No longer showing 'form_input' element`); // fade out previous content - fetch(`dataProcessing?data=${formvalue}`).then(response => response.json()).then(data => { + const formvalue = document.getElementById('inputtextbot').value; // Assign variable to the current value of the textbox + $('#form_input').fadeOut('fast'); // fade out previous content + log(`No longer showing 'form_input' element`); + function fetchData() { + return fetch(`dataProcessing?action=submit&data=${formvalue}`) + .then((response) => response.json()) + .then((responseData) => { + return responseData; + }).catch(error => log(error, 'warn')); + } + fetchData().then(data => { log(`Server responsed with '${data.response}'`); - document.getElementById("submissiontextbox").value = `${window.location}view?key=${data.response}`; log(`Updated 'submissiontextbox.value'`); // Set text box to view message URL - document.getElementById("submissiontextbox").innerHTML = `${window.location}view?key=${data.response}`; log(`Updated 'submissiontextbox.innerHTML'`); // Set text box to view message URL + document.getElementById('submissiontextbox').value = `${window.location}view?key=${data.response}`; // Set text box to view message URL + log(`Updated 'submissiontextbox.value'`); + document.getElementById('submissiontextbox').innerHTML = `${window.location}view?key=${data.response}`; // Set text box to view message URL + log(`Updated 'submissiontextbox.innerHTML'`); }); - setTimeout(function () { - $('#form_submission').fadeIn('fast'); log(`Now showing 'form_submission' element`); // fade in new content + setTimeout(() => { + $('#form_submission').fadeIn('fast'); // fade in new content + log(`Now showing 'form_submission' element`); }, 200); } function updateViewDisplay() { - $('#form_confirmation').fadeOut('fast'); log(`No longer showing 'form_confirmation' element`); // fade out previous content - var key = new URL(window.location).searchParams.get("key"); log(`Got key variable from url -> ${key}`); // Get key variable from URL; replacing PHP usage + $('#form_confirmation').fadeOut('fast'); // fade out previous content + log(`No longer showing 'form_confirmation' element`); + + let key = new URL(window.location).searchParams.get('key'); // Get key variable from URL; replacing PHP usage + log(`Got key variable from url -> ${key}`); + fetch(`dataProcessing?action=decrypt&key=${key}`).then(response => response.json()).then(data => { - if (data.response == "") { + if (!data.response) { showSnackBar('snackbarError'); - $('#form_error').fadeIn('fast'); log(`Now showing 'form_error' element`); // fade in new content - log(`Encryption not found; redirecting in 2s`) - setTimeout(function () { - window.location.replace("./"); // Redirect to home page + $('#form_error').fadeIn('fast'); // fade in new content + log(`Now showing 'form_error' element`); + log(`Encryption not found; redirecting in 2s`); + setTimeout(() => { + window.location.replace('./'); // Redirect to home page }, 2000); } else { - log(`Server responded with '${data.response}'`); - document.getElementById("valuetextbox").value = data.response; log(`Updated 'valuetextbox.value'`); // Set text box to decrypted message - document.getElementById("valuetextbox").innerHTML = data.response; log(`Updated 'valuetextbox.innerHTML'`); // Set text box to decrypted message - setTimeout(function () { - $('#form_content').fadeIn('fast'); log(`Now showing 'form_content' element`); // fade in new content + document.getElementById('valuetextbox').value = data.response; // Set text box to decrypted message + log(`Updated 'valuetextbox.value'`); + document.getElementById('valuetextbox').innerHTML = data.response; // Set text box to decrypted message + log(`Updated 'valuetextbox.innerHTML'`); + setTimeout(() => { + $('#form_content').fadeIn('fast'); // fade in new content + log(`Now showing 'form_content' element`); }, 200); - } + log(`Server responded with '${data.response}'`); + }; }); } \ No newline at end of file diff --git a/Public/assets/js/globalFunctions.js b/Public/assets/js/globalFunctions.js index b3655d1..169252d 100644 --- a/Public/assets/js/globalFunctions.js +++ b/Public/assets/js/globalFunctions.js @@ -5689,6 +5689,13 @@ // document.addEventListener('DOMContentLoaded', function () { + fetch(`dataProcessing?action=isDebugMode`).then(response => response.json()).then(data => { + if (data.response == "false") { + console.log( + `[${moment().format('hh:mm:ss')}] [Initialisation/DEBUG] Debug mode is disabled!` + ); + } + }); log(`${moment()}`, `Initialisation/DEBUG`); log(`Successfully loaded all assets`, `Initialisation/DEBUG`); }, false); @@ -5707,13 +5714,23 @@ document.addEventListener('DOMContentLoaded', function () { }) function log(content, type = null) { - if (!type) { - console.log( - `[${moment().format('hh:mm:ss')}] [Site Debug/INFO] ${content}` - ); - } else { - console.log( - `[${moment().format('hh:mm:ss')}] [${type}] ${content}` - ); - } + fetch(`dataProcessing?action=isDebugMode`).then(response => response.json()).then(data => { + if (data.response == "true") { + if (!type) { + console.log( + `[${moment().format('hh:mm:ss')}] [Site Debug/INFO] ${content}` + ); + } else { + if(type == "warn"){ + console.warn( + `[${moment().format('hh:mm:ss')}] ${content}` + ); + } else{ + console.log( + `[${moment().format('hh:mm:ss')}] [${type}] ${content}` + ); + } + } + } + }); } \ No newline at end of file diff --git a/Public/dataProcessing.php b/Public/dataProcessing.php index 192cf78..b65356f 100644 --- a/Public/dataProcessing.php +++ b/Public/dataProcessing.php @@ -1,6 +1,7 @@
+
+ +
+


diff --git a/Public/Error/DatabaseCredentials.php b/Public/error_docs/DatabaseCredentials.php similarity index 88% rename from Public/Error/DatabaseCredentials.php rename to Public/error_docs/DatabaseCredentials.php index dec25e0..8e86782 100644 --- a/Public/Error/DatabaseCredentials.php +++ b/Public/error_docs/DatabaseCredentials.php @@ -4,7 +4,7 @@ - + "> QuickBlaze @@ -17,6 +17,10 @@
+
+ +
+


@@ -39,4 +43,5 @@ + \ No newline at end of file diff --git a/Public/Error/ServerConfiguration.php b/Public/error_docs/ServerConfiguration.php similarity index 100% rename from Public/Error/ServerConfiguration.php rename to Public/error_docs/ServerConfiguration.php diff --git a/index.php b/index.php index c596ecd..e6749b9 100644 --- a/index.php +++ b/index.php @@ -7,39 +7,37 @@ /* Initialise Displays */ if ($url == "dataProcessing") { /* Form Submission Handler */ - require("./Modules/Functions.php"); - //setupStorageMethod(); // Check database + require("./Modules/functions.php"); require("./Public/dataProcessing.php"); return; } if ($url == "view") { /* View Message Page */ - require("./Modules/Functions.php"); - //setupStorageMethod(); // Check database + require("./Modules/functions.php"); require("./Public/view.php"); return; } if ($url == "") { /* Primary Display Page */ - require("./Modules/Functions.php"); - setupStorageMethod(); // Check database + require("./Modules/functions.php"); + initialiseSystem(); // Call system functions to initialise require("./Public/index.php"); } elseif ($url == "404") { /* Not Found Page */ - require("./Modules/Functions.php"); - return require("./Public/Error/404.php"); + require("./Modules/functions.php"); + return require("./Public/error_docs/404.php"); } elseif ($url == "403") { /* Not Found Page */ - require("./Modules/Functions.php"); - return require("./Public/Error/403.php"); + require("./Modules/functions.php"); + return require("./Public/error_docs/403.php"); } else { if ($url == "500") { /* Server Error Page */ - require("./Modules/Functions.php"); - return require("./Public/Error/500.php"); + require("./Modules/functions.php"); + return require("./Public/error_docs/500.php"); } else { /* Not Found Page */ - require("./Modules/Functions.php"); - return require("./Public/Error/404.php"); + require("./Modules/functions.php"); + return require("./Public/error_docs/404.php"); } }