1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 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 Log; |
28
|
|
|
use Alert; |
29
|
|
|
use Javascript; |
30
|
|
|
use Pterodactyl\Models; |
31
|
|
|
use Illuminate\Http\Request; |
32
|
|
|
use GuzzleHttp\Exception\TransferException; |
33
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
34
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
35
|
|
|
use Pterodactyl\Repositories\ServerRepository; |
36
|
|
|
use Pterodactyl\Repositories\DatabaseRepository; |
37
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
38
|
|
|
|
39
|
|
|
class ServersController extends Controller |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* Display the index page with all servers currently on the system. |
43
|
|
|
* |
44
|
|
|
* @param Request $request |
45
|
|
|
* @return \Illuminate\View\View |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function index(Request $request) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$servers = Models\Server::withTrashed()->with( |
|
|
|
|
50
|
|
|
'node', 'user', 'allocation' |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
if (! is_null($request->input('query'))) { |
54
|
|
|
$servers->search($request->input('query')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return view('admin.servers.index', [ |
|
|
|
|
58
|
|
|
'servers' => $servers->paginate(25), |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Display create new server page. |
64
|
|
|
* |
65
|
|
|
* @param Request $request |
66
|
|
|
* @return \Illuminate\View\View |
67
|
|
|
*/ |
68
|
|
|
public function new(Request $request) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$services = Models\Service::with('options.packs', 'options.variables')->get(); |
|
|
|
|
71
|
|
|
Javascript::put([ |
72
|
|
|
'services' => $services->map(function ($item) { |
73
|
|
|
return array_merge($item->toArray(), [ |
74
|
|
|
'options' => $item->options->keyBy('id')->toArray(), |
75
|
|
|
]); |
76
|
|
|
})->keyBy('id'), |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
return view('admin.servers.new', [ |
|
|
|
|
80
|
|
|
'locations' => Models\Location::all(), |
81
|
|
|
'services' => $services, |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Create server controller method. |
87
|
|
|
* |
88
|
|
|
* @param Request $request |
89
|
|
|
* @return \Illuminate\Response\RedirectResponse |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function create(Request $request) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
try { |
94
|
|
|
$repo = new ServerRepository; |
95
|
|
|
$server = $repo->create($request->except('_token')); |
96
|
|
|
|
97
|
|
|
return redirect()->route('admin.servers.view', $server->id); |
|
|
|
|
98
|
|
|
} catch (DisplayValidationException $ex) { |
99
|
|
|
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
100
|
|
|
} catch (DisplayException $ex) { |
101
|
|
|
Alert::danger($ex->getMessage())->flash(); |
102
|
|
|
} catch (\Exception $ex) { |
103
|
|
|
Log::error($ex); |
104
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return redirect()->route('admin.servers.new')->withInput(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns a tree of all avaliable nodes in a given location. |
112
|
|
|
* |
113
|
|
|
* @param Request $request |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function newServerNodes(Request $request) |
117
|
|
|
{ |
118
|
|
|
$nodes = Models\Node::with('allocations')->where('location_id', $request->input('location'))->get(); |
|
|
|
|
119
|
|
|
|
120
|
|
|
return $nodes->map(function ($item) { |
121
|
|
|
$filtered = $item->allocations->where('server_id', null)->map(function ($map) { |
122
|
|
|
return collect($map)->only(['id', 'ip', 'port']); |
123
|
|
|
}); |
124
|
|
|
|
125
|
|
|
$item->ports = $filtered->map(function ($map) use ($item) { |
126
|
|
|
return [ |
127
|
|
|
'id' => $map['id'], |
128
|
|
|
'text' => $map['ip'] . ':' . $map['port'], |
129
|
|
|
]; |
130
|
|
|
})->values(); |
131
|
|
|
|
132
|
|
|
return [ |
133
|
|
|
'id' => $item->id, |
134
|
|
|
'text' => $item->name, |
135
|
|
|
'allocations' => $item->ports, |
136
|
|
|
]; |
137
|
|
|
})->values(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Display the index when viewing a specific server. |
142
|
|
|
* |
143
|
|
|
* @param Request $request |
144
|
|
|
* @param int $id |
145
|
|
|
* @return \Illuminate\View\View |
146
|
|
|
*/ |
147
|
|
|
public function viewIndex(Request $request, $id) |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
return view('admin.servers.view.index', ['server' => Models\Server::withTrashed()->findOrFail($id)]); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Display the details page when viewing a specific server. |
154
|
|
|
* |
155
|
|
|
* @param Request $request |
156
|
|
|
* @param int $id |
157
|
|
|
* @return \Illuminate\View\View |
158
|
|
|
*/ |
159
|
|
|
public function viewDetails(Request $request, $id) |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
$server = Models\Server::where('installed', 1)->findOrFail($id); |
162
|
|
|
|
163
|
|
|
return view('admin.servers.view.details', ['server' => $server]); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Display the build details page when viewing a specific server. |
168
|
|
|
* |
169
|
|
|
* @param Request $request |
170
|
|
|
* @param int $id |
171
|
|
|
* @return \Illuminate\View\View |
172
|
|
|
*/ |
173
|
|
|
public function viewBuild(Request $request, $id) |
|
|
|
|
174
|
|
|
{ |
175
|
|
|
$server = Models\Server::where('installed', 1)->with('node.allocations')->findOrFail($id); |
176
|
|
|
|
177
|
|
|
return view('admin.servers.view.build', [ |
|
|
|
|
178
|
|
|
'server' => $server, |
179
|
|
|
'assigned' => $server->node->allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'), |
180
|
|
|
'unassigned' => $server->node->allocations->where('server_id', null)->sortBy('port')->sortBy('ip'), |
181
|
|
|
]); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Display startup configuration page for a server. |
186
|
|
|
* |
187
|
|
|
* @param Request $request |
188
|
|
|
* @param int $id |
189
|
|
|
* @return \Illuminate\View\View |
190
|
|
|
*/ |
191
|
|
|
public function viewStartup(Request $request, $id) |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
$server = Models\Server::where('installed', 1)->with('option.variables', 'variables')->findOrFail($id); |
194
|
|
|
$server->option->variables->transform(function ($item, $key) use ($server) { |
|
|
|
|
195
|
|
|
$item->server_value = $server->variables->where('variable_id', $item->id)->pluck('variable_value')->first(); |
196
|
|
|
|
197
|
|
|
return $item; |
198
|
|
|
}); |
199
|
|
|
|
200
|
|
|
return view('admin.servers.view.startup', ['server' => $server]); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Display the database management page for a specific server. |
205
|
|
|
* |
206
|
|
|
* @param Request $request |
207
|
|
|
* @param int $id |
208
|
|
|
* @return \Illuminate\View\View |
209
|
|
|
*/ |
210
|
|
|
public function viewDatabase(Request $request, $id) |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$server = Models\Server::where('installed', 1)->with('databases.host')->findOrFail($id); |
213
|
|
|
|
214
|
|
|
return view('admin.servers.view.database', [ |
|
|
|
|
215
|
|
|
'hosts' => Models\DatabaseServer::all(), |
216
|
|
|
'server' => $server, |
217
|
|
|
]); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Display the management page when viewing a specific server. |
222
|
|
|
* |
223
|
|
|
* @param Request $request |
224
|
|
|
* @param int $id |
225
|
|
|
* @return \Illuminate\View\View |
226
|
|
|
*/ |
227
|
|
|
public function viewManage(Request $request, $id) |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
return view('admin.servers.view.manage', ['server' => Models\Server::findOrFail($id)]); |
|
|
|
|
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Display the deletion page for a server. |
234
|
|
|
* |
235
|
|
|
* @param Request $request |
236
|
|
|
* @param int $id |
237
|
|
|
* @return \Illuminate\View\View |
238
|
|
|
*/ |
239
|
|
|
public function viewDelete(Request $request, $id) |
|
|
|
|
240
|
|
|
{ |
241
|
|
|
return view('admin.servers.view.delete', ['server' => Models\Server::withTrashed()->findOrFail($id)]); |
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Update the details for a server. |
246
|
|
|
* |
247
|
|
|
* @param Request $request |
248
|
|
|
* @param int $id |
249
|
|
|
* @return \Illuminate\Response\RedirectResponse |
250
|
|
|
*/ |
251
|
|
|
public function setDetails(Request $request, $id) |
252
|
|
|
{ |
253
|
|
|
$repo = new ServerRepository; |
254
|
|
|
try { |
255
|
|
|
$repo->updateDetails($id, $request->intersect([ |
256
|
|
|
'owner_id', 'name', 'reset_token', |
257
|
|
|
])); |
258
|
|
|
|
259
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
260
|
|
|
} catch (DisplayValidationException $ex) { |
261
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
262
|
|
|
} catch (DisplayException $ex) { |
263
|
|
|
Alert::danger($ex->getMessage())->flash(); |
264
|
|
|
} catch (\Exception $ex) { |
265
|
|
|
Log::error($ex); |
266
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server. This error has been logged.')->flash(); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withInput(); |
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Set the new docker container for a server. |
274
|
|
|
* |
275
|
|
|
* @param Request $request |
276
|
|
|
* @param int $id |
277
|
|
|
* @return \Illuminate\Response\RedirectResponse |
278
|
|
|
*/ |
279
|
|
View Code Duplication |
public function setContainer(Request $request, $id) |
|
|
|
|
280
|
|
|
{ |
281
|
|
|
$repo = new ServerRepository; |
282
|
|
|
|
283
|
|
|
try { |
284
|
|
|
$repo->updateContainer($id, $request->intersect('docker_image')); |
285
|
|
|
|
286
|
|
|
Alert::success('Successfully updated this server\'s docker image.')->flash(); |
287
|
|
|
} catch (DisplayValidationException $ex) { |
288
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
289
|
|
|
} catch (DisplayException $ex) { |
290
|
|
|
Alert::danger($ex->getMessage())->flash(); |
291
|
|
|
} catch (\Exception $ex) { |
292
|
|
|
Log::error($ex); |
293
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. This error has been logged.')->flash(); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
return redirect()->route('admin.servers.view.details', $id); |
|
|
|
|
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Toggles the install status for a server. |
301
|
|
|
* |
302
|
|
|
* @param Request $request |
303
|
|
|
* @param int $id |
304
|
|
|
* @return \Illuminate\Response\RedirectResponse |
305
|
|
|
*/ |
306
|
|
View Code Duplication |
public function toggleInstall(Request $request, $id) |
|
|
|
|
307
|
|
|
{ |
308
|
|
|
$repo = new ServerRepository; |
309
|
|
|
try { |
310
|
|
|
$repo->toggleInstall($id); |
311
|
|
|
|
312
|
|
|
Alert::success('Server install status was successfully toggled.')->flash(); |
313
|
|
|
} catch (DisplayException $ex) { |
314
|
|
|
Alert::danger($ex->getMessage())->flash(); |
315
|
|
|
} catch (\Exception $ex) { |
316
|
|
|
Log::error($ex); |
317
|
|
|
Alert::danger('An unhandled exception occured while attemping to toggle this servers status. This error has been logged.')->flash(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Setup a server to have a container rebuild. |
325
|
|
|
* |
326
|
|
|
* @param Request $request |
327
|
|
|
* @param int $id |
328
|
|
|
* @return \Illuminate\Response\RedirectResponse |
329
|
|
|
*/ |
330
|
|
|
public function rebuildContainer(Request $request, $id) |
|
|
|
|
331
|
|
|
{ |
332
|
|
|
$server = Models\Server::with('node')->findOrFail($id); |
|
|
|
|
333
|
|
|
|
334
|
|
|
try { |
335
|
|
|
$server->node->guzzleClient([ |
336
|
|
|
'X-Access-Server' => $server->uuid, |
337
|
|
|
'X-Access-Token' => $server->node->daemonSecret, |
338
|
|
|
])->request('POST', '/server/rebuild'); |
339
|
|
|
|
340
|
|
|
Alert::success('A rebuild has been queued successfully. It will run the next time this server is booted.')->flash(); |
341
|
|
|
} catch (TransferException $ex) { |
342
|
|
|
Log::warning($ex); |
343
|
|
|
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')->flash(); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Manage the suspension status for a server. |
351
|
|
|
* |
352
|
|
|
* @param Request $request |
353
|
|
|
* @param int $id |
354
|
|
|
* @return \Illuminate\Response\RedirectResponse |
355
|
|
|
*/ |
356
|
|
|
public function manageSuspension(Request $request, $id) |
357
|
|
|
{ |
358
|
|
|
$repo = new ServerRepository; |
359
|
|
|
$action = $request->input('action'); |
360
|
|
|
|
361
|
|
|
if (! in_array($action, ['suspend', 'unsuspend'])) { |
362
|
|
|
Alert::danger('Invalid action was passed to function.')->flash(); |
363
|
|
|
|
364
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
try { |
368
|
|
|
$repo->$action($id); |
369
|
|
|
|
370
|
|
|
Alert::success('Server has been ' . $action . 'ed.'); |
371
|
|
|
} catch (DisplayException $ex) { |
372
|
|
|
Alert::danger($ex->getMessage())->flash(); |
373
|
|
|
} catch (\Exception $ex) { |
374
|
|
|
Log::error($ex); |
375
|
|
|
Alert::danger('An unhandled exception occured while attemping to ' . $action . ' this server. This error has been logged.')->flash(); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Update the build configuration for a server. |
383
|
|
|
* |
384
|
|
|
* @param Request $request |
385
|
|
|
* @param int $id |
386
|
|
|
* @return \Illuminate\Response\RedirectResponse |
387
|
|
|
*/ |
388
|
|
View Code Duplication |
public function updateBuild(Request $request, $id) |
|
|
|
|
389
|
|
|
{ |
390
|
|
|
$repo = new ServerRepository; |
391
|
|
|
|
392
|
|
|
try { |
393
|
|
|
$repo->changeBuild($id, $request->intersect([ |
394
|
|
|
'allocation_id', 'add_allocations', 'remove_allocations', |
395
|
|
|
'memory', 'swap', 'io', 'cpu', |
396
|
|
|
])); |
397
|
|
|
|
398
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
399
|
|
|
} catch (DisplayValidationException $ex) { |
400
|
|
|
return redirect()->route('admin.servers.view.build', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
401
|
|
|
} catch (DisplayException $ex) { |
402
|
|
|
Alert::danger($ex->getMessage())->flash(); |
403
|
|
|
} catch (\Exception $ex) { |
404
|
|
|
Log::error($ex); |
405
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. This error has been logged.')->flash(); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
return redirect()->route('admin.servers.view.build', $id); |
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Start the server deletion process. |
413
|
|
|
* |
414
|
|
|
* @param Request $request |
415
|
|
|
* @param int $id |
416
|
|
|
* @return \Illuminate\Response\RedirectResponse |
417
|
|
|
*/ |
418
|
|
View Code Duplication |
public function delete(Request $request, $id) |
|
|
|
|
419
|
|
|
{ |
420
|
|
|
$repo = new ServerRepository; |
421
|
|
|
|
422
|
|
|
try { |
423
|
|
|
$repo->queueDeletion($id, ($request->input('is_force') > 0)); |
424
|
|
|
Alert::success('Server has been marked for deletion on the system.')->flash(); |
425
|
|
|
} catch (DisplayException $ex) { |
426
|
|
|
Alert::danger($ex->getMessage())->flash(); |
427
|
|
|
} catch (\Exception $ex) { |
428
|
|
|
Log::error($ex); |
429
|
|
|
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash(); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
return redirect()->route('admin.servers.view.delete', $id); |
|
|
|
|
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Cancels a pending server deletion request. |
437
|
|
|
* |
438
|
|
|
* @param Request $request |
439
|
|
|
* @param int $id |
440
|
|
|
* @return \Illuminate\Response\RedirectResponse |
441
|
|
|
*/ |
442
|
|
|
public function cancelDeletion(Request $request, $id) |
|
|
|
|
443
|
|
|
{ |
444
|
|
|
$repo = new ServerRepository; |
445
|
|
|
|
446
|
|
|
$repo->cancelDeletion($id); |
447
|
|
|
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash(); |
448
|
|
|
|
449
|
|
|
return redirect()->route('admin.servers.view.delete', $id); |
|
|
|
|
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Skips the queue and continues the server deletion process. |
454
|
|
|
* |
455
|
|
|
* @param Request $request |
456
|
|
|
* @param int $id |
457
|
|
|
* @return \Illuminate\Response\RedirectResponse |
458
|
|
|
*/ |
459
|
|
|
public function continueDeletion(Request $request, $id, $method) |
|
|
|
|
460
|
|
|
{ |
461
|
|
|
$repo = new ServerRepository; |
462
|
|
|
|
463
|
|
|
try { |
464
|
|
|
$repo->delete($id, (isset($method) && $method === 'force')); |
465
|
|
|
Alert::success('Server was successfully deleted from the system.')->flash(); |
466
|
|
|
|
467
|
|
|
return redirect()->route('admin.servers'); |
468
|
|
|
} catch (DisplayException $ex) { |
469
|
|
|
Alert::danger($ex->getMessage())->flash(); |
470
|
|
|
} catch (TransferException $ex) { |
471
|
|
|
Log::warning($ex); |
472
|
|
|
Alert::danger('A TransferException occurred while attempting to delete this server from the daemon, please ensure it is running. This error has been logged.')->flash(); |
473
|
|
|
} catch (\Exception $ex) { |
474
|
|
|
Log::error($ex); |
475
|
|
|
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash(); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
return redirect()->route('admin.servers.view.delete', $id); |
|
|
|
|
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Update the startup command as well as variables. |
483
|
|
|
* |
484
|
|
|
* @param Request $request |
485
|
|
|
* @param int $id |
486
|
|
|
* @return \Illuminate\Response\RedirectResponse |
487
|
|
|
*/ |
488
|
|
|
public function saveStartup(Request $request, $id) |
489
|
|
|
{ |
490
|
|
|
$repo = new ServerRepository; |
491
|
|
|
|
492
|
|
|
try { |
493
|
|
|
$repo->updateStartup($id, $request->except('_token'), true); |
494
|
|
|
|
495
|
|
|
Alert::success('Startup variables were successfully modified and assigned for this server.')->flash(); |
496
|
|
|
} catch (DisplayValidationException $ex) { |
497
|
|
|
return redirect()->route('admin.servers.view.startup', $id)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
498
|
|
|
} catch (DisplayException $ex) { |
499
|
|
|
Alert::danger($ex->getMessage())->flash(); |
500
|
|
|
} catch (TransferException $ex) { |
501
|
|
|
Log::warning($ex); |
502
|
|
|
Alert::danger('A TransferException occurred while attempting to update the startup for this server, please ensure the daemon is running. This error has been logged.')->flash(); |
503
|
|
|
} catch (\Exception $ex) { |
504
|
|
|
Log::error($ex); |
505
|
|
|
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. This error has been logged.')->flash(); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
return redirect()->route('admin.servers.view.startup', $id); |
|
|
|
|
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Creates a new database assigned to a specific server. |
513
|
|
|
* @param Request $request |
514
|
|
|
* @param int $id |
515
|
|
|
* @return \Illuminate\Response\RedirectResponse |
516
|
|
|
*/ |
517
|
|
|
public function newDatabase(Request $request, $id) |
518
|
|
|
{ |
519
|
|
|
$repo = new DatabaseRepository; |
520
|
|
|
|
521
|
|
|
try { |
522
|
|
|
$repo->create($id, $request->only(['host', 'database', 'connection'])); |
523
|
|
|
|
524
|
|
|
Alert::success('A new database was assigned to this server successfully.')->flash(); |
525
|
|
|
} catch (DisplayValidationException $ex) { |
526
|
|
|
return redirect()->route('admin.servers.view.database', $id)->withInput()->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
527
|
|
|
} catch (DisplayException $ex) { |
528
|
|
|
Alert::danger($ex->getMessage())->flash(); |
529
|
|
|
} catch (\Exception $ex) { |
530
|
|
|
Log::error($ex); |
531
|
|
|
Alert::danger('An exception occured while attempting to add a new database for this server. This error has been logged.')->flash(); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
return redirect()->route('admin.servers.view.database', $id)->withInput(); |
|
|
|
|
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* Resets the database password for a specific database on this server. |
539
|
|
|
* @param Request $request |
540
|
|
|
* @param int $id |
541
|
|
|
* @return \Illuminate\Response\RedirectResponse |
542
|
|
|
*/ |
543
|
|
View Code Duplication |
public function resetDatabasePassword(Request $request, $id) |
|
|
|
|
544
|
|
|
{ |
545
|
|
|
$database = Models\Database::where('server_id', $id)->findOrFail($request->input('database')); |
546
|
|
|
$repo = new DatabaseRepository; |
547
|
|
|
|
548
|
|
|
try { |
549
|
|
|
$repo->password($database->id, str_random(20)); |
550
|
|
|
|
551
|
|
|
return response('', 204); |
552
|
|
|
} catch (\Exception $ex) { |
553
|
|
|
Log::error($ex); |
554
|
|
|
|
555
|
|
|
return response()->json(['error' => 'A unhandled exception occurred while attempting to reset this password. This error has been logged.'], 503); |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Deletes a database from a server. |
561
|
|
|
* @param Request $request |
562
|
|
|
* @param int $id |
563
|
|
|
* @return \Illuminate\Response\RedirectResponse |
564
|
|
|
*/ |
565
|
|
View Code Duplication |
public function deleteDatabase(Request $request, $id, $database) |
|
|
|
|
566
|
|
|
{ |
567
|
|
|
$database = Models\Database::where('server_id', $id)->findOrFail($database); |
568
|
|
|
$repo = new DatabaseRepository; |
569
|
|
|
|
570
|
|
|
try { |
571
|
|
|
$repo->drop($database->id); |
572
|
|
|
|
573
|
|
|
return response('', 204); |
574
|
|
|
} catch (\Exception $ex) { |
575
|
|
|
Log::error($ex); |
576
|
|
|
|
577
|
|
|
return response()->json(['error' => 'A unhandled exception occurred while attempting to drop this database. This error has been logged.'], 503); |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
} |
581
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.