-
Notifications
You must be signed in to change notification settings - Fork 6
/
wpvulnerability-admin.php
1240 lines (1154 loc) · 50.6 KB
/
wpvulnerability-admin.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
/**
* Process functions
*
* @package WPVulnerability
*
* @version 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_option( 'wpvulnerability-config' );
$wpvulnerability_analyze = get_option( 'wpvulnerability-analyze' );
/**
* Enqueues the WPVulnerability admin CSS file on WPVulnerability admin pages.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_enqueue_scripts() {
wp_enqueue_style(
'wpvulnerability-admin',
WPVULNERABILITY_PLUGIN_URL . 'assets/admin.css',
array(),
WPVULNERABILITY_PLUGIN_VERSION
);
}
add_action( 'admin_enqueue_scripts', 'wpvulnerability_admin_enqueue_scripts' );
/**
* Reset the data.
*
* This function checks for a reset request and, if valid, calls the function to update the database data.
*
* @since 3.0.0
*
* @return void
*/
if ( isset( $_POST['wpvulnerability_reset'] ) && check_admin_referer( 'wpvulnerability_reset_action', 'wpvulnerability_reset_nonce' ) ) {
// Calls the reset function.
wpvulnerability_update_database_data();
// Set a transient message for success.
set_transient( 'wpvulnerability_message_manual_success', __( 'Data from source has been reloaded.', 'wpvulnerability' ), 10 );
}
/**
* Send a test email.
*
* This code checks for a request to send a test email and executes the notification function.
*
* @since 3.0.0
*
* @return void
*/
if ( isset( $_POST['wpvulnerability_email'] ) && check_admin_referer( 'wpvulnerability_email_action', 'wpvulnerability_email_nonce' ) ) {
// Include necessary files if the notification function is not already defined.
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.
$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 );
}
}
/**
* 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() {
$wpvulnerability_settings = get_option( 'wpvulnerability-config' );
?>
<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/logo64.png" 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(); ?>
<div class="wrap">
<div class="wpvulnerability-container">
<div class="wpvulnerability-column">
<section class="section">
<form method="post" action="options.php">
<?php
settings_fields( 'admin_wpvulnerability_settings' );
do_settings_sections( 'wpvulnerability-config' );
submit_button();
?>
</form>
</section>
<section class="section">
<form method="post" action="options.php">
<?php
settings_fields( 'admin_wpvulnerability_analyze' );
do_settings_sections( 'wpvulnerability-analyze' );
submit_button();
?>
</form>
</section>
<section class="section">
<header class="section-header">
<h2><?php esc_html_e( 'Reload the data from source', 'wpvulnerability' ); ?></h2>
</header>
<div class="section-content">
<p><?php esc_html_e( 'Reload all Core, Plugins, Themes and other components information directly from the API to have updated data.', 'wpvulnerability' ); ?></p>
<form method="post" action="options-general.php?page=wpvulnerability-options">
<?php wp_nonce_field( 'wpvulnerability_reset_action', 'wpvulnerability_reset_nonce' ); ?>
<input type="submit" name="wpvulnerability_reset" value="<?php esc_attr_e( 'Reload Data', 'wpvulnerability' ); ?>" class="button button-secondary">
</form>
</div>
</section>
<section class="section">
<header class="section-header">
<h2><?php esc_html_e( 'Email test', 'wpvulnerability' ); ?></h2>
</header>
<div class="section-content">
<?php
$from_email = null;
if ( defined( 'WPVULNERABILITY_MAIL' ) ) {
$from_email = sanitize_email( trim( WPVULNERABILITY_MAIL ) );
if ( is_email( $from_email ) ) {
?>
<p><?php esc_html_e( 'The mail will be sent from (set on WPVULNERABILITY_MAIL): ', 'wpvulnerability' ); ?> <code><?php echo esc_html( $from_email ); ?></code></p>
<?php
}
}
if ( ! $from_email ) {
$from_email = get_bloginfo( 'admin_email' );
?>
<p><?php esc_html_e( 'The mail will be sent from: ', 'wpvulnerability' ); ?> <code><?php echo esc_html( $from_email ); ?></code></p>
<?php
}
?>
<p><?php esc_html_e( 'Send an email with the vulnerabilities (or empty).', 'wpvulnerability' ); ?></p>
<form method="post" action="options-general.php?page=wpvulnerability-options">
<?php wp_nonce_field( 'wpvulnerability_email_action', 'wpvulnerability_email_nonce' ); ?>
<input type="submit" name="wpvulnerability_email" value="<?php esc_attr_e( 'Send email', 'wpvulnerability' ); ?>" class="button button-secondary">
</form>
</div>
</section>
</div>
<div class="wpvulnerability-column">
<?php
$wpvulnerability_statistics = json_decode( get_option( 'wpvulnerability-statistics' ), true );
?>
<section class="section">
<header class="section-header">
<h2><?php esc_html_e( 'WPVulnerability Statistics', 'wpvulnerability' ); ?></h2>
</header>
<div class="section-content">
<div class="wpvulnerability-container">
<div class="wpvulnerability-column">
<dl>
<dt><?php esc_html_e( 'Plugins', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['plugins'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['plugins']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['plugins']['vulnerabilities'] ) ) )
);
printf(
// translators: number of plugins.
esc_html( _n( ' (%s plugin)', ' (%s plugins)', absint( $wpvulnerability_statistics['plugins']['products'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['plugins']['products'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'Themes', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['themes'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['themes']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['themes']['vulnerabilities'] ) ) )
);
printf(
// translators: number of themes.
esc_html( _n( ' (%s theme)', ' (%s themes)', absint( $wpvulnerability_statistics['themes']['products'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['themes']['products'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'PHP', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['php'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['php']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['php']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'Apache HTTPD', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['apache'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['apache']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['apache']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'nginx', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['nginx'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['nginx']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['nginx']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'MariaDB', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['mariadb'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['mariadb']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['mariadb']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
</dl>
</div>
<div class="wpvulnerability-column">
<dl>
<dt><?php esc_html_e( 'MySQL', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['mysql'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['mysql']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['mysql']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'ImageMagick', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['imagemagick'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['imagemagick']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['imagemagick']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'curl', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['curl'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['curl']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['curl']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'memcached', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['memcached'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['memcached']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['memcached']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'Redis', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['redis'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['redis']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['redis']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
<dt><?php esc_html_e( 'SQLite', 'wpvulnerability' ); ?></dt>
<?php
if ( isset( $wpvulnerability_statistics['sqlite'] ) ) {
?>
<dd>
<?php
printf(
// translators: number of vulnerabilities.
esc_html( _n( '%s vulnerability', '%s vulnerabilities', absint( $wpvulnerability_statistics['sqlite']['vulnerabilities'] ), 'wpvulnerability' ) ),
esc_html( number_format_i18n( absint( $wpvulnerability_statistics['sqlite']['vulnerabilities'] ) ) )
);
?>
</dd>
<?php
} else {
?>
<dd><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></dd>
<?php
}
?>
</dl>
</div>
</div>
<?php
if ( isset( $wpvulnerability_statistics['updated'] ) ) {
if ( version_compare( $GLOBALS['wp_version'], '5.0', '>=' ) ) {
switch_to_locale( determine_locale() );
} elseif ( version_compare( $GLOBALS['wp_version'], '4.7', '>=' ) ) {
switch_to_locale( get_locale() );
}
$formatted_datetime = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $wpvulnerability_statistics['updated']['unixepoch'] );
?>
<p><small>
<?php
// translators: date of last update.
printf( esc_html__( 'Updated: %s', 'wpvulnerability' ), esc_html( $formatted_datetime ) );
?>
</small></p>
<?php
if ( version_compare( $GLOBALS['wp_version'], '4.7', '>=' ) ) {
restore_previous_locale();
}
}
?>
</div>
</section>
<section class="section">
<header class="section-header">
<h2><?php esc_html_e( 'Behind the Project', 'wpvulnerability' ); ?></h2>
</header>
<div class="section-content">
<div class="wpvulnerability-container">
<div class="wpvulnerability-column">
<h3><?php esc_html_e( 'Sponsors', 'wpvulnerability' ); ?></h3>
<?php
if ( isset( $wpvulnerability_statistics['sponsors'] ) ) {
foreach ( $wpvulnerability_statistics['sponsors'] as $sponsor ) {
?>
<p><img src="<?php echo esc_url( $sponsor['image'] ); ?>" width="32" height="32" style="vertical-align: middle; margin-right: 8px;"> <a href="<?php echo esc_url( $sponsor['url'] ); ?>" target="_blank" rel="noreferrer noopener"><?php echo esc_html( $sponsor['name'] ); ?></a></p>
<?php
}
} else {
?>
<p><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></p>
<?php
}
?>
</div>
<div class="wpvulnerability-column">
<h3><?php esc_html_e( 'Contributors', 'wpvulnerability' ); ?></h3>
<?php
if ( isset( $wpvulnerability_statistics['contributors'] ) ) {
foreach ( $wpvulnerability_statistics['contributors'] as $contributor ) {
?>
<p><img src="<?php echo esc_url( $contributor['image'] ); ?>" width="32" height="32" style="vertical-align: middle; margin-right: 8px;"> <a href="<?php echo esc_url( $contributor['url'] ); ?>" target="_blank" rel="noreferrer noopener"><?php echo esc_html( $contributor['name'] ); ?></a></p>
<?php
}
} else {
?>
<p><?php esc_html_e( 'Data not available.', 'wpvulnerability' ); ?></p>
<?php
}
?>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<?php
}
/**
* Adds a WP-Admin menu option for the WPVulnerability plugin.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_menu() {
// Adds a submenu page under the Settings menu.
add_submenu_page(
'options-general.php',
__( 'WPVulnerability', 'wpvulnerability' ),
__( 'WPVulnerability', 'wpvulnerability' ),
'manage_options',
'wpvulnerability-options',
'wpvulnerability_create_admin_page'
);
}
add_action( 'admin_menu', 'wpvulnerability_admin_menu' );
/**
* Print the settings header information for the notifications section.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_section_notifications() {
// Output the header information for the notifications section.
esc_html_e( 'Configure and save these settings to receive email notifications.', 'wpvulnerability' );
}
/**
* Print the settings header information for the analyze section.
*
* @since 3.3.0
*
* @return void
*/
function wpvulnerability_admin_section_analyze() {
// Output the header information for the analyze section.
esc_html_e( 'Configure and save these settings to hide vulnerabilities.', 'wpvulnerability' );
}
/**
* Callback function to display the email input field in the admin settings page.
* This function retrieves the current WPVulnerability plugin settings and displays the email input field
* for users to enter their email addresses. If no email is saved in the settings, the admin email is displayed.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_emails_callback() {
// Retrieve the WPVulnerability plugin settings.
$wpvulnerability_settings = get_option( 'wpvulnerability-config' );
// Set a default value for the email input field if no email is saved in the settings.
if ( ! isset( $wpvulnerability_settings['emails'] ) ) {
$wpvulnerability_settings['emails'] = '';
}
// Output the email input field.
$admin_email = get_bloginfo( 'admin_email' );
// Output the email input field. Use the network admin email as a placeholder in a multisite environment.
?>
<input class="regular-text" 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'] ); ?>">
<br><small><?php esc_html_e( 'Default administrator email', 'wpvulnerability' ); ?>: <?php echo esc_attr( (string) $admin_email ); ?></small>
<?php
unset( $admin_email );
}
/**
* Print when to send the vulnerability scan emails.
*
* @since 2.0.0
*
* @return void
*/
function wpvulnerability_admin_period_callback() {
// Get the saved plugin settings.
$wpvulnerability_settings = get_option( 'wpvulnerability-config', array() );
// Set the default period to 'weekly' if not set or empty.
if ( ! isset( $wpvulnerability_settings['period'] ) || empty( $wpvulnerability_settings['period'] ) ) {
$wpvulnerability_settings['period'] = 'weekly';
}
// Output the period select box.
?>
<div id="wpvulnerability_period">
<label>
<input type="radio" name="wpvulnerability-config[period]" value="daily" <?php checked( $wpvulnerability_settings['period'], 'daily' ); ?> />
<?php esc_html_e( 'Daily', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="radio" name="wpvulnerability-config[period]" value="weekly" <?php checked( $wpvulnerability_settings['period'], 'weekly' ); ?> />
<?php esc_html_e( 'Weekly', 'wpvulnerability' ); ?>
</label>
</div>
<?php
}
/**
* Displays the WPVulnerability plugin analysis settings in the admin panel.
*
* This function retrieves the current WPVulnerability analysis settings and
* ensures all necessary options are set. It then outputs a multiple-select
* field allowing the user to select which components (core, plugins, themes,
* php, apache, nginx) to analyze.
*
* @since 3.3.0
*
* @return void
*/
function wpvulnerability_admin_analyze_callback() {
// Retrieve the WPVulnerability plugin settings.
$wpvulnerability_analyze = get_option( 'wpvulnerability-analyze', array() );
if ( ! isset( $wpvulnerability_analyze['core'] ) ) {
$wpvulnerability_analyze['core'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['plugins'] ) ) {
$wpvulnerability_analyze['plugins'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['themes'] ) ) {
$wpvulnerability_analyze['themes'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['php'] ) ) {
$wpvulnerability_analyze['php'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['apache'] ) ) {
$wpvulnerability_analyze['apache'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['nginx'] ) ) {
$wpvulnerability_analyze['nginx'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['mariadb'] ) ) {
$wpvulnerability_analyze['mariadb'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['mysql'] ) ) {
$wpvulnerability_analyze['mysql'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['imagemagick'] ) ) {
$wpvulnerability_analyze['imagemagick'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['curl'] ) ) {
$wpvulnerability_analyze['curl'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['memcached'] ) ) {
$wpvulnerability_analyze['memcached'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['redis'] ) ) {
$wpvulnerability_analyze['redis'] = 0;
}
if ( ! isset( $wpvulnerability_analyze['sqlite'] ) ) {
$wpvulnerability_analyze['sqlite'] = 0;
}
?>
<div id="wpvulnerability_analyze">
<label>
<input type="checkbox" name="wpvulnerability-analyze[core]" value="core" <?php checked( $wpvulnerability_analyze['core'] ); ?> />
<?php esc_html_e( 'Core', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[plugins]" value="plugins" <?php checked( $wpvulnerability_analyze['plugins'] ); ?> />
<?php esc_html_e( 'Plugins', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[themes]" value="themes" <?php checked( $wpvulnerability_analyze['themes'] ); ?> />
<?php esc_html_e( 'Themes', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[php]" value="php" <?php checked( $wpvulnerability_analyze['php'] ); ?> />
<?php esc_html_e( 'PHP', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[apache]" value="apache" <?php checked( $wpvulnerability_analyze['apache'] ); ?> />
<?php esc_html_e( 'Apache HTTPD', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[nginx]" value="nginx" <?php checked( $wpvulnerability_analyze['nginx'] ); ?> />
<?php esc_html_e( 'nginx', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[mariadb]" value="mariadb" <?php checked( $wpvulnerability_analyze['mariadb'] ); ?> />
<?php esc_html_e( 'MariaDB', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[mysql]" value="mysql" <?php checked( $wpvulnerability_analyze['mysql'] ); ?> />
<?php esc_html_e( 'MySQL', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[imagemagick]" value="imagemagick" <?php checked( $wpvulnerability_analyze['imagemagick'] ); ?> />
<?php esc_html_e( 'ImageMagick', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[curl]" value="curl" <?php checked( $wpvulnerability_analyze['curl'] ); ?> />
<?php esc_html_e( 'curl', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[memcached]" value="memcached" <?php checked( $wpvulnerability_analyze['memcached'] ); ?> />
<?php esc_html_e( 'memcached', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[redis]" value="redis" <?php checked( $wpvulnerability_analyze['redis'] ); ?> />
<?php esc_html_e( 'Redis', 'wpvulnerability' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="wpvulnerability-analyze[sqlite]" value="sqlite" <?php checked( $wpvulnerability_analyze['sqlite'] ); ?> />
<?php esc_html_e( 'SQLite', 'wpvulnerability' ); ?>
</label>
</div>
<?php
}
/**
* Sanitize fields before saving into the database
*
* @since 2.0.0
*
* @param array $input The input fields to sanitize.
*
* @return array The sanitized values.
*/
function wpvulnerability_admin_sanitize( $input ) {
$sanitized_values = array();
$input_emails = array();
if ( isset( $input['emails'] ) ) {
$input_email_text = explode( ',', $input['emails'] );
// Loop through each email address in the input field.
foreach ( $input_email_text as $input_email ) {
// Sanitize each email address.
$input_email = sanitize_email( trim( $input_email ) );
if ( $input_email ) {
$input_emails[] = $input_email;
}
}
}
if ( count( $input_emails ) ) {
$sanitized_values['emails'] = implode( ',', $input_emails );
} else {
$sanitized_values['emails'] = null;
}
if ( isset( $input['period'] ) ) {
// Check the value of the period field and sanitize it.
switch ( $input['period'] ) {
case 'daily':
$sanitized_values['period'] = 'daily';
break;
case 'weekly':
default:
$sanitized_values['period'] = 'weekly';
break;
}
}
// Clear the scheduled hook for the notification event and set it to run at the sanitized interval.
wp_clear_scheduled_hook( 'wpvulnerability_notification' );
wp_schedule_event( time(), $sanitized_values['period'], 'wpvulnerability_notification' );
return $sanitized_values;
}
/**
* Sanitizes the input fields for vulnerability analysis.
*
* This function takes an array of input fields and sanitizes them by setting
* the corresponding values in the output array to 1 if they are present in
* the input. The possible fields are 'core', 'plugins', 'themes', 'php',
* 'apache', and 'nginx'.
*
* @since 3.3.0
*
* @param array $input The input fields to sanitize.
*
* @return array The sanitized values with keys 'core', 'plugins', 'themes', 'php', 'apache', and 'nginx'.
*/
function wpvulnerability_analyze_sanitize( $input ) {
$sanitized_values = array(
'core' => isset( $input['core'] ) ? 1 : 0,
'plugins' => isset( $input['plugins'] ) ? 1 : 0,
'themes' => isset( $input['themes'] ) ? 1 : 0,
'php' => isset( $input['php'] ) ? 1 : 0,
'apache' => isset( $input['apache'] ) ? 1 : 0,
'nginx' => isset( $input['nginx'] ) ? 1 : 0,
'mariadb' => isset( $input['mariadb'] ) ? 1 : 0,
'mysql' => isset( $input['mysql'] ) ? 1 : 0,
'imagemagick' => isset( $input['imagemagick'] ) ? 1 : 0,
'curl' => isset( $input['curl'] ) ? 1 : 0,
'memcached' => isset( $input['memcached'] ) ? 1 : 0,
'redis' => isset( $input['redis'] ) ? 1 : 0,
'sqlite' => isset( $input['sqlite'] ) ? 1 : 0,
);
return $sanitized_values;
}
/**
* Content for the Dashboard Widget
*
* @since 2.2.0
*
* @return void
*/
function wpvulnerability_admin_dashboard_content() {
// Get the number of core vulnerabilites from cache.
$wpvulnerability_test_core_counter = json_decode( get_option( 'wpvulnerability-core-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_core_counter ) ) {
$wpvulnerability_test_core_counter = 0;
}
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_core = sprintf( _n( 'Core: %d vulnerability', 'Core: %d vulnerabilities', $wpvulnerability_test_core_counter, 'wpvulnerability' ), $wpvulnerability_test_core_counter );
// Get the number of themes vulnerabilites from cache.
$wpvulnerability_test_themes_counter = json_decode( get_option( 'wpvulnerability-themes-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_themes_counter ) ) {
$wpvulnerability_test_themes_counter = 0;
}
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_themes = sprintf( _n( 'Themes: %d vulnerability', 'Themes: %d vulnerabilities', $wpvulnerability_test_themes_counter, 'wpvulnerability' ), $wpvulnerability_test_themes_counter );
// Get the number of plugins vulnerabilites from cache.
$wpvulnerability_test_plugins_counter = json_decode( get_option( 'wpvulnerability-plugins-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_plugins_counter ) ) {
$wpvulnerability_test_plugins_counter = 0;
}
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_plugins = sprintf( _n( 'Plugins: %d vulnerability', 'Plugins: %d vulnerabilities', $wpvulnerability_test_plugins_counter, 'wpvulnerability' ), $wpvulnerability_test_plugins_counter );
// Get the number of PHP vulnerabilites from cache.
$wpvulnerability_test_php_counter = json_decode( get_option( 'wpvulnerability-php-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_php_counter ) ) {
$wpvulnerability_test_php_counter = 0;
}
$wpvulnerability_test_php_version = wpvulnerability_detect_php();
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_php = sprintf( __( 'PHP %s: ', 'wpvulnerability' ), $wpvulnerability_test_php_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_php_counter, 'wpvulnerability' ), $wpvulnerability_test_php_counter );
// Get the number of Apache HTTPD vulnerabilites from cache.
$show_apache = false;
$msg_apache = null;
$webserver = wpvulnerability_detect_webserver();
if ( isset( $webserver['id'] ) && 'apache' === $webserver['id'] && isset( $webserver['version'] ) && $webserver['version'] ) {
// Get the Apache HTTPD version.
$apache_version = wp_kses( (string) $webserver['version'], 'strip' );
$wpvulnerability_test_apache_counter = json_decode( get_option( 'wpvulnerability-apache-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_apache_counter ) ) {
$wpvulnerability_test_apache_counter = 0;
}
$wpvulnerability_test_apache_version = wpvulnerability_sanitize_and_validate_version( $apache_version );
$show_apache = true;
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_apache = sprintf( __( 'Apache %s: ', 'wpvulnerability' ), $wpvulnerability_test_apache_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_apache_counter, 'wpvulnerability' ), $wpvulnerability_test_apache_counter );
}
// Get the number of nginx vulnerabilites from cache.
$show_nginx = false;
$msg_nginx = null;
$webserver = wpvulnerability_detect_webserver();
if ( isset( $webserver['id'] ) && 'nginx' === $webserver['id'] && isset( $webserver['version'] ) && $webserver['version'] ) {
// Get the nginx version.
$nginx_version = wp_kses( (string) $webserver['version'], 'strip' );
$wpvulnerability_test_nginx_counter = json_decode( get_option( 'wpvulnerability-nginx-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_nginx_counter ) ) {
$wpvulnerability_test_nginx_counter = 0;
}
$wpvulnerability_test_nginx_version = wpvulnerability_sanitize_and_validate_version( $nginx_version );
$show_nginx = true;
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_nginx = sprintf( __( 'nginx %s: ', 'wpvulnerability' ), $wpvulnerability_test_nginx_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_nginx_counter, 'wpvulnerability' ), $wpvulnerability_test_nginx_counter );
}
// Get the number of mariadb vulnerabilites from cache.
$show_mariadb = false;
$msg_mariadb = null;
$sqlserver = wpvulnerability_detect_sqlserver();
if ( isset( $sqlserver['id'] ) && 'mariadb' === $sqlserver['id'] && isset( $sqlserver['version'] ) && $sqlserver['version'] ) {
// Get the mariadb version.
$mariadb_version = wp_kses( (string) $sqlserver['version'], 'strip' );
$wpvulnerability_test_mariadb_counter = json_decode( get_option( 'wpvulnerability-mariadb-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_mariadb_counter ) ) {
$wpvulnerability_test_mariadb_counter = 0;
}
$wpvulnerability_test_mariadb_version = wpvulnerability_sanitize_and_validate_version( $mariadb_version );
$show_mariadb = true;
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_mariadb = sprintf( __( 'MariaDB %s: ', 'wpvulnerability' ), $wpvulnerability_test_mariadb_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_mariadb_counter, 'wpvulnerability' ), $wpvulnerability_test_mariadb_counter );
}
// Get the number of mysql vulnerabilites from cache.
$show_mysql = false;
$msg_mysql = null;
$sqlserver = wpvulnerability_detect_sqlserver();
if ( isset( $sqlserver['id'] ) && 'mysql' === $sqlserver['id'] && isset( $sqlserver['version'] ) && $sqlserver['version'] ) {
// Get the mysql version.
$mysql_version = wp_kses( (string) $sqlserver['version'], 'strip' );
$wpvulnerability_test_mysql_counter = json_decode( get_option( 'wpvulnerability-mysql-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_mysql_counter ) ) {
$wpvulnerability_test_mysql_counter = 0;
}
$wpvulnerability_test_mysql_version = wpvulnerability_sanitize_and_validate_version( $mysql_version );
$show_mysql = true;
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_mysql = sprintf( __( 'MySQL %s: ', 'wpvulnerability' ), $wpvulnerability_test_mysql_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_mysql_counter, 'wpvulnerability' ), $wpvulnerability_test_mysql_counter );
}
// Get the number of ImageMagick vulnerabilites from cache.
$msg_imagemagick = null;
$show_imagemagick = false;
$version_imagemagick = wpvulnerability_get_software_version( 'imagemagick' );
if ( $version_imagemagick ) {
$show_imagemagick = true;
$wpvulnerability_test_imagemagick_counter = json_decode( get_option( 'wpvulnerability-imagemagick-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_imagemagick_counter ) ) {
$wpvulnerability_test_imagemagick_counter = 0;
}
$wpvulnerability_test_imagemagick_version = wpvulnerability_sanitize_and_validate_version( $version_imagemagick );
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_imagemagick = sprintf( __( 'ImageMagick %s: ', 'wpvulnerability' ), $wpvulnerability_test_imagemagick_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_imagemagick_counter, 'wpvulnerability' ), $wpvulnerability_test_imagemagick_counter );
}
// Get the number of curl vulnerabilites from cache.
$msg_curl = null;
$show_curl = false;
$version_curl = wpvulnerability_get_software_version( 'curl' );
if ( $version_curl ) {
$show_curl = true;
$wpvulnerability_test_curl_counter = json_decode( get_option( 'wpvulnerability-curl-vulnerable' ) );
if ( ! is_numeric( $wpvulnerability_test_curl_counter ) ) {
$wpvulnerability_test_curl_counter = 0;
}
$wpvulnerability_test_curl_version = wpvulnerability_sanitize_and_validate_version( $version_curl );
/* translators: Show the number of vulnerabilities in a WP-Admin dashboard */
$msg_curl = sprintf( __( 'curl %s: ', 'wpvulnerability' ), $wpvulnerability_test_curl_version ) . sprintf( _n( '%d vulnerability', '%d vulnerabilities', $wpvulnerability_test_curl_counter, 'wpvulnerability' ), $wpvulnerability_test_curl_counter );
}
// Get the number of memcached vulnerabilites from cache.
$msg_memcached = null;
$show_memcached = false;
$version_memcached = wpvulnerability_get_software_version( 'memcached' );
if ( $version_memcached ) {
$show_memcached = true;