function cerber_acl_form_process() { if (!current_user_can('manage_options')) { return; } if (!isset($_POST['cerber_nonce']) || !wp_verify_nonce($_POST['cerber_nonce'], 'cerber_dashboard')) { return; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['add_acl_W']) && ($ip = trim($_POST['add_acl_W']))) { if (cerber_is_ip($ip) && cerber_add_white($ip)) { update_site_option('cerber_admin_message', sprintf(__('Address %s was added to White IP Access List', 'cerber'), $ip)); } } if (isset($_POST['add_acl_B']) && ($ip = trim($_POST['add_acl_B']))) { if (cerber_is_ip($ip)) { if (!cerber_is_myip($ip)) { // Protection from adding IP of current user if (cerber_add_black($ip)) { update_site_option('cerber_admin_message', sprintf(__('Address %s was added to Black IP Access List', 'cerber'), $ip)); } } else { update_site_option('cerber_admin_notice', __("You can't add your IP address", 'cerber') . ' ' . $ip); } } } } }
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()); }