|
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 Pterodactyl\Models; |
|
30
|
|
|
use Illuminate\Http\Request; |
|
31
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
|
32
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
33
|
|
|
use Pterodactyl\Repositories\ServiceRepository; |
|
34
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
|
35
|
|
|
|
|
36
|
|
|
class ServiceController extends Controller |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Display service overview page. |
|
40
|
|
|
* |
|
41
|
|
|
* @param Request $request |
|
42
|
|
|
* @return \Illuminate\View\View |
|
43
|
|
|
*/ |
|
44
|
|
|
public function index(Request $request) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
return view('admin.services.index', [ |
|
|
|
|
|
|
47
|
|
|
'services' => Models\Service::withCount('servers', 'options', 'packs')->get(), |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Display create service page. |
|
53
|
|
|
* |
|
54
|
|
|
* @param Request $request |
|
55
|
|
|
* @return \Illuminate\View\View |
|
56
|
|
|
*/ |
|
57
|
|
|
public function new(Request $request) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
return view('admin.services.new'); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Return base view for a service. |
|
64
|
|
|
* |
|
65
|
|
|
* @param Request $request |
|
66
|
|
|
* @param int $id |
|
67
|
|
|
* @return \Illuminate\View\View |
|
68
|
|
|
*/ |
|
69
|
|
|
public function view(Request $request, $id) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
return view('admin.services.view', [ |
|
|
|
|
|
|
72
|
|
|
'service' => Models\Service::with('options', 'options.servers')->findOrFail($id), |
|
|
|
|
|
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return function editing view for a service. |
|
78
|
|
|
* |
|
79
|
|
|
* @param Request $request |
|
80
|
|
|
* @param int $id |
|
81
|
|
|
* @return \Illuminate\View\View |
|
82
|
|
|
*/ |
|
83
|
|
|
public function viewFunctions(Request $request, $id) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return view('admin.services.functions', ['service' => Models\Service::findOrFail($id)]); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Handle post action for new service. |
|
90
|
|
|
* |
|
91
|
|
|
* @param Request $request |
|
92
|
|
|
* @return \Illuminate\Response\RedirectResponse |
|
93
|
|
|
*/ |
|
94
|
|
View Code Duplication |
public function create(Request $request) |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
|
|
$repo = new ServiceRepository; |
|
97
|
|
|
|
|
98
|
|
|
try { |
|
99
|
|
|
$service = $repo->create($request->intersect([ |
|
100
|
|
|
'name', 'description', 'folder', 'startup', |
|
101
|
|
|
])); |
|
102
|
|
|
Alert::success('Successfully created new service!')->flash(); |
|
103
|
|
|
|
|
104
|
|
|
return redirect()->route('admin.services.view', $service->id); |
|
|
|
|
|
|
105
|
|
|
} catch (DisplayValidationException $ex) { |
|
106
|
|
|
return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
107
|
|
|
} catch (DisplayException $ex) { |
|
108
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
109
|
|
|
} catch (\Exception $ex) { |
|
110
|
|
|
Log::error($ex); |
|
111
|
|
|
Alert::danger('An error occured while attempting to add a new service. This error has been logged.')->flash(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return redirect()->route('admin.services.new')->withInput(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Edits configuration for a specific service. |
|
119
|
|
|
* |
|
120
|
|
|
* @param Request $request |
|
121
|
|
|
* @param int $id |
|
122
|
|
|
* @return \Illuminate\Response\RedirectResponse |
|
123
|
|
|
*/ |
|
124
|
|
|
public function edit(Request $request, $id) |
|
125
|
|
|
{ |
|
126
|
|
|
$repo = new ServiceRepository; |
|
127
|
|
|
$redirectTo = ($request->input('redirect_to')) ? 'admin.services.view.functions' : 'admin.services.view'; |
|
128
|
|
|
|
|
129
|
|
|
try { |
|
130
|
|
|
if ($request->input('action') !== 'delete') { |
|
131
|
|
|
$repo->update($id, $request->intersect([ |
|
132
|
|
|
'name', 'description', 'folder', 'startup', 'index_file', |
|
133
|
|
|
])); |
|
134
|
|
|
Alert::success('Service has been updated successfully.')->flash(); |
|
135
|
|
|
} else { |
|
136
|
|
|
$repo->delete($id); |
|
137
|
|
|
Alert::success('Successfully deleted service from the system.')->flash(); |
|
138
|
|
|
|
|
139
|
|
|
return redirect()->route('admin.services'); |
|
140
|
|
|
} |
|
141
|
|
|
} catch (DisplayValidationException $ex) { |
|
142
|
|
|
return redirect()->route($redirectTo, $id)->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
|
|
|
|
|
143
|
|
|
} catch (DisplayException $ex) { |
|
144
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
145
|
|
|
} catch (\Exception $ex) { |
|
146
|
|
|
Log::error($ex); |
|
147
|
|
|
Alert::danger('An error occurred while attempting to update this service. This error has been logged.')->flash(); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
return redirect()->route($redirectTo, $id); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.