| @@ 48-68 (lines=21) @@ | ||
| 45 | * @throws DisplayException |
|
| 46 | * @throws RequestException |
|
| 47 | */ |
|
| 48 | public function send($command) |
|
| 49 | { |
|
| 50 | // We don't use the user's specific daemon secret here since we |
|
| 51 | // are assuming that a call to this function has been validated. |
|
| 52 | // Additionally not all calls to this will be from a logged in user. |
|
| 53 | // (e.g. task queue or API) |
|
| 54 | try { |
|
| 55 | $response = $this->server->node->guzzleClient([ |
|
| 56 | 'X-Access-Token' => $this->server->daemonSecret, |
|
| 57 | 'X-Access-Server' => $this->server->uuid, |
|
| 58 | ])->request('POST', '/server/command', ['json' => ['command' => $command]]); |
|
| 59 | ||
| 60 | if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
|
| 61 | throw new DisplayException('Command sending responded with a non-200 error code.'); |
|
| 62 | } |
|
| 63 | ||
| 64 | return $response->getBody(); |
|
| 65 | } catch (\Exception $ex) { |
|
| 66 | throw $ex; |
|
| 67 | } |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||
| @@ 40-60 (lines=21) @@ | ||
| 37 | $this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($server); |
|
| 38 | } |
|
| 39 | ||
| 40 | public function do($action) |
|
| 41 | { |
|
| 42 | // We don't use the user's specific daemon secret here since we |
|
| 43 | // are assuming that a call to this function has been validated. |
|
| 44 | // Additionally not all calls to this will be from a logged in user. |
|
| 45 | // (e.g. task queue or API) |
|
| 46 | try { |
|
| 47 | $response = $this->server->node->guzzleClient([ |
|
| 48 | 'X-Access-Token' => $this->server->daemonSecret, |
|
| 49 | 'X-Access-Server' => $this->server->uuid, |
|
| 50 | ])->request('PUT', '/server/power', ['json' => ['action' => $action]]); |
|
| 51 | ||
| 52 | if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
|
| 53 | throw new DisplayException('Power status responded with a non-200 error code.'); |
|
| 54 | } |
|
| 55 | ||
| 56 | return $response->getBody(); |
|
| 57 | } catch (\Exception $ex) { |
|
| 58 | throw $ex; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| 62 | public function start() |
|
| 63 | { |
|