inc/dns.inc.php
changeset 82 c255196bc447
parent 79 0c0aa144356a
child 94 6b4d19ef3de4
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
    41 	$nocheck = array('SOA', 'HINFO', 'NAPTR', 'URL', 'MBOXFW', 'TXT');
    41 	$nocheck = array('SOA', 'HINFO', 'NAPTR', 'URL', 'MBOXFW', 'TXT');
    42 	$hostname = false;
    42 	$hostname = false;
    43 	$ip4 = false;
    43 	$ip4 = false;
    44 	$ip6 = false;
    44 	$ip6 = false;
    45 
    45 
    46 	if(!in_array(strtoupper($type), $nocheck))
    46 	if(!in_array(strtoupper($type), $nocheck)) {
    47 	{
    47 		if(!is_valid_ip6($content)) {
    48 
    48 			if(!is_valid_ip($content)) {
    49 		if(!is_valid_ip6($content))
    49 				if(!is_valid_hostname($content)) {
    50 		{
       
    51 			if(!is_valid_ip($content))
       
    52 			{
       
    53 				if(!is_valid_hostname($content))
       
    54 				{
       
    55 					error(ERR_DNS_CONTENT);
    50 					error(ERR_DNS_CONTENT);
    56 				}
    51 					return false;
    57 				else
    52 				} else {
    58 				{
       
    59 					$hostname = true;
    53 					$hostname = true;
    60 				}
    54 				}
    61 			}
    55 			} else {
    62 			else
       
    63 			{
       
    64 				$ip4 = true;
    56 				$ip4 = true;
    65 			}
    57 			}
    66 		}
    58 		} else {
    67 		else
       
    68 		{
       
    69 			$ip6 = true;
    59 			$ip6 = true;
    70 		}
    60 		}
    71 	}
    61 	}
    72 
    62 
    73 	// Prepare total hostname.
    63 	// Prepare total hostname.
    74 
    64 
    75 	if($name == '*')
    65 	if ($name == '*') {
    76 	{
       
    77 		$wildcard = true;
    66 		$wildcard = true;
    78 	} else {
    67 	} else {
    79 		$wildcard = false;
    68 		$wildcard = false;
    80 	}
    69 	}
    81 
    70 
    82 	if ($name=="0") {
    71 // TODO:	Needs to be checked what this is good for. Since we started insert an array
    83 	   $name=$name.".".$domain;
    72 //		in functions like edit_record, "name"'s like "sub-fqdn.example.net" became 
    84 	} else {
    73 //		"sub-fqdn.example.net.example.net". 
    85 	   $name = ($name) ? $name.".".$domain : $domain;
    74 //	if ($name=="0") {
    86 	}
    75 //		$name=$name.".".$domain;
       
    76 //	} else {
       
    77 //		$name = ($name) ? $name.".".$domain : $domain;
       
    78 //	}
    87 
    79 
    88 	if (preg_match('!@\.!i', $name))
    80 	if (preg_match('!@\.!i', $name))
    89 	{
    81 	{
    90 		$name = str_replace('@.', '@', $name);
    82 		$name = str_replace('@.', '@', $name);
    91 	}
    83 	}
    92 
    84 	if(!$wildcard) {
    93 	if(!$wildcard)
    85 		if(!is_valid_hostname($name)) {
    94 	{
       
    95 		if(!is_valid_hostname($name))
       
    96 		{
       
    97 			error(ERR_DNS_HOSTNAME);
    86 			error(ERR_DNS_HOSTNAME);
       
    87 			return false;
    98 		}
    88 		}
    99 	}
    89 	}
   100 
    90 
   101 	// Check record type (if it exists in our allowed list.
    91 	// Check record type (if it exists in our allowed list.
   102 	if (!in_array(strtoupper($type), get_record_types()))
    92 	if (!in_array(strtoupper($type), get_record_types())) {
   103 	{
       
   104 		error(ERR_DNS_RECORDTYPE);
    93 		error(ERR_DNS_RECORDTYPE);
       
    94 		return false;
   105 	}
    95 	}
   106 
    96 
   107 	// Start handling the demands for the functions.
    97 	// Start handling the demands for the functions.
   108 	// Validation for IN A records. Can only have an IP. Nothing else.
    98 	// Validation for IN A records. Can only have an IP. Nothing else.
   109 	if ($type == 'A' && !$ip4)
    99 	if ($type == 'A' && !$ip4) {
   110 	{
       
   111 		error(ERR_DNS_IPV4);
   100 		error(ERR_DNS_IPV4);
   112 	}
   101 		return false;
   113 
   102 	}
   114 	if ($type == 'AAAA' && !$ip6)
   103 
   115 	{
   104 	if ($type == 'AAAA' && !$ip6) {
   116 		error(ERR_DNS_IPV6);
   105 		error(ERR_DNS_IPV6);
   117 	}
   106 		return false;
   118 
   107 	}
   119 	if ($type == 'CNAME' && $hostname)
   108 
   120 	{
   109 	if ($type == 'CNAME' && $hostname) {
   121 		if(!is_valid_cname($name))
   110 		if(!is_valid_cname($name)) {
   122 		{
       
   123 			error(ERR_DNS_CNAME);
   111 			error(ERR_DNS_CNAME);
   124 		}
   112 			return false;
   125 	}
   113 		}
   126 
   114 	}
   127 	if ($type == 'NS')
   115 
   128 	{
   116 	if ($type == 'NS') {
   129 		$status = is_valid_ns($content, $hostname);
   117 		$status = is_valid_ns($content, $hostname);
   130 		if($status == -1)
   118 		if($status == -1) {
   131 		{
       
   132 			error(ERR_DNS_NS_HNAME);
   119 			error(ERR_DNS_NS_HNAME);
   133 		}
   120 			return false;
   134 		elseif($status == -2)
   121 		}
   135 		{
   122 		elseif($status == -2) {
   136 			error(ERR_DNS_NS_CNAME);
   123 			error(ERR_DNS_NS_CNAME);
   137 		}
   124 			return false;
   138 		// Otherwise its ok
   125 		}
   139 	}
   126 	}
   140 
   127 
   141 	if ($type == 'SOA')
   128 	if ($type == 'SOA') {
   142 	{
       
   143 		$status = is_valid_soa($content, $zoneid);
   129 		$status = is_valid_soa($content, $zoneid);
   144 		if($status == -1)
   130 		if($status == -1) {
   145 		{
       
   146 			error(ERR_DNS_SOA_UNIQUE);
   131 			error(ERR_DNS_SOA_UNIQUE);
   147 			// Make nicer error
   132 		} elseif($status == -2) {
   148 		}
       
   149 		elseif($status == -2)
       
   150 		{
       
   151 			error(ERR_DNS_SOA_NUMERIC);
   133 			error(ERR_DNS_SOA_NUMERIC);
       
   134 			return false;
   152 		}
   135 		}
   153 	}
   136 	}
   154 
   137 
   155 	// HINFO and TXT require no validation.
   138 	// HINFO and TXT require no validation.
   156 
   139 
   157 	if ($type == 'URL')
   140 	if ($type == 'URL') {
   158 	{
   141 		if(!is_valid_url($content)) {
   159 		if(!is_valid_url($content))
       
   160 		{
       
   161 			error(ERR_INV_URL);
   142 			error(ERR_INV_URL);
   162 		}
   143 			return false;
   163 	}
   144 		}
   164 	if ($type == 'MBOXFW')
   145 	}
   165 	{
   146 	if ($type == 'MBOXFW') 	{
   166 		if(!is_valid_mboxfw($content))
   147 		if(!is_valid_mboxfw($content)) {
   167 		{
       
   168 			error(ERR_INV_EMAIL);
   148 			error(ERR_INV_EMAIL);
       
   149 			return false;
   169 		}
   150 		}
   170 	}
   151 	}
   171 
   152 
   172 	// NAPTR has to be done.
   153 	// NAPTR has to be done.
   173 	// Do we want that?
   154 	// Do we want that?
   175 	// http://www.zvon.org/tmRFC/RFC2915/Output/chapter2.html
   156 	// http://www.zvon.org/tmRFC/RFC2915/Output/chapter2.html
   176 	// http://www.zvon.org/tmRFC/RFC3403/Output/chapter4.html
   157 	// http://www.zvon.org/tmRFC/RFC3403/Output/chapter4.html
   177 
   158 
   178 	// See if the prio field is valid and if we have one.
   159 	// See if the prio field is valid and if we have one.
   179 	// If we dont have one and the type is MX record, give it value '10'
   160 	// If we dont have one and the type is MX record, give it value '10'
   180 	if($type == 'NAPTR')
   161 	if($type == 'NAPTR') {
   181 	{
       
   182 
   162 
   183 	}
   163 	}
   184 	
   164 	
   185 	if($type == 'MX')
   165 	if($type == 'MX') {
   186 	{
   166 		if($hostname) {
   187 		if($hostname)
       
   188 		{
       
   189 			$status = is_valid_mx($content, $prio);
   167 			$status = is_valid_mx($content, $prio);
   190 			if($status == -1)
   168 			if($status == -1) {
   191 			{
       
   192 				error(ERR_DNS_MX_CNAME);
   169 				error(ERR_DNS_MX_CNAME);
   193 			}
   170 				return false;
   194 			elseif($status == -2)
   171 			}
   195 			{
   172 			elseif($status == -2) {
   196 				error(ERR_DNS_MX_PRIO);
   173 				error(ERR_DNS_MX_PRIO);
   197 			}
   174 				return false;
   198 		}
   175 			}
   199 		else
   176 		} else {
   200 		{
   177 			error( _('If you specify an MX record it must be a hostname.') ); // TODO make error
   201 			error( _('If you specify an MX record it must be a hostname.') );
   178 			return false;
   202 		}
   179 		}
   203 	}
   180 	} else {
   204 	else
       
   205 	{
       
   206 		$prio=0;
   181 		$prio=0;
   207 	}
   182 	}
   208 	// Validate the TTL, it has to be numeric.
   183 	// Validate the TTL, it has to be numeric.
   209 	$ttl = (!isset($ttl) || !is_numeric($ttl)) ? $DEFAULT_TTL : $ttl;
   184 	$ttl = (!isset($ttl) || !is_numeric($ttl)) ? $DEFAULT_TTL : $ttl;
       
   185 	
       
   186 	return true;
   210 }
   187 }
   211 
   188 
   212 
   189 
   213 
   190 
   214 		/****************************************
   191 		/****************************************