1 | 1 | simandl | <?php |
2 | | | /******************************************************************************* |
3 | | | |
4 | | | Author ......... Howard Jones |
5 | | | Contact ........ howie@thingy.com |
6 | | | Home Site ...... http://wotsit.thingy.com/haj/ |
7 | | | Program ........ Network Weathermap for Cacti |
8 | | | Version ........ See code below |
9 | | | Purpose ........ Network Usage Overview |
10 | | | |
11 | | | *******************************************************************************/ |
12 | | | |
13 | | | function weathermap_version () { |
14 | | | return array( 'name' => 'weathermap', |
15 | 13 | simandl | 'version' => '0.92', |
16 | 1 | simandl | 'longname' => 'PHP Network Weathermap', |
17 | | | 'author' => 'Howard Jones', |
18 | | | 'homepage' => 'http://wotsit.thingy.com/haj/cacti/php-weathermap/', |
19 | | | 'email' => 'howie@thingy.com', |
20 | | | 'url' => 'http://wotsit.thingy.com/haj/cacti/versions.php' |
21 | | | ); |
22 | | | } |
23 | | | |
24 | | | function plugin_init_weathermap() { |
25 | | | global $plugin_hooks; |
26 | | | $plugin_hooks['top_header_tabs']['weathermap'] = 'weathermap_show_tab'; |
27 | | | $plugin_hooks['top_graph_header_tabs']['weathermap'] = 'weathermap_show_tab'; |
28 | | | |
29 | | | $plugin_hooks['config_arrays']['weathermap'] = 'weathermap_config_arrays'; |
30 | | | $plugin_hooks['draw_navigation_text']['weathermap'] = 'weathermap_draw_navigation_text'; |
31 | | | $plugin_hooks['config_settings']['weathermap'] = 'weathermap_config_settings'; |
32 | | | $plugin_hooks['poller_bottom']['weathermap'] = 'weathermap_poller_bottom'; |
33 | | | |
34 | | | $plugin_hooks['top_graph_refresh']['weathermap'] = 'weathermap_top_graph_refresh'; |
35 | | | } |
36 | | | |
37 | | | function weathermap_top_graph_refresh($refresh) |
38 | | | { |
39 | | | if (basename($_SERVER["PHP_SELF"]) != "weathermap-cacti-plugin.php") |
40 | | | return $refresh; |
41 | | | |
42 | | | // if we're cycling maps, then we want to handle reloads ourselves, thanks |
43 | | | if($_REQUEST["action"] == 'viewmapcycle') |
44 | | | { |
45 | | | return(86400); |
46 | | | } |
47 | | | return ($refresh); |
48 | | | } |
49 | | | |
50 | | | function weathermap_config_settings () { |
51 | | | global $tabs, $settings; |
52 | | | $tabs["misc"] = "Misc"; |
53 | | | |
54 | | | $temp = array( |
55 | | | "weathermap_header" => array( |
56 | | | "friendly_name" => "Network Weathermap", |
57 | | | "method" => "spacer", |
58 | | | ), |
59 | | | "weathermap_pagestyle" => array( |
60 | | | "friendly_name" => "Page style", |
61 | | | "description" => "How to display multiple maps.", |
62 | | | "method" => "drop_array", |
63 | | | "array" => array(0 => "Thumbnail Overview", 1 => "Full Images") |
64 | | | ), |
65 | | | "weathermap_thumbsize" => array( |
66 | | | "friendly_name" => "Thumbnail Maximum Size", |
67 | | | "description" => "The maximum width or height for thumbnails in thumbnail view, in pixels. Takes effect after the next poller run.", |
68 | | | "method" => "textbox", |
69 | | | "max_length" => 5, |
70 | | | ), |
71 | | | "weathermap_cycle_refresh" => array( |
72 | | | "friendly_name" => "Refresh Time", |
73 | | | "description" => "How often to refresh the page in Cycle mode. Automatic makes all available maps fit into 5 minutes.", |
74 | | | "method" => "drop_array", |
75 | | | "array" => array(0 => "Automatic", 5 => "5 Seconds", |
76 | | | 15 => '15 Seconds', |
77 | | | 30 => '30 Seconds', |
78 | | | 60 => '1 Minute', |
79 | | | 120 => '2 Minutes', |
80 | | | 300 => '5 Minutes', |
81 | | | ) |
82 | | | ), |
83 | | | "weathermap_output_format" => array( |
84 | | | "friendly_name" => "Output Format", |
85 | | | "description" => "What format do you prefer for the generated map images and thumbnails?", |
86 | | | "method" => "drop_array", |
87 | | | "array" => array('png' => "PNG (default)", |
88 | | | 'jpg' => "JPEG", |
89 | | | 'gif' => 'GIF' |
90 | | | ) |
91 | | | ), |
92 | | | "weathermap_render_period" => array( |
93 | | | "friendly_name" => "Map Rendering Interval", |
94 | | | "description" => "How often do you want Weathermap to recalculate it's maps? You should not touch this unless you know what you are doing! It is mainly needed for people with non-standard polling setups.", |
95 | | | "method" => "drop_array", |
96 | | | "array" => array(-1 => "Never (manual updates)", |
97 | | | |
98 | | | 2 => 'Every 2 Poller Cycles', |
99 | | | 3 => 'Every 3 Poller Cycles', |
100 | | | 4 => 'Every 4 Poller Cycles', |
101 | | | 5 => 'Every 5 Poller Cycles', |
102 | | | 10 => 'Every 10 Poller Cycles', |
103 | | | 12 => 'Every 12 Poller Cycles', |
104 | | | 24 => 'Every 24 Poller Cycles', |
105 | | | 36 => 'Every 36 Poller Cycles', |
106 | | | 48 => 'Every 48 Poller Cycles', |
107 | | | 72 => 'Every 72 Poller Cycles', |
108 | | | 288 => 'Every 288 Poller Cycles', |
109 | | | ), |
110 | | | ), |
111 | | | |
112 | | | "weathermap_quiet_logging" => array( |
113 | | | "friendly_name" => "Quiet Logging", |
114 | | | "description" => "By default, even in LOW level logging, Weathermap logs normal activity. This makes it REALLY log only errors in LOW mode.", |
115 | | | "method" => "drop_array", |
116 | | | "array" => array(0=>"Chatty (default)",1=>"Quiet") |
117 | | | ) |
118 | | | ); |
119 | | | if (isset($settings["misc"])) |
120 | | | $settings["misc"] = array_merge($settings["misc"], $temp); |
121 | | | else |
122 | | | $settings["misc"]=$temp; |
123 | | | } |
124 | | | |
125 | | | |
126 | | | function weathermap_setup_table () { |
127 | | | global $config, $database_default; |
128 | | | include_once($config["library_path"] . DIRECTORY_SEPARATOR . "database.php"); |
129 | | | |
130 | | | $sql = "show tables from " . $database_default; |
131 | | | $result = db_fetch_assoc($sql) or die (mysql_error()); |
132 | | | |
133 | | | $tables = array(); |
134 | | | $sql = array(); |
135 | | | |
136 | | | foreach($result as $index => $arr) { |
137 | | | foreach ($arr as $t) { |
138 | | | $tables[] = $t; |
139 | | | } |
140 | | | } |
141 | | | |
142 | | | $sql[] = "update weathermap_maps set sortorder=id where sortorder is null;"; |
143 | | | |
144 | | | if (!in_array('weathermap_maps', $tables)) { |
145 | | | $sql[] = "CREATE TABLE weathermap_maps ( |
146 | | | id int(11) NOT NULL auto_increment, |
147 | | | sortorder int(11) NOT NULL default 0, |
148 | | | active set('on','off') NOT NULL default 'on', |
149 | | | configfile text NOT NULL, |
150 | | | imagefile text NOT NULL, |
151 | | | htmlfile text NOT NULL, |
152 | | | titlecache text NOT NULL, |
153 | | | PRIMARY KEY (id) |
154 | | | ) TYPE=MyISAM;"; |
155 | | | } |
156 | | | else |
157 | | | { |
158 | | | $colsql = "show columns from weathermap_maps from " . $database_default; |
159 | | | $result = mysql_query($colsql) or die (mysql_error()); |
160 | | | $found = false; |
161 | | | while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { |
162 | | | if ($row['Field'] == 'sortorder') |
163 | | | $found = true; |
164 | | | } |
165 | | | if (!$found) |
166 | | | { |
167 | | | $sql[] = "alter table weathermap_maps add sortorder int(11) NOT NULL default 0 after id"; |
168 | | | } |
169 | | | } |
170 | | | |
171 | | | if (!in_array('weathermap_auth', $tables)) { |
172 | | | $sql[] = "CREATE TABLE weathermap_auth ( |
173 | | | userid mediumint(9) NOT NULL default '0', |
174 | | | mapid int(11) NOT NULL default '0' |
175 | | | ) TYPE=MyISAM;"; |
176 | | | } |
177 | | | |
178 | | | // create the settings entries, if necessary |
179 | | | |
180 | | | $pagestyle = read_config_option("weathermap_pagestyle"); |
181 | | | if($pagestyle == '' or $pagestyle < 0 or $pagestyle >1) |
182 | | | { |
183 | | | $sql[] = "replace into settings values('weathermap_pagestyle',0)"; |
184 | | | } |
185 | | | |
186 | | | $cycledelay = read_config_option("weathermap_cycle_refresh"); |
187 | | | if($cycledelay == '' or intval($cycledelay < 0) ) |
188 | | | { |
189 | | | $sql[] = "replace into settings values('weathermap_cycle_refresh',0)"; |
190 | | | } |
191 | | | |
192 | | | $renderperiod = read_config_option("weathermap_render_period"); |
193 | | | if($renderperiod == '' or intval($renderperiod < -1) ) |
194 | | | { |
195 | | | $sql[] = "replace into settings values('weathermap_render_period',0)"; |
196 | | | } |
197 | | | |
198 | | | $quietlogging = read_config_option("weathermap_quiet_logging"); |
199 | | | if($quietlogging == '' or intval($quietlogging < -1) ) |
200 | | | { |
201 | | | $sql[] = "replace into settings values('weathermap_quiet_logging',0)"; |
202 | | | } |
203 | | | |
204 | | | $rendercounter = read_config_option("weathermap_render_counter"); |
205 | | | if($rendercounter == '' or intval($rendercounter < 0) ) |
206 | | | { |
207 | | | $sql[] = "replace into settings values('weathermap_render_counter',0)"; |
208 | | | } |
209 | | | |
210 | | | $outputformat = read_config_option("weathermap_output_format"); |
211 | | | if($outputformat == '' ) |
212 | | | { |
213 | | | $sql[] = "replace into settings values('weathermap_output_format','png')"; |
214 | | | } |
215 | | | |
216 | | | $tsize = read_config_option("weathermap_thumbsize"); |
217 | | | if($tsize == '' or $tsize < 1) |
218 | | | { |
219 | | | $sql[] = "replace into settings values('weathermap_thumbsize',250)"; |
220 | | | } |
221 | | | |
222 | | | // patch up the sortorder for any maps that don't have one. |
223 | | | $sql[] = "update weathermap_maps set sortorder=id where sortorder is null or sortorder=0;"; |
224 | | | |
225 | | | if (!empty($sql)) { |
226 | | | for ($a = 0; $a < count($sql); $a++) { |
227 | | | $result = db_execute($sql[$a]); |
228 | | | } |
229 | | | } |
230 | | | } |
231 | | | |
232 | | | function weathermap_config_arrays () { |
233 | | | global $user_auth_realms, $user_auth_realm_filenames, $menu; |
234 | | | |
235 | | | $user_auth_realms[42]='Configure Weathermap'; |
236 | | | $user_auth_realms[43]='View Weathermaps'; |
237 | | | $user_auth_realm_filenames['weathermap-cacti-plugin.php'] = 43; |
238 | | | $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'] = 42; |
239 | | | |
240 | | | $menu["Management"]['plugins/weathermap/weathermap-cacti-plugin-mgmt.php'] = "Weathermaps"; |
241 | | | } |
242 | | | |
243 | | | function weathermap_show_tab () { |
244 | | | global $config, $user_auth_realms, $user_auth_realm_filenames; |
245 | | | $realm_id2 = 0; |
246 | | | |
247 | | | if (isset($user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')])) { |
248 | | | $realm_id2 = $user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')]; |
249 | | | } |
250 | | | |
251 | | | if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.user_id='" . $_SESSION["sess_user_id"] . "' and user_auth_realm.realm_id='$realm_id2'")) || (empty($realm_id2))) { |
252 | | | |
253 | | | print '<a href="' . $config['url_path'] . 'plugins/weathermap/weathermap-cacti-plugin.php"><img src="' . $config['url_path'] . 'plugins/weathermap/images/tab_wmap.gif" alt="Weathermap" align="absmiddle" border="0"></a>'; |
254 | | | |
255 | | | } |
256 | | | |
257 | | | weathermap_setup_table(); |
258 | | | } |
259 | | | |
260 | | | function weathermap_draw_navigation_text ($nav) { |
261 | | | $nav["weathermap-cacti-plugin.php:"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1"); |
262 | | | $nav["weathermap-cacti-plugin.php:viewmap"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1"); |
263 | | | $nav["weathermap-cacti-plugin.php:viewmapcycle"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1"); |
264 | | | |
265 | | | $nav["weathermap-cacti-plugin-mgmt.php:"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
266 | | | // $nav["weathermap-cacti-plugin-mgmt.php:addmap_picker"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
267 | | | $nav["weathermap-cacti-plugin-mgmt.php:viewconfig"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
268 | | | $nav["weathermap-cacti-plugin-mgmt.php:addmap"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
269 | | | $nav["weathermap-cacti-plugin-mgmt.php:editmap"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
270 | | | $nav["weathermap-cacti-plugin-mgmt.php:editor"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
271 | | | |
272 | | | // "graphs.php:graph_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"), |
273 | | | |
274 | | | $nav["weathermap-cacti-plugin-mgmt.php:perms_edit"] = array("title" => "Edit Permissions", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2"); |
275 | | | $nav["weathermap-cacti-plugin-mgmt.php:addmap_picker"] = array("title" => "Add Map", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2"); |
276 | | | |
277 | | | |
278 | | | // $nav["weathermap-cacti-plugin-mgmt.php:perms_edit"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
279 | | | $nav["weathermap-cacti-plugin-mgmt.php:perms_add_user"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
280 | | | $nav["weathermap-cacti-plugin-mgmt.php:perms_delete_user"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
281 | | | $nav["weathermap-cacti-plugin-mgmt.php:delete_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
282 | | | $nav["weathermap-cacti-plugin-mgmt.php:move_map_down"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
283 | | | $nav["weathermap-cacti-plugin-mgmt.php:move_map_up"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
284 | | | $nav["weathermap-cacti-plugin-mgmt.php:activate_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
285 | | | $nav["weathermap-cacti-plugin-mgmt.php:deactivate_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
286 | | | $nav["weathermap-cacti-plugin-mgmt.php:rebuildnow"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1"); |
287 | | | |
288 | | | return $nav; |
289 | | | } |
290 | | | |
291 | | | |
292 | | | function weathermap_poller_bottom () { |
293 | | | global $config; |
294 | | | global $weathermap_debugging, $WEATHERMAP_VERSION; |
295 | | | |
296 | | | include_once($config["library_path"] . DIRECTORY_SEPARATOR."database.php"); |
297 | | | include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."poller-common.php"); |
298 | | | |
299 | | | weathermap_setup_table(); |
300 | | | |
301 | | | $renderperiod = read_config_option("weathermap_render_period"); |
302 | | | $rendercounter = read_config_option("weathermap_render_counter"); |
303 | | | $quietlogging = read_config_option("weathermap_quiet_logging"); |
304 | | | |
305 | | | if($renderperiod<0) |
306 | | | { |
307 | | | // manual updates only |
308 | | | if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no updates ever",true,"WEATHERMAP"); |
309 | | | return; |
310 | | | } |
311 | | | else |
312 | | | { |
313 | | | // if we're due, run the render updates |
314 | | | if( ($rendercounter % $renderperiod) == 0) |
315 | | | { |
316 | | | weathermap_run_maps(dirname(__FILE__) ); |
317 | | | } |
318 | | | else |
319 | | | { |
320 | | | if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no update in this cycle ($rendercounter)",true,"WEATHERMAP"); |
321 | | | } |
322 | | | # cacti_log("Weathermap counter is $rendercounter. period is $renderperiod.", true, "WEATHERMAP"); |
323 | | | // increment the counter |
324 | | | $newcount = ($rendercounter+1)%1000; |
325 | | | db_execute("replace into settings values('weathermap_render_counter',".$newcount.")"); |
326 | | | } |
327 | | | } |
328 | | | |
329 | | | // vim:ts=4:sw=4: |
330 | 13 | simandl | ?> |