Location: PHPKode > projects > PSlash > pslash-0.70/html/domain.php
<? 

###############################################################################
# Copyright (C) 2000  Derek Leung
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# You may modify your copy or copies of this Program or any portion of it,
# but you must cause the modified files to carry prominent notices stating 
# that you changed the files and the date of any change.  And you are required 
# to keep a copy of this License along with this Program.
#
# You are not required to accept this License, since you have not signed it. 
# However, nothing else grants you permission to modify or distribute this 
# Program or its derivative works. These actions are prohibited by law if 
# you do not accept this License. Therefore, by modifying or distributing 
# this Program (or any work based on this Program), you indicate your 
# acceptance of this License to do so, and all its terms and conditions 
# for copying, distributing or modifying this Program or works based on it.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# See the GNU General Public License for more details.
# http://www.opensource.org/licenses/gpl-license.html
###############################################################################

require("mainfile.php");
global $config;

	$domainFile = $config[data_path] . "/domain.txt";
	$myArray = array();

	// we don't want any new entry go to domain and domain_log while we are updating, so we lock it.
	mysql_query("LOCK TABLES ps_domain WRITE, ps_domain_log WRITE");
	$result = mysql_query("select domain from ps_domain_log");
	// Find if any domain we need to take out of DNS server and write to the domain.txt for further processing by nsupdate.
	while (list($domain) = mysql_fetch_row($result)) {
		
		// check if it is a valid domain name
		if (preg_match("/^[a-zA-Z0-9][a-zA-Z0-9-]*$/i",$domain)) {
			$delete = "update delete $domain$config[ip_mapping_domain] A";
			$myArray[] = $delete;
		} else {
			echo "domain.php: Error on domain $domain";
		}
		
	}
	if ($result) {
		mysql_free_result($result);
	}
	// clean the log
	mysql_query("delete from ps_domain_log");

	// Find if any domain we need to add to DNS server and write to domain.txt for further processing by nsupdate.
	$result = mysql_query("select domain,currentIP,uid from ps_domain where domainUpdated='false'");
	while (list($domain,$ip,$uid) = mysql_fetch_row($result)) {
		
		// check if it is a valid domain name
		if (preg_match("/^[a-zA-Z0-9][a-zA-Z0-9-]*$/i",$domain)) {
			$add = "update add $domain$config[ip_mapping_domain] 10 A $ip";
			$myArray[] = $add;
		} else {
			echo "domain.php: Error on domain $domain by uid $uid";
		}
		
		mysql_query("update ps_domain set domainUpdated='true' where uid=$uid");
	}
	if ($result) {
		mysql_free_result($result);
	}
	$result = mysql_query("UNLOCK TABLES");

	// write the domain.txt now.
	if (sizeof($myArray) > 0) {
		$fp = fopen($domainFile,"w");
		foreach ($myArray as $key) {
			$key = trim($key) . "\n";
			$len = strlen($key);
			fputs($fp,$key,$len);
		}
	fputs($fp,"\n\n");
	fclose($fp);
	
	// do the update
	system("$config[nsupdate_path] $domainFile");
}


?>
Return current item: PSlash