/** * Check if info or master password is set as token in the request * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string $tokenType * @return mixed */ public function handle($request, Closure $next, $tokenType) { $token = $request->input('token') ?: $request->header('TOKEN'); if ($tokenType == 'info') { if ($token != getInfoPassword()) { abort(401); } } if ($tokenType == 'master') { if ($token != getMasterPassword()) { abort(401); } } return $next($request); }
/** * Call the a Slave to get his informations and the informations about his slaves * * @TODO Refactor Errorhandling * @param string $slave * @return array */ private function getSlaveInformations($slave) { $server = []; try { $response = $this->client->get($slave . ApiUrl::$server_matrix . '?token=' . getInfoPassword(), ['timeout' => $this->timeout])->getBody(); $response = json_decode($response, true); $server = array_merge(['status' => ServerStatusCode::code('available')], $response); } catch (ConnectException $e) { $server = ['status' => ServerStatusCode::code('unavailable'), 'url' => $slave]; } catch (ClientException $e) { $server = ['status' => ServerStatusCode::code('token_incorrect'), 'url' => $slave]; } catch (ServerException $e) { $server = ['status' => ServerStatusCode::code('host_cannot_resolved'), 'url' => $slave]; } return $server; }