-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsetup.php
1252 lines (1035 loc) · 43.6 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2022-2024 The Cacti Group, Inc. |
| |
| Based on the Original Plugin developed by Howard Jones |
| |
| Copyright (C) 2005-2022 Howard Jones and contributors |
| |
| Permission is hereby granted, free of charge, to any person obtaining |
| a copy of this software and associated documentation files |
| (the "Software"), to deal in the Software without restriction, |
| including without limitation the rights to use, copy, modify, merge, |
| publish, distribute, sublicense, and/or sell copies of the Software, |
| and to permit persons to whom the Software is furnished to do so, |
| subject to the following conditions: |
| |
| The above copyright notice and this permission notice shall be |
| included in all copies or substantial portions of the Software. |
| |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| SOFTWARE. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| Extensions to Howard Jones' original work are designed, written, and |
| maintained by the Cacti Group. |
| |
| Howard Jones was the original author of Weathermap. You can reach |
| him at: howie@thingy.com |
+-------------------------------------------------------------------------+
| http://www.network-weathermap.com/ |
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
if (!defined('WM_COPYRIGHT_YEARS')) {
define('WM_COPYRIGHT_YEARS', '2008-2024');
}
function plugin_weathermap_install() {
api_plugin_register_hook('weathermap', 'config_arrays', 'weathermap_config_arrays', 'setup.php');
api_plugin_register_hook('weathermap', 'config_settings', 'weathermap_config_settings', 'setup.php');
api_plugin_register_hook('weathermap', 'top_header_tabs', 'weathermap_show_tab', 'setup.php');
api_plugin_register_hook('weathermap', 'top_graph_header_tabs', 'weathermap_show_tab', 'setup.php');
api_plugin_register_hook('weathermap', 'draw_navigation_text', 'weathermap_draw_navigation_text', 'setup.php');
api_plugin_register_hook('weathermap', 'top_graph_refresh', 'weathermap_top_graph_refresh', 'setup.php');
api_plugin_register_hook('weathermap', 'page_title', 'weathermap_page_title', 'setup.php');
api_plugin_register_hook('weathermap', 'poller_top', 'weathermap_poller_top', 'setup.php');
api_plugin_register_hook('weathermap', 'poller_output', 'weathermap_poller_output', 'setup.php');
api_plugin_register_hook('weathermap', 'poller_bottom', 'weathermap_poller_bottom', 'setup.php');
api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin.php', 'View Weathermaps', 1);
api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin-mgmt.php,weathermap-cacti-plugin-mgmt-groups.php', 'Manage Weathermap', 1);
api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin-editor.php', 'Edit Weathermaps', 1);
weathermap_determine_config();
if (!defined('WM_CONFIGDIR')) {
raise_message('weathermap_info', __('Please rename your config.php.dist and in there define your output and config directories. Make sure you move those directories out of the WeatherMap plugin directory.', 'weathermap'), MESSAGE_LEVEL_ERROR);
return false;
}
weathermap_setup_table();
}
function plugin_weathermap_uninstall() {
set_config_option('weathermap_version', '');
db_execute('DROP TABLE IF EXISTS weathermap_auth');
db_execute('DROP TABLE IF EXISTS weathermap_data');
db_execute('DROP TABLE IF EXISTS weathermap_maps');
db_execute('DROP TABLE IF EXISTS weathermap_groups');
db_execute('DROP TABLE IF EXISTS weathermap_settings');
}
function plugin_weathermap_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/weathermap/INFO', true);
return $info['info'];
}
function plugin_weathermap_numeric_version() {
static $current;
if ($current == null) {
$current = plugin_weathermap_version();
}
return $current['version'];
}
function plugin_weathermap_check_config() {
// Here we will check to ensure everything is configured
if (!file_exists(dirname(__FILE__) . '/config.php')) {
raise_message('weathermap_info', __('Please rename your config.php.dist and in there define your output and config directories. Make sure you move those directories out of the WeatherMap plugin directory.', 'weathermap'), MESSAGE_LEVEL_ERROR);
return false;
}
if (api_plugin_installed('weathermap')) {
plugin_weathermap_upgrade();
}
return true;
}
function plugin_weathermap_upgrade() {
global $config;
$files = array('index.php', 'plugins.php');
if (!in_array(get_current_page(), $files) && strpos(get_current_page(), 'weathermap-cacti') === false) {
return;
}
include_once($config['base_path'] . '/plugins/weathermap/lib/poller-common.php');
if (function_exists('api_plugin_upgrade_register')) {
if (!api_plugin_upgrade_register('syslog')) {
// No upgrade required
return;
}
} else {
$info = plugin_weathermap_version();
$current = $info['version'];
$old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='weathermap'");
if ($current != $old) {
db_execute_prepared("UPDATE plugin_config SET
version = ?, name = ?, author = ?, webpage = ?
WHERE directory = ?",
array(
$info['version'],
$info['longname'],
$info['author'],
$info['homepage'],
$info['name']
)
);
} else {
// No upgrade required
return;
}
}
db_execute_prepared('UPDATE plugin_realms
SET display = ? WHERE file = ?',
array('View Weathermaps', 'weathermap-cacti-plugin.php'));
db_execute_prepared('UPDATE plugin_realms
SET display = ? WHERE file = ?',
array('Edit Weathermaps', 'weathermap-cacti-plugin-editor.php'));
db_execute_prepared('UPDATE plugin_realms
SET display = ? WHERE file = ?',
array('Manage Weathermap', 'weathermap-cacti-plugin-mgmt.php'));
db_execute_prepared('UPDATE plugin_realms
SET file = ? WHERE file = ?',
array('weathermap-cacti-plugin-mgmt.php,weathermap-cacti-plugin-mgmt-groups.php', 'weathermap-cacti-plugin-mgmt.php'));
db_execute('DELETE FROM plugin_hooks WHERE name = "weathermap" AND hook = "page_head"');
weathermap_repair_maps();
return false;
}
function weathermap_determine_config() {
// Setup the location for weathermap files
if (!defined('WM_CONFIGDIR') && file_exists(dirname(__FILE__) . '/config.php')) {
include_once(dirname(__FILE__) . '/config.php');
}
}
function weathermap_poller_top() {
global $weathermap_poller_start_time;
$n = time();
// round to the nearest minute, since that's all we need for the crontab-style stuff
$weathermap_poller_start_time = $n - ($n % 60);
}
function weathermap_page_title($t) {
if (preg_match('/plugins\/weathermap\//', $_SERVER['REQUEST_URI'], $matches)) {
if (preg_match('/plugins\/weathermap\/weathermap-cacti-plugin.php\?action=viewmap&id=([^&]+)/', $_SERVER['REQUEST_URI'], $matches)) {
$mapid = $matches[1];
if (preg_match('/^\d+$/', $mapid)) {
$title = db_fetch_cell_prepared('SELECT titlecache FROM weathermap_maps WHERE id = ?', array($mapid));
} else {
$title = db_fetch_cell_prepared('SELECT titlecache FROM weathermap_maps WHERE filehash = ?', array($mapid));
}
if ($title != '') {
$t .= ' > ' . $title;
}
}
return($t);
}
return($t);
}
function weathermap_top_graph_refresh($refresh) {
if (basename($_SERVER['PHP_SELF']) != 'weathermap-cacti-plugin.php') {
return $refresh;
}
// if we're cycling maps, then we want to handle reloads ourselves, thanks
if (isset_request_var('action') && get_request_var('action') == 'viewmapcycle') {
return (86400);
} elseif (get_request_var('action') == '' || get_request_var('action') == 'viewmap') {
return (read_user_setting('page_refresh'));
}
return ($refresh);
}
function weathermap_config_settings() {
global $tabs, $settings;
$tabs['wmap'] = __('Weathermap', 'weathermap');
$temp = array(
'weathermap_header' => array(
'friendly_name' => __('Network Weathermap', 'weathermap'),
'method' => 'spacer',
),
'weathermap_pagestyle' => array(
'friendly_name' => __('Page style', 'weathermap'),
'description' => __('How to display multiple maps.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
0 => __('Thumbnail Overview', 'weathermap'),
1 => __('Full Images', 'weathermap'),
2 => __('Show Only First', 'weathermap'),
)
),
'weathermap_thumbsize' => array(
'friendly_name' => __('Thumbnail Maximum Size', 'weathermap'),
'description' => __('The maximum width or height for thumbnails in thumbnail view, in pixels. Takes effect after the next poller run.', 'weathermap'),
'method' => 'textbox',
'size' => 3,
'max_length' => 4,
),
'weathermap_width' => array(
'friendly_name' => __('Hover Graph Default Width', 'weathermap'),
'description' => __('The default width of the RRDtool Graphs that appear when you over on a Link.', 'weathermap'),
'method' => 'textbox',
'default' => 400,
'size' => 3,
'max_length' => 4,
),
'weathermap_height' => array(
'friendly_name' => __('Hover Graph Default Height', 'weathermap'),
'description' => __('The default height of the RRDtool Graphs that appear when you over on a Link.', 'weathermap'),
'method' => 'textbox',
'default' => 125,
'size' => 3,
'max_length' => 4,
),
'weathermap_nolegend' => array(
'friendly_name' => __('Hover Graph Style', 'weathermap'),
'description' => __('When hovering over the Links or Nodes, what style of Graph would you like displayed?', 'weathermap'),
'method' => 'drop_array',
'array' => array(
'thumb' => __('Thumbnail Graphs', 'weathermap'),
'full' => __('Full Graphs', 'weathermap')
)
),
'weathermap_timeout' => array(
'friendly_name' => __('Map Processing Timeout', 'weathermap'),
'description' => __('How much time should be allowed before timing out the periodic map generation process.', 'weathermap'),
'method' => 'drop_array',
'default' => 300,
'array' => array(
'300' => __('%d Minutes', 5, 'weathermap'),
'600' => __('%d Minutes', 10, 'weathermap'),
'900' => __('%d Minutes', 15, 'weathermap'),
'1200' => __('%d Minutes', 20, 'weathermap')
)
),
'weathermap_cycle_refresh' => array(
'friendly_name' => __('Refresh Time', 'weathermap'),
'description' => __('How often to refresh the page in Cycle mode. Automatic makes all available maps fit into 5 minutes.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
0 => __('Automatic', 'weathermap'),
5 => __('%d Seconds', 5, 'weathermap'),
15 => __('%d Seconds', 15, 'weathermap'),
30 => __('%d Seconds', 30, 'weathermap'),
60 => __('%d Minute', 1, 'weathermap'),
120 => __('%d Minutes', 2, 'weathermap'),
300 => __('%d Minutes', 3, 'weathermap'),
)
),
'weathermap_output_format' => array(
'friendly_name' => __('Output Format', 'weathermap'),
'description' => __('What format do you prefer for the generated map images and thumbnails?', 'weathermap'),
'method' => 'drop_array',
'array' => array(
'png' => __('PNG (default)', 'weathermap'),
'jpg' => __('JPEG', 'weathermap'),
'gif' => __('GIF', 'weathermap'),
)
),
'weathermap_render_period' => array(
'friendly_name' => __('Map Rendering Interval', 'weathermap'),
'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.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
-1 => __('Never (manual updates)', 'weathermap'),
0 => __('Every Poller Cycle (default)', 'weathermap'),
2 => __('Every %d Poller Cycles', 2, 'weathermap'),
3 => __('Every %d Poller Cycles', 3, 'weathermap'),
4 => __('Every %d Poller Cycles', 4, 'weathermap'),
5 => __('Every %d Poller Cycles', 5, 'weathermap'),
10 => __('Every %d Poller Cycles', 10, 'weathermap'),
12 => __('Every %d Poller Cycles', 12, 'weathermap'),
24 => __('Every %d Poller Cycles', 24, 'weathermap'),
36 => __('Every %d Poller Cycles', 36, 'weathermap'),
48 => __('Every %d Poller Cycles', 48, 'weathermap'),
72 => __('Every %d Poller Cycles', 72, 'weathermap'),
288 => __('Every %d Poller Cycles', 288, 'weathermap'),
),
),
'weathermap_showversion' => array(
'friendly_name' => __('Show Weathermap Help Links', 'weathermap'),
'description' => __('If checked, all Weathermap pages will include a link to documentation.', 'weathermap'),
'method' => 'checkbox',
'default' => ''
),
'weathermap_all_tab' => array(
'friendly_name' => __('Show \'All\' Tab', 'weathermap'),
'description' => __('When using groups, add an \'All Maps\' tab to the tab bar.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
0 => __('No (default)', 'weathermap'),
1 => __('Yes', 'weathermap'),
)
),
'weathermap_map_selector' => array(
'friendly_name' => __('Show Map Selector', 'weathermap'),
'description' => __('Show a combo-box map selector on the full-screen map view.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
0 => __('No', 'weathermap'),
1 => __('Yes (default)', 'weathermap'),
)
),
'weathermap_quiet_logging' => array(
'friendly_name' => __('Quiet Logging', 'weathermap'),
'description' => __('By default, even in LOW level logging, Weathermap logs normal activity. This makes it REALLY log only errors in LOW mode.', 'weathermap'),
'method' => 'drop_array',
'array' => array(
0 => __('Chatty (default)', 'weathermap'),
1 => __('Quiet', 'weathermap'),
)
)
);
if (isset($settings['wmap'])) {
$settings['wmap'] = array_merge($settings['wmap'], $temp);
} else {
$settings['wmap'] = $temp;
}
}
function weathermap_setup_table() {
global $config, $database_default;
$dbversion = read_config_option('weathermap_db_version');
$myversion = plugin_weathermap_numeric_version();
// only bother with all this if it's a new install, a new version, or we're in a development version
// - saves a handful of db hits per request!
if (($dbversion == '') || (preg_match('/dev$/', $myversion)) || ($dbversion != $myversion) || !db_table_exists('weathermap_maps')) {
db_execute('CREATE TABLE IF NOT EXISTS weathermap_maps (
`id` int(11) NOT NULL auto_increment,
`sortorder` int(11) NOT NULL default 0,
`group_id` int(11) NOT NULL default 1,
`active` set("on","off") NOT NULL default "on",
`configfile` varchar(255) NOT NULL,
`imagefile` varchar(255) NOT NULL,
`htmlfile` varchar(255) NOT NULL,
`titlecache` varchar(60) NOT NULL,
`filehash` varchar (40) NOT NULL default "",
`warncount` int(11) NOT NULL default 0,
`debug` set("on","off","once") NOT NULL DEFAULT "off",
`config` text NOT NULL,
`thumb_width` int(11) NOT NULL default 0,
`thumb_height` int(11) NOT NULL default 0,
`schedule` varchar(32) NOT NULL default "*",
`archiving` set("on","off") NOT NULL default "off",
`duration` double NOT NULL default "0",
`last_runtime` int unsigned not null default "0",
PRIMARY KEY (id),
UNIQUE KEY configfile(configfile))
ENGINE = InnoDB
ROW_FORMAT=Dynamic');
db_execute('CREATE TABLE IF NOT EXISTS weathermap_auth (
`userid` mediumint(9) NOT NULL default "0",
`mapid` int(11) NOT NULL default "0")
ENGINE=InnoDB
ROW_FORMAT=Dynamic');
db_execute('CREATE TABLE IF NOT EXISTS weathermap_settings (
`id` int(11) NOT NULL auto_increment,
`mapid` int(11) NOT NULL default "0",
`groupid` int(11) NOT NULL default "0",
`optname` varchar(128) NOT NULL default "",
`optvalue` varchar(128) NOT NULL default "",
PRIMARY KEY (id),
UNIQUE INDEX mapid_groupid_optname(mapid, groupid, optname))
ENGINE=InnoDB
ROW_FORMAT=Dynamic');
db_execute('CREATE TABLE IF NOT EXISTS weathermap_data (
`id` int(11) NOT NULL auto_increment,
`rrdfile` varchar(255) NOT NULL,
`data_source_name` varchar(19) NOT NULL,
`last_time` int(11) NOT NULL DEFAULT -1,
`last_value` varchar(255) NOT NULL DEFAULT "",
`last_calc` varchar(255) NOT NULL DEFAULT "",
`sequence` int(11) NOT NULL DEFAULT 0,
`local_data_id` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (id),
KEY rrdfile (rrdfile(250)),
KEY local_data_id (local_data_id),
KEY data_source_name (data_source_name))
ENGINE=InnoDB
ROW_FORMAT=Dynamic');
if (!db_table_exists('weathermap_groups')) {
db_execute('CREATE TABLE IF NOT EXISTS weathermap_groups (
`id` INT(11) NOT NULL auto_increment,
`name` VARCHAR(128) NOT NULL default "",
`sortorder` INT(11) NOT NULL default 0,
PRIMARY KEY (id))
ENGINE=InnoDB
ROW_FORMAT=Dynamic');
db_execute('INSERT INTO weathermap_groups (id, name, sortorder) VALUES (1, "Weathermaps", 1)');
}
db_execute('DELETE FROM weathermap_data WHERE local_data_id = 0');
if (db_column_exists('weathermap_maps', 'sortorder')) {
db_execute('UPDATE weathermap_maps SET sortorder = id WHERE sortorder IS NULL');
}
if (!db_column_exists('weathermap_maps', 'sortorder')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN sortorder int(11) NOT NULL default 0 AFTER id');
}
if (!db_column_exists('weathermap_maps', 'filehash')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN filehash varchar(40) NOT NULL default "" AFTER titlecache');
}
if (!db_column_exists('weathermap_maps', 'warncount')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN warncount int(11) NOT NULL default 0 AFTER filehash');
}
if (!db_column_exists('weathermap_maps', 'debug')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN debug `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount');
}
if (!db_column_exists('weathermap_maps', 'config')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN config text NOT NULL default "" AFTER warncount');
}
if (!db_column_exists('weathermap_maps', 'thumb_width')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN thumb_width int(11) NOT NULL default 0 AFTER config');
}
if (!db_column_exists('weathermap_maps', 'thumb_height')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN thumb_height int(11) NOT NULL default 0 AFTER thumb_width');
}
if (!db_column_exists('weathermap_maps', 'schedule')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN schedule varchar(32) NOT NULL default "*" AFTER thumb_height');
}
if (!db_column_exists('weathermap_maps', 'archiving')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN archiving set("on","off") NOT NULL default "off" AFTER schedule');
}
if (!db_column_exists('weathermap_maps', 'group_id')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN group_id int(11) NOT NULL default 1 AFTER sortorder');
}
if (!db_column_exists('weathermap_settings', 'groupid')) {
db_execute('ALTER TABLE `weathermap_settings` ADD COLUMN `groupid` INT NOT NULL DEFAULT "0" AFTER `mapid`');
}
if (!db_column_exists('weathermap_maps', 'duration')) {
db_execute('ALTER TABLE `weathermap_maps` ADD COLUMN `duration` double NOT NULL DEFAULT "0" AFTER `archiving`');
}
if (!db_column_exists('weathermap_maps', 'last_runtime')) {
db_execute('ALTER TABLE `weathermap_maps` ADD COLUMN `last_runtime` INT UNSIGNED NOT NULL DEFAULT "0" AFTER `duration`');
}
if (!db_index_exists('weathermap_maps', 'configfile')) {
db_execute('ALTER TABLE `weathermap_maps` ADD UNIQUE INDEX `configfile`(`configfile`)');
}
db_execute('UPDATE weathermap_maps SET `filehash` = LEFT(MD5(concat(id,configfile,rand())),20) WHERE `filehash` = ""');
if (!db_column_exists('weathermap_data', 'local_data_id')) {
db_execute('ALTER TABLE weathermap_data
ADD COLUMN local_data_id int(11) NOT NULL default 0 AFTER sequence,
ADD INDEX (`local_data_id`)');
}
// create the settings entries, if necessary
$pagestyle = read_config_option('weathermap_pagestyle');
if ($pagestyle == '' || $pagestyle < 0 || $pagestyle > 2) {
set_config_option('weathermap_pagestyle', '0');
}
$cycledelay = read_config_option('weathermap_cycle_refresh');
if ($cycledelay == '' || $cycledelay < 0) {
set_config_option('weathermap_cycle_refresh', '0');
}
$renderperiod = read_config_option('weathermap_render_period');
if ($renderperiod == '' || $renderperiod < -1) {
set_config_option('weathermap_render_period', '0');
}
$quietlogging = read_config_option('weathermap_quiet_logging');
if ($quietlogging == '' || $quietlogging < -1) {
set_config_option('weathermap_quiet_logging', '0');
}
$rendercounter = read_config_option('weathermap_render_counter');
if ($rendercounter == '' || $rendercounter < 0) {
set_config_option('weathermap_render_counter', '0');
}
$outputformat = read_config_option('weathermap_output_format');
if ($outputformat == '') {
set_config_option('weathermap_output_format', 'png');
}
$tsize = read_config_option('weathermap_thumbsize');
if ($tsize == '' || $tsize < 1) {
set_config_option('weathermap_thumbsize', '250');
}
$ms = read_config_option('weathermap_map_selector');
if ($ms == '' || $ms < 0 || $ms > 1) {
set_config_option('weathermap_map_selector', '1');
}
$at = read_config_option('weathermap_all_tab');
if ($at == '' || $at < 0 || $at > 1) {
set_config_option('weathermap_all_tab', '0');
}
// update the version, so we can skip this next time
set_config_option('weathermap_db_version', $myversion);
// patch up the sortorder for any maps that don't have one.
db_execute('UPDATE weathermap_maps SET sortorder = id WHERE sortorder IS NULL OR sortorder = 0');
// make sure Weathermaps uses a sane width for columns
db_execute('ALTER TABLE weathermap_maps MODIFY COLUMN `configfile` varchar(255) NOT NULL');
db_execute('ALTER TABLE weathermap_maps MODIFY COLUMN `imagefile` varchar(255) NOT NULL');
db_execute('ALTER TABLE weathermap_maps MODIFY COLUMN `htmlfile` varchar(255) NOT NULL');
db_execute('ALTER TABLE weathermap_maps MODIFY COLUMN `titlecache` varchar(60) NOT NULL');
// Check and enable boost support if it's enabled
weathermap_check_set_boost();
// Correct weathermap settings table of duplicate entries
while (true) {
$rows = db_fetch_assoc('SELECT mapid, groupid, optname, COUNT(*) AS totals
FROM weathermap_settings
GROUP BY mapid, groupid, optname
HAVING totals > 1');
if (cacti_sizeof($rows)) {
foreach($rows as $row) {
db_execute_prepared('DELETE FROM weathermap_settings
WHERE mapid = ? AND groupid = ? AND optname = ?
LIMIT 1',
array($row['mapid'], $row['groupid'], $row['optname']));
}
} else {
break;
}
}
}
}
function weathermap_check_set_boost() {
$boost = read_config_option('boost_rrd_update_enable') == 'on' ? true:false;
if ($boost) {
$exists = db_fetch_row('SELECT id, optvalue
FROM weathermap_settings
WHERE mapid = 0
AND groupid = 0
AND optname = "rrd_use_poller_output"');
if (!cacti_sizeof($exists)) {
db_execute('INSERT INTO weathermap_settings (mapid, groupid, optname, optvalue)
VALUES (0, 0, "rrd_use_poller_output", 1)');
} elseif ($exists['optvalue'] == 0) {
db_execute_prepared('UPDATE weathermap_settings
SET optvalue = 1
WHERE id = ?',
array($exists['id']));
}
}
}
function weathermap_config_arrays() {
global $menu;
global $tree_item_types, $tree_item_handlers;
plugin_weathermap_upgrade();
// if there is support for custom graph tree types, then register ourselves
if (isset($tree_item_handlers)) {
$tree_item_types[10] = __('Weathermap', 'weathermap');
$tree_item_handlers[10] = array(
'render' => 'weathermap_tree_item_render',
'name' => 'weathermap_tree_item_name',
'edit' => 'weathermap_tree_item_edit'
);
}
$wm_menu = array(
'plugins/weathermap/weathermap-cacti-plugin-mgmt.php' => __('Weathermaps', 'weathermap'),
'plugins/weathermap/weathermap-cacti-plugin-mgmt-groups.php' => __('Weathermap Groups', 'weathermap')
);
$menu[__('Management')]['plugins/weathermap/weathermap-cacti-plugin-mgmt.php'] = $wm_menu;
// These simply need to be declared for i18n the realm names
$realm_array = array(
__('View Weathermaps', 'weathermap'),
__('Edit Weathermaps', 'weathermap'),
__('Manage Weathermap', 'weathermap')
);
if (function_exists('auth_augment_roles')) {
auth_augment_roles_byname(__('General Administration'), 'Manage Weathermap');
auth_augment_roles_byname(__('General Administration'), 'Edit Weathermaps');
auth_augment_roles_byname(__('Normal User'), 'View Weathermaps');
}
}
function weathermap_tree_item_render($leaf) {
weathermap_determine_config();
if (defined('WM_CONFIGDIR')) {
$confdir = WM_CONFIGDIR;
} else {
$confdir = __DIR__ . '/configs/';
}
if (defined('WM_OUTPUTDIR')) {
$outdir = WM_OUTPUTDIR;
} else {
$outdir = __DIR__ . '/output/';
}
$map = db_fetch_row_prepared('SELECT weathermap_maps.*
FROM weathermap_auth, weathermap_maps
WHERE weathermap_maps.id = weathermap_auth.mapid
AND active = "on"
AND (userid = ? OR userid = 0)
AND weathermap_maps.id = ?',
array($_SESSION['sess_user_id'], $leaf['item_id']));
if (cacti_sizeof($map)) {
$htmlfile = $outdir . 'weathermap_' . $map['id'] . '.html';
$maptitle = $map['titlecache'];
if ($maptitle == '') {
$maptitle = __('Map for config file: %s', $map['configfile'], 'weathermap');
}
print "<br/><table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellpadding='1'>";
?>
<tr class='even'>
<td>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td class='textHeader' nowrap><?php print $maptitle; ?></td>
</tr>
</table>
</td>
</tr>
<?php
print '<tr><td>';
if (file_exists($htmlfile)) {
include($htmlfile);
}
print '</td></tr>';
print '</table>';
}
}
// calculate the name that cacti will use for this item in the tree views
function weathermap_tree_item_name($item_id) {
$description = db_fetch_cell_prepared('SELECT titlecache
FROM weathermap_maps
WHERE id = ?',
array($item_id));
if ($description == '') {
$configfile = db_fetch_cell_prepared('SELECT configfile
FROM weathermap_maps
WHERE id = ?',
array($item_id));
$description = __('Map for config file: %s', $configfile, 'weathermap');
}
return $description;
}
// the edit form, for when you add or edit a map in a graph tree
function weathermap_tree_item_edit($tree_item) {
form_alternate_row();
$titles = db_fetch_assoc("SELECT id, CONCAT_WS('',titlecache,' (', configfile, ')') AS name
FROM weathermap_maps
WHERE active = 'on'
ORDER BY titlecache, configfile");
print "<td width='50%'><font class='textEditTitle'>" . __('Map', 'weathermap') . '</font><br />' . __('Choose which weathermap to add to the tree.', 'weathermap') . '</td><td>';
form_dropdown('item_id', $titles, 'name', 'id', $tree_item['item_id'], '', '0');
print '</td></tr>';
form_alternate_row();
print '<td width="50%"><font class="textEditTitle">' . __('Style', 'weathermap') . '</font><br />' . __('How should the map be displayed?', 'weathermap') . '</td><td>';
print '<select name="item_options">
<option value="1">' . __('Thumbnail', 'weathermap') . '</option>
<option value="2">' . __('Full Size', 'weathermap') . '</option></select>';
print '</td></tr>';
}
function weathermap_show_tab() {
global $config;
$tabstyle = read_config_option('superlinks_tabstyle');
if (api_plugin_user_realm_auth('weathermap-cacti-plugin.php')) {
if ($tabstyle > 0) {
$prefix = 's_';
} else {
$prefix = '';
}
print '<a href="' . $config['url_path'] . 'plugins/weathermap/weathermap-cacti-plugin.php"><img src="' . $config['url_path'] . 'plugins/weathermap/images/' . $prefix . 'tab_weathermap';
if (preg_match('/plugins\/weathermap\/weathermap-cacti-plugin.php/', $_SERVER['REQUEST_URI'], $matches)) {
print '_red';
}
print '.gif" alt="weathermap" align="absmiddle" border="0"></a>';
}
weathermap_setup_table();
}
function weathermap_draw_navigation_text($nav) {
$nav['weathermap-cacti-plugin.php:'] = array(
'title' => __('Weathermap', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:viewmap'] = array(
'title' => __('Weathermap', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:liveview'] = array(
'title' => __('Weathermap', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:liveviewimage'] = array(
'title' => __('Weathermap', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:viewmapcycle'] = array(
'title' => __('Weathermap', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:mrss'] = array(
'title' => __('Weathermaps', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:viewimage'] = array(
'title' => __('View Map Image', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin.php:viewthumb'] = array(
'title' => __('View Map Thumbnail', 'weathermap'),
'mapping' => '',
'url' => 'weathermap-cacti-plugin.php',
'level' => '0'
);
$nav['weathermap-cacti-plugin-mgmt.php:'] = array(
'title' => __('Weathermaps', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:addmap_picker'] = array(
'title' => __('Add Map', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:viewconfig'] = array(
'title' => __('View Configuration', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:,weathermap-cacti-plugin-mgmt.php:addmap_picker',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '3'
);
$nav['weathermap-cacti-plugin-mgmt.php:addmap'] = array(
'title' => __('Add Map', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:editmap'] = array(
'title' => __('Edit Map', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:editor'] = array(
'title' => __('Weathermap Editor', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:perms_edit'] = array(
'title' => __('Edit Permissions', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:map_settings'] = array(
'title' => __('Map Settings', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:map_settings_form'] = array(
'title' => __('Map Settings', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:map_settings_delete'] = array(
'title' => __('Map Settings Delete', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:map_settings_update'] = array(
'title' => __('Map Settings Update', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:map_settings_add'] = array(
'title' => __('Map Settings Add', 'weathermap'),
'mapping' => 'index.php:,weathermap-cacti-plugin-mgmt.php:',
'url' => '',
'level' => '2'
);
$nav['weathermap-cacti-plugin-mgmt.php:perms_edit'] = array(
'title' => __('Permissions Edit', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:perms_add_user'] = array(
'title' => __('Add User', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:perms_delete_user'] = array(
'title' => __('Delete User', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:delete_map'] = array(
'title' => __('Delete Map', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:move_map_down'] = array(
'title' => __('Move Map Up', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:move_map_up'] = array(
'title' => __('Move Map Up', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:move_group_down'] = array(
'title' => __('Move Group Down', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:move_group_up'] = array(
'title' => __('Move Group Up', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);
$nav['weathermap-cacti-plugin-mgmt.php:group_form'] = array(
'title' => __('Group Edit', 'weathermap'),
'mapping' => 'index.php:',
'url' => 'weathermap-cacti-plugin-mgmt.php',
'level' => '1'
);