forked from pluginkollektiv/antivirus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantivirus.php
1046 lines (905 loc) · 24.3 KB
/
antivirus.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
/**
* Plugin Name: AntiVirus
* Description: Security plugin to protect your blog or website against exploits and spam injections.
* Author: pluginkollektiv
* Author URI: http://pluginkollektiv.org
* Plugin URI: https://wordpress.org/plugins/antivirus/
* Text Domain: antivirus
* Domain Path: /lang
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Version: 1.3.9
*
* @package AntiVirus
*/
/*
Copyright (C) 2009-2015 Sergej Müller
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.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// Make sure we don't expose any info if called directly.
if ( ! class_exists( 'WP' ) ) {
die();
}
/**
* Main plugin class.
*/
class AntiVirus {
/**
* The basename of a plugin.
*
* @var string
*/
private static $base;
/**
* Pseudo constructor.
*/
public static function instance() {
new self();
}
/**
* Constructor.
*
* Should not be called directly,
*
* @see AntiVirus::instance()
*/
public function __construct() {
// Don't run during autosave or XML-RPC request.
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
return;
}
// Save the plugin basename.
self::$base = plugin_basename( __FILE__ );
// Run the daily cronjob.
if ( defined( 'DOING_CRON' ) ) {
add_action( 'antivirus_daily_cronjob', array( __CLASS__, 'do_daily_cronjob' ) );
}
if ( is_admin() ) {
/* AJAX */
if ( defined( 'DOING_AJAX' ) ) {
add_action( 'wp_ajax_get_ajax_response', array( __CLASS__, 'get_ajax_response' ) );
} else {
/* Actions */
add_action( 'init', array( __CLASS__, 'load_plugin_lang' ) );
add_action( 'admin_menu', array( __CLASS__, 'add_sidebar_menu' ) );
add_action( 'admin_notices', array( __CLASS__, 'show_dashboard_notice' ) );
add_action( 'deactivate_' . self::$base, array( __CLASS__, 'clear_scheduled_hook' ) );
add_action( 'plugin_row_meta', array( __CLASS__, 'init_row_meta' ), 10, 2 );
add_action( 'plugin_action_links_' . self::$base, array( __CLASS__, 'init_action_links' ) );
}
}
}
/**
* Load plugin translations.
*/
public static function load_plugin_lang() {
load_plugin_textdomain( 'antivirus', false, basename( dirname( plugin_dir_path( __FILE__ ) ) ) . '/lang' );
}
/**
* Adds a link to the plugin settings in the plugin list table.
*
* @param array $data Plugin action links.
* @return array The modified action links array.
*/
public static function init_action_links( $data ) {
// Only add link if user has permissions to view them.
if ( ! current_user_can( 'manage_options' ) ) {
return $data;
}
return array_merge(
$data,
array(
sprintf(
'<a href="%s">%s</a>',
add_query_arg(
array(
'page' => 'antivirus',
),
admin_url( 'options-general.php' )
),
__( 'Settings' )
),
)
);
}
/**
* Adds a donation link to the second row in the plugin list table.
*
* @param array $data Plugin links array.
* @param string $page The current row identifier.
* @return array The modified links array.
*/
public static function init_row_meta( $data, $page ) {
if ( $page !== self::$base ) {
return $data;
}
return array_merge(
$data,
array(
'<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8CH5FPR88QYML" target="_blank">PayPal</a>',
)
);
}
/**
* Plugin activation hook.
*/
public static function activation() {
// Add default option.
add_option(
'antivirus',
array(),
'',
'no'
);
// Add cron schedule.
if ( self::_get_option( 'cronjob_enable' ) ) {
self::_add_scheduled_hook();
}
}
/**
* Plugin deactivation hook.
*/
public static function deactivation() {
self::clear_scheduled_hook();
}
/**
* Plugin uninstall hook.
*/
public static function uninstall() {
delete_option( 'antivirus' );
}
/**
* Get a plugin option value.
*
* @param string $field Option name.
* @return string The option value.
*/
private static function _get_option( $field ) {
$options = wp_parse_args(
get_option( 'antivirus' ),
array(
'cronjob_enable' => 0,
'cronjob_alert' => 0,
'safe_browsing' => 0,
'notify_email' => '',
'white_list' => '',
)
);
return ( empty( $options[ $field ] ) ? '' : $options[ $field ] );
}
/**
* Update an option in the database.
*
* @param string $field The option name.
* @param string|int $value The option value.
*/
private static function _update_option( $field, $value ) {
self::_update_options(
array(
$field => $value,
)
);
}
/**
* Update multiple options in the database.
*
* @param array $data An associative array of option fields and values.
*/
private static function _update_options( $data ) {
update_option(
'antivirus',
array_merge(
(array) get_option( 'antivirus' ),
$data
)
);
}
/**
* Initialize the cronjob.
*
* Schedules the AntiVirus cronjob to run daily.
*/
private static function _add_scheduled_hook() {
if ( ! wp_next_scheduled( 'antivirus_daily_cronjob' ) ) {
wp_schedule_event(
time(),
'daily',
'antivirus_daily_cronjob'
);
}
}
/**
* Cancel the daily cronjob.
*/
public static function clear_scheduled_hook() {
if ( wp_next_scheduled( 'antivirus_daily_cronjob' ) ) {
wp_clear_scheduled_hook( 'antivirus_daily_cronjob' );
}
}
/**
* Cronjob callback.
*/
public static function do_daily_cronjob() {
// Check if cronjob is enabled in the plugin.
if ( ! self::_get_option( 'cronjob_enable' ) ) {
return;
}
// Load plugin textdomain.
self::load_plugin_lang();
// Check the Safe Browsing API.
self::_check_safe_browsing();
// Check the theme and permalinks.
self::_check_blog_internals();
}
/**
* Pings the Safe Browsing API to see if the website is infected.
*/
private static function _check_safe_browsing() {
// Check if option is enabled in the plugin.
if ( ! self::_get_option( 'safe_browsing' ) ) {
return;
}
// Request the API.
$response = wp_remote_get(
sprintf(
'https://sb-ssl.google.com/safebrowsing/api/lookup?client=wpantivirus&key=%s&appver=1.3.7&pver=3.1&url=%s',
'AIzaSyALNYwuy-Pidn7vx3-In-hU0zgMH5Wr42U',
urlencode( get_bloginfo( 'url' ) )
)
);
// API error?
if ( is_wp_error( $response ) ) {
return;
}
// All clear, nothing bad detected.
if ( wp_remote_retrieve_response_code( $response ) === 204 ) {
return;
}
// Send notification.
self::_send_warning_notification(
esc_html__( 'Safe Browsing Alert', 'antivirus' ),
sprintf(
"%s\r\nhttps://www.google.com/safebrowsing/diagnostic?site=%s&hl=%s",
esc_html__( 'Please check the Google Safe Browsing diagnostic page:', 'antivirus' ),
urlencode( get_bloginfo( 'url' ) ),
substr( get_locale(), 0, 2 )
)
);
}
/**
* Check blog internals like theme files and the permalink structure.
*/
private static function _check_blog_internals() {
// Execute checks.
if ( ! self::_check_theme_files() && ! self::_check_permalink_structure() ) {
return;
}
// Send notification.
self::_send_warning_notification(
esc_html__( 'Virus suspected', 'antivirus' ),
sprintf(
"%s\r\n%s",
esc_html__( 'The daily antivirus scan of your blog suggests alarm.', 'antivirus' ),
get_bloginfo( 'url' )
)
);
// Store alert in database.
self::_update_option(
'cronjob_alert',
1
);
}
/**
* Send a warning via email that something was detected.
*
* @param string $subject Subject of the notification email.
* @param string $body Email body.
*/
private static function _send_warning_notification( $subject, $body ) {
// Get recipient email address.
$email = self::_get_option( 'notify_email' );
// Get admin email address if nothing is stored.
if ( ! is_email( $email ) ) {
$email = get_bloginfo( 'admin_email' );
}
// Send email.
wp_mail(
$email,
sprintf(
'[%s] %s',
get_bloginfo( 'name' ),
$subject
),
sprintf(
"%s\r\n\r\n\r\n%s\r\n%s\r\n",
$body,
esc_html__( 'Notify message by AntiVirus for WordPress', 'antivirus' ),
esc_html__( 'http://wpantivirus.com', 'antivirus' )
)
);
}
/**
* Add sub menu page to the options main menu.
*/
public static function add_sidebar_menu() {
$page = add_options_page(
__( 'AntiVirus', 'antivirus' ),
__( 'AntiVirus', 'antivirus' ),
'manage_options',
'antivirus',
array(
__CLASS__,
'show_admin_menu',
)
);
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'add_enqueue_style' ) );
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'add_enqueue_script' ) );
}
/**
* Enqueue our JavaScript.
*/
public static function add_enqueue_script() {
// Get plugin data.
$data = get_plugin_data( __FILE__ );
// Enqueue the JavaScript.
wp_enqueue_script(
'av_script',
plugins_url( 'js/script.min.js', __FILE__ ),
array( 'jquery' ),
$data['Version']
);
// Localize script data.
wp_localize_script(
'av_script',
'av_settings',
array(
'nonce' => wp_create_nonce( 'av_ajax_nonce' ),
'theme' => esc_js( urlencode( self::_get_theme_name() ) ),
'msg_1' => esc_js( __( 'There is no virus', 'antivirus' ) ),
'msg_2' => esc_js( __( 'View line', 'antivirus' ) ),
'msg_3' => esc_js( __( 'Scan finished', 'antivirus' ) ),
)
);
}
/**
* Enqueue our stylesheet.
*/
public static function add_enqueue_style() {
// Get plugin data.
$data = get_plugin_data( __FILE__ );
// Enqueue the stylesheet.
wp_enqueue_style(
'av_css',
plugins_url( 'css/style.min.css', __FILE__ ),
array(),
$data['Version']
);
}
/**
* Get the currently activated theme.
*
* @return array|false An array holding the theme data or false on failure.
*/
private static function _get_current_theme() {
$theme = wp_get_theme();
$name = $theme->get( 'Name' );
$slug = $theme->get_stylesheet();
$files = $theme->get_files( 'php', 1 );
// Check if empty.
if ( empty( $name ) || empty( $files ) ) {
return false;
}
return array(
'Name' => $name,
'Slug' => $slug,
'Template Files' => $files,
);
}
/**
* Get all the files belonging to the current theme.
*
* @return array|false Theme files or false on failure.
*/
private static function _get_theme_files() {
// Check if the theme exists.
if ( ! $theme = self::_get_current_theme() ) {
return false;
}
// Check its files.
if ( empty( $theme['Template Files'] ) ) {
return false;
}
// Returns the files, stripping out the content dir from the paths.
return array_unique(
array_map(
create_function(
'$v',
'return str_replace(array(WP_CONTENT_DIR, "wp-content"), "", $v);'
),
$theme['Template Files']
)
);
}
/**
* Get the name of the currently activated theme.
*
* @return string|false The theme name or false on failure.
*/
private static function _get_theme_name() {
if ( $theme = self::_get_current_theme() ) {
if ( ! empty( $theme['Slug'] ) ) {
return $theme['Slug'];
}
if ( ! empty( $theme['Name'] ) ) {
return $theme['Name'];
}
}
return false;
}
/**
* Get the whitelist.
*
* @return array MD5 hashes of whitelisted files.
*/
private static function _get_white_list() {
return explode(
':',
self::_get_option( 'white_list' )
);
}
/**
* Ajax response handler.
*/
public static function get_ajax_response() {
// Check referer.
check_ajax_referer( 'av_ajax_nonce' );
// Check if there really is some data.
if ( empty( $_POST['_action_request'] ) ) {
exit();
}
// Check user permissions.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$values = array();
// Get value based on request.
switch ( $_POST['_action_request'] ) {
case 'get_theme_files':
self::_update_option(
'cronjob_alert',
0
);
$values = self::_get_theme_files();
break;
case 'check_theme_file':
if ( ! empty( $_POST['_theme_file'] ) && $lines = self::_check_theme_file( $_POST['_theme_file'] ) ) {
foreach ( $lines as $num => $line ) {
foreach ( $line as $string ) {
$values[] = $num;
$values[] = htmlentities( $string, ENT_QUOTES );
$values[] = md5( $num . $string );
}
}
}
break;
case 'update_white_list':
if ( ! empty( $_POST['_file_md5'] ) && preg_match( '/^[a-f0-9]{32}$/', $_POST['_file_md5'] ) ) {
self::_update_option(
'white_list',
implode(
':',
array_unique(
array_merge(
self::_get_white_list(),
array( $_POST['_file_md5'] )
)
)
)
);
$values = array( $_POST['_file_md5'] );
}
break;
default:
break;
}
// Send response.
if ( $values ) {
wp_send_json(
array(
'data' => array_values( $values ),
'nonce' => $_POST['_ajax_nonce'],
)
);
}
exit();
}
/**
* Get file contents
*
* @param string $file File path.
* @return array An array containing all the lines of the file.
*/
private static function _get_file_content( $file ) {
return file( WP_CONTENT_DIR . $file );
}
/**
* Shorten a string, append ellipsis.
*
* @param string $line The line.
* @param string $tag The tag we're looking for.
* @param int $max Maximum number of chars on each side.
* @return string|false The shortened string or false on failure.
*/
private static function _get_dotted_line( $line, $tag, $max = 100 ) {
// No values?
if ( ! $line || ! $tag ) {
return false;
}
// Return tag if it's higher than the maximum.
if ( strlen( $tag ) > $max ) {
return $tag;
}
// Get difference between the tag and the maximum.
$left = round( ( $max - strlen( $tag ) ) / 2 );
// Quote regular expression characters.
$tag = preg_quote( $tag );
// Shorten string on the right side.
$output = preg_replace(
'/(' . $tag . ')(.{' . $left . '}).{0,}$/',
'$1$2 ...',
$line
);
// Shorten string on the left side.
$output = preg_replace(
'/^.{0,}(.{' . $left . ',})(' . $tag . ')/',
'... $1$2',
$output
);
return $output;
}
/**
* Get the regular expression for all disallowed words/functions.
*
* @return string Regular expression.
*/
private static function _php_match_pattern() {
return '/(assert|file_get_contents|curl_exec|popen|proc_open|unserialize|eval|base64_encode|base64_decode|create_function|exec|shell_exec|system|passthru|ob_get_contents|file|curl_init|readfile|fopen|fsockopen|pfsockopen|fclose|fread|file_put_contents)\s*?\(/';
}
/**
* Check a specific line number.
*
* @param string $line The line to check.
* @param int $num Line number.
* @return array|bool An array of matched lines or false on failure.
*/
private static function _check_file_line( $line = '', $num ) {
// Trim value.
$line = trim( (string) $line );
// Make sure the values aren't empty.
if ( ! $line || ! isset( $num ) ) {
return false;
}
$results = array();
$output = array();
// Check if the regex matches.
preg_match_all(
self::_php_match_pattern(),
$line,
$matches
);
// Save matches.
if ( $matches[1] ) {
$results = $matches[1];
}
// Search for base64 encoded strings.
preg_match_all(
'/[\'\"\$\\ \/]*?([a-zA-Z0-9]{' . strlen( base64_encode( 'sergej + swetlana = love.' ) ) . ',})/', /* get length of my life ;) */
$line,
$matches
);
// Save matches.
if ( $matches[1] ) {
$results = array_merge( $results, $matches[1] );
}
// Look for frames.
preg_match_all(
'/<\s*?(i?frame)/',
$line,
$matches
);
// Save matches.
if ( $matches[1] ) {
$results = array_merge( $results, $matches[1] );
}
// Look for the MailPoet vulnerability.
preg_match_all(
'/explode\s?\(chr\s?\(\s?\(\d{3}\s?-\s?\d{3}\s?\)\s?\)\s?,/',
$line,
$matches
);
// Save matches.
if ( $matches[0] ) {
$results = array_merge( $results, $matches[0] );
}
// Look for `get_option` calls.
preg_match(
'/get_option\s*\(\s*[\'"](.*?)[\'"]\s*\)/',
$line,
$matches
);
// Check option.
if ( $matches && $matches[1] && self::_check_file_line( get_option( $matches[1] ), $num ) ) {
array_push( $results, 'get_option' );
}
if ( $results ) {
// Remove duplicates.
$results = array_unique( $results );
// Get whitelist.
$md5 = self::_get_white_list();
// Loop through results.
foreach ( $results as $tag ) {
$string = str_replace(
$tag,
'@span@' . $tag . '@/span@',
self::_get_dotted_line( $line, $tag )
);
// Add line to output if it's not on the whitelist.
if ( ! in_array( md5( $num . $string ), $md5 ) ) {
$output[] = $string;
}
}
return $output;
}
return false;
}
/**
* Check the files of the currently activated theme.
*
* @return array|false Results array or false on failure.
*/
private static function _check_theme_files() {
// Check if there are any files.
if ( ! $files = self::_get_theme_files() ) {
return false;
}
$results = array();
// Loop through files.
foreach ( $files as $file ) {
if ( $result = self::_check_theme_file( $file ) ) {
$results[ $file ] = $result;
}
}
// Return results if found.
if ( ! empty( $results ) ) {
return $results;
}
return false;
}
/**
* Check a single file.
*
* @param string $file File path.
* @return array|false Results array or false on failure.
*/
private static function _check_theme_file( $file ) {
// Simple file path check.
if ( filter_var( $file, FILTER_SANITIZE_URL ) !== $file ) {
return false;
}
// Sanitize file string.
if ( validate_file( $file ) !== 0 ) {
return false;
}
// No file?
if ( ! $file ) {
return false;
}
// Get file content.
$content = self::_get_file_content( $file );
if ( ! $content ) {
return false;
}
$results = array();
// Loop through lines.
foreach ( $content as $num => $line ) {
if ( $result = self::_check_file_line( $line, $num ) ) {
$results[ $num ] = $result;
}
}
// Return results if found.
if ( ! empty( $results ) ) {
return $results;
}
return false;
}
/**
* Check the permalink structure.
*
* @return array|false Results array or false on failure.
*/
private static function _check_permalink_structure() {
$structure = get_option( 'permalink_structure' );
if ( ! $structure ) {
return false;
}
// Regex check.
preg_match_all(
self::_php_match_pattern(),
$structure,
$matches
);
// Save matches.
if ( $matches[1] ) {
return $matches[1];
}
return false;
}
/**
* Show notice on the dashboard.
*/
public static function show_dashboard_notice() {
// Only show notice if there's an alert.
if ( ! self::_get_option( 'cronjob_alert' ) ) {
return;
}
// Display warning.
echo sprintf(
'<div class="error"><p><strong>%1$s:</strong> %2$s <a href="%3$s">%4$s →</a></p></div>',
esc_html__( 'Virus suspected', 'antivirus' ),
esc_html__( 'The daily antivirus scan of your blog suggests alarm.', 'antivirus' ),
esc_url( add_query_arg(
array(
'page' => 'antivirus',
),
admin_url( 'options-general.php' )
) ),
esc_html__( 'Manual malware scan', 'antivirus' )
);
}
/**
* Print the settings page.
*/
public static function show_admin_menu() {
// Save updates.
if ( ! empty( $_POST ) ) {
// Check the referer.
check_admin_referer( 'antivirus' );
// Save values.
$options = array(
'cronjob_enable' => (int) ( ! empty( $_POST['av_cronjob_enable'] ) ),
'notify_email' => sanitize_email( @$_POST['av_notify_email'] ),
'safe_browsing' => (int) ( ! empty( $_POST['av_safe_browsing'] ) ),
);
// No cronjob?
if ( empty( $options['cronjob_enable'] ) ) {
$options['notify_email'] = '';
$options['safe_browsing'] = 0;
}
// Stop cron if it was disabled.
if ( $options['cronjob_enable'] && ! self::_get_option( 'cronjob_enable' ) ) {
self::_add_scheduled_hook();
} else if ( ! $options['cronjob_enable'] && self::_get_option( 'cronjob_enable' ) ) {
self::clear_scheduled_hook();
}
// Save options.
self::_update_options( $options ); ?>
<div id="message" class="updated fade">
<p>
<strong>
<?php esc_html_e( 'Settings saved.', 'antivirus' ); ?>
</strong>
</p>
</div>
<?php } ?>
<div class="wrap" id="av_main">
<h2>
<?php esc_html_e( 'AntiVirus', 'antivirus' ); ?>
</h2>
<table class="form-table">
<tr valign="top">
<th scope="row">
<?php esc_html_e( 'Manual malware scan', 'antivirus' ); ?>
</th>
<td>
<div class="inside" id="av_manual_scan">
<p>
<a href="#" class="button button-primary">
<?php esc_html_e( 'Scan the theme templates now', 'antivirus' ); ?>
</a>
<span class="alert"></span>
</p>
<div class="output"></div>
</div>
</td>
</tr>
</table>
<form method="post" action="">
<?php wp_nonce_field( 'antivirus' ) ?>
<table class="form-table">
<tr valign="top">
<th scope="row">
<?php esc_html_e( 'Daily malware scan', 'antivirus' ) ?>
</th>
<td>
<fieldset>
<label for="av_cronjob_enable">
<input type="checkbox" name="av_cronjob_enable" id="av_cronjob_enable"
value="1" <?php checked( self::_get_option( 'cronjob_enable' ), 1 ) ?> />
<?php esc_html_e( 'Check the theme templates for malware', 'antivirus' ) ?>
</label>
<p class="description">
<?php
if ( $timestamp = wp_next_scheduled( 'antivirus_daily_cronjob' ) ) {
echo sprintf(
'%s: %s',
esc_html__( 'Next Run', 'antivirus' ),
date_i18n( 'd.m.Y H:i:s', $timestamp + get_option( 'gmt_offset' ) * 3600 )
);
}
?>
</p>
<br/>
<label for="av_safe_browsing">
<input type="checkbox" name="av_safe_browsing" id="av_safe_browsing"
value="1" <?php checked( self::_get_option( 'safe_browsing' ), 1 ) ?> />
<?php esc_html_e( 'Malware detection by Google Safe Browsing', 'antivirus' ) ?>
</label>
<p class="description">
<?php esc_html_e( 'Diagnosis and notification in suspicion case', 'antivirus' ) ?>
</p>
<br/>
<label for="av_notify_email">
<input type="text" name="av_notify_email" id="av_notify_email"
value="<?php esc_attr_e( self::_get_option( 'notify_email' ) ) ?>"