Пример #1
0
 private function queryServer($id, $server, $data)
 {
     // Add required fields
     $data['serverid'] = $id;
     $data['auth'] = $server['auth'];
     // Connect and send the data
     $fs = @fsockopen($server['host'], $server['port'], $errno, $errstr, Config::get('lowendping.query.timeout', 5));
     if (!$fs) {
         // mark as unable to connect so we aren't waiting forever
         $resp = new QueryResponse();
         $resp->query_id = $data['id'];
         $resp->server_id = $id;
         $resp->response = 'Failed to connect.';
         $resp->save();
         return;
     }
     fwrite($fs, json_encode($data));
     fclose($fs);
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Clean unsent responses older than 30 minutes, since the client likely exited the page.
     $unsent_min = \Carbon\Carbon::now()->subMinutes(30);
     QueryResponse::unsent()->where('created_at', '<', $unsent_min)->delete();
     // Check the archive
     if (Config::get('lowendping.archive.enabled', false)) {
         $mintime = \Carbon\Carbon::now()->subDays(Config::get('lowendping.archive.days'));
         $queries = Query::where('created_at', '<', $mintime)->get();
         foreach ($queries as $query) {
             $this->info('Deleting query ' . $query->id);
             QueryResponse::where('query_id', $query->id)->delete();
             $query->delete();
         }
     }
 }
Пример #3
0
 /**
  * @param string JSON'ified string we'll receive from ZeroMQ
  */
 public function onServerResponse($entry)
 {
     $entryData = json_decode($entry, true);
     // If the lookup topic object isn't set there is no one to publish to
     if (!array_key_exists($entryData['query_id'], $this->subscribedTopics)) {
         return;
     }
     $response = \QueryResponse::where('query_id', $entryData['query_id'])->where('server_id', $entryData['server_id']);
     if ($response) {
         if (\Config::get('lowendping.archive.enabled', false)) {
             $response->update(array('sent' => 1));
         } else {
             $response->delete();
         }
     }
     $topic = $this->subscribedTopics[$entryData['query_id']];
     // re-send the data to all the clients subscribed to that category
     $topic->broadcast($entryData);
 }
Пример #4
0
 public function serverResponse()
 {
     $validator = Validator::make(Input::all(), array('id' => array('required', 'exists:queries,id'), 'serverid' => array('required', 'server'), 'response' => array('required'), 'auth' => array('required')));
     if ($validator->fails()) {
         return Response::json(array('success' => false, 'error' => $validator->messages()->first()));
     }
     $query = Query::find(Input::get('id'));
     $serverid = Input::get('serverid');
     $servers = Config::get('lowendping.servers');
     if (QueryResponse::where('server_id', $serverid)->where('query_id', $query->id)->count() > 0) {
         return Response::json(array('success' => false, 'error' => 'Response already logged!'));
     }
     if (!Input::has('auth') || Input::get('auth') != $servers[$serverid]['auth']) {
         // Should we be doing this? It makes sense since it could be a valid error.
         $this->submitResponse($query, $serverid, 'Invalid response authentication.');
         return Response::json(array('success' => false, 'error' => 'Invalid authentication!'));
     }
     $this->submitResponse($query, $serverid, Input::get('response'));
 }