From 221ce0e0a4a2527adcf9cec8a15fb4027d7f4a0a Mon Sep 17 00:00:00 2001 From: Tony Roman Date: Tue, 25 Apr 2017 20:24:22 -0400 Subject: [PATCH 1/8] Preping for 1.1.5 release --- include/global.php | 2 +- include/global_arrays.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/global.php b/include/global.php index e0e5d37fd9..2669d3d189 100644 --- a/include/global.php +++ b/include/global.php @@ -348,5 +348,5 @@ if ($is_web) { api_plugin_hook('config_insert'); /* current cacti version */ -$config['cacti_version'] = '1.1.4'; +$config['cacti_version'] = '1.1.5'; diff --git a/include/global_arrays.php b/include/global_arrays.php index 8ca8cd6f04..efbc461842 100644 --- a/include/global_arrays.php +++ b/include/global_arrays.php @@ -964,6 +964,7 @@ $hash_version_codes = array( '1.1.2' => '0100', '1.1.3' => '0100', '1.1.4' => '0100', + '1.1.5' => '0100', ); $hash_type_names = array( From a2a2c92273a19996441ca81a8e2a7966a75f514d Mon Sep 17 00:00:00 2001 From: cigamit Date: Wed, 26 Apr 2017 05:54:07 -0500 Subject: [PATCH 2/8] Resolving Issue #620 The table poller_data_template_field_mappings can get out of syn when manipulating data templates. --- data_templates.php | 9 ++++++++- docs/CHANGELOG | 3 +++ lib/utility.php | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/data_templates.php b/data_templates.php index 786f1ffc17..318cef74c8 100644 --- a/data_templates.php +++ b/data_templates.php @@ -245,6 +245,12 @@ function form_save() { push_out_host(0, 0, $data_template_id); /* push out field mappings for the data collector */ + /* its important to delete first due to the possibility that + * the field names were changed */ + db_execute('DELETE FROM poller_data_template_field_mappings + WHERE data_template_id = ?', + array($data_template_id)); + db_execute_prepared('REPLACE INTO poller_data_template_field_mappings SELECT dtr.data_template_id, dif.data_name, @@ -255,7 +261,8 @@ function form_save() { ON dtr.data_input_field_id = dif.id WHERE dtr.local_data_id = 0 AND dtr.data_template_id = ? - GROUP BY dtr.data_template_id, dif.data_name', array($data_template_id)); + GROUP BY dtr.data_template_id, dif.data_name', + array($data_template_id)); } } diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 15024a4fc3..f52f4af53e 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -1,5 +1,8 @@ Cacti CHANGELOG +1.1.6 +-issue#620: The table poller_data_template_field_mappings can get out of sync when manipulating data templates + 1.1.5 -issue#580: Data collection warnings when using cmd.php -issue#592: Incorrectly formatted HTML diff --git a/lib/utility.php b/lib/utility.php index f81f1632c1..7af043eb86 100644 --- a/lib/utility.php +++ b/lib/utility.php @@ -63,6 +63,16 @@ function repopulate_poller_cache() { api_data_source_cache_crc_update($poller_id); } } + + /* update the field mappings for the poller */ + db_execute("TRUNCATE TABLE poller_data_template_field_mappings"); + db_execute("INSERT IGNORE INTO poller_data_template_field_mappings + SELECT dtr.data_template_id, dif.data_name, GROUP_CONCAT(dtr.data_source_name ORDER BY dtr.data_source_name) AS data_source_names, NOW() + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id=0 + GROUP BY dtr.data_template_id, dif.data_name"); } function update_poller_cache_from_query($host_id, $data_query_id) { From e1f010f2418ecaaae330c4b37ce2c771d0563dd9 Mon Sep 17 00:00:00 2001 From: cigamit Date: Wed, 26 Apr 2017 06:03:07 -0500 Subject: [PATCH 3/8] Resolving Issue #622 Can not connec to MySQL over a socket --- docs/CHANGELOG | 1 + lib/database.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index f52f4af53e..3db7a05e6e 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -2,6 +2,7 @@ Cacti CHANGELOG 1.1.6 -issue#620: The table poller_data_template_field_mappings can get out of sync when manipulating data templates +-issue#622: Can not connect to MySQL over a socket 1.1.5 -issue#580: Data collection warnings when using cmd.php diff --git a/lib/database.php b/lib/database.php index 0ef4918d42..e2564fb538 100644 --- a/lib/database.php +++ b/lib/database.php @@ -60,7 +60,11 @@ function db_connect_real($device, $user, $pass, $db_name, $db_type = 'mysql', $p while ($i <= $retries) { try { - $cnn_id = new PDO("$db_type:host=$device;port=$port;dbname=$db_name;charset=utf8", $user, $pass, $flags); + if (file_exists($device)) { + $cnn_id = new PDO("$db_type:unix_socket=$device;dbname=$db_name;charset=utf8", $user, $pass, $flags); + }else{ + $cnn_id = new PDO("$db_type:host=$device;port=$port;dbname=$db_name;charset=utf8", $user, $pass, $flags); + } $cnn_id->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); // MySQL 5.7 forces NO_ZERO_DATE on From e27a1b65dad5d6d5f37f6148da8ea116295ef190 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Apr 2017 21:19:26 +0200 Subject: [PATCH 4/8] Small optimisations for threeview - fixed several alignment issues api_tree.php - api_tree_rename_node() Removed 3 unused methodcalls - api_tree_item_save() removed unused query - api_tree_get_branch_ordering() defined fields in query auth.php: - defined tablenames for fields html_tree.php - draw_dhtml_tree_level_graphing() - removed unused parameter - moved get_allowed_graphs() call out of the foreach() graph_view.php - simplified the $matched queries - typo in "update_timepsan" => "update_timespan" --- graph_view.php | 35 ++++++------ lib/api_tree.php | 132 ++++++++++++++++++++++------------------------ lib/auth.php | 44 +++++++++------- lib/html_tree.php | 37 +++++++------ 4 files changed, 123 insertions(+), 125 deletions(-) diff --git a/graph_view.php b/graph_view.php index 5f24fa7963..b3bb1925f8 100644 --- a/graph_view.php +++ b/graph_view.php @@ -49,8 +49,7 @@ function get_matching_nodes() { $filter = '%' . get_nfilter_request_var('str') . '%'; if (get_nfilter_request_var('str') != '') { - $matching = db_fetch_assoc_prepared("SELECT gti.id, gti.parent, - gti.graph_tree_id, IF(gti.title != '', '1', '0') AS node + $matching = db_fetch_assoc_prepared("SELECT gti.parent, gti.graph_tree_id FROM graph_tree_items AS gti LEFT JOIN host AS h ON h.id=gti.host_id @@ -61,22 +60,18 @@ function get_matching_nodes() { OR h.hostname LIKE ? OR gti.title LIKE ?", array($filter, $filter, $filter, $filter)); - }else{ - $matching = db_fetch_assoc("SELECT gti.id, gti.parent, - gti.graph_tree_id, IF(gti.title != '', '1', '0') AS node - FROM graph_tree_items AS gti - LEFT JOIN host AS h - ON h.id=gti.host_id - LEFT JOIN graph_templates_graph AS gtg - ON gtg.local_graph_id=gti.local_graph_id AND gtg.local_graph_id>0"); + } else { + $matching = db_fetch_assoc("SELECT parent, graph_tree_id FROM graph_tree_items"); } if (sizeof($matching)) { foreach($matching as $row) { while ($row['parent'] != '0') { $match[] = 'tbranch-' . $row['parent']; - $row = db_fetch_row_prepared('SELECT id, parent, graph_tree_id FROM graph_tree_items WHERE id = ?', array($row['parent'])); - if (!sizeof($row)) break; + $row = db_fetch_row_prepared('SELECT parent, graph_tree_id FROM graph_tree_items WHERE id = ?', array($row['parent'])); + if (!sizeof($row)) { + break; + } } if (sizeof($row)) { @@ -95,7 +90,7 @@ function get_matching_nodes() { if (isset($match[$level])) { if ($level == 0) { $final_array[$match[$level]][$match[$level]] = 1; - }else{ + } else { $final_array[$match[0]][$match[$level]] = 1; } $found++; @@ -103,10 +98,14 @@ function get_matching_nodes() { } $level++; - if ($found == 0) break; + if ($found == 0) { + break; + } } if (sizeof($final_array)) { + $fa = array(); + foreach($final_array as $key => $matches) { foreach($matches as $branch => $dnc) { $fa[] = $branch; @@ -131,7 +130,7 @@ case 'ajax_search': exit; break; -case 'update_timepsan': +case 'update_timespan': // we really don't need to do anything. The session variables have already been updated break; @@ -561,9 +560,9 @@ case 'list': 0) { - foreach ($item_rows as $key => $value) { - print "\n"; - } + foreach ($item_rows as $key => $value) { + print "\n"; + } } ?> diff --git a/lib/api_tree.php b/lib/api_tree.php index 512c0e1135..692b145f71 100644 --- a/lib/api_tree.php +++ b/lib/api_tree.php @@ -314,16 +314,16 @@ function api_tree_delete_node_content($tree_id, $leaf_id) { WHERE graph_tree_id = ? AND parent = ?', array($tree_id, $leaf_id)); if (sizeof($children)) { - foreach($children as $child) { - if ($child['host_id'] == 0 && $child['graph_id'] == 0) { - api_tree_delete_node_content($tree_id, $child['id']); - } + foreach($children as $child) { + if ($child['host_id'] == 0 && $child['graph_id'] == 0) { + api_tree_delete_node_content($tree_id, $child['id']); + } - db_execute_prepared('DELETE - FROM graph_tree_items - WHERE graph_tree_id = ? - AND id = ?', array($tree_id, $child['id'])); - } + db_execute_prepared('DELETE + FROM graph_tree_items + WHERE graph_tree_id = ? + AND id = ?', array($tree_id, $child['id'])); + } } } @@ -373,10 +373,10 @@ function api_tree_move_node($tree_id, $node_id, $new_parent, $new_position) { $position = $new_position + 1; if (sizeof($others)) { - foreach($others as $other) { - db_execute_prepared('UPDATE graph_tree_items SET position = ? WHERE id = ?', array($position, $other['id'])); - $position++; - } + foreach($others as $other) { + db_execute_prepared('UPDATE graph_tree_items SET position = ? WHERE id = ?', array($position, $other['id'])); + $position++; + } } api_tree_sort_branch($data['leaf_id'], $tree_id); @@ -395,10 +395,10 @@ function api_tree_move_node($tree_id, $node_id, $new_parent, $new_position) { $position = $new_position + 1; if (sizeof($others)) { - foreach($others as $other) { - db_execute_prepared('UPDATE graph_tree_items SET position = ? WHERE id = ?', array($position, $other['id'])); - $position++; - } + foreach($others as $other) { + db_execute_prepared('UPDATE graph_tree_items SET position = ? WHERE id = ?', array($position, $other['id'])); + $position++; + } } api_tree_sort_branch($data['leaf_id'], $tree_id); @@ -422,25 +422,25 @@ function api_tree_parse_node_data($variable) { // Process the 'id' variable $ndata = explode('_', $variable); if (sizeof($ndata)) { - foreach($ndata as $data) { - list($type, $tid) = explode(':', $data); + foreach($ndata as $data) { + list($type, $tid) = explode(':', $data); - /* watch out for monkey business */ - input_validate_input_number($tid); + /* watch out for monkey business */ + input_validate_input_number($tid); - switch ($type) { - case 'tbranch': - $leaf_id = $tid; - break; - case 'tgraph': - $graph_id = $tid; - break; - case 'thost': - $host_id = $tid; - break; + switch ($type) { + case 'tbranch': + $leaf_id = $tid; + break; + case 'tgraph': + $graph_id = $tid; + break; + case 'thost': + $host_id = $tid; + break; + } } } - } } if ($leaf_id > 0) { @@ -483,44 +483,38 @@ function api_tree_rename_node($tree_id, $node_id = '', $text = '') { return; } - $data = api_tree_parse_node_data($node_id); - - $oname = api_tree_get_branch_name($tree_id, $data['leaf_id']); - - $exists_id = api_tree_branch_exists($tree_id, $data['parent'], $text); - // Initialize some variables $leaf_id = 0; $graph_id = 0; $host_id = 0; // Process the 'id' variable - $ndata = explode('_', $node_id); + $ndata = explode('_', $node_id); if (sizeof($ndata)) { - foreach($ndata as $data) { - list($type, $tid) = explode(':', $data); + foreach($ndata as $data) { + list($type, $tid) = explode(':', $data); - /* watch out for monkey business */ - input_validate_input_number($tid); + /* watch out for monkey business */ + input_validate_input_number($tid); - switch ($type) { - case 'tbranch': - $leaf_id = $tid; - break; - case 'tgraph': - $graph_id = $tid; - break; - case 'thost': - $host_id = $tid; - break; + switch ($type) { + case 'tbranch': + $leaf_id = $tid; + break; + case 'tgraph': + $graph_id = $tid; + break; + case 'thost': + $host_id = $tid; + break; + } } } - } if (isset($leaf_id) && $leaf_id > 0) { if ($host_id > 0 || $graph_id > 0) { // Ignore. Need to customize context - }else{ + } else { db_execute_prepared('UPDATE graph_tree_items SET title = ? WHERE graph_tree_id = ? @@ -551,26 +545,26 @@ function api_tree_get_main($tree_id, $parent = 0) { $heirarchy = draw_dhtml_tree_level_graphing($tree_id, $parent); if (sizeof($heirarchy)) { - foreach($heirarchy as $h) { - print $h; - } + foreach($heirarchy as $h) { + print $h; + } } }else{ $heirarchy = draw_dhtml_tree_level_graphing($tree_id, $parent); if (sizeof($heirarchy)) { - foreach($heirarchy as $h) { - print $h; - } + foreach($heirarchy as $h) { + print $h; + } } } }else{ $heirarchy = draw_dhtml_tree_level_graphing($tree_id, $parent); if (sizeof($heirarchy)) { - foreach($heirarchy as $h) { - print $h; - } + foreach($heirarchy as $h) { + print $h; + } } } @@ -595,9 +589,9 @@ function api_tree_get_node($tree_id, $node_id) { } if (sizeof($heirarchy)) { - foreach($heirarchy as $h) { - print $h; - } + foreach($heirarchy as $h) { + print $h; + } } } @@ -622,8 +616,6 @@ function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, //api_tree_get_lock('tree-lock', 10); - $position = db_fetch_cell_prepared('SELECT MAX(position)+1 FROM graph_tree_items WHERE parent = ? AND graph_tree_id = ?', array($parent_tree_item_id, $tree_id)); - if ($local_graph_id > 0) { $exists = db_fetch_cell_prepared('SELECT id FROM graph_tree_items WHERE local_graph_id = ? AND parent = ? AND graph_tree_id = ?', array($local_graph_id, $parent_tree_item_id, $tree_id)); if ($exists) { @@ -698,7 +690,7 @@ function naturally_sort_graphs($a, $b) { * @arg $leaf_id - the leaf_id of the element * @returns - the ordering of the parent leaf/branch */ function api_tree_get_branch_ordering($leaf_id) { - $leaf = db_fetch_row_prepared('SELECT * FROM graph_tree_items WHERE id = ?', array($leaf_id)); + $leaf = db_fetch_row_prepared('SELECT sort_children_type, parent, graph_tree_id FROM graph_tree_items WHERE id = ?', array($leaf_id)); if (sizeof($leaf)) { if ($leaf['sort_children_type'] == 0) { diff --git a/lib/auth.php b/lib/auth.php index b347ed3c0c..4df6a1af36 100644 --- a/lib/auth.php +++ b/lib/auth.php @@ -629,25 +629,26 @@ function get_allowed_tree_level($tree_id, $parent_id, $user = 0) { ON gt.id = gti.graph_tree_id LEFT JOIN host AS h ON h.id = gti.host_id - WHERE graph_tree_id = ? - AND parent = ? - ORDER BY position ASC', array($tree_id, $parent_id)); + WHERE gti.graph_tree_id = ? + AND gti.parent = ? + ORDER BY gti.position ASC', array($tree_id, $parent_id) + ); - $i = 0; + $i = 0; if (sizeof($items)) { - foreach($items as $item) { - if ($item['host_id'] > 0) { - if (!is_device_allowed($item['host_id'], $user)) { - unset($items[$i]); + foreach($items as $item) { + if ($item['host_id'] > 0) { + if (!is_device_allowed($item['host_id'], $user)) { + unset($items[$i]); + } + } elseif($item['local_graph_id'] > 0) { + if (!is_graph_allowed($item['local_graph_id'], $user)) { + unset($items[$i]); + } } - }elseif($item['local_graph_id'] > 0) { - if (!is_graph_allowed($item['local_graph_id'], $user)) { - unset($items[$i]); - } - } - $i++; - } + $i++; + } } return $items; @@ -1091,11 +1092,14 @@ function get_allowed_graph_templates($sql_where = '', $order_by = 'name', $limit /* get policies for all groups and user */ $policies = db_fetch_assoc_prepared("SELECT uag.id, - 'group' AS type, policy_graphs, policy_hosts, policy_graph_templates + 'group' AS type, uag.policy_graphs, uag.policy_hosts, uag.policy_graph_templates FROM user_auth_group AS uag INNER JOIN user_auth_group_members AS uagm ON uag.id = uagm.group_id - WHERE uag.enabled = 'on' AND uagm.user_id = ?", array($user)); + WHERE uag.enabled = 'on' + AND uagm.user_id = ?", + array($user) + ); $policies[] = db_fetch_row_prepared("SELECT id, 'user' AS type, policy_graphs, policy_hosts, policy_graph_templates FROM user_auth WHERE id = ?", array($user)); @@ -1524,9 +1528,9 @@ function get_allowed_ajax_hosts($include_any = true, $include_none = true, $sql_ } if (sizeof($hosts)) { - foreach($hosts as $host) { - $return[] = array('label' => $host['description'], 'value' => $host['description'], 'id' => $host['id']); - } + foreach($hosts as $host) { + $return[] = array('label' => $host['description'], 'value' => $host['description'], 'id' => $host['id']); + } } print json_encode($return); diff --git a/lib/html_tree.php b/lib/html_tree.php index c34dc5e877..76f9c214f3 100644 --- a/lib/html_tree.php +++ b/lib/html_tree.php @@ -285,7 +285,7 @@ function get_tree_path() { $linknode = db_fetch_row_prepared('SELECT * FROM graph_tree_items - WHERE id = ?', + WHERE id = ?', array($node)); if (sizeof($linknode)) { @@ -362,7 +362,7 @@ function draw_dhtml_tree_level($tree_id, $parent = 0, $graphing = false) { return $dhtml_tree; } -function draw_dhtml_tree_level_graphing($tree_id, $parent = 0, $export = false) { +function draw_dhtml_tree_level_graphing($tree_id, $parent = 0) { global $config; include_once($config['base_path'] . '/lib/data_query.php'); @@ -388,7 +388,7 @@ function draw_dhtml_tree_level_graphing($tree_id, $parent = 0, $export = false) $dhtml_tree[] = "\t\t\t\t\t\t
  • " . htmlspecialchars($graph_template['name']) . "
  • \n"; } } - }else if ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) { + } elseif ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) { $data_queries = db_fetch_assoc_prepared('SELECT sq.id, sq.name FROM graph_local AS gl INNER JOIN snmp_query AS sq @@ -403,20 +403,23 @@ function draw_dhtml_tree_level_graphing($tree_id, $parent = 0, $export = false) )); if (sizeof($data_queries)) { + $ntg = get_allowed_graphs('gl.host_id=' . $leaf['host_id'] . ' AND gl.snmp_query_id=0'); + foreach ($data_queries as $data_query) { + if ($data_query['id'] == 0) { + $non_template_graphs = $ntg; + } else { + $non_template_graphs = array(); + } + /* fetch a list of field names that are sorted by the preferred sort field */ $sort_field_data = get_formatted_data_query_indexes($leaf['host_id'], $data_query['id']); - if ($data_query['id'] == 0) { - $non_template_graphs = get_allowed_graphs('gl.host_id=' . $leaf['host_id'] . ' AND gl.snmp_query_id=0'); - }else{ - $non_template_graphs = 0; - } - - if ((($data_query['id'] == 0) && (sizeof($non_template_graphs))) || - (($data_query['id'] > 0) && (sizeof($sort_field_data) > 0))) { + if (($data_query['id'] == 0 && sizeof($non_template_graphs)) || + ($data_query['id'] > 0 && sizeof($sort_field_data) > 0) + ) { if ($data_query['name'] != 'Non Query Based') { $dhtml_tree[] = "\t\t\t\t\t\t
  • ' . htmlspecialchars($data_query['name']) . "\n"; - }else{ + } else { $dhtml_tree[] = "\t\t\t\t\t\t
  • ' . htmlspecialchars($data_query['name']) . "\n"; } @@ -440,7 +443,7 @@ function draw_dhtml_tree_level_graphing($tree_id, $parent = 0, $export = false) } $dhtml_tree[] = "\t\t\t\t
  • \n"; - }else{ //It's not a host + } else { //It's not a host $children = db_fetch_cell_prepared('SELECT COUNT(*) FROM graph_tree_items WHERE parent = ? AND local_graph_id=0', array($leaf['id'])); $dhtml_tree[] = "\t\t\t\t
  • 0 ? "class='jstree-closed'":"") . ">' . htmlspecialchars($leaf['title']) . "
  • \n"; @@ -448,7 +451,7 @@ function draw_dhtml_tree_level_graphing($tree_id, $parent = 0, $export = false) } $dhtml_tree[] = "\t\t\t\n"; - }else{ + } else { $dhtml_tree[] = "