function cerber_activate() { global $wpdb, $wp_version; cerber_load_lang(); if (version_compare(CERBER_REQ_PHP, phpversion(), '>')) { cerber_stop_activating('<h3>' . sprintf(__('The WP Cerber requires PHP %s or higher. You are running', 'cerber'), CERBER_REQ_PHP) . ' ' . phpversion() . '</h3>'); } if (version_compare(CERBER_REQ_WP, $wp_version, '>')) { cerber_stop_activating('<h3>' . sprintf(__('The WP Cerber requires WordPress %s or higher. You are running', 'cerber'), CERBER_REQ_WP) . ' ' . $wp_version . '</h3>'); } // Tables $db_errors = array(); if (!$wpdb->get_row("SHOW TABLES LIKE '" . CERBER_LOG_TABLE . "'")) { if (!$wpdb->query("\n\n\tCREATE TABLE IF NOT EXISTS " . CERBER_LOG_TABLE . " (\n `ip` varchar(39) CHARACTER SET ascii NOT NULL COMMENT 'Remote IP',\n `user_login` varchar(60) NOT NULL COMMENT 'Login from POST request',\n `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n `stamp` bigint(20) unsigned NOT NULL COMMENT 'Unix timestamp',\n `activity` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'What''s happen?',\n KEY `ip` (`ip`)\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Cerber actions log';\n\n\n\t\t\t\t")) { $db_errors[] = $wpdb->last_error; } } if (!$wpdb->get_row("SHOW TABLES LIKE '" . CERBER_ACL_TABLE . "'")) { if (!$wpdb->query("\n\n\tCREATE TABLE IF NOT EXISTS " . CERBER_ACL_TABLE . " (\n `ip` varchar(39) CHARACTER SET ascii NOT NULL COMMENT 'IP',\n `tag` char(1) NOT NULL COMMENT 'Type: B or W',\n `comments` varchar(250) NOT NULL,\n UNIQUE KEY `ip` (`ip`)\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Cerber IP access lists';\n\n\t\t\t\t")) { $db_errors[] = $wpdb->last_error; } } if (!$wpdb->get_row("SHOW TABLES LIKE '" . CERBER_BLOCKS_TABLE . "'")) { if (!$wpdb->query("\n\n\tCREATE TABLE IF NOT EXISTS " . CERBER_BLOCKS_TABLE . " (\n `ip` varchar(39) CHARACTER SET ascii NOT NULL COMMENT 'Remote IP',\n `block_until` bigint(20) unsigned NOT NULL COMMENT 'Unix timestamp',\n `reason` varchar(250) NOT NULL COMMENT 'Why was blocked',\n UNIQUE KEY `ip` (`ip`)\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of blocked IP';\n\n\t\t\t\t")) { $db_errors[] = $wpdb->last_error; } } if ($db_errors) { cerber_stop_activating('<h3>' . __("Can't activate WP Cerber due to a database error.", 'cerber') . '</h3><p>' . implode('<p>', $db_errors)); } cerber_cookie1(); cerber_disable_citadel(); cerber_get_groove(); cerber_add_white(cerber_get_subnet(cerber_get_ip())); // Protection for non-experienced user update_site_option('cerber_admin_message', __('WP Cerber is now active and has started protecting your site.', 'cerber') . ' <a href="' . admin_url(cerber_get_opage()) . '">' . __('Check settings here', 'cerber') . '.</a>'); $opt = cerber_get_options(); $opt = array_filter($opt); if (!empty($opt)) { return; } update_site_option(CERBER_OPT, cerber_get_defaults()); }
function cerber_admin_request() { global $wpdb; if (!current_user_can('manage_options')) { return; } if ($_SERVER['REQUEST_METHOD'] != 'GET' || !isset($_GET['cerber_nonce']) || !wp_verify_nonce($_GET['cerber_nonce'], 'control')) { return; } if (isset($_GET['testnotify'])) { cerber_send_notify($_GET['testnotify']); update_site_option('cerber_admin_message', __('Message has been sent to ', 'cerber') . ' ' . get_option('admin_email')); wp_safe_redirect(remove_query_arg('testnotify')); exit; } if (isset($_GET['lockdelete'])) { $ip = $_GET['lockdelete']; if (cerber_block_delete($ip)) { update_site_option('cerber_admin_message', sprintf(__('Lockout for %s was removed', 'cerber'), $ip)); } } if (isset($_GET['citadel']) && $_GET['citadel'] == 'deactivate') { cerber_disable_citadel(); } if (isset($_GET['load_settings']) && $_GET['load_settings'] == 'default') { update_site_option(CERBER_OPT, cerber_get_defaults()); update_site_option('cerber_admin_message', __('Settings saved.')); wp_safe_redirect(remove_query_arg('load_settings')); // mandatory! exit; // mandatory! } }