2016-01-05 04:59:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use Alert;
|
|
|
|
use Debugbar;
|
|
|
|
use Log;
|
|
|
|
use DB;
|
|
|
|
|
|
|
|
use Pterodactyl\Models;
|
|
|
|
use Pterodactyl\Repositories\NodeRepository;
|
|
|
|
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class NodesController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIndex(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.nodes.index', [
|
|
|
|
'nodes' => Models\Node::select(
|
|
|
|
'nodes.*',
|
|
|
|
'locations.long as a_locationName',
|
|
|
|
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node = nodes.id) as a_serverCount')
|
|
|
|
)->join('locations', 'nodes.location', '=', 'locations.id')->paginate(20),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNew(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.nodes.new', [
|
|
|
|
'locations' => Models\Location::all()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postNew(Request $request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$node = new NodeRepository;
|
|
|
|
$new = $node->create($request->except([
|
|
|
|
'_token'
|
|
|
|
]));
|
|
|
|
Alert::success('Successfully created new node. You should allocate some IP addresses to it now.')->flash();
|
|
|
|
return redirect()->route('admin.nodes.view', [
|
|
|
|
'id' => $new
|
|
|
|
]);
|
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayValidationException $e) {
|
|
|
|
return redirect()->route('admin.nodes.new')->withErrors(json_decode($e->getMessage()))->withInput();
|
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayException $e) {
|
|
|
|
Alert::danger($e->getMessage())->flash();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e);
|
|
|
|
Alert::danger('An unhandled exception occured while attempting to add this node. Please try again.')->flash();
|
|
|
|
}
|
|
|
|
return redirect()->route('admin.nodes.new')->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getView(Request $request, $id)
|
|
|
|
{
|
|
|
|
$node = Models\Node::findOrFail($id);
|
|
|
|
return view('admin.nodes.view', [
|
2016-01-05 05:52:20 +00:00
|
|
|
'node' => $node,
|
|
|
|
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
|
|
|
|
->join('users', 'users.id', '=', 'servers.owner')
|
|
|
|
->join('services', 'services.id', '=', 'servers.service')
|
2016-01-05 23:31:25 +00:00
|
|
|
->where('node', $id)->paginate(10),
|
|
|
|
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
|
|
|
|
'locations' => Models\Location::all(),
|
2016-01-05 04:59:45 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-01-05 23:31:25 +00:00
|
|
|
public function postView(Request $request, $id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$node = new NodeRepository;
|
|
|
|
$node->update($id, $request->except([
|
|
|
|
'_token'
|
|
|
|
]));
|
|
|
|
Alert::success('Successfully update this node\'s information. If you changed any daemon settings you will need to restart it now.')->flash();
|
|
|
|
return redirect()->route('admin.nodes.view', [
|
|
|
|
'id' => $id,
|
|
|
|
'tab' => 'tab_settings'
|
|
|
|
]);
|
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayValidationException $e) {
|
|
|
|
return redirect()->route('admin.nodes.view', $id)->withErrors(json_decode($e->getMessage()))->withInput();
|
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayException $e) {
|
|
|
|
Alert::danger($e->getMessage())->flash();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e);
|
|
|
|
Alert::danger('An unhandled exception occured while attempting to edit this node. Please try again.')->flash();
|
|
|
|
}
|
|
|
|
return redirect()->route('admin.nodes.view', [
|
|
|
|
'id' => $id,
|
|
|
|
'tab' => 'tab_settings'
|
|
|
|
])->withInput();
|
|
|
|
}
|
|
|
|
|
2016-01-05 04:59:45 +00:00
|
|
|
}
|