-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangedisk.php
More file actions
155 lines (71 loc) · 2.92 KB
/
changedisk.php
File metadata and controls
155 lines (71 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
session_start();
include("global.php");
include("config.php");
include("plans.php");
if( checklogin() == true ) {
$user = $_SESSION['discord_user'];
} else {
notloggedin("You must be logged in.");
}
if( !isset($_GET['id']) || empty($_GET['id']) || !isset($_GET['newdisk']) || empty($_GET['newdisk']) ) {
header("Location: /");
die();
}
if(is_numeric($_GET['newdisk']) && $_GET['newdisk'] > 0 && $_GET['newdisk'] == round($_GET['newdisk'], 0)){
//pass
} else {
ShowError("Disk must be a number.");
}
// Check if user have permissions for the server ID, and if the server exists
$checkperms = $conn->query("SELECT * FROM servers WHERE owner_id='" . mysqli_real_escape_string($conn, $user->id) . "' AND pterodactyl_serverid=" . mysqli_real_escape_string($conn, $_GET['id']));
if( $checkperms->num_rows == 0 ) {
ShowError("You don't have permissions to control this server or this server doesn't exists.");
}
//Check if user exceeded his disk per server
if( intval($_GET['newdisk']) > ($maxdisk + $user_extra_disk) ) {
ShowError("Sorry, your max disk space per server is " . ($maxdisk + $user_extra_disk) . " MB");
}
// Get some server information, those are needed to update disk
$ch = curl_init("https://" . $ptero_domain . "/api/application/servers/" . $_GET['id']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer " . $ptero_key,
"Content-Type: application/json",
"Accept: Application/vnd.pterodactyl.v1+json"
));
$result = curl_exec($ch);
curl_close($ch);
$ServerAllocation = json_decode($result, true)['attributes']['allocation'];
$x_ServerCpu = json_decode($result, true)['attributes']['limits']['cpu'];
$x_ServerMemory = json_decode($result, true)['attributes']['limits']['memory'];
$x_ServerIO = json_decode($result, true)['attributes']['limits']['io'];
$x_ServerDbs = json_decode($result, true)['attributes']['feature_limits']['databases'];
$x_ServerAllocations = json_decode($result, true)['attributes']['feature_limits']['allocations'];
// Update server disk now
$ch = curl_init("https://" . $ptero_domain . "/api/application/servers/" . $_GET['id'] . "/build");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
"allocation" => $ServerAllocation,
"memory" => $x_ServerMemory,
"swap" => 0,
"disk" => intval($_GET['newdisk']),
"io" => $x_ServerIO,
"cpu" => $x_ServerCpu,
"feature_limits" => array(
"databases" => $x_ServerDbs,
"allocations" => $x_ServerAllocations
)
)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer " . $ptero_key,
"Content-Type: application/json",
"Accept: Application/vnd.pterodactyl.v1+json"
));
$result = curl_exec($ch);
curl_close($ch);
// Redirect user to homepage with success message
ShowSuccess("Changed disk space!");
?>