Beispiel #1
0
/**
 * Read and parse the content of the general settings template.
 *
 * @return string Parsed HTML code for the general settings panel.
 */
function sucuriscan_settings_general()
{
    global $sucuriscan_emails_per_hour, $sucuriscan_maximum_failed_logins, $sucuriscan_verify_ssl_cert;
    // Check the nonce here to populate the value through other functions.
    $page_nonce = SucuriScanInterface::check_nonce();
    // Process all form submissions.
    sucuriscan_settings_form_submissions($page_nonce);
    // Register the site, get its API key, and store it locally for future usage.
    $api_registered_modal = '';
    // Whether the form to manually add the API key should be shown or not.
    $display_manual_key_form = (bool) (SucuriScanRequest::post(':recover_key') !== false);
    if ($page_nonce && SucuriScanRequest::post(':plugin_api_key') !== false) {
        $registered = SucuriScanAPI::register_site();
        if ($registered) {
            $api_registered_modal = SucuriScanTemplate::get_modal('settings-apiregistered', array('Title' => 'Site registered successfully', 'CssClass' => 'sucuriscan-apikey-registered'));
        } else {
            $display_manual_key_form = true;
        }
    }
    // Get initial variables to decide some things bellow.
    $api_key = SucuriScanAPI::get_plugin_key();
    $emails_per_hour = SucuriScanOption::get_option(':emails_per_hour');
    $maximum_failed_logins = SucuriScanOption::get_option(':maximum_failed_logins');
    $verify_ssl_cert = SucuriScanOption::get_option(':verify_ssl_cert');
    $audit_report = SucuriScanOption::get_option(':audit_report');
    $logs4report = SucuriScanOption::get_option(':logs4report');
    $revproxy = SucuriScanOption::get_option(':revproxy');
    $invalid_domain = false;
    // Check whether the domain name is valid or not.
    if (!$api_key) {
        $clean_domain = SucuriScan::get_top_level_domain();
        $domain_address = @gethostbyname($clean_domain);
        $invalid_domain = $domain_address == $clean_domain ? true : false;
    }
    // Generate the HTML code for the option list in the form select fields.
    $emails_per_hour_options = SucuriScanTemplate::get_select_options($sucuriscan_emails_per_hour, $emails_per_hour);
    $maximum_failed_logins_options = SucuriScanTemplate::get_select_options($sucuriscan_maximum_failed_logins, $maximum_failed_logins);
    $verify_ssl_cert_options = SucuriScanTemplate::get_select_options($sucuriscan_verify_ssl_cert, $verify_ssl_cert);
    $template_variables = array('APIKey' => !$api_key ? '<em>(not set)</em>' : $api_key, 'APIKey.RecoverVisibility' => SucuriScanTemplate::visibility(!$api_key && !$display_manual_key_form), 'APIKey.ManualKeyFormVisibility' => SucuriScanTemplate::visibility($display_manual_key_form), 'APIKey.RemoveVisibility' => SucuriScanTemplate::visibility((bool) $api_key), 'InvalidDomainVisibility' => SucuriScanTemplate::visibility($invalid_domain), 'NotifyTo' => SucuriScanOption::get_option(':notify_to'), 'EmailsPerHour' => 'Undefined', 'EmailsPerHourOptions' => $emails_per_hour_options, 'MaximumFailedLogins' => 'Undefined', 'MaximumFailedLoginsOptions' => $maximum_failed_logins_options, 'VerifySSLCert' => 'Undefined', 'VerifySSLCertOptions' => $verify_ssl_cert_options, 'RequestTimeout' => SucuriScanOption::get_option(':request_timeout') . ' seconds', 'DatastorePath' => SucuriScanOption::get_option(':datastore_path'), 'CollectWrongPasswords' => 'No collect passwords', 'ModalWhenAPIRegistered' => $api_registered_modal, 'AuditReportStatus' => 'Enabled', 'AuditReportSwitchText' => 'Disable', 'AuditReportSwitchValue' => 'disable', 'AuditReportSwitchCssClass' => 'button-danger', 'AuditReportLimit' => $logs4report, 'ReverseProxyStatus' => 'Enabled', 'ReverseProxySwitchText' => 'Disable', 'ReverseProxySwitchValue' => 'disable', 'ReverseProxySwitchCssClass' => 'button-danger', 'APIProxy.Host' => 'n/a', 'APIProxy.Port' => 'n/a', 'APIProxy.Username' => 'n/a', 'APIProxy.Password' => 'n/a', 'APIProxy.PasswordType' => 'default', 'APIProxy.PasswordText' => 'empty');
    if (array_key_exists($emails_per_hour, $sucuriscan_emails_per_hour)) {
        $template_variables['EmailsPerHour'] = $sucuriscan_emails_per_hour[$emails_per_hour];
    }
    if (array_key_exists($maximum_failed_logins, $sucuriscan_maximum_failed_logins)) {
        $template_variables['MaximumFailedLogins'] = $sucuriscan_maximum_failed_logins[$maximum_failed_logins];
    }
    if (array_key_exists($verify_ssl_cert, $sucuriscan_verify_ssl_cert)) {
        $template_variables['VerifySSLCert'] = $sucuriscan_verify_ssl_cert[$verify_ssl_cert];
    }
    if ($audit_report == 'disabled') {
        $template_variables['AuditReportStatus'] = 'Disabled';
        $template_variables['AuditReportSwitchText'] = 'Enable';
        $template_variables['AuditReportSwitchValue'] = 'enable';
        $template_variables['AuditReportSwitchCssClass'] = 'button-success';
    }
    if ($revproxy == 'disabled') {
        $template_variables['ReverseProxyStatus'] = 'Disabled';
        $template_variables['ReverseProxySwitchText'] = 'Enable';
        $template_variables['ReverseProxySwitchValue'] = 'enable';
        $template_variables['ReverseProxySwitchCssClass'] = 'button-success';
    }
    if (sucuriscan_collect_wrong_passwords() === true) {
        $template_variables['CollectWrongPasswords'] = '<span class="sucuriscan-label-error">Yes, collect passwords</span>';
    }
    // Determine if the API calls with pass through a proxy or not.
    if (class_exists('WP_HTTP_Proxy')) {
        $wp_http_proxy = new WP_HTTP_Proxy();
        if ($wp_http_proxy->is_enabled()) {
            $proxy_host = SucuriScan::escape($wp_http_proxy->host());
            $proxy_port = SucuriScan::escape($wp_http_proxy->port());
            $proxy_username = SucuriScan::escape($wp_http_proxy->username());
            $proxy_password = SucuriScan::escape($wp_http_proxy->password());
            $template_variables['APIProxy.Host'] = $proxy_host;
            $template_variables['APIProxy.Port'] = $proxy_port;
            $template_variables['APIProxy.Username'] = $proxy_username;
            $template_variables['APIProxy.Password'] = $proxy_password;
            $template_variables['APIProxy.PasswordType'] = 'info';
            $template_variables['APIProxy.PasswordText'] = 'hidden';
        }
    }
    return SucuriScanTemplate::get_section('settings-general', $template_variables);
}
Beispiel #2
0
 /**
  * Display a notice message with instructions to continue the setup of the
  * plugin, this includes the generation of the API key and other steps that need
  * to be done to fully activate this plugin.
  *
  * @return void
  */
 public static function setup_notice()
 {
     if (current_user_can('manage_options') && SucuriScan::no_notices_here() === false && !SucuriScanAPI::get_plugin_key() && SucuriScanRequest::post(':plugin_api_key') === false && SucuriScanRequest::post(':recover_key') === false && !SucuriScanRequest::post(':manual_api_key')) {
         if (SucuriScanRequest::get(':dismiss_setup') !== false) {
             SucuriScanOption::update_option(':dismiss_setup', 'enabled');
         } elseif (SucuriScanOption::is_enabled(':dismiss_setup')) {
             /* Do not display API key generation form. */
         } else {
             echo SucuriScanTemplate::get_section('setup-notice');
             echo SucuriScanTemplate::get_modal('setup-form', array('Visibility' => 'hidden', 'Title' => 'Sucuri API key generation', 'CssClass' => 'sucuriscan-setup-instructions'));
         }
     }
 }
Beispiel #3
0
 /**
  * Display a notice message with instructions to continue the setup of the
  * plugin, this includes the generation of the API key and other steps that need
  * to be done to fully activate this plugin.
  *
  * @return void
  */
 public static function setup_notice()
 {
     if (current_user_can('manage_options') && SucuriScan::no_notices_here() === false && !SucuriScanAPI::get_plugin_key() && SucuriScanRequest::post(':plugin_api_key') === false && SucuriScanRequest::post(':recover_key') === false && !SucuriScanRequest::post(':manual_api_key')) {
         echo SucuriScanTemplate::get_section('setup-notice');
         echo SucuriScanTemplate::get_modal('setup-form', array('Visibility' => 'hidden', 'Title' => 'Sucuri API key generation', 'CssClass' => 'sucuriscan-setup-instructions'));
     }
 }