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 Illuminate\Http\Request; |
31
|
|
|
use Pterodactyl\Models\Service; |
32
|
|
|
use Pterodactyl\Models\ServiceOption; |
33
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
34
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
35
|
|
|
use Pterodactyl\Repositories\OptionRepository; |
36
|
|
|
use Pterodactyl\Repositories\VariableRepository; |
37
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
38
|
|
|
|
39
|
|
|
class OptionController extends Controller |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* Handles request to view page for adding new option. |
43
|
|
|
* |
44
|
|
|
* @param \Illuminate\Http\Request $request |
45
|
|
|
* @return \Illuminate\View\View |
46
|
|
|
*/ |
47
|
|
|
public function create(Request $request) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$services = Service::with('options')->get(); |
|
|
|
|
50
|
|
|
Javascript::put(['services' => $services->keyBy('id')]); |
51
|
|
|
|
52
|
|
|
return view('admin.services.options.new', ['services' => $services]); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Handles POST request to create a new option. |
57
|
|
|
* |
58
|
|
|
* @param \Illuminate\Http\Request $request |
59
|
|
|
* @return \Illuminate\Response\RedirectResponse |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function store(Request $request) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$repo = new OptionRepository; |
64
|
|
|
|
65
|
|
|
try { |
66
|
|
|
$option = $repo->create($request->intersect([ |
67
|
|
|
'service_id', 'name', 'description', 'tag', |
68
|
|
|
'docker_image', 'startup', 'config_from', 'config_startup', |
69
|
|
|
'config_logs', 'config_files', 'config_stop', |
70
|
|
|
])); |
71
|
|
|
Alert::success('Successfully created new service option.')->flash(); |
72
|
|
|
|
73
|
|
|
return redirect()->route('admin.services.option.view', $option->id); |
74
|
|
|
} catch (DisplayValidationException $ex) { |
75
|
|
|
return redirect()->route('admin.services.option.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
76
|
|
|
} catch (DisplayException $ex) { |
77
|
|
|
Alert::danger($ex->getMessage())->flash(); |
78
|
|
|
} catch (\Exception $ex) { |
79
|
|
|
Log::error($ex); |
80
|
|
|
Alert::danger('An unhandled exception occurred while attempting to create this service. This error has been logged.')->flash(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return redirect()->route('admin.services.option.new')->withInput(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Handles POST request to create a new option variable. |
88
|
|
|
* |
89
|
|
|
* @param \Illuminate\Http\Request $request |
90
|
|
|
* @param int $id |
91
|
|
|
* @return \Illuminate\Http\RedirectResponse |
92
|
|
|
*/ |
93
|
|
|
public function createVariable(Request $request, $id) |
94
|
|
|
{ |
95
|
|
|
$repo = new VariableRepository; |
96
|
|
|
|
97
|
|
|
try { |
98
|
|
|
$variable = $repo->create($id, $request->intersect([ |
|
|
|
|
99
|
|
|
'name', 'description', 'env_variable', |
100
|
|
|
'default_value', 'options', 'rules', |
101
|
|
|
])); |
102
|
|
|
|
103
|
|
|
Alert::success('New variable successfully assigned to this service option.')->flash(); |
104
|
|
|
} catch (DisplayValidationException $ex) { |
105
|
|
|
return redirect()->route('admin.services.option.variables', $id)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
106
|
|
|
} catch (DisplayException $ex) { |
107
|
|
|
Alert::danger($ex->getMessage())->flash(); |
108
|
|
|
} catch (\Exception $ex) { |
109
|
|
|
Log::error($ex); |
110
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return redirect()->route('admin.services.option.variables', $id); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Display option overview page. |
118
|
|
|
* |
119
|
|
|
* @param \Illuminate\Http\Request $request |
120
|
|
|
* @param int $id |
121
|
|
|
* @return \Illuminate\View\View |
122
|
|
|
*/ |
123
|
|
|
public function viewConfiguration(Request $request, $id) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
return view('admin.services.options.view', ['option' => ServiceOption::findOrFail($id)]); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Display variable overview page for a service option. |
130
|
|
|
* |
131
|
|
|
* @param \Illuminate\Http\Request $request |
132
|
|
|
* @param int $id |
133
|
|
|
* @return \Illuminate\View\View |
134
|
|
|
*/ |
135
|
|
|
public function viewVariables(Request $request, $id) |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
return view('admin.services.options.variables', ['option' => ServiceOption::with('variables')->findOrFail($id)]); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Display script management page for an option. |
142
|
|
|
* |
143
|
|
|
* @param Request $request |
144
|
|
|
* @param int $id |
145
|
|
|
* @return \Illuminate\View\View |
146
|
|
|
*/ |
147
|
|
|
public function viewScripts(Request $request, $id) |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
return view('admin.services.options.scripts', ['option' => ServiceOption::findOrFail($id)]); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Handles POST when editing a configration for a service option. |
154
|
|
|
* |
155
|
|
|
* @param \Illuminate\Http\Request $request |
156
|
|
|
* @param int $id |
157
|
|
|
* @return \Illuminate\Http\RedirectResponse |
158
|
|
|
*/ |
159
|
|
|
public function editConfiguration(Request $request, $id) |
160
|
|
|
{ |
161
|
|
|
$repo = new OptionRepository; |
162
|
|
|
|
163
|
|
|
try { |
164
|
|
|
if ($request->input('action') !== 'delete') { |
165
|
|
|
$repo->update($id, $request->intersect([ |
166
|
|
|
'name', 'description', 'tag', 'docker_image', 'startup', |
167
|
|
|
'config_from', 'config_stop', 'config_logs', 'config_files', 'config_startup', |
168
|
|
|
])); |
169
|
|
|
Alert::success('Service option configuration has been successfully updated.')->flash(); |
170
|
|
|
} else { |
171
|
|
|
$option = ServiceOption::with('service')->where('id', $id)->first(); |
|
|
|
|
172
|
|
|
$repo->delete($id); |
173
|
|
|
Alert::success('Successfully deleted service option from the system.')->flash(); |
174
|
|
|
|
175
|
|
|
return redirect()->route('admin.services.view', $option->service_id); |
176
|
|
|
} |
177
|
|
|
} catch (DisplayValidationException $ex) { |
178
|
|
|
return redirect()->route('admin.services.option.view', $id)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
179
|
|
|
} catch (DisplayException $ex) { |
180
|
|
|
Alert::danger($ex->getMessage())->flash(); |
181
|
|
|
} catch (\Exception $ex) { |
182
|
|
|
Log::error($ex); |
183
|
|
|
Alert::danger('An unhandled exception occurred while attempting to perform that action. This error has been logged.')->flash(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return redirect()->route('admin.services.option.view', $id); |
|
|
|
|
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Handles POST when editing a configration for a service option. |
191
|
|
|
* |
192
|
|
|
* @param \Illuminate\Http\Request $request |
193
|
|
|
* @param int $option |
194
|
|
|
* @param int $variable |
195
|
|
|
* @return \Illuminate\Http\RedirectResponse |
196
|
|
|
*/ |
197
|
|
|
public function editVariable(Request $request, $option, $variable) |
198
|
|
|
{ |
199
|
|
|
$repo = new VariableRepository; |
200
|
|
|
|
201
|
|
|
try { |
202
|
|
|
if ($request->input('action') !== 'delete') { |
203
|
|
|
$variable = $repo->update($variable, $request->intersect([ |
204
|
|
|
'name', 'description', 'env_variable', |
205
|
|
|
'default_value', 'options', 'rules', |
206
|
|
|
])); |
207
|
|
|
Alert::success("The service variable '{$variable->name}' has been updated.")->flash(); |
208
|
|
|
} else { |
209
|
|
|
$repo->delete($variable); |
210
|
|
|
Alert::success('That service variable has been deleted.')->flash(); |
211
|
|
|
} |
212
|
|
|
} catch (DisplayValidationException $ex) { |
213
|
|
|
return redirect()->route('admin.services.option.variables', $option)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
214
|
|
|
} catch (DisplayException $ex) { |
215
|
|
|
Alert::danger($ex->getMessage())->flash(); |
216
|
|
|
} catch (\Exception $ex) { |
217
|
|
|
Log::error($ex); |
218
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
return redirect()->route('admin.services.option.variables', $option); |
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Handles POST when updating scripts for a service option. |
226
|
|
|
* |
227
|
|
|
* @param Request $request |
228
|
|
|
* @param int $id |
229
|
|
|
* @return \Illuminate\Response\RedirectResponse |
230
|
|
|
*/ |
231
|
|
View Code Duplication |
public function updateScripts(Request $request, $id) |
|
|
|
|
232
|
|
|
{ |
233
|
|
|
$repo = new OptionRepository; |
234
|
|
|
|
235
|
|
|
try { |
236
|
|
|
$repo->scripts($id, $request->only([ |
237
|
|
|
'script_install', 'script_entry', 'script_container', |
238
|
|
|
])); |
239
|
|
|
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash(); |
240
|
|
|
} catch (DisplayValidationException $ex) { |
241
|
|
|
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
242
|
|
|
} catch (\Exception $ex) { |
243
|
|
|
Log::error($ex); |
244
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash(); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return redirect()->route('admin.services.option.scripts', $id); |
|
|
|
|
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.