Push some basic add server functionality
Doesn’t support adding the server, but adds improved support for handling picking server location, node, and ip+port
This commit is contained in:
parent
28594cff70
commit
47235b670a
9 changed files with 344 additions and 7 deletions
63
app/Http/Controllers/Admin/AjaxController.php
Normal file
63
app/Http/Controllers/Admin/AjaxController.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Debugbar;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Node;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AjaxController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Controller Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
// All routes in this controller are protected by the authentication middleware.
|
||||
$this->middleware('auth');
|
||||
$this->middleware('admin');
|
||||
|
||||
}
|
||||
|
||||
public function postNewServerGetNodes(Request $request)
|
||||
{
|
||||
|
||||
if(!$request->input('location')) {
|
||||
return response()->json([
|
||||
'error' => 'Missing location in request.'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response(Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()->toJson());
|
||||
|
||||
}
|
||||
|
||||
public function postNewServerGetIps(Request $request)
|
||||
{
|
||||
|
||||
if(!$request->input('node')) {
|
||||
return response()->json([
|
||||
'error' => 'Missing node in request.'
|
||||
], 500);
|
||||
}
|
||||
|
||||
$ips = Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get();
|
||||
$listing = [];
|
||||
|
||||
foreach($ips as &$ip) {
|
||||
if (array_key_exists($ip->ip, $listing)) {
|
||||
$listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]);
|
||||
} else {
|
||||
$listing[$ip->ip] = [$ip->port];
|
||||
}
|
||||
}
|
||||
return response()->json($listing);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Controllers\Admin;
|
|||
use Debugbar;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Location;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -36,7 +37,9 @@ class ServersController extends Controller
|
|||
|
||||
public function getNew(Request $request)
|
||||
{
|
||||
//
|
||||
return view('admin.servers.new', [
|
||||
'locations' => Location::all()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getView(Request $request, $id)
|
||||
|
|
|
@ -24,6 +24,12 @@ class AdminRoutes {
|
|||
$router->get('/view/{id}', [ 'as' => 'admin.servers.view', 'uses' => 'Admin\ServersController@getView' ]);
|
||||
});
|
||||
|
||||
// AJAX Routes
|
||||
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
|
||||
$router->post('/new/server/get-nodes', [ 'uses' => 'Admin\AjaxController@postNewServerGetNodes' ]);
|
||||
$router->post('/new/server/get-ips', [ 'uses' => 'Admin\AjaxController@postNewServerGetIps' ]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
17
app/Models/Allocation.php
Normal file
17
app/Models/Allocation.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Allocation extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'allocations';
|
||||
|
||||
}
|
17
app/Models/Location.php
Normal file
17
app/Models/Location.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Location extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'locations';
|
||||
|
||||
}
|
31
database/migrations/2015_12_07_043347_add_assigned_to.php
Normal file
31
database/migrations/2015_12_07_043347_add_assigned_to.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddAssignedTo extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('allocations', function (Blueprint $table) {
|
||||
$table->mediumInteger('assigned_to')->unsigned()->nullable()->after('port');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('allocations', function (Blueprint $table) {
|
||||
$table->dropColumn('assigned_to');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -63,8 +63,8 @@ body{font-size:13px}
|
|||
.centered{text-align:center}
|
||||
.console{font:85% 'Droid Sans Mono',monospace;color:#333;height:300px!important;text-wrap:normal;overflow-y:scroll;overflow-x:hidden;border:0;resize:none}
|
||||
.console[readonly=readonly]{background:#fefefe;cursor:default}
|
||||
.files_loading_box{position:absolute;background:rgba(255,255,255,.8);width:100%;z-index:9999;display:none}
|
||||
.files_loading_box i{font-size:30px;color:rgba(0,0,0,.6);position:absolute}
|
||||
.ajax_loading_box{position:absolute;background:rgba(255,255,255,.8);width:100%;z-index:9999;display:none}
|
||||
.ajax_loading_box i{font-size:30px;color:rgba(0,0,0,.6);position:absolute}
|
||||
.btn-xxs{padding:2px 6px;font-size:10px;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:2px}
|
||||
.form-control{height:36px}
|
||||
.input-group-addon{font-size:12px;}
|
||||
|
|
200
resources/views/admin/servers/new.blade.php
Normal file
200
resources/views/admin/servers/new.blade.php
Normal file
|
@ -0,0 +1,200 @@
|
|||
@extends('layouts.admin')
|
||||
|
||||
@section('title')
|
||||
Server List
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="col-md-9">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="/admin">Admin Control</a></li>
|
||||
<li><a href="/admin/servers">Servers</a></li>
|
||||
<li class="active">Create New Server</li>
|
||||
</ul>
|
||||
<h3>Create New Server</h3><hr />
|
||||
<form action="#" method="POST">
|
||||
<div class="well">
|
||||
<div class="row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="server_name" class="control-label">Server Name</label>
|
||||
<div>
|
||||
<input type="text" autocomplete="off" name="server_name" class="form-control" />
|
||||
<p class="text-muted" style="margin: 0 0 -10.5px;"><small><em>Character limits: <code>a-zA-Z0-9_-</code> and <code>[Space]</code> (max 35 characters)</em></small></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="server_name" class="control-label">Owner Email</label>
|
||||
<div>
|
||||
<input type="text" autocomplete="off" name="owner_email" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="load_settings">
|
||||
<div class="well">
|
||||
<div class="row">
|
||||
<div class="ajax_loading_box" style="display:none;"><i class="fa fa-refresh fa-spin" id="position_me"></i></div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="location" class="control-label">Server Location</label>
|
||||
<div>
|
||||
<select name="location" id="getLocation" class="form-control">
|
||||
<option></option>
|
||||
@foreach($locations as $location)
|
||||
<option value="{{ $location->id }}">{{ $location->long }} ({{ $location->short }})</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6 hidden">
|
||||
<label for="location" class="control-label">Server Node</label>
|
||||
<div>
|
||||
<select name="node" id="getNode" class="form-control">
|
||||
<option></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-6 hidden">
|
||||
<label for="location" class="control-label">Server IP</label>
|
||||
<div>
|
||||
<select name="node" id="getIP" class="form-control">
|
||||
<option></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6 hidden">
|
||||
<label for="location" class="control-label">Server Port</label>
|
||||
<div>
|
||||
<select name="node" id="getPort" class="form-control"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var nodeData = null;
|
||||
var currentLocation = null;
|
||||
var currentNode = null;
|
||||
$('#getLocation').on('change', function (event) {
|
||||
|
||||
if ($('#getLocation').val() === '' || $('#getLocation').val() === currentLocation) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentLocation = $('#getLocation').val();
|
||||
currentNode = null;
|
||||
|
||||
// Hide Existing, and Reset contents
|
||||
$('#getNode').html('<option></option>').parent().parent().addClass('hidden');
|
||||
$('#getIP').html('<option></option>').parent().parent().addClass('hidden');
|
||||
$('#getPort').html('').parent().parent().addClass('hidden');
|
||||
|
||||
handleLoader(true);
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '/admin/ajax/new/server/get-nodes',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
data: {
|
||||
location: $('#getLocation').val()
|
||||
}
|
||||
}).done(function (data) {
|
||||
var data = $.parseJSON(data);
|
||||
$.each(data, function (i, item) {
|
||||
var isPublic = (item.public !== 1) ? '(Private Node)' : '';
|
||||
$('#getNode').append('<option value="' + item.id + '">' + item.name + ' ' + isPublic + '</option>');
|
||||
});
|
||||
$('#getNode').parent().parent().removeClass('hidden')
|
||||
}).fail(function (jqXHR) {
|
||||
alert('An error occured while attempting to load a list of nodes in this location.');
|
||||
console.log(jqXHR);
|
||||
}).always(function () {
|
||||
handleLoader();
|
||||
})
|
||||
});
|
||||
$('#getNode').on('change', function (event) {
|
||||
|
||||
if ($('#getNode').val() === '' || $('#getNode').val() === currentNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentNode = $('#getNode').val();
|
||||
|
||||
// Hide Existing, and Reset contents
|
||||
$('#getIP').html('<option></option>').parent().parent().addClass('hidden');
|
||||
$('#getPort').html('').parent().parent().addClass('hidden');
|
||||
|
||||
handleLoader(true);
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '/admin/ajax/new/server/get-ips',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
data: {
|
||||
node: $('#getNode').val()
|
||||
}
|
||||
}).done(function (data) {
|
||||
nodeData = data;
|
||||
$.each(data, function (ip, ports) {
|
||||
$('#getIP').append('<option value="' + ip + '">' + ip + '</option>');
|
||||
});
|
||||
$('#getIP').parent().parent().removeClass('hidden');
|
||||
}).fail(function (jqXHR) {
|
||||
console.log(jqXHR);
|
||||
}).always(function () {
|
||||
handleLoader();
|
||||
});
|
||||
|
||||
});
|
||||
$('#getIP').on('change', function (event) {
|
||||
|
||||
if ($('#getIP').val() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#getPort').html('');
|
||||
|
||||
$.each(nodeData[$('#getIP').val()], function (i, port) {
|
||||
$('#getPort').append('<option value="' + port +'">' + port + '</option>');
|
||||
});
|
||||
|
||||
$('#getPort').parent().parent().removeClass('hidden');
|
||||
|
||||
});
|
||||
|
||||
// Show Loading Animation
|
||||
function handleLoader (show) {
|
||||
|
||||
// Show Animation
|
||||
if (show === true){
|
||||
var height = $('#load_settings').height();
|
||||
var width = $('#load_settings').width();
|
||||
var center_height = (height / 2) - 16;
|
||||
var center_width = (width / 2) - 16;
|
||||
$('#position_me').css({
|
||||
'top': center_height,
|
||||
'left': center_width,
|
||||
'font-size': '32px'
|
||||
});
|
||||
$(".ajax_loading_box").css({
|
||||
'height': height,
|
||||
'margin': '-20px 0 0 -5px',
|
||||
'width': width
|
||||
}).fadeIn();
|
||||
} else {
|
||||
$('.ajax_loading_box').fadeOut(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
@endsection
|
|
@ -23,7 +23,7 @@
|
|||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
<div class="files_loading_box"><i class="fa fa-refresh fa-spin" id="position_me"></i></div>
|
||||
<div class="ajax_loading_box"><i class="fa fa-refresh fa-spin" id="position_me"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -56,7 +56,7 @@
|
|||
// Show Animation
|
||||
if (show === true){
|
||||
var height = $('#load_files').height();
|
||||
var width = $('.files_loading_box').width();
|
||||
var width = $('.ajax_loading_box').width();
|
||||
var center_height = (height / 2) - 30;
|
||||
var center_width = (width / 2) - 30;
|
||||
$('#position_me').css({
|
||||
|
@ -64,9 +64,9 @@
|
|||
'left': center_width,
|
||||
'font-size': '60px'
|
||||
});
|
||||
$(".files_loading_box").css('height', (height + 5)).fadeIn();
|
||||
$(".ajax_loading_box").css('height', (height + 5)).fadeIn();
|
||||
} else {
|
||||
$('.files_loading_box').fadeOut(100);
|
||||
$('.ajax_loading_box').fadeOut(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue