function hosting_ip_validate in Hosting 6.2
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 - Implementation of hook_validate().
File
- server/
hosting.ip.inc, line 50 - General IP address CRUD routines.
Code
function hosting_ip_validate($node) {
$ips = is_array($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
if ($cid = db_result(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 = %d', $id))) {
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,
)));
}
}
}