1
|
1 |
<? |
47
|
2 |
|
|
3 |
/* PowerAdmin, a friendly web-based admin tool for PowerDNS. |
|
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 |
|
|
24 |
/************* |
|
25 |
* Constants * |
|
26 |
*************/ |
|
27 |
|
23
|
28 |
define(ROWAMOUNT, 50); |
1
|
29 |
|
|
30 |
if (isset($_GET["start"])) { |
|
31 |
define(ROWSTART, (($_GET["start"] - 1) * ROWAMOUNT)); |
|
32 |
} else { |
|
33 |
define(ROWSTART, 0); |
|
34 |
} |
|
35 |
|
|
36 |
if (isset($_GET["letter"])) { |
|
37 |
define(LETTERSTART, $_GET["letter"]); |
|
38 |
$_SESSION["letter"] = $_GET["letter"]; |
|
39 |
} elseif(isset($_SESSION["letter"])) { |
|
40 |
define(LETTERSTART, $_SESSION["letter"]); |
|
41 |
} else { |
|
42 |
define(LETTERSTART, "a"); |
|
43 |
} |
|
44 |
|
|
45 |
if(!@include_once("config.inc.php")) |
|
46 |
{ |
6
|
47 |
error( _('You have to create a config.inc.php!') ); |
1
|
48 |
} |
|
49 |
|
|
50 |
if(is_file( dirname(__FILE__) . '/../install.php')) |
|
51 |
{ |
6
|
52 |
error( _('You have to remove install.php before this program will run') ); |
1
|
53 |
} |
|
54 |
|
|
55 |
if(is_file( dirname(__FILE__) . '/../migrator.php')) |
|
56 |
{ |
6
|
57 |
error( _('You have to remove migrator.php before this program will run') ); |
1
|
58 |
} |
|
59 |
|
|
60 |
/* Database connection */ |
|
61 |
|
|
62 |
require_once("database.inc.php"); |
|
63 |
// Generates $db variable to access database. |
|
64 |
|
13
|
65 |
|
|
66 |
// Array of the available zone types |
|
67 |
$server_types = array("MASTER", "SLAVE", "NATIVE"); |
|
68 |
|
|
69 |
|
1
|
70 |
/************* |
|
71 |
* Includes * |
|
72 |
*************/ |
|
73 |
|
|
74 |
require_once("error.inc.php"); |
|
75 |
require_once("auth.inc.php"); |
3
|
76 |
require_once("i18n.inc.php"); |
1
|
77 |
require_once("users.inc.php"); |
|
78 |
require_once("dns.inc.php"); |
|
79 |
require_once("record.inc.php"); |
|
80 |
|
|
81 |
|
|
82 |
/************* |
|
83 |
* Functions * |
|
84 |
*************/ |
|
85 |
|
|
86 |
/* |
|
87 |
* Display the page option: [1] [2] .. [n] |
|
88 |
*/ |
|
89 |
|
|
90 |
function show_pages($amount,$rowamount,$id='') |
|
91 |
{ |
|
92 |
if ($amount > $rowamount) { |
|
93 |
if (!isset($_GET["start"])) $_GET["start"]=1; |
13
|
94 |
echo _('Show page') . "<br>"; |
1
|
95 |
for ($i=1;$i<=ceil($amount / $rowamount);$i++) { |
|
96 |
if ($_GET["start"] == $i) { |
|
97 |
echo "[ <b>".$i."</b> ] "; |
|
98 |
} else { |
|
99 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i; |
|
100 |
if ($id!='') echo "&id=".$id; |
|
101 |
echo "\">".$i."</a> ] "; |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* Display the alphabetic option: [0-9] [a] [b] .. [z] |
|
109 |
*/ |
|
110 |
|
29
|
111 |
function show_letters($letterstart,$userid=true) |
1
|
112 |
{ |
29
|
113 |
echo _('Show zones beginning with:') . "<br>"; |
|
114 |
|
|
115 |
$letter = "[[:digit:]]"; |
|
116 |
if ($letterstart == "0") |
|
117 |
{ |
|
118 |
echo "[ <span class=\"lettertaken\">0-9</span> ] "; |
|
119 |
} |
|
120 |
elseif (zone_letter_start($letter,$userid)) |
|
121 |
{ |
32
|
122 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=1\">0-9</a> ] "; |
29
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
echo "[ <span class=\"letternotavailble\">0-9</span> ] "; |
|
127 |
} |
1
|
128 |
|
29
|
129 |
foreach (range('a','z') as $letter) |
|
130 |
{ |
|
131 |
if ($letter == $letterstart) |
|
132 |
{ |
|
133 |
echo "[ <span class=\"lettertaken\">".$letter."</span> ] "; |
|
134 |
} |
|
135 |
elseif (zone_letter_start($letter,$userid)) |
|
136 |
{ |
|
137 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] "; |
|
138 |
} |
|
139 |
else |
|
140 |
{ |
|
141 |
echo "[ <span class=\"letternotavailble\">".$letter."</span> ] "; |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
function zone_letter_start($letter,$userid=true) |
|
147 |
{ |
|
148 |
global $db; |
|
149 |
$sqlq = "SELECT domains.id AS domain_id, |
|
150 |
zones.owner, |
|
151 |
records.id, |
|
152 |
domains.name AS domainname |
|
153 |
FROM domains |
|
154 |
LEFT JOIN zones ON domains.id=zones.domain_id |
|
155 |
LEFT JOIN records ON records.domain_id=domains.id |
|
156 |
WHERE 1"; |
|
157 |
if((!level(5) || !$userid) && !level(10) && !level(5)) |
|
158 |
{ |
37
|
159 |
// First select the zones for which we have ownership on one or more records. |
|
160 |
$query = 'SELECT records.domain_id FROM records, record_owners WHERE user_id = '.$_SESSION['userid'].' AND records.id = record_owners.record_id'; |
|
161 |
$result = $db->query($query); |
|
162 |
$zones = array(); |
|
163 |
if (!PEAR::isError($result)) { |
|
164 |
$zones = $result->fetchCol(); |
|
165 |
} |
|
166 |
|
|
167 |
$sqlq .= " AND (zones.owner=".$_SESSION["userid"]; |
|
168 |
if (count($zones) > 0) { |
|
169 |
$sqlq .= ' OR zones.domain_id IN ('.implode(',', $zones).') '; |
|
170 |
|
|
171 |
} |
|
172 |
$sqlq .= ')'; |
29
|
173 |
} |
|
174 |
$sqlq .= " AND substring(domains.name,1,1) REGEXP '^".$letter."' LIMIT 1"; |
|
175 |
$result = $db->query($sqlq); |
|
176 |
$numrows = $result->numRows(); |
|
177 |
if ( $numrows == "1" ) |
|
178 |
{ |
|
179 |
return 1; |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
return 0; |
|
184 |
} |
1
|
185 |
} |
|
186 |
|
|
187 |
/* |
|
188 |
* Print a nice useraimed error. |
|
189 |
*/ |
|
190 |
function error($msg) |
|
191 |
{ |
|
192 |
// General function for printing critical errors. |
|
193 |
if ($msg) |
|
194 |
{ |
|
195 |
include_once("header.inc.php"); |
|
196 |
?> |
13
|
197 |
<p><? echo _('Oops! An error occured!'); ?></p> |
|
198 |
<p><? echo nl2br($msg) ?></p> |
1
|
199 |
<? |
|
200 |
include_once("footer.inc.php"); |
|
201 |
die(); |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
include_once("footer.inc.php"); |
|
206 |
die("No error specified!"); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
/* |
|
211 |
* Something has been done nicely, display a message and a back button. |
|
212 |
*/ |
|
213 |
function message($msg) |
|
214 |
{ |
|
215 |
include_once("header.inc.php"); |
|
216 |
?> |
4
|
217 |
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2><? echo _('Success!'); ?></H2> |
1
|
218 |
<BR> |
|
219 |
<FONT STYLE="font-weight: Bold"> |
|
220 |
<P> |
|
221 |
<? |
|
222 |
if($msg) |
|
223 |
{ |
|
224 |
echo nl2br($msg); |
|
225 |
} |
|
226 |
else |
|
227 |
{ |
4
|
228 |
echo _('Successful!'); |
1
|
229 |
} |
|
230 |
?> |
|
231 |
</P> |
|
232 |
<BR> |
|
233 |
<P> |
4
|
234 |
<a href="javascript:history.go(-1)"><< <? echo _('back'); ?></a></FONT> |
1
|
235 |
</P> |
|
236 |
</TD></TR></TABLE></P> |
|
237 |
<? |
|
238 |
include_once("footer.inc.php"); |
|
239 |
} |
|
240 |
|
|
241 |
|
|
242 |
/* |
|
243 |
* Reroute a user to a cleanpage of (if passed) arg |
|
244 |
*/ |
|
245 |
|
|
246 |
function clean_page($arg='') |
|
247 |
{ |
|
248 |
if (!$arg) |
|
249 |
{ |
|
250 |
header("Location: ".$_SERVER["PHP_SELF"]."?time=".time()); |
|
251 |
exit; |
|
252 |
} |
|
253 |
else |
|
254 |
{ |
|
255 |
if (preg_match('!\?!si', $arg)) |
|
256 |
{ |
|
257 |
$add = "&time="; |
|
258 |
} |
|
259 |
else |
|
260 |
{ |
|
261 |
$add = "?time="; |
|
262 |
} |
|
263 |
header("Location: $arg$add".time()); |
|
264 |
exit; |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
function level($l) |
|
269 |
{ |
|
270 |
if ($_SESSION["level"] >= $l) |
|
271 |
{ |
|
272 |
return 1; |
|
273 |
} |
|
274 |
else |
|
275 |
{ |
|
276 |
return 0; |
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
function xs($zoneid) |
|
281 |
{ |
|
282 |
global $db; |
|
283 |
if (is_numeric($zoneid) && is_numeric($_SESSION["level"])) |
|
284 |
{ |
|
285 |
$result = $db->query("SELECT id FROM zones WHERE owner=".$_SESSION["userid"]." AND domain_id=$zoneid"); |
|
286 |
$result_extra = $db->query("SELECT record_owners.id FROM record_owners,records WHERE record_owners.user_id=".$_SESSION["userid"]." AND records.domain_id = $zoneid AND records.id = record_owners.record_id LIMIT 1"); |
|
287 |
|
|
288 |
if ($result->numRows() == 1 || $_SESSION["level"] >= 5) |
|
289 |
{ |
|
290 |
$_SESSION[$zoneid."_ispartial"] = 0; |
|
291 |
return true; |
|
292 |
} |
|
293 |
elseif ($result_extra->numRows() == 1) |
|
294 |
{ |
|
295 |
$_SESSION[$zoneid."_ispartial"] = 1; |
|
296 |
return true; |
|
297 |
} |
|
298 |
else |
|
299 |
{ |
|
300 |
return false; |
|
301 |
} |
|
302 |
} |
|
303 |
else |
|
304 |
{ |
|
305 |
return false; |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
function get_status($res) |
|
310 |
{ |
|
311 |
if ($res == '0') |
|
312 |
{ |
4
|
313 |
return "<FONT CLASS=\"inactive\">" . _('Inactive') . "</FONT>"; |
1
|
314 |
} |
|
315 |
elseif ($res == '1') |
|
316 |
{ |
4
|
317 |
return "<FONT CLASS=\"active\">" . _('Active') . "</FONT>"; |
1
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
function parse_template_value($val, $domain, $webip, $mailip) |
|
322 |
{ |
|
323 |
$val = str_replace('##DOMAIN##', $domain, $val); |
|
324 |
$val = str_replace('##WEBIP##', $webip, $val); |
|
325 |
$val = str_replace('##MAILIP##', $mailip, $val); |
|
326 |
return $val; |
|
327 |
} |
|
328 |
|
|
329 |
|
|
330 |
/* |
|
331 |
* Validates an email address. |
|
332 |
* Checks if there is something before the at '@' sign and its followed by a domain and a tld of minimum 2 |
|
333 |
* and maximum of 4 characters. |
|
334 |
*/ |
|
335 |
function is_valid_email($email) |
|
336 |
{ |
|
337 |
if(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.([a-z]{2,6}$)", $email)) |
|
338 |
{ |
|
339 |
return false; |
|
340 |
} |
|
341 |
return true; |
|
342 |
} |
|
343 |
?> |