/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed * @throws AuthenticationException */ public function handle($request, Closure $next) { try { $node = $this->ACSNodeRepository->findByAPIKey($request->header('ApiKey')); } catch (\Exception $e) { throw new AuthenticationException("API Key Invalid"); } //Possibly do some checking here on the access rights for the acs node return $next($request); }
/** * Execute the console command. * * @return mixed */ public function handle() { foreach ($this->acsNodeRepository->getAll() as $device) { $this->info('Checking device ' . $device->name); /** @var $device \BB\Entities\ACSNode */ if ($device->heartbeatWarning()) { $this->warn('Heartbeat warning'); //There is a warning with the device, see if people have been notified $notificationHash = $device->device_id . md5($device->last_heartbeat->timestamp); $message = 'Nothing has been heard from device "' . $device->name . '"" in a while. '; $message .= 'The last update was ' . \Carbon\Carbon::now()->diffForHumans($device->last_heartbeat, true) . ' ago.'; $role = Role::findByName('acs'); foreach ($role->users()->get() as $user) { $this->info(' Notifying ' . $user->name); Notification::logNew($user->id, $message, 'device_contact', $notificationHash); } } } }
/** * @param string $receivedData * @return \Illuminate\Http\Response */ public function handleSystemMessage($receivedData) { $receivedData = substr($receivedData, 1, strlen($receivedData)); $messageParts = ["", ""]; if (strpos($receivedData, '|') !== false) { $messageParts = explode('|', $receivedData); } $device = $messageParts[0]; $message = $messageParts[1]; if ($message == 'boot') { $this->acsNodeRepository->logBoot($device); } elseif ($message == 'heartbeat') { $this->acsNodeRepository->logHeartbeat($device); } //Log::debug("System Message: ".$receivedData); return \Response::make(PHP_EOL, 200); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response * * @SWG\Post( * path="/acs/node/heartbeat", * tags={"acs"}, * description="Record a heartbeat message, used to determin if the device is online", * @SWG\Response(response="200", description="Heartbeat recorded"), * security={{"api_key": {}}} * ) */ public function heartbeat(Request $request) { $node = $this->ACSNodeRepository->findByAPIKey($request->header('ApiKey')); $this->ACSNodeRepository->logHeartbeat($node->device_id); }