Call this v1.1

master
Pentium44 2021-02-03 14:21:00 -08:00
parent f59f480791
commit 2e967ff116
10 changed files with 257 additions and 33 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
servers/*.tgz
!servers/*.html
mtm_db/

View File

@ -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

View File

@ -17,6 +17,11 @@ $portrange = "30"; // <port range>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";

BIN
ctn/bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

View File

@ -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 {

View File

@ -85,6 +85,19 @@ EOD;
}*/
function modUploadForm() {
?>
<p>
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.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=upload-modzip" method="POST" enctype="multipart/form-data">
<input type="file" name="file"></input>
<input style="padding: 2px;" class="text" type="submit" name="upload-btn" value="Upload">
</form>
</p>
<?php
}
function modsForm() {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=configure-mods" method="post">
@ -100,6 +113,26 @@ function modsForm() {
<?php
}
function userModsForm($username) {
if(count(glob("mtm_db/usermods/$username/*")) !== 0) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=configure-user-mods" method="post">
<?php
chdir("mtm_db/usermods/$username/");
foreach(glob("*") as $filename) {
echo "<input class='text' type='checkbox' name='$filename'> $filename<br />\n";
}
chdir("../../../");
?>
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set mods">
</form>
<?php
} else {
echo "No user mods available!";
}
}
function settingsForm() {
?>
<div class="login">

225
index.php
View File

@ -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'];
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=.55, shrink-to-fit=yes"><meta name="description" content="<?php echo htmlentities($mtsmtitle) . " - " . $desc; ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="ctn/style.css">
</head>
<body>
@ -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", "<div style='display:inline;color:#ff0000;'>Stopped</div>\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", "<div style='display:inline;color:#ff0000;'>Stopped</div>\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 "<meta http-equiv='refresh' content='5' />";
} else {
echo $username . "'s Server<br /> Server status: ";
$serverstatus = file_get_contents("mtm_db/users/$userid.pid.status");
echo $serverstatus;
echo "<br /><a href='index.php?do=reset-config' class='button'>Reset minetest.conf</a> &nbsp;";
echo " <a href='index.php?do=del-logfile' class='button'>Reset logfile</a>\n";
echo "<h3>Server information</h3>";
echo "<h4>minetest.conf</h4>";
$userserverconfig = file_get_contents("mtm_db/worlds/$userid/minetest.conf");
echo "<code><pre>$userserverconfig</pre></code>";
echo "<h4>server log</h4>";
$userserverdebug = file_get_contents("mtm_db/users/$userid.slog");
echo "<code><pre>$userserverdebug</pre></code>";
}
} 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 "<meta http-equiv='refresh' content='5' />";
} 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<br /> Server status: ";
$serverstatus = file_get_contents("mtm_db/users/$userid.pid.status");
echo $serverstatus;
echo "<br /><br /><a href='index.php?do=start' class='button'>Start</a>&nbsp;";
echo "<a href='index.php?do=stop' class='button'>Stop</a>&nbsp;<a href='index.php?do=delete' class='button'>Delete</a>";
echo "~ <a href='index.php?do=settings' class='button'>Server Settings</a>&nbsp;<a href='index.php?do=mods' class='button'>Mod Settings</a><br />";
echo "<a href='index.php?do=stop' class='button'>Stop</a>&nbsp;<a href='index.php?do=delete' class='button'>Delete</a><br />";
echo "<a href='index.php?do=settings' class='button'>Server Settings</a>&nbsp;<a href='index.php?do=mods' class='button'>Mod Settings</a>&nbsp;";
echo "<a href='index.php?do=info-debug' class='button'>Server Information</a>";
echo "<br /><br />";
echo "<b>Connection information:</b><br />";
echo "<table><tr><td>IP/Port:</td><td>" . $defaultip . "/30" . $userid . "</td></tr>";
echo "<table><tr><td>IP/Port:</td><td>" . $defaultip . "/" . $portrange . $userid . "</td></tr>";
echo "<tr><td>Admin: </td><td>$username</td></tr>";
echo "</table>\n";
echo "<h4>minetest.conf</h4>";
$userserverconfig = file_get_contents("mtm_db/worlds/$userid/minetest.conf");
echo "<code><pre>$userserverconfig</pre></code>";
echo "<h4>debug.txt</h4>";
$userserverdebug = file_get_contents("mtm_db/users/$userid.slog");
echo "<code><pre>$userserverdebug</pre></code>";
if(is_dir("mtm_db/worlds/$userid/worlds/world/worldmods")) {
echo "<h4>mods enabled</h4>";
@ -445,8 +538,6 @@ else if(isset($_GET['do']))
echo $username . "'s Server<br /> Server status: ";
$serverstatus = file_get_contents("mtm_db/users/$userid.pid.status");
echo $serverstatus;
echo "<br /><a href='index.php?do=reset-config' class='button'>Reset minetest.conf</a> &nbsp;";
echo " <a href='index.php?do=del-logfile' class='button'>Reset logfile</a>\n";
echo "<br />";
echo "<h3>Configure minetest.conf</h3>";
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 "<meta http-equiv='refresh' content='5' />";
} 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 "<br /><a href='index.php?do=reset-mods' class='button'>Reset mods</a>\n";
echo "<br />";
echo "<h3>Enable mods</h3>";
modsForm();
echo "<br />";
echo "<h3>Change default game</h3>";
chdir("games");
foreach(glob("*") as $gamemode) {
echo "<a href='index.php?do=configure-game&game=$gamemode' class='button'>$gamemode</a>";
}
chdir("..");
echo "<h3>Enable mods from local repository</h3>";
modsForm();
echo "<h3>Enable user available mods</h3>";
// In case someone fucks there shit up
echo "<a href='index.php?do=reset-user-mods' class='button'>Delete user mods</a><br />";
userModsForm($username);
echo "<h3>Personal mod upload</h3>";
modUploadForm();
}
} else {
echo "ERROR: Server not found!";
@ -499,7 +642,37 @@ else if(isset($_GET['do']))
echo "<meta http-equiv='refresh' content='5' />";
} 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 "<meta http-equiv='refresh' content='5' />";
} 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 "<h3>Minetest server creation</h3>";
echo "<p>You will have the ability to create a server, and will have a consistent uptime based on server uptime, and automated server management!</p>";
echo "<p>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.</p>";
// 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 "<p>You've been assigned a Minetest server, click &quot;Manage&quot; for more information on your server.</p>";
}
{
header("Location: index.php?do=manage");
}
} else {
// This is the admin panel!
echo "<h3>Administration panel</h3>";

4
server
View File

@ -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

View File

@ -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

View File

@ -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!