-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_ram.php
More file actions
171 lines (78 loc) · 3.03 KB
/
c_ram.php
File metadata and controls
171 lines (78 loc) · 3.03 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?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( empty($_POST) ) {
header("Location: /");
die();
}
$NewBalanceWillBe = 0;
foreach( $_POST as $stuff => $val ) {
$NewBalanceWillBe = $NewBalanceWillBe + intval($val);
}
if( $NewBalanceWillBe > ($rambalance + $user_extra_ram) ) {
ShowError("Sorry, your RAM balance will be " . $NewBalanceWillBe . " MB after this change, but your maximum RAM balance is " . ($rambalance + $user_extra_ram) . " MB");
}
foreach( $_POST as $stuff => $val ) {
if(is_numeric($val) && $val > 0 && $val == round($val, 0)){
//pass
} else {
ShowError("RAM must be a number.");
}
if( $val < 128 ) {
ShowError("The minimum memory for each server is 128 MB.");
}
// 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, $stuff));
if( $checkperms->num_rows == 0 ) {
ShowError("You don't have permissions to control one of these servers or these server doesn't exists.");
}
// Get some server information, those are needed to update RAM
$ch = curl_init("https://" . $ptero_domain . "/api/application/servers/" . $stuff);
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_ServerDisk = json_decode($result, true)['attributes']['limits']['disk'];
$x_ServerCpu = json_decode($result, true)['attributes']['limits']['cpu'];
$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 RAM now
$ch = curl_init("https://" . $ptero_domain . "/api/application/servers/" . $stuff . "/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" => intval($val),
"swap" => 0,
"disk" => $x_ServerDisk,
"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);
}
ShowSuccess("Changed RAM!");
?>