inc/record.inc.php
changeset 8 47dd15d8bb8c
parent 5 ebf8868e99f5
child 13 2ff220cfde13
equal deleted inserted replaced
7:ac0ca51809b1 8:47dd15d8bb8c
    44 	 * NOTICE: This function will allow only 100 DNS zone transfers ;-)
    44 	 * NOTICE: This function will allow only 100 DNS zone transfers ;-)
    45 	 * YYYYMMDDnn
    45 	 * YYYYMMDDnn
    46 	 */
    46 	 */
    47 
    47 
    48 	$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '".$domain_id."'";
    48 	$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '".$domain_id."'";
    49 	$notified_serial = $db->getOne($sqlq);
    49 	$notified_serial = $db->queryOne($sqlq);
    50 
    50 
    51 	$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '".$domain_id."'";
    51 	$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '".$domain_id."'";
    52 	$content = $db->getOne($sqlq);
    52 	$content = $db->queryOne($sqlq);
    53     $need_to_update = false;
    53     $need_to_update = false;
    54 	
    54 	
    55 	// Getting the serial field.
    55 	// Getting the serial field.
    56 	$soa = explode(" ", $content);
    56 	$soa = explode(" ", $content);
    57 	
    57 	
   169 	{
   169 	{
   170 		error(ERR_RECORD_ACCESS_DENIED);
   170 		error(ERR_RECORD_ACCESS_DENIED);
   171 	}
   171 	}
   172 	if (is_numeric($zoneid))
   172 	if (is_numeric($zoneid))
   173 	{
   173 	{
   174 
       
   175 		// Get the Insert ID, we can not rely on auto_increment
       
   176 		$idrecords = $db->nextID('records');
       
   177 
       
   178 		// Check the user input.
   174 		// Check the user input.
   179 		validate_input($idrecords, $zoneid, $type, $content, $name, $prio, $ttl);
   175 		validate_input($zoneid, $type, $content, $name, $prio, $ttl);
   180 
   176 
   181 		// Generate new timestamp for the Daemon
   177 		// Generate new timestamp for the daemon
   182 		$change = time();
   178 		$change = time();
       
   179 		
   183 		// Execute query.
   180 		// Execute query.
   184 		$db->query("INSERT INTO records (id, domain_id, name, type, content, ttl, prio, change_date) VALUES ($idrecords, $zoneid, '$name', '$type', '$content', $ttl, '$prio', $change)");
   181 		$db->query("INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ($zoneid, '$name', '$type', '$content', $ttl, '$prio', $change)");
   185 		if ($type != 'SOA')
   182 		if ($type != 'SOA')
   186 		{
   183 		{
   187 			update_soa_serial($zoneid);
   184 			update_soa_serial($zoneid);
   188 		}
   185 		}
   189 		return true;
   186 		return true;
   268 	// the domain is an arpa record and owner is given
   265 	// the domain is an arpa record and owner is given
   269 	// THAN
   266 	// THAN
   270 	// Continue this function
   267 	// Continue this function
   271 	if (($domain && $owner && $webip && $mailip) || ($empty && $owner && $domain) || (eregi('in-addr.arpa', $domain) && $owner))
   268 	if (($domain && $owner && $webip && $mailip) || ($empty && $owner && $domain) || (eregi('in-addr.arpa', $domain) && $owner))
   272 	{
   269 	{
   273 		// Retrieve next zones id.
   270                 
   274 		$idzones = $db->nextID('zones');
   271                 // First insert zone into domain table
   275 		$iddomains = $db->nextID('domains');
   272                 $db->query("INSERT INTO domains (name, type) VALUES ('$domain', '$type')");
   276 
   273 
   277 		$db->query("INSERT INTO zones (id, domain_id, owner) VALUES ('$idzones', '$iddomains', $owner)");
   274                 // Determine id of insert zone (in other words, find domain_id)
   278 
   275                 $iddomain = $db->lastInsertId('domains', 'id');
   279 		/*
   276                 if (PEAR::isError($iddomain)) {
   280 		 * TODO : NATIVE OPERATION ONLY FOR NOW
   277                         die($id->getMessage());
   281 		 */
   278                 }
   282 
   279 
   283 		$db->query("INSERT INTO domains (id, name, type) VALUES ('$iddomains', '$domain', '$type')");
   280                 // Second, insert into zones tables
   284 
   281                 $db->query("INSERT INTO zones (domain_id, owner) VALUES ('$iddomain', $owner)");
   285 		// Generate new timestamp. We need this one anyhow.
   282 
   286 		$now = time();
   283                 // Generate new timestamp. We need this one anyhow.
   287 
   284                 $now = time();
   288 		if ($empty && $iddomains)
   285 
   289 		{
   286 		if ($empty && $iddomain)
   290 			// If we come into this if statement we dont want to apply templates.
   287 		{
   291 			// Retrieve configuration settings.
   288                         // If we come into this if statement we dont want to apply templates.
   292 			$ns1 = $GLOBALS["NS1"];
   289                         // Retrieve configuration settings.
   293 			$hm  = $GLOBALS["HOSTMASTER"];
   290                         $ns1 = $GLOBALS["NS1"];
   294 			$ttl = $GLOBALS["DEFAULT_TTL"];
   291                         $hm  = $GLOBALS["HOSTMASTER"];
   295 
   292                         $ttl = $GLOBALS["DEFAULT_TTL"];
   296 			// Retrieve next records id
   293 
   297 			$idrecords = $db->nextID('records');
   294                         // Build and execute query
   298 
   295                         $sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$domain', '$ns1 $hm 1', 'SOA', $ttl, '', '$now')";
   299 			// Build and execute query
   296                         $db->query($sql);
   300 			$sql = "INSERT INTO records (id, domain_id, name, content, type, ttl, prio, change_date) VALUES ('$idrecords', '$iddomains', '$domain', '$ns1 $hm 1', 'SOA', $ttl, '', '$now')";
   297 
   301 			$db->query($sql);
   298                         // Done
   302 
   299                         return true;
   303 			// Done
   300 		}
   304 			return true;
   301 		elseif ($iddomain)
   305 		}
       
   306 		elseif ($iddomains)
       
   307 		{
   302 		{
   308 			// If we are here we want to apply templates.
   303 			// If we are here we want to apply templates.
   309 			global $template;
   304 			global $template;
   310 
   305 
   311 			// Iterate over the template and apply it for each field.
   306 			// Iterate over the template and apply it for each field.
   325 					if (!$ttl)
   320 					if (!$ttl)
   326 					{
   321 					{
   327 						$ttl = $GLOBALS["DEFAULT_TTL"];
   322 						$ttl = $GLOBALS["DEFAULT_TTL"];
   328 					}
   323 					}
   329 
   324 
   330 					// Retrieve new record id;
   325 					$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$name','$content','$type','$ttl','$prio','$now')";
   331 					$idrecords = $db->nextID('records');
       
   332 					$sql = "INSERT INTO records (id, domain_id, name, content, type, ttl, prio, change_date) VALUES ('$idrecords', '$iddomains', '$name','$content','$type','$ttl','$prio','$now')";
       
   333 					$db->query($sql);
   326 					$db->query($sql);
   334 				}
   327 				}
   335 			}
   328 			}
   336 			// All done.
   329 			// All done.
   337 			return true;
   330 			return true;
   463 		error(ERR_LEVEL_5);
   456 		error(ERR_LEVEL_5);
   464 	}
   457 	}
   465 
   458 
   466 	if (is_numeric($domain) && is_numeric($newowner) && is_valid_user($newowner))
   459 	if (is_numeric($domain) && is_numeric($newowner) && is_valid_user($newowner))
   467 	{
   460 	{
   468 		$iid = $db->nextID('zones');
   461 		if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$newowner AND domain_id=$domain") == 0)
   469 		if($db->getOne("SELECT COUNT(id) FROM zones WHERE owner=$newowner AND domain_id=$domain") == 0)
   462 		{
   470 		{
   463 			$db->query("INSERT INTO zones (domain_id, owner) VALUES($domain, $newowner)");
   471 			$db->query("INSERT INTO zones(id, domain_id, owner) VALUES($iid, $domain, $newowner)");
       
   472 		}
   464 		}
   473 		return true;
   465 		return true;
   474 	}
   466 	}
   475 	else
   467 	else
   476 	{
   468 	{
   480 
   472 
   481 
   473 
   482 function delete_owner($domain, $owner)
   474 function delete_owner($domain, $owner)
   483 {
   475 {
   484 	global $db;
   476 	global $db;
   485 	if($db->getOne("SELECT COUNT(id) FROM zones WHERE owner=$owner AND domain_id=$domain") != 0)
   477 	if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$owner AND domain_id=$domain") != 0)
   486 	{
   478 	{
   487 		$db->query("DELETE FROM zones WHERE owner=$owner AND domain_id=$domain");
   479 		$db->query("DELETE FROM zones WHERE owner=$owner AND domain_id=$domain");
   488 	}
   480 	}
   489 	return true;
   481 	return true;
   490 }
   482 }
   653 	AND records.domain_id = ".$id."
   645 	AND records.domain_id = ".$id."
   654 
   646 
   655 	GROUP BY name, owner, users.fullname
   647 	GROUP BY name, owner, users.fullname
   656 	ORDER BY name";
   648 	ORDER BY name";
   657 	
   649 	
   658 	$result = $db->getRow($sqlq);
   650 	$result = $db->queryRow($sqlq);
   659 
   651 
   660 	$ret = array(
   652 	$ret = array(
   661 	"name"          =>              $result["name"],
   653 	"name"          =>              $result["name"],
   662 	"ownerid"       =>              $_SESSION["userid"],
   654 	"ownerid"       =>              $_SESSION["userid"],
   663 	"owner"         =>              $result["owner"],
   655 	"owner"         =>              $result["owner"],
   680 			WHERE domains.id=$id
   672 			WHERE domains.id=$id
   681 			GROUP BY name, owner, users.fullname
   673 			GROUP BY name, owner, users.fullname
   682 			ORDER BY zones.id";
   674 			ORDER BY zones.id";
   683 
   675 
   684 		// Put the first occurence in an array and return it.
   676 		// Put the first occurence in an array and return it.
   685 		$result = $db->getRow($sqlq);
   677 		$result = $db->queryRow($sqlq);
   686 
   678 
   687 		//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->getOne("select min(id) from users where users.level=10") : $result["ownerid"];
   679 		//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $result["ownerid"];
   688 
   680 
   689 		$ret = array(
   681 		$ret = array(
   690 		"name"          =>              $result["name"],
   682 		"name"          =>              $result["name"],
   691 		"ownerid"       =>              $result["ownerid"],
   683 		"ownerid"       =>              $result["ownerid"],
   692 		"owner"         =>              $result["owner"],
   684 		"owner"         =>              $result["owner"],
   827 	}
   819 	}
   828 */
   820 */
   829 
   821 
   830 	while($r = $result->fetchRow())
   822 	while($r = $result->fetchRow())
   831 	{
   823 	{
   832 		$r["owner"] = ($r["owner"] == NULL) ? $db->getOne("select min(id) from users where users.level=10") : $r["owner"];
   824 		$r["owner"] = ($r["owner"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $r["owner"];
   833 	     	$ret[$r["domainname"]] = array(
   825 	     	$ret[$r["domainname"]] = array(
   834 		"name"          =>              $r["domainname"],
   826 		"name"          =>              $r["domainname"],
   835 		"id"            =>              $r["domain_id"],
   827 		"id"            =>              $r["domain_id"],
   836 		"owner"         =>              $r["owner"],
   828 		"owner"         =>              $r["owner"],
   837 		"numrec"        =>              $r["aantal"]
   829 		"numrec"        =>              $r["aantal"]
   990 
   982 
   991 
   983 
   992 function get_users_from_domain_id($id)
   984 function get_users_from_domain_id($id)
   993 {
   985 {
   994 	global $db;
   986 	global $db;
   995 	$result = $db->getCol("SELECT owner FROM zones WHERE domain_id=$id");
   987 	$result = $db->queryCol("SELECT owner FROM zones WHERE domain_id=$id");
   996 	$ret = array();
   988 	$ret = array();
   997 	foreach($result as $uid)
   989 	foreach($result as $uid)
   998 	{
   990 	{
   999 		$fullname = $db->getOne("SELECT fullname FROM users WHERE id=$uid");
   991 		$fullname = $db->queryOne("SELECT fullname FROM users WHERE id=$uid");
  1000 		$ret[] = array(
   992 		$ret[] = array(
  1001 		"id" 		=> 	$uid,
   993 		"id" 		=> 	$uid,
  1002 		"fullname"	=>	$fullname		
   994 		"fullname"	=>	$fullname		
  1003 		);		
   995 		);		
  1004 	}
   996 	}
  1103 }
  1095 }
  1104 
  1096 
  1105 function get_domain_type($id)
  1097 function get_domain_type($id)
  1106 {
  1098 {
  1107 	global $db;
  1099 	global $db;
  1108 	$type = $db->getOne("SELECT `type` FROM `domains` WHERE `id` = '".$id."'");
  1100 	$type = $db->queryOne("SELECT `type` FROM `domains` WHERE `id` = '".$id."'");
  1109 	if($type == "")
  1101 	if($type == "")
  1110 	{
  1102 	{
  1111 		$type = "NATIVE";
  1103 		$type = "NATIVE";
  1112 	}
  1104 	}
  1113 	return $type;
  1105 	return $type;