inc/dns.inc.php
changeset 121 90cab8725693
parent 119 f74e4f88b680
child 122 2e2cc9cfa115
equal deleted inserted replaced
120:982f722376b4 121:90cab8725693
   417  */
   417  */
   418 function is_valid_soa(&$content, $zoneid)
   418 function is_valid_soa(&$content, $zoneid)
   419 {
   419 {
   420 
   420 
   421 	/*
   421 	/*
   422 	 * SOA (start of authority)
       
   423 	 * there is only _ONE_ SOA record allowed in every zone.
       
   424 	 * Validate SOA record
       
   425 	 * The Start of Authority record is one of the most complex available. It specifies a lot
       
   426 	 * about a domain: the name of the master nameserver ('the primary'), the hostmaster and
       
   427 	 * a set of numbers indicating how the data in this domain expires and how often it needs
       
   428 	 * to be checked. Further more, it contains a serial number which should rise on each change
       
   429 	 * of the domain.
       
   430 	 					    2002120902 28800 7200 604800 10800
       
   431 	 * The stored format is: primary hostmaster serial refresh retry expire default_ttl
   422 	 * The stored format is: primary hostmaster serial refresh retry expire default_ttl
   432 	 * From the powerdns documentation.
       
   433 	 */
   423 	 */
   434 
   424 
   435 
       
   436 	// Check if there already is an occurence of a SOA, if so see if its not the one we are currently changing
       
   437 	$return = get_records_by_type_from_domid("SOA", $zoneid);
   425 	$return = get_records_by_type_from_domid("SOA", $zoneid);
   438 	if($return->numRows() > 1)
   426 	if($return->numRows() > 1) {
   439 	{
       
   440 		return -1;
   427 		return -1;
   441 	}
   428 	}
   442 
   429 
   443 
   430 	$soacontent = preg_split("/\s+/", $content);
   444 	$soacontent = explode(" ", $content);
   431 	debug_print($soacontent);
   445 	// Field is at least one otherwise it wouldnt even get here.
   432 	
   446 	if(is_valid_hostname($soacontent[0]))
   433 	if(is_valid_hostname($soacontent[0])) {
   447 	{
   434 
   448 		$totalsoa = $soacontent[0];
   435 		$totalsoa = $soacontent[0];
   449 		// It doesnt matter what field 2 contains, but lets check if its there
   436 		// It doesnt matter what field 2 contains, but lets check if its there
   450 		// We assume the 2nd field wont have numbers, otherwise its a TTL field
   437 		// We assume the 2nd field wont have numbers, otherwise its a TTL field
   451 		if(count($soacontent) > 1)
   438 
   452 		{
   439 		if(count($soacontent) > 1) {
   453 			if(is_numeric($soacontent[1]))
   440 			if(is_numeric($soacontent[1])) {
   454 			{
       
   455 				// its a TTL field, or at least not hostmaster or alike
   441 				// its a TTL field, or at least not hostmaster or alike
   456 				// Set final string to the default hostmaster addy
   442 				// Set final string to the default hostmaster addy
   457 				global $HOSTMASTER;
   443 				global $HOSTMASTER;
   458 				$totalsoa .= " ". $HOSTMASTER;
   444 				$totalsoa .= " ". $HOSTMASTER;
   459 			}
   445 			} else {
   460 			else
       
   461 			{
       
   462 				$totalsoa .= " ".$soacontent[1];
   446 				$totalsoa .= " ".$soacontent[1];
   463 			}
   447 			}
   464 			// For loop to iterate over the numbers
   448 			// For loop to iterate over the numbers
   465 			$imax = count($soacontent);
   449 			$imax = count($soacontent);
   466 			for($i = 2; ($i < $imax) && ($i < 7); $i++)
   450 			for($i = 2; ($i < $imax) && ($i < 7); $i++) {
   467 			{
   451 				if(!is_numeric($soacontent[$i])) {
   468 				if(!is_numeric($soacontent[$i]))
       
   469 				{
       
   470 					return -2;
   452 					return -2;
   471 				}
   453 				} else {
   472 				else
       
   473 				{
       
   474 					$totalsoa .= " ".$soacontent[$i];
   454 					$totalsoa .= " ".$soacontent[$i];
   475 				}
   455 				}
   476 			}
   456 			}
   477 			if($i > 7)
   457 			// if($i > 7) --> SOA contained too many fields, should we provide error?
   478 			{
   458 		}
   479 				error(ERR_DNS_SOA_NUMERIC_FIELDS);
   459 	} else {
   480 			}
       
   481 		}
       
   482 	}
       
   483 	else
       
   484 	{
       
   485 		error(ERR_DNS_SOA_HOSTNAME);
   460 		error(ERR_DNS_SOA_HOSTNAME);
   486 	}
   461 	}
   487 	$content = $totalsoa;
   462 	$content = $totalsoa;
   488 	return 1;
   463 	return 1;
   489 }
   464 }