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' ]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue