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 Request $request |
45
|
|
|
* @return \Illuminate\View\View |
46
|
|
|
*/ |
47
|
|
|
public function new(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 Request $request |
59
|
|
|
* @return \Illuminate\Response\RedirectResponse |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function create(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 Request $request |
90
|
|
|
* @param int $id The ID of the service option to assign this variable to. |
91
|
|
|
* @return \Illuminate\Response\RedirectResponse |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function createVariable(Request $request, $id) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$repo = new VariableRepository; |
96
|
|
|
|
97
|
|
|
try { |
98
|
|
|
$variable = $repo->create($id, $request->only([ |
|
|
|
|
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 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 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
|
|
|
* Handles POST when editing a configration for a service option. |
142
|
|
|
* |
143
|
|
|
* @param Request $request |
144
|
|
|
* @return \Illuminate\Response\RedirectResponse |
145
|
|
|
*/ |
146
|
|
|
public function editConfiguration(Request $request, $id) |
147
|
|
|
{ |
148
|
|
|
$repo = new OptionRepository; |
149
|
|
|
|
150
|
|
|
try { |
151
|
|
|
if ($request->input('action') !== 'delete') { |
152
|
|
|
$repo->update($id, $request->intersect([ |
153
|
|
|
'name', 'description', 'tag', 'docker_image', 'startup', |
154
|
|
|
'config_from', 'config_stop', 'config_logs', 'config_files', 'config_startup', |
155
|
|
|
])); |
156
|
|
|
Alert::success('Service option configuration has been successfully updated.')->flash(); |
157
|
|
|
} else { |
158
|
|
|
$option = ServiceOption::with('service')->where('id', $id)->first(); |
|
|
|
|
159
|
|
|
$repo->delete($id); |
160
|
|
|
Alert::success('Successfully deleted service option from the system.')->flash(); |
161
|
|
|
|
162
|
|
|
return redirect()->route('admin.services.view', $option->service_id); |
163
|
|
|
} |
164
|
|
|
} catch (DisplayValidationException $ex) { |
165
|
|
|
return redirect()->route('admin.services.option.view', $id)->withErrors(json_decode($ex->getMessage())); |
166
|
|
|
} catch (DisplayException $ex) { |
167
|
|
|
Alert::danger($ex->getMessage())->flash(); |
168
|
|
|
} catch (\Exception $ex) { |
169
|
|
|
Log::error($ex); |
170
|
|
|
Alert::danger('An unhandled exception occurred while attempting to perform that action. This error has been logged.')->flash(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return redirect()->route('admin.services.option.view', $id); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Handles POST when editing a configration for a service option. |
178
|
|
|
* |
179
|
|
|
* @param Request $request |
180
|
|
|
* @param int $option |
181
|
|
|
* @param int $variable |
182
|
|
|
* @return \Illuminate\Response\RedirectResponse |
183
|
|
|
*/ |
184
|
|
|
public function editVariable(Request $request, $option, $variable) |
185
|
|
|
{ |
186
|
|
|
$repo = new VariableRepository; |
187
|
|
|
|
188
|
|
|
try { |
189
|
|
|
if ($request->input('action') !== 'delete') { |
190
|
|
|
$variable = $repo->update($variable, $request->only([ |
191
|
|
|
'name', 'description', 'env_variable', |
192
|
|
|
'default_value', 'options', 'rules', |
193
|
|
|
])); |
194
|
|
|
Alert::success("The service variable '{$variable->name}' has been updated.")->flash(); |
|
|
|
|
195
|
|
|
} else { |
196
|
|
|
$repo->delete($variable); |
197
|
|
|
Alert::success('That service variable has been deleted.')->flash(); |
198
|
|
|
} |
199
|
|
|
} catch (DisplayValidationException $ex) { |
200
|
|
|
return redirect()->route('admin.services.option.variables', $option)->withErrors(json_decode($ex->getMessage())); |
|
|
|
|
201
|
|
|
} catch (DisplayException $ex) { |
202
|
|
|
Alert::danger($ex->getMessage())->flash(); |
203
|
|
|
} catch (\Exception $ex) { |
204
|
|
|
Log::error($ex); |
205
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash(); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return redirect()->route('admin.services.option.variables', $option); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.