Use is_array before foreach
This commit is contained in:
parent
0fce8ac1a5
commit
be257eeb03
|
|
@ -66,9 +66,11 @@
|
||||||
//set default default log file
|
//set default default log file
|
||||||
if (isset($_POST['log_file'])) {
|
if (isset($_POST['log_file'])) {
|
||||||
$approved_files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
$approved_files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
||||||
foreach($approved_files as $approved_file) {
|
if (is_array($approved_files)) {
|
||||||
if ($approved_file == $_SESSION['switch']['log']['dir'].'/'.$_POST['log_file']) {
|
foreach($approved_files as $approved_file) {
|
||||||
$log_file = $approved_file;
|
if ($approved_file == $_SESSION['switch']['log']['dir'].'/'.$_POST['log_file']) {
|
||||||
|
$log_file = $approved_file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,9 +83,11 @@
|
||||||
if (isset($_GET['n'])) {
|
if (isset($_GET['n'])) {
|
||||||
if (isset($filename)) { unset($filename); }
|
if (isset($filename)) { unset($filename); }
|
||||||
$approved_files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
$approved_files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
||||||
foreach($approved_files as $approved_file) {
|
if (is_array($approved_files)) {
|
||||||
if ($approved_file == $_SESSION['switch']['log']['dir'].'/'.$_GET['n']) {
|
foreach($approved_files as $approved_file) {
|
||||||
$filename = $approved_file;
|
if ($approved_file == $_SESSION['switch']['log']['dir'].'/'.$_GET['n']) {
|
||||||
|
$filename = $approved_file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($filename) && file_exists($filename)) {
|
if (isset($filename) && file_exists($filename)) {
|
||||||
|
|
@ -98,6 +102,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the file size
|
||||||
|
if (file_exists($log_file)) {
|
||||||
|
$file_size = filesize($log_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//read the log
|
||||||
|
if (file_exists($log_file)) {
|
||||||
|
$file_handle = fopen($log_file, "r");
|
||||||
|
}
|
||||||
|
|
||||||
//include the header
|
//include the header
|
||||||
$document['title'] = $text['title-log_viewer'];
|
$document['title'] = $text['title-log_viewer'];
|
||||||
require_once "resources/header.php";
|
require_once "resources/header.php";
|
||||||
|
|
@ -109,9 +123,11 @@
|
||||||
echo "<form name='frm' id='frm' class='inline' method='post'>\n";
|
echo "<form name='frm' id='frm' class='inline' method='post'>\n";
|
||||||
echo " ".$text['label-log_file']." <select name='log_file' class='formfld' style='width: 150px; margin-right: 20px;'>";
|
echo " ".$text['label-log_file']." <select name='log_file' class='formfld' style='width: 150px; margin-right: 20px;'>";
|
||||||
$files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
$files = glob($_SESSION['switch']['log']['dir'].'/freeswitch.log*');
|
||||||
foreach($files as $file) {
|
if (is_array($files)) {
|
||||||
$selected = ($file == $log_file) ? "selected='selected'" : "";
|
foreach($files as $file_name) {
|
||||||
echo " <option value='".basename($file)."'".$selected.">".basename($file)."</option>";
|
$selected = ($file_name == $log_file) ? "selected='selected'" : "";
|
||||||
|
echo " <option value='".basename($file_name)."'".$selected.">".basename($file_name)."</option>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo " </select>\n";
|
echo " </select>\n";
|
||||||
echo $text['label-filter']." <input type='text' name='filter' class='formfld' style='width: 150px; text-align: center; margin-right: 20px;' value=\"".escape($_POST['filter'])."\" onclick='this.select();'>";
|
echo $text['label-filter']." <input type='text' name='filter' class='formfld' style='width: 150px; text-align: center; margin-right: 20px;' value=\"".escape($_POST['filter'])."\" onclick='this.select();'>";
|
||||||
|
|
@ -181,8 +197,6 @@
|
||||||
$array_filter[6]['type'] = 'bold';
|
$array_filter[6]['type'] = 'bold';
|
||||||
$array_filter[6]['font'] = 'monospace';
|
$array_filter[6]['font'] = 'monospace';
|
||||||
|
|
||||||
$file_size = filesize($log_file);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// removed: duplicate of above
|
// removed: duplicate of above
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
|
|
@ -208,8 +222,6 @@
|
||||||
echo " ".$text['label-displaying']." ".number_format($user_file_size,0,'.',',')." of ".number_format($file_size,0,'.',',')." ".$text['label-bytes'].".";
|
echo " ".$text['label-displaying']." ".number_format($user_file_size,0,'.',',')." of ".number_format($file_size,0,'.',',')." ".$text['label-bytes'].".";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
|
|
||||||
$file = fopen($log_file, "r") or exit($text['error-open_file']);
|
|
||||||
|
|
||||||
//set pointer in file
|
//set pointer in file
|
||||||
if ($user_file_size >= '0') {
|
if ($user_file_size >= '0') {
|
||||||
if ($user_file_size == '0') {
|
if ($user_file_size == '0') {
|
||||||
|
|
@ -217,21 +229,23 @@
|
||||||
}
|
}
|
||||||
if ($file_size >= $user_file_size) {
|
if ($file_size >= $user_file_size) {
|
||||||
//set an offset on fopen
|
//set an offset on fopen
|
||||||
$byte_count=$file_size-$user_file_size;
|
$byte_count = $file_size-$user_file_size;
|
||||||
fseek($file, $byte_count);
|
fseek($file, $byte_count);
|
||||||
//echo "opening at " . $byte_count . " bytes<br>";
|
//echo "opening at " . $byte_count . " bytes<br>";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($file_size >= $default_file_size) {
|
if ($file_size >= $default_file_size) {
|
||||||
//set an offset on fopen
|
//set an offset on fopen
|
||||||
$byte_count=$file_size-$default_file_size;
|
$byte_count = $file_size-$default_file_size;
|
||||||
fseek($file, $byte_count);
|
fseek($file, $byte_count);
|
||||||
echo $text['label-open_at']." " . $byte_count . " ".$text['label-bytes']."<br>";
|
echo $text['label-open_at']." " . $byte_count . " ".$text['label-bytes']."<br>";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//open the file
|
//open the file
|
||||||
$byte_count='0';
|
$byte_count ='0';
|
||||||
fseek($file, 0);
|
if ($file_handle) {
|
||||||
|
fseek($file_handle, 0);
|
||||||
|
}
|
||||||
echo "<br>".$text['label-open_file']."<br>";
|
echo "<br>".$text['label-open_file']."<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -253,40 +267,42 @@
|
||||||
|
|
||||||
//start processing
|
//start processing
|
||||||
$byte_count = 0;
|
$byte_count = 0;
|
||||||
while(!feof($file)) {
|
if ($file_handle) {
|
||||||
$log_line = escape(fgets($file));
|
while(!feof($file_handle)) {
|
||||||
$byte_count++;
|
$log_line = escape(fgets($file_handle));
|
||||||
$noprint = false;
|
$byte_count++;
|
||||||
|
$noprint = false;
|
||||||
|
|
||||||
$skip_line = false;
|
$skip_line = false;
|
||||||
if (!empty($filter) ) {
|
if (!empty($filter) ) {
|
||||||
$uuid_match = strpos($log_line, $filter);
|
$uuid_match = strpos($log_line, $filter);
|
||||||
if ($uuid_match === false) {
|
if ($uuid_match === false) {
|
||||||
$skip_line = true;
|
$skip_line = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$skip_line = false;
|
$skip_line = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($skip_line === false) {
|
|
||||||
foreach ($array_filter as $v1) {
|
|
||||||
$pos = strpos($log_line, escape($v1['pattern']));
|
|
||||||
//echo "</br> POS is: '$pos'</br>";
|
|
||||||
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(escape($v1["pattern".$i]), "<span style='color: ".$v1["color".$i].";'>".$v1["pattern".$i]."</span>", $log_line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$array_output[] = "<span style='color: ".$v1['color']."; font-family: ".$v1['font'].";'>".$log_line."</span><br>";
|
|
||||||
$noprint = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($noprint !== true) {
|
if ($skip_line === false) {
|
||||||
$array_output[] = "<span style='color: ".$default_color."; font-family: ".$default_font.";'>".$log_line."</span><br>";
|
foreach ($array_filter as $v1) {
|
||||||
|
$pos = strpos($log_line, escape($v1['pattern']));
|
||||||
|
//echo "</br> POS is: '$pos'</br>";
|
||||||
|
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(escape($v1["pattern".$i]), "<span style='color: ".$v1["color".$i].";'>".$v1["pattern".$i]."</span>", $log_line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array_output[] = "<span style='color: ".$v1['color']."; font-family: ".$v1['font'].";'>".$log_line."</span><br>";
|
||||||
|
$noprint = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($noprint !== true) {
|
||||||
|
$array_output[] = "<span style='color: ".$default_color."; font-family: ".$default_font.";'>".$log_line."</span><br>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -299,16 +315,18 @@
|
||||||
else {
|
else {
|
||||||
$adj_index = 1;
|
$adj_index = 1;
|
||||||
}
|
}
|
||||||
foreach ($array_output as $index => $line) {
|
if (is_array($array_output)) {
|
||||||
$line_num = "";
|
foreach ($array_output as $index => $line) {
|
||||||
if ($line != "<span style='color: #fff; font-family: monospace;'></span><br>") {
|
$line_num = "";
|
||||||
if ($_POST['line_number']) {
|
if ($line != "<span style='color: #fff; font-family: monospace;'></span><br>") {
|
||||||
$line_num = "<span style='font-family: courier; color: #aaa; font-size: 10px;'>".($index + $adj_index)." </span>";
|
if ($_POST['line_number']) {
|
||||||
|
$line_num = "<span style='font-family: courier; color: #aaa; font-size: 10px;'>".($index + $adj_index)." </span>";
|
||||||
|
}
|
||||||
|
echo $line_num." ".$line;
|
||||||
}
|
}
|
||||||
echo $line_num." ".$line;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($file);
|
|
||||||
echo " </div>";
|
echo " </div>";
|
||||||
}
|
}
|
||||||
echo " </td>";
|
echo " </td>";
|
||||||
|
|
@ -318,4 +336,9 @@
|
||||||
//include the footer
|
//include the footer
|
||||||
require_once "resources/footer.php";
|
require_once "resources/footer.php";
|
||||||
|
|
||||||
|
//close the file
|
||||||
|
if ($file_handle) {
|
||||||
|
fclose($file_handle);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue