array( 'title' => __('PHP rules', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_php_rules'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ), 'htaccess-rules' => array( 'title' => __('.htaccess rules', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_htaccess_rules'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ), '6g-firewall' => array( 'title' => __('6G firewall rules', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_6g_firewall'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ), 'internet-bots' => array( 'title' => __('Internet bots', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_internet_bots'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ), 'blacklist' => array( 'title' => __('Blacklist', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_blacklist'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ), 'wp-rest-api' => array( 'title' => __('WP REST API', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_wp_rest_api'), ), 'advanced-settings' => array( 'title' => __('Advanced settings', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_advanced_settings'), 'display_condition_callback' => array('AIOWPSecurity_Utility_Permissions', 'is_main_site_and_super_admin'), ) ); $this->menu_tabs = array_filter($menu_tabs, array($this, 'should_display_tab')); } /** * Renders the PHP Firewall settings tab * * @return void */ protected function render_php_rules() { global $aiowps_feature_mgr; global $aio_wp_security; global $aiowps_firewall_config; if (isset($_POST['aiowps_apply_php_firewall_settings'])) { // Do form submission tasks $nonce = $_POST['_wpnonce']; $result = AIOWPSecurity_Utility_Permissions::check_nonce_and_user_cap($nonce, 'aiowpsec-php-firewall-nonce'); if (is_wp_error($result)) { $aio_wp_security->debug_logger->log_debug($result->get_error_message(), 4); die("Nonce check failed on enable PHP firewall settings"); } //Save settings $aiowps_firewall_config->set_value('aiowps_enable_pingback_firewall', isset($_POST["aiowps_enable_pingback_firewall"])); $aio_wp_security->configs->set_value('aiowps_disable_xmlrpc_pingback_methods', isset($_POST["aiowps_disable_xmlrpc_pingback_methods"]) ? '1' : ''); //this disables only pingback methods of xmlrpc but leaves other methods so that Jetpack and other apps will still work $aio_wp_security->configs->set_value('aiowps_disable_rss_and_atom_feeds', isset($_POST['aiowps_disable_rss_and_atom_feeds']) ? '1' : ''); $aiowps_firewall_config->set_value('aiowps_forbid_proxy_comments', isset($_POST['aiowps_forbid_proxy_comments'])); $aiowps_firewall_config->set_value('aiowps_deny_bad_query_strings', isset($_POST['aiowps_deny_bad_query_strings'])); $aiowps_firewall_config->set_value('aiowps_advanced_char_string_filter', isset($_POST['aiowps_advanced_char_string_filter'])); //Commit the config settings $aio_wp_security->configs->save_config(); //Recalculate points after the feature status/options have been altered $aiowps_feature_mgr->check_feature_status_and_recalculate_points(); $this->show_msg_updated(__('Settings were successfully saved', 'all-in-one-wp-security-and-firewall')); } $aio_wp_security->include_template('wp-admin/firewall/php-firewall-rules.php'); } /** * Renders the Htaccess Firewall tab * * @return void */ protected function render_htaccess_rules() { global $aiowps_feature_mgr; global $aio_wp_security; if (isset($_POST['aiowps_apply_htaccess_firewall_settings'])) { // Do form submission tasks $nonce = $_POST['_wpnonce']; $result = AIOWPSecurity_Utility_Permissions::check_nonce_and_user_cap($nonce, 'aiowpsec-htaccess-firewall-nonce'); if (is_wp_error($result)) { $aio_wp_security->debug_logger->log_debug($result->get_error_message(), 4); die("Nonce check failed on enable htaccess firewall settings"); } // Max file upload size in basic rules $upload_size = absint($_POST['aiowps_max_file_upload_size']); $upload_size = apply_filters('aiowps_max_allowed_upload_config', $upload_size); // Set a filterable limit if (empty($upload_size)) { $upload_size = AIOS_FIREWALL_MAX_FILE_UPLOAD_LIMIT_MB; } //Save settings $aio_wp_security->configs->set_value('aiowps_enable_basic_firewall', isset($_POST["aiowps_enable_basic_firewall"]) ? '1' : ''); $aio_wp_security->configs->set_value('aiowps_max_file_upload_size', $upload_size); $aio_wp_security->configs->set_value('aiowps_block_debug_log_file_access', isset($_POST["aiowps_block_debug_log_file_access"]) ? '1' : ''); $aio_wp_security->configs->set_value('aiowps_disable_index_views', isset($_POST['aiowps_disable_index_views']) ? '1' : ''); $aio_wp_security->configs->set_value('aiowps_disable_trace_and_track', isset($_POST['aiowps_disable_trace_and_track']) ? '1' : ''); //Commit the config settings $aio_wp_security->configs->save_config(); //Recalculate points after the feature status/options have been altered $aiowps_feature_mgr->check_feature_status_and_recalculate_points(); //Now let's write the applicable rules to the .htaccess file $res = AIOWPSecurity_Utility_Htaccess::write_to_htaccess(); if ($res) { $this->show_msg_updated(__('You have successfully saved the .htaccess rules', 'all-in-one-wp-security-and-firewall')); } else { $this->show_msg_error(__('Could not write to the .htaccess file, please check the file permissions.', 'all-in-one-wp-security-and-firewall')); } } $aio_wp_security->include_template('wp-admin/firewall/htaccess-firewall-rules.php'); } /** * Renders the 6G Blacklist Firewall Rules tab * * @return void */ protected function render_6g_firewall() { global $aio_wp_security, $aiowps_feature_mgr, $aiowps_firewall_config; $block_request_methods = array_map('strtolower', AIOS_Abstracted_Ids::get_firewall_block_request_methods()); $current_request_methods_settings = $aiowps_firewall_config->get_value('aiowps_6g_block_request_methods'); $current_other_settings = array( $aiowps_firewall_config->get_value('aiowps_6g_block_query'), $aiowps_firewall_config->get_value('aiowps_6g_block_request'), $aiowps_firewall_config->get_value('aiowps_6g_block_referrers'), $aiowps_firewall_config->get_value('aiowps_6g_block_agents'), ); $are_methods_set = !empty($current_request_methods_settings); $are_others_set = array_reduce($current_other_settings, function($carry, $item) { return $carry || $item; }); if (($are_methods_set || $are_others_set) && '1' != $aio_wp_security->configs->get_value('aiowps_enable_6g_firewall')) { $aio_wp_security->configs->set_value('aiowps_enable_6g_firewall', '1'); $aio_wp_security->configs->save_config(); $aiowps_feature_mgr->check_feature_status_and_recalculate_points(); } //Save 6G/5G if (isset($_POST['aiowps_apply_5g_6g_firewall_settings'])) { $result = AIOWPSecurity_Utility_Permissions::check_nonce_and_user_cap($_POST['_wpnonce'], 'aiowpsec-enable-5g-6g-firewall-nonce'); if (is_wp_error($result)) { $aio_wp_security->debug_logger->log_debug($result->get_error_message(), 4); die($result->get_error_message()); } // If the user has changed the 5G firewall checkbox settings, then there is a need yo write htaccess rules again. $is_5G_firewall_option_changed = ((isset($_POST['aiowps_enable_5g_firewall']) && '1' != $aio_wp_security->configs->get_value('aiowps_enable_5g_firewall')) || (!isset($_POST['aiowps_enable_5g_firewall']) && '1' == $aio_wp_security->configs->get_value('aiowps_enable_5g_firewall'))); //Save settings if (isset($_POST['aiowps_enable_5g_firewall'])) { $aio_wp_security->configs->set_value('aiowps_enable_5g_firewall', '1'); } else { $aio_wp_security->configs->set_value('aiowps_enable_5g_firewall', ''); } if ($is_5G_firewall_option_changed) { $res = AIOWPSecurity_Utility_Htaccess::write_to_htaccess(); // let's write the applicable rules to the .htaccess file } if (isset($_POST['aiowps_enable_6g_firewall'])) { $aiowps_6g_block_request_methods = array_filter(AIOS_Abstracted_Ids::get_firewall_block_request_methods(), function($block_request_method) { return ('PUT' != $block_request_method); }); if (false === $are_methods_set && false === $are_others_set) { $aiowps_firewall_config->set_value('aiowps_6g_block_request_methods', $aiowps_6g_block_request_methods); $aiowps_firewall_config->set_value('aiowps_6g_block_query', true); $aiowps_firewall_config->set_value('aiowps_6g_block_request', true); $aiowps_firewall_config->set_value('aiowps_6g_block_referrers', true); $aiowps_firewall_config->set_value('aiowps_6g_block_agents', true); } else { $methods = array(); foreach ($block_request_methods as $block_request_method) { if (isset($_POST['aiowps_block_request_method_'.$block_request_method])) { $methods[] = strtoupper($block_request_method); } } $aiowps_firewall_config->set_value('aiowps_6g_block_request_methods', $methods); $aiowps_firewall_config->set_value('aiowps_6g_block_query', isset($_POST['aiowps_block_query'])); $aiowps_firewall_config->set_value('aiowps_6g_block_request', isset($_POST['aiowps_block_request'])); $aiowps_firewall_config->set_value('aiowps_6g_block_referrers', isset($_POST['aiowps_block_refs'])); $aiowps_firewall_config->set_value('aiowps_6g_block_agents', isset($_POST['aiowps_block_agents'])); } $aio_wp_security->configs->set_value('aiowps_enable_6g_firewall', '1'); $res = true; //shows the success notice } else { AIOWPSecurity_Configure_Settings::turn_off_all_6g_firewall_configs(); $aio_wp_security->configs->set_value('aiowps_enable_6g_firewall', ''); $res = true; } //Commit the config settings $aio_wp_security->configs->save_config(); if ($res) { $this->show_msg_updated(__('You have successfully saved the 5G/6G Firewall Protection configuration', 'all-in-one-wp-security-and-firewall')); // Recalculate points after the feature status/options have been altered $aiowps_feature_mgr->check_feature_status_and_recalculate_points(); } else { $this->show_msg_error(__('Could not write to the .htaccess file, please check the file permissions.', 'all-in-one-wp-security-and-firewall')); } } //Load required data from config if (!empty($aiowps_firewall_config)) { // firewall config is available $methods = $aiowps_firewall_config->get_value('aiowps_6g_block_request_methods'); if (empty($methods)) { $methods = array(); } $blocked_query = (bool) $aiowps_firewall_config->get_value('aiowps_6g_block_query'); $blocked_request = (bool) $aiowps_firewall_config->get_value('aiowps_6g_block_request'); $blocked_referrers = (bool) $aiowps_firewall_config->get_value('aiowps_6g_block_referrers'); $blocked_agents = (bool) $aiowps_firewall_config->get_value('aiowps_6g_block_agents'); if (empty($methods) && (!$blocked_query && !$blocked_request && !$blocked_referrers && !$blocked_agents) && '1' == $aio_wp_security->configs->get_value('aiowps_enable_6g_firewall')) { $aio_wp_security->configs->set_value('aiowps_enable_6g_firewall', ''); $aio_wp_security->configs->save_config(); $aiowps_feature_mgr->check_feature_status_and_recalculate_points(); } } else { // firewall config is unavailable ?>