adds support for viewing server stats from 'Your Servers' page
http://s3.pterodactyl.io/bnSTK.png
This commit is contained in:
parent
69f0340c48
commit
09d28bf145
5 changed files with 65 additions and 38 deletions
|
@ -33,7 +33,7 @@ class IndexController extends Controller
|
|||
public function getIndex(Request $request)
|
||||
{
|
||||
return view('base.index', [
|
||||
'servers' => Server::getUserServers(),
|
||||
'servers' => Server::getUserServers(10),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,11 @@ class AjaxController extends Controller
|
|||
{
|
||||
|
||||
$server = Server::getByUUID($uuid);
|
||||
|
||||
if (!$server) {
|
||||
return response()->json([], 404);
|
||||
}
|
||||
|
||||
$client = Node::guzzleRequest($server->node);
|
||||
|
||||
try {
|
||||
|
@ -61,24 +66,19 @@ class AjaxController extends Controller
|
|||
]);
|
||||
|
||||
if($res->getStatusCode() === 200) {
|
||||
|
||||
$json = json_decode($res->getBody());
|
||||
|
||||
if (isset($json->status) && $json->status === 1) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
return response()->json(json_decode($res->getBody()));
|
||||
} else {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
} catch (RequestException $e) {
|
||||
Debugbar::error($e->getMessage());
|
||||
Log::notice('An exception was raised while attempting to contact a Scales instance to get server status information.', [
|
||||
Log::notice('An exception was raised while attempting to contact a daemon instance to get server status information.', [
|
||||
'exception' => $e->getMessage(),
|
||||
'path' => $request->path()
|
||||
]);
|
||||
}
|
||||
|
||||
return 'false';
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,10 +79,10 @@ class Server extends Model
|
|||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getUserServers()
|
||||
public static function getUserServers($paginate = null)
|
||||
{
|
||||
|
||||
$query = self::select('servers.*', 'nodes.name as nodeName', 'locations.long as location')
|
||||
$query = self::select('servers.*', 'nodes.name as nodeName', 'locations.short as a_locationShort')
|
||||
->join('nodes', 'servers.node', '=', 'nodes.id')
|
||||
->join('locations', 'nodes.location', '=', 'locations.id')
|
||||
->where('active', 1);
|
||||
|
@ -91,6 +91,10 @@ class Server extends Model
|
|||
$query->whereIn('servers.id', Subuser::accessServers());
|
||||
}
|
||||
|
||||
if (is_numeric($paginate)) {
|
||||
return $query->paginate($paginate);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue