You are here

function _hosting_ip_validate in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 server/hosting.ip.inc \_hosting_ip_validate()

Validate that IP list is valid. IP utility function for hook_validate.

1 call to _hosting_ip_validate()
hosting_server_validate in server/hosting_server.module
Implements hook_validate().

File

server/hosting.ip.inc, line 63
General IP address CRUD routines.

Code

function _hosting_ip_validate($node) {
  $ips = isset($node->ip_addresses) ? $node->ip_addresses : array();
  foreach ($ips as $id => $ip) {
    $ip = trim($ip);
    if (empty($ip)) {

      // deletion, look if the IP is in use
      $cid = db_query('SELECT ssl_key FROM {hosting_ssl_cert_ips} i INNER JOIN {hosting_ssl_cert} c ON c.cid = i.cid WHERE ip_address = :id', array(
        ':id' => $id,
      ))
        ->fetchField();
      if ($cid) {
        form_set_error("ip_addresses][{$id}", t('Cannot remove IP associated with certificate %cert.', array(
          '%cert' => $cid,
        )));
      }
    }
    elseif (!_hosting_valid_ip($ip)) {
      form_set_error("ip_addresses][{$id}", t('Invalid IP address: %ip.', array(
        '%ip' => $ip,
      )));
    }
  }
  $ips = isset($node->new_ip_addresses) ? (array) $node->new_ip_addresses : array();
  foreach ($ips as $id => $ip) {
    if (!empty($ip) && !_hosting_valid_ip($ip)) {
      form_set_error("ip_addresses][{$id}", t('Invalid IP address: %ip.', array(
        '%ip' => $ip,
      )));
    }
  }
}