mirror of
https://github.com/Cacti/cacti.git
synced 2026-12-05 14:44:14 +09:00
Changed CLOG to use regex replacement for Device[] and DS[] (#1159)
* Changed to use regex replacement for Device[] and DS[] Also fixes issue #1158 * Updated CHANEGLOG for issue #1158 * Fix spacing issues with Spine logs * Correct use of db_fetch_assoc_prepared * Fix syntax error from last commit
This commit is contained in:
1 parent
498b498c6f
commit
70c55ebe21
2 files changed
+73
-63
No files matched your search
@@ -12,6 +12,7 @@ Cacti CHANGELOG
|
||||
1.1.30
|
||||
-issue#1155: Non-secure mail setting not functional due to changes in phpmailer
|
||||
-issue#1157: Resolve issue with branch permission api
|
||||
-issue#1158: Change CLOG to use regex replacement so line details are not mangled
|
||||
-issue: basename function undefined during upgrade to 1.0.x
|
||||
-issue: Storage API and translations required for Change password function
|
||||
-issue: ALTER IGNORE still throws an error when attempting to drop the primary key
|
||||
|
||||
+72
-63
@@ -259,72 +259,16 @@ function clog_view_logfile() {
|
||||
}
|
||||
|
||||
foreach ($logcontents as $item) {
|
||||
$host_start = strpos($item, 'Device[');
|
||||
$ds_start = strpos($item, 'DS[');
|
||||
$new_item = html_escape($item);
|
||||
|
||||
if (!$host_start && !$ds_start) {
|
||||
$new_item = html_escape($item);
|
||||
} else {
|
||||
$new_item = '';
|
||||
$host_start = strpos($new_item, 'Device[');
|
||||
$ds_start = strpos($new_item, 'DS[');
|
||||
|
||||
// Process the host section
|
||||
if ($host_start) {
|
||||
$host_end = strpos($item, ']', $host_start);
|
||||
$host_id = substr($item, $host_start + 7, $host_end - ($host_start + 7));
|
||||
$new_item .= substr($item, 0, $host_start) . " Device[<a href='" . html_escape($config['url_path'] . 'host.php?action=edit&id=' . $host_id) . "'>" . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:'') . '</a>]';
|
||||
$item = substr($item, $host_end + 1);
|
||||
}
|
||||
$ds_regex = '~( DS\[)([, \d]+)(\])~';
|
||||
$dev_regex = '~( Device\[)([, \d]+)(\])~';
|
||||
|
||||
// Process the Data Source Section
|
||||
$ds_start = strpos($item, 'DS[');
|
||||
|
||||
if ($ds_start) {
|
||||
$ds_end = strpos($item, ']', $ds_start);
|
||||
$ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
|
||||
$ds_ids = explode(', ', $ds_id);
|
||||
|
||||
if (sizeof($ds_ids)) {
|
||||
$graph_add = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
|
||||
|
||||
if ($new_item == '') {
|
||||
$new_item .= substr($item, 0, $ds_start);
|
||||
}
|
||||
|
||||
$title = '';
|
||||
$i = 0;
|
||||
|
||||
foreach($ds_ids as $ds_id) {
|
||||
$graph_ids = clog_get_graphs_from_datasource($ds_id);
|
||||
|
||||
if (sizeof($graph_ids)) {
|
||||
$new_item .= " Graphs[<a href='";
|
||||
|
||||
foreach($graph_ids as $key => $title) {
|
||||
$graph_add .= ($i > 0 ? '%2C' : '') . $key;
|
||||
$title .= ($title != '' ? ', ':'') . html_escape($title);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$new_item .= html_escape($graph_add) . "' title='" . __esc('View Graphs') . "'>" . $title . '</a>]';
|
||||
}
|
||||
}
|
||||
|
||||
$new_item .= ' DS[';
|
||||
$i = 0;
|
||||
|
||||
foreach($ds_ids as $ds_id) {
|
||||
$new_item .= ($i == 0 ? '':', ') . "<a href='" . html_escape($config['url_path'] . 'data_sources.php?action=ds_edit&id=' . $ds_id) . "'>" . $ds_id . '</a>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$new_item .= ']';
|
||||
}
|
||||
} else {
|
||||
$new_item .= html_escape($item);
|
||||
}
|
||||
}
|
||||
$new_item = preg_replace_callback($dev_regex,'clog_regex_device',$new_item);
|
||||
$new_item = preg_replace_callback($ds_regex,'clog_regex_datasource',$new_item);
|
||||
|
||||
/* respect the exclusion filter */
|
||||
if ($exclude_regex != '' && !$clogAdmin) {
|
||||
@@ -578,3 +522,68 @@ function filter($clogAdmin) {
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
function clog_regex_device($matches) {
|
||||
global $config;
|
||||
$dev_ids = explode(',',str_replace(" ","",$matches[2]));
|
||||
$result = '';
|
||||
if (sizeof($dev_ids)) {
|
||||
$hosts = db_fetch_assoc_prepared('SELECT id, description
|
||||
FROM host
|
||||
WHERE id in (?)',
|
||||
array(implode(',',$dev_ids)));
|
||||
$hostDescriptions = array();
|
||||
foreach ($hosts as $host) {
|
||||
$hostDescriptions[$host['id']] = html_escape($host['description']);
|
||||
}
|
||||
|
||||
foreach ($dev_ids as $host_id) {
|
||||
$result .= $matches[1].'<a href=\'' . html_escape($config['url_path'] . 'host.php?action=edit&id=' . $host_id) . '\'>' . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:$host_id) . '</a>' . $matches[3];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function clog_regex_datasource($matches) {
|
||||
global $config;
|
||||
|
||||
$ds_ids = explode(',',str_replace(" ","",$matches[2]));
|
||||
|
||||
$result = '';
|
||||
|
||||
if (sizeof($ds_ids)) {
|
||||
$graph_add = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
|
||||
|
||||
$title = '';
|
||||
$i = 0;
|
||||
|
||||
foreach($ds_ids as $ds_id) {
|
||||
$graph_ids = clog_get_graphs_from_datasource($ds_id);
|
||||
|
||||
if (sizeof($graph_ids)) {
|
||||
$result .= " Graphs[<a href='";
|
||||
|
||||
foreach($graph_ids as $key => $title) {
|
||||
$graph_add .= ($i > 0 ? '%2C' : '') . $key;
|
||||
$title .= ($title != '' ? ', ':'') . html_escape($title);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$result .= html_escape($graph_add) . "' title='" . __esc('View Graphs') . "'>" . $title . '</a>]';
|
||||
}
|
||||
}
|
||||
|
||||
$result .= $matches[1];
|
||||
$i = 0;
|
||||
|
||||
foreach($ds_ids as $ds_id) {
|
||||
$result .= ($i == 0 ? '':', ') . "<a href='" . html_escape($config['url_path'] . 'data_sources.php?action=ds_edit&id=' . $ds_id) . "'>" . $ds_id . '</a>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$result .= $matches[3];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in new issue
Block a user