]>
Commit | Line | Data |
---|---|---|
8514c08f ER |
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 | |
3b9a4a0d | 4 | @@ -0,0 +1,136 @@ |
8514c08f ER |
5 | +<?php |
6 | +/* | |
7 | + +-------------------------------------------------------------------------+ | |
8 | + | Copyright (C) 2004-2009 The Cacti Group | | |
9 | + | | | |
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. | | |
14 | + | | | |
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 | + +-------------------------------------------------------------------------+ | |
27 | +*/ | |
28 | + | |
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>"); | |
32 | +} | |
33 | + | |
34 | +$no_http_headers = true; | |
35 | + | |
36 | +include(dirname(__FILE__) . "/../include/global.php"); | |
37 | +include_once("../lib/utility.php"); | |
38 | +include_once("../lib/template.php"); | |
39 | + | |
40 | +/* process calling arguments */ | |
41 | +$parms = $_SERVER["argv"]; | |
42 | +array_shift($parms); | |
43 | + | |
44 | +$execute = FALSE; | |
45 | + | |
46 | +foreach($parms as $parameter) { | |
47 | + @list($arg, $value) = @explode("=", $parameter); | |
48 | + | |
49 | + switch ($arg) { | |
50 | + case "--execute": | |
51 | + $execute = TRUE; | |
52 | + break; | |
53 | + case "-h": | |
54 | + case "-v": | |
55 | + case "-V": | |
56 | + case "--version": | |
57 | + case "--help": | |
58 | + display_help(); | |
59 | + exit; | |
60 | + default: | |
61 | + print "ERROR: Invalid Parameter " . $parameter . "\n\n"; | |
62 | + display_help(); | |
63 | + exit; | |
64 | + } | |
65 | +} | |
66 | + | |
67 | +if ($execute) { | |
68 | + echo "NOTE: Repairing All Duplicated Templates\n"; | |
69 | +} else { | |
70 | + echo "NOTE: Performing Check of Templates\n"; | |
71 | +} | |
72 | + | |
73 | +/* repair data templates first */ | |
74 | +if ($execute) { | |
75 | + echo "NOTE: Repairing Data Templates\n"; | |
76 | +} else { | |
77 | + echo "NOTE: Performing Check of Data Templates\n"; | |
78 | +} | |
79 | + | |
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) { | |
3b9a4a0d | 83 | + $template_name = db_fetch_cell("SELECT name FROM data_template WHERE id=" . $id["data_template_id"]); |
8514c08f ER |
84 | + echo "NOTE: Data Template '$template_name' is Damaged and can be repaired\n"; |
85 | + } | |
86 | + | |
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"; | |
90 | + if ($execute) { | |
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"]); | |
94 | + } | |
95 | + } | |
96 | + } | |
97 | +} else { | |
98 | + echo "NOTE: No Damaged Data Templates Found\n"; | |
99 | +} | |
100 | + | |
101 | +/* reset the array */ | |
102 | +$damaged_templates = array(); | |
103 | + | |
104 | +/* repair graph templates */ | |
105 | +if ($execute) { | |
106 | + echo "NOTE: Repairing Graph Templates\n"; | |
107 | +} else { | |
108 | + echo "NOTE: Performing Check of Graph Templates\n"; | |
109 | +} | |
110 | + | |
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"; | |
116 | + } | |
117 | + | |
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"; | |
121 | + if ($execute) { | |
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"]); | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | +} else { | |
129 | + echo "NOTE: No Damaged Graph Templates Found\n"; | |
130 | +} | |
131 | + | |
132 | + | |
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"; | |
139 | +} | |
140 | +?> | |
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 | |
144 | @@ -90,6 +90,9 @@ | |
145 | table | |
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 | |
150 | + those templates. | |
151 | ||
152 | ||
153 | ||
8514c08f ER |
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 | |
156 | @@ -811,7 +811,9 @@ | |
157 | } | |
158 | ||
159 | function xml_character_encode($text) { | |
160 | - | |
161 | + if (function_exists("htmlspecialchars")) { | |
162 | + return htmlspecialchars($text, ENT_QUOTES, "UTF-8"); | |
163 | + } else { | |
164 | $text = str_replace("&", "&", $text); | |
165 | $text = str_replace(">", ">", $text); | |
166 | $text = str_replace("<", "<", $text); | |
167 | @@ -819,6 +821,7 @@ | |
168 | $text = str_replace("\'", "'", $text); | |
169 | ||
170 | return $text; | |
171 | + } | |
172 | } | |
173 | ||
174 | ?> | |
8514c08f ER |
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 | |
177 | @@ -36,10 +36,6 @@ | |
178 | return $info_array; | |
179 | } | |
180 | ||
181 | - if (isset($xml_array["name"])) { | |
182 | - $xml_array["name"] = htmlspecialchars($xml_array["name"]); | |
183 | - } | |
184 | - | |
185 | while (list($hash, $hash_array) = each($xml_array)) { | |
186 | /* parse information from the hash */ | |
187 | $parsed_hash = parse_xml_hash($hash); | |
188 | @@ -115,7 +111,7 @@ | |
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"); | |
195 | ||
196 | $hash_cache["graph_template"][$hash] = $graph_template_id; | |
197 | @@ -914,9 +910,13 @@ | |
198 | } | |
199 | ||
200 | function xml_character_decode($text) { | |
201 | + if (function_exists("html_entity_decode")) { | |
202 | + return html_entity_decode($text, ENT_QUOTES, "UTF-8"); | |
203 | + } else { | |
204 | $trans_tbl = get_html_translation_table(HTML_ENTITIES); | |
205 | $trans_tbl = array_flip($trans_tbl); | |
206 | return strtr($text, $trans_tbl); | |
207 | + } | |
208 | } | |
209 | ||
210 | ?> | |
8514c08f ER |
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 | |
213 | @@ -346,6 +346,7 @@ | |
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"); | |
218 | ||
219 | $graph_template_input_id = sql_save($save, "graph_template_input"); | |
220 | ||
221 | @@ -436,6 +437,11 @@ | |
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"); | |
227 | + } else { | |
228 | + $save["hash"] = ''; | |
229 | + } | |
230 | ||
231 | while (list($field, $array) = each($struct_data_source_item)) { | |
232 | $save{$field} = $data_template_rrd{$field}; |