Skip to content

Commit b6b44fd

Browse files
committed
PUSH
# v3.2.2-Nexus ## Bug Fixes - WebServers logs are not uploading if the file was empty! - Fixed server slot buy - Fixed a bug with permissions - Server max limit config into actions.php ## Enhancements - None ## Breaking Changes - None
1 parent 21938e9 commit b6b44fd

File tree

4 files changed

+133
-73
lines changed

4 files changed

+133
-73
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# v3.2.2-Nexus
2+
3+
## Bug Fixes
4+
5+
- WebServers logs are not uploading if the file was empty!
6+
- Fixed server slot buy
7+
- Fixed a bug with permissions
8+
- Server max limit config into actions.php
9+
10+
## Enhancements
11+
- None
12+
## Breaking Changes
13+
- None
14+
115
# v3.2.1-Nexus
216

317
## Bug Fixes

backend/app/Api/User/Server/actions.php

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -181,42 +181,32 @@
181181
'servers' => $available_resources[UserColumns::SERVER_LIMIT] - $resources['servers'],
182182
];
183183

184-
// Check if user has enough resources for the changes
185-
if ($memory > $free_resources['memory']) {
186-
$appInstance->BadRequest('You do not have enough memory resources', ['error_code' => 'MEMORY_INSUFFICIENT']);
187-
184+
// Check if user has enough resources for the changes (update endpoint)
185+
if ($memory > $free_resources['memory'] || ($resources['memory'] + $memory) > $available_resources[UserColumns::MEMORY_LIMIT]) {
186+
$appInstance->BadRequest('This change would exceed your maximum memory limit', ['error_code' => 'MAX_MEMORY_LIMIT', 'required' => $available_resources[UserColumns::MEMORY_LIMIT], 'current_usage' => $resources['memory'], 'attempted_to_add' => $memory]);
188187
return;
189188
}
190-
191-
if ($cpu > $free_resources['cpu']) {
192-
$appInstance->BadRequest('You do not have enough CPU resources', ['error_code' => 'CPU_INSUFFICIENT']);
193-
189+
if ($cpu > $free_resources['cpu'] || ($resources['cpu'] + $cpu) > $available_resources[UserColumns::CPU_LIMIT]) {
190+
$appInstance->BadRequest('This change would exceed your maximum CPU limit', ['error_code' => 'MAX_CPU_LIMIT', 'required' => $available_resources[UserColumns::CPU_LIMIT], 'current_usage' => $resources['cpu'], 'attempted_to_add' => $cpu]);
194191
return;
195192
}
196-
197-
if ($disk > $free_resources['disk']) {
198-
$appInstance->BadRequest('You do not have enough disk space resources', ['error_code' => 'DISK_INSUFFICIENT']);
199-
193+
if ($disk > $free_resources['disk'] || ($resources['disk'] + $disk) > $available_resources[UserColumns::DISK_LIMIT]) {
194+
$appInstance->BadRequest('This change would exceed your maximum disk limit', ['error_code' => 'MAX_DISK_LIMIT', 'required' => $available_resources[UserColumns::DISK_LIMIT], 'current_usage' => $resources['disk'], 'attempted_to_add' => $disk]);
200195
return;
201196
}
202-
203-
if ($databases > $free_resources['databases']) {
204-
$appInstance->BadRequest('You do not have enough database resources', ['error_code' => 'DATABASES_INSUFFICIENT']);
205-
197+
if ($databases > $free_resources['databases'] || ($resources['databases'] + $databases) > $available_resources[UserColumns::DATABASE_LIMIT]) {
198+
$appInstance->BadRequest('This change would exceed your maximum databases limit', ['error_code' => 'MAX_DATABASES_LIMIT', 'required' => $available_resources[UserColumns::DATABASE_LIMIT], 'current_usage' => $resources['databases'], 'attempted_to_add' => $databases]);
206199
return;
207200
}
208-
209-
if ($backups > $free_resources['backups']) {
210-
$appInstance->BadRequest('You do not have enough backup resources', ['error_code' => 'BACKUPS_INSUFFICIENT']);
211-
201+
if ($backups > $free_resources['backups'] || ($resources['backups'] + $backups) > $available_resources[UserColumns::BACKUP_LIMIT]) {
202+
$appInstance->BadRequest('This change would exceed your maximum backups limit', ['error_code' => 'MAX_BACKUPS_LIMIT', 'required' => $available_resources[UserColumns::BACKUP_LIMIT], 'current_usage' => $resources['backups'], 'attempted_to_add' => $backups]);
212203
return;
213204
}
214-
215-
if ($allocations > $free_resources['allocations']) {
216-
$appInstance->BadRequest('You do not have enough allocation resources', ['error_code' => 'ALLOCATIONS_INSUFFICIENT']);
217-
205+
if ($allocations > $free_resources['allocations'] || ($resources['allocations'] + $allocations) > $available_resources[UserColumns::ALLOCATION_LIMIT]) {
206+
$appInstance->BadRequest('This change would exceed your maximum allocations limit', ['error_code' => 'MAX_ALLOCATIONS_LIMIT', 'required' => $available_resources[UserColumns::ALLOCATION_LIMIT], 'current_usage' => $resources['allocations'], 'attempted_to_add' => $allocations]);
218207
return;
219208
}
209+
// No $servers check in update endpoint
220210

221211
// Update server details
222212
try {
@@ -681,45 +671,32 @@
681671
'servers' => $available_resources[UserColumns::SERVER_LIMIT],
682672
];
683673

684-
if ($free_resources['memory'] < $memory) {
685-
$appInstance->BadRequest('Not enough memory', ['error_code' => 'NOT_ENOUGH_MEMORY']);
686-
674+
if ($memory > $free_resources['memory'] || ($resources['memory'] + $memory) > $total_resources['memory']) {
675+
$appInstance->BadRequest('This server would exceed your maximum memory limit', ['error_code' => 'MAX_MEMORY_LIMIT', 'required' => $total_resources['memory'], 'current_usage' => $resources['memory'], 'attempted_to_add' => $memory]);
687676
return;
688677
}
689-
690-
if ($free_resources['disk'] < $disk) {
691-
$appInstance->BadRequest('Not enough disk space', ['error_code' => 'NOT_ENOUGH_DISK_SPACE']);
692-
678+
if ($cpu > $free_resources['cpu'] || ($resources['cpu'] + $cpu) > $total_resources['cpu']) {
679+
$appInstance->BadRequest('This server would exceed your maximum CPU limit', ['error_code' => 'MAX_CPU_LIMIT', 'required' => $total_resources['cpu'], 'current_usage' => $resources['cpu'], 'attempted_to_add' => $cpu]);
693680
return;
694681
}
695-
696-
if ($free_resources['cpu'] < $cpu) {
697-
$appInstance->BadRequest('Not enough CPU', ['error_code' => 'NOT_ENOUGH_CPU']);
698-
682+
if ($disk > $free_resources['disk'] || ($resources['disk'] + $disk) > $total_resources['disk']) {
683+
$appInstance->BadRequest('This server would exceed your maximum disk limit', ['error_code' => 'MAX_DISK_LIMIT', 'required' => $total_resources['disk'], 'current_usage' => $resources['disk'], 'attempted_to_add' => $disk]);
699684
return;
700685
}
701-
702-
if ($free_resources['databases'] < $databases) {
703-
$appInstance->BadRequest('Not enough databases', ['error_code' => 'NOT_ENOUGH_DATABASES']);
704-
686+
if ($databases > $free_resources['databases'] || ($resources['databases'] + $databases) > $total_resources['databases']) {
687+
$appInstance->BadRequest('This server would exceed your maximum databases limit', ['error_code' => 'MAX_DATABASES_LIMIT', 'required' => $total_resources['databases'], 'current_usage' => $resources['databases'], 'attempted_to_add' => $databases]);
705688
return;
706689
}
707-
708-
if ($free_resources['backups'] < $backups) {
709-
$appInstance->BadRequest('Not enough backups', ['error_code' => 'NOT_ENOUGH_BACKUPS']);
710-
690+
if ($backups > $free_resources['backups'] || ($resources['backups'] + $backups) > $total_resources['backups']) {
691+
$appInstance->BadRequest('This server would exceed your maximum backups limit', ['error_code' => 'MAX_BACKUPS_LIMIT', 'required' => $total_resources['backups'], 'current_usage' => $resources['backups'], 'attempted_to_add' => $backups]);
711692
return;
712693
}
713-
714-
if ($free_resources['allocations'] < $allocations) {
715-
$appInstance->BadRequest('Not enough allocations', ['error_code' => 'NOT_ENOUGH_ALLOCATIONS']);
716-
694+
if ($allocations > $free_resources['allocations'] || ($resources['allocations'] + $allocations) > $total_resources['allocations']) {
695+
$appInstance->BadRequest('This server would exceed your maximum allocations limit', ['error_code' => 'MAX_ALLOCATIONS_LIMIT', 'required' => $total_resources['allocations'], 'current_usage' => $resources['allocations'], 'attempted_to_add' => $allocations]);
717696
return;
718697
}
719-
720698
if ($free_resources['servers'] < 1) {
721699
$appInstance->BadRequest('Not enough servers', ['error_code' => 'NOT_ENOUGH_SERVERS']);
722-
723700
return;
724701
}
725702

backend/app/Api/User/Store/Purchase.php

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,85 +132,155 @@
132132
switch ($itemId) {
133133
case 'ram':
134134
$maxRam = $config->getSetting(ConfigInterface::MAX_RAM, 1024);
135-
if ($session->getInfo(UserColumns::MEMORY_LIMIT, false) >= $maxRam) {
135+
$currentRam = (int)$session->getInfo(UserColumns::MEMORY_LIMIT, false);
136+
$ramToAdd = isset($item['ram']) ? (int)$item['ram'] : 1024;
137+
if ($currentRam >= (int)$maxRam) {
136138
$appInstance->BadRequest('You have reached the maximum RAM limit', [
137139
'error_code' => 'MAX_RAM_LIMIT',
138140
'required' => $maxRam,
139-
'available' => $session->getInfo(UserColumns::MEMORY_LIMIT, false),
141+
'available' => $currentRam,
142+
]);
143+
return;
144+
}
145+
if (($currentRam + $ramToAdd) > (int)$maxRam) {
146+
$appInstance->BadRequest('This purchase would exceed your maximum RAM limit', [
147+
'error_code' => 'MAX_RAM_LIMIT',
148+
'required' => $maxRam,
149+
'available' => $currentRam,
150+
'attempted_to_add' => $ramToAdd,
140151
]);
141-
142152
return;
143153
}
144154
break;
145155
case 'disk':
146156
$maxDisk = $config->getSetting(ConfigInterface::MAX_DISK, 1024);
147-
if ($session->getInfo(UserColumns::DISK_LIMIT, false) >= $maxDisk) {
157+
$currentDisk = (int)$session->getInfo(UserColumns::DISK_LIMIT, false);
158+
$diskToAdd = isset($item['disk']) ? (int)$item['disk'] : 1024;
159+
if ($currentDisk >= (int)$maxDisk) {
148160
$appInstance->BadRequest('You have reached the maximum disk limit', [
149161
'error_code' => 'MAX_DISK_LIMIT',
150162
'required' => $maxDisk,
151-
'available' => $session->getInfo(UserColumns::DISK_LIMIT, false),
163+
'available' => $currentDisk,
164+
]);
165+
return;
166+
}
167+
if (($currentDisk + $diskToAdd) > (int)$maxDisk) {
168+
$appInstance->BadRequest('This purchase would exceed your maximum disk limit', [
169+
'error_code' => 'MAX_DISK_LIMIT',
170+
'required' => $maxDisk,
171+
'available' => $currentDisk,
172+
'attempted_to_add' => $diskToAdd,
152173
]);
153-
154174
return;
155175
}
156176
break;
157177
case 'cpu':
158178
$maxCpu = $config->getSetting(ConfigInterface::MAX_CPU, 100);
159-
if ($session->getInfo(UserColumns::CPU_LIMIT, false) >= $maxCpu) {
179+
$currentCpu = (int)$session->getInfo(UserColumns::CPU_LIMIT, false);
180+
$cpuToAdd = isset($item['cpu']) ? (int)$item['cpu'] : 100;
181+
if ($currentCpu >= (int)$maxCpu) {
160182
$appInstance->BadRequest('You have reached the maximum CPU limit', [
161183
'error_code' => 'MAX_CPU_LIMIT',
162184
'required' => $maxCpu,
163-
'available' => $session->getInfo(UserColumns::CPU_LIMIT, false),
185+
'available' => $currentCpu,
186+
]);
187+
return;
188+
}
189+
if (($currentCpu + $cpuToAdd) > (int)$maxCpu) {
190+
$appInstance->BadRequest('This purchase would exceed your maximum CPU limit', [
191+
'error_code' => 'MAX_CPU_LIMIT',
192+
'required' => $maxCpu,
193+
'available' => $currentCpu,
194+
'attempted_to_add' => $cpuToAdd,
164195
]);
165-
166196
return;
167197
}
168198
break;
169199
case 'server_slot':
170-
$maxServerSlots = $config->getSetting(ConfigInterface::MAX_SERVER_SLOTS, 1);
171-
if ($session->getInfo(UserColumns::SERVER_LIMIT, false) >= $maxServerSlots) {
200+
$maxServerSlots = (int)$config->getSetting(ConfigInterface::MAX_SERVER_SLOTS, 1);
201+
$currentSlots = (int)$session->getInfo(UserColumns::SERVER_LIMIT, false);
202+
if ($currentSlots >= (int)$maxServerSlots) {
172203
$appInstance->BadRequest('You have reached the maximum server slots limit', [
173204
'error_code' => 'MAX_SERVER_SLOTS_LIMIT',
174205
'required' => $maxServerSlots,
175-
'available' => $session->getInfo(UserColumns::SERVER_LIMIT, false),
206+
'available' => $currentSlots,
207+
]);
208+
return;
209+
}
210+
$slotsToAdd = isset($item['slots']) ? (int)$item['slots'] : 1;
211+
if (($currentSlots + $slotsToAdd) > (int)$maxServerSlots) {
212+
$appInstance->BadRequest('This purchase would exceed your maximum server slots limit', [
213+
'error_code' => 'MAX_SERVER_SLOTS_LIMIT',
214+
'required' => $maxServerSlots,
215+
'available' => $currentSlots,
216+
'attempted_to_add' => $slotsToAdd,
176217
]);
177-
178218
return;
179219
}
180220
break;
181221
case 'server_backup':
182222
$maxBackups = $config->getSetting(ConfigInterface::MAX_BACKUPS, 5);
183-
if ($session->getInfo(UserColumns::BACKUP_LIMIT, false) >= $maxBackups) {
223+
$currentBackups = (int)$session->getInfo(UserColumns::BACKUP_LIMIT, false);
224+
$backupsToAdd = isset($item['backups']) ? (int)$item['backups'] : 1;
225+
if ($currentBackups >= (int)$maxBackups) {
184226
$appInstance->BadRequest('You have reached the maximum backups limit', [
185227
'error_code' => 'MAX_BACKUPS_LIMIT',
186228
'required' => $maxBackups,
187-
'available' => $session->getInfo(UserColumns::BACKUP_LIMIT, false),
229+
'available' => $currentBackups,
230+
]);
231+
return;
232+
}
233+
if (($currentBackups + $backupsToAdd) > (int)$maxBackups) {
234+
$appInstance->BadRequest('This purchase would exceed your maximum backups limit', [
235+
'error_code' => 'MAX_BACKUPS_LIMIT',
236+
'required' => $maxBackups,
237+
'available' => $currentBackups,
238+
'attempted_to_add' => $backupsToAdd,
188239
]);
189-
190240
return;
191241
}
192242
break;
193243
case 'server_allocation':
194244
$maxPorts = $config->getSetting(ConfigInterface::MAX_PORTS, 2);
195-
if ($session->getInfo(UserColumns::ALLOCATION_LIMIT, false) >= $maxPorts) {
245+
$currentPorts = (int)$session->getInfo(UserColumns::ALLOCATION_LIMIT, false);
246+
$portsToAdd = isset($item['ports']) ? (int)$item['ports'] : 1;
247+
if ($currentPorts >= (int)$maxPorts) {
196248
$appInstance->BadRequest('You have reached the maximum ports limit', [
197249
'error_code' => 'MAX_PORTS_LIMIT',
198250
'required' => $maxPorts,
199-
'available' => $session->getInfo(UserColumns::ALLOCATION_LIMIT, false),
251+
'available' => $currentPorts,
252+
]);
253+
return;
254+
}
255+
if (($currentPorts + $portsToAdd) > (int)$maxPorts) {
256+
$appInstance->BadRequest('This purchase would exceed your maximum ports limit', [
257+
'error_code' => 'MAX_PORTS_LIMIT',
258+
'required' => $maxPorts,
259+
'available' => $currentPorts,
260+
'attempted_to_add' => $portsToAdd,
200261
]);
201-
202262
return;
203263
}
204264
break;
205265
case 'server_database':
206266
$maxDatabases = $config->getSetting(ConfigInterface::MAX_DATABASES, 1);
207-
if ($session->getInfo(UserColumns::DATABASE_LIMIT, false) >= $maxDatabases) {
267+
$currentDatabases = (int)$session->getInfo(UserColumns::DATABASE_LIMIT, false);
268+
$databasesToAdd = isset($item['databases']) ? (int)$item['databases'] : 1;
269+
if ($currentDatabases >= (int)$maxDatabases) {
208270
$appInstance->BadRequest('You have reached the maximum databases limit', [
209271
'error_code' => 'MAX_DATABASES_LIMIT',
210272
'required' => $maxDatabases,
211-
'available' => $session->getInfo(UserColumns::DATABASE_LIMIT, false),
273+
'available' => $currentDatabases,
274+
]);
275+
return;
276+
}
277+
if (($currentDatabases + $databasesToAdd) > (int)$maxDatabases) {
278+
$appInstance->BadRequest('This purchase would exceed your maximum databases limit', [
279+
'error_code' => 'MAX_DATABASES_LIMIT',
280+
'required' => $maxDatabases,
281+
'available' => $currentDatabases,
282+
'attempted_to_add' => $databasesToAdd,
212283
]);
213-
214284
return;
215285
}
216286
break;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
chown -R www-data:www-data /var/www/mythicaldash-v3/
2-
chmod -R 777 /var/www/mythicaldash-v3/
1+
chown -R www-data:www-data /var/www/mythicaldash-v3/*

0 commit comments

Comments
 (0)