mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-25 10:32:31 +01:00
add ability to create new service
This commit is contained in:
parent
e42547a1ff
commit
a50bb5da14
@ -53,12 +53,27 @@ class ServiceController extends Controller
|
|||||||
|
|
||||||
public function getNew(Request $request)
|
public function getNew(Request $request)
|
||||||
{
|
{
|
||||||
//
|
return view('admin.services.new');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postNew(Request $request)
|
public function postNew(Request $request)
|
||||||
{
|
{
|
||||||
//
|
try {
|
||||||
|
$repo = new ServiceRepository\Service;
|
||||||
|
$id = $repo->create($request->except([
|
||||||
|
'_token'
|
||||||
|
]));
|
||||||
|
Alert::success('Successfully created new service!')->flash();
|
||||||
|
return redirect()->route('admin.services.service', $id);
|
||||||
|
} catch (DisplayValidationException $ex) {
|
||||||
|
return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||||
|
} catch (DisplayException $ex) {
|
||||||
|
Alert::danger($ex->getMessage())->flash();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
Log::error($ex);
|
||||||
|
Alert::danger('An error occured while attempting to add a new service.')->flash();
|
||||||
|
}
|
||||||
|
return redirect()->route('admin.services.new')->withInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getService(Request $request, $service)
|
public function getService(Request $request, $service)
|
||||||
|
@ -348,6 +348,15 @@ class AdminRoutes {
|
|||||||
'uses' => 'Admin\ServiceController@getIndex'
|
'uses' => 'Admin\ServiceController@getIndex'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$router->get('/new', [
|
||||||
|
'as' => 'admin.services.new',
|
||||||
|
'uses' => 'Admin\ServiceController@getNew'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$router->post('/new', [
|
||||||
|
'uses' => 'Admin\ServiceController@postNew'
|
||||||
|
]);
|
||||||
|
|
||||||
$router->get('/service/{id}', [
|
$router->get('/service/{id}', [
|
||||||
'as' => 'admin.services.service',
|
'as' => 'admin.services.service',
|
||||||
'uses' => 'Admin\ServiceController@getService'
|
'uses' => 'Admin\ServiceController@getService'
|
||||||
|
@ -40,6 +40,31 @@ class Service
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function create(array $data)
|
||||||
|
{
|
||||||
|
$validator = Validator::make($data, [
|
||||||
|
'name' => 'required|string|min:1|max:255',
|
||||||
|
'description' => 'required|string',
|
||||||
|
'file' => 'required|regex:/^[\w.-]{1,50}$/',
|
||||||
|
'executable' => 'required|max:255|regex:/^(.*)$/',
|
||||||
|
'startup' => 'required|string'
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
throw new DisplayValidationException($validator->errors());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Models\Service::where('file', $data['file'])->first()) {
|
||||||
|
throw new DisplayException('A service using that configuration file already exists on the system.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$service = new Models\Service;
|
||||||
|
$service->fill($data);
|
||||||
|
$service->save();
|
||||||
|
|
||||||
|
return $service->id;
|
||||||
|
}
|
||||||
|
|
||||||
public function update($id, array $data)
|
public function update($id, array $data)
|
||||||
{
|
{
|
||||||
$service = Models\Service::findOrFail($id);
|
$service = Models\Service::findOrFail($id);
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
{{-- Copyright (c) 2015 - 2016 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. --}}
|
||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Manage Services
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="col-md-12">
|
||||||
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="/admin">Admin Control</a></li>
|
||||||
|
<li><a href="{{ route('admin.services') }}">Services</a></li>
|
||||||
|
<li class="active">New Service</li>
|
||||||
|
</ul>
|
||||||
|
<h3 class="nopad">Add New Service</h3><hr />
|
||||||
|
<form action="{{ route('admin.services.new') }}" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 form-group">
|
||||||
|
<label class="control-label">Service Name:</label>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="name" class="form-control" value="{{ old('name') }}" />
|
||||||
|
<p class="text-muted"><small>This should be a descriptive category name that emcompasses all of the options within the service.</small></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 form-group">
|
||||||
|
<label class="control-label">Service Description:</label>
|
||||||
|
<div>
|
||||||
|
<textarea name="description" class="form-control" rows="4">{{ old('description') }}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 form-group">
|
||||||
|
<label class="control-label">Service Configuration File:</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon">/src/services/</span>
|
||||||
|
<input type="text" name="file" class="form-control" value="{{ old('file') }}" />
|
||||||
|
<span class="input-group-addon">/index.js</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-muted"><small>This should be the name of the folder on the daemon that contains all of the service logic.</small></p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 form-group">
|
||||||
|
<label class="control-label">Display Executable:</label>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="executable" class="form-control" value="{{ old('executable') }}" />
|
||||||
|
</div>
|
||||||
|
<p class="text-muted"><small>Changing this has no effect on operation of the daemon, it is simply used for display purposes on the panel. This can be changed per-option.</small></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 form-group">
|
||||||
|
<label class="control-label">Default Startup:</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon" id="disp_exec"></span>
|
||||||
|
<input type="text" name="startup" class="form-control" value="{{ old('startup') }}" />
|
||||||
|
</div>
|
||||||
|
<p class="text-muted"><small>This is the default startup that will be used for all servers created using this service. This can be changed per-option.</small></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="alert alert-info">You will be able to add service options and variables once the service is created.</div>
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<input type="submit" class="btn btn-sm btn-primary" value="Add New Service" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#sidebar_links').find("a[href='/admin/services/new']").addClass('active');
|
||||||
|
$('input[name="executable"]').on('keyup', function() {
|
||||||
|
$("#disp_exec").html(escape($(this).val()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
Loading…
Reference in New Issue
Block a user