You are here

function httpbl_admin_settings_validate in http:BL 6

Same name and namespace in other branches
  1. 5 httpbl.module \httpbl_admin_settings_validate()
  2. 6.2 httpbl.module \httpbl_admin_settings_validate()
  3. 7 httpbl.admin.inc \httpbl_admin_settings_validate()

Form API callback to validate the httpbl settings form.

File

./httpbl.module, line 313
Implementation of http:BL for Drupal. It provides IP-based blacklisting through http:BL and allows linking to a honeypot.

Code

function httpbl_admin_settings_validate($form, &$form_state) {
  $key = $form_state['values']['httpbl_accesskey'];
  if ($form_state['values']['httpbl_check'] && !$key) {
    form_set_error('httpbl_accesskey', t('You must enter an access key to enable blacklist checks.'));
  }
  if ($form_state['values']['httpbl_footer'] && !$form_state['values']['httpbl_link']) {
    form_set_error('httpbl_link', t('You must enter a link to be able to add it to the footer.'));
  }
  if ($key) {

    // Key should be 12 lowercase alpha characters.
    // There's no unicode allowed, so we're not using drupal_strlen().
    if (ereg('[^a-z]', $key) || strlen($key) != 12) {
      form_set_error('httpbl_accesskey', t('Your access key is formatted incorrectly.'));
    }
    else {
      if (!count(form_get_errors())) {

        // Do a test lookup (with known result).
        $lookup = httpbl_dnslookup('127.1.80.1', $key);
        if (!$lookup || $lookup['threat'] != 80) {
          form_set_error('httpbl_accesskey', t('Testcase failed. This either means that your access key is incorrect or that there is a problem in your DNS system.'));
        }
        else {
          drupal_set_message('http:BL test completed successfully.');
        }
      }
    }
  }
}