v0.5, big changes to configuration and settings

This commit is contained in:
Taylor Courage 2023-12-17 05:31:12 -05:00
parent 9b83516293
commit 914df023c3
10 changed files with 347 additions and 41 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
credentials.php
uploads/ uploads/
config/db_config.php config/db_config.php

View File

@ -26,13 +26,18 @@ First you will want to either clone this repo, or download the zip (and unzip it
Next you need to edit `config/db_config.php` and add your SQL credentials. Next you need to edit `config/db_config.php` and add your SQL credentials.
If you plan on using a custom domain, you can also edit `config/configuation.php` to include that. Then you need to navigate to `http://imghost.local/config/` (or your custom domain) to finish setup. Simply change the available options based on your preferences and click `Setup server`, once complete you will be redirected to the home page where your server should be ready to use. The same web page can be used later to change settings.
Then you will need to navigate to `http://imghost.local/config/` or your custom domain to finish database and folder setup. Simply change the available options based on your preferences and click `Setup databases`, once complete you will be redirected to the home page where your server should be ready to use!
## Changelog ## Changelog
### v0.5.0-alpha - Dec 17, 2023
- Big changes to configuration system - values are stored to MySQL and read from there as well
- Overhauled system settings page - settings are now configurable while the server is running
- Slightly altered the default background to be more aesthetically pleasing
- Decided to change to 'alpha' status to more accurately reflect the state of this program - while I strive to make it work as best as possible, it is easy to overlook things that seem like basic features. For example there is a settings page with no password protection.
### v0.4.0-beta - Dec 16, 2023 ### v0.4.0-beta - Dec 16, 2023
- Full re-factor to convert the old "Meme Machine" to a general-purpose, plug-and-play image hosting software. - Full re-factor to convert the old "Meme Machine" to a general-purpose, plug-and-play image hosting software.

View File

@ -40,14 +40,17 @@ if (mysqli_num_rows($result) > 0) {
} }
} }
} else { } else {
echo "Shit, something broke. Try again! Or if the problem persists contact the system administrator"; echo "Shit, something broke. Try again! Maybe there's nothing here? Or if the problem persists after uploading, contact the system administrator or make a new issue on GitHub";
?> ?>
<p>&nbsp;</p> <p>&nbsp;</p>
<a href="./">Home</a> <a href="../">Home</a>
<?php <?php
} }
echo '<br>';
echo '<br>';
echo '<br>';
echo '<h6>' . $serverName . " - " . $serverVers . "</h6>";
echo '</body>'; echo '</body>';
echo '</html>'; echo '</html>';
?> ?>

View File

