|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2016 Dane Everitt <[email protected]>. |
|
5
|
|
|
* |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
* in the Software without restriction, including without limitation the rights |
|
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
* furnished to do so, subject to the following conditions: |
|
12
|
|
|
* |
|
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
14
|
|
|
* copies or substantial portions of the Software. |
|
15
|
|
|
* |
|
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
* SOFTWARE. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Pterodactyl\Http\Controllers\Admin; |
|
26
|
|
|
|
|
27
|
|
|
use DB; |
|
28
|
|
|
use Log; |
|
29
|
|
|
use Alert; |
|
30
|
|
|
use Pterodactyl\Models; |
|
31
|
|
|
use Illuminate\Http\Request; |
|
32
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
|
33
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
34
|
|
|
use Pterodactyl\Repositories\ServerRepository; |
|
35
|
|
|
use Pterodactyl\Repositories\DatabaseRepository; |
|
36
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
|
37
|
|
|
|
|
38
|
|
|
class ServersController extends Controller |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Controller Constructor. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
|
|
// |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getIndex(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
$query = Models\Server::withTrashed()->select( |
|
|
|
|
|
|
51
|
|
|
'servers.*', |
|
52
|
|
|
'nodes.name as a_nodeName', |
|
53
|
|
|
'users.email as a_ownerEmail', |
|
54
|
|
|
'allocations.ip', |
|
55
|
|
|
'allocations.port', |
|
56
|
|
|
'allocations.ip_alias' |
|
57
|
|
|
)->join('nodes', 'servers.node', '=', 'nodes.id') |
|
58
|
|
|
->join('users', 'servers.owner', '=', 'users.id') |
|
59
|
|
|
->join('allocations', 'servers.allocation', '=', 'allocations.id'); |
|
60
|
|
|
|
|
61
|
|
|
if ($request->input('filter') && ! is_null($request->input('filter'))) { |
|
62
|
|
|
preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches); |
|
63
|
|
|
foreach ($matches[0] as $match) { |
|
64
|
|
|
$match = str_replace('"', '', $match); |
|
65
|
|
|
if (strpos($match, ':')) { |
|
66
|
|
|
list($field, $term) = explode(':', $match); |
|
67
|
|
|
if ($field === 'node') { |
|
68
|
|
|
$field = 'nodes.name'; |
|
69
|
|
|
} elseif ($field === 'owner') { |
|
70
|
|
|
$field = 'users.email'; |
|
71
|
|
|
} elseif (! strpos($field, '.')) { |
|
72
|
|
|
$field = 'servers.' . $field; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$query->orWhere($field, 'LIKE', '%' . $term . '%'); |
|
76
|
|
|
} else { |
|
77
|
|
|
$query->where('servers.name', 'LIKE', '%' . $match . '%'); |
|
78
|
|
|
$query->orWhere([ |
|
79
|
|
|
['servers.username', 'LIKE', '%' . $match . '%'], |
|
80
|
|
|
['users.email', 'LIKE', '%' . $match . '%'], |
|
81
|
|
|
['allocations.port', 'LIKE', '%' . $match . '%'], |
|
82
|
|
|
['allocations.ip', 'LIKE', '%' . $match . '%'], |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
try { |
|
89
|
|
|
$servers = $query->paginate(20); |
|
90
|
|
|
} catch (\Exception $ex) { |
|
91
|
|
|
Alert::warning('There was an error with the search parameters provided.'); |
|
92
|
|
|
$servers = Models\Server::withTrashed()->select( |
|
|
|
|
|
|
93
|
|
|
'servers.*', |
|
94
|
|
|
'nodes.name as a_nodeName', |
|
95
|
|
|
'users.email as a_ownerEmail', |
|
96
|
|
|
'allocations.ip', |
|
97
|
|
|
'allocations.port', |
|
98
|
|
|
'allocations.ip_alias' |
|
99
|
|
|
)->join('nodes', 'servers.node', '=', 'nodes.id') |
|
100
|
|
|
->join('users', 'servers.owner', '=', 'users.id') |
|
101
|
|
|
->join('allocations', 'servers.allocation', '=', 'allocations.id') |
|
102
|
|
|
->paginate(20); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return view('admin.servers.index', [ |
|
106
|
|
|
'servers' => $servers, |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getNew(Request $request) |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
return view('admin.servers.new', [ |
|
113
|
|
|
'locations' => Models\Location::all(), |
|
114
|
|
|
'services' => Models\Service::all(), |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function getView(Request $request, $id) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
$server = Models\Server::withTrashed()->select( |
|
|
|
|
|
|
121
|
|
|
'servers.*', |
|
122
|
|
|
'users.email as a_ownerEmail', |
|
123
|
|
|
'services.name as a_serviceName', |
|
124
|
|
|
DB::raw('IFNULL(service_options.executable, services.executable) as a_serviceExecutable'), |
|
125
|
|
|
'service_options.docker_image', |
|
126
|
|
|
'service_options.name as a_servceOptionName', |
|
127
|
|
|
'allocations.ip', |
|
128
|
|
|
'allocations.port', |
|
129
|
|
|
'allocations.ip_alias' |
|
130
|
|
|
)->join('nodes', 'servers.node', '=', 'nodes.id') |
|
131
|
|
|
->join('users', 'servers.owner', '=', 'users.id') |
|
132
|
|
|
->join('services', 'servers.service', '=', 'services.id') |
|
133
|
|
|
->join('service_options', 'servers.option', '=', 'service_options.id') |
|
134
|
|
|
->join('allocations', 'servers.allocation', '=', 'allocations.id') |
|
135
|
|
|
->where('servers.id', $id) |
|
136
|
|
|
->first(); |
|
137
|
|
|
|
|
138
|
|
|
if (! $server) { |
|
139
|
|
|
return abort(404); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return view('admin.servers.view', [ |
|
143
|
|
|
'server' => $server, |
|
144
|
|
|
'node' => Models\Node::select( |
|
145
|
|
|
'nodes.*', |
|
146
|
|
|
'locations.long as a_locationName' |
|
147
|
|
|
)->join('locations', 'nodes.location', '=', 'locations.id') |
|
148
|
|
|
->where('nodes.id', $server->node) |
|
149
|
|
|
->first(), |
|
150
|
|
|
'assigned' => Models\Allocation::where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), |
|
151
|
|
|
'unassigned' => Models\Allocation::where('node', $server->node)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), |
|
152
|
|
|
'startup' => Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue') |
|
153
|
|
|
->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id') |
|
154
|
|
|
->where('service_variables.option_id', $server->option) |
|
155
|
|
|
->where('server_variables.server_id', $server->id) |
|
156
|
|
|
->get(), |
|
157
|
|
|
'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port') |
|
158
|
|
|
->where('server_id', $server->id) |
|
159
|
|
|
->join('database_servers', 'database_servers.id', '=', 'databases.db_server') |
|
160
|
|
|
->get(), |
|
161
|
|
|
'db_servers' => Models\DatabaseServer::all(), |
|
162
|
|
|
]); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
View Code Duplication |
public function postNewServer(Request $request) |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
try { |
|
168
|
|
|
$server = new ServerRepository; |
|
169
|
|
|
$response = $server->create($request->all()); |
|
170
|
|
|
|
|
171
|
|
|
return redirect()->route('admin.servers.view', ['id' => $response]); |
|
172
|
|
|
} catch (DisplayValidationException $ex) { |
|
173
|
|
|
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
174
|
|
|
} catch (DisplayException $ex) { |
|
175
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
176
|
|
|
|
|
177
|
|
|
return redirect()->route('admin.servers.new')->withInput(); |
|
178
|
|
|
} catch (\Exception $ex) { |
|
179
|
|
|
Log::error($ex); |
|
180
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash(); |
|
181
|
|
|
|
|
182
|
|
|
return redirect()->route('admin.servers.new')->withInput(); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Returns a JSON tree of all avaliable nodes in a given location. |
|
188
|
|
|
* |
|
189
|
|
|
* @param \Illuminate\Http\Request $request |
|
190
|
|
|
* @return \Illuminate\Contracts\View\View |
|
191
|
|
|
*/ |
|
192
|
|
|
public function postNewServerGetNodes(Request $request) |
|
193
|
|
|
{ |
|
194
|
|
|
if (! $request->input('location')) { |
|
195
|
|
|
return response()->json([ |
|
196
|
|
|
'error' => 'Missing location in request.', |
|
197
|
|
|
], 500); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
return response()->json(Models\Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Returns a JSON tree of all avaliable IPs and Ports on a given node. |
|
205
|
|
|
* |
|
206
|
|
|
* @param \Illuminate\Http\Request $request |
|
207
|
|
|
* @return \Illuminate\Contracts\View\View |
|
208
|
|
|
*/ |
|
209
|
|
|
public function postNewServerGetIps(Request $request) |
|
210
|
|
|
{ |
|
211
|
|
|
if (! $request->input('node')) { |
|
212
|
|
|
return response()->json([ |
|
213
|
|
|
'error' => 'Missing node in request.', |
|
214
|
|
|
], 500); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
$ips = Models\Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get(); |
|
218
|
|
|
$listing = []; |
|
219
|
|
|
|
|
220
|
|
|
foreach ($ips as &$ip) { |
|
221
|
|
|
if (array_key_exists($ip->ip, $listing)) { |
|
222
|
|
|
$listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]); |
|
223
|
|
|
} else { |
|
224
|
|
|
$listing[$ip->ip] = [$ip->port]; |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
return response()->json($listing); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Returns a JSON tree of all avaliable options for a given service. |
|
233
|
|
|
* |
|
234
|
|
|
* @param \Illuminate\Http\Request $request |
|
235
|
|
|
* @return \Illuminate\Contracts\View\View |
|
236
|
|
|
*/ |
|
237
|
|
|
public function postNewServerServiceOptions(Request $request) |
|
238
|
|
|
{ |
|
239
|
|
|
if (! $request->input('service')) { |
|
240
|
|
|
return response()->json([ |
|
241
|
|
|
'error' => 'Missing service in request.', |
|
242
|
|
|
], 500); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$service = Models\Service::select('executable', 'startup')->where('id', $request->input('service'))->first(); |
|
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get()); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Returns a JSON tree of all avaliable variables for a given service option. |
|
252
|
|
|
* |
|
253
|
|
|
* @param \Illuminate\Http\Request $request |
|
254
|
|
|
* @return \Illuminate\Contracts\View\View |
|
255
|
|
|
*/ |
|
256
|
|
|
public function postNewServerServiceVariables(Request $request) |
|
257
|
|
|
{ |
|
258
|
|
|
if (! $request->input('option')) { |
|
259
|
|
|
return response()->json([ |
|
260
|
|
|
'error' => 'Missing option in request.', |
|
261
|
|
|
], 500); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
$option = Models\ServiceOptions::select( |
|
265
|
|
|
DB::raw('COALESCE(service_options.executable, services.executable) as executable'), |
|
266
|
|
|
DB::raw('COALESCE(service_options.startup, services.startup) as startup') |
|
267
|
|
|
)->leftJoin('services', 'services.id', '=', 'service_options.parent_service') |
|
268
|
|
|
->where('service_options.id', $request->input('option')) |
|
269
|
|
|
->first(); |
|
270
|
|
|
|
|
271
|
|
|
return response()->json([ |
|
272
|
|
|
'variables' => Models\ServiceVariables::where('option_id', $request->input('option'))->get(), |
|
273
|
|
|
'exec' => $option->executable, |
|
274
|
|
|
'startup' => $option->startup, |
|
275
|
|
|
]); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function postUpdateServerDetails(Request $request, $id) |
|
279
|
|
|
{ |
|
280
|
|
|
try { |
|
281
|
|
|
$server = new ServerRepository; |
|
282
|
|
|
$server->updateDetails($id, [ |
|
283
|
|
|
'owner' => $request->input('owner'), |
|
284
|
|
|
'name' => $request->input('name'), |
|
285
|
|
|
'reset_token' => ($request->input('reset_token', false) === 'on') ? true : false, |
|
|
|
|
|
|
286
|
|
|
]); |
|
287
|
|
|
|
|
288
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
|
289
|
|
|
} catch (DisplayValidationException $ex) { |
|
290
|
|
|
return redirect()->route('admin.servers.view', [ |
|
291
|
|
|
'id' => $id, |
|
292
|
|
|
'tab' => 'tab_details', |
|
293
|
|
|
])->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
294
|
|
|
} catch (DisplayException $ex) { |
|
295
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
296
|
|
|
} catch (\Exception $ex) { |
|
297
|
|
|
Log::error($ex); |
|
298
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server. Please try again.')->flash(); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
return redirect()->route('admin.servers.view', [ |
|
302
|
|
|
'id' => $id, |
|
303
|
|
|
'tab' => 'tab_details', |
|
304
|
|
|
])->withInput(); |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
View Code Duplication |
public function postUpdateContainerDetails(Request $request, $id) |
|
|
|
|
|
|
308
|
|
|
{ |
|
309
|
|
|
try { |
|
310
|
|
|
$server = new ServerRepository; |
|
311
|
|
|
$server->updateContainer($id, [ |
|
312
|
|
|
'image' => $request->input('docker_image'), |
|
313
|
|
|
]); |
|
314
|
|
|
Alert::success('Successfully updated this server\'s docker image.')->flash(); |
|
315
|
|
|
} catch (DisplayValidationException $ex) { |
|
316
|
|
|
return redirect()->route('admin.servers.view', [ |
|
317
|
|
|
'id' => $id, |
|
318
|
|
|
'tab' => 'tab_details', |
|
319
|
|
|
])->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
320
|
|
|
} catch (DisplayException $ex) { |
|
321
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
322
|
|
|
} catch (\Exception $ex) { |
|
323
|
|
|
Log::error($ex); |
|
324
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. Please try again.')->flash(); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return redirect()->route('admin.servers.view', [ |
|
328
|
|
|
'id' => $id, |
|
329
|
|
|
'tab' => 'tab_details', |
|
330
|
|
|
]); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
public function postUpdateServerToggleBuild(Request $request, $id) |
|
|
|
|
|
|
334
|
|
|
{ |
|
335
|
|
|
$server = Models\Server::findOrFail($id); |
|
336
|
|
|
$node = Models\Node::findOrFail($server->node); |
|
337
|
|
|
$client = Models\Node::guzzleRequest($server->node); |
|
338
|
|
|
|
|
339
|
|
|
try { |
|
340
|
|
|
$res = $client->request('POST', '/server/rebuild', [ |
|
|
|
|
|
|
341
|
|
|
'headers' => [ |
|
342
|
|
|
'X-Access-Server' => $server->uuid, |
|
343
|
|
|
'X-Access-Token' => $node->daemonSecret, |
|
344
|
|
|
], |
|
345
|
|
|
]); |
|
346
|
|
|
Alert::success('A rebuild has been queued successfully. It will run the next time this server is booted.')->flash(); |
|
347
|
|
|
} catch (\GuzzleHttp\Exception\TransferException $ex) { |
|
348
|
|
|
Log::warning($ex); |
|
349
|
|
|
Alert::danger('An error occured while attempting to toggle a rebuild.')->flash(); |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
return redirect()->route('admin.servers.view', [ |
|
353
|
|
|
'id' => $id, |
|
354
|
|
|
'tab' => 'tab_manage', |
|
355
|
|
|
]); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
public function postUpdateServerUpdateBuild(Request $request, $id) |
|
359
|
|
|
{ |
|
360
|
|
|
try { |
|
361
|
|
|
$server = new ServerRepository; |
|
362
|
|
|
$server->changeBuild($id, [ |
|
363
|
|
|
'default' => $request->input('default'), |
|
364
|
|
|
'add_additional' => $request->input('add_additional'), |
|
365
|
|
|
'remove_additional' => $request->input('remove_additional'), |
|
366
|
|
|
'memory' => $request->input('memory'), |
|
367
|
|
|
'swap' => $request->input('swap'), |
|
368
|
|
|
'io' => $request->input('io'), |
|
369
|
|
|
'cpu' => $request->input('cpu'), |
|
370
|
|
|
]); |
|
371
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
|
372
|
|
|
} catch (DisplayValidationException $ex) { |
|
373
|
|
|
return redirect()->route('admin.servers.view', [ |
|
374
|
|
|
'id' => $id, |
|
375
|
|
|
'tab' => 'tab_build', |
|
376
|
|
|
])->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
377
|
|
|
} catch (DisplayException $ex) { |
|
378
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
379
|
|
|
|
|
380
|
|
|
return redirect()->route('admin.servers.view', [ |
|
381
|
|
|
'id' => $id, |
|
382
|
|
|
'tab' => 'tab_build', |
|
383
|
|
|
]); |
|
384
|
|
|
} catch (\Exception $ex) { |
|
385
|
|
|
Log::error($ex); |
|
386
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
return redirect()->route('admin.servers.view', [ |
|
390
|
|
|
'id' => $id, |
|
391
|
|
|
'tab' => 'tab_build', |
|
392
|
|
|
]); |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
View Code Duplication |
public function deleteServer(Request $request, $id, $force = null) |
|
|
|
|
|
|
396
|
|
|
{ |
|
397
|
|
|
try { |
|
398
|
|
|
$server = new ServerRepository; |
|
399
|
|
|
$server->deleteServer($id, $force); |
|
400
|
|
|
Alert::success('Server has been marked for deletion on the system.')->flash(); |
|
401
|
|
|
|
|
402
|
|
|
return redirect()->route('admin.servers'); |
|
403
|
|
|
} catch (DisplayException $ex) { |
|
404
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
405
|
|
|
} catch (\Exception $ex) { |
|
406
|
|
|
Log::error($ex); |
|
407
|
|
|
Alert::danger('An unhandled exception occured while attemping to delete this server. Please try again.')->flash(); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
return redirect()->route('admin.servers.view', [ |
|
411
|
|
|
'id' => $id, |
|
412
|
|
|
'tab' => 'tab_delete', |
|
413
|
|
|
]); |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
View Code Duplication |
public function postToggleInstall(Request $request, $id) |
|
|
|
|
|
|
417
|
|
|
{ |
|
418
|
|
|
try { |
|
419
|
|
|
$server = new ServerRepository; |
|
420
|
|
|
$server->toggleInstall($id); |
|
421
|
|
|
Alert::success('Server status was successfully toggled.')->flash(); |
|
422
|
|
|
} catch (DisplayException $ex) { |
|
423
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
424
|
|
|
} catch (\Exception $ex) { |
|
425
|
|
|
Log::error($ex); |
|
426
|
|
|
Alert::danger('An unhandled exception occured while attemping to toggle this servers status.')->flash(); |
|
427
|
|
|
} finally { |
|
428
|
|
|
return redirect()->route('admin.servers.view', [ |
|
429
|
|
|
'id' => $id, |
|
430
|
|
|
'tab' => 'tab_manage', |
|
431
|
|
|
]); |
|
432
|
|
|
} |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
View Code Duplication |
public function postUpdateServerStartup(Request $request, $id) |
|
|
|
|
|
|
436
|
|
|
{ |
|
437
|
|
|
try { |
|
438
|
|
|
$server = new ServerRepository; |
|
439
|
|
|
$server->updateStartup($id, $request->except([ |
|
440
|
|
|
'_token', |
|
441
|
|
|
]), true); |
|
442
|
|
|
Alert::success('Server startup variables were successfully updated.')->flash(); |
|
443
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayException $e) { |
|
444
|
|
|
Alert::danger($e->getMessage())->flash(); |
|
445
|
|
|
} catch (\Exception $e) { |
|
446
|
|
|
Log::error($e); |
|
447
|
|
|
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash(); |
|
448
|
|
|
} finally { |
|
449
|
|
|
return redirect()->route('admin.servers.view', [ |
|
450
|
|
|
'id' => $id, |
|
451
|
|
|
'tab' => 'tab_startup', |
|
452
|
|
|
])->withInput(); |
|
453
|
|
|
} |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
View Code Duplication |
public function postDatabase(Request $request, $id) |
|
|
|
|
|
|
457
|
|
|
{ |
|
458
|
|
|
try { |
|
459
|
|
|
$repo = new DatabaseRepository; |
|
460
|
|
|
$repo->create($id, $request->except([ |
|
461
|
|
|
'_token', |
|
462
|
|
|
])); |
|
463
|
|
|
Alert::success('Added new database to this server.')->flash(); |
|
464
|
|
|
} catch (DisplayValidationException $ex) { |
|
465
|
|
|
return redirect()->route('admin.servers.view', [ |
|
466
|
|
|
'id' => $id, |
|
467
|
|
|
'tab' => 'tab_database', |
|
468
|
|
|
])->withInput()->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
469
|
|
|
} catch (\Exception $ex) { |
|
470
|
|
|
Log::error($ex); |
|
471
|
|
|
Alert::danger('An exception occured while attempting to add a new database for this server.')->flash(); |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
return redirect()->route('admin.servers.view', [ |
|
475
|
|
|
'id' => $id, |
|
476
|
|
|
'tab' => 'tab_database', |
|
477
|
|
|
])->withInput(); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
View Code Duplication |
public function postSuspendServer(Request $request, $id) |
|
|
|
|
|
|
481
|
|
|
{ |
|
482
|
|
|
try { |
|
483
|
|
|
$repo = new ServerRepository; |
|
484
|
|
|
$repo->suspend($id); |
|
485
|
|
|
Alert::success('Server has been suspended on the system. All running processes have been stopped and will not be startable until it is un-suspended.'); |
|
486
|
|
|
} catch (DisplayException $e) { |
|
487
|
|
|
Alert::danger($e->getMessage())->flash(); |
|
488
|
|
|
} catch (\Exception $e) { |
|
489
|
|
|
Log::error($e); |
|
490
|
|
|
Alert::danger('An unhandled exception occured while attemping to suspend this server. Please try again.')->flash(); |
|
491
|
|
|
} finally { |
|
492
|
|
|
return redirect()->route('admin.servers.view', [ |
|
493
|
|
|
'id' => $id, |
|
494
|
|
|
'tab' => 'tab_manage', |
|
495
|
|
|
]); |
|
496
|
|
|
} |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
View Code Duplication |
public function postUnsuspendServer(Request $request, $id) |
|
|
|
|
|
|
500
|
|
|
{ |
|
501
|
|
|
try { |
|
502
|
|
|
$repo = new ServerRepository; |
|
503
|
|
|
$repo->unsuspend($id); |
|
504
|
|
|
Alert::success('Server has been unsuspended on the system. Access has been re-enabled.'); |
|
505
|
|
|
} catch (DisplayException $e) { |
|
506
|
|
|
Alert::danger($e->getMessage())->flash(); |
|
507
|
|
|
} catch (\Exception $e) { |
|
508
|
|
|
Log::error($e); |
|
509
|
|
|
Alert::danger('An unhandled exception occured while attemping to unsuspend this server. Please try again.')->flash(); |
|
510
|
|
|
} finally { |
|
511
|
|
|
return redirect()->route('admin.servers.view', [ |
|
512
|
|
|
'id' => $id, |
|
513
|
|
|
'tab' => 'tab_manage', |
|
514
|
|
|
]); |
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
public function postQueuedDeletionHandler(Request $request, $id) |
|
519
|
|
|
{ |
|
520
|
|
|
try { |
|
521
|
|
|
$repo = new ServerRepository; |
|
522
|
|
|
if (! is_null($request->input('cancel'))) { |
|
523
|
|
|
$repo->cancelDeletion($id); |
|
524
|
|
|
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash(); |
|
525
|
|
|
|
|
526
|
|
|
return redirect()->route('admin.servers.view', $id); |
|
527
|
|
|
} elseif (! is_null($request->input('delete'))) { |
|
528
|
|
|
$repo->deleteNow($id); |
|
529
|
|
|
Alert::success('Server was successfully deleted from the system.')->flash(); |
|
530
|
|
|
|
|
531
|
|
|
return redirect()->route('admin.servers'); |
|
532
|
|
|
} elseif (! is_null($request->input('force_delete'))) { |
|
533
|
|
|
$repo->deleteNow($id, true); |
|
534
|
|
|
Alert::success('Server was successfully force deleted from the system.')->flash(); |
|
535
|
|
|
|
|
536
|
|
|
return redirect()->route('admin.servers'); |
|
537
|
|
|
} |
|
538
|
|
|
} catch (DisplayException $ex) { |
|
539
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
540
|
|
|
|
|
541
|
|
|
return redirect()->route('admin.servers.view', $id); |
|
542
|
|
|
} catch (\Exception $ex) { |
|
543
|
|
|
Log::error($ex); |
|
544
|
|
|
Alert::danger('An unhandled error occured while attempting to perform this action.')->flash(); |
|
545
|
|
|
|
|
546
|
|
|
return redirect()->route('admin.servers.view', $id); |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
} |
|
550
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.