|<)/',"",htmlspecialchars($_REQUEST['strfilter'])); $logtype = strtolower($_REQUEST['logtype']); // Get log type (access or error) if ($logtype == "error") $error="-error"; // Define log file name $logfile ='/var/log/httpd-'. preg_replace("/(\s|'|\"|;)/","",$_REQUEST['logfile']) . $error.'.log'; if ($logfile == '/var/log/httpd-access-error.log') $logfile = '/var/log/httpd-error.log'; //debug echo "\n"; echo "$logfile\n"; if (file_exists($logfile)){ switch ($logtype) { case 'access': //show table headers show_tds(array("Time","Host","Response","Method","Request")); //fetch lines $logarr=fetch_log($logfile); // Print lines foreach ($logarr as $logent) { // Split line by space delimiter $logline = preg_split("/\n/", $logent); /* field 1: 189.29.36.26 field 2: - field 3: - field 4: 04/Jul/2012 field 5: 10:54:39 field 6: -0300 field 7: GET field 8: / field 9: HTTP/1.1 field 10: 303 field 11: - field 12: - field 13: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/12.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19 */ $regex = '/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) "([^"]*)" "([^"]*)"$/'; if (preg_match($regex, $logline[0],$line)) { // Apply filter and color if ($filter != "") $line = preg_replace("@($filter)@i","$1",$line); $agent_info="onmouseover=\"jQuery('#bowserinfo').empty().html('{$line[13]}');\"\n"; echo "\n"; echo "{$line[5]}({$line[6]})\n"; echo "{$line[1]}\n"; echo "{$line[10]}\n"; echo "{$line[7]}\n"; //echo "{$line[8]}\n"; echo "{$line[8]}\n"; echo "\n"; } } break; case 'error': //show table headers show_tds(array("DateTime","Severity","Message")); //fetch lines $logarr=fetch_log($logfile); // Print lines foreach ($logarr as $logent) { // Split line by space delimiter $logline = preg_split("/\n/", $logent); /* field 1: Wed Jul 04 20:22:28 2012 field 2: error field 3: 187.10.53.87 field 4: proxy: DNS lookup failure for: 192.168.15.272 returned by / */ $regex = '/^\[([^\]]+)\] \[([^\]]+)\] (?:\[client ([^\]]+)\])?\s*(.*)$/i'; if (preg_match($regex, $logline[0],$line)) { // Apply filter and color if ($filter != "") $line = preg_replace("@($filter)@i","$1",$line); if ($line[3]) $line[3] = gettext("Client address:") . " [{$line[3]}]"; echo "\n"; echo "{$line[1]}\n"; echo "{$line[2]}\n"; echo "{$line[3]} {$line[4]}\n"; echo "\n"; } } break; } } } # ------------------------------------------------------------------------------ # Functions # ------------------------------------------------------------------------------ // From SquidGuard Package function html_autowrap($cont) { # split strings $p = 0; $pstep = 25; $str = $cont; $cont = ''; for ( $p = 0; $p < strlen($str); $p += $pstep ) { $s = substr( $str, $p, $pstep ); if ( !$s ) break; $cont .= $s . ""; } return $cont; } // Show Logs function fetch_log($log){ global $filter; // Get Data from form post $lines = $_REQUEST['maxlines']; if (preg_match("/!/",htmlspecialchars($_REQUEST['strfilter']))) $grep_arg="-iv"; else $grep_arg="-i"; // Get logs based in filter expression if($filter != "") { exec("tail -2000 {$log} | /usr/bin/grep {$grep_arg} " . escapeshellarg($filter). " | tail -r -n {$lines}" , $logarr); } else { exec("tail -r -n {$lines} {$log}", $logarr); } // return logs return $logarr; } function show_tds($tds){ echo "\n"; foreach ($tds as $td){ echo "".gettext($td)."\n"; } echo "\n"; } ?>