function validate_ip_range_range($ip_range) { $parts = explode('-', $ip_range); if (2 < ($parts_count = count($parts))) { return false; } if (validate_ipv4($parts[0], $arr)) { $ip_parts = explode('.', $parts[0]); if ($parts_count == 2) { if (!ereg('^[0-9]{1,3}$', $parts[1])) { return false; } sscanf($ip_parts[3], "%d", $from_value); sscanf($parts[1], "%d", $to_value); if ($to_value > 255 || $from_value > $to_value) { return false; } } } else { if (defined('ZBX_HAVE_IPV6') && validate_ipv6($parts[0], $arr)) { $ip_parts = explode(':', $parts[0]); $ip_parts_count = count($ip_parts); if ($parts_count == 2) { if (!ereg('^[A-Fa-f0-9]{1,4}$', $parts[1])) { return false; } sscanf($ip_parts[$ip_parts_count - 1], "%x", $from_value); sscanf($parts[1], "%x", $to_value); if ($from_value > $to_value) { return false; } } } else { return false; } } return true; }
function verify_record($name, $type, $address, $distance, $weight, $port, $ttl) { // convert type to single character format $type = set_type($type); // Make sure name was given for non A and MX records if ($type != 'A' && $type != 'M' && $name == "") { return "no Hostname supplied"; } // verify A record if ($type == 'A') { if (validate_ip($address) == FALSE) { return "\"{$address}\" is not a valid A record address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid A record name"; } } if ($type == '=') { if (validate_ip($address) == FALSE) { return "\"{$address}\" is not a valid A+PTR record address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid A+PTR record name"; } } // verify AAAA record if ($type == '3') { if (validate_ipv6($address) == FALSE) { return "\"{$address}\" is not a valid AAAA record address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid AAAA record name"; } } // verify AAAA+PTR record if ($type == '6') { if (validate_ipv6($address) == FALSE) { return "\"{$address}\" is not a valid AAAA+PTR record address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid AAAA+PTR record name"; } } // verify NS record if ($type == 'N') { if (validate_ip($address) != FALSE) { return "\"{$address}\" should not be an IP address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid NS record name"; } } // verify MX record if ($type == 'M') { if (validate_ip($name)) { return "MX records can not be an IP address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid MX record name"; } if (!preg_match('/^([0-9])+$/i', $distance)) { return "\"{$distance}\" is not a valid MX distance"; } } // verify PTR if ($type == 'P') { if (!preg_match('/^.*\\.in-addr.arpa\\.*$/i', $name) && !preg_match('/^.*\\.ip6.arpa\\.*$/i', $name)) { return "PTR \"{$name}\" does not end in .in-addr.arpa or ip6.arpa."; } } // verify CNAME record if ($type == 'C') { if (validate_ip($address)) { return "CNAME records can not point to an IP address"; } if (check_domain_name_format($name) == FALSE) { return "\"{$name}\" is not a valid CNAME record name"; } if (validate_domain_name($address) == FALSE) { return "\"{$address}\" is not a valid CNAME record address"; } } // verify SRV record if ($type == 'V') { if (!preg_match('/^_.*\\._.*$/i', $name)) { return "SRV \"{$name}\" should be in the format _service._protocol"; } if ($distance > 65535 || !preg_match('/^([0-9])+$/i', $distance)) { return "SRV distance must be a numeric value between 0 and 65535"; } if ($weight > 65535 || !preg_match('/^([0-9])+$/i', $weight)) { return "SRV weight must be a numeric value between 0 and 65535"; } if ($port > 65535 || !preg_match('/^([0-9])+$/i', $port)) { return "SRV port must be a numeric value between 0 and 65535"; } } // make sure a TTL was given if ($ttl == "") { return "no TTL given"; } return 'OK'; }
function validate_ip_range_range($ip_range) { $parts = explode('-', $ip_range); if (($parts_count = count($parts)) > 2) { return false; } if (validate_ipv4($parts[0], $arr)) { $ip_parts = explode('.', $parts[0]); if ($parts_count == 2) { if (!preg_match('/^([0-9]{1,3})$/', $parts[1])) { return false; } sscanf($ip_parts[3], "%d", $from_value); sscanf($parts[1], "%d", $to_value); if ($to_value > 255 || $from_value > $to_value) { return false; } } } elseif (ZBX_HAVE_IPV6 && validate_ipv6($parts[0])) { $ip_parts = explode(':', $parts[0]); $ip_parts_count = count($ip_parts); if ($parts_count == 2) { if (!preg_match('/^([a-f0-9]{1,4})$/i', $parts[1])) { return false; } sscanf($ip_parts[$ip_parts_count - 1], "%x", $from_value); sscanf($parts[1], "%x", $to_value); if ($from_value > $to_value) { return false; } } } else { return false; } return true; }