1 diff -ruBbd 0.8.7e/cli/repair_templates.php 0.8.7/cli/repair_templates.php
2 --- 0.8.7e/cli/repair_templates.php 2009-08-18 22:03:22.000000000 -0400
3 +++ 0.8.7/cli/repair_templates.php 2009-08-20 07:43:54.000000000 -0400
7 + +-------------------------------------------------------------------------+
8 + | Copyright (C) 2004-2009 The Cacti Group |
10 + | This program is free software; you can redistribute it and/or |
11 + | modify it under the terms of the GNU General Public License |
12 + | as published by the Free Software Foundation; either version 2 |
13 + | of the License, or (at your option) any later version. |
15 + | This program is distributed in the hope that it will be useful, |
16 + | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 + | GNU General Public License for more details. |
19 + +-------------------------------------------------------------------------+
20 + | Cacti: The Complete RRDTool-based Graphing Solution |
21 + +-------------------------------------------------------------------------+
22 + | This code is designed, written, and maintained by the Cacti Group. See |
23 + | about.php and/or the AUTHORS file for specific developer information. |
24 + +-------------------------------------------------------------------------+
25 + | http://www.cacti.net/ |
26 + +-------------------------------------------------------------------------+
29 +/* do NOT run this script through a web browser */
30 +if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
31 + die("<br><strong>This script is only meant to run at the command line.</strong>");
34 +$no_http_headers = true;
36 +include(dirname(__FILE__) . "/../include/global.php");
37 +include_once("../lib/utility.php");
38 +include_once("../lib/template.php");
40 +/* process calling arguments */
41 +$parms = $_SERVER["argv"];
46 +foreach($parms as $parameter) {
47 + @list($arg, $value) = @explode("=", $parameter);
61 + print "ERROR: Invalid Parameter " . $parameter . "\n\n";
68 + echo "NOTE: Repairing All Duplicated Templates\n";
70 + echo "NOTE: Performing Check of Templates\n";
73 +/* repair data templates first */
75 + echo "NOTE: Repairing Data Templates\n";
77 + echo "NOTE: Performing Check of Data Templates\n";
80 +$damaged_template_ids = db_fetch_assoc("SELECT DISTINCT data_template_id FROM data_template_rrd WHERE hash='' AND local_data_id=0");
81 +if (sizeof($damaged_template_ids)) {
82 + foreach($damaged_template_ids as $id) {
83 + $template_name = db_fetch_cell("SELECT name FROM data_template WHERE id=" . $id["data_template_id"]);
84 + echo "NOTE: Data Template '$template_name' is Damaged and can be repaired\n";
87 + $damaged_templates = db_fetch_assoc("SELECT * FROM data_template_rrd WHERE hash='' AND local_data_id=0");
88 + if (sizeof($damaged_templates)) {
89 + echo "NOTE: -- Damaged Data Templates Objects Found is '" . sizeof($damaged_templates) . "'\n";
91 + foreach($damaged_templates as $template) {
92 + $hash = get_hash_data_template($template["local_data_template_rrd_id"], "data_template_item");
93 + db_execute("UPDATE data_template_rrd SET hash='$hash' WHERE id=" . $template["id"]);
98 + echo "NOTE: No Damaged Data Templates Found\n";
101 +/* reset the array */
102 +$damaged_templates = array();
104 +/* repair graph templates */
106 + echo "NOTE: Repairing Graph Templates\n";
108 + echo "NOTE: Performing Check of Graph Templates\n";
111 +$damaged_template_ids = db_fetch_assoc("SELECT DISTINCT graph_template_id FROM graph_template_input WHERE hash=''");
112 +if (sizeof($damaged_template_ids)) {
113 + foreach($damaged_template_ids as $id) {
114 + $template_name = db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . $id["graph_template_id"]);
115 + echo "NOTE: Graph Template '$template_name' is Damaged and can be repaired\n";
118 + $damaged_templates = db_fetch_assoc("SELECT * FROM graph_template_input WHERE hash=''");
119 + if (sizeof($damaged_templates)) {
120 + echo "NOTE: -- Damaged Graph Templates Objects Found is '" . sizeof($damaged_templates) . "'\n";
122 + foreach($damaged_templates as $template) {
123 + $hash = get_hash_graph_template(0, "graph_template_input");
124 + db_execute("UPDATE graph_template_input SET hash='$hash' WHERE id=" . $template["id"]);
129 + echo "NOTE: No Damaged Graph Templates Found\n";
133 +/* display_help - displays the usage of the function */
134 +function display_help () {
135 + print "Cacti Database Template Repair Tool v1.0, Copyright 2004-2009 - The Cacti Group\n\n";
136 + print "usage: repair_templates.php --execute [--help]\n\n";
137 + print "--execute - Perform the repair\n";
138 + print "--help - display this help message\n";
141 diff -ruBbd 0.8.7e/docs/README 0.8.7/docs/README
142 --- 0.8.7e/docs/README 2009-08-18 21:57:30.000000000 -0400
143 +++ 0.8.7/docs/README 2009-08-18 21:58:09.000000000 -0400
146 poller_reindex_hosts.php - Cause data query reindex on hosts
147 rebuild_poller_cache.php - Rebuilds the poller cache
148 + repair_templates.php - Certain templates, when created using the "duplicate"
149 + function in Cacti, do not import/export well. This utility repairs
154 --- 0.8.7e/lib/export.php 2009-08-18 21:56:47.000000000 -0400
155 +++ 0.8.7/lib/export.php 2009-08-18 21:57:50.000000000 -0400
159 function xml_character_encode($text) {
161 + if (function_exists("htmlspecialchars")) {
162 + return htmlspecialchars($text, ENT_QUOTES, "UTF-8");
164 $text = str_replace("&", "&", $text);
165 $text = str_replace(">", ">", $text);
166 $text = str_replace("<", "<", $text);
168 $text = str_replace("\'", "'", $text);
175 --- 0.8.7e/lib/import.php 2009-08-18 21:56:59.000000000 -0400
176 +++ 0.8.7/lib/import.php 2009-08-18 21:57:55.000000000 -0400
181 - if (isset($xml_array["name"])) {
182 - $xml_array["name"] = htmlspecialchars($xml_array["name"]);
185 while (list($hash, $hash_array) = each($xml_array)) {
186 /* parse information from the hash */
187 $parsed_hash = parse_xml_hash($hash);
189 $_graph_template_id = db_fetch_cell("select id from graph_templates where hash='$hash'");
190 $save["id"] = (empty($_graph_template_id) ? "0" : $_graph_template_id);
191 $save["hash"] = $hash;
192 - $save["name"] = htmlspecialchars($xml_array["name"]);
193 + $save["name"] = $xml_array["name"];
194 $graph_template_id = sql_save($save, "graph_templates");
196 $hash_cache["graph_template"][$hash] = $graph_template_id;
200 function xml_character_decode($text) {
201 + if (function_exists("html_entity_decode")) {
202 + return html_entity_decode($text, ENT_QUOTES, "UTF-8");
204 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
205 $trans_tbl = array_flip($trans_tbl);
206 return strtr($text, $trans_tbl);
211 --- 0.8.7e/lib/utility.php 2009-08-18 21:57:08.000000000 -0400
212 +++ 0.8.7/lib/utility.php 2009-08-18 21:58:00.000000000 -0400
214 $save["name"] = $graph_template_input["name"];
215 $save["description"] = $graph_template_input["description"];
216 $save["column_name"] = $graph_template_input["column_name"];
217 + $save["hash"] = get_hash_graph_template(0, "graph_template_input");
219 $graph_template_input_id = sql_save($save, "graph_template_input");
222 $save["local_data_id"] = (isset($local_data_id) ? $local_data_id : 0);
223 $save["local_data_template_rrd_id"] = (isset($data_template_rrd["local_data_template_rrd_id"]) ? $data_template_rrd["local_data_template_rrd_id"] : 0);
224 $save["data_template_id"] = (!empty($_local_data_id) ? $data_template_rrd["data_template_id"] : $data_template_id);
225 + if ($save["local_data_id"] == 0) {
226 + $save["hash"] = get_hash_data_template($data_template_rrd["local_data_template_rrd_id"], "data_template_item");
228 + $save["hash"] = '';
231 while (list($field, $array) = each($struct_data_source_item)) {
232 $save{$field} = $data_template_rrd{$field};