Location: PHPKode > projects > WeBBind Web Gui to Bind > webbind_0.98/createnewzone.php
<?
require("htmlcommon.php");
require("global.php");
require("locking.php");

function CheckExists ($zonefile,$username,$phpbindurl,$server)
{
if (file_exists($zonefile)) {
	HTMLHeader();
	Banner("Zone Name already exists on $server ....<BR>Only modification allowed !<BR><BR><A HREF=\"$phpbindurl\">Back To Search Page</A>",$username,$server);
	clearstatcache();
	exit();
	}
}

function CheckSyntax($zonefile)
{
 $ar_zonefile = explode(".", $zonefile) ;
 if (end($ar_zonefile) != "dns") {
	$zonefile .= ".dns";
	return($zonefile);
 } else {
	return($zonefile);
 }
}
 

//Riceve la query dal form nuovo dominio
//
if ( $newzonechoose != ".dns" ) {
        $server = $servername[$newserverchoose];
	
	$newzone = $newzonechoose;
	
	$newchekedzone = CheckSyntax($newzone);	//Appende il suffisso .dns se rimosso dal form in fase di inserimento nome zona

        $zonefile="$basemount/$server/zones/$newchekedzone";

            CheckExists ($zonefile,$username,$phpbindurl,$server);

        //prepara output per named.conf master e slave 
        //crea file di zona iniziale
        //reconfig dei name servers daemons
        
	$ZONENAME = ereg_replace("\.dns", "", $newchekedzone);
		
    		$namedoutmaster .= "zone \"$ZONENAME\" {\n";
                $namedoutmaster .= "\ttype master;\n";
                $namedoutmaster .= "\tfile \"$newchekedzone\";\n";
//SE ESISTE UNA SELEZIONE PER SLAVE SERVER O EXTERNAL SERVER
		$namedoutmaster .= "\tallow-transfer { ";
		if ($newslavechoose != "") { $namedoutmaster .= "$ipfe[$newslavechoose];"; }
		if ($extslavefqdn != "") { $namedoutmaster .= " $extslaveip;"; }
		for ($tal = 0; $tal < (count ($transallowed)); $tal++) { $namedoutmaster .= " $transallowed[$tal];"; }
		$namedoutmaster .= " };\n";
//
                $namedoutmaster .= "};\n";
		$namedoutmaster .= "\n";
$fl=Filelock();
	if ($fl) {
		$fp = fopen ("$basemount/$servername[$newserverchoose]/etc/named.conf","a");
                fwrite ($fp, $namedoutmaster);
                fclose ($fp);
        fclose($fl);
	}        
                $ZONENAME = ereg_replace("\.dns", "", $newchekedzone);
		$TIMESTAMP = "Last modification on  ".date("Y/m/d H:i:s")."  by user: $username" ;

		$zoneout .= ";\n";
		$zoneout .= ";\t$TIMESTAMP\n";
		$zoneout .= ";\n";
		$zoneout .= ";\tDatabase file $newchekedzone for $ZONENAME zone.\n";
		$zoneout .= ";\n";
		$zoneout .= ";\n";
		$zoneout .= "\$TTL 86400\n";
		$zoneout .= "@\t\tIN\tSOA $server. postmaster.$server. (\n";
		$zoneout .= "\t\t\t$serial\t; serial number\n";
		$zoneout .= "\t\t\t$refresh\t\t; refresh\n";
		$zoneout .= "\t\t\t$retry\t\t; retry\n";
		$zoneout .= "\t\t\t$expire\t\t; expire\n";
		$zoneout .= "\t\t\t$ttl )\t\t; minimum TTL\n";
		$zoneout .= ";\n";
		$zoneout .= ";\n";
		$zoneout .= ";\tZone NS records\n";
		$zoneout .= ";\n";
		$zoneout .= ";\n";
		$zoneout .= "@\t\tNS\t$server.\n";
//SE ESISTE UNA SELEZIONE PER SLAVE SERVER O EXTERNAL SLAVE SERVER
if ($newslavechoose != "") { $zoneout .= "@\t\tNS\t$servername[$newslavechoose].\n"; }
if ($extslavefqdn != "") { $zoneout .= "@\t\tNS\t$extslavefqdn.\n"; }
//
		$fp = fopen ("$zonefile", "w+");
		fwrite ($fp, $zoneout);
		fclose ($fp);

                exec ("$remexec $ipbe[$newserverchoose] $subin[$newserverchoose]/ndc reconfig , $result");
                
//SE ESISTE UNA SELEZIONE PER SLAVE SERVER DIRETTAMENTE MANTENUTO AGGIORNARE IL NAMED.CONF SULLA MACCHINA
	if ($newslavechoose != "") {
			$namedoutslave .= "zone \"$ZONENAME\" {\n";
                	$namedoutslave .= "\ttype slave;\n";
                	$namedoutslave .= "\tfile \"$newchekedzone.slavezone\";\n";
			$namedoutslave .= "\tmasters { $ipfe[$newserverchoose]; };\n";
			   $namedoutslave .= "\tallow-transfer { ";
			   for ($tal = 0; $tal < (count ($transallowed)); $tal++) { $namedoutslave .= " $transallowed[$tal];"; }
			   $namedoutslave .= " };\n";
                	$namedoutslave .= "};\n";
			$namedoutslave .= "\n";
$fl=Filelock();
        if ($fl) {
	                $fp = fopen ("$basemount/$servername[$newslavechoose]/etc/named.conf","a");
        	        fwrite ($fp, $namedoutslave);
                	fclose ($fp);
        fclose($fl);
        }
                	exec ("$remexec $ipbe[$newslavechoose] $subin[$newslavechoose]/ndc reconfig , $result");
		}


        
        header ("Location: $phpbindurl/showzone.php?modifica=Modifica&zonechoose=$zonefile&idserver=$newserverchoose&username=$username");

} else {
	HTMLHeader();
	Banner("Zone Name not specified<BR><BR><A HREF=\"$phpbindurl\">Back To Search Page</A>",$username,$servername[$newserverchoose]);
}

?>
Return current item: WeBBind Web Gui to Bind