|<)/',"",htmlspecialchars($_GET['strfilter']));
$logtype = strtolower($_GET['logtype']);
switch ($logtype) {
case 'access':
//192.168.15.227 - - [02/Jul/2012:19:57:29 -0300] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q (internal dummy connection)"
$regex = '/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) "([^"]*)" "([^"]*)"$/i';
// Define log file
$log='/var/log/httpd-access.log';
//fetch lines
$logarr=fetch_log($log);
/*
// Print lines
foreach ($logarr as $logent) {
// Split line by space delimiter
$logline = preg_split("/\n/", $logent);
// Apply filter and color
// Need validate special chars
if ($filter != "")
$logline = preg_replace("@($filter)@i","$1",$logline);
echo $logline[0]."\n
";
}
*/
$x=1;
foreach ($logarr as $logent) {
$logline = preg_split("/\n/", $logent);
if (preg_match($regex, $logline[0],$line)) {
echo "campo 1: $line[1]
";
echo "campo 2: $line[2]
";
echo "campo 3: $line[3]
";
echo "campo 4: $line[4]
";
echo "campo 5: $line[5]
";
echo "campo 6: $line[6]
";
echo "campo 7: $line[7]
";
echo "campo 8: $line[8]
";
echo "campo 9: $line[9]
";
echo "campo 10: $line[10]
";
echo "campo 11: $line[11]
";
echo "campo 12: $line[12]
";
echo "campo 13: $line[13]
";
}
echo "$x ===================
";
$x++;
}
break;
case 'error':
//[Wed Jul 04 20:22:28 2012] [error] [client 187.10.53.87] proxy: DNS lookup failure for: 192.168.15.272 returned by /
$regex = $regex = '/^\[([^\]]+)\] \[([^\]]+)\] (?:\[client ([^\]]+)\])?\s*(.*)$/i';
// Define log file
$log='/var/log/httpd-error.log';
//fetch lines
$logarr=fetch_log($log);
/*
// Print lines
foreach ($logarr as $logent) {
// Split line by space delimiter
$logline = preg_split("/\n/", $logent);
// Apply filter and color
// Need validate special chars
if ($filter != "")
$logline = preg_replace("@($filter)@i","$1",$logline);
echo $logline[0]."\n
";
}
*/
$x=1;
foreach ($logarr as $logent) {
$logline = preg_split("/\n/", $logent);
if (preg_match($regex, $logline[0],$line)) {
echo "campo 1: $line[1]
";
echo "campo 2: $line[2]
";
echo "campo 3: $line[3]
";
echo "campo 4: $line[4]
";
echo "campo 5: $line[5]
";
echo "campo 6: $line[6]
";
echo "campo 7: $line[7]
";
echo "campo 8: $line[8]
";
echo "campo 9: $line[9]
";
echo "campo 10: $line[10]
";
echo "campo 11: $line[11]
";
echo "campo 12: $line[12]
";
echo "campo 13: $line[13]
";
}
echo "$x ===================
";
$x++;
}
break;
}
}
# ------------------------------------------------------------------------------
# Functions
# ------------------------------------------------------------------------------
// Show Squid Logs
function fetch_log($log){
global $filter;
// Get Data from form post
$lines = $_GET['maxlines'];
if (preg_match("/!/",htmlspecialchars($_GET['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;
}
foreach ($config['installedpackages']['apachevirtualhost']['config'] as $virtualhost){
if (is_array($virtualhost['row']) && $virtualhost['enable'] == 'on'){
if (preg_match("/(\S+)/",base64_decode($virtualhost['primarysitehostname']),$matches)) {
echo $matches[1]."
";
}
}
}
?>