1 | 85 | simandl | <?php |
2 | | | |
3 | | | chdir('../../'); |
4 | | | include_once("./include/auth.php"); |
5 | | | include_once("./include/config.php"); |
6 | | | |
7 | | | include_once($config["library_path"] . "/database.php"); |
8 | | | |
9 | | | $weathermap_confdir = realpath(dirname(__FILE__).'/configs'); |
10 | | | |
11 | | | // include the weathermap class so that we can get the version |
12 | | | include_once(dirname(__FILE__)."/Weathermap.class.php"); |
13 | | | |
14 | | | $i_understand_file_permissions_and_how_to_fix_them = FALSE; |
15 | | | |
16 | | | $action = ""; |
17 | | | if (isset($_POST['action'])) { |
18 | | | $action = $_POST['action']; |
19 | | | } else if (isset($_GET['action'])) { |
20 | | | $action = $_GET['action']; |
21 | | | } |
22 | | | |
23 | | | switch ($action) { |
24 | | | |
25 | | | case 'group_update': |
26 | | | $id = -1; |
27 | | | $newname = ""; |
28 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $id = intval($_REQUEST['id']); } |
29 | | | if( isset($_REQUEST['gname']) && (strlen($_REQUEST['gname'])>0) ) { $newname = $_REQUEST['gname']; } |
30 | | | |
31 | | | if($id >= 0 && $newname != "") weathermap_group_update($id,$newname); |
32 | | | if($id < 0 && $newname != "") weathermap_group_create($newname); |
33 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin"); |
34 | | | |
35 | | | break; |
36 | | | |
37 | | | case 'groupadmin_delete': |
38 | | | |
39 | | | $id = -1; |
40 | | | |
41 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $id = intval($_REQUEST['id']); } |
42 | | | |
43 | | | if($id>=1) |
44 | | | { |
45 | | | weathermap_group_delete($id); |
46 | | | } |
47 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin"); |
48 | | | break; |
49 | | | |
50 | | | case 'group_form': |
51 | | | |
52 | | | $id = -1; |
53 | | | |
54 | | | include_once($config["base_path"]."/include/top_header.php"); |
55 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $id = intval($_REQUEST['id']); } |
56 | | | |
57 | | | if($id>=0) |
58 | | | { |
59 | | | weathermap_group_form($id); |
60 | | | } |
61 | | | |
62 | | | weathermap_footer_links(); |
63 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
64 | | | break; |
65 | | | |
66 | | | case 'groupadmin': |
67 | | | include_once($config["base_path"]."/include/top_header.php"); |
68 | | | weathermap_group_editor(); |
69 | | | weathermap_footer_links(); |
70 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
71 | | | break; |
72 | | | |
73 | | | case 'chgroup_update': |
74 | | | $mapid = -1; |
75 | | | $groupid = -1; |
76 | | | |
77 | | | if( isset($_REQUEST['map_id']) && is_numeric($_REQUEST['map_id'])) { $mapid = intval($_REQUEST['map_id']); } |
78 | | | if( isset($_REQUEST['new_group']) && is_numeric($_REQUEST['new_group'])) { $groupid = intval($_REQUEST['new_group']); } |
79 | | | |
80 | | | if( ($groupid > 0) && ($mapid >= 0)) { weathermap_set_group($mapid,$groupid); } |
81 | | | |
82 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
83 | | | break; |
84 | | | |
85 | | | case 'chgroup': |
86 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
87 | | | { |
88 | | | include_once($config["base_path"]."/include/top_header.php"); |
89 | | | weathermap_chgroup( intval($_REQUEST['id']) ); |
90 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
91 | | | } |
92 | | | else |
93 | | | { |
94 | | | print "Something got lost back there."; |
95 | | | } |
96 | | | break; |
97 | | | |
98 | | | case 'map_settings_delete': |
99 | | | $mapid = NULL; |
100 | | | $settingid = NULL; |
101 | | | if( isset($_REQUEST['mapid']) && is_numeric($_REQUEST['mapid'])) { $mapid = intval($_REQUEST['mapid']); } |
102 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $settingid = intval($_REQUEST['id']); } |
103 | | | |
104 | | | if(! is_null($mapid) && ! is_null($settingid) ) |
105 | | | { |
106 | | | // create setting |
107 | | | weathermap_setting_delete($mapid,$settingid); |
108 | | | } |
109 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=map_settings&id=".$mapid); |
110 | | | break; |
111 | | | |
112 | | | // this is the save option from the map_settings_form |
113 | | | case 'save': |
114 | | | $mapid = NULL; |
115 | | | $settingid = NULL; |
116 | | | $name=''; $value=''; |
117 | | | |
118 | | | if( isset($_REQUEST['mapid']) && is_numeric($_REQUEST['mapid'])) { $mapid = intval($_REQUEST['mapid']); } |
119 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $settingid = intval($_REQUEST['id']); } |
120 | | | |
121 | | | if( isset($_REQUEST['name']) && $_REQUEST['name']) { $name = $_REQUEST['name']; } |
122 | | | if( isset($_REQUEST['value']) && $_REQUEST['value']) { $value = $_REQUEST['value']; } |
123 | | | |
124 | | | if(! is_null($mapid) && $settingid==0 ) |
125 | | | { |
126 | | | // create setting |
127 | | | weathermap_setting_save($mapid,$name,$value); |
128 | | | } |
129 | | | elseif(! is_null($mapid) && ! is_null($settingid) ) |
130 | | | { |
131 | | | // update setting |
132 | | | weathermap_setting_update($mapid,$settingid,$name,$value); |
133 | | | } |
134 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=map_settings&id=".$mapid); |
135 | | | break; |
136 | | | |
137 | | | case 'map_settings_form': |
138 | | | if( isset($_REQUEST['mapid']) && is_numeric($_REQUEST['mapid'])) |
139 | | | { |
140 | | | include_once($config["base_path"]."/include/top_header.php"); |
141 | | | |
142 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) |
143 | | | { |
144 | | | weathermap_map_settings_form(intval($_REQUEST['mapid']), intval($_REQUEST['id']) ); |
145 | | | } |
146 | | | else |
147 | | | { |
148 | | | weathermap_map_settings_form(intval($_REQUEST['mapid'])); |
149 | | | } |
150 | | | |
151 | | | weathermap_footer_links(); |
152 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
153 | | | } |
154 | | | break; |
155 | | | case 'map_settings': |
156 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) |
157 | | | { |
158 | | | include_once($config["base_path"]."/include/top_header.php"); |
159 | | | weathermap_map_settings(intval($_REQUEST['id'])); |
160 | | | weathermap_footer_links(); |
161 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
162 | | | } |
163 | | | break; |
164 | | | |
165 | | | case 'perms_add_user': |
166 | | | if( isset($_REQUEST['mapid']) && is_numeric($_REQUEST['mapid']) |
167 | | | && isset($_REQUEST['userid']) && is_numeric($_REQUEST['userid']) |
168 | | | ) |
169 | | | { |
170 | | | perms_add_user(intval($_REQUEST['mapid']),intval($_REQUEST['userid'])); |
171 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=perms_edit&id=".intval($_REQUEST['mapid'])); |
172 | | | } |
173 | | | break; |
174 | | | case 'perms_delete_user': |
175 | | | if( isset($_REQUEST['mapid']) && is_numeric($_REQUEST['mapid']) |
176 | | | && isset($_REQUEST['userid']) && is_numeric($_REQUEST['userid']) |
177 | | | ) |
178 | | | { |
179 | | | perms_delete_user($_REQUEST['mapid'],$_REQUEST['userid']); |
180 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=perms_edit&id=".$_REQUEST['mapid']); |
181 | | | } |
182 | | | break; |
183 | | | case 'perms_edit': |
184 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
185 | | | { |
186 | | | include_once($config["base_path"]."/include/top_header.php"); |
187 | | | perms_list($_REQUEST['id']); |
188 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
189 | | | } |
190 | | | else |
191 | | | { |
192 | | | print "Something got lost back there."; |
193 | | | } |
194 | | | break; |
195 | | | |
196 | | | |
197 | | | |
198 | | | case 'delete_map': |
199 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) map_delete($_REQUEST['id']); |
200 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
201 | | | break; |
202 | | | |
203 | | | case 'deactivate_map': |
204 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) map_deactivate($_REQUEST['id']); |
205 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
206 | | | break; |
207 | | | |
208 | | | case 'activate_map': |
209 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) map_activate($_REQUEST['id']); |
210 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
211 | | | break; |
212 | | | |
213 | | | case 'move_map_up': |
214 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && |
215 | | | isset($_REQUEST['order']) && is_numeric($_REQUEST['order']) ) |
216 | | | map_move($_REQUEST['id'],$_REQUEST['order'],-1); |
217 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
218 | | | break; |
219 | | | case 'move_map_down': |
220 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && |
221 | | | isset($_REQUEST['order']) && is_numeric($_REQUEST['order']) ) |
222 | | | map_move($_REQUEST['id'],$_REQUEST['order'],+1); |
223 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
224 | | | break; |
225 | | | |
226 | | | case 'move_group_up': |
227 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && |
228 | | | isset($_REQUEST['order']) && is_numeric($_REQUEST['order']) ) |
229 | | | weathermap_group_move(intval($_REQUEST['id']),intval($_REQUEST['order']),-1); |
230 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin"); |
231 | | | break; |
232 | | | case 'move_group_down': |
233 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && |
234 | | | isset($_REQUEST['order']) && is_numeric($_REQUEST['order']) ) |
235 | | | weathermap_group_move(intval($_REQUEST['id']),intval($_REQUEST['order']),1); |
236 | | | header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin"); |
237 | | | break; |
238 | | | |
239 | | | case 'viewconfig': |
240 | | | include_once($config["base_path"]."/include/top_graph_header.php"); |
241 | | | if(isset($_REQUEST['file'])) |
242 | | | { |
243 | | | preview_config($_REQUEST['file']); |
244 | | | } |
245 | | | else |
246 | | | { |
247 | | | print "No such file."; |
248 | | | } |
249 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
250 | | | break; |
251 | | | |
252 | | | case 'addmap_picker': |
253 | | | |
254 | | | include_once($config["base_path"]."/include/top_header.php"); |
255 | | | if(isset($_REQUEST['show']) && $_REQUEST['show']=='all') |
256 | | | { |
257 | | | addmap_picker(true); |
258 | | | } |
259 | | | else |
260 | | | { |
261 | | | addmap_picker(false); |
262 | | | } |
263 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
264 | | | break; |
265 | | | |
266 | | | case 'addmap': |
267 | | | if(isset($_REQUEST['file'])) |
268 | | | { |
269 | | | add_config($_REQUEST['file']); |
270 | | | header("Location: weathermap-cacti-plugin-mgmt.php"); |
271 | | | } |
272 | | | else |
273 | | | { |
274 | | | print "No such file."; |
275 | | | } |
276 | | | |
277 | | | break; |
278 | | | |
279 | | | case 'editor': |
280 | | | // chdir(dirname(__FILE__)); |
281 | | | // include_once('./weathermap-cacti-plugin-editor.php'); |
282 | | | break; |
283 | | | |
284 | | | case 'rebuildnow': |
285 | | | |
286 | | | include_once($config["base_path"]."/include/top_header.php"); |
287 | | | |
288 | | | print "<h3>REALLY Rebuild all maps?</h3><strong>NOTE: Because your Cacti poller process probably doesn't run as the same user as your webserver, it's possible this will fail with file permission problems even though the normal poller process runs fine. In some situations, it MAY have memory_limit problems, if your mod_php/ISAPI module uses a different php.ini to your command-line PHP.</strong><hr>"; |
289 | | | |
290 | | | print "<p>It is recommended that you don't use this feature, unless you understand and accept the problems it may cause.</p>"; |
291 | | | print "<h4><a href=\"weathermap-cacti-plugin-mgmt.php?action=rebuildnow2\">YES</a></h4>"; |
292 | | | print "<h1><a href=\"weathermap-cacti-plugin-mgmt.php\">NO</a></h1>"; |
293 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
294 | | | break; |
295 | | | |
296 | | | case 'rebuildnow2': |
297 | | | include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."Weathermap.class.php"); |
298 | | | include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."poller-common.php"); |
299 | | | |
300 | | | include_once($config["base_path"]."/include/top_header.php"); |
301 | | | print "<h3>Rebuilding all maps</h3><strong>NOTE: Because your Cacti poller process probably doesn't run as the same user as your webserver, it's possible this will fail with file permission problems even though the normal poller process runs fine. In some situations, it MAY have memory_limit problems, if your mod_php/ISAPI module uses a different php.ini to your command-line PHP.</strong><hr><pre>"; |
302 | | | weathermap_run_maps(dirname(__FILE__)); |
303 | | | print "</pre>"; |
304 | | | print "<hr /><h3>Done.</h3>"; |
305 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
306 | | | |
307 | | | break; |
308 | | | |
309 | | | // by default, just list the map setup |
310 | | | default: |
311 | | | include_once($config["base_path"]."/include/top_header.php"); |
312 | | | maplist(); |
313 | | | weathermap_footer_links(); |
314 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
315 | | | break; |
316 | | | } |
317 | | | |
318 | | | /////////////////////////////////////////////////////////////////////////// |
319 | | | |
320 | | | function weathermap_footer_links() |
321 | | | { |
322 | | | global $colors; |
323 | | | global $WEATHERMAP_VERSION; |
324 | | | print '<br />'; |
325 | | | html_start_box("<center><a target=\"_blank\" class=\"linkOverDark\" href=\"docs/\">Local Documentation</a> -- <a target=\"_blank\" class=\"linkOverDark\" href=\"http://www.network-weathermap.com/\">Weathermap Website</a> -- <a target=\"_target\" class=\"linkOverDark\" href=\"editor.php?plug=1\">Weathermap Editor</a> -- This is version $WEATHERMAP_VERSION</center>", "78%", $colors["header"], "2", "center", ""); |
326 | | | html_end_box(); |
327 | | | } |
328 | | | |
329 | | | // Repair the sort order column (for when something is deleted or inserted, or moved between groups) |
330 | | | // our primary concern is to make the sort order consistent, rather than any special 'correctness' |
331 | | | function map_resort() |
332 | | | { |
333 | | | $list = db_fetch_assoc("select * from weathermap_maps order by group_id,sortorder;"); |
334 | | | $i = 1; |
335 | | | $last_group = -1020.5; |
336 | | | foreach ($list as $map) |
337 | | | { |
338 | | | if($last_group != $map['group_id']) |
339 | | | { |
340 | | | $last_group = $map['group_id']; |
341 | | | $i=1; |
342 | | | } |
343 | | | $sql[] = "update weathermap_maps set sortorder = $i where id = ".$map['id']; |
344 | | | $i++; |
345 | | | } |
346 | | | if (!empty($sql)) { |
347 | | | for ($a = 0; $a < count($sql); $a++) { |
348 | | | $result = db_execute($sql[$a]); |
349 | | | } |
350 | | | } |
351 | | | } |
352 | | | |
353 | | | // Repair the sort order column (for when something is deleted or inserted) |
354 | | | function weathermap_group_resort() |
355 | | | { |
356 | | | $list = db_fetch_assoc("select * from weathermap_groups order by sortorder;"); |
357 | | | $i = 1; |
358 | | | foreach ($list as $group) |
359 | | | { |
360 | | | $sql[] = "update weathermap_groups set sortorder = $i where id = ".$group['id']; |
361 | | | $i++; |
362 | | | } |
363 | | | if (!empty($sql)) { |
364 | | | for ($a = 0; $a < count($sql); $a++) { |
365 | | | $result = db_execute($sql[$a]); |
366 | | | } |
367 | | | } |
368 | | | } |
369 | | | |
370 | | | function map_move($mapid,$junk,$direction) |
371 | | | { |
372 | | | $source = db_fetch_assoc("select * from weathermap_maps where id=$mapid"); |
373 | | | $oldorder = $source[0]['sortorder']; |
374 | | | $group = $source[0]['group_id']; |
375 | | | |
376 | | | $neworder = $oldorder + $direction; |
377 | | | $target = db_fetch_assoc("select * from weathermap_maps where group_id=$group and sortorder = $neworder"); |
378 | | | |
379 | | | if(!empty($target[0]['id'])) |
380 | | | { |
381 | | | $otherid = $target[0]['id']; |
382 | | | // move $mapid in direction $direction |
383 | | | $sql[] = "update weathermap_maps set sortorder = $neworder where id=$mapid"; |
384 | | | // then find the other one with the same sortorder and move that in the opposite direction |
385 | | | $sql[] = "update weathermap_maps set sortorder = $oldorder where id=$otherid"; |
386 | | | } |
387 | | | if (!empty($sql)) { |
388 | | | for ($a = 0; $a < count($sql); $a++) { |
389 | | | $result = db_execute($sql[$a]); |
390 | | | } |
391 | | | } |
392 | | | } |
393 | | | |
394 | | | function weathermap_group_move($id,$junk,$direction) |
395 | | | { |
396 | | | $source = db_fetch_assoc("select * from weathermap_groups where id=$id"); |
397 | | | $oldorder = $source[0]['sortorder']; |
398 | | | |
399 | | | $neworder = $oldorder + $direction; |
400 | | | $target = db_fetch_assoc("select * from weathermap_groups where sortorder = $neworder"); |
401 | | | |
402 | | | if(!empty($target[0]['id'])) |
403 | | | { |
404 | | | $otherid = $target[0]['id']; |
405 | | | // move $mapid in direction $direction |
406 | | | $sql[] = "update weathermap_groups set sortorder = $neworder where id=$id"; |
407 | | | // then find the other one with the same sortorder and move that in the opposite direction |
408 | | | $sql[] = "update weathermap_groups set sortorder = $oldorder where id=$otherid"; |
409 | | | } |
410 | | | if (!empty($sql)) { |
411 | | | for ($a = 0; $a < count($sql); $a++) { |
412 | | | $result = db_execute($sql[$a]); |
413 | | | } |
414 | | | } |
415 | | | } |
416 | | | |
417 | | | function maplist() |
418 | | | { |
419 | | | global $colors, $menu; |
420 | | | global $i_understand_file_permissions_and_how_to_fix_them; |
421 | | | |
422 | | | #print "<pre>"; |
423 | | | #print_r($menu); |
424 | | | #print "</pre>"; |
425 | | | |
426 | | | $last_started = read_config_option("weathermap_last_started_file",true); |
427 | | | $last_finished = read_config_option("weathermap_last_finished_file",true); |
428 | | | $last_start_time = intval(read_config_option("weathermap_last_start_time",true)); |
429 | | | $last_finish_time = intval(read_config_option("weathermap_last_finish_time",true)); |
430 | | | $poller_interval = intval(read_config_option("poller_interval")); |
431 | | | |
432 | | | if( ($last_finish_time - $last_start_time) > $poller_interval ) { |
433 | | | |
434 | | | if( ($last_started != $last_finished) && ($last_started != "") ) { |
435 | | | print '<div align="center" class="wm_warning"><p>'; |
436 | | | print "Last time it ran, Weathermap did NOT complete it's run. It failed during processing for '$last_started'. "; |
437 | | | print "This <strong>may</strong> have affected other plugins that run during the poller process. </p><p>"; |
438 | | | print "You should either disable this map, or fault-find. Possible causes include memory_limit issues. The log may have more information."; |
439 | | | print '</p></div>'; |
440 | | | } |
441 | | | } |
442 | | | |
443 | | | html_start_box("<strong>Weathermaps</strong>", "78%", $colors["header"], "3", "center", "weathermap-cacti-plugin-mgmt.php?action=addmap_picker"); |
444 | | | |
445 | | | html_header(array("Config File", "Title", "Group", "Active", "Settings", "Sort Order", "Accessible By","")); |
446 | | | |
447 | | | $query = db_fetch_assoc("select id,username from user_auth"); |
448 | | | $users[0] = 'Anyone'; |
449 | | | |
450 | | | foreach ($query as $user) |
451 | | | { |
452 | | | $users[$user['id']] = $user['username']; |
453 | | | } |
454 | | | |
455 | | | $i = 0; |
456 | | | $queryrows = db_fetch_assoc("select weathermap_maps.*, weathermap_groups.name as groupname from weathermap_maps, weathermap_groups where weathermap_maps.group_id=weathermap_groups.id order by weathermap_groups.sortorder,sortorder"); |
457 | | | // or die (mysql_error("Could not connect to database") ) |
458 | | | |
459 | | | $previous_id = -2; |
460 | | | $had_warnings = 0; |
461 | | | if( is_array($queryrows) ) |
462 | | | { |
463 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$i); |
464 | | | print "<td>ALL MAPS</td><td>(special settings for all maps)</td><td></td><td></td>"; |
465 | | | |
466 | | | print "<td><a href='?action=map_settings&id=0'>"; |
467 | | | $setting_count = db_fetch_cell("select count(*) from weathermap_settings where mapid=0 and groupid=0"); |
468 | | | if($setting_count > 0) |
469 | | | { |
470 | | | print $setting_count." special"; |
471 | | | if($setting_count>1) print "s"; |
472 | | | } |
473 | | | else |
474 | | | { |
475 | | | print "standard"; |
476 | | | } |
477 | | | print "</a>"; |
478 | | | |
479 | | | print "</td>"; |
480 | | | print "<td></td>"; |
481 | | | print "<td></td>"; |
482 | | | print "<td></td>"; |
483 | | | print "</tr>"; |
484 | | | $i++; |
485 | | | |
486 | | | foreach ($queryrows as $map) |
487 | | | { |
488 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$i); |
489 | | | |
490 | | | print '<td><a title="Click to start editor with this file" href="editor.php?plug=1&mapname='.htmlspecialchars($map['configfile']).'">'.htmlspecialchars($map['configfile']).'</a>'; |
491 | | | if($map['warncount']>0) |
492 | | | { |
493 | | | $had_warnings++; |
494 | | | |
495 | | | print '<a href="../../utilities.php?tail_lines=500&message_type=2&action=view_logfile&filter='.urlencode($map['configfile']).'" title="Check cacti.log for this map"><img border=0 src="images/exclamation.png" title="'.$map['warncount'].' warnings last time this map was run. Check your logs.">'.$map['warncount']."</a>"; |
496 | | | } |
497 | | | print "</td>"; |
498 | | | |
499 | | | # print '<a href="?action=editor&plug=1&mapname='.htmlspecialchars($map['configfile']).'">[edit]</a></td>'; |
500 | | | print '<td>'.htmlspecialchars($map['titlecache']).'</td>'; |
501 | | | print '<td><a title="Click to change group" href="?action=chgroup&id='.$map['id'].'">'.htmlspecialchars($map['groupname']).'</a></td>'; |
502 | | | |
503 | | | if($map['active'] == 'on') |
504 | | | { |
505 | | | print '<td class="wm_enabled"><a title="Click to Deactivate" href="?action=deactivate_map&id='.$map['id'].'"><font color="green">Yes</font></a>'; |
506 | | | } |
507 | | | else |
508 | | | { |
509 | | | print '<td class="wm_disabled"><a title="Click to Activate" href="?action=activate_map&id='.$map['id'].'"><font color="red">No</font></a>'; |
510 | | | } |
511 | | | print "<td>"; |
512 | | | |
513 | | | print "<a href='?action=map_settings&id=".$map['id']."'>"; |
514 | | | $setting_count = db_fetch_cell("select count(*) from weathermap_settings where mapid=".$map['id']); |
515 | | | if($setting_count > 0) |
516 | | | { |
517 | | | print $setting_count." special"; |
518 | | | if($setting_count>1) print "s"; |
519 | | | } |
520 | | | else |
521 | | | { |
522 | | | print "standard"; |
523 | | | } |
524 | | | print "</a>"; |
525 | | | |
526 | | | print "</td>"; |
527 | | | |
528 | | | print '</td>'; |
529 | | | |
530 | | | print '<td>'; |
531 | | | |
532 | | | print '<a href="?action=move_map_up&order='.$map['sortorder'].'&id='.$map['id'].'"><img src="../../images/move_up.gif" width="14" height="10" border="0" alt="Move Map Up" title="Move Map Up"></a>'; |
533 | | | print '<a href="?action=move_map_down&order='.$map['sortorder'].'&id='.$map['id'].'"><img src="../../images/move_down.gif" width="14" height="10" border="0" alt="Move Map Down" title="Move Map Down"></a>'; |
534 | | | // print $map['sortorder']; |
535 | | | |
536 | | | print "</td>"; |
537 | | | |
538 | | | print '<td>'; |
539 | | | $UserSQL = 'select * from weathermap_auth where mapid='.$map['id'].' order by userid'; |
540 | | | $userlist = db_fetch_assoc($UserSQL); |
541 | | | |
542 | | | $mapusers = array(); |
543 | | | foreach ($userlist as $user) |
544 | | | { |
545 | | | if(array_key_exists($user['userid'],$users)) |
546 | | | { |
547 | | | $mapusers[] = $users[$user['userid']]; |
548 | | | } |
549 | | | } |
550 | | | |
551 | | | print '<a title="Click to edit permissions" href="?action=perms_edit&id='.$map['id'].'">'; |
552 | | | if(count($mapusers) == 0) |
553 | | | { |
554 | | | print "(no users)"; |
555 | | | } |
556 | | | else |
557 | | | { |
558 | | | print join(", ",$mapusers); |
559 | | | } |
560 | | | print '</a>'; |
561 | | | |
562 | | | print '</td>'; |
563 | | | // print '<td><a href="?action=editor&mapname='.urlencode($map['configfile']).'">Edit Map</a></td>'; |
564 | | | print '<td>'; |
565 | | | print '<a href="?action=delete_map&id='.$map['id'].'"><img src="../../images/delete_icon.gif" width="10" height="10" border="0" alt="Delete Map" title="Delete Map"></a>'; |
566 | | | print '</td>'; |
567 | | | |
568 | | | print '</tr>'; |
569 | | | $i++; |
570 | | | } |
571 | | | } |
572 | | | |
573 | | | if($i==0) |
574 | | | { |
575 | | | print "<tr><td><em>No Weathermaps Configured</em></td></tr>\n"; |
576 | | | } |
577 | | | |
578 | | | html_end_box(); |
579 | | | |
580 | | | $last_stats = read_config_option("weathermap_last_stats", true); |
581 | | | |
582 | | | if($last_stats != "") { |
583 | | | print "<div align='center'><strong>Last Completed Run:</strong> $last_stats</div>"; |
584 | | | } else { |
585 | | | |
586 | | | } |
587 | | | |
588 | | | if($had_warnings>0) |
589 | | | { |
590 | | | print '<div align="center" class="wm_warning">'.$had_warnings.' of your maps had warnings last time '.($had_warnings>1?"they":"it").' ran. You can try to find these in your Cacti log file or by clicking on the warning sign next to that map (you might need to increase the log line count).</div>'; |
591 | | | } |
592 | | | |
593 | | | print "<div align='center'>"; |
594 | | | print "<a href='weathermap-cacti-plugin-mgmt.php?action=groupadmin'><img src='images/button_editgroups.png' border=0 alt='Edit Groups' /></a>"; |
595 | | | print " <a href='../../settings.php?tab=misc'><img src='images/button_settings.gif' border=0 alt='Settings' /></a>"; |
596 | | | if($i>0 && $i_understand_file_permissions_and_how_to_fix_them) |
597 | | | { |
598 | | | print '<br /><a href="?action=rebuildnow"><img src="images/btn_recalc.png" border="0" alt="Rebuild All Maps Right Now"><br />(Experimental - You should NOT need to use this normally)</a><br />'; |
599 | | | } |
600 | | | print "</div>"; |
601 | | | |
602 | | | } |
603 | | | |
604 | | | function addmap_picker($show_all=false) |
605 | | | { |
606 | | | global $weathermap_confdir; |
607 | | | global $colors; |
608 | | | |
609 | | | $loaded=array(); |
610 | | | $flags=array(); |
611 | | | // find out what maps are already in the database, so we can skip those |
612 | | | $queryrows = db_fetch_assoc("select * from weathermap_maps"); |
613 | | | if( is_array($queryrows) ) |
614 | | | { |
615 | | | foreach ($queryrows as $map) |
616 | | | { |
617 | | | $loaded[]=$map['configfile']; |
618 | | | |
619 | | | } |
620 | | | } |
621 | | | $loaded[]='index.php'; |
622 | | | |
623 | | | html_start_box("<strong>Available Weathermap Configuration Files</strong>", "78%", $colors["header"], "1", "center", ""); |
624 | | | |
625 | | | if( is_dir($weathermap_confdir)) |
626 | | | { |
627 | | | $n=0; |
628 | | | $dh = opendir($weathermap_confdir); |
629 | | | if($dh) |
630 | | | { |
631 | | | $i = 0; $skipped = 0; |
632 | | | html_header(array("","","Config File", "Title",""),2); |
633 | | | |
634 | | | while($file = readdir($dh)) |
635 | | | { |
636 | | | $realfile = $weathermap_confdir.'/'.$file; |
637 | | | |
638 | | | $used = in_array($file,$loaded); |
639 | | | $flags[$file] = ''; |
640 | | | if($used) $flags[$file] = 'USED'; |
641 | | | |
642 | | | if( is_file($realfile) ) |
643 | | | { |
644 | | | if( $used && !$show_all) |
645 | | | { |
646 | | | $skipped++; |
647 | | | } |
648 | | | else |
649 | | | { |
650 | | | $title = wmap_get_title($realfile); |
651 | | | $titles[$file] = $title; |
652 | | | $i++; |
653 | | | } |
654 | | | } |
655 | | | } |
656 | | | closedir($dh); |
657 | | | |
658 | | | if($i>0) |
659 | | | { |
660 | | | ksort($titles); |
661 | | | |
662 | | | $i=0; |
663 | | | foreach ($titles as $file=>$title) |
664 | | | { |
665 | | | $title = $titles[$file]; |
666 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$i); |
667 | | | print '<td><a href="?action=addmap&file='.$file.'" title="Add the configuration file">Add</a></td>'; |
668 | | | print '<td><a href="?action=viewconfig&file='.$file.'" title="View the configuration file in a new window" target="_blank">View</a></td>'; |
669 | | | print '<td>'.htmlspecialchars($file); |
670 | | | if($flags[$file] == 'USED') print ' <b>(USED)</b>'; |
671 | | | print '</td>'; |
672 | | | print '<td><em>'.htmlspecialchars($title).'</em></td>'; |
673 | | | print '</tr>'; |
674 | | | $i++; |
675 | | | } |
676 | | | } |
677 | | | |
678 | | | if( ($i + $skipped) == 0 ) |
679 | | | { |
680 | | | print "<tr><td>No files were found in the configs directory.</td></tr>"; |
681 | | | } |
682 | | | |
683 | | | if( ($i == 0) && $skipped>0) |
684 | | | { |
685 | | | print "<tr><td>($skipped files weren't shown because they are already in the database</td></tr>"; |
686 | | | } |
687 | | | } |
688 | | | else |
689 | | | { |
690 | | | print "<tr><td>Can't open $weathermap_confdir to read - you should set it to be readable by the webserver.</td></tr>"; |
691 | | | } |
692 | | | } |
693 | | | else |
694 | | | { |
695 | | | print "<tr><td>There is no directory named $weathermap_confdir - you will need to create it, and set it to be readable by the webserver. If you want to upload configuration files from inside Cacti, then it should be <i>writable</i> by the webserver too.</td></tr>"; |
696 | | | } |
697 | | | |
698 | | | html_end_box(); |
699 | | | |
700 | | | if($skipped>0) |
701 | | | { |
702 | | | print "<p align=center>Some files are not shown because they have already been added. You can <a href='?action=addmap_picker&show=all'>show these files too</a>, if you need to.</p>"; |
703 | | | } |
704 | | | if($show_all) |
705 | | | { |
706 | | | print "<p align=center>Some files are shown even though they have already been added. You can <a href='?action=addmap_picker'>hide those files too</a>, if you need to.</p>"; |
707 | | | } |
708 | | | |
709 | | | } |
710 | | | |
711 | | | function preview_config($file) |
712 | | | { |
713 | | | global $weathermap_confdir; |
714 | | | global $colors; |
715 | | | |
716 | | | chdir($weathermap_confdir); |
717 | | | |
718 | | | $path_parts = pathinfo($file); |
719 | | | $file_dir = realpath($path_parts['dirname']); |
720 | | | |
721 | | | if($file_dir != $weathermap_confdir) |
722 | | | { |
723 | | | // someone is trying to read arbitrary files? |
724 | | | // print "$file_dir != $weathermap_confdir"; |
725 | | | print "<h3>Path mismatch</h3>"; |
726 | | | } |
727 | | | else |
728 | | | { |
729 | | | html_start_box("<strong>Preview of $file</strong>", "98%", $colors["header"], "3", "center", ""); |
730 | | | |
731 | | | print '<tr><td valign="top" bgcolor="#'.$colors["light"].'" class="textArea">'; |
732 | | | print '<pre>'; |
733 | | | $realfile = $weathermap_confdir.'/'.$file; |
734 | | | if( is_file($realfile) ) |
735 | | | { |
736 | | | $fd = fopen($realfile,"r"); |
737 | | | while (!feof($fd)) |
738 | | | { |
739 | | | $buffer = fgets($fd,4096); |
740 | | | print $buffer; |
741 | | | } |
742 | | | fclose($fd); |
743 | | | } |
744 | | | print '</pre>'; |
745 | | | print '</td></tr>'; |
746 | | | html_end_box(); |
747 | | | } |
748 | | | } |
749 | | | |
750 | | | function add_config($file) |
751 | | | { |
752 | | | global $weathermap_confdir; |
753 | | | global $colors; |
754 | | | |
755 | | | chdir($weathermap_confdir); |
756 | | | |
757 | | | $path_parts = pathinfo($file); |
758 | | | $file_dir = realpath($path_parts['dirname']); |
759 | | | |
760 | | | if($file_dir != $weathermap_confdir) |
761 | | | { |
762 | | | // someone is trying to read arbitrary files? |
763 | | | // print "$file_dir != $weathermap_confdir"; |
764 | | | print "<h3>Path mismatch</h3>"; |
765 | | | } |
766 | | | else |
767 | | | { |
768 | | | $realfile = $weathermap_confdir.DIRECTORY_SEPARATOR.$file; |
769 | | | $title = wmap_get_title($realfile); |
770 | | | |
771 | | | $file = mysql_real_escape_string($file); |
772 | | | $title = mysql_real_escape_string($title); |
773 | | | $SQL = "insert into weathermap_maps (configfile,titlecache,active,imagefile,htmlfile,filehash,config) VALUES ('$file','$title','on','','','','')"; |
774 | | | db_execute($SQL); |
775 | | | |
776 | | | // add auth for 'admin' |
777 | | | $last_id = mysql_insert_id(); |
778 | | | // $myuid = (int)$_SESSION["sess_user_id"]; |
779 | | | $myuid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
780 | | | $SQL = "insert into weathermap_auth (mapid,userid) VALUES ($last_id,$myuid)"; |
781 | | | db_execute($SQL); |
782 | | | |
783 | | | db_execute("update weathermap_maps set filehash=LEFT(MD5(concat(id,configfile,rand())),20) where id=$last_id"); |
784 | | | |
785 | | | map_resort(); |
786 | | | } |
787 | | | } |
788 | | | |
789 | | | function wmap_get_title($filename) |
790 | | | { |
791 | | | $title = "(no title)"; |
792 | | | $fd = fopen($filename,"r"); |
793 | | | while (!feof($fd)) |
794 | | | { |
795 | | | $buffer = fgets($fd,4096); |
796 | | | if(preg_match("/^\s*TITLE\s+(.*)/i",$buffer, $matches)) |
797 | | | { |
798 | | | $title = $matches[1]; |
799 | | | } |
800 | | | // this regexp is tweaked from the ReadConfig version, to only match TITLEPOS lines *with* a title appended |
801 | | | if(preg_match("/^\s*TITLEPOS\s+\d+\s+\d+\s+(.+)/i",$buffer, $matches)) |
802 | | | { |
803 | | | $title = $matches[1]; |
804 | | | } |
805 | | | // strip out any DOS line endings that got through |
806 | | | $title=str_replace("\r", "", $title); |
807 | | | } |
808 | | | fclose($fd); |
809 | | | |
810 | | | return($title); |
811 | | | } |
812 | | | |
813 | | | function map_deactivate($id) |
814 | | | { |
815 | | | $SQL = "update weathermap_maps set active='off' where id=".$id; |
816 | | | db_execute($SQL); |
817 | | | } |
818 | | | |
819 | | | function map_activate($id) |
820 | | | { |
821 | | | $SQL = "update weathermap_maps set active='on' where id=".$id; |
822 | | | db_execute($SQL); |
823 | | | } |
824 | | | |
825 | | | function map_delete($id) |
826 | | | { |
827 | | | $SQL = "delete from weathermap_maps where id=".$id; |
828 | | | db_execute($SQL); |
829 | | | |
830 | | | $SQL = "delete from weathermap_auth where mapid=".$id; |
831 | | | db_execute($SQL); |
832 | | | |
833 | | | $SQL = "delete from weathermap_settings where mapid=".$id; |
834 | | | db_execute($SQL); |
835 | | | |
836 | | | map_resort(); |
837 | | | } |
838 | | | |
839 | | | function weathermap_set_group($mapid,$groupid) |
840 | | | { |
841 | | | # print "UPDATING"; |
842 | | | $SQL = sprintf("update weathermap_maps set group_id=%d where id=%d", $groupid, $mapid); |
843 | | | db_execute($SQL); |
844 | | | map_resort(); |
845 | | | } |
846 | | | |
847 | | | function perms_add_user($mapid,$userid) |
848 | | | { |
849 | | | $SQL = "insert into weathermap_auth (mapid,userid) values($mapid,$userid)"; |
850 | | | db_execute($SQL); |
851 | | | } |
852 | | | |
853 | | | function perms_delete_user($mapid,$userid) |
854 | | | { |
855 | | | $SQL = "delete from weathermap_auth where mapid=$mapid and userid=$userid"; |
856 | | | db_execute($SQL); |
857 | | | } |
858 | | | |
859 | | | function perms_list($id) |
860 | | | { |
861 | | | global $colors; |
862 | | | |
863 | | | // $title_sql = "select titlecache from weathermap_maps where id=$id"; |
864 | | | $title = db_fetch_cell("select titlecache from weathermap_maps where id=".intval($id)); |
865 | | | // $title = $results[0]['titlecache']; |
866 | | | |
867 | | | $auth_sql = "select * from weathermap_auth where mapid=$id order by userid"; |
868 | | | |
869 | | | $query = db_fetch_assoc("select id,username from user_auth order by username"); |
870 | | | $users[0] = 'Anyone'; |
871 | | | foreach ($query as $user) |
872 | | | { |
873 | | | $users[$user['id']] = $user['username']; |
874 | | | } |
875 | | | |
876 | | | $auth_results = db_fetch_assoc($auth_sql); |
877 | | | $mapusers = array(); |
878 | | | $mapuserids = array(); |
879 | | | foreach ($auth_results as $user) |
880 | | | { |
881 | | | if(isset($users[$user['userid']])) |
882 | | | { |
883 | | | $mapusers[] = $users[$user['userid']]; |
884 | | | $mapuserids[] = $user['userid']; |
885 | | | } |
886 | | | } |
887 | | | |
888 | | | $userselect=""; |
889 | | | foreach ($users as $uid => $name) |
890 | | | { |
891 | | | if(! in_array($uid,$mapuserids)) $userselect .= "<option value=\"$uid\">$name</option>\n"; |
892 | | | } |
893 | | | |
894 | | | html_start_box("<strong>Edit permissions for Weathermap $id: $title</strong>", "70%", $colors["header"], "2", "center", ""); |
895 | | | html_header(array("Username", "")); |
896 | | | |
897 | | | $n = 0; |
898 | | | foreach($mapuserids as $user) |
899 | | | { |
900 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n); |
901 | | | print "<td>".$users[$user]."</td>"; |
902 | | | print '<td><a href="?action=perms_delete_user&mapid='.$id.'&userid='.$user.'"><img src="../../images/delete_icon.gif" width="10" height="10" border="0" alt="Remove permissions for this user to see this map"></a></td>'; |
903 | | | |
904 | | | print "</tr>"; |
905 | | | $n++; |
906 | | | } |
907 | | | if($n==0) |
908 | | | { |
909 | | | print "<tr><td><em><strong>nobody</strong> can see this map</em></td></tr>"; |
910 | | | } |
911 | | | html_end_box(); |
912 | | | |
913 | | | html_start_box("", "70%", $colors["header"], "3", "center", ""); |
914 | | | print "<tr>"; |
915 | | | if($userselect == '') |
916 | | | { |
917 | | | print "<td><em>There aren't any users left to add!</em></td></tr>"; |
918 | | | } |
919 | | | else |
920 | | | { |
921 | | | print "<td><form action=\"\">Allow <input type=\"hidden\" name=\"action\" value=\"perms_add_user\"><input type=\"hidden\" name=\"mapid\" value=\"$id\"><select name=\"userid\">"; |
922 | | | print $userselect; |
923 | | | print "</select> to see this map <input type=\"submit\" value=\"Update\"></form></td>"; |
924 | | | print "</tr>"; |
925 | | | } |
926 | | | html_end_box(); |
927 | | | } |
928 | | | |
929 | | | function weathermap_map_settings($id) |
930 | | | { |
931 | | | global $colors, $config; |
932 | | | |
933 | | | if($id==0) |
934 | | | { |
935 | | | $title = "Additional settings for ALL maps"; |
936 | | | $nonemsg = "There are no settings for all maps yet. You can add some by clicking Add up in the top-right, or choose a single map from the management screen to add settings for that map."; |
937 | | | $type = "global"; |
938 | | | $settingrows = db_fetch_assoc("select * from weathermap_settings where mapid=0 and groupid=0"); |
939 | | | |
940 | | | } |
941 | | | elseif($id<0) |
942 | | | { |
943 | | | $group_id = -intval($id); |
944 | | | $groupname = db_fetch_cell("select name from weathermap_groups where id=".$group_id); |
945 | | | $title = "Edit per-map settings for Group ". $group_id . ": " . $groupname; |
946 | | | $nonemsg = "There are no per-group settings for this group yet. You can add some by clicking Add up in the top-right."; |
947 | | | $type="group"; |
948 | | | $settingrows = db_fetch_assoc("select * from weathermap_settings where groupid=".$group_id); |
949 | | | } |
950 | | | else |
951 | | | { |
952 | | | // print "Per-map settings for map $id"; |
953 | | | $map = db_fetch_row("select * from weathermap_maps where id=".intval($id)); |
954 | | | |
955 | | | $groupname = db_fetch_cell("select name from weathermap_groups where id=".intval($map['group_id'])); |
956 | | | $title = "Edit per-map settings for Weathermap $id: " . $map['titlecache']; |
957 | | | $nonemsg = "There are no per-map settings for this map yet. You can add some by clicking Add up in the top-right."; |
958 | | | $type = "map"; |
959 | | | $settingrows = db_fetch_assoc("select * from weathermap_settings where mapid=".intval($id)); |
960 | | | } |
961 | | | |
962 | | | if($type == "group") |
963 | | | { |
964 | | | print "<p>All maps in this group are also affected by the following GLOBAL settings (group overrides global, map overrides group, but BOTH override SET commands within the map config file):</p>"; |
965 | | | weathermap_readonly_settings(0, "Global Settings"); |
966 | | | |
967 | | | } |
968 | | | |
969 | | | if($type == "map") |
970 | | | { |
971 | | | print "<p>This map is also affected by the following GLOBAL and GROUP settings (group overrides global, map overrides group, but BOTH override SET commands within the map config file):</p>"; |
972 | | | |
973 | | | weathermap_readonly_settings(0, "Global Settings"); |
974 | | | |
975 | | | weathermap_readonly_settings(-$map['group_id'], "Group Settings (".htmlspecialchars($groupname).")"); |
976 | | | |
977 | | | } |
978 | | | |
979 | | | html_start_box("<strong>$title</strong>", "70%", $colors["header"], "2", "center", "weathermap-cacti-plugin-mgmt.php?action=map_settings_form&mapid=".intval($id)); |
980 | | | html_header(array("","Name", "Value","")); |
981 | | | |
982 | | | $n=0; |
983 | | | |
984 | | | |
985 | | | |
986 | | | if( is_array($settingrows) ) |
987 | | | { |
988 | | | if(sizeof($settingrows)>0) |
989 | | | { |
990 | | | foreach( $settingrows as $setting) |
991 | | | { |
992 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n); |
993 | | | print '<td><a href="?action=map_settings_form&mapid='.$id.'&id='.intval($setting['id']).'"><img src="../../images/graph_properties.gif" width="16" height="16" border="0" alt="Edit this definition">Edit</a></td>'; |
994 | | | print "<td>".htmlspecialchars($setting['optname'])."</td>"; |
995 | | | print "<td>".htmlspecialchars($setting['optvalue'])."</td>"; |
996 | | | print '<td><a href="?action=map_settings_delete&mapid='.$id.'&id='.intval($setting['id']).'"><img src="../../images/delete_icon_large.gif" width="12" height="12" border="0" alt="Remove this definition from this map"></a></td>'; |
997 | | | print "</tr>"; |
998 | | | $n++; |
999 | | | } |
1000 | | | } |
1001 | | | else |
1002 | | | { |
1003 | | | print "<tr>"; |
1004 | | | print "<td colspan=2>$nonemsg</td>"; |
1005 | | | print "</tr>"; |
1006 | | | } |
1007 | | | } |
1008 | | | |
1009 | | | html_end_box(); |
1010 | | | |
1011 | | | print "<div align=center>"; |
1012 | | | if($type == "group") print "<a href='?action=groupadmin'>Back to Group Admin</a>"; |
1013 | | | if($type == "global") print "<a href='?action='>Back to Map Admin</a>"; |
1014 | | | print "</div>"; |
1015 | | | } |
1016 | | | |
1017 | | | function weathermap_readonly_settings($id,$title="Settings") |
1018 | | | { |
1019 | | | global $colors, $config; |
1020 | | | |
1021 | | | if($id == 0) $query = "select * from weathermap_settings where mapid=0 and groupid=0"; |
1022 | | | if($id < 0) $query = "select * from weathermap_settings where mapid=0 and groupid=".(-intval($id)); |
1023 | | | if($id > 0) $query = "select * from weathermap_settings where mapid=".intval($id); |
1024 | | | |
1025 | | | $settings = db_fetch_assoc($query); |
1026 | | | |
1027 | | | html_start_box("<strong>$title</strong>", "70%", $colors["header"], "2", "center", ""); |
1028 | | | html_header(array("","Name", "Value","")); |
1029 | | | |
1030 | | | $n=0; |
1031 | | | |
1032 | | | if(sizeof($settings)>0) |
1033 | | | { |
1034 | | | foreach($settings as $setting) |
1035 | | | { |
1036 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n); |
1037 | | | print "<td></td>"; |
1038 | | | print "<td>".htmlspecialchars($setting['optname'])."</td><td>".htmlspecialchars($setting['optvalue'])."</td>"; |
1039 | | | print "<td></td>"; |
1040 | | | print "</tr>"; |
1041 | | | $n++; |
1042 | | | } |
1043 | | | } |
1044 | | | else |
1045 | | | { |
1046 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n); |
1047 | | | print "<td colspan=4><em>No Settings</em></td>"; |
1048 | | | print "</tr>"; |
1049 | | | } |
1050 | | | |
1051 | | | html_end_box(); |
1052 | | | |
1053 | | | } |
1054 | | | |
1055 | | | function weathermap_map_settings_form($mapid=0,$settingid=0) |
1056 | | | { |
1057 | | | global $colors, $config; |
1058 | | | |
1059 | | | // print "Per-map settings for map $id"; |
1060 | | | |
1061 | | | if($mapid > 0) $title = db_fetch_cell("select titlecache from weathermap_maps where id=".intval( $mapid )); |
1062 | | | if($mapid < 0) $title = db_fetch_cell("select name from weathermap_groups where id=".intval( -$mapid )); |
1063 | | | // print "Settings edit/add form."; |
1064 | | | |
1065 | | | $name = ""; |
1066 | | | $value = ""; |
1067 | | | |
1068 | | | if($settingid != 0) |
1069 | | | { |
1070 | | | |
1071 | | | $result = db_fetch_assoc("select * from weathermap_settings where id=".intval($settingid)); |
1072 | | | |
1073 | | | if(is_array($result) && sizeof($result)>0) |
1074 | | | { |
1075 | | | $name = $result[0]['optname']; |
1076 | | | $value = $result[0]['optvalue']; |
1077 | | | } |
1078 | | | } |
1079 | | | |
1080 | | | # print "$mapid $settingid |$name| |$value|"; |
1081 | | | |
1082 | | | $values_ar = array(); |
1083 | | | |
1084 | | | $field_ar = array( |
1085 | | | "mapid" => array("friendly_name" => "Map ID", "method" => "hidden_zero", "value" => $mapid ) , |
1086 | | | "id" => array("friendly_name" => "Setting ID", "method" => "hidden_zero", "value" => $settingid ) , |
1087 | | | "name" => array("friendly_name" => "Name", "method" => "textbox", "max_length"=>128,"description"=>"The name of the map-global SET variable", "value"=>$name), |
1088 | | | "value" => array("friendly_name" => "Value", "method" => "textbox", "max_length"=>128, "description"=>"What to set it to", "value"=>$value) |
1089 | | | ); |
1090 | | | |
1091 | | | $action = "Edit"; |
1092 | | | if($settingid == 0) $action ="Create"; |
1093 | | | |
1094 | | | if($mapid == 0) |
1095 | | | { |
1096 | | | $title = "setting for ALL maps"; |
1097 | | | } |
1098 | | | elseif($mapid < 0) |
1099 | | | { |
1100 | | | $grpid = -$mapid; |
1101 | | | $title = "per-group setting for Group $grpid: $title"; |
1102 | | | } |
1103 | | | else |
1104 | | | { |
1105 | | | $title = "per-map setting for Weathermap $mapid: $title"; |
1106 | | | } |
1107 | | | |
1108 | | | html_start_box("<strong>$action $title</strong>", "98%", $colors["header"], "3", "center", ""); |
1109 | | | draw_edit_form( array("config"=>$values_ar, "fields"=>$field_ar) ); |
1110 | | | html_end_box(); |
1111 | | | |
1112 | | | form_save_button("weathermap-cacti-plugin-mgmt.php?action=map_settings&id=".$mapid); |
1113 | | | |
1114 | | | } |
1115 | | | |
1116 | | | function weathermap_setting_save($mapid,$name,$value) |
1117 | | | { |
1118 | | | if($mapid >0) |
1119 | | | { |
1120 | | | db_execute("insert into weathermap_settings (mapid, optname, optvalue) values ($mapid,'".mysql_real_escape_string($name)."','".mysql_real_escape_string($value)."')"); |
1121 | | | } |
1122 | | | elseif($mapid <0) |
1123 | | | { |
1124 | | | db_execute("insert into weathermap_settings (mapid, groupid, optname, optvalue) values (0, -$mapid,'".mysql_real_escape_string($name)."','".mysql_real_escape_string($value)."')"); |
1125 | | | } |
1126 | | | else |
1127 | | | { |
1128 | | | db_execute("insert into weathermap_settings (mapid, groupid, optname, optvalue) values (0, 0,'".mysql_real_escape_string($name)."','".mysql_real_escape_string($value)."')"); |
1129 | | | } |
1130 | | | } |
1131 | | | function weathermap_setting_update($mapid,$settingid,$name,$value) |
1132 | | | { |
1133 | | | db_execute("update weathermap_settings set optname='".mysql_real_escape_string($name)."', optvalue='".mysql_real_escape_string($value)."' where id=".intval($settingid)); |
1134 | | | } |
1135 | | | |
1136 | | | function weathermap_setting_delete($mapid,$settingid) |
1137 | | | { |
1138 | | | db_execute("delete from weathermap_settings where id=".intval($settingid)." and mapid=".intval($mapid)); |
1139 | | | } |
1140 | | | |
1141 | | | function weathermap_chgroup($id) |
1142 | | | { |
1143 | | | global $colors; |
1144 | | | |
1145 | | | $title = db_fetch_cell("select titlecache from weathermap_maps where id=".intval($id)); |
1146 | | | $curgroup = db_fetch_cell("select group_id from weathermap_maps where id=".intval($id)); |
1147 | | | |
1148 | | | $n=0; |
1149 | | | |
1150 | | | print "<form>"; |
1151 | | | print "<input type=hidden name='map_id' value='".$id."'>"; |
1152 | | | print "<input type=hidden name='action' value='chgroup_update'>"; |
1153 | | | html_start_box("<strong>Edit map group for Weathermap $id: $title</strong>", "70%", $colors["header"], "2", "center", ""); |
1154 | | | |
1155 | | | # html_header(array("Group Name", "")); |
1156 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n++); |
1157 | | | print "<td><strong>Choose an existing Group:</strong><select name='new_group'>"; |
1158 | | | $SQL = "select * from weathermap_groups order by sortorder"; |
1159 | | | $results = db_fetch_assoc($SQL); |
1160 | | | |
1161 | | | foreach ($results as $grp) |
1162 | | | { |
1163 | | | print "<option "; |
1164 | | | if($grp['id'] == $curgroup) print " SELECTED "; |
1165 | | | print "value=".$grp['id'].">".htmlspecialchars($grp['name'])."</option>"; |
1166 | | | } |
1167 | | | |
1168 | | | print "</select>"; |
1169 | | | print '<input type="image" src="../../images/button_save.gif" border="0" alt="Change Group" title="Change Group" />'; |
1170 | | | print "</td>"; |
1171 | | | print "</tr>\n"; |
1172 | | | print "<tr><td></td></tr>"; |
1173 | | | |
1174 | | | print "<tr><td><p>or create a new group in the <strong><a href='?action=groupadmin'>group management screen</a></strong></p></td></tr>"; |
1175 | | | |
1176 | | | html_end_box(); |
1177 | | | print "</form>\n"; |
1178 | | | } |
1179 | | | |
1180 | | | function weathermap_group_form($id=0) |
1181 | | | { |
1182 | | | global $colors, $config; |
1183 | | | |
1184 | | | $grouptext = ""; |
1185 | | | // if id==0, it's an Add, otherwise it's an editor. |
1186 | | | if($id == 0) |
1187 | | | { |
1188 | | | print "Adding a group..."; |
1189 | | | } |
1190 | | | else |
1191 | | | { |
1192 | | | print "Editing group $id\n"; |
1193 | | | $grouptext = db_fetch_cell("select name from weathermap_groups where id=".$id); |
1194 | | | } |
1195 | | | |
1196 | | | print "<form action=weathermap-cacti-plugin-mgmt.php>\n<input type=hidden name=action value=group_update />\n"; |
1197 | | | |
1198 | | | print "Group Name: <input name=gname value='".htmlspecialchars($grouptext)."'/>\n"; |
1199 | | | if($id>0) |
1200 | | | { |
1201 | | | print "<input type=hidden name=id value=$id />\n"; |
1202 | | | print "Group Name: <input type=submit value='Update' />\n"; |
1203 | | | } |
1204 | | | else |
1205 | | | { |
1206 | | | # print "<input type=hidden name=id value=$id />\n"; |
1207 | | | print "Group Name: <input type=submit value='Add' />\n"; |
1208 | | | } |
1209 | | | |
1210 | | | print "</form>\n"; |
1211 | | | |
1212 | | | } |
1213 | | | |
1214 | | | function weathermap_group_editor() |
1215 | | | { |
1216 | | | global $colors, $config; |
1217 | | | |
1218 | | | html_start_box("<strong>Edit Map Groups</strong>", "70%", $colors["header"], "2", "center", "weathermap-cacti-plugin-mgmt.php?action=group_form&id=0"); |
1219 | | | html_header(array("", "Group Name", "Settings", "Sort Order", "")); |
1220 | | | |
1221 | | | $groups = db_fetch_assoc("select * from weathermap_groups order by sortorder"); |
1222 | | | |
1223 | | | $n = 0; |
1224 | | | |
1225 | | | if( is_array($groups) ) |
1226 | | | { |
1227 | | | if(sizeof($groups)>0) |
1228 | | | { |
1229 | | | foreach( $groups as $group) |
1230 | | | { |
1231 | | | form_alternate_row_color($colors["alternate"],$colors["light"],$n); |
1232 | | | print '<td><a href="weathermap-cacti-plugin-mgmt.php?action=group_form&id='.intval($group['id']).'"><img src="../../images/graph_properties.gif" width="16" height="16" border="0" alt="Rename This Group" title="Rename This Group">Rename</a></td>'; |
1233 | | | print "<td>".htmlspecialchars($group['name'])."</td>"; |
1234 | | | |
1235 | | | print "<td>"; |
1236 | | | |
1237 | | | print "<a href='?action=map_settings&id=-".$group['id']."'>"; |
1238 | | | $setting_count = db_fetch_cell("select count(*) from weathermap_settings where mapid=0 and groupid=".$group['id']); |
1239 | | | if($setting_count > 0) |
1240 | | | { |
1241 | | | print $setting_count." special"; |
1242 | | | if($setting_count>1) print "s"; |
1243 | | | } |
1244 | | | else |
1245 | | | { |
1246 | | | print "standard"; |
1247 | | | } |
1248 | | | print "</a>"; |
1249 | | | |
1250 | | | print "</td>"; |
1251 | | | |
1252 | | | |
1253 | | | print '<td>'; |
1254 | | | |
1255 | | | print '<a href="weathermap-cacti-plugin-mgmt.php?action=move_group_up&order='.$group['sortorder'].'&id='.$group['id'].'"><img src="../../images/move_up.gif" width="14" height="10" border="0" alt="Move Group Up" title="Move Group Up"></a>'; |
1256 | | | print '<a href="weathermap-cacti-plugin-mgmt.php?action=move_group_down&order='.$group['sortorder'].'&id='.$group['id'].'"><img src="../../images/move_down.gif" width="14" height="10" border="0" alt="Move Group Down" title="Move Group Down"></a>'; |
1257 | | | // print $map['sortorder']; |
1258 | | | |
1259 | | | print "</td>"; |
1260 | | | |
1261 | | | print '<td>'; |
1262 | | | if($group['id']>1) |
1263 | | | { |
1264 | | | print '<a href="weathermap-cacti-plugin-mgmt.php?action=groupadmin_delete&id='.intval($group['id']).'"><img src="../../images/delete_icon.gif" width="10" height="10" border="0" alt="Remove this definition from this map"></a>'; |
1265 | | | } |
1266 | | | print '</td>'; |
1267 | | | |
1268 | | | print "</tr>"; |
1269 | | | $n++; |
1270 | | | } |
1271 | | | } |
1272 | | | else |
1273 | | | { |
1274 | | | print "<tr>"; |
1275 | | | print "<td colspan=2>No groups are defined.</td>"; |
1276 | | | print "</tr>"; |
1277 | | | } |
1278 | | | } |
1279 | | | |
1280 | | | html_end_box(); |
1281 | | | } |
1282 | | | |
1283 | | | function weathermap_group_create($newname) |
1284 | | | { |
1285 | | | $sortorder = db_fetch_cell("select max(sortorder)+1 from weathermap_groups"); |
1286 | | | $SQL = sprintf("insert into weathermap_groups (name, sortorder) values ('%s',%d)", mysql_escape_string($newname), $sortorder); |
1287 | | | # print $SQL; |
1288 | | | db_execute($SQL); |
1289 | | | } |
1290 | | | |
1291 | | | function weathermap_group_update($id, $newname) |
1292 | | | { |
1293 | | | |
1294 | | | $SQL = sprintf("update weathermap_groups set name='%s' where id=%d", mysql_escape_string($newname), $id); |
1295 | | | # print $SQL; |
1296 | | | db_execute($SQL); |
1297 | | | } |
1298 | | | |
1299 | | | function weathermap_group_delete($id) |
1300 | | | { |
1301 | | | $SQL1 = "SELECT MIN(id) from weathermap_groups where id <> ". $id; |
1302 | | | $newid = db_fetch_cell($SQL1); |
1303 | | | # move any maps out of this group into a still-existing one |
1304 | | | $SQL2 = "UPDATE weathermap_maps set group_id=$newid where group_id=".$id; |
1305 | | | # then delete the group |
1306 | | | $SQL3 = "DELETE from weathermap_groups where id=".$id; |
1307 | | | db_execute($SQL2); |
1308 | | | db_execute($SQL3); |
1309 | | | } |
1310 | | | |
1311 | | | // vim:ts=4:sw=4: |
1312 | | | ?> |
1313 | | | |