Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Finish #78
-> Fixed server creation page with no name
  • Loading branch information
NaysKutzu committed Oct 27, 2023
1 parent a8b7af4 commit 7d386ee
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 13 deletions.
1 change: 1 addition & 0 deletions migrate/24.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_servers` ADD `purge` ENUM('true','false') NOT NULL DEFAULT 'true' AFTER `uid`;
1 change: 1 addition & 0 deletions migrate/25.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_settings` ADD `server_purge` ENUM('false','true') NOT NULL AFTER `privacy_policy`
4 changes: 4 additions & 0 deletions routes/admin/servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
require("../view/admin/servers/list.php");
});

$router->add("/admin/servers/purge", function () {
require("../include/main.php");
require("../view/admin/servers/purge.php");
});

$router->add("/admin/server/delete", function () {
require("../include/main.php");
Expand Down
4 changes: 4 additions & 0 deletions routes/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
require("../view/admin/settings/pterodactyl.php");
});

$router->add("/admin/settings/purge", function () {
require("../include/main.php");
require("../view/admin/settings/purge.php");
});

$router->add("/admin/settings/seo", function () {
require("../include/main.php");
Expand Down
5 changes: 5 additions & 0 deletions routes/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
require("../view/server/edit.php");
});

$router->add('/server/active', function () {
require("../include/main.php");
require("../view/server/active.php");
});

