|
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
|
|
|
$services = Models\Service::with('options.packs', 'options.variables')->get(); |
|
|
|
|
|
|
202
|
|
|
Javascript::put([ |
|
203
|
|
|
'services' => $services->map(function ($item) { |
|
204
|
|
|
return array_merge($item->toArray(), [ |
|
205
|
|
|
'options' => $item->options->keyBy('id')->toArray(), |
|
206
|
|
|
]); |
|
207
|
|
|
})->keyBy('id'), |
|
208
|
|
|
'server_variables' => $server->variables->mapWithKeys(function ($item) { |
|
209
|
|
|
return ['env_' . $item->variable_id => [ |
|
210
|
|
|
'value' => $item->variable_value, |
|
211
|
|
|
]]; |
|
212
|
|
|
})->toArray(), |
|
213
|
|
|
]); |
|
214
|
|
|
|
|
215
|
|
|
return view('admin.servers.view.startup', [ |
|
|
|
|
|
|
216
|
|
|
'server' => $server, |
|
217
|
|
|
'services' => $services, |
|
218
|
|
|
]); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Display the database management page for a specific server. |
|
223
|
|
|
* |
|
224
|
|
|
* @param \Illuminate\Http\Request $request |
|
225
|
|
|
* @param int $id |
|
226
|
|
|
* @return \Illuminate\View\View |
|
227
|
|
|
*/ |
|
228
|
|
|
public function viewDatabase(Request $request, $id) |
|
|
|
|
|
|
229
|
|
|
{ |
|
230
|
|
|
$server = Models\Server::where('installed', 1)->with('databases.host')->findOrFail($id); |
|
231
|
|
|
|
|
232
|
|
|
return view('admin.servers.view.database', [ |
|
|
|
|
|
|
233
|
|
|
'hosts' => Models\DatabaseHost::all(), |
|
234
|
|
|
'server' => $server, |
|
235
|
|
|
]); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Display the management page when viewing a specific server. |
|
240
|
|
|
* |
|
241
|
|
|
* @param \Illuminate\Http\Request $request |
|
242
|
|
|
* @param int $id |
|
243
|
|
|
* @return \Illuminate\View\View |
|
244
|
|
|
*/ |
|
245
|
|
|
public function viewManage(Request $request, $id) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
return view('admin.servers.view.manage', ['server' => Models\Server::findOrFail($id)]); |
|
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Display the deletion page for a server. |
|
252
|
|
|
* |
|
253
|
|
|
* @param \Illuminate\Http\Request $request |
|
254
|
|
|
* @param int $id |
|
255
|
|
|
* @return \Illuminate\View\View |
|
256
|
|
|
*/ |
|
257
|
|
|
public function viewDelete(Request $request, $id) |
|
|
|
|
|
|
258
|
|
|
{ |
|
259
|
|
|
return view('admin.servers.view.delete', ['server' => Models\Server::findOrFail($id)]); |
|
|
|
|
|
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Update the details for a server. |
|
264
|
|
|
* |
|
265
|
|
|
* @param \Illuminate\Http\Request $request |
|
266
|
|
|
* @param int $id |
|
267
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
268
|
|
|
*/ |
|
269
|
|
View Code Duplication |
public function setDetails(Request $request, $id) |
|
|
|
|
|
|
270
|
|
|
{ |
|
271
|
|
|
$repo = new ServerRepository; |
|
272
|
|
|
try { |
|
273
|
|
|
$repo->updateDetails($id, $request->intersect([ |
|
274
|
|
|
'owner_id', 'name', 'description', 'reset_token', |
|
275
|
|
|
])); |
|
276
|
|
|
|
|
277
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
|
278
|
|
|
} catch (DisplayValidationException $ex) { |
|
279
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
|
|
280
|
|
|
} catch (DisplayException $ex) { |
|
281
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
282
|
|
|
} catch (\Exception $ex) { |
|
283
|
|
|
Log::error($ex); |
|
284
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server. This error has been logged.')->flash(); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withInput(); |
|
|
|
|
|
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Set the new docker container for a server. |
|
292
|
|
|
* |
|
293
|
|
|
* @param \Illuminate\Http\Request $request |
|
294
|
|
|
* @param int $id |
|
295
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
296
|
|
|
*/ |
|
297
|
|
View Code Duplication |
public function setContainer(Request $request, $id) |
|
|
|
|
|
|
298
|
|
|
{ |
|
299
|
|
|
$repo = new ServerRepository; |
|
300
|
|
|
|
|
301
|
|
|
try { |
|
302
|
|
|
$repo->updateContainer($id, $request->intersect('docker_image')); |
|
303
|
|
|
|
|
304
|
|
|
Alert::success('Successfully updated this server\'s docker image.')->flash(); |
|
305
|
|
|
} catch (DisplayValidationException $ex) { |
|
306
|
|
|
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
|
|
307
|
|
|
} catch (TransferException $ex) { |
|
308
|
|
|
Log::warning($ex); |
|
309
|
|
|
Alert::danger('A TransferException occured while attempting to update the container image. Is the daemon online? This error has been logged.'); |
|
310
|
|
|
} catch (\Exception $ex) { |
|
311
|
|
|
Log::error($ex); |
|
312
|
|
|
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. This error has been logged.')->flash(); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
return redirect()->route('admin.servers.view.details', $id); |
|
|
|
|
|
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Toggles the install status for a server. |
|
320
|
|
|
* |
|
321
|
|
|
* @param \Illuminate\Http\Request $request |
|
322
|
|
|
* @param int $id |
|
323
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
324
|
|
|
*/ |
|
325
|
|
View Code Duplication |
public function toggleInstall(Request $request, $id) |
|
|
|
|
|
|
326
|
|
|
{ |
|
327
|
|
|
$repo = new ServerRepository; |
|
328
|
|
|
try { |
|
329
|
|
|
$repo->toggleInstall($id); |
|
330
|
|
|
|
|
331
|
|
|
Alert::success('Server install status was successfully toggled.')->flash(); |
|
332
|
|
|
} catch (DisplayException $ex) { |
|
333
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
334
|
|
|
} catch (\Exception $ex) { |
|
335
|
|
|
Log::error($ex); |
|
336
|
|
|
Alert::danger('An unhandled exception occured while attemping to toggle this servers status. This error has been logged.')->flash(); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
|
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Reinstalls the server with the currently assigned pack and service. |
|
344
|
|
|
* |
|
345
|
|
|
* @param \Illuminate\Http\Request $request |
|
346
|
|
|
* @param int $id |
|
347
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
348
|
|
|
*/ |
|
349
|
|
|
public function reinstallServer(Request $request, $id) |
|
|
|
|
|
|
350
|
|
|
{ |
|
351
|
|
|
$repo = new ServerRepository; |
|
352
|
|
|
try { |
|
353
|
|
|
$repo->reinstall($id); |
|
354
|
|
|
|
|
355
|
|
|
Alert::success('Server successfully marked for reinstallation.')->flash(); |
|
356
|
|
|
} catch (DisplayException $ex) { |
|
357
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
358
|
|
|
} catch (\Exception $ex) { |
|
359
|
|
|
Log::error($ex); |
|
360
|
|
|
Alert::danger('An unhandled exception occured while attemping to perform this reinstallation. This error has been logged.')->flash(); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
|
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* Setup a server to have a container rebuild. |
|
368
|
|
|
* |
|
369
|
|
|
* @param \Illuminate\Http\Request $request |
|
370
|
|
|
* @param int $id |
|
371
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
372
|
|
|
*/ |
|
373
|
|
|
public function rebuildContainer(Request $request, $id) |
|
|
|
|
|
|
374
|
|
|
{ |
|
375
|
|
|
$server = Models\Server::with('node')->findOrFail($id); |
|
|
|
|
|
|
376
|
|
|
|
|
377
|
|
|
try { |
|
378
|
|
|
$server->node->guzzleClient([ |
|
379
|
|
|
'X-Access-Server' => $server->uuid, |
|
380
|
|
|
'X-Access-Token' => $server->node->daemonSecret, |
|
381
|
|
|
])->request('POST', '/server/rebuild'); |
|
382
|
|
|
|
|
383
|
|
|
Alert::success('A rebuild has been queued successfully. It will run the next time this server is booted.')->flash(); |
|
384
|
|
|
} catch (TransferException $ex) { |
|
385
|
|
|
Log::warning($ex); |
|
386
|
|
|
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(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
|
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* Manage the suspension status for a server. |
|
394
|
|
|
* |
|
395
|
|
|
* @param \Illuminate\Http\Request $request |
|
396
|
|
|
* @param int $id |
|
397
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
398
|
|
|
*/ |
|
399
|
|
|
public function manageSuspension(Request $request, $id) |
|
400
|
|
|
{ |
|
401
|
|
|
$repo = new ServerRepository; |
|
402
|
|
|
$action = $request->input('action'); |
|
403
|
|
|
|
|
404
|
|
|
if (! in_array($action, ['suspend', 'unsuspend'])) { |
|
405
|
|
|
Alert::danger('Invalid action was passed to function.')->flash(); |
|
406
|
|
|
|
|
407
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
|
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
try { |
|
411
|
|
|
$repo->toggleAccess($id, ($action === 'unsuspend')); |
|
412
|
|
|
|
|
413
|
|
|
Alert::success('Server has been ' . $action . 'ed.'); |
|
414
|
|
|
} catch (TransferException $ex) { |
|
415
|
|
|
Log::warning($ex); |
|
416
|
|
|
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(); |
|
417
|
|
|
} catch (\Exception $ex) { |
|
418
|
|
|
Log::error($ex); |
|
419
|
|
|
Alert::danger('An unhandled exception occured while attemping to ' . $action . ' this server. This error has been logged.')->flash(); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
return redirect()->route('admin.servers.view.manage', $id); |
|
|
|
|
|
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* Update the build configuration for a server. |
|
427
|
|
|
* |
|
428
|
|
|
* @param \Illuminate\Http\Request $request |
|
429
|
|
|
* @param int $id |
|
430
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
431
|
|
|
*/ |
|
432
|
|
|
public function updateBuild(Request $request, $id) |
|
433
|
|
|
{ |
|
434
|
|
|
$repo = new ServerRepository; |
|
435
|
|
|
|
|
436
|
|
|
try { |
|
437
|
|
|
$repo->changeBuild($id, $request->intersect([ |
|
438
|
|
|
'allocation_id', 'add_allocations', 'remove_allocations', |
|
439
|
|
|
'memory', 'swap', 'io', 'cpu', |
|
440
|
|
|
])); |
|
441
|
|
|
|
|
442
|
|
|
Alert::success('Server details were successfully updated.')->flash(); |
|
443
|
|
|
} catch (DisplayValidationException $ex) { |
|
444
|
|
|
return redirect()->route('admin.servers.view.build', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
|
|
445
|
|
|
} catch (DisplayException $ex) { |
|
446
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
447
|
|
|
} catch (TransferException $ex) { |
|
448
|
|
|
Log::warning($ex); |
|
449
|
|
|
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(); |
|
450
|
|
|
} catch (\Exception $ex) { |
|
451
|
|
|
Log::error($ex); |
|
452
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. This error has been logged.')->flash(); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
return redirect()->route('admin.servers.view.build', $id); |
|
|
|
|
|
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* Start the server deletion process. |
|
460
|
|
|
* |
|
461
|
|
|
* @param \Illuminate\Http\Request $request |
|
462
|
|
|
* @param int $id |
|
463
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
464
|
|
|
*/ |
|
465
|
|
View Code Duplication |
public function delete(Request $request, $id) |
|
|
|
|
|
|
466
|
|
|
{ |
|
467
|
|
|
$repo = new ServerRepository; |
|
468
|
|
|
|
|
469
|
|
|
try { |
|
470
|
|
|
$repo->delete($id, $request->has('force_delete')); |
|
471
|
|
|
Alert::success('Server was successfully deleted from the system.')->flash(); |
|
472
|
|
|
|
|
473
|
|
|
return redirect()->route('admin.servers'); |
|
474
|
|
|
} catch (DisplayException $ex) { |
|
475
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
476
|
|
|
} catch (TransferException $ex) { |
|
477
|
|
|
Log::warning($ex); |
|
478
|
|
|
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(); |
|
479
|
|
|
} catch (\Exception $ex) { |
|
480
|
|
|
Log::error($ex); |
|
481
|
|
|
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash(); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
return redirect()->route('admin.servers.view.delete', $id); |
|
|
|
|
|
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* Update the startup command as well as variables. |
|
489
|
|
|
* |
|
490
|
|
|
* @param \Illuminate\Http\Request $request |
|
491
|
|
|
* @param int $id |
|
492
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
493
|
|
|
*/ |
|
494
|
|
|
public function saveStartup(Request $request, $id) |
|
495
|
|
|
{ |
|
496
|
|
|
$repo = new ServerRepository; |
|
497
|
|
|
|
|
498
|
|
|
try { |
|
499
|
|
|
if ($repo->updateStartup($id, $request->except('_token'), true)) { |
|
500
|
|
|
Alert::success('Service configuration successfully modfied for this server, reinstalling now.')->flash(); |
|
501
|
|
|
|
|
502
|
|
|
return redirect()->route('admin.servers.view', $id); |
|
|
|
|
|
|
503
|
|
|
} else { |
|
504
|
|
|
Alert::success('Startup variables were successfully modified and assigned for this server.')->flash(); |
|
505
|
|
|
} |
|
506
|
|
|
} catch (DisplayValidationException $ex) { |
|
507
|
|
|
return redirect()->route('admin.servers.view.startup', $id)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
|
|
508
|
|
|
} catch (DisplayException $ex) { |
|
509
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
510
|
|
|
} catch (TransferException $ex) { |
|
511
|
|
|
Log::warning($ex); |
|
512
|
|
|
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(); |
|
513
|
|
|
} catch (\Exception $ex) { |
|
514
|
|
|
Log::error($ex); |
|
515
|
|
|
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. This error has been logged.')->flash(); |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
return redirect()->route('admin.servers.view.startup', $id); |
|
|
|
|
|
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
/** |
|
522
|
|
|
* Creates a new database assigned to a specific server. |
|
523
|
|
|
* |
|
524
|
|
|
* @param \Illuminate\Http\Request $request |
|
525
|
|
|
* @param int $id |
|
526
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
527
|
|
|
*/ |
|
528
|
|
|
public function newDatabase(Request $request, $id) |
|
529
|
|
|
{ |
|
530
|
|
|
$repo = new DatabaseRepository; |
|
531
|
|
|
|
|
532
|
|
|
try { |
|
533
|
|
|
$repo->create($id, $request->only(['host', 'database', 'connection'])); |
|
534
|
|
|
|
|
535
|
|
|
Alert::success('A new database was assigned to this server successfully.')->flash(); |
|
536
|
|
|
} catch (DisplayValidationException $ex) { |
|
537
|
|
|
return redirect()->route('admin.servers.view.database', $id)->withInput()->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
|
|
538
|
|
|
} catch (DisplayException $ex) { |
|
539
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
540
|
|
|
} catch (\Exception $ex) { |
|
541
|
|
|
Log::error($ex); |
|
542
|
|
|
Alert::danger('An exception occured while attempting to add a new database for this server. This error has been logged.')->flash(); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
return redirect()->route('admin.servers.view.database', $id)->withInput(); |
|
|
|
|
|
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* Resets the database password for a specific database on this server. |
|
550
|
|
|
* |
|
551
|
|
|
* @param \Illuminate\Http\Request $request |
|
552
|
|
|
* @param int $id |
|
553
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
554
|
|
|
*/ |
|
555
|
|
View Code Duplication |
public function resetDatabasePassword(Request $request, $id) |
|
|
|
|
|
|
556
|
|
|
{ |
|
557
|
|
|
$database = Models\Database::where('server_id', $id)->findOrFail($request->input('database')); |
|
558
|
|
|
$repo = new DatabaseRepository; |
|
559
|
|
|
|
|
560
|
|
|
try { |
|
561
|
|
|
$repo->password($database->id, str_random(20)); |
|
562
|
|
|
|
|
563
|
|
|
return response('', 204); |
|
564
|
|
|
} catch (\Exception $ex) { |
|
565
|
|
|
Log::error($ex); |
|
566
|
|
|
|
|
567
|
|
|
return response()->json(['error' => 'A unhandled exception occurred while attempting to reset this password. This error has been logged.'], 503); |
|
|
|
|
|
|
568
|
|
|
} |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
/** |
|
572
|
|
|
* Deletes a database from a server. |
|
573
|
|
|
* |
|
574
|
|
|
* @param \Illuminate\Http\Request $request |
|
575
|
|
|
* @param int $id |
|
576
|
|
|
* @param int $database |
|
577
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
578
|
|
|
*/ |
|
579
|
|
View Code Duplication |
public function deleteDatabase(Request $request, $id, $database) |
|
|
|
|
|
|
580
|
|
|
{ |
|
581
|
|
|
$database = Models\Database::where('server_id', $id)->findOrFail($database); |
|
582
|
|
|
$repo = new DatabaseRepository; |
|
583
|
|
|
|
|
584
|
|
|
try { |
|
585
|
|
|
$repo->drop($database->id); |
|
586
|
|
|
|
|
587
|
|
|
return response('', 204); |
|
588
|
|
|
} catch (\Exception $ex) { |
|
589
|
|
|
Log::error($ex); |
|
590
|
|
|
|
|
591
|
|
|
return response()->json(['error' => 'A unhandled exception occurred while attempting to drop this database. This error has been logged.'], 503); |
|
|
|
|
|
|
592
|
|
|
} |
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
|