2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
use Alert;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Debugbar;
|
2015-12-15 20:08:41 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models;
|
2015-12-14 03:22:16 +00:00
|
|
|
use Pterodactyl\Repositories\ServerRepository;
|
2015-12-15 20:08:41 +00:00
|
|
|
|
|
|
|
use Pterodactly\Exceptions\DisplayException;
|
|
|
|
use Pterodactly\Exceptions\DisplayValidationException;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ServersController 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 getIndex(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.servers.index', [
|
2015-12-15 20:08:41 +00:00
|
|
|
'servers' => Models\Server::select('servers.*', 'nodes.name as a_nodeName', 'users.email as a_ownerEmail')
|
2015-12-06 18:58:49 +00:00
|
|
|
->join('nodes', 'servers.node', '=', 'nodes.id')
|
|
|
|
->join('users', 'servers.owner', '=', 'users.id')
|
|
|
|
->paginate(20),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNew(Request $request)
|
|
|
|
{
|
2015-12-07 05:47:19 +00:00
|
|
|
return view('admin.servers.new', [
|
2015-12-15 20:08:41 +00:00
|
|
|
'locations' => Models\Location::all(),
|
|
|
|
'services' => Models\Service::all()
|
2015-12-07 05:47:19 +00:00
|
|
|
]);
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getView(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2015-12-10 23:30:47 +00:00
|
|
|
public function postNewServer(Request $request)
|
|
|
|
{
|
2015-12-12 04:28:58 +00:00
|
|
|
|
|
|
|
try {
|
2015-12-15 20:08:41 +00:00
|
|
|
|
2015-12-14 03:22:16 +00:00
|
|
|
$server = new ServerRepository;
|
2015-12-15 20:08:41 +00:00
|
|
|
$response = $server->create($request->all());
|
|
|
|
|
|
|
|
return redirect()->route('admin.servers.view', [ 'id' => $response ]);
|
|
|
|
|
2015-12-12 04:28:58 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
if ($e instanceof \Pterodactyl\Exceptions\DisplayValidationException) {
|
|
|
|
return redirect()->route('admin.servers.new')->withErrors(json_decode($e->getMessage()))->withInput();
|
|
|
|
} else if ($e instanceof \Pterodactyl\Exceptions\DisplayException) {
|
|
|
|
Alert::danger($e->getMessage())->flash();
|
|
|
|
} else {
|
|
|
|
Debugbar::addException($e);
|
|
|
|
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('admin.servers.new')->withInput();
|
|
|
|
|
|
|
|
}
|
2015-12-12 04:28:58 +00:00
|
|
|
|
2015-12-10 23:30:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JSON tree of all avaliable nodes in a given location.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function postNewServerGetNodes(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$request->input('location')) {
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'Missing location in request.'
|
|
|
|
], 500);
|
|
|
|
}
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
return response()->json(Models\Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get());
|
2015-12-10 23:30:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JSON tree of all avaliable IPs and Ports on a given node.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function postNewServerGetIps(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$request->input('node')) {
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'Missing node in request.'
|
|
|
|
], 500);
|
|
|
|
}
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
$ips = Models\Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get();
|
2015-12-10 23:30:47 +00:00
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JSON tree of all avaliable options for a given service.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function postNewServerServiceOptions(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$request->input('service')) {
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'Missing service in request.'
|
|
|
|
], 500);
|
|
|
|
}
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get());
|
2015-12-10 23:30:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JSON tree of all avaliable variables for a given service option.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function postNewServerServiceVariables(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$request->input('option')) {
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'Missing option in request.'
|
|
|
|
], 500);
|
|
|
|
}
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
return response()->json(Models\ServiceVariables::where('option_id', $request->input('option'))->get());
|
2015-12-10 23:30:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|