@ -1,26 +1,95 @@
<?php <?php
include "./db_config.php";
mysqli_report(MYSQLI_REPORT_OFF);
/************ CONFIGURATION FILE ***********/ /************ CONFIGURATION FILE ***********/
/** This file is used for general server **/ /** This file is used for general server **/
/** configuration. These values may be **/ /** configuration. It is not recommended **/
/** changed as necessary to suit your **/ /** to change things here unless you **/
/** requirements. **/ /** know what you are doing; use the **/
/** /config webpage to edit server **/
/** settings. **/
// The name that will appear on the pages of the server //Connect to MySQL to grab data
$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword);
if (!$conn) {
die ("CONNECTION FAIL " . mysqli_connect_error());
}
$checkQuery = "SHOW DATABASES LIKE '$dbname'";
$checkDB = mysqli_query($conn, $checkQuery);
$check = mysqli_fetch_assoc($checkDB);
// The name and version that will appear on the pages of the server
$serverName = "ImgHost"; $serverName = "ImgHost";
$serverVers = "0.5.0-alpha";
// Hostname of the server
$serverHostname = "imghost.local"; $serverHostname = "imghost.local";
// Directory where the images will be stored // Directory where the images will be stored
$targetDir = "uploads/"; $targetDir = "uploads";
// Filename of the style sheet (found in config foler) // Filename of the style sheet (found in config foler)
$stylesheet = "style.css"; $stylesheet = "style.css";
// Set private enable flag`
$enablePrivate = 0;
// Enable logging
// FUTURE FEATURE NOT YET IMPLEMENTED
$enableLogging = 1;
if (!$check) {
echo "DB not found! Using defaults!<br>Try re-initializing the server if this persists!<br>";
$dbExists = 0;
} else {
$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword, $dbname);
$getSettings = "SELECT * FROM $settingstable";
$settings = mysqli_query($conn, $getSettings);
$data = mysqli_fetch_assoc($settings);
$dbExists = 1;
if (!$settings){
echo "db connect bad, using defaults";
} else {
// The name and version that will appear on the pages of the server
$serverName = $data["serverName"];
// Hostname of the server
$serverHostname = $data["serverHostName"];
// Directory where the images will be stored
$targetDir = $data["uploadDir"] . "/";
// Filename of the style sheet (found in config foler)
$stylesheet = $data["stylesheet"];
// Set private enable flag`
$enablePrivate = $data["privateEnable"];
// Enable logging
// FUTURE FEATURE NOT YET IMPLEMENTED
$enableLogging = $data["loggingEnable"];
}
}
// Supported file types // Supported file types
$supportedFileTypes = array ( $supportedFileTypes = array (
"image/jpeg", "image/jpeg",

View File

@ -19,5 +19,7 @@ $sqlPassword = "password";
// Database Settings // Database Settings
$dbname = "imghost_data"; $dbname = "imghost_data";
$tablename = "images"; $tablename = "images";
$settingstable = "settings";
$authtable = "auth";
?> ?>

View File

@ -1,36 +1,73 @@
<?php <?php
include './configuration.php'; include './db_config.php';
include './db_config.php'; include './configuration.php';
?> ?>
<html> <html>
<head> <head>
<link rel="stylesheet" href="./<?php echo $stylesheet; ?>"> <link rel="stylesheet" href="./style.css">
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title><?php echo $serverName; ?> Config</title> <title>ImgHost Config</title>
</head> </head>
<body class="background"> <body class="background">
<div class="layout" align="center"> <div class="layout" align="center">
<h1><?php echo $serverName; ?></h1> <?php
<br /> // MySQL connection
<form action="initial_setup.php" method="post" enctype="multipart/form-data"> if ($dbExists == 0) {
$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword);
if (!$conn) {
die ("CONNECTION FAIL " .mysqli_connect_error());
}
echo '<h1>' . $serverName . ' Setup</h1>
<br /> <br />
<p><input type="submit" value="Setup databases" name="submit" /></p> <h3>Initial Configuration</h3>
</form> <form action="initial_setup.php" method="post" enctype="multipart/form-data">
</div> <br />
<div align="center"> <p>Server Name: <input type="text" name="serverName" id="serverName" value="ImgHost" /></p>
<p>Hostname: <input type="text" name="serverHostName" id="serverHostName" value="imghost.local" /></p>
<p>Uploads Directory: <input type="text" name="uploadDir" id="uploadDir" value="uploads" /></label></p>
<p>Stylesheet: <input type="text" name="stylesheet" id="stylesheet" value="style.css" /></p>
<p>Enable private uploads: <input type="checkbox" name="enablePrivate" id="enablePrivate" checked="false" /></p>
<p><input type="submit" value="Setup server" name="submit" /></p>
</form>';
} else if ($dbExists == 1) {
$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword, $dbname);
if (!$conn) {
die ("CONNECTION FAIL " .mysqli_connect_error());
}
if ($enablePrivate == 1) {
$privateChecked = "checked='true'";
} else {
$privateChecked = "";
}
echo '<h1>' . $serverName . ' Setup</h1>
<br />
<h3>Configuration</h3>
<form action="update_setup.php" method="post" enctype="multipart/form-data">
<br />
<p>Server Name: <input type="text" name="serverName" id="serverName" value="' . $serverName . '" /></p>
<p>Hostname: <input type="text" name="serverHostName" id="serverHostName" value="' . $serverHostname . '" /></p>
<p>Uploads Directory: <input type="text" name="uploadDir" id="uploadDir" value="' . $targetDir . '" /></label></p>
<p>Stylesheet: <input type="text" name="stylesheet" id="stylesheet" value="' . $stylesheet . '" /></p>
<p>Enable private uploads: <input type="checkbox" name="enablePrivate" id="enablePrivate"' . $privateChecked . ' /></p>
<p><input type="submit" value="Update configuration" name="submit" /></p>
</form>';
}
?>
<br /> <br />
<br /> <br />
<hr> <hr>
<br /> <br />
<p><a href='../'>Home</a></p>
</div>
<div align="center">
<br /> <br />
<br /> <br />
<br /> <h6><?php echo $serverName . " - " . $serverVers; ?></h6>
<h6>ImgHost (v0.4.0-beta)</h6>
</div> </div>
</html> </html>

View File

