2017-03-10 23:25:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use Log;
|
|
|
|
use Alert;
|
2017-03-12 05:00:06 +00:00
|
|
|
use Javascript;
|
2017-03-10 23:25:12 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-03-12 05:00:06 +00:00
|
|
|
use Pterodactyl\Models\Service;
|
|
|
|
use Pterodactyl\Models\ServiceOption;
|
2017-03-10 23:25:12 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Repositories\OptionRepository;
|
2017-03-12 05:00:06 +00:00
|
|
|
use Pterodactyl\Repositories\VariableRepository;
|
2017-03-10 23:25:12 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException;
|
|
|
|
|
|
|
|
class OptionController extends Controller
|
|
|
|
{
|
2017-03-12 05:00:06 +00:00
|
|
|
/**
|
|
|
|
* Handles request to view page for adding new option.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-03-12 05:00:06 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function create(Request $request)
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
|
|
|
$services = Service::with('options')->get();
|
|
|
|
Javascript::put(['services' => $services->keyBy('id')]);
|
|
|
|
|
|
|
|
return view('admin.services.options.new', ['services' => $services]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles POST request to create a new option.
|
2017-03-12 20:28:38 +00:00
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-03-12 05:00:06 +00:00
|
|
|
* @return \Illuminate\Response\RedirectResponse
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function store(Request $request)
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
|
|
|
$repo = new OptionRepository;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$option = $repo->create($request->intersect([
|
|
|
|
'service_id', 'name', 'description', 'tag',
|
|
|
|
'docker_image', 'startup', 'config_from', 'config_startup',
|
2017-03-12 20:34:43 +00:00
|
|
|
'config_logs', 'config_files', 'config_stop',
|
2017-03-12 05:00:06 +00:00
|
|
|
]));
|
|
|
|
Alert::success('Successfully created new service option.')->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.view', $option->id);
|
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.services.option.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An unhandled exception occurred while attempting to create this service. This error has been logged.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.new')->withInput();
|
|
|
|
}
|
|
|
|
|
2017-03-12 20:28:38 +00:00
|
|
|
/**
|
|
|
|
* Handles POST request to create a new option variable.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-03-12 20:28:38 +00:00
|
|
|
*/
|
|
|
|
public function createVariable(Request $request, $id)
|
|
|
|
{
|
|
|
|
$repo = new VariableRepository;
|
|
|
|
|
|
|
|
try {
|
2017-04-20 22:52:43 +00:00
|
|
|
$variable = $repo->create($id, $request->intersect([
|
2017-03-12 20:28:38 +00:00
|
|
|
'name', 'description', 'env_variable',
|
|
|
|
'default_value', 'options', 'rules',
|
|
|
|
]));
|
|
|
|
|
|
|
|
Alert::success('New variable successfully assigned to this service option.')->flash();
|
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.services.option.variables', $id)->withErrors(json_decode($ex->getMessage()));
|
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.variables', $id);
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Display option overview page.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
2017-03-10 23:25:12 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function viewConfiguration(Request $request, $id)
|
|
|
|
{
|
2017-03-12 05:00:06 +00:00
|
|
|
return view('admin.services.options.view', ['option' => ServiceOption::findOrFail($id)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display variable overview page for a service option.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
2017-03-12 05:00:06 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function viewVariables(Request $request, $id)
|
|
|
|
{
|
|
|
|
return view('admin.services.options.variables', ['option' => ServiceOption::with('variables')->findOrFail($id)]);
|
2017-03-10 23:25:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 17:09:30 +00:00
|
|
|
/**
|
|
|
|
* Display script management page for an option.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function viewScripts(Request $request, $id)
|
|
|
|
{
|
2017-04-27 20:16:57 +00:00
|
|
|
$option = ServiceOption::with('copyFrom')->findOrFail($id);
|
|
|
|
|
|
|
|
return view('admin.services.options.scripts', [
|
|
|
|
'copyFromOptions' => ServiceOption::whereNull('copy_script_from')->where([
|
|
|
|
['service_id', $option->service_id],
|
|
|
|
['id', '!=', $option->id],
|
|
|
|
])->get(),
|
|
|
|
'relyOnScript' => ServiceOption::where('copy_script_from', $option->id)->get(),
|
|
|
|
'option' => $option,
|
|
|
|
]);
|
2017-03-18 17:09:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 05:00:06 +00:00
|
|
|
/**
|
|
|
|
* Handles POST when editing a configration for a service option.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-03-12 05:00:06 +00:00
|
|
|
*/
|
2017-03-10 23:25:12 +00:00
|
|
|
public function editConfiguration(Request $request, $id)
|
|
|
|
{
|
|
|
|
$repo = new OptionRepository;
|
|
|
|
|
|
|
|
try {
|
2017-03-12 05:00:06 +00:00
|
|
|
if ($request->input('action') !== 'delete') {
|
|
|
|
$repo->update($id, $request->intersect([
|
|
|
|
'name', 'description', 'tag', 'docker_image', 'startup',
|
|
|
|
'config_from', 'config_stop', 'config_logs', 'config_files', 'config_startup',
|
|
|
|
]));
|
|
|
|
Alert::success('Service option configuration has been successfully updated.')->flash();
|
|
|
|
} else {
|
|
|
|
$option = ServiceOption::with('service')->where('id', $id)->first();
|
|
|
|
$repo->delete($id);
|
|
|
|
Alert::success('Successfully deleted service option from the system.')->flash();
|
2017-03-10 23:25:12 +00:00
|
|
|
|
2017-03-12 05:00:06 +00:00
|
|
|
return redirect()->route('admin.services.view', $option->service_id);
|
|
|
|
}
|
2017-03-10 23:25:12 +00:00
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.services.option.view', $id)->withErrors(json_decode($ex->getMessage()));
|
2017-03-12 05:00:06 +00:00
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
2017-03-10 23:25:12 +00:00
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
2017-03-12 05:00:06 +00:00
|
|
|
Alert::danger('An unhandled exception occurred while attempting to perform that action. This error has been logged.')->flash();
|
2017-03-10 23:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.view', $id);
|
|
|
|
}
|
2017-03-12 05:00:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles POST when editing a configration for a service option.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $option
|
|
|
|
* @param int $variable
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-03-12 05:00:06 +00:00
|
|
|
*/
|
|
|
|
public function editVariable(Request $request, $option, $variable)
|
|
|
|
{
|
|
|
|
$repo = new VariableRepository;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($request->input('action') !== 'delete') {
|
2017-06-19 01:39:04 +00:00
|
|
|
$variable = $repo->update($variable, $request->only([
|
2017-03-12 05:00:06 +00:00
|
|
|
'name', 'description', 'env_variable',
|
|
|
|
'default_value', 'options', 'rules',
|
|
|
|
]));
|
|
|
|
Alert::success("The service variable '{$variable->name}' has been updated.")->flash();
|
|
|
|
} else {
|
|
|
|
$repo->delete($variable);
|
2017-03-12 20:34:43 +00:00
|
|
|
Alert::success('That service variable has been deleted.')->flash();
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.services.option.variables', $option)->withErrors(json_decode($ex->getMessage()));
|
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.variables', $option);
|
|
|
|
}
|
2017-03-18 17:09:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles POST when updating scripts for a service option.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Response\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function updateScripts(Request $request, $id)
|
|
|
|
{
|
|
|
|
$repo = new OptionRepository;
|
|
|
|
|
|
|
|
try {
|
2017-04-20 22:52:43 +00:00
|
|
|
$repo->scripts($id, $request->only([
|
2017-04-27 20:16:57 +00:00
|
|
|
'script_install', 'script_entry',
|
|
|
|
'script_container', 'copy_script_from',
|
2017-04-20 22:52:43 +00:00
|
|
|
]));
|
2017-04-20 21:26:20 +00:00
|
|
|
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash();
|
2017-03-18 17:09:30 +00:00
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
|
2017-04-27 20:16:57 +00:00
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
2017-03-18 17:09:30 +00:00
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.scripts', $id);
|
|
|
|
}
|
2017-03-10 23:25:12 +00:00
|
|
|
}
|