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