@ -1,7 +1,5 @@
<?php <?php
include './db_config.php'; include './db_config.php';
include './configuration.php';
echo "Configuration started...<br>"; echo "Configuration started...<br>";
@ -36,7 +34,7 @@ if (!$conn) {
} }
echo "Sql connection successful!<br>"; echo "Sql connection successful!<br>";
// Create the table, if doesn't exit // Create the table for storing image data, if doesn't exit
$tableSetup = "CREATE TABLE IF NOT EXISTS $tablename ( $tableSetup = "CREATE TABLE IF NOT EXISTS $tablename (
imgID CHAR(12), imgID CHAR(12),
fileType VARCHAR(4), fileType VARCHAR(4),
@ -46,15 +44,106 @@ $tableSetup = "CREATE TABLE IF NOT EXISTS $tablename (
editDate DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP editDate DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)"; )";
echo "Preparing table with command - " . $tableSetup . "<br>"; echo "Preparing images database table with command - " . $tableSetup . "<br>";
if (mysqli_query($conn, $tableSetup)) { if (mysqli_query($conn, $tableSetup)) {
echo "Table successfully prepared!<br>"; echo "Images table successfully prepared!<br>";
} else { } else {
echo "Database Error " . $sql . "<br>" . mysqli_error($conn); echo "Database Error " . $sql . "<br>" . mysqli_error($conn);
} }
echo "Preparing images folder...<br>"; // Create the table to store server settings
$settingsSetup = "CREATE TABLE IF NOT EXISTS $settingstable (
serverName VARCHAR(100),
serverHostName VARCHAR(100),
stylesheet VARCHAR(100),
uploadDir VARCHAR(100),
privateEnable BOOLEAN,
loggingEnable BOOLEAN,
genesisDate DATETIME DEFAULT CURRENT_TIMESTAMP,
editDate DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
echo "Preparing settings database table with command - " . $settingstable . "<br>";
if (mysqli_query($conn, $settingsSetup)) {
echo "Settings table successfully prepared!<br>";
} else {
echo "Database Error " . $sql . "<br>" . mysqli_error($conn);
}
echo "Writing settings to database...<br>";
// Grab details entered by user
if (isset($_POST["serverName"])) { //Server name
$serverName = $_POST["serverName"];
}
if (isset($_POST["serverHostName"])) { //Hostname
$serverHostName = $_POST["serverHostName"];
}
if (isset($_POST["stylesheet"])) { //Custom CSS
$stylesheet = $_POST["stylesheet"];
}
if (isset($_POST["uploadDir"])) { //Directory
$targetDir = $_POST["uploadDir"];
}
// Set defaults for any fields left blank
if ($serverName == ''){
$serverName = "ImgHost";
}
if ($serverHostName == ''){
$serverHostName = "imghost.local";
}
if ($stylesheet == ''){
$stylesheet = "style.css";
}
if ($targetDir == ''){
$targetDir = "uploads";
}
// Check if private flag is active
if (isset($_POST["enablePrivate"])) {
$enablePrivate = 1;
}
// TODO setup logging IP addresses
$enableLogging = 0;
$settingsApply = "INSERT INTO $settingstable (
serverName,
serverHostName,
stylesheet,
uploadDir,
privateEnable,
loggingEnable
) VALUES (
'$serverName',
'$serverHostName',
'$stylesheet',
'$targetDir',
'$enablePrivate',
'$enableLogging'
)";
echo "Preparing to write settings with command - " . $settingsApply . "<br>";
if (mysqli_query($conn, $settingsApply)) {
echo "Settings table successfully written!<br>";
} else {
echo "Database Error " . $sql . "<br>" . mysqli_error($conn);
}
// Prepare uploads directory
echo "Preparing directories...<br>";
$directory = "../" . $targetDir; $directory = "../" . $targetDir;
echo $directory. "<br>"; echo $directory. "<br>";

View File

