diff --git a/.gitignore b/.gitignore index 3d0d873..96db2b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -credentials.php uploads/ config/db_config.php diff --git a/README.md b/README.md index 18b336a..4747942 100644 --- a/README.md +++ b/README.md @@ -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. -If you plan on using a custom domain, you can also edit `config/configuation.php` to include that. - -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! +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. ## 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 - Full re-factor to convert the old "Meme Machine" to a general-purpose, plug-and-play image hosting software. diff --git a/browse/index.php b/browse/index.php index dc881bc..513543b 100644 --- a/browse/index.php +++ b/browse/index.php @@ -40,14 +40,17 @@ if (mysqli_num_rows($result) > 0) { } } } 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"; ?>

 

- Home + Home '; +echo '
'; +echo '
'; +echo '
' . $serverName . " - " . $serverVers . "
"; echo ''; echo ''; ?> diff --git a/config/configuration.php b/config/configuration.php index 8ec767a..67749f2 100644 --- a/config/configuration.php +++ b/config/configuration.php @@ -1,26 +1,95 @@ Try re-initializing the server if this persists!
"; + $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 $supportedFileTypes = array ( "image/jpeg", diff --git a/config/db_config.php b/config/db_config.php index 954ffb0..e1e3830 100644 --- a/config/db_config.php +++ b/config/db_config.php @@ -19,5 +19,7 @@ $sqlPassword = "password"; // Database Settings $dbname = "imghost_data"; $tablename = "images"; +$settingstable = "settings"; +$authtable = "auth"; ?> \ No newline at end of file diff --git a/config/index.php b/config/index.php index a296d40..0f0dea1 100644 --- a/config/index.php +++ b/config/index.php @@ -1,36 +1,73 @@ - - + - <?php echo $serverName; ?> Config + ImgHost Config
-

-
-
+ ' . $serverName . ' Setup
-

-
-
-
+

Initial Configuration

+
+
+

Server Name:

+

Hostname:

+

Uploads Directory:

+

Stylesheet:

+

Enable private uploads:

+

+
'; + + } 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 '

' . $serverName . ' Setup

+
+

Configuration

+
+
+

Server Name:

+

Hostname:

+

Uploads Directory:

+

Stylesheet:

+

Enable private uploads:

+

+
'; + + } + ?>



- -
-
+

Home



-
-
ImgHost (v0.4.0-beta)
+
diff --git a/config/initial_setup.php b/config/initial_setup.php index 829e8fd..73cba9f 100644 --- a/config/initial_setup.php +++ b/config/initial_setup.php @@ -1,7 +1,5 @@ "; @@ -36,7 +34,7 @@ if (!$conn) { } echo "Sql connection successful!
"; -// 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 ( imgID CHAR(12), fileType VARCHAR(4), @@ -46,15 +44,106 @@ $tableSetup = "CREATE TABLE IF NOT EXISTS $tablename ( editDate DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; -echo "Preparing table with command - " . $tableSetup . "
"; +echo "Preparing images database table with command - " . $tableSetup . "
"; if (mysqli_query($conn, $tableSetup)) { - echo "Table successfully prepared!
"; + echo "Images table successfully prepared!
"; } else { echo "Database Error " . $sql . "
" . mysqli_error($conn); } -echo "Preparing images folder...
"; +// 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 . "
"; + +if (mysqli_query($conn, $settingsSetup)) { + echo "Settings table successfully prepared!
"; +} else { + echo "Database Error " . $sql . "
" . mysqli_error($conn); +} + +echo "Writing settings to database...
"; + +// 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 . "
"; + + +if (mysqli_query($conn, $settingsApply)) { + echo "Settings table successfully written!
"; +} else { + echo "Database Error " . $sql . "
" . mysqli_error($conn); +} + + + + +// Prepare uploads directory +echo "Preparing directories...
"; + + $directory = "../" . $targetDir; echo $directory. "
"; diff --git a/config/style.css b/config/style.css index 3ca39ef..5d7f6ed 100644 --- a/config/style.css +++ b/config/style.css @@ -1,6 +1,6 @@ .background { background-attachment: fixed; - background: linear-gradient(237deg, #0000ffd2, #1eff009a, #7d00a7); + background: linear-gradient(237deg, #92018ba1, #0000ffd2, #1eff008c, #ffae008c, #a70016ce); background-size: 500% 500%; -webkit-animation: AnimationName 90s ease infinite; diff --git a/config/update_setup.php b/config/update_setup.php new file mode 100644 index 0000000..4414622 --- /dev/null +++ b/config/update_setup.php @@ -0,0 +1,94 @@ +"; +echo "$sqlServer
"; +echo "$sqlUsername
"; +echo "$sqlPassword
"; + +echo "Connecting to database...
"; +$conn = mysqli_connect($sqlServer, $sqlUsername, $sqlPassword, $dbname); + +if (!$conn) { + die("Connection failed: " . mysqli_connect_error()); +} +echo "Sql connection successful!
"; + +// 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 . "
"; + +// Apply the settomgs +if (mysqli_query($conn, $settingsApply)) { + echo "Settings successfully updated!
"; +} else { + echo "Database Error " . $sql . "
" . mysqli_error($conn); +} + + +// Prepare uploads directory if the user changed it + +if ($targetDir != $oldDir) { + echo "Preparing directories...
"; + $directory = "../" . $targetDir; + echo $directory. "
"; + mkdir ($directory); +} + +echo "
Configuration update complete! Going back in 3 seconds, or click below for the home page.

"; +echo ""; + +?> + +Homepage \ No newline at end of file diff --git a/index.php b/index.php index 8a21f22..8e12ee7 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,11 @@ @@ -19,12 +21,17 @@


+

Image Upload


-

-

Private images will not be shown in the public gallery, but will still be accessible by visiting the provided link.

-

All links are generated at random, and are virtually impossible to guess. "Security" through obscurity!

+

'; + echo '

Private images will not be shown in the public gallery, but will still be accessible by visiting the provided link.

'; + echo '

All links are generated at random, and are virtually impossible to guess. "Security" through obscurity!

'; + } + ?>


@@ -36,6 +43,7 @@


-
ImgHost (v0.4.0-beta)
+
+