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 Alert; |
28
|
|
|
use Pterodactyl\Models; |
29
|
|
|
use Illuminate\Http\Request; |
30
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
31
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
32
|
|
|
use Pterodactyl\Repositories\LocationRepository; |
33
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
34
|
|
|
|
35
|
|
|
class LocationsController extends Controller |
36
|
|
|
{ |
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
// |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getIndex(Request $request) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
return view('admin.locations.index', [ |
45
|
|
|
'locations' => Models\Location::withCount('nodes', 'servers')->paginate(20), |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function deleteLocation(Request $request, $id) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$location = Models\Location::withCount('nodes')->findOrFail($id); |
52
|
|
|
|
53
|
|
|
if ($location->nodes_count > 0) { |
54
|
|
|
return response()->json([ |
55
|
|
|
'error' => 'You cannot remove a location that is currently assigned to a node.', |
56
|
|
|
], 422); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$location->delete(); |
60
|
|
|
|
61
|
|
|
return response('', 204); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function patchLocation(Request $request, $id) |
65
|
|
|
{ |
66
|
|
|
try { |
67
|
|
|
$location = new LocationRepository; |
68
|
|
|
$location->edit($id, $request->only(['long', 'short'])); |
69
|
|
|
|
70
|
|
|
return response('', 204); |
71
|
|
|
} catch (DisplayValidationException $ex) { |
72
|
|
|
return response()->json([ |
73
|
|
|
'error' => 'There was a validation error while processing this request. Location descriptions must be between 1 and 255 characters, and the location code must be between 1 and 20 characters with no spaces or special characters.', |
74
|
|
|
], 422); |
75
|
|
|
} catch (\Exception $ex) { |
76
|
|
|
// This gets caught and processed into JSON anyways. |
77
|
|
|
throw $ex; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function postLocation(Request $request) |
82
|
|
|
{ |
83
|
|
|
try { |
84
|
|
|
$location = new LocationRepository; |
85
|
|
|
$location->create($request->only(['long', 'short'])); |
86
|
|
|
Alert::success('New location successfully added.')->flash(); |
87
|
|
|
|
88
|
|
|
return redirect()->route('admin.locations'); |
89
|
|
|
} catch (DisplayValidationException $ex) { |
90
|
|
|
return redirect()->route('admin.locations')->withErrors(json_decode($ex->getMessage()))->withInput(); |
91
|
|
|
} catch (DisplayException $ex) { |
92
|
|
|
Alert::danger($ex->getMessage())->flash(); |
93
|
|
|
} catch (\Exception $ex) { |
94
|
|
|
Log::error($ex); |
95
|
|
|
Alert::danger('An unhandled exception occured while attempting to add this location. Please try again.')->flash(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return redirect()->route('admin.locations')->withInput(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.