Commit 7fe908c5 authored by Marius Cramer's avatar Marius Cramer

Cleaning up code to match coding guidelines

parent 7d52e00a
...@@ -2,103 +2,103 @@ ...@@ -2,103 +2,103 @@
$host="IP_ADDRESS"; $host="IP_ADDRESS";
$user="USERNAME"; $user="USERNAME";
$password="PASSWORD"; $password="PASSWORD";
mysql_connect($host,$user,$password) or die(mysql_error()); mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db("dbispconfig"); mysql_select_db("dbispconfig");
$result = ""; $result = "";
$result = mysql_query("SELECT id,origin,ns,ttl,mbox,serial,refresh,retry,expire,minimum FROM dns_soa;"); $result = mysql_query("SELECT id,origin,ns,ttl,mbox,serial,refresh,retry,expire,minimum FROM dns_soa;");
function hostname2ipfunktion($tmp1, $timeout = 1) function hostname2ipfunktion($tmp1, $timeout = 1)
{ {
if ($tmp1 == 0) if ($tmp1 == 0)
{ {
$query = `nslookup -timeout=$timeout -retry=0 $tmp1`; $query = `nslookup -timeout=$timeout -retry=0 $tmp1`;
if(preg_match('/\nAddress: (.*)\n/', $query, $matches)) if(preg_match('/\nAddress: (.*)\n/', $query, $matches))
return trim($matches[1]); return trim($matches[1]);
return $tmp1; return $tmp1;
} }
} }
$serialsearch=date("Ymd"); $serialsearch=date("Ymd");
$resultx12 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;"); $resultx12 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;");
while ($rowx12=mysql_fetch_array($resultx12)) { while ($rowx12=mysql_fetch_array($resultx12)) {
$zone=substr($rowx12["origin"],0,-1); $zone=substr($rowx12["origin"], 0, -1);
$filename_x1="/var/cache/bind/".$zone; $filename_x1="/var/cache/bind/".$zone;
if (file_exists($filename_x1)) { if (file_exists($filename_x1)) {
$serialvergleich[$zone]=exec("grep \";Serial\" /var/cache/bind/$zone |cut -d\" \" -f1 | awk '{print $1}'"); $serialvergleich[$zone]=exec("grep \";Serial\" /var/cache/bind/$zone |cut -d\" \" -f1 | awk '{print $1}'");
} }
} }
while($row = mysql_fetch_array($result)) while($row = mysql_fetch_array($result))
{ {
### Hier ALLES Aktivieren bei Primary Nameserver TEIL 1 ################################################################################# //## Hier ALLES Aktivieren bei Primary Nameserver TEIL 1 #################################################################################
$varx11=substr($row["origin"],0,-1); $varx11=substr($row["origin"], 0, -1);
$filename="/var/cache/bind/".$varx11; $filename="/var/cache/bind/".$varx11;
if (file_exists($filename)) { if (file_exists($filename)) {
unlink("/var/cache/bind/$varx11"); unlink("/var/cache/bind/$varx11");
} }
$arr1[$x11]="zone \"$varx11\" in { type master; file \"$varx11\"; };\n"; $arr1[$x11]="zone \"$varx11\" in { type master; file \"$varx11\"; };\n";
$x11=$x11+1; $x11=$x11+1;
$result2 = mysql_query("select name,type,aux,data from dns_rr where zone=$row[id] and active='Y' ORDER BY name ASC;"); $result2 = mysql_query("select name,type,aux,data from dns_rr where zone=$row[id] and active='Y' ORDER BY name ASC;");
$arr3[0]="\$TTL ".$row['ttl']."\n@ IN SOA ".$row['ns']." ".$row['mbox']." (\n ".$row['serial']." ;Serial\n"." ".$row['refresh']." ;Refresh\n"." ".$row['retry']." ;Retry\n"." ".$row['expire']." ;Expire\n"." ".$row['minimum']." ) ;Minimum\n\n"; $arr3[0]="\$TTL ".$row['ttl']."\n@ IN SOA ".$row['ns']." ".$row['mbox']." (\n ".$row['serial']." ;Serial\n"." ".$row['refresh']." ;Refresh\n"." ".$row['retry']." ;Retry\n"." ".$row['expire']." ;Expire\n"." ".$row['minimum']." ) ;Minimum\n\n";
$xx1=1; $xx1=1;
while($row2 = mysql_fetch_row($result2)) while($row2 = mysql_fetch_row($result2))
{ {
$arr2[$xx1]=$row2['0']." IN ".$row2['1']." "; $arr2[$xx1]=$row2['0']." IN ".$row2['1']." ";
if ($row2['2']>0) if ($row2['2']>0)
{ {
$arr3[$xx1]=$arr2[$xx1].$row2['2']." ".$row2['3']."\n"; $arr3[$xx1]=$arr2[$xx1].$row2['2']." ".$row2['3']."\n";
} }
else else
{ {
$arr3[$xx1]=$arr2[$xx1].$row2['3']."\n"; $arr3[$xx1]=$arr2[$xx1].$row2['3']."\n";
} }
$xx1=$xx1+1; $xx1=$xx1+1;
} }
$f = fopen("/var/cache/bind/$varx11", "a+"); $f = fopen("/var/cache/bind/$varx11", "a+");
foreach($arr3 as $values) fputs($f, $values); foreach($arr3 as $values) fputs($f, $values);
fclose($f); fclose($f);
$arr2=array(); $arr2=array();
$arr3=array(); $arr3=array();
### ENDE Primärer Nameserver TEIL 2 ##################################################################################################### //## ENDE Primärer Nameserver TEIL 2 #####################################################################################################
### Hier ALLES Aktivieren bei Secondary Nameserver ###################################################################################### //## Hier ALLES Aktivieren bei Secondary Nameserver ######################################################################################
# $tmp1 = substr($row["ns"],0,-1); // $tmp1 = substr($row["ns"],0,-1);
# $tmp2 = substr($row["origin"],0,-1); // $tmp2 = substr($row["origin"],0,-1);
# if (!isset($dnscache[$tmp1])) $nsip = hostname2ipfunktion($tmp1) ; // if (!isset($dnscache[$tmp1])) $nsip = hostname2ipfunktion($tmp1) ;
# else $nsip=$dnscache[$tmp1] ; // else $nsip=$dnscache[$tmp1] ;
# if ($nsip == $tmp1) // if ($nsip == $tmp1)
# { // {
# echo "$tmp2 $tmp1 Not a valid Nameserver"; // echo "$tmp2 $tmp1 Not a valid Nameserver";
# echo "\n"; // echo "\n";
# } // }
# else // else
# { // {
# $dnscache[$tmp1]=$nsip; // $dnscache[$tmp1]=$nsip;
# $arr1[$x11]="zone \"".$tmp2."\" in { type slave; file \"".$tmp2."\"; masters {".$nsip."; }; };\n"; // $arr1[$x11]="zone \"".$tmp2."\" in { type slave; file \"".$tmp2."\"; masters {".$nsip."; }; };\n";
# $x11=$x11+1; // $x11=$x11+1;
# } // }
### ENDE Secondary Nameserver ########################################################################################################### //## ENDE Secondary Nameserver ###########################################################################################################
} }
unlink ("/etc/bind/named.conf.local"); unlink("/etc/bind/named.conf.local");
$fx = fopen("/etc/bind/named.conf.local", "a+"); $fx = fopen("/etc/bind/named.conf.local", "a+");
foreach($arr1 as $values) fputs($fx, $values); foreach($arr1 as $values) fputs($fx, $values);
fclose($fx); fclose($fx);
system("rndc reconfig >/dev/null 2>&1"); system("rndc reconfig >/dev/null 2>&1");
### ANFANG Primärer Namerserver TEIL 2 ################################################################################################## //## ANFANG Primärer Namerserver TEIL 2 ##################################################################################################
$serialsearch=date("Ymd"); $serialsearch=date("Ymd");
$resultx13 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;"); $resultx13 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;");
while ($rowx13=mysql_fetch_array($resultx13)) { while ($rowx13=mysql_fetch_array($resultx13)) {
$serial_ist=($rowx13["serial"]); $serial_ist=($rowx13["serial"]);
$zone=substr($rowx13["origin"],0,-1); $zone=substr($rowx13["origin"], 0, -1);
# echo "zone: ".$zone." ist: ".$serial_ist." vergleich: ".$serialvergleich[$zone]."\n"; // echo "zone: ".$zone." ist: ".$serial_ist." vergleich: ".$serialvergleich[$zone]."\n";
if ($serialvergleich[$zone] != $serial_ist) { if ($serialvergleich[$zone] != $serial_ist) {
$reload=system("rndc reload $zone >/dev/null 2>&1"); $reload=system("rndc reload $zone >/dev/null 2>&1");
} }
} }
### ENDE Primärer NamerserverTEIL 2 ###################################################################################################### //## ENDE Primärer NamerserverTEIL 2 ######################################################################################################
?> ?>
\ No newline at end of file
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
$host="IP_ADDRESS"; $host="IP_ADDRESS";
$user="USERNAME"; $user="USERNAME";
$password="PASSWORD"; $password="PASSWORD";
mysql_connect($host,$user,$password) or die(mysql_error()); mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db("dbispconfig"); mysql_select_db("dbispconfig");
$result = ""; $result = "";
$result = mysql_query("SELECT origin FROM dns_soa ORDER BY origin ASC;"); $result = mysql_query("SELECT origin FROM dns_soa ORDER BY origin ASC;");
while($row = mysql_fetch_array($result)) while($row = mysql_fetch_array($result))
{ {
$zone=substr($row["origin"],0,-1); $zone=substr($row["origin"], 0, -1);
system("rndc retransfer ".$zone); system("rndc retransfer ".$zone);
} }
?> ?>
\ No newline at end of file
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
$host="localhost"; $host="localhost";
$user="root"; $user="root";
$password="MYSQL-ROOT-PASSWD"; $password="MYSQL-ROOT-PASSWD";
mysql_connect($host,$user,$password) or die(mysql_error()); mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db("dbispconfig"); mysql_select_db("dbispconfig");
$sql1 = mysql_query("SELECT id, substr(origin,1, LENGTH(origin)-1) AS origin, substr(ns,1, LENGTH(ns)-1) AS ns, substr(mbox,1, LENGTH(mbox)-1) AS mbox,ttl FROM dns_soa order by id asc;"); $sql1 = mysql_query("SELECT id, substr(origin,1, LENGTH(origin)-1) AS origin, substr(ns,1, LENGTH(ns)-1) AS ns, substr(mbox,1, LENGTH(mbox)-1) AS mbox,ttl FROM dns_soa order by id asc;");
mysql_select_db("powerdns"); mysql_select_db("powerdns");
while($row1 = mysql_fetch_array($sql1)) while($row1 = mysql_fetch_array($sql1))
{ {
mysql_query("INSERT INTO domains (id,name,type,ispconfig_id) values ('$row1[id]','$row1[origin]','NATIVE','$row1[id]');"); mysql_query("INSERT INTO domains (id,name,type,ispconfig_id) values ('$row1[id]','$row1[origin]','NATIVE','$row1[id]');");
mysql_query("INSERT INTO records (domain_id,name,content,ispconfig_id,type,ttl,prio,change_date) values ('$row1[id]','$row1[origin]','$row1[ns] $row1[mbox] 0','$row1[id]','SOA','$row1[ttl]','0','1260446221');"); mysql_query("INSERT INTO records (domain_id,name,content,ispconfig_id,type,ttl,prio,change_date) values ('$row1[id]','$row1[origin]','$row1[ns] $row1[mbox] 0','$row1[id]','SOA','$row1[ttl]','0','1260446221');");
} }
mysql_select_db("dbispconfig");