]> git.pld-linux.org Git - packages/cacti.git/blame - template_duplication.patch
- add 5 official patches, upgrade PluginArchidecture patch to 0.8.7e-PA-v2.6
[packages/cacti.git] / template_duplication.patch
CommitLineData
8514c08f
ER
1diff -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
4@@ -0,0 +1,135 @@
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) {
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";
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+?>
141diff -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
154diff -ruBbd 0.8.7e/lib/export.php 0.8.7/lib/export.php
155--- 0.8.7e/lib/export.php 2009-08-18 21:56:47.000000000 -0400
156+++ 0.8.7/lib/export.php 2009-08-18 21:57:50.000000000 -0400
157@@ -811,7 +811,9 @@
158 }
159
160 function xml_character_encode($text) {
161-
162+ if (function_exists("htmlspecialchars")) {
163+ return htmlspecialchars($text, ENT_QUOTES, "UTF-8");
164+ } else {
165 $text = str_replace("&", "&amp;", $text);
166 $text = str_replace(">", "&gt;", $text);
167 $text = str_replace("<", "&lt;", $text);
168@@ -819,6 +821,7 @@
169 $text = str_replace("\'", "&apos;", $text);
170
171 return $text;
172+ }
173 }
174
175 ?>
176diff -ruBbd 0.8.7e/lib/import.php 0.8.7/lib/import.php
177--- 0.8.7e/lib/import.php 2009-08-18 21:56:59.000000000 -0400
178+++ 0.8.7/lib/import.php 2009-08-18 21:57:55.000000000 -0400
179@@ -36,10 +36,6 @@
180 return $info_array;
181 }
182
183- if (isset($xml_array["name"])) {
184- $xml_array["name"] = htmlspecialchars($xml_array["name"]);
185- }
186-
187 while (list($hash, $hash_array) = each($xml_array)) {
188 /* parse information from the hash */
189 $parsed_hash = parse_xml_hash($hash);
190@@ -115,7 +111,7 @@
191 $_graph_template_id = db_fetch_cell("select id from graph_templates where hash='$hash'");
192 $save["id"] = (empty($_graph_template_id) ? "0" : $_graph_template_id);
193 $save["hash"] = $hash;
194- $save["name"] = htmlspecialchars($xml_array["name"]);
195+ $save["name"] = $xml_array["name"];
196 $graph_template_id = sql_save($save, "graph_templates");
197
198 $hash_cache["graph_template"][$hash] = $graph_template_id;
199@@ -914,9 +910,13 @@
200 }
201
202 function xml_character_decode($text) {
203+ if (function_exists("html_entity_decode")) {
204+ return html_entity_decode($text, ENT_QUOTES, "UTF-8");
205+ } else {
206 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
207 $trans_tbl = array_flip($trans_tbl);
208 return strtr($text, $trans_tbl);
209+ }
210 }
211
212 ?>
213diff -ruBbd 0.8.7e/lib/utility.php 0.8.7/lib/utility.php
214--- 0.8.7e/lib/utility.php 2009-08-18 21:57:08.000000000 -0400
215+++ 0.8.7/lib/utility.php 2009-08-18 21:58:00.000000000 -0400
216@@ -346,6 +346,7 @@
217 $save["name"] = $graph_template_input["name"];
218 $save["description"] = $graph_template_input["description"];
219 $save["column_name"] = $graph_template_input["column_name"];
220+ $save["hash"] = get_hash_graph_template(0, "graph_template_input");
221
222 $graph_template_input_id = sql_save($save, "graph_template_input");
223
224@@ -436,6 +437,11 @@
225 $save["local_data_id"] = (isset($local_data_id) ? $local_data_id : 0);
226 $save["local_data_template_rrd_id"] = (isset($data_template_rrd["local_data_template_rrd_id"]) ? $data_template_rrd["local_data_template_rrd_id"] : 0);
227 $save["data_template_id"] = (!empty($_local_data_id) ? $data_template_rrd["data_template_id"] : $data_template_id);
228+ if ($save["local_data_id"] == 0) {
229+ $save["hash"] = get_hash_data_template($data_template_rrd["local_data_template_rrd_id"], "data_template_item");
230+ } else {
231+ $save["hash"] = '';
232+ }
233
234 while (list($field, $array) = each($struct_data_source_item)) {
235 $save{$field} = $data_template_rrd{$field};
This page took 0.596642 seconds and 4 git commands to generate.