-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
plugins.php
1946 lines (1598 loc) · 69.3 KB
/
plugins.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) 2004-2024 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include('./include/auth.php');
include_once('./lib/poller.php');
global $local_db_cnn_id;
/* the list of all known actions */
$actions = array(
/* list functions */
'list' => __('Loaded Plugins'),
'avail' => __('Available Plugins'),
/* classic calls */
'install' => __('Install'),
'enable' => __('Enable'),
'disable' => __('Disable'),
'uninstall' => __('Uninstall'),
'check' => __('Check Configuration'),
'confirm' => __('Install Prompt Confirmation'),
/* removed plugin data handling */
'remove_data' => __('Remove Plugin Data'),
/* load order switching */
'moveup' => __('Move Up'),
'movedown' => __('Move Down'),
/* plugin archiving */
'archive' => __('Archive'),
'restore' => __('Archive Restore'),
'delete' => __('Archive Delete'),
/* manage downloaded content */
'load' => __('Install from Downloaded Plugins'),
'readme' => __('View the Plugins Readme File'),
'changelog' => __('View the Plugins ChangeLog File'),
'latest' => __('Fetch Latest Plugin Archives'),
/* remote poller plugin functions */
'remote_enable' => __('Remote Enable'),
'remote_disable' => __('Remote Disable'),
/* drag and drop */
'ajax_dnd' => __('Drag and Drop'),
);
$status_names = array(
-1 => __('Not Compatible'),
-2 => __('Disabled Naming Errors'),
-3 => __('Disabled Invalid Directory'),
-4 => __('Disabled No INFO File'),
-5 => __('Disabled Directory Missing'),
0 => __('Loaded, Not Installed'),
1 => __('Installed/Active'),
2 => __('Configuration Issues'),
3 => __('Awaiting Upgrade'),
4 => __('Installed/Inactive'),
5 => __('Installed or Active'),
6 => __('Installable'),
7 => __('Disabled by Error'),
8 => __('Archived'),
);
/* temporary workaround till project finished */
db_execute("CREATE TABLE IF NOT EXISTS `plugin_available` (
`plugin` varchar(32) NOT NULL DEFAULT '',
`description` varchar(128) NOT NULL DEFAULT '',
`author` varchar(40) NOT NULL DEFAULT '',
`webpage` varchar(128) NOT NULL DEFAULT '',
`tag_name` varchar(20) NOT NULL DEFAULT '',
`published_at` timestamp NULL DEFAULT NULL,
`compat` varchar(20) NOT NULL DEFAULT '',
`requires` varchar(128) NOT NULL DEFAULT '',
`body` blob DEFAULT NULL,
`info` blob DEFAULT NULL,
`readme` blob DEFAULT NULL,
`changelog` blob DEFAULT NULL,
`archive` longblob DEFAULT NULL,
`last_updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`plugin`,`tag_name`))
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_archive` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`plugin` varchar(32) NOT NULL DEFAULT '',
`description` varchar(64) NOT NULL DEFAULT '',
`author` varchar(64) NOT NULL DEFAULT '',
`webpage` varchar(255) NOT NULL DEFAULT '',
`user_id` int(10) unsigned NOT NULL DEFAULT 0,
`version` varchar(10) NOT NULL DEFAULT '',
`requires` varchar(128) DEFAULT '',
`compat` varchar(20) NOT NULL DEFAULT '',
`dir_md5sum` varchar(32) NOT NULL DEFAULT '',
`last_updated` timestamp NULL DEFAULT NULL,
`archive` longblob DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `directory` (`plugin`))
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC");
/* get the list of installed plugins */
$pluginslist = plugins_retrieve_plugin_list();
set_default_action('list');
/**
* this is for legacy support for plugins like syslog
* that are dependent on the mode request variable
* to be set.
*/
if (isset_request_var('mode')) {
set_request_var('action', get_nfilter_request_var('mode'));
if (isset_request_var('id')) {
set_request_var('plugin', get_nfilter_request_var('id'));
}
}
$action = get_nfilter_request_var('action');
/* pre-check for actions that will fail by default */
if (isset_request_var('plugin')) {
get_filter_request_var('plugin', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9 _]+)$/')));
$plugin = sanitize_search_string(get_request_var('plugin'));
$safe_actions = array(
'changelog',
'readme',
'load',
'install',
'confirm',
'delete',
'ajax_dnd',
'remove_data'
);
$display_action = ucwords(str_replace('_', ' ', $action));
if (!in_array($plugin, $pluginslist, true) && !in_array($action, $safe_actions, true)) {
raise_message('invalid_plugin', __('The action \'%s\' on Plugin \'%s\' can not be performed due to the Plugin in it\'s current state.', $display_action, $plugin), MESSAGE_LEVEL_ERROR);
header('Location: plugins.php');
exit;
} elseif (in_array($plugin, $plugins_integrated, true)) {
raise_message('invalid_plugin_action', __('The action \'%s\' \'%s\' on Plugin \'%s\' can not be taken as the Plugin is integrated.', $display_action, $plugin), MESSAGE_LEVEL_ERROR);
header('Location: plugins.php');
exit;
}
} else {
$plugin = '';
}
switch($action) {
case 'list':
case 'avail':
top_header();
update_show_current();
bottom_footer();
break;
case 'load':
$tag = get_nfilter_request_var('tag');
api_plugin_archive_restore($plugin, $tag, 'available');
header('Location: plugins.php?state=-99');
exit;
break;
case 'readme':
$tag = get_nfilter_request_var('tag');
api_plugin_get_available_file_contents($plugin, $tag, 'readme');
break;
case 'changelog':
$tag = get_nfilter_request_var('tag');
api_plugin_get_available_file_contents($plugin, $tag, 'changelog');
break;
case 'latest':
$running = is_process_running('pfetch', 'master', 0);
if ($running === false) {
$php_binary = read_config_option('path_php_binary');
exec_background($php_binary, CACTI_PATH_CLI . '/fetch_plugins.php');
usleep(300000);
raise_message('fetch_background', __('The fetch latest plugins process has been launched into background.'), MESSAGE_LEVEL_INFO);
} elseif ($running === true) {
raise_message('fetch_background', __('The fetch latest plugins process has already been started.'), MESSAGE_LEVEL_WARN);
}
header('Location: plugins.php');
exit;
break;
case 'install':
api_plugin_install($plugin);
define('IN_PLUGIN_INSTALL', 1);
if ($_SESSION['sess_plugins_state'] >= 0) {
header('Location: plugins.php?state=5');
} else {
header('Location: plugins.php');
}
break;
case 'uninstall':
define('IN_PLUGIN_INSTALL', 1);
api_plugin_uninstall($plugin);
header('Location: plugins.php');
break;
case 'remove_data':
api_plugin_remove_data($plugin);
header('Location: plugins.php');
break;
case 'disable':
api_plugin_disable($plugin);
header('Location: plugins.php');
break;
case 'enable':
api_plugin_enable($plugin);
header('Location: plugins.php');
break;
case 'check':
$response = api_plugin_check_config($plugin);
if ($response === true) {
/* set the status as installable again if check passes */
db_execute_prepared('UPDATE plugin_config
SET status = 0
WHERE directory = ?',
array($plugin));
raise_message('plugin_good', __('Plugin \'%s\' has passed it\'s Configuration Check test and can not be Installed', $plugin), MESSAGE_LEVEL_INFO);
} elseif ($response === null) {
raise_message('plugin_good', __('Plugin \'%s\' Check Configuration function returned a null response which is invalid. Please check with Plugin Developer for an update.', $plugin), MESSAGE_LEVEL_WARN);
}
header('Location: plugins.php');
break;
case 'moveup':
api_plugin_moveup($plugin);
header('Location: plugins.php');
break;
case 'movedown':
api_plugin_movedown($plugin);
header('Location: plugins.php');
break;
case 'remote_enable':
if ($config['poller_id'] > 1) {
db_execute_prepared('UPDATE plugin_config
SET status = 1
WHERE directory = ?',
array($plugin), false, $local_db_cnn_id);
}
header('Location: plugins.php' . ($option != '' ? '&' . $option:''));
break;
case 'remote_disable':
if ($config['poller_id'] > 1) {
db_execute_prepared('UPDATE plugin_config
SET status = 4
WHERE directory = ?',
array($plugin), false, $local_db_cnn_id);
}
header('Location: plugins.php' . ($option != '' ? '&' . $option:''));
break;
case 'restore':
$id = get_filter_request_var('id');
api_plugin_archive_restore($plugin, $id, 'archive');
header('Location: plugins.php');
break;
case 'delete':
$id = get_filter_request_var('id');
api_plugin_archive_remove($plugin, $id);
header('Location: plugins.php');
break;
case 'archive':
$archive_note = get_nfilter_request_var('archive_note');
api_plugin_archive($plugin, $archive_note);
header('Location: plugins.php');
break;
case 'ajax_dnd':
$new_order = get_nfilter_request_var('dnd');
api_plugin_reorder($new_order);
header('Location: plugins.php');
break;
}
exit;
function plugins_retrieve_plugin_list() {
$pluginslist = array();
$temp = db_fetch_assoc('SELECT directory AS plugin FROM plugin_config ORDER BY name');
foreach ($temp as $t) {
$pluginslist[] = $t['plugin'];
}
return $pluginslist;
}
function plugins_temp_table_exists($table) {
return cacti_sizeof(db_fetch_row("SHOW TABLES LIKE '$table'"));
}
function plugins_load_temp_table() {
global $config, $plugins, $plugins_integrated, $local_db_cnn_id;
$table = 'plugin_temp_table_' . rand();
$x = 0;
while ($x < 30) {
if (!plugins_temp_table_exists($table)) {
$_SESSION['plugin_temp_table'] = $table;
db_execute("CREATE TEMPORARY TABLE IF NOT EXISTS $table LIKE plugin_config");
db_execute("TRUNCATE $table");
db_execute("INSERT INTO $table SELECT * FROM plugin_config");
break;
} else {
$table = 'plugin_temp_table_' . rand();
}
$x++;
}
if (!db_column_exists($table, 'requires')) {
db_execute("ALTER TABLE $table
CHANGE COLUMN directory plugin varchar(32) NOT NULL default '',
CHANGE COLUMN name description varchar(64) NOT NULL default '',
ADD COLUMN compat varchar(64) NOT NULL default '',
ADD COLUMN remote_status tinyint(2) DEFAULT '0' AFTER status,
ADD COLUMN capabilities varchar(128) DEFAULT NULL,
ADD COLUMN requires varchar(80) DEFAULT NULL,
ADD COLUMN dir_md5sum varchar(32) DEFAULT NULL");
}
if ($config['poller_id'] > 1) {
$status = db_fetch_assoc('SELECT directory AS plugin, status
FROM plugin_config', false, $local_db_cnn_id);
if (cacti_sizeof($status)) {
foreach ($status as $r) {
$exists = db_fetch_cell_prepared("SELECT id
FROM $table
WHERE plugin = ?",
array($r['plugin']));
if ($exists) {
$capabilities = api_plugin_remote_capabilities($r['plugin']);
db_execute_prepared("UPDATE $table
SET capabilities = ?
WHERE plugin = ?",
array($capabilities, $r['plugin']));
db_execute_prepared("UPDATE $table
SET remote_status = ?
WHERE plugin = ?",
array($r['status'], $r['plugin']));
} else {
db_execute_prepared("UPDATE $table
SET status = -2, remote_status = ?
WHERE plugin = ?",
array($r['status'], $r['plugin']));
}
}
}
}
$path = CACTI_PATH_PLUGINS . '/';
$dh = opendir($path);
$cinfo = array();
if ($dh !== false) {
while (($file = readdir($dh)) !== false) {
if (is_dir("$path$file") && file_exists("$path$file/setup.php") && !in_array($file, $plugins_integrated, true)) {
$info_file = "$path$file/INFO";
$md5sum = md5sum_path("$path$file");
if (file_exists($info_file)) {
$cinfo[$file] = plugin_load_info_file($info_file);
$pluginslist[] = $file;
} else {
$cinfo[$file] = plugin_load_info_defaults($info_file, false);
}
$exists = db_fetch_cell_prepared("SELECT COUNT(*)
FROM $table
WHERE plugin = ?",
array($file));
$plugin_name = $cinfo[$file]['name'];
if (!$exists) {
db_execute_prepared("INSERT INTO $table
(plugin, description, status, author, webpage, version, requires, compat, dir_md5sum)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
array(
$plugin_name,
$cinfo[$file]['longname'],
$cinfo[$file]['status'],
$cinfo[$file]['author'],
$cinfo[$file]['homepage'],
$cinfo[$file]['version'],
$cinfo[$file]['requires'],
$cinfo[$file]['compat'],
$md5sum
)
);
} else {
db_execute_prepared("UPDATE $table
SET requires = ?, dir_md5sum = ?, compat = ?
WHERE plugin = ?",
array($cinfo[$file]['requires'], $md5sum, $cinfo[$file]['compat'], $plugin_name));
}
}
}
closedir($dh);
}
$found_plugins = array_keys($cinfo);
$plugins = db_fetch_assoc('SELECT id, directory AS plugin, status FROM plugin_config');
if (cacti_sizeof($plugins)) {
foreach ($plugins as $plugin) {
if (!in_array($plugin['plugin'], $found_plugins, true)) {
$plugin['status'] = '-5';
$exists = db_fetch_cell_prepared("SELECT COUNT(*)
FROM $table
WHERE plugin = ?",
array($plugin['plugin']));
if (!$exists) {
$md5sum = md5sum_path("$path$file");
db_execute_prepared("INSERT INTO $table
(plugin, description, status, author, webpage, version, requires, dir_md5sum)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
array(
$plugin['plugin'],
$plugin['longname'],
$plugin['status'],
$plugin['author'],
$plugin['homepage'],
$plugin['version'],
$plugin['requires'],
$md5sum
)
);
} else {
$md5sum = md5sum_path("$path$file");
db_execute_prepared("UPDATE $table
SET status = ?, dir_md5sum = ?
WHERE plugin = ?",
array($plugin['status'], $md5sum, $plugin['plugin']));
}
}
}
}
return $table;
}
function update_show_current() {
global $plugins, $pluginslist, $config, $status_names, $actions, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'type' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'pi.plugin',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'state' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-99'
)
);
validate_store_request_vars($filters, 'sess_plugins');
/* ================= input validation ================= */
$table = plugins_load_temp_table();
$uninstall_msg = __esc('Uninstalling this Plugin and may remove all Plugin Data and Settings. If you really want to Uninstall the Plugin, click \'Uninstall\' below. Otherwise click \'Cancel\'.');
$uninstall_title = __esc('Are you sure you want to Uninstall?');
$rmdata_msg = __esc('Removing Plugin Data and Settings for will remove all Plugin Data and Settings. If you really want to Remove Data and Settings for this Plugin, click \'Remove Data\' below. Otherwise click \'Cancel\'.');
$rmdata_title = __esc('Are you sure you want to Remove all Plugin Data and Settings?');
$resarchive_msg = __esc('Restoring this Plugin Archive will overwrite the current Plugin directory. If you really want to Restore this Plugin Archive, click \'Restore\' below. Otherwise click \'Cancel\'.');
$resarchive_title = __esc('Are you sure you want to Restore this Archive?');
$rmarchive_msg = __esc('Deleting this Plugin Archive is not reversible without a table restore. If you really want to Delete the Plugin Archive, click \'Delete\' below. Otherwise click \'Cancel\'.');
$rmarchive_title = __esc('Are you sure you want to Delete this Archive?');
$archive_msg = __esc('Archiving makes a backup of the plugin that you may restore at a later date. Before archiving, you may enter an archive note that will be stored with the Archive for later reference. If you really want to Archive the Plugin, click \'Delete\' below. Otherwise click \'Cancel\'.');
$archive_form = '<form name="dialogForm" id="dialogForm"><p><b><label for="archive_note">' . __('Archive Note') . '</label></b> <input type="text" size="80" value="" name="archive_note" id="archive_note"></p></form>';
$archive_title = __esc('Are you sure you want to Archive this Plugin?');
html_start_box(__('Plugin Management'), '100%', '', '3', 'center', '');
?>
<tr class='even noprint'>
<td class='noprint'>
<form id='form_plugins' method='get' action='plugins.php'>
<table class='filterTable'>
<tr class='noprint'>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('Status');?>
</td>
<td>
<select id='state' name='state' onChange='applyFilter()' data-defaultLabel='<?php print __('Status');?>'>
<option value='-99'<?php if (get_request_var('state') == '-99') {?> selected<?php }?>><?php print __('Loaded on Disk');?></option>
<option value='0'<?php if (get_request_var('state') == '0') {?> selected<?php }?>><?php print __('Loaded and Not Installed');?></option>
<option value='1'<?php if (get_request_var('state') == '1') {?> selected<?php }?>><?php print __('Installed and Active');?></option>
<option value='4'<?php if (get_request_var('state') == '4') {?> selected<?php }?>><?php print __('Installed and Inactive');?></option>
<option value='5'<?php if (get_request_var('state') == '5') {?> selected<?php }?>><?php print __('Installed or Active');?></option>
<option value='2'<?php if (get_request_var('state') == '2') {?> selected<?php }?>><?php print __('Configuration Issues');?></option>
<option value='7'<?php if (get_request_var('state') == '7') {?> selected<?php }?>><?php print __('Plugin Errors');?></option>
<option value='6'<?php if (get_request_var('state') == '6') {?> selected<?php }?>><?php print __('Available for Install');?></option>
<option value='8'<?php if (get_request_var('state') == '8') {?> selected<?php }?>><?php print __('Archived');?></option>
</select>
</td>
<?php if (get_request_var('state') == 6 && read_config_option('github_allow_unsafe', true) == 'on') { ?>
<td>
<?php print __('Tag Type');?>
</td>
<td>
<select id='type' name='type' onChange='applyFilter()' data-defaultLabel='<?php print __('All');?>'>
<option value='-1'<?php if (get_request_var('type') == '-1') {?> selected<?php }?>><?php print __('All');?></option>
<option value='1'<?php if (get_request_var('type') == '1') {?> selected<?php }?>><?php print __('Non Develop');?></option>
<option value='2'<?php if (get_request_var('type') == '2') {?> selected<?php }?>><?php print __('Develop');?></option>
<option value='3'<?php if (get_request_var('type') == '3') {?> selected<?php }?>><?php print __('Newer Than Installed');?></option>
</select>
</td>
<?php } else { ?>
<td><input type='hidden' id='type' value='-1'></td>
<?php } ?>
<td>
<?php print __('Plugins');?>
</td>
<td>
<select id='rows' name='rows' onChange='applyFilter()' data-defaultLabel='<?php print __('Plugins');?>'>
<option value='-1'<?php print(get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option>
<?php
if (cacti_sizeof($item_rows) > 0) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'" . (get_request_var('rows') == $key ? ' selected':'') . '>' . html_escape($value) . '</option>';
}
}
?>
</select>
</td>
<td>
<span>
<input type='button' class='ui-button ui-corner-all ui-widget' id='refresh' value='<?php print __esc('Go');?>' title='<?php print __esc('Set/Refresh Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __esc('Clear');?>' title='<?php print __esc('Clear Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='latest' value='<?php print __esc('Check Latest');?>' title='<?php print __esc('Fetch the list of the latest Cacti Plugins');?>'>
</span>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var url = '';
function applyFilter() {
if ($('#state').val() == 6) {
strURL = 'plugins.php?action=avail';
} else {
strURL = 'plugins.php?action=list';
}
strURL += '&filter='+$('#filter').val();
strURL += '&type='+$('#type').val();
strURL += '&rows='+$('#rows').val();
strURL += '&state='+$('#state').val();
loadUrl({url:strURL})
}
function clearFilter() {
strURL = 'plugins.php?action=list&clear=1';
loadUrl({url:strURL})
}
function displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, height, width) {
if ($('#pidialog').dialog('instance')) {
$('#pidialog').dialog('close');
}
var btnButtons = {
'Cancel': {
text: buttonCancel,
id: 'btnCancel',
click: function() {
$(this).dialog('close');
}
},
'Continue': {
text: buttonContinue,
id: 'btnContinue',
click: function() {
$(this).dialog('close');
if ($('#dialogForm').length) {
var post = $('#dialogForm').serializeObject();
post['__csrf_magic'] = csrfMagicToken;
postUrl({url: url, noState: true}, post);
} else {
loadUrl({url: url});
}
}
}
};
var message = "<div id='pidialog' style='display:none;'><div><p>"+dialogMessage+"</p></div><div>"+dialogForm+"</div></div>";
if ($('#pidialog').length == 0) {
$('#main').append(message);
} else {
$('#pidialog').remove().append(message);
}
$('#pidialog').dialog({
title: dialogTitle,
minHeight: height,
minWidth: width,
buttons: btnButtons,
open: function() {
$('.ui-dialog-buttonpane > button:last').focus();
$('#pidialog').offset().top;
}
});
}
function displayFileDialog(url, dialogTitle, height, width) {
if ($('#pidialog').dialog('instance')) {
$('#pidialog').dialog('close');
}
$.get(url, function(data) {
if (data != '') {
var message = "<div id='pidialog' style='display:none;'><div>"+DOMPurify.sanitize(data)+'</div></div>';
if ($('#pidialog').length == 0) {
$('#main').append(message);
} else {
$('#pidialog').remove().append(message);
}
$('#pidialog').dialog({
title: dialogTitle,
maxHeight: height,
minWidth: width,
open: function() {
$('.ui-dialog-buttonpane > button:last').focus();
$('#pidialog').offset().top;
}
});
}
});
}
$(function() {
var sortColumn = '<?php print get_request_var('sort_column');?>';
var dndActive = <?php print read_config_option('drag_and_drop') == 'on' ? 'true':'false';?>;
var tableState = <?php print get_request_var('state');?>
$('#refresh').click(function() {
applyFilter();
});
$('#clear').click(function() {
clearFilter();
});
$('#latest').click(function() {
strURL = 'plugins.php?action=latest';
loadUrl({url:strURL});
});
$('#form_plugins').submit(function(event) {
event.preventDefault();
applyFilter();
});
if (sortColumn == 'pi.id' && dndActive && tableState == -99) {
$('#plugins_list2_child').attr('id', 'dnd');
$('#dnd').tableDnD({
onDrag: function(table, row) {
// console.log(table);
// console.log(row);
},
onDrop: function(table, row) {
loadUrl({url:'plugins.php?action=ajax_dnd&'+$.tableDnD.serialize()})
}
});
}
$('.pirestore').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print $resarchive_title;?>';
var dialogMessage = '<?php print $resarchive_msg;?>';
var dialogForm = '';
var buttonContinue = '<?php print __('Restore Archive');?>';
var buttonCancel = '<?php print __('Cancel');?>';
var url = $(this).attr('href');
displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, 80, 400);
});
$('.pirmarchive').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print $rmarchive_title;?>';
var dialogMessage = '<?php print $rmarchive_msg;?>';
var dialogForm = '';
var buttonContinue = '<?php print __('Delete Archive');?>';
var buttonCancel = '<?php print __('Cancel');?>';
var url = $(this).attr('href');
displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, 80, 400);
});
$('.piarchive').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print $archive_title;?>';
var dialogMessage = '<?php print $archive_msg;?>';
var dialogForm = '<?php print $archive_form;?>';
var buttonContinue = '<?php print __('Archive Plugin');?>';
var buttonCancel = '<?php print __('Cancel');?>';
var url = $(this).attr('href');
displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, 120, 600);
});
$('.pirmdata').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print $rmdata_title;?>';
var dialogMessage = '<?php print $rmdata_msg;?>';
var dialogForm = '';
var buttonContinue = '<?php print __('Remove Data');?>';
var buttonCancel = '<?php print __('Cancel');?>';
var url = $(this).attr('href');
displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, 80, 400);
});
$('.piuninstall').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print $uninstall_title;?>';
var dialogMessage = '<?php print $uninstall_msg;?>';
var dialogForm = '';
var buttonContinue = '<?php print __('Uninstall');?>';
var buttonCancel = '<?php print __('Cancel');?>';
var url = $(this).attr('href');
displayDialog(url, dialogTitle, dialogMessage, dialogForm, buttonContinue, buttonCancel, 80, 400);
});
$('.pireadme').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print __esc('Plugin Reame File');?>';
var url = $(this).attr('href');
displayFileDialog(url, dialogTitle, 400, 700);
});
$('.pichangelog').off('click').on('click', function(event) {
event.preventDefault();
var dialogTitle = '<?php print __esc('Plugin ChangeLog File');?>';
var url = $(this).attr('href');
displayFileDialog(url, dialogTitle, 400, 700);
});
});
</script>
</td>
</tr>
<?php
html_end_box();
$sql_where = '';
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
switch(get_request_var('state')) {
case 8:
$sql_where = 'WHERE (
pi.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.author LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.plugin LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.webpage LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.author LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.plugin LIKE ' . db_qstr('%' . get_request_var('filter') . '%') .
')';
break;
case 6:
$sql_where = 'WHERE (
pi.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.author LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.plugin LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.webpage LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pa.author LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.plugin LIKE ' . db_qstr('%' . get_request_var('filter') . '%') .
')';
break;
default:
$sql_where = 'WHERE (
pi.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.author LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.webpage LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR
pi.plugin LIKE ' . db_qstr('%' . get_request_var('filter') . '%') .
')';
}
}
if (!isset_request_var('state')) {
set_request_var('status', -99);
}
switch (get_request_var('state')) {
case 6:
/* show all matching plugins */
if (read_config_option('github_allow_unsafe') == '') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pa.tag_name != "develop"';
} else {
if (get_request_var('type') == '1') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pa.tag_name != "develop"';
} elseif (get_request_var('type') == '2') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pa.tag_name = "develop"';
} elseif (get_request_var('type') == '3') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . '(pi.last_updated != "0000-00-00" AND pi.last_updated < pa.published_at)';
}
}
break;
case 8:
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pi.status IN(0,1,2,4,7) OR pi.status IS NULL';
break;
case 5:
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pi.status IN(1,4)';
break;
case 0:
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pi.status NOT IN(1,4) OR pi.status IS NULL';
break;
case 7:
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pi.status = 7';
break;
case -99:
break;
default:
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' pi.status = ' . get_request_var('state');
break;
}
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
switch(get_request_var('state')) {
case 8:
$total_rows = db_fetch_cell("SELECT COUNT(*)
FROM plugin_archive AS pa
LEFT JOIN $table AS pi
ON pa.plugin = pi.plugin
$sql_where");
break;
case 6:
$total_rows = db_fetch_cell("SELECT COUNT(*)
FROM plugin_available AS pa
LEFT JOIN $table AS pi
ON pa.plugin = pi.plugin