From bffd1f59b67693cc96fefa60139600191fe246a2 Mon Sep 17 00:00:00 2001 From: Verdict-as-a-Service Team Date: Mon, 2 Sep 2024 11:13:51 +0200 Subject: [PATCH 1/6] WordPress Review ## The URL(s) declared in your plugin seems to be invalid or does not work. --- Readme.md | 4 ++-- gdata-antivirus.php | 2 +- tests/unittests/GdataAntivirusTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index e618aff..a9bc40c 100644 --- a/Readme.md +++ b/Readme.md @@ -41,11 +41,11 @@ The scheduled scan feature of the WordPress Antivirus Plugin with G DATA VaaS In ## Support and Feedback -For any issues, questions, or feedback we have two channels [our vaas e-mail contact](oem@gdata.de) or leave us an issue on our [gitub-repository](https://github.com/GDATASoftwareAG/gdata-antivirus/issues). We appreciate your input and are committed to continually improving the plugin to meet your security needs. +For any issues, questions, or feedback we have two channels [our vaas e-mail contact](oem@gdata.de) or leave us an issue on our [gitub-repository](https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus/issues). We appreciate your input and are committed to continually improving the plugin to meet your security needs. ## License -This WordPress Antivirus Plugin is released under the [GNU General Public License v3.0](https://github.com/GDATASoftwareAG/gdata-antivirus/blob/main/LICENSE). Feel free to contribute, share, and modify the plugin within the terms of the license. +This WordPress Antivirus Plugin is released under the [GNU General Public License v3.0](https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus/blob/main/LICENSE). Feel free to contribute, share, and modify the plugin within the terms of the license. ## Contribution diff --git a/gdata-antivirus.php b/gdata-antivirus.php index fb8b634..b6b9451 100644 --- a/gdata-antivirus.php +++ b/gdata-antivirus.php @@ -14,7 +14,7 @@ * Requires at least: 6.2 * Tested up to: 6.6 * Requires PHP: 8.1 - * Plugin URI: https://github.com/GDATASoftwareAG/gdata-antivirus + * Plugin URI: https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus * Description: Vaas is a virus scanner for your WordPress installation. * License: GNU General Public License v3.0 * License URI: https://github.com/GDATASoftwareAG/vaas/blob/main/LICENSE diff --git a/tests/unittests/GdataAntivirusTest.php b/tests/unittests/GdataAntivirusTest.php index fc418a4..b199bd4 100644 --- a/tests/unittests/GdataAntivirusTest.php +++ b/tests/unittests/GdataAntivirusTest.php @@ -12,7 +12,7 @@ * Plugin Name: G DATA Antivirus * Version: 0.0.1 * Requires PHP: 8.1 - * Plugin URI: https://github.com/GDATASoftwareAG/gdata-antivirus + * Plugin URI: https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus * Description: Vaas is a virus scanner for your WordPress installation. * License: GNU General Public License v3.0 * License URI: https://github.com/GDATASoftwareAG/vaas/blob/main/LICENSE From dcfd56efd49b47521772dd5aab2e2fd0f973585e Mon Sep 17 00:00:00 2001 From: Verdict-as-a-Service Team Date: Mon, 2 Sep 2024 11:15:30 +0200 Subject: [PATCH 2/6] WordPress Review ## Using composer but could not find composer.json file --- .zipignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.zipignore b/.zipignore index d410737..2e2cd71 100644 --- a/.zipignore +++ b/.zipignore @@ -3,7 +3,7 @@ .git/* wordpress/* tests/* -compose* +compose.yml Dockerfile test.sh xdebug.ini From 47831b132a5f62782f752b198b8bc5049b1304a2 Mon Sep 17 00:00:00 2001 From: Verdict-as-a-Service Team Date: Mon, 2 Sep 2024 11:32:10 +0200 Subject: [PATCH 3/6] WordPress Review ## Internationalization: Don't use variables or defines as text, context or text domain parameters. --- PluginPage/FullScan/FullScanMenuPage.php | 6 +++--- Vaas/ScanClient.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PluginPage/FullScan/FullScanMenuPage.php b/PluginPage/FullScan/FullScanMenuPage.php index e1e11f2..06675b3 100644 --- a/PluginPage/FullScan/FullScanMenuPage.php +++ b/PluginPage/FullScan/FullScanMenuPage.php @@ -204,7 +204,7 @@ public function wordpress_gdata_antivirus_options_full_scan_batch_size_validatio add_settings_error( 'wordpress_gdata_antivirus_options_full_scan_batch_size', 'wordpress_gdata_antivirus_options_full', - __('batch_size cannot be 0') + __('batch_size cannot be 0', 'gdata-antivirus') ); } if ($value < 100) { @@ -212,7 +212,7 @@ public function wordpress_gdata_antivirus_options_full_scan_batch_size_validatio add_settings_error( 'wordpress_gdata_antivirus_options_full_scan_batch_size', 'wordpress_gdata_antivirus_options_full', - __('batch_size should be at least 100') + __('batch_size should be at least 100', 'gdata-antivirus') ); } return $value; @@ -230,7 +230,7 @@ public function wordpress_gdata_antivirus_options_full_scan_schedule_start_valid add_settings_error( 'wordpress_gdata_antivirus_options_full_scan_schedule_start', 'wordpress_gdata_antivirus_options_full_scan', - __('schedule start must be of format H:i') + __('schedule start must be of format H:i', 'gdata-antivirus') ); } return $value; diff --git a/Vaas/ScanClient.php b/Vaas/ScanClient.php index 455f027..6a68f6a 100644 --- a/Vaas/ScanClient.php +++ b/Vaas/ScanClient.php @@ -95,7 +95,7 @@ public function scan_post( $data, $postarr, $unsanitized_postarr ) { // phpcs:ignore if (\VaasSdk\Message\Verdict::MALICIOUS === $verdict->Verdict) { $this->logger->debug('gdata-antivirus: virus found in post'); - wp_die(esc_html__('virus found')); + wp_die(esc_html__('virus found', 'gdata-antivirus')); } return $postdata; } @@ -133,7 +133,7 @@ public function scan_comment( $commentdata ) { // phpcs:ignore if (\VaasSdk\Message\Verdict::MALICIOUS === $verdict->Verdict) { $this->logger->debug('gdata-antivirus: virus found in comment'); - wp_die(\esc_html__('virus found')); + wp_die(\esc_html__('virus found', 'gdata-antivirus')); } return $commentdata; } @@ -175,7 +175,7 @@ public function scan_single_upload( $file ) { $verdict = $this->scan_file($file['tmp_name']); if (\VaasSdk\Message\Verdict::MALICIOUS === $verdict) { - $file['error'] = __('virus found'); + $file['error'] = __('virus found', 'gdata-antivirus'); } return $file; } From ca090ec967f865e80d12a15e6269ca68f7d4394c Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Mon, 2 Sep 2024 09:51:14 +0000 Subject: [PATCH 4/6] WordPress review ## Generic function/class/define/namespace/option names --- PluginPage/AdminNotices.php | 6 +- PluginPage/Findings/FindingsMenuPage.php | 10 +- PluginPage/FullScan/FullScanMenuPage.php | 132 +++++++++--------- PluginPage/GdataAntivirusMenuPage.php | 110 +++++++-------- PluginPage/OnDemandScan/OnDemandScan.php | 106 +++++++------- PluginPage/js/authentication-method-toggle.js | 10 +- Vaas/ScanClient.php | 25 ++-- Vaas/VaasOptions.php | 6 +- gdata-antivirus.php | 14 +- tests/unittests/GdataAntivirusTest.php | 14 +- 10 files changed, 215 insertions(+), 218 deletions(-) diff --git a/PluginPage/AdminNotices.php b/PluginPage/AdminNotices.php index 9167ed5..f5bdf2f 100644 --- a/PluginPage/AdminNotices.php +++ b/PluginPage/AdminNotices.php @@ -19,11 +19,11 @@ public static function add_notice( $text ) { } public function save_notices() { - update_option('GdataAntivirusMenuNotices', self::$notices); + update_option('gdatacyberdefenseag_antivirus_notices', self::$notices); } public function output_notices() { - $notices = maybe_unserialize(get_option('GdataAntivirusMenuNotices')); + $notices = maybe_unserialize(get_option('gdatacyberdefenseag_antivirus_notices')); if (! empty($notices)) { echo '
'; @@ -34,7 +34,7 @@ public function output_notices() { echo '
'; - delete_option('GdataAntivirusMenuNotices'); + delete_option('gdatacyberdefenseag_antivirus_notices'); } } } diff --git a/PluginPage/Findings/FindingsMenuPage.php b/PluginPage/Findings/FindingsMenuPage.php index 1fe9037..6ac1d8a 100644 --- a/PluginPage/Findings/FindingsMenuPage.php +++ b/PluginPage/Findings/FindingsMenuPage.php @@ -28,8 +28,8 @@ public function __construct( $this->logger = $logger; $this->admin_notices = $admin_notices; - register_activation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_findings_table' )); - register_deactivation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_findings_table' )); + register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_findings_table' )); + register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_findings_table' )); if ($this->get_findings_count() === 0) { return; @@ -41,7 +41,7 @@ public function __construct( private function get_table_name(): string { $this->logger->debug('FindingsMenuPage::get_table_name'); - return $this->database->get_prefix(). WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME; + return $this->database->get_prefix(). GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME; } public function create_findings_table() { @@ -134,11 +134,11 @@ public function get_findings_count(): int { public function setup_menu(): void { \add_submenu_page( - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, 'Scan Findings', 'Scan Findings ' . $this->get_findings_count() . '', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_SLUG, array( $this, 'findings_list' ) ); } diff --git a/PluginPage/FullScan/FullScanMenuPage.php b/PluginPage/FullScan/FullScanMenuPage.php index 06675b3..ca0c9bd 100644 --- a/PluginPage/FullScan/FullScanMenuPage.php +++ b/PluginPage/FullScan/FullScanMenuPage.php @@ -32,8 +32,8 @@ public function __construct( $this->logger = $logger; $this->database = $database; - register_activation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_full_scan_operations_table' )); - register_deactivation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_full_scan_operations_table' )); + register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_full_scan_operations_table' )); + register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_full_scan_operations_table' )); if (! $vaas_options->credentials_configured()) { return; @@ -44,9 +44,9 @@ public function __construct( \add_action('init', array( $this, 'setup_fields' )); \add_action('admin_menu', array( $this, 'setup_menu' )); \add_action('admin_post_full_scan', array( $this, 'full_scan_interactive' )); - \add_action('wordpress_gdata_antivirus_scheduled_full_scan', array( $this, 'full_scan' )); + \add_action('gdatacyberdefenseag_antivirus_scheduled_full_scan', array( $this, 'full_scan' )); \add_action( - 'wordpress_gdata_antivirus_scan_batch', + 'gdatacyberdefenseag_antivirus_scan_batch', array( $this, 'scan_batch' ), ); @@ -54,26 +54,26 @@ public function __construct( } private function setup_scheduled_scan() { - $full_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false); - $schedule_start = \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00'); - $next = wp_next_scheduled('wordpress_gdata_antivirus_scheduled_full_scan'); + $full_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false); + $schedule_start = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00'); + $next = wp_next_scheduled('gdatacyberdefenseag_antivirus_scheduled_full_scan'); if (! $full_scan_enabled && $next) { - \wp_unschedule_event($next, 'wordpress_gdata_antivirus_scheduled_full_scan'); + \wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan'); return; } if ($full_scan_enabled && ! $next) { $timestamp = strtotime($schedule_start); $this->logger->debug('schedule start timestamp: ' . $timestamp); - \wp_schedule_event($timestamp, 'daily', 'wordpress_gdata_antivirus_scheduled_full_scan'); + \wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan'); return; } $nextschedule_start = gmdate('H:i', $next); if ($nextschedule_start !== $schedule_start) { - \wp_unschedule_event($next, 'wordpress_gdata_antivirus_scheduled_full_scan'); + \wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan'); $timestamp = strtotime($schedule_start); - \wp_schedule_event($timestamp, 'daily', 'wordpress_gdata_antivirus_scheduled_full_scan'); + \wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan'); } } @@ -91,7 +91,7 @@ public function create_full_scan_operations_table() { } private function get_table_name(): string { - return $this->database->get_prefix() . WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME; + return $this->database->get_prefix() . GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME; } public function lock_scan_operations_table() { @@ -128,26 +128,26 @@ public function reset_scan_operations(): void { public function setup_fields(): void { \register_setting( - 'wordpress_gdata_antivirus_options_full_scan_run', - 'wordpress_gdata_antivirus_options_full_scan_batch_size', + 'gdatacyberdefenseag_antivirus_options_full_scan_run', + 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size', array( 'type' => 'number', 'default' => 100, - 'sanitize_callback' => array( $this, 'wordpress_gdata_antivirus_options_full_scan_batch_size_validation' ), + 'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation' ), ) ); \register_setting( - 'wordpress_gdata_antivirus_options_full_scan_run', - 'wordpress_gdata_antivirus_options_full_scan_schedule_start', + 'gdatacyberdefenseag_antivirus_options_full_scan_run', + 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', array( 'type' => 'string', 'default' => '01:00', - 'sanitize_callback' => array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_start_validation' ), + 'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation' ), ) ); \register_setting( - 'wordpress_gdata_antivirus_options_full_scan_run', - 'wordpress_gdata_antivirus_options_full_scan_schedule_enabled', + 'gdatacyberdefenseag_antivirus_options_full_scan_run', + 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', array( 'type' => 'boolean', 'default' => false, @@ -157,70 +157,70 @@ public function setup_fields(): void { public function setup_menu(): void { \add_settings_section( - 'wordpress_gdata_antivirus_options_full_scan', + 'gdatacyberdefenseag_antivirus_options_full_scan', esc_html__('Full Scan', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_full_scan_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG + array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG ); \add_settings_field( - 'wordpress_gdata_antivirus_options_full_scan_batch_size', + 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size', esc_html__('Batch Size', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_full_scan_batch_size_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_full_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_full_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_full_scan_schedule_enabled', + 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', esc_html__('Scheduled Scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_full_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_full_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_full_scan_schedule_start', + 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', esc_html__('Scheduled Scan starting Hour', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_start_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_full_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_full_scan' ); \add_submenu_page( - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, 'Full scan', 'Full scan', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG, array( $this, 'full_scan_menu' ) ); } - public function wordpress_gdata_antivirus_options_full_scan_batch_size_validation( $value ) { - $option = get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100); + public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation( $value ) { + $option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100); if (0 === $value) { $value = $option; add_settings_error( - 'wordpress_gdata_antivirus_options_full_scan_batch_size', - 'wordpress_gdata_antivirus_options_full', + 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size', + 'gdatacyberdefenseag_antivirus_options_full', __('batch_size cannot be 0', 'gdata-antivirus') ); } if ($value < 100) { $value = $option; add_settings_error( - 'wordpress_gdata_antivirus_options_full_scan_batch_size', - 'wordpress_gdata_antivirus_options_full', + 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size', + 'gdatacyberdefenseag_antivirus_options_full', __('batch_size should be at least 100', 'gdata-antivirus') ); } return $value; } - public function wordpress_gdata_antivirus_options_full_scan_schedule_start_validation( $value ) { - $option = get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00'); - $full_scan_enabled = get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false); + public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation( $value ) { + $option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00'); + $full_scan_enabled = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false); if (! $full_scan_enabled) { return $option; @@ -228,35 +228,35 @@ public function wordpress_gdata_antivirus_options_full_scan_schedule_start_valid if (preg_match('#^[0-9]{2}:[0-9]{2}$#', $value) !== 1) { $value = $option; add_settings_error( - 'wordpress_gdata_antivirus_options_full_scan_schedule_start', - 'wordpress_gdata_antivirus_options_full_scan', + 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', + 'gdatacyberdefenseag_antivirus_options_full_scan', __('schedule start must be of format H:i', 'gdata-antivirus') ); } return $value; } - public function wordpress_gdata_antivirus_options_full_scan_text() { + public function gdatacyberdefenseag_antivirus_options_full_scan_text() { echo '

' . esc_html__('Here you can set options for the full scan', 'gdata-antivirus') . '

'; } - public function wordpress_gdata_antivirus_options_full_scan_schedule_enabled_text() { - $full_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false); - echo ""; + public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text() { + $full_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false); + echo ""; } - public function wordpress_gdata_antivirus_options_full_scan_batch_size_text() { - $batch_size = \get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100); - echo ""; + public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text() { + $batch_size = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100); + echo ""; } - public function wordpress_gdata_antivirus_options_full_scan_schedule_start_text() { - $schedule_start = \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00'); + public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text() { + $schedule_start = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00'); $full_scan_enabled = - (bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false); + (bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false); $this->logger->debug('schedule_start: ' . $schedule_start); - echo "'; + echo "'; } public function full_scan_interactive(): void { @@ -285,7 +285,7 @@ public function full_scan_interactive(): void { public function full_scan(): void { $this->admin_notices->add_notice(__('Full Scan started', 'gdata-antivirus')); - $batch_size = \get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100); + $batch_size = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100); $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ABSPATH, \FilesystemIterator::SKIP_DOTS)); $files = array(); foreach ($it as $file_path) { @@ -300,13 +300,13 @@ public function full_scan(): void { if (count($files) >= $batch_size) { $this->increase_scheduled_scans(); - \wp_schedule_single_event(time(), 'wordpress_gdata_antivirus_scan_batch', array( 'files' => $files )); + \wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files )); $files = array(); } } if (count($files) > 0) { $this->increase_scheduled_scans(); - \wp_schedule_single_event(time(), 'wordpress_gdata_antivirus_scan_batch', array( 'files' => $files )); + \wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files )); } } @@ -339,14 +339,14 @@ public function scan_batch( array $files ): void { } public function full_scan_menu(): void { - settings_errors('wordpress_gdata_antivirus_options_full_scan_schedule_start'); - settings_errors('wordpress_gdata_antivirus_options_full_scan_batch_size'); + settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start'); + settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_batch_size'); ?>

Full Scan Settings

diff --git a/PluginPage/GdataAntivirusMenuPage.php b/PluginPage/GdataAntivirusMenuPage.php index 704c0ec..b09234e 100644 --- a/PluginPage/GdataAntivirusMenuPage.php +++ b/PluginPage/GdataAntivirusMenuPage.php @@ -27,59 +27,59 @@ public function __construct( public function setup_menu(): void { \add_settings_section( - 'wordpress_gdata_antivirus_options_credentials', + 'gdatacyberdefenseag_antivirus_options_credentials', esc_html__('Credentials', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG + array( $this, 'gdatacyberdefenseag_antivirus_credentials_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_authentication_method', + 'gdatacyberdefenseag_antivirus_credentials_authentication_method', esc_html__('Authentication Method', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_authentication_method_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_authentication_method_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_client_id', + 'gdatacyberdefenseag_antivirus_credentials_client_id', esc_html__('Client ID', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_client_id_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_client_id_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_client_secret', + 'gdatacyberdefenseag_antivirus_credentials_client_secret', esc_html__('Client Secret', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_client_secret_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_client_secret_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_username', + 'gdatacyberdefenseag_antivirus_credentials_username', esc_html__('Username', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_username_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_username_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_password', + 'gdatacyberdefenseag_antivirus_credentials_password', esc_html__('Password', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_password_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_password_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_vaas_url', + 'gdatacyberdefenseag_antivirus_credentials_vaas_url', esc_html__('VaaS-Url', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_vaas_url_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_vaas_url_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); \add_settings_field( - 'wordpress_gdata_antivirus_credentials_token_endpoint', + 'gdatacyberdefenseag_antivirus_credentials_token_endpoint', esc_html__('Token-Endpoint', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_credentials_token_endpoint_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, - 'wordpress_gdata_antivirus_options_credentials' + array( $this, 'gdatacyberdefenseag_antivirus_credentials_token_endpoint_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, + 'gdatacyberdefenseag_antivirus_options_credentials' ); $count = $this->findings_menu_page->get_findings_count(); @@ -89,16 +89,16 @@ public function setup_menu(): void { 'G DATA VaaS', $menu_title, 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, array( $this, 'credentials_menu_item' ), \plugin_dir_url(__FILE__) . '../PluginPage/assets/gdata16.png' ); \add_submenu_page( - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, $menu_title, 'Credentials', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, array( $this, 'credentials_menu_item' ) ); } else { @@ -106,16 +106,16 @@ public function setup_menu(): void { 'G DATA VaaS', 'VaaS', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, array( $this, 'credentials_menu_item' ), \plugin_dir_url(__FILE__) . '../PluginPage/assets/gdata16.png' ); \add_submenu_page( - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, 'VaaS', 'Credentials', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, array( $this, 'credentials_menu_item' ) ); } @@ -123,7 +123,7 @@ public function setup_menu(): void { public function enqueue_scripts( $hook_suffix ): void { \wp_enqueue_script( - 'wordpress_gdata_antivirus_options_credentials_authentication_method_toggle', + 'gdatacyberdefenseag_antivirus_options_credentials_authentication_method_toggle', \plugin_dir_url(__FILE__) . '/js/authentication-method-toggle.js', array(), "1.0.0", @@ -131,60 +131,60 @@ public function enqueue_scripts( $hook_suffix ): void { ); } - public function wordpress_gdata_antivirus_credentials_text() { + public function gdatacyberdefenseag_antivirus_credentials_text() { ?>

vaas_options->get_options(); ?> - "; "; "; vaas_options->get_options(); ?> - ' /> + ' /> vaas_options->get_options(); ?> - ' /> + ' /> vaas_options->get_options(); ?> - ' /> + ' /> vaas_options->get_options(); ?> - ' /> + ' /> vaas_options->get_options(); ?> - ' /> + ' /> vaas_options->get_options(); ?> - ' /> + ' /> VaaS Settings
diff --git a/PluginPage/OnDemandScan/OnDemandScan.php b/PluginPage/OnDemandScan/OnDemandScan.php index 9da56e2..752abd8 100644 --- a/PluginPage/OnDemandScan/OnDemandScan.php +++ b/PluginPage/OnDemandScan/OnDemandScan.php @@ -21,40 +21,40 @@ public function __construct( public function setup_fields(): void { \register_setting( - 'wordpress_gdata_antivirus_options_on_demand_scan', - 'wordpress_gdata_antivirus_options_on_demand_scan_media_upload_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', array( 'type' => 'boolean', 'default' => false, ) ); \register_setting( - 'wordpress_gdata_antivirus_options_on_demand_scan', - 'wordpress_gdata_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', array( 'type' => 'boolean', 'default' => false, ) ); \register_setting( - 'wordpress_gdata_antivirus_options_on_demand_scan', - 'wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', array( 'type' => 'boolean', 'default' => false, ) ); \register_setting( - 'wordpress_gdata_antivirus_options_on_demand_scan', - 'wordpress_gdata_antivirus_options_on_demand_scan_pingback_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', array( 'type' => 'boolean', 'default' => false, ) ); \register_setting( - 'wordpress_gdata_antivirus_options_on_demand_scan', - 'wordpress_gdata_antivirus_options_on_demand_scan_post_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', array( 'type' => 'boolean', 'default' => false, @@ -64,89 +64,89 @@ public function setup_fields(): void { public function setup_menu(): void { \add_settings_section( - 'wordpress_gdata_antivirus_options_on_demand_scan', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan', esc_html__('OnDemand scans', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_on_demand_scans_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG + array( $this, 'gdatacyberdefenseag_antivirus_options_on_demand_scans_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG ); \add_settings_field( - 'wordpress_gdata_antivirus_options_on_demand_scan_media_upload_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', esc_html__('Media upload scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_media_upload_scan_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_on_demand_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_media_upload_scan_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_on_demand_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', esc_html__('Plugin upload scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_plugin_upload_scan_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_on_demand_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_plugin_upload_scan_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_on_demand_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', esc_html__('Comment scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_comment_scan_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_on_demand_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_comment_scan_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_on_demand_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_on_demand_scan_pingback_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', esc_html__('Pingback scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_pingback_scan_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_on_demand_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_pingback_scan_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_on_demand_scan' ); \add_settings_field( - 'wordpress_gdata_antivirus_options_on_demand_scan_post_scan_enabled', + 'gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', esc_html__('Post scan enabled', 'gdata-antivirus'), - array( $this, 'wordpress_gdata_antivirus_options_post_scan_enabled_text' ), - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, - 'wordpress_gdata_antivirus_options_on_demand_scan' + array( $this, 'gdatacyberdefenseag_antivirus_options_post_scan_enabled_text' ), + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + 'gdatacyberdefenseag_antivirus_options_on_demand_scan' ); \add_submenu_page( - WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG, 'OnDemandScan', 'OnDemandScan', 'manage_options', - WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, + GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG, array( $this, 'on_demand_scan_menu' ) ); } - public function wordpress_gdata_antivirus_options_on_demand_scans_text() { + public function gdatacyberdefenseag_antivirus_options_on_demand_scans_text() { echo '

' . esc_html__('Here you can set options for the on demand scans', 'gdata-antivirus') . '

'; } - public function wordpress_gdata_antivirus_options_media_upload_scan_enabled_text() { - $media_upload_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); - echo ''; + public function gdatacyberdefenseag_antivirus_options_media_upload_scan_enabled_text() { + $media_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); + echo ''; } - public function wordpress_gdata_antivirus_options_plugin_upload_scan_enabled_text() { - $plugin_upload_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); - echo ''; + public function gdatacyberdefenseag_antivirus_options_plugin_upload_scan_enabled_text() { + $plugin_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); + echo ''; } - public function wordpress_gdata_antivirus_options_comment_scan_enabled_text() { - $comment_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', false); - echo ''; + public function gdatacyberdefenseag_antivirus_options_comment_scan_enabled_text() { + $comment_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', false); + echo ''; } - public function wordpress_gdata_antivirus_options_pingback_scan_enabled_text() { - $pingback_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_pingback_scan_enabled', false); - echo ''; + public function gdatacyberdefenseag_antivirus_options_pingback_scan_enabled_text() { + $pingback_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', false); + echo ''; } - public function wordpress_gdata_antivirus_options_post_scan_enabled_text() { - $post_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_post_scan_enabled', false); - echo ''; + public function gdatacyberdefenseag_antivirus_options_post_scan_enabled_text() { + $post_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', false); + echo ''; } public function on_demand_scan_menu(): void { @@ -154,8 +154,8 @@ public function on_demand_scan_menu(): void {

OnDenamns Scan Settings

diff --git a/PluginPage/js/authentication-method-toggle.js b/PluginPage/js/authentication-method-toggle.js index 257257d..1ee7a6b 100644 --- a/PluginPage/js/authentication-method-toggle.js +++ b/PluginPage/js/authentication-method-toggle.js @@ -1,11 +1,11 @@ document.addEventListener( 'DOMContentLoaded', function () { - const authMethodSelect = document.getElementById('wordpress_gdata_antivirus_credentials_authentication_method'); - const clientCredentialsClientIdField = document.getElementById('wordpress_gdata_antivirus_credentials_client_id').parentElement.parentElement; - const clientCredentialsClientSecretField = document.getElementById('wordpress_gdata_antivirus_credentials_client_secret').parentElement.parentElement; - const resourceOwnerUsernameField = document.getElementById('wordpress_gdata_antivirus_credentials_username').parentElement.parentElement; - const resourceOwnerPasswordField = document.getElementById('wordpress_gdata_antivirus_credentials_password').parentElement.parentElement; + const authMethodSelect = document.getElementById('gdatacyberdefenseag_antivirus_credentials_authentication_method'); + const clientCredentialsClientIdField = document.getElementById('gdatacyberdefenseag_antivirus_credentials_client_id').parentElement.parentElement; + const clientCredentialsClientSecretField = document.getElementById('gdatacyberdefenseag_antivirus_credentials_client_secret').parentElement.parentElement; + const resourceOwnerUsernameField = document.getElementById('gdatacyberdefenseag_antivirus_credentials_username').parentElement.parentElement; + const resourceOwnerPasswordField = document.getElementById('gdatacyberdefenseag_antivirus_credentials_password').parentElement.parentElement; function toggleAuthFields() { console.log(authMethodSelect.value); diff --git a/Vaas/ScanClient.php b/Vaas/ScanClient.php index 6a68f6a..c2fa6c7 100644 --- a/Vaas/ScanClient.php +++ b/Vaas/ScanClient.php @@ -2,7 +2,6 @@ namespace Gdatacyberdefenseag\GdataAntivirus\Vaas; -use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Database\IGdataAntivirusDatabase; use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem; use Psr\Log\LoggerInterface; use VaasSdk\Vaas; @@ -11,8 +10,6 @@ use VaasSdk\Message\Verdict; use VaasSdk\VaasOptions as VaasParameters; -use function Amp\ByteStream\Internal\tryToCreateReadableStreamFromResource; - if (! class_exists('ScanClient')) { class ScanClient { private Vaas $vaas; @@ -27,22 +24,22 @@ public function __construct( LoggerInterface $logger, VaasOptions $vaas_options, $this->file_system = $file_system; $this->Connect(); - $plugin_upload_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); - $media_upload_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); + $plugin_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); + $media_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); // We don't need to add the filters if both plugin and media upload scan are disabled. if ($plugin_upload_scan_enabled === true || $media_upload_scan_enabled === true) { \add_filter('wp_handle_upload_prefilter', array( $this, 'scan_single_upload' )); \add_filter('wp_handle_sideload_prefilter', array( $this, 'scan_single_upload' )); } - $comment_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', false); - $pingback_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_pingback_scan_enabled', false); + $comment_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', false); + $pingback_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', false); // We don't need to add the filter if both comment and pingback scan are disabled. if ($comment_scan_enabled === true || $pingback_scan_enabled === true) { \add_filter('preprocess_comment', array( $this, 'scan_comment' )); } - $post_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_post_scan_enabled', false); + $post_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', false); if ($post_scan_enabled === true) { \add_filter('wp_insert_post_data', array( $this, 'scan_post' )); } @@ -78,7 +75,7 @@ public function scan_post( $data, $postarr, $unsanitized_postarr ) { return $data; } - $post_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_post_scan_enabled', false); + $post_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', false); if ($post_scan_enabled === false) { return $data; } @@ -101,10 +98,10 @@ public function scan_post( $data, $postarr, $unsanitized_postarr ) { } public function scan_comment( $commentdata ) { - $comment_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', false); - $pingback_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_on_demand_scan_pingback_scan_enabled', false); + $comment_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', false); + $pingback_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', false); - $comment_scan_enabled = \get_option('wordpress_gdata_antivirus_options_on_demand_scan_comment_scan_enabled', false); + $comment_scan_enabled = \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', false); if ($comment_scan_enabled === false) { return $commentdata; } @@ -139,8 +136,8 @@ public function scan_comment( $commentdata ) { } public function scan_single_upload( $file ) { - $plugin_upload_scan_enabled = \get_option('wordpress_gdata_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); - $media_upload_scan_enabled = \get_option('wordpress_gdata_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); + $plugin_upload_scan_enabled = \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); + $media_upload_scan_enabled = \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); /** * When this is a plugin uplaod but the plugin upload scan is disabled, diff --git a/Vaas/VaasOptions.php b/Vaas/VaasOptions.php index 11143f1..f888483 100644 --- a/Vaas/VaasOptions.php +++ b/Vaas/VaasOptions.php @@ -19,8 +19,8 @@ public function __construct() { public function setup_fields(): void { \register_setting( - 'wordpress_gdata_antivirus_options_credentials', - 'wordpress_gdata_antivirus_options_credentials ', + 'gdatacyberdefenseag_antivirus_options_credentials', + 'gdatacyberdefenseag_antivirus_options_credentials ', array( 'type' => 'array', 'default ' => self::$option_defaults, @@ -29,7 +29,7 @@ public function setup_fields(): void { } public function get_options(): array { - $options = \get_option('wordpress_gdata_antivirus_options_credentials', self::$option_defaults); + $options = \get_option('gdatacyberdefenseag_antivirus_options_credentials', self::$option_defaults); $options = array_merge(self::$option_defaults, $options); return $options; } diff --git a/gdata-antivirus.php b/gdata-antivirus.php index b6b9451..92d737c 100644 --- a/gdata-antivirus.php +++ b/gdata-antivirus.php @@ -30,13 +30,13 @@ use Gdatacyberdefenseag\GdataAntivirus\GdataAntivirusPlugin; use Psr\Log\LoggerInterface; -define('WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__', __FILE__); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG', 'gdata-antivirus-menu'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-findings'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME', 'WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-full-scan'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME', 'WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-on-demand-scan'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__', __FILE__); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG', 'gdata-antivirus-menu'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-findings'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME', 'GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-full-scan'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME', 'GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-on-demand-scan'); $app = new GdataAntivirusPlugin(); $app->singleton( diff --git a/tests/unittests/GdataAntivirusTest.php b/tests/unittests/GdataAntivirusTest.php index b199bd4..f8f8142 100644 --- a/tests/unittests/GdataAntivirusTest.php +++ b/tests/unittests/GdataAntivirusTest.php @@ -61,13 +61,13 @@ // include __DIR__ . '/wordpress/wp-includes/formatting.php';. -define('WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__', __FILE__); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG', 'gdata-antivirus-menu'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-findings'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME', 'WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-full-scan'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME', 'WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS'); -define('WORDPRESS_GDATA_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG', WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG . '-on-demand-scan'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__', __FILE__); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG', 'gdata-antivirus-menu'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-findings'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME', 'GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-full-scan'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME', 'GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS'); +define('GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_ON_DEMAND_SCAN_SLUG', GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG . '-on-demand-scan'); class GdataAntivirusTest extends TestCase { public function testDependencyInjection() { From 3e24b10825c7ecee4ad6f7ac3ff292a58d669cb8 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Mon, 2 Sep 2024 10:14:32 +0000 Subject: [PATCH 5/6] for the better user experience, the defaults should be true --- PluginPage/OnDemandScan/OnDemandScan.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PluginPage/OnDemandScan/OnDemandScan.php b/PluginPage/OnDemandScan/OnDemandScan.php index 752abd8..fd48677 100644 --- a/PluginPage/OnDemandScan/OnDemandScan.php +++ b/PluginPage/OnDemandScan/OnDemandScan.php @@ -25,7 +25,7 @@ public function setup_fields(): void { 'gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', array( 'type' => 'boolean', - 'default' => false, + 'default' => true, ) ); \register_setting( @@ -33,7 +33,7 @@ public function setup_fields(): void { 'gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', array( 'type' => 'boolean', - 'default' => false, + 'default' => true, ) ); \register_setting( @@ -41,7 +41,7 @@ public function setup_fields(): void { 'gdatacyberdefenseag_antivirus_options_on_demand_scan_comment_scan_enabled', array( 'type' => 'boolean', - 'default' => false, + 'default' => true, ) ); \register_setting( @@ -49,7 +49,7 @@ public function setup_fields(): void { 'gdatacyberdefenseag_antivirus_options_on_demand_scan_pingback_scan_enabled', array( 'type' => 'boolean', - 'default' => false, + 'default' => true, ) ); \register_setting( @@ -57,7 +57,7 @@ public function setup_fields(): void { 'gdatacyberdefenseag_antivirus_options_on_demand_scan_post_scan_enabled', array( 'type' => 'boolean', - 'default' => false, + 'default' => true, ) ); } From 50fcb2c3e77948c3c983c3818f55612a1b5e9184 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Mon, 2 Sep 2024 10:20:31 +0000 Subject: [PATCH 6/6] Show error message when vaas cannot actually connect --- Vaas/ScanClient.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Vaas/ScanClient.php b/Vaas/ScanClient.php index c2fa6c7..15b920d 100644 --- a/Vaas/ScanClient.php +++ b/Vaas/ScanClient.php @@ -3,6 +3,7 @@ namespace Gdatacyberdefenseag\GdataAntivirus\Vaas; use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem; +use Gdatacyberdefenseag\GdataAntivirus\PluginPage\AdminNotices; use Psr\Log\LoggerInterface; use VaasSdk\Vaas; use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator; @@ -16,14 +17,27 @@ class ScanClient { private LoggerInterface $logger; private VaasOptions $vaas_options; private IGdataAntivirusFileSystem $file_system; - - public function __construct( LoggerInterface $logger, VaasOptions $vaas_options, IGdataAntivirusFileSystem $file_system ) { + private AdminNotices $admin_notices; + + public function __construct( + LoggerInterface $logger, + VaasOptions $vaas_options, + IGdataAntivirusFileSystem $file_system, + AdminNotices $admin_notices + ) { $logger->info('ScanClient::__construct'); $this->logger = $logger; $this->vaas_options = $vaas_options; $this->file_system = $file_system; + $this->admin_notices = $admin_notices; - $this->Connect(); + try { + $this->Connect(); + } catch (\Exception $e) { + $this->admin_notices->add_notice($e->getMessage()); + $this->logger->error("VaaS connection failed. Please verify if the VaaS-Url is correct."); + return; + } $plugin_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); $media_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); // We don't need to add the filters if both plugin and media upload scan are disabled.