From 05533395eb8c72d82ccb59c571239e378e75427d Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Tue, 1 Nov 2022 17:34:24 +0000 Subject: [PATCH] Fixing problems caused with conf.json Adding to upcoming autofix feature --- app/account/account.php | 4 +- app/app.php | 84 ++++++++++++++++++++++++++++------------- app/settings.php | 13 ++----- index.php | 4 +- 4 files changed, 66 insertions(+), 39 deletions(-) diff --git a/app/account/account.php b/app/account/account.php index 5f858e3..1fda8f7 100644 --- a/app/account/account.php +++ b/app/account/account.php @@ -47,7 +47,9 @@ if (isset($_POST['submit_login'])) { query($sql) === TRUE) { echo "Table users created successfully"; } - $sql = "CREATE TABLE IF NOT EXISTS images ()"; + $sql = "CREATE TABLE IF NOT EXISTS images ( + id INT(11) AUTO_INCREMENT PRIMARY KEY, + imagename VARCHAR(255) NOT NULL, + alt VARCHAR(text) NOT NULL, + tags VARCHAR(text) NOT NULL, + author INT(11) NOT NULL, + last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"; if ($conn->query($sql) === TRUE) { echo "Table images created successfully"; } - $sql = "CREATE TABLE IF NOT EXISTS groups ()"; + $sql = "CREATE TABLE IF NOT EXISTS groups ( + id INT(11) AUTO_INCREMENT PRIMARY KEY, + group_name VARCHAR(255) NOT NULL, + image_list VARCHAR(text) NOT NULL, + last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"; if ($conn->query($sql) === TRUE) { echo "Table groups created successfully"; } - $sql = "CREATE TABLE IF NOT EXISTS logs ()"; + $sql = "CREATE TABLE IF NOT EXISTS logs ( + id INT(11) AUTO_INCREMENT PRIMARY KEY, + ipaddress VARCHAR(16) NOT NULL, + action VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"; if ($conn->query($sql) === TRUE) { echo "Table logs created successfully"; } + + $sql = "CREATE TABLE IF NOT EXISTS bans ( + id INT(11) AUTO_INCREMENT PRIMARY KEY, + ipaddress VARCHAR(16) NOT NULL, + reason VARCHAR(255) NOT NULL, + time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + length VARCHAR(255) NOT NULL, + permanent BOOLEAN NOT NULL DEFAULT FALSE + )"; + if ($conn->query($sql) === TRUE) { + echo "Table bans created successfully"; + } + + $sql = "CREATE TABLE IF NOT EXISTS tokens ( + id INT(11) AUTO_INCREMENT PRIMARY KEY, + code VARCHAR(59) NOT NULL, + used BOOLEAN NOT NULL DEFAULT FALSE, + timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + )"; + if ($conn->query($sql) === TRUE) { + echo "Table tokens created successfully"; + } */ + return True; } @@ -379,20 +421,8 @@ class Setup { } if (!is_file(__DIR__."/../usr/conf/conf.json")) { - $manifest = array( - "website_name" => "Only Legs", - "website_description" => "A simple PHP gallery with multiple users in mind", - "welcome_message" => array("*internal screaming*", "Welcome to Only Legs!"), - "user_name" => "[your name]", - "is_test" => true, - "upload" => array( - "max_filesize" => 35, - "rename_on_upload" => true, - "rename_to" => "IMG_{{username}}_{{time}}", - "allowed_extensions" => array("jpg", "jpeg", "png", "webp") - ) - ); - file_put_contents(__DIR__."/../usr/conf/conf.json", json_encode($manifest)); + $manifest = file_get_contents(__DIR__."/../usr/conf.default.json"); + file_put_contents(__DIR__."/../usr/conf/conf.json", $manifest); } } } diff --git a/app/settings.php b/app/settings.php index 364fa04..83cbd62 100644 --- a/app/settings.php +++ b/app/settings.php @@ -8,22 +8,15 @@ | the default background and accent colour |------------------------------------------------------------- */ -$user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf/conf.json"), true); - if (is_file(__DIR__."/../usr/conf/conf.json")) { - $settings = json_decode(file_get_contents(__DIR__."/../usr/conf/conf.json"), true); + $user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf/conf.json"), true); } else { - $settings = json_decode(file_get_contents(__DIR__."/../usr/conf.default.json"), true); + $user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf.default.json"), true); } if (is_file(__DIR__."/../usr/conf/msg.json")) { $user_welcome = json_decode(file_get_contents(__DIR__."/../usr/conf/msg.json"), true); $user_welcome = $user_welcome['welcome']; -} else { - $user_welcome = array('Welcome to your new Only Legs installation! You can change this message in the settings page.'); } - -$web_info = json_decode(file_get_contents(__DIR__."/app.json"), true); - -$upload_conf = $user_settings["upload"]; \ No newline at end of file +$web_info = json_decode(file_get_contents(__DIR__."/app.json"), true); \ No newline at end of file diff --git a/index.php b/index.php index 935d5c6..3f3f0aa 100644 --- a/index.php +++ b/index.php @@ -96,7 +96,9 @@ } // Random welcome message - echo "

".$user_welcome[array_rand($user_welcome, 1)]."

"; + if (isset($user_welcome)) { + echo "

".$user_welcome[array_rand($user_welcome, 1)]."

"; + } ?>