@ -1,6 +1,6 @@
.background { .background {
background-attachment: fixed; background-attachment: fixed;
background: linear-gradient(237deg, #0000ffd2, #1eff009a, #7d00a7); background: linear-gradient(237deg, #92018ba1, #0000ffd2, #1eff008c, #ffae008c, #a70016ce);
background-size: 500% 500%; background-size: 500% 500%;
-webkit-animation: AnimationName 90s ease infinite; -webkit-animation: AnimationName 90s ease infinite;

94
config/update_setup.php Normal file
View File

@ -0,0 +1,94 @@
<?php
include './db_config.php';
include './configuration.php';
$oldServerName = $serverName;
$oldDir = $targetDir;
echo "Configuration update started...<br>";
echo "$sqlServer<br>";
echo "$sqlUsername<br>";
echo "$sqlPassword<br>";
echo "Connecting to database...<br>";
$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Sql connection successful!<br>";
// Grab details entered by user
if (isset($_POST["serverName"])) { //Server name
$serverName = $_POST["serverName"];
}
if (isset($_POST["serverHostName"])) { //Hostname
$serverHostName = $_POST["serverHostName"];
}
if (isset($_POST["stylesheet"])) { //Custom CSS
$stylesheet = $_POST["stylesheet"];
}
if (isset($_POST["uploadDir"])) { //Directory
$targetDir = rtrim($_POST["uploadDir"], '/');
}
// Set defaults for any fields left blank
if ($serverName == ''){
$serverName = "ImgHost";
}
if ($serverHostName == ''){
$serverHostName = "imghost.local";
}
if ($stylesheet == ''){
$stylesheet = "style.css";
}
if ($targetDir == ''){
$targetDir = "uploads";
}
// Check if private flag is active
if (isset($_POST["enablePrivate"])) {
$enablePrivate = 1;
} else {
$enablePrivate = 0;
}
// TODO setup logging IP addresses
$enableLogging = 0;
// SQL command that will update our settings
$settingsApply = "UPDATE $settingstable SET
serverName = '$serverName',
serverHostName = '$serverHostName',
stylesheet = '$stylesheet',
uploadDir = '$targetDir',
privateEnable = '$enablePrivate',
loggingEnable = '$enableLogging'
WHERE serverName = '$oldServerName'";
echo "Preparing to write settings with command - " . $settingsApply . "<br>";
// Apply the settomgs
if (mysqli_query($conn, $settingsApply)) {
echo "Settings successfully updated!<br>";
} else {
echo "Database Error " . $sql . "<br>" . mysqli_error($conn);
}
// Prepare uploads directory if the user changed it
if ($targetDir != $oldDir) {
echo "Preparing directories...<br>";
$directory = "../" . $targetDir;
echo $directory. "<br>";
mkdir ($directory);
}
echo "<br>Configuration update complete! Going back in 3 seconds, or click below for the home page.<br><br>";
echo "<meta http-equiv='refresh' content='3;url=./' />";
?>
<a href="../">Homepage</a>

View File

@ -1,9 +1,11 @@
<!-- <!--
ImgHost - An open source image databasing and hosting system ImgHost - An open source image databasing and hosting system
A project by Taylor Courage (http://taylorcourage.net) A project by Taylor Courage (http://taylorcourage.net)
Latest Release: v0.4.0-beta (Dec 16, 2023) Latest Release: v0.5.0-alpha (Dec 17, 2023)
See README.MD for the latest changelog
--> -->
<?php <?php
include './config/db_config.php';
include './config/configuration.php'; include './config/configuration.php';
?> ?>
<html> <html>
@ -19,12 +21,17 @@
<div class="layout" align="center"> <div class="layout" align="center">
<h1><?php echo $serverName; ?></h1> <h1><?php echo $serverName; ?></h1>
<br /> <br />
<h3>Image Upload</h3>
<form action="upload.php" method="post" enctype="multipart/form-data"> <form action="upload.php" method="post" enctype="multipart/form-data">
<br /> <br />
<p><input type="file" name="fileToUpload" id="fileToUpload" /></p> <p><input type="file" name="fileToUpload" id="fileToUpload" /></p>
<p><input type="checkbox" name="isPrivate" id="isPrivate" value="1" /><label for="isPrivate"> Private</label></p> <?php
<p>Private images will not be shown in the public gallery, but will still be accessible by visiting the provided link.</p> if ($enablePrivate == 1) {
<p>All links are generated at random, and are virtually impossible to guess. "Security" through obscurity!</p> echo '<p><input type="checkbox" name="isPrivate" id="isPrivate" value="1" /><label for="isPrivate"> Private</label></p>';
echo '<p>Private images will not be shown in the public gallery, but will still be accessible by visiting the provided link.</p>';
echo '<p>All links are generated at random, and are virtually impossible to guess. "Security" through obscurity!</p>';
}
?>
<p><input type="submit" value="Upload Your Image" name="submit" /></p> <p><input type="submit" value="Upload Your Image" name="submit" /></p>
</form> </form>
<br /> <br />
@ -36,6 +43,7 @@
<br /> <br />
<br /> <br />
<br /> <br />
<h6>ImgHost (v0.4.0-beta)</h6> <h6><?php echo $serverName . " - " . $serverVers; ?></h6>
</div> </div>
</body>
</html> </html>