s invalid.
* @throws Waf_Exception If the activation fails.
*
* @return void
*/
public static function activate() {
Waf_Constants::define_mode();
if ( ! self::is_allowed_mode( JETPACK_WAF_MODE ) ) {
throw new Waf_Exception( 'Invalid firewall mode.' );
}
$version = get_option( Waf_Rules_Manager::VERSION_OPTION_NAME );
if ( ! $version ) {
add_option( Waf_Rules_Manager::VERSION_OPTION_NAME, Waf_Rules_Manager::RULES_VERSION );
}
add_option( self::SHARE_DATA_OPTION_NAME, true );
self::initialize_filesystem();
Waf_Rules_Manager::generate_automatic_rules();
Waf_Rules_Manager::generate_ip_rules();
Waf_Rules_Manager::generate_rules();
self::create_blocklog_table();
}
/**
* Ensures that the waf directory is created.
*
* @throws File_System_Exception If filesystem is unavailable.
* @throws File_System_Exception If creating the directory fails.
*
* @return void
*/
public static function initialize_waf_directory() {
WP_Filesystem();
Waf_Constants::define_waf_directory();
global $wp_filesystem;
if ( ! $wp_filesystem ) {
throw new File_System_Exception( 'Can not work without the file system being initialized.' );
}
if ( ! $wp_filesystem->is_dir( JETPACK_WAF_DIR ) ) {
if ( ! $wp_filesystem->mkdir( JETPACK_WAF_DIR ) ) {
throw new File_System_Exception( 'Failed creating WAF file directory: ' . JETPACK_WAF_DIR );
}
}
}
/**
* Create the log table when plugin is activated.
*
* @return void
*/
public static function create_blocklog_table() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "
CREATE TABLE {$wpdb->prefix}jetpack_waf_blocklog (
log_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
timestamp datetime NOT NULL,
rule_id BIGINT NOT NULL,
reason longtext NOT NULL,
PRIMARY KEY (log_id),
KEY timestamp (timestamp)
)
";
dbDelta( $sql );
}
/**
* Deactivates the WAF by deleting the relevant options and emptying rules file.
*
* @throws File_System_Exception If file writing fails.
*
* @return void
*/
public static function deactivate() {
delete_option( self::MODE_OPTION_NAME );
delete_option( Waf_Rules_Manager::VERSION_OPTION_NAME );
global $wp_filesystem;
self::initialize_filesystem();
// If the rules file doesn't exist, there's nothing else to do.
if ( ! $wp_filesystem->exists( self::get_waf_file_path( Waf_Rules_Manager::RULES_ENTRYPOINT_FILE ) ) ) {
return;
}
// Empty the rules entrypoint file.
if ( ! $wp_filesystem->put_contents( self::get_waf_file_path( Waf_Rules_Manager::RULES_ENTRYPOINT_FILE ), "generate();
}
/**
* Check if an automatic rules file is available
*
* @return bool False if an automatic rules file is not available, true otherwise
*/
public static function automatic_rules_available() {
$automatic_rules_last_updated = get_option( Waf_Rules_Manager::AUTOMATIC_RULES_LAST_UPDATED_OPTION_NAME );
// If we do not have a automatic rules last updated timestamp cached, return false.
if ( ! $automatic_rules_last_updated ) {
return false;
}
// Validate that the automatic rules file exists and is not empty.
global $wp_filesystem;
try {
self::initialize_filesystem();
} catch ( Waf_Exception $e ) {
return false;
}
$automatic_rules_file_contents = $wp_filesystem->get_contents( self::get_waf_file_path( Waf_Rules_Manager::AUTOMATIC_RULES_FILE ) );
// If the automatic rules file was removed or is now empty, return false.
if ( ! $automatic_rules_file_contents || "
Fatal error: Uncaught Error: Class "Automattic\Jetpack\Waf\Waf_Runner" not found in /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/src/class-waf-initializer.php:215
Stack trace:
#0 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-includes/class-wp-hook.php(326): Automattic\Jetpack\Waf\Waf_Initializer::remove_module_on_unsupported_environments()
#1 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#2 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-modules.php(311): apply_filters()
#3 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-modules.php(211): Automattic\Jetpack\Modules->get_available()
#4 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-modules.php(32): Automattic\Jetpack\Modules->get_active()
#5 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/src/class-brute-force-protection.php(206): Automattic\Jetpack\Modules->is_active()
#6 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/src/class-brute-force-protection.php(166): Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection::is_enabled()
#7 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/src/class-waf-initializer.php(56): Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection::initialize()
#8 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(315): Automattic\Jetpack\Waf\Waf_Initializer::init()
#9 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(217): Automattic\Jetpack\Config->enable_waf()
#10 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(149): Automattic\Jetpack\Config->ensure_feature()
#11 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-includes/class-wp-hook.php(324): Automattic\Jetpack\Config->on_plugins_loaded()
#12 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#13 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-includes/plugin.php(517): WP_Hook->do_action()
#14 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-settings.php(550): do_action()
#15 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-config.php(87): require_once('...')
#16 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-load.php(50): require_once('...')
#17 /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-blog-header.php(13): require_once('...')
#18 /var/www/vhosts/casainfotech.co.nz/httpdocs/index.php(17): require('...')
#19 {main}
thrown in /var/www/vhosts/casainfotech.co.nz/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/src/class-waf-initializer.php on line 215