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