Initial implementation of option scripts on panel side.

This commit is contained in:
Dane Everitt 2017-03-18 13:09:30 -04:00
parent 5d990dcb06
commit 03e0de28d9
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 284 additions and 0 deletions

View file

@ -137,6 +137,18 @@ class OptionController extends Controller
return view('admin.services.options.variables', ['option' => ServiceOption::with('variables')->findOrFail($id)]);
}
/**
* Display script management page for an option.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewScripts(Request $request, $id)
{
return view('admin.services.options.scripts', ['option' => ServiceOption::findOrFail($id)]);
}
/**
* Handles POST when editing a configration for a service option.
*
@ -207,4 +219,30 @@ class OptionController extends Controller
return redirect()->route('admin.services.option.variables', $option);
}
/**
* 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 {
$repo->scripts($id, $request->only([
'script_install', 'script_upgrade',
]));
Alert::success('Successfully updated option scripts to be run when servers are installed or updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
} 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);
}
}

View file

@ -0,0 +1,56 @@
<?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\Daemon;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Http\Controllers\Controller;
class OptionController extends Controller
{
public function details(Request $request, $server)
{
$server = Server::with('allocation', 'option', 'variables.variable')->where('uuid', $server)->firstOrFail();
$environment = $server->variables->map(function ($item) {
return sprintf('%s=%s', $item->variable->env_variable, $item->variable_value);
});
return response()->json([
'scripts' => [
'install' => str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_install),
'upgrade' => str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_upgrade),
'privileged' => $server->option->script_is_privileged,
],
'env' => $environment->merge([
'STARTUP=' . $server->startup,
'SERVER_MEMORY=' . $server->memory,
'SERVER_IP=' . $server->allocation->ip,
'SERVER_PORT=' . $server->allocation->port,
])->toArray(),
]);
}
}

View file

@ -434,6 +434,14 @@ class AdminRoutes
'as' => 'admin.services.option.variables.edit',
'uses' => 'Admin\OptionController@editVariable',
]);
$router->get('/option/{id}/scripts', [
'as' => 'admin.services.option.scripts',
'uses' => 'Admin\OptionController@viewScripts',
]);
$router->post('/option/{id}/scripts', 'Admin\OptionController@updateScripts');
});
// Service Packs

View file

@ -49,6 +49,11 @@ class DaemonRoutes
'as' => 'daemon.pack.hash',
'uses' => 'Daemon\PackController@hash',
]);
$router->get('details/option/{server}', [
'as' => 'daemon.pack.hash',
'uses' => 'Daemon\OptionController@details',
]);
});
}
}