Exemplo n.º 1
0
/**
 * Process the requests sent by the form submissions originated in the firewall
 * page, all forms must have a nonce field that will be checked against the one
 * generated in the template render function.
 *
 * @return void
 */
function sucuriscan_firewall_form_submissions($nonce)
{
    if ($nonce) {
        // Add and/or Update the Sucuri WAF API Key (do it before anything else).
        $option_name = ':cloudproxy_apikey';
        $api_key = SucuriScanRequest::post($option_name);
        if ($api_key !== false) {
            $api_key = trim($api_key);
            if (SucuriScanAPI::isValidCloudproxyKey($api_key)) {
                SucuriScanOption::update_option($option_name, $api_key);
                SucuriScanInterface::info('CloudProxy API key saved successfully');
                SucuriScanOption::setRevProxy('enable');
                SucuriScanOption::setAddrHeader('HTTP_X_SUCURI_CLIENTIP');
            } else {
                SucuriScanInterface::error('Invalid CloudProxy API key.');
            }
        }
        // Delete CloudProxy API key from the plugin.
        if (SucuriScanRequest::post(':delete_wafkey') !== false) {
            SucuriScanOption::delete_option($option_name);
            SucuriScanInterface::info('CloudProxy API key removed successfully');
            SucuriScanOption::setRevProxy('disable');
            SucuriScanOption::setAddrHeader('REMOTE_ADDR');
        }
    }
}