You are here

function httpbl_admin_settings_validate in http:BL 7

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. 6 httpbl.module \httpbl_admin_settings_validate()

Form API callback to validate the httpbl settings form.

File

./httpbl.admin.inc, line 178
Admin functions for httpbl.

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().
    // ereg is deprecated.  Now using preg_grep instead?
    if (preg_grep('/[^a-z]/', array(
      $key,
    )) || strlen($key) != 12) {
      form_set_error('httpbl_accesskey', t('Your access key is formatted incorrectly.'));
    }
    elseif (!count(form_get_errors())) {

      // Do a test lookup (with known result).
      // Not sure we are really testing a valid key?
      $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(t('Http:BL test completed successfully.'));
      }
    }
  }
}