|<)/',"",htmlspecialchars($_POST['strfilter'])); $program = strtolower($_POST['program']); switch ($program) { case 'squid': // Define log file $log='/var/squid/logs/access.log'; //show table headers show_tds(array("Date","IP","Status","Address","User","Destination")); //fetch lines $logarr=fetch_log($log); // Print lines foreach ($logarr as $logent) { // Split line by space delimiter $logline = preg_split("/\s+/", $logent); // Apply date format to first line //$logline[0] = date("d.m.Y H:i:s",$logline[0]); // Word wrap the URL $logline[7] = htmlentities($logline[7]); $logline[7] = html_autowrap($logline[7]); // Remove /(slash) in destination row $logline_dest = preg_split("/\//", $logline[9]); // Apply filter and color // Need validate special chars if ($filter != "") $logline = preg_replace("@($filter)@i","$1",$logline); echo "\n"; echo "{$logline[0]} {$logline[1]}\n"; echo "{$logline[3]}\n"; echo "{$logline[4]}\n"; echo "{$logline[7]}\n"; echo "{$logline[8]}\n"; echo "{$logline_dest[1]}\n"; echo "\n"; } break; case 'sguard'; $log='/var/squidGuard/log/block.log'; //show table headers show_tds(array("Date-Time","ACL","Address","Host","User")); //fetch lines $logarr=fetch_log($log); foreach ($logarr as $logent) { // Split line by space delimiter $logline = preg_split("/\s+/", $logent); // Apply time format $logline[0] = date("d.m.Y", strtotime($logline[0])); // Word wrap the URL $logline[4] = htmlentities($logline[4]); $logline[4] = html_autowrap($logline[4]); // Apply filter color // Need validate special chars if ($filter != "") $logline = preg_replace("@($filter)@i","$1",$logline); echo "\n"; echo "{$logline[0]} {$logline[1]}\n"; echo "{$logline[3]}\n"; echo "{$logline[4]}\n"; echo "{$logline[5]}\n"; echo "{$logline[6]}\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 Squid Logs function fetch_log($log){ global $filter,$program; // Get Data from form post $lines = $_POST['maxlines']; if (preg_match("/!/",htmlspecialchars($_POST['strfilter']))) $grep_arg="-iv"; else $grep_arg="-i"; //Check program to execute or no the parser if($program == "squid") $parser = "| php -q squid_log_parser.php"; else $parser = ""; // Get logs based in filter expression if($filter != "") { exec("tail -2000 {$log} | /usr/bin/grep {$grep_arg} " . escapeshellarg($filter). " | tail -r -n {$lines} {$parser} " , $logarr); } else { exec("tail -r -n {$lines} {$log} {$parser}", $logarr); } // return logs return $logarr; }; function show_tds($tds){ echo "\n"; foreach ($tds as $td){ echo "".gettext($td)."\n"; } echo "\n"; } ?>