/** * Perform command. */ public function perform() { try { $entry = []; $parser = new \Kassner\LogParser\LogParser(); $parser->setFormat('%h %l %u %t "%r" %>s %O "%{Referer}i" \\"%{User-Agent}i"'); $lines = file('/var/log/apache2/access.log', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as &$line) { $userSpec = $parser->parse($line); $userSpec->device = parse_user_agent($userSpec->HeaderUserAgent); $city = new Reader(__DIR__ . '/../Database/GeoLite2-City.mmdb'); $country = new Reader(__DIR__ . '/../Database/GeoLite2-Country.mmdb'); $userSpec->location = ['city' => $city->city($userSpec->host)->city->name, 'country' => $country->country($userSpec->host)->country->name]; $entry[] = $userSpec; } file_put_contents('/var/log/apache2/access.log', ''); } catch (\Exception $e) { file_put_contents('/var/log/apache2/access.log', ''); } if (count($entry) > 0) { AccessReport::odmCollection()->batchInsert($entry); print "wrote " . count($entry) . " records"; } else { print 0; } }
public function uniquesthismonthAction() { return ['month' => count(AccessReport::odmCollection()->distinct('host', ['stamp' => ['$gt' => time() - 86400 * 30]])), 'day' => count(AccessReport::odmCollection()->distinct('host', ['stamp' => ['$gt' => time() - 86400]])), 'week' => count(AccessReport::odmCollection()->distinct('host', ['stamp' => ['$gt' => time() - 86400 * 7]]))]; }