diff --git a/app/log_viewer/log_viewer.php b/app/log_viewer/log_viewer.php index 5497d6db6f..ebb671fbee 100644 --- a/app/log_viewer/log_viewer.php +++ b/app/log_viewer/log_viewer.php @@ -17,23 +17,27 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('log_view')) { - //access granted -} -else { - echo "access denied"; - exit; -} + +//includes + include "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('log_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; @@ -45,244 +49,246 @@ else { $row_style["1"] = "row_style1"; //set a default line number value (off) - if (!isset($_POST['ln']) || $_POST['ln'] == '') { $_POST['ln'] = 0; } + if (!isset($_POST['line_number']) || $_POST['line_number'] == '') { $_POST['line_number'] = 0; } //set a default ordinal (descending) - if (!isset($_POST['ord']) || $_POST['ord'] == '') { $_POST['ord'] = "asc"; } + if (!isset($_POST['sort']) || $_POST['sort'] == '') { $_POST['sort'] = "asc"; } //set a default file size - if (!isset($_POST['fs']) || strlen($_POST['fs']) == 0) { $_POST['fs'] = "32"; } + if (!isset($_POST['size']) || strlen($_POST['size']) == 0) { $_POST['size'] = "32"; } //set a default filter if (!isset($_POST['filter'])) { $_POST['filter'] = ""; } -if (permission_exists('log_download')) { - if (isset($_GET['a']) && $_GET['a'] == "download") { - if (isset($_GET['t']) && $_GET['t'] == "logs") { - $tmp = $_SESSION['switch']['log']['dir'].'/'; - $filename = 'freeswitch.log'; - } - session_cache_limiter('public'); - $fd = fopen($tmp.$filename, "rb"); - header("Content-Type: binary/octet-stream"); - header("Content-Length: " . filesize($tmp.$filename)); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - fpassthru($fd); - exit; - } -} - -require_once "resources/header.php"; - -echo "\n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " "; -echo " \n"; -echo " "; -echo " \n"; -echo "
\n"; -echo " ".$text['label-log-viewer']."
\n"; -echo "
\n"; -echo "
\n"; -echo " ".$text['label-filter']." "; -echo " "; -echo " "; -echo " Display ".$text['label-kb'].""; -echo " "; -if (permission_exists('log_download')) { - echo " \n"; -} -echo "
\n"; -echo "
 
"; - -if (permission_exists('log_view')) { - - $MAXEL = 3; //pattern2, pattern3|color2, color3 etc... - - $user_filesize = '0'; - $default_color = '#fff'; - $default_type = 'normal'; - $default_font = 'monospace'; - $default_fsize = '512000'; - $log_file = $_SESSION['switch']['log']['dir']."/freeswitch.log"; - - //put the color matches here... - $arr_filter[0]['pattern'] = '[NOTICE]'; - $arr_filter[0]['color'] = 'cyan'; - $arr_filter[0]['type'] = 'normal'; - $arr_filter[0]['font'] = 'monospace'; - - $arr_filter[1]['pattern'] = '[INFO]'; - $arr_filter[1]['color'] = 'chartreuse'; - $arr_filter[1]['type'] = 'normal'; - $arr_filter[1]['font'] = 'monospace'; - - $arr_filter[2]['pattern'] = 'Dialplan:'; - $arr_filter[2]['color'] = 'burlywood'; - $arr_filter[2]['type'] = 'normal'; - $arr_filter[2]['font'] = 'monospace'; - $arr_filter[2]['pattern2'] = 'Regex (PASS)'; - $arr_filter[2]['color2'] = 'chartreuse'; - $arr_filter[2]['pattern3'] = 'Regex (FAIL)'; - $arr_filter[2]['color3'] = 'red'; - - $arr_filter[3]['pattern'] = '[WARNING]'; - $arr_filter[3]['color'] = 'fuchsia'; - $arr_filter[3]['type'] = 'normal'; - $arr_filter[3]['font'] = 'monospace'; - - $arr_filter[4]['pattern'] = '[ERR]'; - $arr_filter[4]['color'] = 'red'; - $arr_filter[4]['type'] = 'bold'; - $arr_filter[4]['font'] = 'monospace'; - - $arr_filter[5]['pattern'] = '[DEBUG]'; - $arr_filter[5]['color'] = 'gold'; - $arr_filter[5]['type'] = 'bold'; - $arr_filter[5]['font'] = 'monospace'; - - $file_size = filesize($log_file); - - /* - // removed: duplicate of above - if (isset($_POST['submit'])) { - if (strlen($_POST['fs']) == 0) { $_POST['fs'] = "32"; } - } - */ - - echo " "; - echo " "; - $user_filesize = '32768'; - if (isset($_POST['submit'])) { - if (!is_numeric($_POST['fs'])){ - //should generate log warning here... - $user_filesize=1024 * 32; - } - else { - $user_filesize = $_POST['fs'] * 1024; - } - if (strlen($_REQUEST['filter']) > 0){ - $uuid_filter = $_REQUEST['filter']; - echo " "; +//download the log + if (permission_exists('log_download')) { + if (isset($_GET['a']) && $_GET['a'] == "download") { + if (isset($_GET['t']) && $_GET['t'] == "logs") { + $tmp = $_SESSION['switch']['log']['dir'].'/'; + $filename = 'freeswitch.log'; + } + session_cache_limiter('public'); + $fd = fopen($tmp.$filename, "rb"); + header("Content-Type: binary/octet-stream"); + header("Content-Length: " . filesize($tmp.$filename)); + header('Content-Disposition: attachment; filename="'.escape($filename).'"'); + fpassthru($fd); + exit; } } - //echo "Log File Size: " . $file_size . " bytes.
"; - echo " "; - echo " "; - echo "
".$text['description-filter']." ".$uuid_filter."".$text['label-displaying']." ".number_format($user_filesize,0,'.',',')." of ".number_format($file_size,0,'.',',')." ".$text['label-bytes'].".
"; - echo "
"; +//include the header + require_once "resources/header.php"; - $file = fopen($log_file, "r") or exit($text['error-open-file']); +//show the content + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " "; + echo " \n"; + echo " "; + echo " \n"; + echo "
\n"; + echo " ".$text['label-log_viewer']."
\n"; + echo "
\n"; + echo "
\n"; + echo " ".$text['label-filter']." "; + echo " "; + echo " "; + echo " Display ".$text['label-size'].""; + echo " "; + if (permission_exists('log_download')) { + echo " \n"; + } + echo "
\n"; + echo "
 
"; - //set pointer in file - if ($user_filesize >= '0') { - if ($user_filesize == '0'){ - $user_filesize = $default_fsize; + if (permission_exists('log_view')) { + + $MAXEL = 3; //pattern2, pattern3|color2, color3 etc... + + $user_file_size = '0'; + $default_color = '#fff'; + $default_type = 'normal'; + $default_font = 'monospace'; + $default_file_size = '512000'; + $log_file = $_SESSION['switch']['log']['dir']."/freeswitch.log"; + + //put the color matches here... + $array_filter[0]['pattern'] = '[NOTICE]'; + $array_filter[0]['color'] = 'cyan'; + $array_filter[0]['type'] = 'normal'; + $array_filter[0]['font'] = 'monospace'; + + $array_filter[1]['pattern'] = '[INFO]'; + $array_filter[1]['color'] = 'chartreuse'; + $array_filter[1]['type'] = 'normal'; + $array_filter[1]['font'] = 'monospace'; + + $array_filter[2]['pattern'] = 'Dialplan:'; + $array_filter[2]['color'] = 'burlywood'; + $array_filter[2]['type'] = 'normal'; + $array_filter[2]['font'] = 'monospace'; + $array_filter[2]['pattern2'] = 'Regex (PASS)'; + $array_filter[2]['color2'] = 'chartreuse'; + $array_filter[2]['pattern3'] = 'Regex (FAIL)'; + $array_filter[2]['color3'] = 'red'; + + $array_filter[3]['pattern'] = '[WARNING]'; + $array_filter[3]['color'] = 'fuchsia'; + $array_filter[3]['type'] = 'normal'; + $array_filter[3]['font'] = 'monospace'; + + $array_filter[4]['pattern'] = '[ERR]'; + $array_filter[4]['color'] = 'red'; + $array_filter[4]['type'] = 'bold'; + $array_filter[4]['font'] = 'monospace'; + + $array_filter[5]['pattern'] = '[DEBUG]'; + $array_filter[5]['color'] = 'gold'; + $array_filter[5]['type'] = 'bold'; + $array_filter[5]['font'] = 'monospace'; + + $file_size = filesize($log_file); + + /* + // removed: duplicate of above + if (isset($_POST['submit'])) { + if (strlen($_POST['size']) == 0) { $_POST['size'] = "32"; } } - if ( $file_size >= $user_filesize ){ - //set an offset on fopen - $bytecount=$file_size-$user_filesize; - fseek($file, $bytecount); - //echo "opening at " . $bytecount . " bytes
"; + */ + + echo " "; + echo " "; + $user_file_size = '32768'; + if (isset($_POST['submit'])) { + if (!is_numeric($_POST['size'])){ + //should generate log warning here... + $user_file_size=1024 * 32; + } + else { + $user_file_size = $_POST['size'] * 1024; + } + if (strlen($_REQUEST['filter']) > 0){ + $uuid_filter = $_REQUEST['filter']; + echo " "; + } } - else { - if ( $file_size >= $default_fsize ){ + + //echo "Log File Size: " . $file_size . " bytes.
"; + echo " "; + echo " "; + echo "
".$text['description-filter']." ".escape($uuid_filter)."".$text['label-displaying']." ".number_format($user_file_size,0,'.',',')." of ".number_format($file_size,0,'.',',')." ".$text['label-bytes'].".
"; + echo "
"; + + $file = fopen($log_file, "r") or exit($text['error-open_file']); + + //set pointer in file + if ($user_file_size >= '0') { + if ($user_file_size == '0'){ + $user_file_size = $default_file_size; + } + if ( $file_size >= $user_file_size ){ //set an offset on fopen - $bytecount=$file_size-$default_fsize; - fseek($file, $bytecount); - echo $text['label-open-at']." " . $bytecount . " ".$text['label-bytes']."
"; + $byte_count=$file_size-$user_file_size; + fseek($file, $byte_count); + //echo "opening at " . $byte_count . " bytes
"; + } + else { + if ( $file_size >= $default_file_size ){ + //set an offset on fopen + $byte_count=$file_size-$default_file_size; + fseek($file, $byte_count); + echo $text['label-open_at']." " . $byte_count . " ".$text['label-bytes']."
"; + } + else { + //open the file + $byte_count='0'; + fseek($file, 0); + echo "
".$text['label-open_file']."
"; + } + } } + else { + if ( $file_size >= $default_file_size ){ + //set an offset on fopen + $byte_count = $file_size - $default_file_size; + fseek($file, $byte_count); + echo $text['label-open_at']." " . $byte_count . " ".$text['label-bytes']."
"; + } else { //open the file - $bytecount='0'; + $byte_count='0'; fseek($file, 0); - echo "
".$text['label-open-file']."
"; - } - } - } - else { - if ( $file_size >= $default_fsize ){ - //set an offset on fopen - $bytecount=$file_size-$default_fsize; - fseek($file, $bytecount); - echo $text['label-open-at']." " . $bytecount . " ".$text['label-bytes']."
"; - } - else { - //open the file - $bytecount='0'; - fseek($file, 0); - echo "
".$text['label-open-file']."
"; - } - } - - //start processing - $byte_count = 0; - while(!feof($file)) - { - $log_line = fgets($file); - $byte_count++; - $noprint = false; - - $skip_line = false; - if (!empty($uuid_filter) ) { - $uuid_match = strpos($log_line, $uuid_filter); - if ($uuid_match === false) { - $skip_line = true; - } - else { - $skip_line = false; + echo "
".$text['label-open_file']."
"; } } - if ($skip_line === false) { - foreach ($arr_filter as $v1) { - $pos = strpos($log_line, $v1['pattern']); - //echo "
POS is: '$pos'
"; - if ($pos !== false){ - //color adjustments on words in log line - for ($i=2; $i<=$MAXEL; $i++){ - if (isset ($v1["pattern".$i])) { - $log_line = str_replace($v1["pattern".$i], "".$v1["pattern".$i]."", $log_line); - } - } - $ary_output[] = "".$log_line."
"; - $noprint = true; + //start processing + $byte_count = 0; + while(!feof($file)) { + $log_line = fgets($file); + $byte_count++; + $noprint = false; + + $skip_line = false; + if (!empty($uuid_filter) ) { + $uuid_match = strpos($log_line, $uuid_filter); + if ($uuid_match === false) { + $skip_line = true; + } + else { + $skip_line = false; } } - if ($noprint !== true){ - $ary_output[] = "".htmlentities($log_line)."
"; + if ($skip_line === false) { + foreach ($array_filter as $v1) { + $pos = strpos($log_line, $v1['pattern']); + //echo "
POS is: '$pos'
"; + if ($pos !== false){ + //color adjustments on words in log line + for ($i=2; $i<=$MAXEL; $i++){ + if (isset ($v1["pattern".$i])) { + $log_line = str_replace($v1["pattern".$i], "".$v1["pattern".$i]."", $log_line); + } + } + $array_output[] = "".$log_line."
"; + $noprint = true; + } + } + + if ($noprint !== true){ + $array_output[] = "".escape($log_line)."
"; + } } } - } - // output according to ordinal selected - if ($_POST['ord'] == 'desc') { - $ary_output = array_reverse($ary_output); - $adj_index = 0; - } - else { - $adj_index = 1; - } - foreach ($ary_output as $index => $line) { - $line_num = ""; - if ($line != "
") { - if ($_POST['ln']) { - $line_num = "".($index + $adj_index)."   "; - } - echo $line_num." ".$line; + // output according to ordinal selected + if ($_POST['sort'] == 'desc') { + $array_output = array_reverse($array_output); + $adj_index = 0; } + else { + $adj_index = 1; + } + foreach ($array_output as $index => $line) { + $line_num = ""; + if ($line != "
") { + if ($_POST['line_number']) { + $line_num = "".($index + $adj_index)."   "; + } + echo $line_num." ".$line; + } + } + fclose($file); + echo " "; } + echo "
\n"; - fclose($file); +//include the footer + require_once "resources/footer.php"; - echo " "; -} -echo "
\n"; - -require_once "resources/footer.php"; ?>