71
|
1 |
<?php |
47
|
2 |
|
119
|
3 |
/* Poweradmin, a friendly web-based admin tool for PowerDNS. |
47
|
4 |
* See <https://rejo.zenger.nl/poweradmin> for more details. |
|
5 |
* |
|
6 |
* Copyright 2007, 2008 Rejo Zenger <rejo@zenger.nl> |
|
7 |
* |
|
8 |
* This program is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
|
1
|
22 |
session_start(); |
|
23 |
|
137
|
24 |
include_once("config-me.inc.php"); |
74
|
25 |
|
|
26 |
if(!@include_once("config.inc.php")) |
|
27 |
{ |
|
28 |
error( _('You have to create a config.inc.php!') ); |
|
29 |
} |
|
30 |
|
1
|
31 |
/************* |
74
|
32 |
* Constants * |
|
33 |
*************/ |
1
|
34 |
|
|
35 |
if (isset($_GET["start"])) { |
136
|
36 |
define('ROWSTART', (($_GET["start"] - 1) * $iface_rowamount)); |
1
|
37 |
} else { |
79
|
38 |
define('ROWSTART', 0); |
1
|
39 |
} |
|
40 |
|
|
41 |
if (isset($_GET["letter"])) { |
79
|
42 |
define('LETTERSTART', $_GET["letter"]); |
1
|
43 |
$_SESSION["letter"] = $_GET["letter"]; |
|
44 |
} elseif(isset($_SESSION["letter"])) { |
79
|
45 |
define('LETTERSTART', $_SESSION["letter"]); |
1
|
46 |
} else { |
79
|
47 |
define('LETTERSTART', "a"); |
1
|
48 |
} |
|
49 |
|
|
50 |
/* Database connection */ |
|
51 |
|
|
52 |
require_once("database.inc.php"); |
|
53 |
// Generates $db variable to access database. |
|
54 |
|
13
|
55 |
|
|
56 |
// Array of the available zone types |
|
57 |
$server_types = array("MASTER", "SLAVE", "NATIVE"); |
|
58 |
|
136
|
59 |
// $rtypes - array of possible record types |
|
60 |
$rtypes = array('A', 'AAAA', 'CNAME', 'HINFO', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'TXT'); |
|
61 |
|
|
62 |
// If fancy records is enabled, extend this field. |
|
63 |
if($dns_fancy) { |
|
64 |
$rtypes[10] = 'URL'; |
|
65 |
$rtypes[11] = 'MBOXFW'; |
|
66 |
} |
|
67 |
|
|
68 |
// $template - array of records that will be applied when adding a new zone file |
|
69 |
$template = array( |
|
70 |
array( |
|
71 |
|
|
72 |
"name" => "##DOMAIN##", |
|
73 |
"type" => "SOA", |
|
74 |
"content" => "$dns_ns1 $dns_hostmaster 0", |
|
75 |
"ttl" => "$dns_ttl", |
|
76 |
"prio" => "" |
|
77 |
), |
|
78 |
array( |
|
79 |
"name" => "##DOMAIN##", |
|
80 |
"type" => "NS", |
|
81 |
"content" => "$dns_ns1", |
|
82 |
"ttl" => "$dns_ttl", |
|
83 |
"prio" => "" |
|
84 |
), |
|
85 |
array( |
|
86 |
"name" => "##DOMAIN##", |
|
87 |
"type" => "NS", |
|
88 |
"content" => "$dns_ns2", |
|
89 |
"ttl" => "$dns_ttl", |
|
90 |
"prio" => "" |
|
91 |
), |
|
92 |
array( |
|
93 |
"name" => "www.##DOMAIN##", |
|
94 |
"type" => "A", |
|
95 |
"content" => "##WEBIP##", |
|
96 |
"ttl" => "$dns_ttl", |
|
97 |
"prio" => "" |
|
98 |
), |
|
99 |
array( |
|
100 |
"name" => "##DOMAIN##", |
|
101 |
"type" => "A", |
|
102 |
"content" => "##WEBIP##", |
|
103 |
"ttl" => "$dns_ttl", |
|
104 |
"prio" => "" |
|
105 |
), |
|
106 |
array( |
|
107 |
"name" => "mail.##DOMAIN##", |
|
108 |
"type" => "A", |
|
109 |
"content" => "##MAILIP##", |
|
110 |
"ttl" => "$dns_ttl", |
|
111 |
"prio" => "" |
|
112 |
), |
|
113 |
array( |
|
114 |
"name" => "localhost.##DOMAIN##", |
|
115 |
"type" => "A", |
|
116 |
"content" => "127.0.0.1", |
|
117 |
"ttl" => "$dns_ttl", |
|
118 |
"prio" => "" |
|
119 |
), |
|
120 |
array( |
|
121 |
"name" => "##DOMAIN##", |
|
122 |
"type" => "MX", |
|
123 |
"content" => "mail.##DOMAIN##", |
|
124 |
"ttl" => "$dns_ttl", |
|
125 |
"prio" => "10" |
|
126 |
) |
|
127 |
); |
|
128 |
|
13
|
129 |
|
1
|
130 |
/************* |
|
131 |
* Includes * |
|
132 |
*************/ |
|
133 |
|
|
134 |
require_once("error.inc.php"); |
|
135 |
require_once("auth.inc.php"); |
3
|
136 |
require_once("i18n.inc.php"); |
1
|
137 |
require_once("users.inc.php"); |
|
138 |
require_once("dns.inc.php"); |
|
139 |
require_once("record.inc.php"); |
|
140 |
|
82
|
141 |
$db = dbConnect(); |
|
142 |
doAuthenticate(); |
|
143 |
|
1
|
144 |
|
|
145 |
/************* |
|
146 |
* Functions * |
|
147 |
*************/ |
|
148 |
|
|
149 |
/* |
|
150 |
* Display the page option: [1] [2] .. [n] |
|
151 |
*/ |
|
152 |
|
|
153 |
function show_pages($amount,$rowamount,$id='') |
|
154 |
{ |
|
155 |
if ($amount > $rowamount) { |
|
156 |
if (!isset($_GET["start"])) $_GET["start"]=1; |
82
|
157 |
echo _('Show page') . ":<br>"; |
1
|
158 |
for ($i=1;$i<=ceil($amount / $rowamount);$i++) { |
|
159 |
if ($_GET["start"] == $i) { |
|
160 |
echo "[ <b>".$i."</b> ] "; |
|
161 |
} else { |
|
162 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i; |
|
163 |
if ($id!='') echo "&id=".$id; |
|
164 |
echo "\">".$i."</a> ] "; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
/* |
|
171 |
* Display the alphabetic option: [0-9] [a] [b] .. [z] |
|
172 |
*/ |
|
173 |
|
29
|
174 |
function show_letters($letterstart,$userid=true) |
1
|
175 |
{ |
82
|
176 |
echo _('Show zones beginning with') . ":<br>"; |
29
|
177 |
|
|
178 |
$letter = "[[:digit:]]"; |
77
|
179 |
if ($letterstart == "1") |
29
|
180 |
{ |
|
181 |
echo "[ <span class=\"lettertaken\">0-9</span> ] "; |
|
182 |
} |
|
183 |
elseif (zone_letter_start($letter,$userid)) |
|
184 |
{ |
32
|
185 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=1\">0-9</a> ] "; |
29
|
186 |
} |
|
187 |
else |
|
188 |
{ |
|
189 |
echo "[ <span class=\"letternotavailble\">0-9</span> ] "; |
|
190 |
} |
1
|
191 |
|
29
|
192 |
foreach (range('a','z') as $letter) |
|
193 |
{ |
|
194 |
if ($letter == $letterstart) |
|
195 |
{ |
|
196 |
echo "[ <span class=\"lettertaken\">".$letter."</span> ] "; |
|
197 |
} |
|
198 |
elseif (zone_letter_start($letter,$userid)) |
|
199 |
{ |
|
200 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] "; |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
echo "[ <span class=\"letternotavailble\">".$letter."</span> ] "; |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
function zone_letter_start($letter,$userid=true) |
|
210 |
{ |
|
211 |
global $db; |
55
|
212 |
global $sql_regexp; |
82
|
213 |
$query = "SELECT |
|
214 |
domains.id AS domain_id, |
|
215 |
zones.owner, |
|
216 |
domains.name AS domainname |
|
217 |
FROM domains |
|
218 |
LEFT JOIN zones ON domains.id=zones.domain_id |
107
|
219 |
WHERE substring(domains.name,1,1) ".$sql_regexp." ".$db->quote("^".$letter); |
82
|
220 |
$db->setLimit(1); |
|
221 |
$result = $db->query($query); |
29
|
222 |
$numrows = $result->numRows(); |
82
|
223 |
if ( $numrows == "1" ) { |
29
|
224 |
return 1; |
82
|
225 |
} else { |
29
|
226 |
return 0; |
|
227 |
} |
1
|
228 |
} |
|
229 |
|
82
|
230 |
function error($msg) { |
|
231 |
if ($msg) { |
|
232 |
echo " <div class=\"error\">Error: " . $msg . "</div>\n"; |
|
233 |
} else { |
|
234 |
echo " <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n"; |
1
|
235 |
} |
|
236 |
} |
|
237 |
|
82
|
238 |
function success($msg) { |
|
239 |
if ($msg) { |
|
240 |
echo " <div class=\"success\">" . $msg . "</div>\n"; |
|
241 |
} else { |
|
242 |
echo " <div class=\"success\">" . _('Something has been successfully performed. What exactly, however, will remain a mystery.') . "</div>\n"; |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
|
1
|
247 |
/* |
|
248 |
* Something has been done nicely, display a message and a back button. |
|
249 |
*/ |
|
250 |
function message($msg) |
|
251 |
{ |
|
252 |
include_once("header.inc.php"); |
|
253 |
?> |
71
|
254 |
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2><?php echo _('Success!'); ?></H2> |
1
|
255 |
<BR> |
|
256 |
<FONT STYLE="font-weight: Bold"> |
|
257 |
<P> |
71
|
258 |
<?php |
1
|
259 |
if($msg) |
|
260 |
{ |
|
261 |
echo nl2br($msg); |
|
262 |
} |
|
263 |
else |
|
264 |
{ |
4
|
265 |
echo _('Successful!'); |
1
|
266 |
} |
|
267 |
?> |
|
268 |
</P> |
|
269 |
<BR> |
|
270 |
<P> |
71
|
271 |
<a href="javascript:history.go(-1)"><< <?php echo _('back'); ?></a></FONT> |
1
|
272 |
</P> |
|
273 |
</TD></TR></TABLE></P> |
71
|
274 |
<?php |
1
|
275 |
include_once("footer.inc.php"); |
|
276 |
} |
|
277 |
|
|
278 |
|
|
279 |
/* |
|
280 |
* Reroute a user to a cleanpage of (if passed) arg |
|
281 |
*/ |
|
282 |
|
|
283 |
function clean_page($arg='') |
|
284 |
{ |
|
285 |
if (!$arg) |
|
286 |
{ |
|
287 |
header("Location: ".$_SERVER["PHP_SELF"]."?time=".time()); |
|
288 |
exit; |
|
289 |
} |
|
290 |
else |
|
291 |
{ |
|
292 |
if (preg_match('!\?!si', $arg)) |
|
293 |
{ |
|
294 |
$add = "&time="; |
|
295 |
} |
|
296 |
else |
|
297 |
{ |
|
298 |
$add = "?time="; |
|
299 |
} |
|
300 |
header("Location: $arg$add".time()); |
|
301 |
exit; |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
function get_status($res) |
|
307 |
{ |
|
308 |
if ($res == '0') |
|
309 |
{ |
4
|
310 |
return "<FONT CLASS=\"inactive\">" . _('Inactive') . "</FONT>"; |
1
|
311 |
} |
|
312 |
elseif ($res == '1') |
|
313 |
{ |
4
|
314 |
return "<FONT CLASS=\"active\">" . _('Active') . "</FONT>"; |
1
|
315 |
} |
|
316 |
} |
|
317 |
|
|
318 |
function parse_template_value($val, $domain, $webip, $mailip) |
|
319 |
{ |
|
320 |
$val = str_replace('##DOMAIN##', $domain, $val); |
|
321 |
$val = str_replace('##WEBIP##', $webip, $val); |
|
322 |
$val = str_replace('##MAILIP##', $mailip, $val); |
|
323 |
return $val; |
|
324 |
} |
|
325 |
|
|
326 |
|
|
327 |
/* |
|
328 |
* Validates an email address. |
|
329 |
* Checks if there is something before the at '@' sign and its followed by a domain and a tld of minimum 2 |
|
330 |
* and maximum of 4 characters. |
|
331 |
*/ |
|
332 |
function is_valid_email($email) |
|
333 |
{ |
|
334 |
if(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.([a-z]{2,6}$)", $email)) |
|
335 |
{ |
|
336 |
return false; |
|
337 |
} |
|
338 |
return true; |
|
339 |
} |
82
|
340 |
|
|
341 |
|
|
342 |
function v_num($string) { |
|
343 |
if (!eregi("^[0-9]+$", $string)) { |
|
344 |
return false ; |
|
345 |
} else { |
|
346 |
return true ; |
|
347 |
} |
|
348 |
} |
|
349 |
|
90
|
350 |
// Debug print |
91
|
351 |
function debug_print($var) { |
82
|
352 |
echo "<pre style=\"border: 2px solid blue;\">\n"; |
91
|
353 |
if (is_array($var)) { print_r($var) ; } else { echo $var ; } |
82
|
354 |
echo "</pre>\n"; |
|
355 |
} |
|
356 |
|
1
|
357 |
?> |