/** * 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(); } } }
/** * @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); }
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')); }