Skip to content

Commit

Permalink
Resolving Issue #1066
Browse files Browse the repository at this point in the history
Made the dropdown logic consistent between clog and utilities as well.
  • Loading branch information
cigamit committed Nov 14, 2017
1 parent 8a24be8 commit 96d793f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
31 changes: 16 additions & 15 deletions lib/clog_webapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ function clog_purge_logfile() {
global $config;

$logfile = read_config_option('path_cactilog');
$logbase = basename($logfile);
if ($logfile == '') {
$logfile = $config['base_path'] . '/log/cacti.log';
}

$logbase = basename($logfile);

if (get_nfilter_request_var('filename') != '') {
if (strpos(get_nfilter_request_var('filename'), $logbase) === false) {
raise_message('clog_invalid');
header('Location: ' . get_current_page() . '?filename=&header=false');
header('Location: ' . get_current_page() . '?filename=' . $logbase);
exit(0);
}
}
Expand Down Expand Up @@ -90,6 +89,7 @@ function clog_view_logfile() {

$clogAdmin = clog_admin();
$logfile = read_config_option('path_cactilog');
$logbase = basename($logfile);

if (isset_request_var('filename')) {
$requestedFile = dirname($logfile) . '/' . basename(get_nfilter_request_var('filename'));
Expand All @@ -100,12 +100,10 @@ function clog_view_logfile() {
$logfile = $config['base_path'] . '/log/cacti.log';
}

$logbase = basename($logfile);

if (get_nfilter_request_var('filename') != '') {
if (!strpos(get_nfilter_request_var('filename'), $logbase) === false) {
if (strpos(get_nfilter_request_var('filename'), $logbase) === false) {
raise_message('clog_invalid');
header('Location: ' . get_current_page() . '?header=false');
header('Location: ' . get_current_page() . '?filename=' . $logbase);
exit(0);
}
}
Expand Down Expand Up @@ -379,8 +377,11 @@ function filter($clogAdmin) {
<?php print __('File');?>
</td>
<td>
<select id='filename'>
<?php
$configLogPath = read_config_option('path_cactilog');
$configLogBase = basename($configLogPath);
$selectedFile = basename(get_nfilter_request_var('filename'));

if ($configLogPath == '') {
$logPath = $config['base_path'] . '/log/';
Expand All @@ -391,16 +392,10 @@ function filter($clogAdmin) {
if (is_readable($logPath)) {
$files = scandir($logPath);
} else {
$files = false;
$files = array('cacti.log');
}

if ($files === false) {
echo '<select id="filename" name="filename">
<option value="cacti.log">cacti.log</option>';
} else {
echo '<select id="filename" name="filename">';
$selectedFile = basename(get_nfilter_request_var('filename'));

if (sizeof($files)) {
foreach ($files as $logFile) {
if (in_array($logFile, array('.', '..', '.htaccess'))) {
continue;
Expand All @@ -411,10 +406,16 @@ function filter($clogAdmin) {
continue;
}

if (strpos($logFile, $configLogBase) === false) {
continue;
}

print "<option value='" . $logFile . "'";

if ($selectedFile == $logFile) {
print ' selected';
}

print '>' . $logFile . "</option>\n";
}
}
Expand Down
43 changes: 28 additions & 15 deletions utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ function utilities_view_logfile() {
global $log_tail_lines, $page_refresh_interval, $config;

$logfile = read_config_option('path_cactilog');
$logbase = basename($logfile);

if (isset_request_var('filename')) {
$requestedFile = dirname($logfile) . '/' . basename(get_nfilter_request_var('filename'));
Expand All @@ -893,12 +894,10 @@ function utilities_view_logfile() {
$logfile = $config['base_path'] . '/log/cacti.log';
}

$logbase = basename($logfile);

if (get_nfilter_request_var('filename') != '') {
if (strpos(get_nfilter_request_var('filename'), $logbase) === false) {
raise_message('clog_invalid');
header('Location: utilities.php?action=view_logfile&filename=&header=false');
header('Location: utilities.php?action=view_logfile&filename=' . $logbase);
exit(0);
}
}
Expand Down Expand Up @@ -1013,28 +1012,42 @@ function clearFilter() {
<?php print __('File');?>
</td>
<td>
<select id='filename' name='filename'>
<select id='filename'>
<?php
$selectedFile = basename(get_nfilter_request_var('filename'));
$logPath = dirname(read_config_option('path_cactilog'));
$configLogPath = read_config_option('path_cactilog');
$configLogBase = basename($configLogPath);
$selectedFile = basename(get_nfilter_request_var('filename'));

if ($configLogPath == '') {
$logPath = $config['base_path'] . '/log/';
} else {
$logPath = dirname($configLogPath);
}

if (is_readable($logPath)) {
$files = scandir($logPath);
} else {
$files = array('cacti.log');
}

foreach($files as $logFile) {
if (in_array($logFile, array('.', '..', '.htaccess'))) {
continue;
}
if (sizeof($files)) {
foreach($files as $logFile) {
if (in_array($logFile, array('.', '..', '.htaccess'))) {
continue;
}

print "<option value='" . $logFile . "'";
if ($selectedFile == $logFile) {
print ' selected';
}
if (strpos($logFile, $configLogBase) === false) {
continue;
}

print "<option value='" . $logFile . "'";

print '>' . $logFile . "</option>\n";
if ($selectedFile == $logFile) {
print ' selected';
}

print '>' . $logFile . "</option>\n";
}
}
?>
</select>
Expand Down

0 comments on commit 96d793f

Please sign in to comment.