commit | author | age
|
fbdcc4
|
1 |
<?php |
2b54b2
|
2 |
$host="IP_ADDRESS"; |
T |
3 |
$user="USERNAME"; |
fbdcc4
|
4 |
$password="PASSWORD"; |
b1a6a5
|
5 |
mysql_connect($host, $user, $password) or die(mysql_error()); |
fbdcc4
|
6 |
mysql_select_db("dbispconfig"); |
T |
7 |
$result = ""; |
|
8 |
$result = mysql_query("SELECT id,origin,ns,ttl,mbox,serial,refresh,retry,expire,minimum FROM dns_soa;"); |
|
9 |
function hostname2ipfunktion($tmp1, $timeout = 1) |
b1a6a5
|
10 |
{ |
MC |
11 |
if ($tmp1 == 0) |
|
12 |
{ |
|
13 |
$query = `nslookup -timeout=$timeout -retry=0 $tmp1`; |
|
14 |
if(preg_match('/\nAddress: (.*)\n/', $query, $matches)) |
|
15 |
return trim($matches[1]); |
|
16 |
return $tmp1; |
|
17 |
} |
|
18 |
} |
2b54b2
|
19 |
|
T |
20 |
$serialsearch=date("Ymd"); |
|
21 |
$resultx12 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;"); |
|
22 |
while ($rowx12=mysql_fetch_array($resultx12)) { |
b1a6a5
|
23 |
$zone=substr($rowx12["origin"], 0, -1); |
MC |
24 |
$filename_x1="/var/cache/bind/".$zone; |
|
25 |
if (file_exists($filename_x1)) { |
|
26 |
$serialvergleich[$zone]=exec("grep \";Serial\" /var/cache/bind/$zone |cut -d\" \" -f1 | awk '{print $1}'"); |
|
27 |
} |
2b54b2
|
28 |
} |
fbdcc4
|
29 |
|
T |
30 |
while($row = mysql_fetch_array($result)) |
b1a6a5
|
31 |
{ |
MC |
32 |
//## Hier ALLES Aktivieren bei Primary Nameserver TEIL 1 ################################################################################# |
|
33 |
$varx11=substr($row["origin"], 0, -1); |
|
34 |
$filename="/var/cache/bind/".$varx11; |
|
35 |
if (file_exists($filename)) { |
|
36 |
unlink("/var/cache/bind/$varx11"); |
|
37 |
} |
|
38 |
$arr1[$x11]="zone \"$varx11\" in { type master; file \"$varx11\"; };\n"; |
|
39 |
$x11=$x11+1; |
|
40 |
$result2 = mysql_query("select name,type,aux,data from dns_rr where zone=$row[id] and active='Y' ORDER BY name ASC;"); |
|
41 |
$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"; |
fbdcc4
|
42 |
|
b1a6a5
|
43 |
$xx1=1; |
MC |
44 |
while($row2 = mysql_fetch_row($result2)) |
|
45 |
{ |
|
46 |
$arr2[$xx1]=$row2['0']." IN ".$row2['1']." "; |
fbdcc4
|
47 |
|
b1a6a5
|
48 |
if ($row2['2']>0) |
MC |
49 |
{ |
|
50 |
$arr3[$xx1]=$arr2[$xx1].$row2['2']." ".$row2['3']."\n"; |
|
51 |
} |
|
52 |
else |
|
53 |
{ |
|
54 |
$arr3[$xx1]=$arr2[$xx1].$row2['3']."\n"; |
|
55 |
} |
|
56 |
$xx1=$xx1+1; |
|
57 |
} |
|
58 |
$f = fopen("/var/cache/bind/$varx11", "a+"); |
|
59 |
foreach($arr3 as $values) fputs($f, $values); |
|
60 |
fclose($f); |
|
61 |
$arr2=array(); |
|
62 |
$arr3=array(); |
|
63 |
//## ENDE Primärer Nameserver TEIL 2 ##################################################################################################### |
fbdcc4
|
64 |
|
b1a6a5
|
65 |
//## Hier ALLES Aktivieren bei Secondary Nameserver ###################################################################################### |
MC |
66 |
// $tmp1 = substr($row["ns"],0,-1); |
|
67 |
// $tmp2 = substr($row["origin"],0,-1); |
2b54b2
|
68 |
|
b1a6a5
|
69 |
// if (!isset($dnscache[$tmp1])) $nsip = hostname2ipfunktion($tmp1) ; |
MC |
70 |
// else $nsip=$dnscache[$tmp1] ; |
2b54b2
|
71 |
|
b1a6a5
|
72 |
// if ($nsip == $tmp1) |
MC |
73 |
// { |
|
74 |
// echo "$tmp2 $tmp1 Not a valid Nameserver"; |
|
75 |
// echo "\n"; |
|
76 |
// } |
|
77 |
// else |
|
78 |
// { |
|
79 |
// $dnscache[$tmp1]=$nsip; |
|
80 |
// $arr1[$x11]="zone \"".$tmp2."\" in { type slave; file \"".$tmp2."\"; masters {".$nsip."; }; };\n"; |
|
81 |
// $x11=$x11+1; |
|
82 |
// } |
|
83 |
//## ENDE Secondary Nameserver ########################################################################################################### |
|
84 |
} |
fbdcc4
|
85 |
|
b1a6a5
|
86 |
unlink("/etc/bind/named.conf.local"); |
fbdcc4
|
87 |
$fx = fopen("/etc/bind/named.conf.local", "a+"); |
T |
88 |
foreach($arr1 as $values) fputs($fx, $values); |
|
89 |
fclose($fx); |
2b54b2
|
90 |
system("rndc reconfig >/dev/null 2>&1"); |
T |
91 |
|
b1a6a5
|
92 |
//## ANFANG Primärer Namerserver TEIL 2 ################################################################################################## |
2b54b2
|
93 |
$serialsearch=date("Ymd"); |
T |
94 |
$resultx13 = mysql_query("SELECT origin,serial FROM dns_soa WHERE serial LIKE '$serialsearch%' ORDER BY origin ASC;"); |
|
95 |
while ($rowx13=mysql_fetch_array($resultx13)) { |
b1a6a5
|
96 |
$serial_ist=($rowx13["serial"]); |
MC |
97 |
$zone=substr($rowx13["origin"], 0, -1); |
|
98 |
// echo "zone: ".$zone." ist: ".$serial_ist." vergleich: ".$serialvergleich[$zone]."\n"; |
|
99 |
if ($serialvergleich[$zone] != $serial_ist) { |
|
100 |
$reload=system("rndc reload $zone >/dev/null 2>&1"); |
|
101 |
} |
2b54b2
|
102 |
} |
b1a6a5
|
103 |
//## ENDE Primärer NamerserverTEIL 2 ###################################################################################################### |
MC |
104 |
?> |