You are here

function hosting_web_server_validate in Hosting 5

Implementation of hook_validate().

File

web_server/hosting_web_server.module, line 267
Web server node type is defined here.

Code

function hosting_web_server_validate(&$node, &$form) {
  if ($node->script_user == 'root') {
    form_set_error('script_user', t('For security reasons, you should not run drush commands as the root user. Please choose a different system account name.'));
  }
  if (!$node->ip_address) {
    if (!_hosting_valid_fqdn($node->title)) {
      form_set_error('title', t('Invalid valid domain name. Either choose a proper domain name or hardcode the IP address of the webserver.'));
    }
    $ip = gethostbyname($node->title);

    // setup IP only if resolution succeeded
    if ($ip != $node->title) {
      form_set_value($form['ip_address'], $ip);
      $node->ip_address = $ip;

      // required to fool the ip check below
      drupal_set_message(t('Initialized the webserver IP to %ip based on hostname %name', array(
        '%ip' => $ip,
        '%name' => $node->title,
      )), 'message');
    }
    else {
      form_set_error('title', t('Could not resolve IP address of webserver %name. Either set the web server name to a FQDN (Fully Qualified Domain Name) or hardcode the IP here.', array(
        '%name' => $node->title,
      )));
    }
  }
  if (!_hosting_valid_ip($node->ip_address)) {
    form_set_error('ip_address', t('Invalid IP address'));
  }
}