diff --git a/app/Models/Server.php b/app/Models/Server.php index 8a3725ed6..1ad025ec7 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -150,24 +150,32 @@ class Server extends Model /** * Returns non-administrative headers for accessing a server on the daemon. * + * @param Pterodactyl\Models\User|null $user * @return array */ - public function guzzleHeaders() + public function guzzleHeaders(User $user = null) { + // If no specific user is passed, see if we can find an active + // auth session to pull data from. + if (is_null($user) && Auth::check()) { + $user = Auth::user(); + } + return [ 'X-Access-Server' => $this->uuid, - 'X-Access-Token' => Auth::user()->daemonToken($this), + 'X-Access-Token' => ($user) ? $user->daemonToken($this) : $this->daemonSecret, ]; } /** * Return an instance of the Guzzle client for this specific server using defined access token. * + * @param Pterodactyl\Models\User|null $user * @return \GuzzleHttp\Client */ - public function guzzleClient() + public function guzzleClient(User $user = null) { - return $this->node->guzzleClient($this->guzzleHeaders()); + return $this->node->guzzleClient($this->guzzleHeaders($user)); } /** diff --git a/app/Models/User.php b/app/Models/User.php index b159da9ad..95e39184a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -176,13 +176,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac return $server->daemonSecret; } - $subuser = Subuser::where('server_id', $server->id)->where('user_id', $this->id)->first(); + $subuser = $this->subuserOf->where('server_id', $server->id)->first(); - if (is_null($subuser)) { - return null; - } - - return $subuser->daemonSecret; + return ($subuser) ? $subuser->daemonSecret : null; } /** @@ -193,9 +189,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac */ public function serverAccessArray() { - $union = Subuser::select('server_id')->where('user_id', $this->id); - - return Server::select('id')->where('owner_id', $this->id)->union($union)->pluck('id')->all(); + return Server::select('id')->where('owner_id', $this->id)->union( + Subuser::select('server_id')->where('user_id', $this->id) + )->pluck('id')->all(); } /**