123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- // SVMM - Simple VM Manager - For Qemu KVM
- // (C) Chris Dorman, 2020
- // License: CC-BY-NC-SA version 3.0
- // http://github.com/Pentium44/SVMM
- session_start();
- include "config.php";
- include "functions.php";
- // check if flatfile database location is populated
- if(!file_exists("svmm_db"))
- {
- mkdir("svmm_db", 0777);
- }
- if(!file_exists("svmm_db/events"))
- {
- mkdir("svmm_db/events", 0777);
- }
- if(!file_exists("svmm_db/disks"))
- {
- mkdir("svmm_db/disks", 0777);
- }
- if(!file_exists("svmm_db/pids"))
- {
- mkdir("svmm_db/pids", 0777);
- }
- if(!file_exists("svmm_db/users"))
- {
- mkdir("svmm_db/users", 0777);
- }
- if(!file_exists("svmm_db/users/usercount"))
- {
- file_put_contents("svmm_db/users/usercount", "9");
- }
- $username = $_SESSION['svmm-user'];
- ?>
- <!DOCTYPE html>
- <html lang="en-us">
- <head>
- <title><?php echo $svmmtitle; ?></title>
- <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($svmmtitle) . " - " . $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">
- </head>
- <body>
- <div class="maincontain">
- <div id="navcontainer">
- <div id="navbar"><!--
- <?php if(isset($_SESSION['svmm-user']) && isset($_SESSION['svmm-pass'])) { ?>
- --><a href="index.php">Create</a><!--
- --><a href="?do=manage">Manage</a><!--
- --><a href="?do=about">About</a><!--
- --><a href="?do=logout">Logout</a><!--
- <?php } else {?>
- --><a href="?forms=login">Login</a><!--
- --><a href="?forms=register">Register</a><!--
- --><a href="?do=about">About</a><!--
- <?php } ?>
- --></div>
- </div>
- <div class='title'><img src='freebox-logo.png' /></div>
- <div class='contain'>
- <?php
- if(isset($_GET['forms']))
- {
- $forms = $_GET['forms'];
- $id = $_GET['pid'];
- if($forms=="register") {
- registerForm();
- }
- else if($forms=="login") {
- loginForm();
- }
- else { echo "ERROR: Unknown form-name<br>"; }
- }
- else if(isset($_GET['notify']))
- {
- $notify = $_GET['notify'];
- if($notify=="1") { echo "Error: User not found"; }
- else if($notify=="2") { echo "Error: Incorrect password provided"; }
- else if($notify=="3") { echo "Error: Please fill out all the text boxes"; }
- else if($notify=="4") { echo "Error: The provided passwords did not match"; }
- else if($notify=="5") { echo "Error: Special characters cannot be used in your username"; }
- else if($notify=="6") { echo "Error: This username is already in use"; }
- else { echo "Error: unknown error... this is quite unusual..."; }
- }
- else if(isset($_GET['do']))
- {
- $do = $_GET['do'];
- // Server admin can just delete ssb_db
- /*if($do=="clean")
- {
- if($_POST['password']!="" && $_POST['password']==$pw)
- {
- $db_content = glob("ssb_db/" . '*', GLOB_MARK);
- foreach($db_content as $file)
- {
- unlink($file);
- }
- rmdir("ssb_db");
- echo "Database Cleaned<br>";
- }
- else
- {
- echo "ERROR: Wrong Password<br>";
- }
- }*/
- // grab session values and send friend request functions.
-
- if($do=="create-medium") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(!file_exists("svmm_db/disks/$userid.img")) {
- if(!copy("svmm_db/disks/alpine.img", "svmm_db/disks/$userid.img"))
- {
- echo "Error copying new disk image to user location... Please contact the system administrator!";
- }
- else
- {
- // Trigger event to start VM!
- file_put_contents("svmm_db/events/$userid", "./machine start-medium $userid");
- file_put_contents("ssvm_db/users/$userid.type", "medium");
- echo "VM created! Refer to the user management panel for start / up info.";
- }
- } else {
- echo "Error: VM exists, please click "Manage" to start / stop your VM or to download a disk backup.";
- }
- }
- }
-
- // For real VMs
- if($do=="create-mini") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(!file_exists("svmm_db/disks/$userid.img")) {
- if(!copy("svmm_db/disks/slitaz.img", "svmm_db/disks/$userid.img"))
- {
- echo "Error copying new disk image to user location... Please contact the system administrator!";
- }
- else
- {
- // Trigger event to start VM!
- file_put_contents("svmm_db/events/$userid", "./machine start-mini $userid");
- file_put_contents("svmm_db/users/$userid.type", "mini");
- echo "VM created! Refer to the user management panel for start / up info.";
- }
- } else {
- echo "Error: VM exists, please click "Manage" to start / stop your VM or to download a disk backup.";
- }
- }
- }
-
- if($do=="start") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(file_exists("svmm_db/disks/$userid.img")) {
- if(!file_exists("svmm_db/users/$userid.pid.statuscode")) {
- echo "Pending: VM is pending creation, this process shouldn't take longer than 30 seconds...";
- } else {
- $vmstatus = file_get_contents("svmm_db/users/$userid.pid.statuscode");
- if($vmstatus == "false") {
- $vmtype = file_get_contents("svmm_db/users/$userid.type");
- if(!file_exists("svmm_db/users/$userid.type") || $vmtype == "medium") {
- file_put_contents("svmm_db/events/$userid", "./machine start-medium $userid");
- } else if($vmtype == "mini") {
- file_put_contents("svmm_db/events/$userid", "./machine start-mini $userid");
- }
- header("Location: index.php?do=manage");
- } else {
- echo "VM already running...";
- }
- }
- } else {
- echo "ERROR: VM not found!";
- }
- }
- }
-
- if($do=="stop") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(file_exists("svmm_db/disks/$userid.img")) {
- if(!file_exists("svmm_db/users/$userid.pid.statuscode")) {
- echo "Pending: VM is pending creation, this process shouldn't take longer than 30 seconds...";
- } else {
- $vmstatus = file_get_contents("svmm_db/users/$userid.pid.statuscode");
- if($vmstatus == "true") {
- file_put_contents("svmm_db/events/$userid", "./machine stop $userid");
- header("Location: index.php?do=manage");
- } else {
- echo "VM already stopped...";
- }
- }
- } else {
- echo "ERROR: VM not found!";
- }
- }
- }
-
- if($do=="delete") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(file_exists("svmm_db/disks/$userid.img")) {
- $vmstatus = file_get_contents("svmm_db/users/$userid.pid.statuscode");
- if($vmstatus == "true") {
- file_put_contents("svmm_db/events/$userid", "./machine del $userid");
- sleep(2);
- unlink("svmm_db/users/$userid.pid.status");
- unlink("svmm_db/users/$userid.pid.statuscode");
- header("Location: index.php");
- } else {
- unlink("svmm_db/users/$userid.pid.status");
- unlink("svmm_db/users/$userid.pid.statuscode");
- unlink("svmm_db/pids/$userid.pid");
- unlink("svmm_db/disks/$userid.img");
- header("Location: index.php");
- }
- } else {
- echo "ERROR: VM not found!";
- }
- }
- }
-
- if($do=="manage") {
- if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass'])) { loginForm(); } else {
- include("svmm_db/users/$username.php");
- if(file_exists("svmm_db/disks/$userid.img")) {
- if(!file_exists("svmm_db/users/$userid.pid.status")) {
- echo "Please wait: VM 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 VM<br /> VM status: ";
- $vmstatus = file_get_contents("svmm_db/users/$userid.pid.status");
- echo $vmstatus;
- echo "<br /><a href='index.php?do=start' class='button'>Start</a> <a href='index.php?do=stop' class='button'>Stop</a> <a href='index.php?do=delete' class='button'>Delete</a><br />";
- echo "The VM manipulation functions above take time to process, the page will update within 1 minute";
- echo "<br /><br />";
- echo "<b>Connection information (Via SSH):</b><br />";
- echo "<table><tr><td>IP/Port:</td><td> cddo.cf/" . $userid . "22</td></tr>";
- echo "<tr><td>Default username:</td><td> user</td></tr>";
- echo "<tr><td>Default user password:</td><td> user</td></tr>";
- echo "<tr><td style='padding-right: 30px;'>Default root password: </td><td>root</td></tr></table><br />";
- echo "<b>Available ports for use:</b>";
- echo "<table><tr><td style='padding-right:30px;'>Server side port</td><td>External port (viewable)</td></tr>";
- echo "<tr><td>21</td><td>" . $userid . "21</td></tr>";
- echo "<tr><td>22</td><td>" . $userid . "22</td></tr>";
- echo "<tr><td>80</td><td>" . $userid . "80</td></tr>";
- //echo "<tr><td>25565</td><td>" . $userid . "65</td></tr>";
- echo "<tr><td>6666</td><td>" . $userid . "66</td></tr>";
- echo "<tr><td>6667</td><td>" . $userid . "67</td></tr>";
- echo "</table>";
- // Refresh the page every 5 seconds for updates on the VM status.
- echo "<meta http-equiv='refresh' content='5' />";
- }
- } else {
- echo "ERROR: VM not found!";
- }
- }
- }
- if($do=="about")
- {
- echo "<h2>About</h2>";
- echo "<p>" . $desc;
- echo "<br />If anyone runs into any issues with the FreeBox services, or wants to request a registration code; please reach out at cddo [at] riseup [dot] net.<br />";
- echo "<br />If you enjoy the FreeBox services, please consider donating!";
- echo '<form action="https://www.paypal.com/donate" method="post" target="_top">
- <input type="hidden" name="cmd" value="_donations" />
- <input type="hidden" name="business" value="cdorm245@gmail.com" />
- <input type="hidden" name="currency_code" value="USD" />
- <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
- <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
- </form></p>';
- }
- if($do=="login")
- {
- $username = $_POST['username'];
- if(file_exists("svmm_db/users/$username.php")) {
- include_once("svmm_db/users/$username.php");
- if($user_password==sha1(md5($_POST['password']))) {
- $pass = $user_password;
- $user = $username;
- $color = $user_color;
- $_SESSION['svmm-user'] = $user;
- $_SESSION['svmm-pass'] = $pass;
- header("Location: index.php");
- } else {
- echo "Wrong password!";
- }
- } else {
- echo "User $username not found!";
- }
- }
- if($do=="logout")
- {
- $_SESSION['svmm-user'] = null;
- $_SESSION['svmm-pass'] = null;
- header("Location: index.php?forms=login");
- }
- if($do=="register")
- {
- if($_POST['username']!="" && $_POST['password']!="" && $_POST['password-again']!="" && $_POST['fullname']!="" && isset($_POST['email']) && $_POST['email']!="") {
- if($_POST['password']==$_POST['password-again']) {
- if(!preg_match('/[^a-z0-9]/i', $_POST['username'])) {
- if(!file_exists("svmm_db/users/" . $_POST['username'] . ".php")) {
- $vpscount = file_get_contents("svmm_db/users/usercount");
- if($vpscount < $maxvm)
- {
- if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
- if(stripslashes(htmlentities($_POST['codeword'])) == $panelpass) {
- $vpscount = $vpscount + 1;
- file_put_contents("svmm_db/users/usercount", $vpscount);
- file_put_contents("svmm_db/users/" . stripslashes(htmlentities($_POST['username'])) . ".php", "<?php\n\$user_handle = \"" . stripslashes(htmlentities($_POST['username'])) . "\";\n\$user_password = \"" . sha1(md5($_POST['password'])) . "\";\n \$user_email = \"" . stripslashes(htmlentities($_POST['email'])) . "\"; \$user_fullname = \"" . stripslashes(htmlentities($_POST['fullname'])) . "\"; \$userid = \"" . $vpscount . "\";\n?>");
- header("Location: index.php");
- }
- else
- {
- echo "ERROR: Registration code incorrect, please try again!";
- }
- }
- else
- {
- echo "ERROR: Email is invalid!";
- }
- }
- else
- {
- echo "ERROR: VPS cap reached!";
- }
- } else {
- header("Location: index.php?notify=6");
- }
- } else {
- header("Location: index.php?notify=5");
- }
- } else {
- header("Location: index.php?notify=4");
- }
- } else {
- header("Location: index.php?notify=3");
- }
- }
- }
- else if (!isset($_SESSION['svmm-user']) || !isset($_SESSION['svmm-pass']))
- {
- header("Location: index.php?do=about");
- }
- else
- {
- include("svmm_db/users/$username.php");
- if(!file_exists("svmm_db/disks/$userid.img"))
- {
- echo "<h3>Free VPS creation</h3>";
- echo "<p>Each user will have the ability to create a VM, and will have a consistent uptime unless FreeBox ends up being disabled due to malicious users improperly using the virtual machines.</p>";
- echo "<table><tr><td style='vertical-align: top; width: 50%; '>Best VM for IRC bouncers / session idling CLI IRC clients. Great for small websites and some development.<br /><br />";
- echo "<ul><li>CPU: 10% of 1x Xeon E5649 core</li><li>RAM: 48MB dedicated</li><li>Disk: 500MB dedicated space</li><li>OS: SliTaz GNU/Linux</li><li>Network: 10mbps down + 5mbps upload</li><li>Select available ports for server operation</li></ul>";
- echo "<div style='display:block;width:100%;text-align:center;'><a href='index.php?do=create-mini' class='button'>Create a Micro Box</a></div>";
- echo "</td><td style='vertical-align: top; width: 50%;'>Best VM for development / IRC server hosting / FTP server hosting. Awesome for hosting source tarballs, websites, forums, git repo, and more!";
- echo "<ul><li>CPU: 25% of 1x Xeon E5649 core</li><li>RAM: 192MB dedicated</li><li>Disk: 10GB dedicated space</li><li>OS: Alpine GNU/Linux</li><li>Network: 10mbps down + 5mbps upload</li><li>Select available ports for server operation</li></ul>";
- echo "<div style='display:block;width:100%;text-align:center;'><a href='index.php?do=create-medium' class='button'>Create a Mini Box</a></div>";
- echo "</td></tr></table>";
- }
- else
- {
- echo "<p>You've been assigned a VPS, click "Manage" for more information on your server.</p>";
- }
- }
- ?>
- <br /><br />
- <div style="margin: auto; width: 100%; text-align: center; background-color: #555555; padding: 3px;">Powered By <a href="https://notabug.org/Pentium44/SVMM">SVMM</a> <?php echo $version; ?></div>
- </div>
- </div> <!-- main contain -->
- </body>
- </html>
|