diff --git a/.gitignore b/.gitignore index f160d1c1..e163e2bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ servers/*.tgz !servers/*.html +mtm_db/ diff --git a/README.md b/README.md index 137e4842..fb2e3ad2 100755 --- a/README.md +++ b/README.md @@ -56,6 +56,14 @@ Mods / Gamepacks ChangeLog ---- +2/03/2021 - v1.1 +* Allow for user mods directory +* Add user mod upload portal (ZIP only) +* CSS tweaks +* Bugfix in mod reset function +* Server creation cleanup +* Administration panel for registration token generation and server management +* User / Server delete functions *TO BE ADDED* 2/01/2021 - v1.0 * Working PHP front end with user registeration and login diff --git a/config.php b/config.php index 08eed510..a400c5e6 100755 --- a/config.php +++ b/config.php @@ -17,6 +17,11 @@ $portrange = "30"; // xxx example 30, would be 30001 for port usage // Default "admin" account password $admin_passwd = "ChangeM3!"; +// Mod upload settings +$max_modzip_size = "20971520"; // Max mod zip file size in bytes, default 20MB +$allowed_file_extension = "zip"; // Allowed archive extension type. +// File mimetype is checked by the index upload-modzip function + // IRC settings, for IRC plugin $default_irc_server = "irc.edgy1.net"; $default_irc_port = "6667"; diff --git a/ctn/bg.jpg b/ctn/bg.jpg new file mode 100644 index 00000000..f49afceb Binary files /dev/null and b/ctn/bg.jpg differ diff --git a/style.css b/ctn/style.css similarity index 94% rename from style.css rename to ctn/style.css index 148179da..f964c9af 100755 --- a/style.css +++ b/ctn/style.css @@ -6,10 +6,11 @@ MTSM Stylesheet - (C) Chris Dorman, 2021 CC-BY-SA 3.0 @import url('https://fonts.googleapis.com/css2?family=Roboto&family=Ubuntu&display=swap'); html, body { - background-color: #626262; + background-color: #cccccc; background-repeat: no-repeat; background-attachment: fixed; background-position: center; + background-image: url('bg.jpg'); color: #e3e3e3; margin: 0 auto; font-size: 14px; @@ -44,13 +45,13 @@ html, body { #navbar a { text-decoration: none; font-family: "Ubuntu", "Roboto", sans-serif; - font-size: 26px; + font-size: 22px; text-align: center; padding-top: 4px; padding-bottom: 5px; background-color: #ffffff; color: #5577ff; - width: 125px; + width: 100px; display: inline-block; } @@ -132,6 +133,7 @@ a:hover { .maincontain { margin: 0 auto; width: 702px; + box-shadow: 0px 0px 22px #111111; } pre, code { diff --git a/functions.php b/functions.php index 47be95b7..5d1c6b5b 100755 --- a/functions.php +++ b/functions.php @@ -85,6 +85,19 @@ EOD; }*/ +function modUploadForm() { +?> +

+ Warning: Mod uploads MUST be in ZIP archive format and MUST have the mod contents WITHIN a parent directory + within the archive. Failure to do so would cause for non-working mod installations into your user mods menu. +

+ + +
+

+
@@ -100,6 +113,26 @@ function modsForm() { + + $filename
\n"; + } + chdir("../../../"); + ?> + +
+
diff --git a/index.php b/index.php index 106b6fcb..8bba13cf 100755 --- a/index.php +++ b/index.php @@ -35,6 +35,12 @@ if(!file_exists("mtm_db/users")) mkdir("mtm_db/users", 0777); } +// Adding a usermods directory +if(!file_exists("mtm_db/usermods")) +{ + mkdir("mtm_db/usermods"); +} + if(!file_exists("mtm_db/users/usercount")) { file_put_contents("mtm_db/users/usercount", "0"); @@ -50,7 +56,7 @@ $username = $_SESSION['mtm-user']; "> - + @@ -134,6 +140,11 @@ else if(isset($_GET['do'])) if(!is_dir("mtm_db/worlds/$userid")) { mkdir("mtm_db/worlds/$userid"); + // Check if usermods folder exists, create if not! + if(!is_dir("mtm_db/usermods/$username")) { + mkdir("mtm_db/usermods/$username"); + } + // Lets setup a default configuration script $config_contents = "port = 30" . $userid . "\n"; $config_contents .= "name = " . $username . "\n"; @@ -147,6 +158,10 @@ else if(isset($_GET['do'])) $config_contents .= "irc.channel = #$username\n"; file_put_contents("mtm_db/worlds/$userid/minetest.conf", $config_contents); + // Toggle server off, to the web panel + file_put_contents("mtm_db/users/$userid.pid.statuscode", "false"); + file_put_contents("mtm_db/users/$userid.pid.status", "
Stopped
\n"); + // Trigger event to start server file_put_contents("mtm_db/events/$userid", "tar -xzf servers/multicraft.tgz -C mtm_db/worlds/$userid"); file_put_contents("mtm_db/users/$userid.type", "multicraft"); @@ -157,13 +172,18 @@ else if(isset($_GET['do'])) } } - // Create private server for testing or private party reasons. + // Create private server for testing or private party reasons. if($do=="create-minetest") { if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { include("mtm_db/users/$username.php"); if(!is_dir("mtm_db/worlds/$userid")) { mkdir("mtm_db/worlds/$userid"); + // Check if usermods folder exists, create if not! + if(!is_dir("mtm_db/usermods/$username")) { + mkdir("mtm_db/usermods/$username"); + } + // Lets setup a default configuration script $config_contents = "port = " . $portrange . $userid . "\n"; $config_contents .= "name = " . $username . "\n"; @@ -177,6 +197,10 @@ else if(isset($_GET['do'])) $config_contents .= "irc.channel = #$username\n"; file_put_contents("mtm_db/worlds/$userid/minetest.conf", $config_contents); + // Toggle server off, to the web panel + file_put_contents("mtm_db/users/$userid.pid.statuscode", "false"); + file_put_contents("mtm_db/users/$userid.pid.status", "
Stopped
\n"); + // Trigger event to start servver file_put_contents("mtm_db/events/$userid", "tar -xzf servers/minetest-current.tgz -C mtm_db/worlds/$userid"); file_put_contents("mtm_db/users/$userid.type", "minetest"); @@ -290,6 +314,8 @@ else if(isset($_GET['do'])) } else { $serverstatus = file_get_contents("mtm_db/users/$userid.pid.statuscode"); if($serverstatus == "false") { + // Let them know this might take a while + echo "Please wait, this might take a few seconds depending on the amount of mods being enabled..."; // Check to see which mods where selected, and go from there! chdir("mods"); foreach(glob("*") as $modname) { @@ -302,7 +328,7 @@ else if(isset($_GET['do'])) sleep(2); } } - + chdir(".."); header("Location: index.php?do=manage"); } else { echo "Shut down server before configuration..."; @@ -314,6 +340,43 @@ else if(isset($_GET['do'])) } } + if($do=="configure-user-mods") + { + if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { + include("mtm_db/users/$username.php"); + if(is_dir("mtm_db/worlds/$userid")) { + if(!is_dir("mtm_db/worlds/$userid/bin")) { + echo "Pending: Server is pending creation, this process shouldn't take longer than 30 seconds..."; + } else { + $serverstatus = file_get_contents("mtm_db/users/$userid.pid.statuscode"); + if($serverstatus == "false") { + // Let them know this might take a while + echo "Please wait, this might take a few seconds depending on the amount of mods being enabled..."; + // Check to see which mods where selected, and go from there! + chdir("mtm_db/usermods/$username"); + foreach(glob("*") as $modname) { + // server_announce = true + if(isset($_POST[$modname])) { + echo "Copying $modname..."; + chdir("../.."); + file_put_contents("events/$userid", "cp -a mtm_db/usermods/$username/$modname mtm_db/worlds/$userid/worlds/world/worldmods/$modname"); + chdir("usermods/$username"); + sleep(2); + } + } + + chdir("../../../"); + + header("Location: index.php?do=manage"); + } else { + echo "Shut down server before configuration..."; + } + } + } else { + echo "ERROR: Server not found!"; + } + } + } if($do=="start") { if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { @@ -387,6 +450,35 @@ else if(isset($_GET['do'])) } } + if($do=="info-debug") { + if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { + include("mtm_db/users/$username.php"); + if(is_dir("mtm_db/worlds/$userid")) { + if(!is_dir("mtm_db/worlds/$userid/bin")) { + echo "Please wait: Server is being created, this process shouldn't take longer than 30 seconds..."; + // Refresh the page every 5 seconds for updates on the VM status. + echo ""; + } else { + echo $username . "'s Server
Server status: "; + $serverstatus = file_get_contents("mtm_db/users/$userid.pid.status"); + echo $serverstatus; + echo "
Reset minetest.conf  "; + echo " Reset logfile\n"; + echo "

Server information

"; + echo "

minetest.conf

"; + $userserverconfig = file_get_contents("mtm_db/worlds/$userid/minetest.conf"); + echo "
$userserverconfig
"; + + echo "

server log

"; + $userserverdebug = file_get_contents("mtm_db/users/$userid.slog"); + echo "
$userserverdebug
"; + } + } else { + echo "ERROR: Server not found!"; + } + } + } + if($do=="manage") { if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { include("mtm_db/users/$username.php"); @@ -396,24 +488,25 @@ else if(isset($_GET['do'])) // Refresh the page every 5 seconds for updates on the VM status. echo ""; } else { + + // Check if usermods folder exists, create if not! + // For users that created their accounts before update. + if(!is_dir("mtm_db/usermods/$username")) { + mkdir("mtm_db/usermods/$username"); + } + echo $username . "'s Server
Server status: "; $serverstatus = file_get_contents("mtm_db/users/$userid.pid.status"); echo $serverstatus; echo "

Start "; - echo "Stop Delete"; - echo "~ Server Settings Mod Settings
"; + echo "Stop Delete
"; + echo "Server Settings Mod Settings "; + echo "Server Information"; echo "

"; echo "Connection information:
"; - echo ""; + echo "
IP/Port:" . $defaultip . "/30" . $userid . "
"; echo ""; echo "
IP/Port:" . $defaultip . "/" . $portrange . $userid . "
Admin: $username
\n"; - echo "

minetest.conf

"; - $userserverconfig = file_get_contents("mtm_db/worlds/$userid/minetest.conf"); - echo "
$userserverconfig
"; - - echo "

debug.txt

"; - $userserverdebug = file_get_contents("mtm_db/users/$userid.slog"); - echo "
$userserverdebug
"; if(is_dir("mtm_db/worlds/$userid/worlds/world/worldmods")) { echo "

mods enabled

"; @@ -445,8 +538,6 @@ else if(isset($_GET['do'])) echo $username . "'s Server
Server status: "; $serverstatus = file_get_contents("mtm_db/users/$userid.pid.status"); echo $serverstatus; - echo "
Reset minetest.conf  "; - echo " Reset logfile\n"; echo "
"; echo "

Configure minetest.conf

"; settingsForm(); @@ -457,6 +548,51 @@ else if(isset($_GET['do'])) } } + if($do=="upload-modzip") + { + if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { + include("mtm_db/users/$username.php"); + if(is_dir("mtm_db/worlds/$userid")) { + if(!is_dir("mtm_db/worlds/$userid/bin")) { + echo "Please wait: Server is being created, this process shouldn't take longer than 30 seconds..."; + // Refresh the page every 5 seconds for updates on the VM status. + echo ""; + } else { + // Lets checkout what's being uploaded + if(isset($_POST['upload-btn'])) { + $filename = basename($_FILES['file']['name']); + $filetype = $_FILES['file']['type']; + $filesize = $_FILES['file']['size']; + if($filesize > $max_modzip_size) { + echo "Error on mod upload, file too big!"; + } else if (strtolower(pathinfo($filename,PATHINFO_EXTENSION))!=$allowed_file_extension) { + echo "Error on mod upload, ZIP archives only!"; + } else if (($_FILES["file"]["type"] == "application/zip") + || ($_FILES["file"]["type"] == "application/octet-stream")) { + // Looking good! + if($_FILES['file']['error'] > 0) { + echo "Unknown error code: " . $_FILES['file']['error']; + } else { + move_uploaded_file($_FILES['file']['tmp_name'], "mtm_db/usermods/$username/tmpmod.zip"); + file_put_contents("mtm_db/events/$userid", "unzip mtm_db/usermods/$username/tmpmod.zip -d mtm_db/usermods/$username/"); + sleep(4); + // Delete the mod zip after extraction + unlink("mtm_db/usermods/$username/tmpmod.zip"); + header("Location: index.php?do=mods"); + } + } else { + echo "Error on mod upload, archive mimetype was not of a ZIP archive."; + } + } else { + echo "Upload button causing some issues?"; + } + } + } else { + echo "ERROR: Server not found!"; + } + } + } + if($do=="mods") { if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { @@ -471,16 +607,23 @@ else if(isset($_GET['do'])) $serverstatus = file_get_contents("mtm_db/users/$userid.pid.status"); echo $serverstatus; echo "
Reset mods\n"; - echo "
"; - echo "

Enable mods

"; - modsForm(); - - echo "
"; echo "

Change default game

"; chdir("games"); foreach(glob("*") as $gamemode) { echo "$gamemode"; } + chdir(".."); + + echo "

Enable mods from local repository

"; + modsForm(); + + echo "

Enable user available mods

"; + // In case someone fucks there shit up + echo "Delete user mods
"; + userModsForm($username); + + echo "

Personal mod upload

"; + modUploadForm(); } } else { echo "ERROR: Server not found!"; @@ -499,7 +642,37 @@ else if(isset($_GET['do'])) echo ""; } else { if(is_dir("mtm_db/worlds/$userid/worlds/world/worldmods")) { - file_put_contents("mtm_db/events/$userid", "rm -r mtm_db/worlds/$userid/worlds/world/worldmods"); + $serverstatus = file_get_contents("mtm_db/users/$userid.pid.statuscode"); + if($serverstatus == "false") { + file_put_contents("mtm_db/events/$userid", "rm -r mtm_db/worlds/$userid/worlds/world/worldmods/*"); + sleep(1); + header("Location: index.php?do=manage"); + } else { + echo "Error: please shut down your server before deleting world mods!"; + } + } else { + echo "Error: mods directory for your world doesn't exit!"; + } + } + } else { + echo "ERROR: Server not found!"; + } + } + } + + if($do=="reset-user-mods") + { + if (!isset($_SESSION['mtm-user']) || !isset($_SESSION['mtm-pass'])) { loginForm(); } else { + include("mtm_db/users/$username.php"); + if(is_dir("mtm_db/worlds/$userid")) { + if(!is_dir("mtm_db/worlds/$userid/bin")) { + echo "Please wait: Server is being created, this process shouldn't take longer than 30 seconds..."; + // Refresh the page every 5 seconds for updates on the VM status. + echo ""; + } else { + if(is_dir("mtm_db/usermods/$username")) { + file_put_contents("mtm_db/events/$userid", "rm -r mtm_db/usermods/$username/*"); + sleep(2); header("Location: index.php?do=manage"); } } @@ -675,8 +848,8 @@ else if(!is_dir("mtm_db/worlds/$userid")) { echo "

Minetest server creation

"; - echo "

You will have the ability to create a server, and will have a consistent uptime based on server uptime, and automated server management!

"; - + echo "

You will have the ability to create a server, and will have a consistent uptime based on server uptime, and automated server management!"; + echo "There's mods and gamepacks available to users and can be toggled on and off! Over time, more will be populated into the local repository.

"; // Get home page for non-users based on users wants $useraboutmulticraft = file_get_contents("text/multicraft.txt"); $useraboutminetest = file_get_contents("text/minetest.txt"); @@ -692,9 +865,9 @@ else } else - { - echo "

You've been assigned a Minetest server, click "Manage" for more information on your server.

"; - } + { + header("Location: index.php?do=manage"); + } } else { // This is the admin panel! echo "

Administration panel

"; diff --git a/server b/server index ab1ef034..2660e26a 100755 --- a/server +++ b/server @@ -25,7 +25,7 @@ case $1 in esac ;; start-minetest ) - ((./mtm_db/worlds/$2/bin/minetestserver --logfile mtm_db/users/$userid.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) & + ((./mtm_db/worlds/$2/bin/minetestserver --logfile mtm_db/users/$2.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) & sleep 10 @@ -35,7 +35,7 @@ case $1 in ;; start-multicraft ) - ((./mtm_db/worlds/$2/bin/multicraftserver --logfile mtm_db/users/$userid.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) & + ((./mtm_db/worlds/$2/bin/multicraftserver --logfile mtm_db/users/$2.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) & sleep 20 diff --git a/start-mtsm b/start-mtsm index 7c49e3dd..e8128607 100755 --- a/start-mtsm +++ b/start-mtsm @@ -2,7 +2,7 @@ # (C) Chris Dorman, 2021 - MTSM - CC-BY-SA 3.0 case $1 in - start ) ./mtsm > /dev/null &;; + start ) ./mtsm > /dev/null 2>&1 &;; stop ) killall mtsm;; * ) echo "Usage: ./start-mtsm [start|stop]";; esac diff --git a/text/multicraft.txt b/text/multicraft.txt index 6e1ebb3d..f1f1ed5c 100755 --- a/text/multicraft.txt +++ b/text/multicraft.txt @@ -2,4 +2,6 @@ MultiCraft is a fork of the original Minetest project in hopes to make a more complete front-end to the minetest-server with server additions as well. This allows for an easy solution to managing multiple game worlds by a single administration control panel. Also enhanced with a powerful user API, -billing integration, built-in database provisioning for backups, and FTP server. +billing integration, built-in database provisioning for backups, and FTP server. Lets not forget that +MultiCraft merges the different version protocol incompatabilities that have risen over the years of +development!