$router->add('/server/queue/delete', function () {
require("../include/main.php");
require("../view/server/queueDelete.php");
Expand Down
2 changes: 2 additions & 0 deletions view/admin/servers/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<th>Panel ID</th>
<th>Location ID</th>
<th>Egg ID</th>
<th>Purge</th>
<th>Created</th>
<th>Action</th>
</tr>
Expand All @@ -82,6 +83,7 @@
echo '<td>' . $row['pid'] . '</td>';
echo '<td>' . $row['location'] . '</td>';
echo '<td>' . $row['egg_id'] . '</td>';
echo '<td>' . $row['purge'] . '</td>';
echo '<td>' . $row['created'] . '</td>';
echo '<td><a href="' . SettingsManager::getSetting("PterodactylURL") . '/admin/servers/view/' . $row['pid'] . '" target="blank" class="btn btn-primary">View</a>&nbsp;<a href="/admin/server/delete?pid=' . $row['pid'] . '" class="btn btn-danger">Delete</a></td>';
echo '</tr>';
Expand Down
51 changes: 51 additions & 0 deletions view/admin/servers/purge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
use MythicalDash\SettingsManager;
include(__DIR__ . '/../../requirements/page.php');
include(__DIR__ . '/../../requirements/admin.php');

function PurgeServers($dbconn)
{
$dbconn->query("TRUNCATE TABLE `mythicaldash`.`mythicaldash_servers_queue`");
$query = "SELECT * FROM mythicaldash_servers WHERE mythicaldash_servers.purge = 'true'";
$resultdb = mysqli_query($dbconn, $query);
if ($resultdb) {
while ($row = mysqli_fetch_assoc($resultdb)) {
$delete_server = curl_init(SettingsManager::getSetting("PterodactylURL") . "/api/application/servers/" . $row['pid'] . "/force");
curl_setopt($delete_server, CURLOPT_CUSTOMREQUEST, "DELETE");
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
"Authorization: Bearer " . SettingsManager::getSetting("PterodactylAPIKey")
);
curl_setopt($delete_server, CURLOPT_HTTPHEADER, $headers);
curl_setopt($delete_server, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($delete_server);
curl_close($delete_server);
if (!empty($result)) {
header('location: /admin/settings?e=There was an error while deleting a server.');
$dbconn->close();
die();
}
if (mysqli_query($dbconn, "DELETE FROM mythicaldash_servers WHERE pid = '" . mysqli_real_escape_string($dbconn, $row['pid']) . "'")) {

} else {
header('location: /admin/settings?e=There was an error while deleting a server.');
$dbconn->close();
die();
}
}
} else {
$dbconn->close();
header('location: /admin/settings?e=Database query error');
die();
}
}
try {
PurgeServers($conn);
header('location: /admin/settings?s=We purged every server that was not active');
die();
} catch (Exception $ex) {
header('location: /admin/settings?e=Failed to run the purge');
die();
}
?>
89 changes: 89 additions & 0 deletions view/admin/settings/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,95 @@ class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
</form>
</div>
</div>
<div class="card mb-4">
<h5 class="card-header">Server Purge</h5>
<hr class="my-0">
<div class="card-body">
<form action="/admin/settings/purge" method="GET">
<div class="row">
<div class="form-group col-md-2">
<label class="control-label">Status</label>
<div>
<?php
if (SettingsManager::getSetting("server_purge") == 'true') {
?>
<select class="form-control" name="purge:enabled">
<option value="true">Enabled</option>
<option value="false">Disabled</option>
</select>
<?php
} else {
?>
<select class="form-control" name="purge:enabled">
<option value="false">Disabled</option>
<option value="true">Enabled</option>
</select>
<?php
}
?>

</div>
</div>
<?php
if (SettingsManager::getSetting("server_purge") == 'true') {
?>
<div class="form-group col-md-2">
<label class="control-label">Execute Purge</label><br>
<button type="button" type="button" data-bs-toggle="modal"
data-bs-target="#runpurge"
class="btn btn-danger waves-effect waves-light">Execute changes</a>
</div>
<?php } ?>
</div>
<br>
<div class="mt-2">
<button type="submit" name="update_settings"
class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
changes</button>
<a href="/admin" class="btn btn-label-secondary waves-effect">Cancel</a>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="runpurge" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg modal-simple modal-edit-user">
<div class="modal-content p-3 p-md-5">
<div class="modal-body">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
<div class="text-center mb-4">
<h3 class="mb-2">Woah, buddy, are you sure you want to run this?</h3>
<p class="form-check-label">If you chose to continue, we are going to delete
%servers% from
your dashboard and panel. Because they did not click the active button on
the server list from inside the dash. Please keep in mind that this function
will be executed after you give your users some time to mark their server as
active. This action can not be undone. Mythical systems do not take any
responsibility for you not being able to read and understand how those
functions work or how to use them! If you want to continue, please press
continue. MAKE SURE YOU READ THIS BEFORE DOING ANYTHING.
</p>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" required type="checkbox" id="ikwhatidoing"
name="ikwhatidoing" />
<label class="form-check-label" for="ikwhatidoing">
I know what this function does, and I have read the text!
</label>
</div>
</div>
<form method="POST" action="/admin/servers/purge" class="row g-3">
<div class="col-12 text-center">
<button type="submit" class="btn btn-danger me-sm-3 me-1">Continue</button>
<button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal"
aria-label="Close">Cancel </button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include(__DIR__ . '/../../components/footer.php') ?>
<div class="content-backdrop fade"></div>
Expand Down
26 changes: 26 additions & 0 deletions view/admin/settings/purge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include(__DIR__ . '/../../requirements/page.php');
include(__DIR__ . '/../../requirements/admin.php');
try {
if (isset($_GET['update_settings'])) {
$enable_purge = mysqli_real_escape_string($conn, $_GET['purge:enabled']);
if ($enable_purge == "true") {
$conn->query("UPDATE mythicaldash_servers SET `purge` = 'true'");
} else {
$conn->query("UPDATE mythicaldash_servers SET `purge` = 'false'");
}
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `server_purge` = '" . $enable_purge . "' WHERE `mythicaldash_settings`.`id` = 1;");

$conn->close();
header('location: /admin/settings?s=We updated the settings inside the database');
die();
} else {
header('location: /admin/settings');
die();
}
} catch (Exception $ex) {
header('location: /admin/settings?e=Failed to update the settings inside the database');
die();
}

?>
6 changes: 3 additions & 3 deletions view/auth/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
header('location: /auth/register?e=Password is not secure. Please choose a different one');
die();
}
$blocked_usernames = array("password", "1234", "qwerty", "letmein", "admin", "pass", "123456789", "dad", "mom", "kek", "fuck", "pussy", "plexed", "badsk", "username", "sex", "porn", "nudes", "nude", "ass", "hacker", "bigdick");
$blocked_usernames = array("password", "1234", "qwerty", "letmein", "admin", "pass", "123456789", "dad", "mom", "kek", "fuck", "pussy", "plexed", "badsk", "username", "Username", "Admin", "sex", "porn", "nudes", "nude", "ass", "hacker", "bigdick");
if (in_array($username, $blocked_usernames)) {
header('location: /auth/register?e=It looks like we blocked this username from being used. Please choose another username.');
die();
Expand Down Expand Up @@ -225,7 +225,7 @@
<div class="mb-3">
<label for="first_name" class="form-label">First name</label>
<input type="text" class="form-control" id="first_name" required name="first_name"
placeholder="Jhon" autofocus />
placeholder="John" autofocus />
</div>
<div class="mb-3">
<label for="last_name" class="form-label">Last name</label>
Expand All @@ -235,7 +235,7 @@
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" required name="username"
placeholder="jhondoe" autofocus />
placeholder="johndoe" autofocus />
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
Expand Down
9 changes: 9 additions & 0 deletions view/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ class="btn btn-primary btn-sm" data-trigger="hover" data-container="body"
data-toggle="popover" data-color="default" data-placement="left"
data-content="Open in the game panel"><i
class="fas fa-external-link-square-alt"></i></a>
<?php
if (SettingsManager::getSetting("server_purge") == "true") {
if ($serverinfo["purge"] == "true") {
?>
<a href="/server/active?id=<?= $serverinfo["id"] ?>" class="btn btn-warning btn-sm">Active</a>
<?php
}
}
?>
<a href="/server/edit?id=<?= $server["id"] ?>"
class="btn btn-primary btn-sm">Edit</a>
<a href="/server/delete?server=<?= $server["id"] ?>"><button type="button"
Expand Down
18 changes: 18 additions & 0 deletions view/server/active.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
include(__DIR__ . '/../requirements/page.php');
if (isset($_GET['id'])) {
$ownsServer = mysqli_query($conn, "SELECT * FROM mythicaldash_servers WHERE id = '" . mysqli_real_escape_string($conn, $_GET["id"]) . "' AND uid = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "'");
if ($ownsServer->num_rows == 0) {
header('location: /dashboard?e=Sorry but you don`t own this server');
$conn->close();
die();
}
$conn->query("UPDATE `mythicaldash_servers` SET `purge` = 'false' WHERE `mythicaldash_servers`.`id` = " . mysqli_real_escape_string($conn, $_GET['id']) . ";");
$conn->close();
header("location: /dashboard?s=We've updated your server settings. Your server will now skip the next purge.");
die();
} else {
header('location: /dashboard');
die();
}
?>
18 changes: 9 additions & 9 deletions view/server/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@
<div class="card-body">
<form method="POST">
<label for="name">Name:</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Name">
<input type="text" name="name" class="form-control" id="name" required placeholder="Name">
<br>
<?php
$locations = mysqli_query($conn, "SELECT * FROM mythicaldash_locations")->fetch_all(MYSQLI_ASSOC);
?>
<label for="location">Location:</label>
<select class="form-control" name="location" id="location">
<select class="form-control" name="location" required id="location">
<?php foreach ($locations as $location): ?>
<?php
$serversOnLoc = mysqli_query($conn, "SELECT * FROM mythicaldash_servers WHERE location='" . $location["id"] . "'")->fetch_all(MYSQLI_ASSOC);
Expand All @@ -271,7 +271,7 @@
<?php endif; ?>
<br>
<label for="egg">Egg:</label>
<select class="form-control" name="egg" id="egg">
<select class="form-control" name="egg" required id="egg">
<?php
$alrCategories = array();
$eggs = mysqli_query($conn, "SELECT * FROM mythicaldash_eggs")->fetch_all(MYSQLI_ASSOC);
Expand All @@ -294,22 +294,22 @@
</select>
<br>
<label for="memory">RAM:</label>
<input type="number" name="memory" class="form-control" id="ram" value="" placeholder="RAM">
<input type="number" name="memory" class="form-control" id="ram" value="" required placeholder="RAM">
<br>
<label for="disk">DISK:</label>
<input type="number" name="disk" class="form-control" id="disk" placeholder="DISK">
<input type="number" name="disk" class="form-control" id="disk" required placeholder="DISK">
<br>
<label for="cpu">CPU:</label>
<input type="number" name="cores" class="form-control" id="cpu" placeholder="CPU">
<input type="number" name="cores" class="form-control" id="cpu" required placeholder="CPU">
<br>
<label for="allocations">PORTS:</label>
<input type="number" name="ports" class="form-control" id="allocations" placeholder="PORTS">
<input type="number" name="ports" class="form-control" id="allocations" required placeholder="PORTS">
<br>
<label for="databases">DATABASES:</label>
<input type="number" name="databases" class="form-control" id="databases" placeholder="DATABASES">
<input type="number" name="databases" class="form-control" id="databases" required placeholder="DATABASES">
<br>
<label for="backups">BACKUPS:</label>
<input type="number" name="backups" class="form-control" id="backups" placeholder="BACKUPS">
<input type="number" name="backups" class="form-control" id="backups" required placeholder="BACKUPS">
<br>
<?= $csrf->input('create-server-form'); ?>
<button action="submit" name="createsv" class="btn btn-primary">Create</button>
Expand Down
Loading

0 comments on commit 7d386ee

Please sign in to comment.