. Copyright (C) 2003-2004 Manuel Kasper . Copyright (C) 2006 Scott Ullrich Copyright (C) 2009 Robert Zelaya Sr. Developer Copyright (C) 2012 Ermal Luci All rights reserved. Adapted for Suricata by: Copyright (C) 2015 Bill Meeks All rights reserved. Javascript and Integration modifications by J. Nieuwenhuizen Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("globals.inc"); require_once("/usr/local/pkg/pfblockerng/pfblockerng.inc"); pfb_global(); // Get log files from directory function getlogs($logdir, $log_extentions = array('log')) { if (!is_array($log_extentions)) { $log_extentions = array($log_extentions); } // Get logfiles $log_filenames = array(); foreach ($log_extentions as $extention) { if ($extention <> '*') { $log_filenames = array_merge($log_filenames, glob($logdir . "*." . $extention)); } else { $log_filenames = array_merge($log_filenames, glob($logdir . "*")); } } // Convert to filenames only if (count($log_filenames) > 0) { $log_totalfiles = count($log_filenames); for ($cnt = 0; $cnt < $log_totalfiles; $cnt++) { $log_filenames[$cnt] = basename($log_filenames[$cnt]); } } // Sort the filename asort($log_filenames); // Done return $log_filenames; } /* Define logtypes: name => Displayname of the type ext => Log extentions (array for multiple extentions) logdir => Log directory clear => Add clear button (TRUE/FALSE) */ $pfb_logtypes = array( 'defaultlogs' => array('name' => 'Log Files', 'logdir' => "{$pfb['logdir']}/", 'logs' => array("pfblockerng.log", "error.log", "geoip.log", "maxmind_ver"), 'download' => TRUE, 'clear' => TRUE ), 'masterfiles' => array('name' => 'Masterfiles', 'logdir' => "{$pfb['dbdir']}/", 'logs' => array("masterfile", "mastercat"), 'download' => TRUE, 'clear' => FALSE ), 'originallogs' => array('name' => 'Original Files', 'ext' => array('orig', 'raw'), 'logdir' => "{$pfb['origdir']}/", 'download' => TRUE, 'clear' => TRUE ), 'denylogs' => array('name' => 'Deny Files', 'ext' => 'txt', 'txt' => 'deny', 'logdir' => "{$pfb['denydir']}/", 'download' => TRUE, 'clear' => TRUE ), 'permitlogs' => array('name' => 'Permit Files', 'ext' => 'txt', 'txt' => 'permit', 'logdir' => "{$pfb['permitdir']}/", 'download' => TRUE, 'clear' => TRUE ), 'matchlogs' => array('name' => 'Match Files', 'ext' => 'txt', 'txt' => 'match', 'logdir' => "{$pfb['matchdir']}/", 'download' => TRUE, 'clear' => TRUE ), 'nativelogs' => array('name' => 'Native Files', 'ext' => 'txt', 'logdir' => "{$pfb['nativedir']}/", 'download' => TRUE, 'clear' => TRUE ), 'aliaslogs' => array('name' => 'Alias Files', 'ext' => 'txt', 'logdir' => "{$pfb['aliasdir']}/", 'download' => TRUE, 'clear' => FALSE ), 'etiprep' => array('name' => 'ET IPRep Files', 'ext' => '*', 'logdir' => "{$pfb['etdir']}/", 'download' => TRUE, 'clear' => FALSE ), 'country' => array('name' => 'Country Files', 'ext' => 'txt', 'logdir' => "{$pfb['ccdir']}/", 'download' => TRUE, 'clear' => FALSE ) ); // Check logtypes $logtypeid = 'defaultlogs'; if (isset($_POST['logtype'])) { $logtypeid = $_POST['logtype']; } elseif (isset($_GET['logtype'])) { $logtypeid = htmlspecialchars($_GET['logtype']); } // Check if POST has been set if (isset($_POST['file'])) { clearstatcache(); $pfb_logfilename = $_POST['file']; $pfb_ext = pathinfo($pfb_logfilename, PATHINFO_EXTENSION); // Load log if ($_POST['action'] == 'load') { if (!is_file($pfb_logfilename)) { echo "|3|" . gettext("Log file is empty or does not exist") . ".|"; } else { $data = file_get_contents($pfb_logfilename); if ($data === false) { echo "|1|" . gettext("Failed to read log file") . ".|"; } else { $data = base64_encode($data); echo "|0|" . $pfb_logfilename . "|" . $data . "|"; } } exit; } } if (isset($_POST['logFile'])) { $s_logfile = $_POST['logFile']; // Clear selected file if (isset($_POST['clear'])) { unlink_if_exists($s_logfile); } // Download log if (isset($_POST['download'])) { if (file_exists($s_logfile)) { ob_start(); //important or other posts will fail if (isset($_SERVER['HTTPS'])) { header('Pragma: '); header('Cache-Control: '); } else { header("Pragma: private"); header("Cache-Control: private, must-revalidate"); } header("Content-Type: application/octet-stream"); header("Content-length: " . filesize($s_logfile)); header("Content-disposition: attachment; filename = " . basename($s_logfile)); ob_end_clean(); //important or other post will fail readfile($s_logfile); } } } else { $s_logfile = ""; } $pgtitle = gettext("pfBlockerNG: Log Browser"); include_once("head.inc"); ?> "); if ($savemsg) { print_info_box($savemsg); } ?>