-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfind-baddels.php
More file actions
168 lines (149 loc) · 4.05 KB
/
find-baddels.php
File metadata and controls
168 lines (149 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
require 'inc/lib.inc';
include 'header.php';
$html_top = '
<HTML>
<HEAD>
<TITLE>Detect NS mismatches</TITLE>
<LINK rel="stylesheet" href="../style.css" type="text/css">
</HEAD>
<BODY bgcolor="#cccc99" background="../images/BG-shadowleft.gif">
<H1>Detect NS mismatches</H1>
';
$html_bottom = '
</BODY>
</HTML>
';
$entrance_prologue = '
This tool detects delegations to our DNS servers, which
do not point to the appropriate server names.
In order to do so, we need the hostname (or IP address) of
a DNS server <em>outside</em> of your network. The default
will usually be a sensible choice. Specifying a server
controlled through this database will accomplish exactly
nothing.<P>
<B>NB:</B> This will take a long time. Have patience.<P>
';
$entrance_body = '
<FORM action="find-baddels.php" method="post">
<INPUT type=text size=32 name=nameserver value="%s">
<INPUT type=submit value="Start">
</FORM>
';
$search_prologue = '
We manage these domains, but they are delegated to
deprecated DNS servers.
So you should get them redelegated to the new, improved
DNS servers.
Be cautious
though: some of these delegations may be strange, but
intentional.<P>
<P>
';
$search_epilogue = '
<P><HR><P>Completed.<P>
Found %s bad delegations.<P>
';
function end_domain($begin, $domainform, $serverform, $end, $noservers, &$counter)
{
global $current_domain, $name_servers, $servers;
$nomatches = 0;
$row = "";
$result = "";
foreach($name_servers as $ns) {
$row .= sprintf($serverform, $ns);
if (!array_key_exists($ns,$servers))
$nomatches++;
}
if ($nomatches) {
$counter++;
$dom = sprintf($domainform, $current_domain);
if (count($name_servers))
$result = $begin.$dom.$row.$end;
else
$result = $begin.$dom.$noservers.$end;
}
$current_domain = "";
return $result;
}
function begin_domain($domain)
{
global $current_domain, $name_servers;
$name_servers = array();
if ($current_domain)
end_domain();
$current_domain = $domain;
}
function domain_name_server($nameserver)
{
global $name_servers;
$name_servers[] = strtolower(ltrim(trim($nameserver)));
}
function entrance_page($text = "")
{
$db = new DB_probind;
global $html_top, $entrance_prologue, $entrance_body, $html_bottom;
$db->query("SELECT value FROM blackboard WHERE name = 'default_external_dns'");
$default_resolver = $db->next_record() ? $db->Record[0] : "8.8.8.8";
print $html_top;
print $entrance_prologue;
print $text;
print sprintf($entrance_body, $default_resolver);
print $html_bottom;
exit;
}
function initialize_servers()
{
$db = new DB_probind;
global $servers;
$db->query("SELECT hostname FROM servers WHERE mknsrec");
while ($db->next_record()) {
$hostname = $db->Record[0];
$servers[$hostname] = 1;
}
}
#
# MAIN
#
get_input();
if (!$INPUT_VARS['nameserver']) {
entrance_page();
} else {
$tmp = strtolower(ltrim(rtrim($INPUT_VARS['nameserver'])));
if (ereg($DOMAIN_RE, $tmp)
&& ((gethostbyname($tmp) != $tmp) || valid_ip($tmp)))
$nameserver = $tmp;
else
entrance_page("Invalid hostname.<P>\n");
}
$db = new DB_probind;
print sprintf($html_top, "#dcdcdc");
initialize_servers();
$db->query("SELECT domain FROM zones WHERE (master IS NULL OR NOT master) AND domain != 'TEMPLATE' AND domain != '0.0.127.in-addr.arpa' ".access()." ORDER BY domain");
$listfile = fopen("$TMP/domains", "w");
while ($db->next_record()) {
$domain = sprintf("%s\n", $db->Record[0]);
fwrite($listfile, $domain);
}
fclose($listfile);
print $search_prologue;
$pipe = popen("$BIN/nsrecs -h $nameserver < $TMP/domains", "r");
$badcounter = 0;
while (!feof($pipe)) {
$result = fgets($pipe, 1000);
$hostnames = explode(" ", $result);
if (strlen($hostnames[0])) {
$zone = get_named_zone($hostnames[0]);
$domstr = "<B><A HREF=\"zones.php?zone=".$zone['id']."\">%s</A></B>";
begin_domain($hostnames[0]);
for ($i=1; $i<count($hostnames); $i++) {
domain_name_server($hostnames[$i]);
}
print end_domain("", "$domstr is delegated to these servers:<UL>", "<LI>%s", "</UL><BR>\n", "<P>No NS records found", $badcounter);
}
}
pclose($pipe);
print sprintf($search_epilogue, $badcounter);
print $html_bottom;
?>