This repository was archived by the owner on Jun 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwpvulnerability-adminms.php
More file actions
3899 lines (3606 loc) · 153 KB
/
Copy pathwpvulnerability-adminms.php
File metadata and controls
3899 lines (3606 loc) · 153 KB
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
/**
* Process functions
*
* @package WPVulnerability
*
* @since 2.0.0
*/
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
/**
* Load the settings to be available always.
*
* @since 2.0.0
*
* @return array|false An array containing the WPVulnerability settings if they exist, or false if they don't.
*/
$wpvulnerability_settings = get_site_option( 'wpvulnerability-config' );
$wpvulnerability_analyze = get_site_option( 'wpvulnerability-analyze' );
/**
* Enqueues the WPVulnerability admin CSS file on WPVulnerability admin pages.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_enqueue_scripts() {
// Enqueue the admin stylesheet.
wp_enqueue_style(
'wpvulnerability-admin',
WPVULNERABILITY_PLUGIN_URL . 'assets/admin.css',
array(),
WPVULNERABILITY_PLUGIN_VERSION
);
wp_enqueue_script(
'wpvulnerability-admin-js',
WPVULNERABILITY_PLUGIN_URL . 'assets/admin.js',
array( 'jquery' ),
WPVULNERABILITY_PLUGIN_VERSION,
true
);
// Localize script with AJAX URL for multisite network admin.
wp_localize_script(
'wpvulnerability-admin-js',
'wpvulnerabilityAjax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
}
add_action( 'admin_enqueue_scripts', 'wpvulnerability_admin_enqueue_scripts' );
/**
* Processes the form submission for the WPVulnerability plugin settings in a multisite network admin context.
*
* Checks if the current request is a submission from the WPVulnerability settings page.
* Verifies the security nonce to prevent CSRF attacks. If the verification fails or if the request
* is not from a network admin or the admin dashboard, the function will halt execution and display an error.
* Otherwise, it sanitizes and updates the plugin settings, reschedules any relevant wp-cron events,
* and registers a settings error to notify the user that the information has been updated.
*
* @since 3.0.0
* @return void
*/
function wpvulnerability_process_network_config_forms() {
// Only process config forms that have the wpvulnerability_submit button.
// Other action forms (delete logs, reset, etc.) have their own handlers.
if ( ! isset( $_POST['wpvulnerability_submit'] ) ) {
return;
}
if ( isset( $_GET['page'] ) && 'wpvulnerability-options' === $_GET['page'] && ! empty( $_POST ) ) {
if ( check_admin_referer( 'wpvulnerability_nonce', 'wpauto_nonce' ) ) {
if ( isset( $_POST['wpvulnerability-config'] ) ) {
$post_config = filter_input( INPUT_POST, 'wpvulnerability-config', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
if ( ! is_array( $post_config ) ) {
$post_config = array();
}
$wpvulnerability_sanitized_values = wpvulnerability_sanitize_config( $post_config );
update_site_option( 'wpvulnerability-config', $wpvulnerability_sanitized_values );
unset( $wpvulnerability_sanitized_values );
add_settings_error(
'wpvulnerability-messages',
'wpvulnerability-updated',
__( 'Settings saved.', 'wpvulnerability' ),
'success'
);
}
if ( isset( $_POST['wpvulnerability_submit'] ) && isset( $_POST['wpvulnerability-analyze'] ) ) {
$wpvulnerability_sanitized_values = array(
'core' => 0,
'plugins' => 0,
'themes' => 0,
'php' => 0,
'apache' => 0,
'nginx' => 0,
'mariadb' => 0,
'mysql' => 0,
'imagemagick' => 0,
'curl' => 0,
'memcached' => 0,
'redis' => 0,
'sqlite' => 0,
);
$wpvulnerability_values = array_map( 'sanitize_text_field', wp_unslash( $_POST['wpvulnerability-analyze'] ) );
foreach ( $wpvulnerability_values as $data ) {
switch ( $data ) {
case 'core':
$wpvulnerability_sanitized_values['core'] = 1;
break;
case 'plugins':
$wpvulnerability_sanitized_values['plugins'] = 1;
break;
case 'themes':
$wpvulnerability_sanitized_values['themes'] = 1;
break;
case 'php':
$wpvulnerability_sanitized_values['php'] = 1;
break;
case 'apache':
$wpvulnerability_sanitized_values['apache'] = 1;
break;
case 'nginx':
$wpvulnerability_sanitized_values['nginx'] = 1;
break;
case 'mariadb':
$wpvulnerability_sanitized_values['mariadb'] = 1;
break;
case 'mysql':
$wpvulnerability_sanitized_values['mysql'] = 1;
break;
case 'imagemagick':
$wpvulnerability_sanitized_values['imagemagick'] = 1;
break;
case 'curl':
$wpvulnerability_sanitized_values['curl'] = 1;
break;
case 'memcached':
$wpvulnerability_sanitized_values['memcached'] = 1;
break;
case 'redis':
$wpvulnerability_sanitized_values['redis'] = 1;
break;
case 'sqlite':
$wpvulnerability_sanitized_values['sqlite'] = 1;
break;
}
}
update_site_option(
'wpvulnerability-analyze',
array(
'core' => $wpvulnerability_sanitized_values['core'],
'plugins' => $wpvulnerability_sanitized_values['plugins'],
'themes' => $wpvulnerability_sanitized_values['themes'],
'php' => $wpvulnerability_sanitized_values['php'],
'apache' => $wpvulnerability_sanitized_values['apache'],
'nginx' => $wpvulnerability_sanitized_values['nginx'],
'mariadb' => $wpvulnerability_sanitized_values['mariadb'],
'mysql' => $wpvulnerability_sanitized_values['mysql'],
'imagemagick' => $wpvulnerability_sanitized_values['imagemagick'],
'curl' => $wpvulnerability_sanitized_values['curl'],
'memcached' => $wpvulnerability_sanitized_values['memcached'],
'redis' => $wpvulnerability_sanitized_values['redis'],
'sqlite' => $wpvulnerability_sanitized_values['sqlite'],
)
);
unset( $wpvulnerability_sanitized_values );
add_settings_error(
'wpvulnerability-messages',
'wpvulnerability-updated',
__( 'Settings saved.', 'wpvulnerability' ),
'success'
);
}
}
}
}
add_action( 'admin_init', 'wpvulnerability_process_network_config_forms' );
/**
* Process action form submissions (delete logs, reset, test email, etc.).
*
* @since 4.3.0
* @return void
*/
function wpvulnerability_process_network_action_forms() {
/**
* Reset the data
*
* @since 3.0.0
*/
if ( isset( $_POST['wpvulnerability_reset'] ) && check_admin_referer( 'wpvulnerability_reset_action', 'wpvulnerability_reset_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
// Calls the reset function.
wpvulnerability_update_database_data();
set_transient( 'wpvulnerability_message_manual_success', __( 'Data from source has been reloaded.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to reload data.', 'wpvulnerability' ), 10 );
}
}
/**
* Send an test email
*
* @since 3.0.0
*/
if ( isset( $_POST['wpvulnerability_email'] ) && check_admin_referer( 'wpvulnerability_email_action', 'wpvulnerability_email_nonce' ) ) {
if ( ! function_exists( 'wpvulnerability_execute_notification' ) ) {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-core.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-plugins.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-themes.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-software.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-process.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-notifications.php';
}
// Calls the notifications function, forced.
if ( current_user_can( 'manage_network_options' ) ) {
$wpmail = wpvulnerability_execute_notification( true );
if ( $wpmail ) {
set_transient( 'wpvulnerability_message_manual_success', __( 'Test email has been sent.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'Test email has failed. Please, check your email settings.', 'wpvulnerability' ), 10 );
}
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to send test emails.', 'wpvulnerability' ), 10 );
}
}
/**
* Repairs scheduled cron events across the network.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_repair_cron'] ) && check_admin_referer( 'wpvulnerability_cron_action', 'wpvulnerability_cron_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
$wpvulnerability_settings = get_site_option( 'wpvulnerability-config', array() );
$cron_config = is_array( $wpvulnerability_settings ) ? $wpvulnerability_settings : array();
wpvulnerability_repair_network_cron_events( $cron_config );
set_transient( 'wpvulnerability_message_manual_success', __( 'WPVulnerability cron events have been repaired across the network.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to repair cron events.', 'wpvulnerability' ), 10 );
}
}
/**
* Delete all stored API logs across the network.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_delete_logs'] ) && check_admin_referer( 'wpvulnerability_delete_logs_action', 'wpvulnerability_delete_logs_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
wpvulnerability_delete_all_logs();
set_transient( 'wpvulnerability_message_manual_success', __( 'All logs have been deleted.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to delete logs.', 'wpvulnerability' ), 10 );
}
}
/**
* Fully resets plugin data, settings, and cached API content across the network.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_full_reset'] ) && check_admin_referer( 'wpvulnerability_full_reset_action', 'wpvulnerability_full_reset_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
wpvulnerability_reset_plugin_data();
set_transient( 'wpvulnerability_message_manual_success', __( 'WPVulnerability has been reset to defaults and reloaded.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to reset WPVulnerability.', 'wpvulnerability' ), 10 );
}
}
/**
* Handles debug action: Clear all caches.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_debug_clear_caches'] ) && check_admin_referer( 'wpvulnerability_debug_action', 'wpvulnerability_debug_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
if ( ! function_exists( 'wpvulnerability_debug_clear_all_caches' ) ) {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-debug.php';
}
wpvulnerability_debug_clear_all_caches();
set_transient( 'wpvulnerability_message_manual_success', __( 'All caches have been cleared.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to clear caches.', 'wpvulnerability' ), 10 );
}
}
/**
* Handles debug action: Reset signatures.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_debug_reset_signatures'] ) && check_admin_referer( 'wpvulnerability_debug_action', 'wpvulnerability_debug_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
if ( ! function_exists( 'wpvulnerability_debug_reset_signatures' ) ) {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-debug.php';
}
wpvulnerability_debug_reset_signatures();
set_transient( 'wpvulnerability_message_manual_success', __( 'Plugin and theme signatures have been reset.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to reset signatures.', 'wpvulnerability' ), 10 );
}
}
/**
* Handles debug action: Export debug info.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_debug_export'] ) && check_admin_referer( 'wpvulnerability_debug_action', 'wpvulnerability_debug_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
if ( ! function_exists( 'wpvulnerability_debug_export_info' ) ) {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-debug.php';
}
$wpvulnerability_debug_info = wpvulnerability_debug_export_info();
$wpvulnerability_filename = 'wpvulnerability-debug-' . gmdate( 'Y-m-d-His' ) . '.json';
header( 'Content-Type: application/json' );
header( 'Content-Disposition: attachment; filename="' . $wpvulnerability_filename . '"' );
header( 'Content-Length: ' . strlen( $wpvulnerability_debug_info ) );
echo $wpvulnerability_debug_info; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit;
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to export debug information.', 'wpvulnerability' ), 10 );
}
}
/**
* Handles debug action: Run update database now.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_run_update'] ) && check_admin_referer( 'wpvulnerability_cron_action', 'wpvulnerability_cron_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
wpvulnerability_update_database_data();
set_transient( 'wpvulnerability_message_manual_success', __( 'Database update has been executed.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to run database updates.', 'wpvulnerability' ), 10 );
}
}
/**
* Handles debug action: Run notification now.
*
* @since 4.3.0
*/
if ( isset( $_POST['wpvulnerability_run_notification'] ) && check_admin_referer( 'wpvulnerability_cron_action', 'wpvulnerability_cron_nonce' ) ) {
if ( current_user_can( 'manage_network_options' ) ) {
if ( ! function_exists( 'wpvulnerability_execute_notification' ) ) {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-core.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-plugins.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-themes.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-software.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-process.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-notifications.php';
}
$wpvulnerability_result = wpvulnerability_execute_notification( true );
if ( $wpvulnerability_result ) {
set_transient( 'wpvulnerability_message_manual_success', __( 'Notification has been sent.', 'wpvulnerability' ), 10 );
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'Notification sending failed.', 'wpvulnerability' ), 10 );
}
} else {
set_transient( 'wpvulnerability_message_manual_error', __( 'You do not have permission to send notifications.', 'wpvulnerability' ), 10 );
}
}
}
add_action( 'admin_init', 'wpvulnerability_process_network_action_forms' );
/**
* Create the WP-Admin options page
* This function generates the HTML output for the WPVulnerability settings page in the WP-Admin.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_create_admin_page() {
?>
<div class="header-wrap">
<div class="wrapper">
<div class="header wpvulnerability-header">
<div class="logo">
<img src="<?php echo esc_url( WPVULNERABILITY_PLUGIN_URL ); ?>assets/icon.svg" style="height: 64px; vertical-align: text-top; width: 64px;" alt="" title="WPVulnerability">
<h2><?php esc_html_e( 'WPVulnerability settings', 'wpvulnerability' ); ?></h2>
</div>
</div>
</div>
</div>
<?php
$wpvulnerability_message_manual_success = get_transient( 'wpvulnerability_message_manual_success' );
if ( $wpvulnerability_message_manual_success ) {
echo '<div class="notice notice-success"><p>' . esc_html( (string) $wpvulnerability_message_manual_success ) . '</p></div>';
delete_transient( 'wpvulnerability_message_manual_success' );
unset( $wpvulnerability_message_manual_success );
}
$wpvulnerability_message_manual_error = get_transient( 'wpvulnerability_message_manual_error' );
if ( $wpvulnerability_message_manual_error ) {
echo '<div class="notice notice-error"><p>' . esc_html( (string) $wpvulnerability_message_manual_error ) . '</p></div>';
delete_transient( 'wpvulnerability_message_manual_error' );
unset( $wpvulnerability_message_manual_error );
}
?>
<?php settings_errors( 'wpvulnerability-messages', true ); ?>
<?php
$tabs = wpvulnerability_get_network_admin_tabs();
if ( empty( $tabs ) ) {
return;
}
$current_tab = wpvulnerability_get_current_network_admin_tab( $tabs );
if ( ! isset( $tabs[ $current_tab ] ) ) {
$tab_keys = array_keys( $tabs );
$current_tab = reset( $tab_keys );
}
?>
<div class="wrap">
<div class="wpvulnerability-settings">
<h2 class="nav-tab-wrapper wpvulnerability-tab-nav" role="tablist">
<?php
foreach ( $tabs as $tab_slug => $tab_data ) {
$tab_label = isset( $tab_data['label'] ) ? $tab_data['label'] : '';
$is_active = ( $tab_slug === $current_tab );
$tab_url = add_query_arg(
array(
'page' => 'wpvulnerability-options',
'tab' => $tab_slug,
),
network_admin_url( 'settings.php' )
);
$tab_class = 'nav-tab wpvulnerability-tab-link';
if ( $is_active ) {
$tab_class .= ' nav-tab-active';
}
?>
<a
href="<?php echo esc_url( $tab_url ); ?>"
class="<?php echo esc_attr( $tab_class ); ?>"
id="<?php echo esc_attr( 'wpvulnerability-network-tab-link-' . $tab_slug ); ?>"
role="tab"
aria-controls="<?php echo esc_attr( 'wpvulnerability-network-tab-panel-' . $tab_slug ); ?>"
aria-selected="<?php echo $is_active ? 'true' : 'false'; ?>"
<?php
if ( ! $is_active ) :
?>
tabindex="-1"<?php endif; ?>
>
<?php echo esc_html( $tab_label ); ?>
</a>
<?php
}
?>
</h2>
<div
id="<?php echo esc_attr( 'wpvulnerability-network-tab-panel-' . $current_tab ); ?>"
class="wpvulnerability-tab-panel is-active"
role="tabpanel"
aria-labelledby="<?php echo esc_attr( 'wpvulnerability-network-tab-link-' . $current_tab ); ?>"
tabindex="0"
>
<?php wpvulnerability_render_network_admin_tab( $current_tab ); ?>
</div>
</div>
</div>
<?php
}
/**
* Retrieves the available tabs for the multisite admin settings page.
*
* @since 4.1.2
*
* @return array<string, array<string, string>> An associative array of tab slugs and their labels.
*/
function wpvulnerability_get_network_admin_tabs() {
$tabs = array(
'notifications' => array(
'label' => __( 'Notifications', 'wpvulnerability' ),
),
'analysis' => array(
'label' => __( 'Analysis', 'wpvulnerability' ),
),
'logs' => array(
'label' => __( 'Logs', 'wpvulnerability' ),
),
'security' => array(
'label' => __( 'Security', 'wpvulnerability' ),
),
'tools' => array(
'label' => __( 'Tools', 'wpvulnerability' ),
),
);
// Add Debug tab only if WP_DEBUG is enabled.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$tabs['debug'] = array(
'label' => __( 'Debug', 'wpvulnerability' ),
);
}
$tabs['about'] = array(
'label' => __( 'About', 'wpvulnerability' ),
);
return $tabs;
}
/**
* Determines the active multisite admin tab.
*
* @since 4.1.2
*
* @param array<string, array<string, string>> $tabs Registered multisite admin tabs.
*
* @return string The active tab slug.
*/
function wpvulnerability_get_current_network_admin_tab( $tabs ) {
$tab_keys = array_keys( $tabs );
$default = reset( $tab_keys );
$tab_filter = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_SPECIAL_CHARS );
if ( $tab_filter ) {
$tab_filter = sanitize_key( $tab_filter );
}
if ( $tab_filter && isset( $tabs[ $tab_filter ] ) ) {
return $tab_filter;
}
return $default ? $default : 'notifications';
}
/**
* Renders the requested multisite admin tab content.
*
* @since 4.1.2
*
* @param string $tab Tab slug to render.
*
* @return void
*/
function wpvulnerability_render_network_admin_tab( $tab ) {
switch ( $tab ) {
case 'analysis':
wpvulnerability_render_network_admin_tab_analysis();
break;
case 'logs':
wpvulnerability_render_network_admin_tab_logs();
break;
case 'security':
wpvulnerability_render_network_admin_tab_security();
break;
case 'tools':
wpvulnerability_render_network_admin_tab_tools();
break;
case 'debug':
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
wpvulnerability_render_network_admin_tab_debug();
}
break;
case 'about':
wpvulnerability_render_network_admin_tab_about();
break;
case 'notifications':
default:
wpvulnerability_render_network_admin_tab_notifications();
break;
}
}
/**
* Outputs the Notifications tab contents for the multisite settings screen.
*
* @since 4.1.2
*
* @return void
*/
function wpvulnerability_render_network_admin_tab_notifications() {
$wpvulnerability_settings = get_site_option( 'wpvulnerability-config', array() );
$defaults = array(
'cache' => 12,
'period' => 'weekly',
'day' => 'monday',
'hour' => 0,
'minute' => 0,
'emails' => '',
'slack_webhook' => '',
'teams_webhook' => '',
'discord_webhook' => '',
'telegram_bot_token' => '',
'telegram_chat_id' => '',
'notify' => array(
'email' => 'y',
'slack' => 'n',
'teams' => 'n',
'discord' => 'n',
'telegram' => 'n',
),
);
$wpvulnerability_settings = wp_parse_args( $wpvulnerability_settings, $defaults );
// Normalize notify settings.
if ( ! is_array( $wpvulnerability_settings['notify'] ) ) {
$wpvulnerability_settings['notify'] = $defaults['notify'];
} else {
$wpvulnerability_settings['notify'] = wp_parse_args( $wpvulnerability_settings['notify'], $defaults['notify'] );
}
$wpvulnerability_settings['notify'] = wpvulnerability_normalize_notify_settings( $wpvulnerability_settings['notify'] );
$email_enabled = wpvulnerability_is_yes( $wpvulnerability_settings['notify']['email'] );
$slack_enabled = wpvulnerability_is_yes( $wpvulnerability_settings['notify']['slack'] );
$teams_enabled = wpvulnerability_is_yes( $wpvulnerability_settings['notify']['teams'] );
$discord_enabled = wpvulnerability_is_yes( $wpvulnerability_settings['notify']['discord'] );
$telegram_enabled = wpvulnerability_is_yes( $wpvulnerability_settings['notify']['telegram'] );
// Check if cache is forced.
$forced_cache = null;
$cache_options = array( 1, 6, 12, 24 );
if ( defined( 'WPVULNERABILITY_CACHE_HOURS' ) ) {
$forced_cache = (int) WPVULNERABILITY_CACHE_HOURS;
if ( ! in_array( $forced_cache, $cache_options, true ) ) {
$cache_options[] = $forced_cache;
sort( $cache_options, SORT_NUMERIC );
}
}
$current_cache = null !== $forced_cache ? $forced_cache : (int) $wpvulnerability_settings['cache'];
$admin_email = get_site_option( 'admin_email' );
?>
<section class="section wpvulnerability-notifications-panel">
<form method="post" action="">
<?php wp_nonce_field( 'wpvulnerability_nonce', 'wpauto_nonce' ); ?>
<div class="wpvulnerability-security-section">
<h3><?php esc_html_e( 'Notification Settings', 'wpvulnerability' ); ?></h3>
<div class="wpvulnerability-intro">
<p><strong><?php esc_html_e( 'Configure how and when you want to receive vulnerability notifications.', 'wpvulnerability' ); ?></strong></p>
<p><?php esc_html_e( 'Stay informed about security vulnerabilities in your WordPress installation, plugins, themes, and server software.', 'wpvulnerability' ); ?></p>
</div>
<!-- Cache Settings -->
<div class="wpvulnerability-setting-group">
<div class="wpvulnerability-setting-label">
<span class="wpvulnerability-setting-icon">⏱️</span>
<?php esc_html_e( 'Cache Expiration Time', 'wpvulnerability' ); ?>
<?php if ( null !== $forced_cache ) : ?>
<span class="wpvulnerability-forced-badge"><?php esc_html_e( 'FORCED', 'wpvulnerability' ); ?></span>
<?php endif; ?>
</div>
<div class="wpvulnerability-setting-description">
<?php esc_html_e( 'How long to cache vulnerability data before refreshing from the API.', 'wpvulnerability' ); ?>
</div>
<select name="wpvulnerability-config[cache]" id="wpvulnerability_cache" <?php disabled( null !== $forced_cache ); ?>>
<?php foreach ( $cache_options as $hours ) : ?>
<option value="<?php echo esc_attr( $hours ); ?>" <?php selected( $current_cache, $hours ); ?>>
<?php
echo esc_html(
sprintf(
/* translators: %d: number of hours */
_n( '%d hour', '%d hours', $hours, 'wpvulnerability' ),
$hours
)
);
?>
</option>
<?php endforeach; ?>
</select>
<?php if ( null !== $forced_cache ) : ?>
<input type="hidden" name="wpvulnerability-config[cache]" value="<?php echo esc_attr( $current_cache ); ?>" />
<?php endif; ?>
<div class="wpvulnerability-info-box">
<p>
<?php
printf(
/* translators: %s: documentation URL */
wp_kses_post( __( 'You can force the cache time via wp-config.php constant. <a href="%s" target="_blank" rel="noopener noreferrer">Learn more →</a>', 'wpvulnerability' ) ),
esc_url( 'https://www.wpvulnerability.com/plugin/#cache-duration' )
);
?>
</p>
</div>
</div>
<!-- Notification Frequency -->
<div class="wpvulnerability-setting-group">
<div class="wpvulnerability-setting-label">
<span class="wpvulnerability-setting-icon">📅</span>
<?php esc_html_e( 'Notification Frequency', 'wpvulnerability' ); ?>
</div>
<div class="wpvulnerability-setting-description">
<?php esc_html_e( 'Choose how often you want to receive vulnerability notifications.', 'wpvulnerability' ); ?>
</div>
<div class="wpvulnerability-radio-group">
<label>
<input type="radio" name="wpvulnerability-config[period]" value="never" <?php checked( $wpvulnerability_settings['period'], 'never' ); ?> onchange="wpvUpdateScheduleVisibility()" />
<?php esc_html_e( 'Never - Disable automatic notifications', 'wpvulnerability' ); ?>
</label>
<label>
<input type="radio" name="wpvulnerability-config[period]" value="daily" <?php checked( $wpvulnerability_settings['period'], 'daily' ); ?> onchange="wpvUpdateScheduleVisibility()" />
<?php esc_html_e( 'Daily - Receive notifications every day', 'wpvulnerability' ); ?>
</label>
<label>
<input type="radio" name="wpvulnerability-config[period]" value="weekly" <?php checked( $wpvulnerability_settings['period'], 'weekly' ); ?> onchange="wpvUpdateScheduleVisibility()" />
<?php esc_html_e( 'Weekly - Receive notifications once a week', 'wpvulnerability' ); ?>
</label>
</div>
<div class="wpvulnerability-schedule-controls" id="wpvulnerability-schedule-controls">
<div class="wpvulnerability-schedule-row" id="wpvulnerability-day-selector">
<label for="wpvulnerability_day"><?php esc_html_e( 'Day:', 'wpvulnerability' ); ?></label>
<select name="wpvulnerability-config[day]" id="wpvulnerability_day">
<option value="monday" <?php selected( $wpvulnerability_settings['day'], 'monday' ); ?>><?php esc_html_e( 'Monday', 'wpvulnerability' ); ?></option>
<option value="tuesday" <?php selected( $wpvulnerability_settings['day'], 'tuesday' ); ?>><?php esc_html_e( 'Tuesday', 'wpvulnerability' ); ?></option>
<option value="wednesday" <?php selected( $wpvulnerability_settings['day'], 'wednesday' ); ?>><?php esc_html_e( 'Wednesday', 'wpvulnerability' ); ?></option>
<option value="thursday" <?php selected( $wpvulnerability_settings['day'], 'thursday' ); ?>><?php esc_html_e( 'Thursday', 'wpvulnerability' ); ?></option>
<option value="friday" <?php selected( $wpvulnerability_settings['day'], 'friday' ); ?>><?php esc_html_e( 'Friday', 'wpvulnerability' ); ?></option>
<option value="saturday" <?php selected( $wpvulnerability_settings['day'], 'saturday' ); ?>><?php esc_html_e( 'Saturday', 'wpvulnerability' ); ?></option>
<option value="sunday" <?php selected( $wpvulnerability_settings['day'], 'sunday' ); ?>><?php esc_html_e( 'Sunday', 'wpvulnerability' ); ?></option>
</select>
</div>
<div class="wpvulnerability-schedule-row">
<label for="wpvulnerability_hour"><?php esc_html_e( 'Time:', 'wpvulnerability' ); ?></label>
<input type="number" min="0" max="23" name="wpvulnerability-config[hour]" id="wpvulnerability_hour" value="<?php echo esc_attr( (string) $wpvulnerability_settings['hour'] ); ?>" />
<span>:</span>
<input type="number" min="0" max="59" name="wpvulnerability-config[minute]" id="wpvulnerability_minute" value="<?php echo esc_attr( (string) $wpvulnerability_settings['minute'] ); ?>" />
<span class="wpvulnerability-input-hint"><?php esc_html_e( '(24-hour format, server timezone)', 'wpvulnerability' ); ?></span>
</div>
</div>
</div>
<!-- Notification Channels -->
<div class="wpvulnerability-setting-group">
<div class="wpvulnerability-setting-label">
<span class="wpvulnerability-setting-icon">📢</span>
<?php esc_html_e( 'Notification Channels', 'wpvulnerability' ); ?>
</div>
<div class="wpvulnerability-setting-description">
<?php esc_html_e( 'Select where you want to receive notifications.', 'wpvulnerability' ); ?>
</div>
<div class="wpvulnerability-checkbox-group">
<label>
<input type="checkbox" name="wpvulnerability-config[notify][email]" value="y" <?php checked( $email_enabled ); ?> onchange="wpvToggleChannelInput('email')" />
<?php esc_html_e( 'Email', 'wpvulnerability' ); ?>
</label>
<div class="wpvulnerability-channel-inputs" id="wpvulnerability-email-inputs">
<label for="wpvulnerability_emails"><?php esc_html_e( 'Email Addresses (separated by commas):', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="text" name="wpvulnerability-config[emails]" id="wpvulnerability_emails" placeholder="<?php echo esc_attr( (string) $admin_email ); ?>" value="<?php echo esc_attr( (string) $wpvulnerability_settings['emails'] ); ?>" />
<span class="wpvulnerability-input-hint"><?php esc_html_e( 'Default:', 'wpvulnerability' ); ?> <?php echo esc_html( (string) $admin_email ); ?></span>
</div>
<label>
<input type="checkbox" name="wpvulnerability-config[notify][slack]" value="y" <?php checked( $slack_enabled ); ?> onchange="wpvToggleChannelInput('slack')" />
<?php esc_html_e( 'Slack', 'wpvulnerability' ); ?>
</label>
<div class="wpvulnerability-channel-inputs" id="wpvulnerability-slack-inputs">
<label for="wpvulnerability_slack_webhook"><?php esc_html_e( 'Slack Webhook URL:', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="url" name="wpvulnerability-config[slack_webhook]" id="wpvulnerability_slack_webhook" placeholder="https://hooks.slack.com/services/..." value="<?php echo esc_attr( (string) $wpvulnerability_settings['slack_webhook'] ); ?>" />
<span class="wpvulnerability-input-hint">
<?php
printf(
/* translators: %s: Slack documentation URL */
wp_kses_post( __( '<a href="%s" target="_blank" rel="noopener noreferrer">Learn how to create a Slack incoming webhook →</a>', 'wpvulnerability' ) ),
esc_url( 'https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/' )
);
?>
</span>
</div>
<label>
<input type="checkbox" name="wpvulnerability-config[notify][teams]" value="y" <?php checked( $teams_enabled ); ?> onchange="wpvToggleChannelInput('teams')" />
<?php esc_html_e( 'Microsoft Teams', 'wpvulnerability' ); ?>
</label>
<div class="wpvulnerability-channel-inputs" id="wpvulnerability-teams-inputs">
<label for="wpvulnerability_teams_webhook"><?php esc_html_e( 'Teams Webhook URL:', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="url" name="wpvulnerability-config[teams_webhook]" id="wpvulnerability_teams_webhook" placeholder="https://outlook.office.com/webhook/..." value="<?php echo esc_attr( (string) $wpvulnerability_settings['teams_webhook'] ); ?>" />
<span class="wpvulnerability-input-hint">
<?php
printf(
/* translators: %s: Microsoft Teams documentation URL */
wp_kses_post( __( '<a href="%s" target="_blank" rel="noopener noreferrer">Learn how to create a Teams incoming webhook →</a>', 'wpvulnerability' ) ),
esc_url( 'https://learn.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook' )
);
?>
</span>
</div>
<label>
<input type="checkbox" name="wpvulnerability-config[notify][discord]" value="y" <?php checked( $discord_enabled ); ?> onchange="wpvToggleChannelInput('discord')" />
<?php esc_html_e( 'Discord', 'wpvulnerability' ); ?>
</label>
<div class="wpvulnerability-channel-inputs" id="wpvulnerability-discord-inputs">
<label for="wpvulnerability_discord_webhook"><?php esc_html_e( 'Discord Webhook URL:', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="url" name="wpvulnerability-config[discord_webhook]" id="wpvulnerability_discord_webhook" placeholder="https://discord.com/api/webhooks/..." value="<?php echo esc_attr( (string) $wpvulnerability_settings['discord_webhook'] ); ?>" />
<span class="wpvulnerability-input-hint">
<?php
printf(
/* translators: %s: Discord documentation URL */
wp_kses_post( __( '<a href="%s" target="_blank" rel="noopener noreferrer">Learn how to create a Discord webhook →</a>', 'wpvulnerability' ) ),
esc_url( 'https://support.discord.com/hc/articles/228383668' )
);
?>
</span>
</div>
<label>
<input type="checkbox" name="wpvulnerability-config[notify][telegram]" value="y" <?php checked( $telegram_enabled ); ?> onchange="wpvToggleChannelInput('telegram')" />
<?php esc_html_e( 'Telegram', 'wpvulnerability' ); ?>
</label>
<div class="wpvulnerability-channel-inputs" id="wpvulnerability-telegram-inputs">
<label for="wpvulnerability_telegram_bot_token"><?php esc_html_e( 'Telegram Bot Token:', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="text" name="wpvulnerability-config[telegram_bot_token]" id="wpvulnerability_telegram_bot_token" placeholder="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" value="<?php echo esc_attr( (string) $wpvulnerability_settings['telegram_bot_token'] ); ?>" />
<span class="wpvulnerability-input-hint"><?php esc_html_e( 'Format: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11', 'wpvulnerability' ); ?></span>
<label for="wpvulnerability_telegram_chat_id" style="margin-top: 12px;"><?php esc_html_e( 'Telegram Chat ID:', 'wpvulnerability' ); ?></label>
<input class="wpvulnerability-input-full" type="text" name="wpvulnerability-config[telegram_chat_id]" id="wpvulnerability_telegram_chat_id" placeholder="-1001234567890" value="<?php echo esc_attr( (string) $wpvulnerability_settings['telegram_chat_id'] ); ?>" />
<span class="wpvulnerability-input-hint">
<?php
printf(
/* translators: %s: Telegram documentation URL */
wp_kses_post( __( '<a href="%s" target="_blank" rel="noopener noreferrer">Learn how to create a Telegram bot and get Chat ID →</a>', 'wpvulnerability' ) ),
esc_url( 'https://core.telegram.org/bots' )
);
?>
</span>
</div>
</div>
</div>
<div class="wpvulnerability-save-section">
<?php submit_button( __( 'Save Notification Settings', 'wpvulnerability' ), 'primary', 'wpvulnerability_submit', false ); ?>
</div>
</div>
</form>
<script>
function wpvUpdateScheduleVisibility() {
var period = document.querySelector('input[name="wpvulnerability-config[period]"]:checked').value;
var scheduleControls = document.getElementById('wpvulnerability-schedule-controls');
var daySelector = document.getElementById('wpvulnerability-day-selector');
if (period === 'never') {
scheduleControls.classList.add('wpvulnerability-hidden');
} else {
scheduleControls.classList.remove('wpvulnerability-hidden');
if (period === 'weekly') {
daySelector.style.display = 'block';
} else {
daySelector.style.display = 'none';
}
}
}
function wpvToggleChannelInput(channel) {
var checkbox = document.querySelector('input[name="wpvulnerability-config[notify][' + channel + ']"]');
var inputs = document.getElementById('wpvulnerability-' + channel + '-inputs');
if (checkbox.checked) {
inputs.classList.remove('wpvulnerability-hidden');
} else {
inputs.classList.add('wpvulnerability-hidden');
}
}
// Initialize visibility on page load.
document.addEventListener('DOMContentLoaded', function() {
wpvUpdateScheduleVisibility();
wpvToggleChannelInput('email');
wpvToggleChannelInput('slack');
wpvToggleChannelInput('teams');
wpvToggleChannelInput('discord');
wpvToggleChannelInput('telegram');
});
</script>
</section>
<?php
}
/**
* Outputs the Analysis tab contents for the multisite settings screen.
*
* @since 4.1.2
*
* @return void
*/
function wpvulnerability_render_network_admin_tab_analysis() {
$wpvulnerability_analyze = get_site_option( 'wpvulnerability-analyze', array() );
$components = array( 'core', 'plugins', 'themes', 'php', 'apache', 'nginx', 'mariadb', 'mysql', 'imagemagick', 'curl', 'memcached', 'redis', 'sqlite' );
$forced = array();
foreach ( $components as $component ) {
if ( ! isset( $wpvulnerability_analyze[ $component ] ) ) {
$wpvulnerability_analyze[ $component ] = 0;
}
$constant = 'WPVULNERABILITY_HIDE_' . strtoupper( (string) $component );
$forced[ $component ] = defined( $constant ) && constant( $constant );
if ( $forced[ $component ] ) {
$wpvulnerability_analyze[ $component ] = 1;
}
}
// Component configuration with labels and icons.
$component_config = array(
'wordpress' => array(
'label' => __( 'WordPress Components', 'wpvulnerability' ),
'items' => array(
'core' => array(
'label' => __( 'WordPress Core', 'wpvulnerability' ),
'icon' => '🌐',
),
'plugins' => array(
'label' => __( 'Plugins', 'wpvulnerability' ),
'icon' => '🧩',
),
'themes' => array(
'label' => __( 'Themes', 'wpvulnerability' ),
'icon' => '🎨',
),
),
),
'software' => array(
'label' => __( 'Software & Languages', 'wpvulnerability' ),
'items' => array(
'php' => array(
'label' => __( 'PHP', 'wpvulnerability' ),
'icon' => '🐘',
),
),
),
'webservers' => array(
'label' => __( 'Web Servers', 'wpvulnerability' ),
'items' => array(
'apache' => array(
'label' => __( 'Apache HTTPD', 'wpvulnerability' ),
'icon' => '🪶',
),
'nginx' => array(
'label' => __( 'nginx', 'wpvulnerability' ),
'icon' => '🟩',
),
),
),
'databases' => array(
'label' => __( 'Databases', 'wpvulnerability' ),
'items' => array(
'mariadb' => array(
'label' => __( 'MariaDB', 'wpvulnerability' ),
'icon' => '🐬',
),
'mysql' => array(
'label' => __( 'MySQL', 'wpvulnerability' ),
'icon' => '🐬',
),
'sqlite' => array(
'label' => __( 'SQLite', 'wpvulnerability' ),
'icon' => '💾',
),
),
),
'tools' => array(
'label' => __( 'Additional Tools', 'wpvulnerability' ),
'items' => array(