public function parseBlocked() { require FRAMEWORK . DS . 'conf' . DS . 'fortiguardlog.php'; $logs = file($blockedlogfile); $model = new ftgdblockedModel(); $last = $model->getmax('logid'); foreach ($logs as $log) { $logpieces = explode(',', $log); $logpieces = explode(',', $log); $firstpieces = explode(' ', $logpieces[0]); $i = 0; $j = 0; $time = ''; while ($i < 3) { if ($firstpieces[$j] != '') { $time .= $firstpieces[$j] . ' '; $i++; } $j++; } $time = strtotime($time); list($null, $logid) = explode('=', $logpieces[10]); list($null, $user) = explode('=', $logpieces[11]); $user = str_replace('"', '', $user); list($null, $group) = explode('=', $logpieces[12]); $group = str_replace('"', '', $group); list($null, $srcip) = explode('=', $logpieces[13]); list($null, $dstip) = explode('=', $logpieces[16]); list($null, $cat) = explode('=', $logpieces[22]); $cat = str_replace('"', '', $cat); list($null, $host) = explode('=', $logpieces[23]); $host = str_replace('"', '', $host); list($null, $url) = explode('=', $logpieces[25]); $url = str_replace('"', '', $url); if ($logid > $last) { $logobject = new ftgdblockedObject(); $logobject->setLogid($logid); $logobject->setUser($user); $logobject->setGroup($group); $logobject->setSourceip($srcip); $logobject->setDestip($dstip); $logobject->setCat($cat); $logobject->setHost($host); $logobject->setUrl($url); $logobject->setTime($time); $time = date("d/m/Y - H:i:s", $time); echo "Time: {$time}, Log id: {$logid}, user: {$user}, group: {$group}, source ip: {$srcip}, destination ip: {$dstip}, url: {$host}{$url}, Categorie: {$cat}\n<br />"; $model->save($logobject); } } }
<?php // Some constants that should be configured define('DS', '\\'); define('BASE_PATH', 'D:' . DS . 'websites' . DS . 'azl' . DS . 'framework'); define('FRAMEWORK', BASE_PATH); // Get the dispatcher require_once FRAMEWORK . DS . 'dispatcher.php'; // And fire it up try { //$disp = new dispatcher(); } catch (Exception $e) { echo $e->getMessage(); echo $e->getTrace(); } $parser = new ftgdlogparser(); $parser->parseBlocked(); $parser->parseAllowed(); //clear old logs $old = 60 * 60 * 24 * 7 * 4; // 4 weeks $cond = array('time' => array('mode' => '<', 'value' => time() - $old)); $amodel = new ftgdallowedModel(); $bmodel = new ftgdblockedModel(); $amodel->delete($cond); $bmodel->delete($cond);