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 |
if(!@include_once("config.inc.php")) |
|
26 |
{ |
|
27 |
error( _('You have to create a config.inc.php!') ); |
|
28 |
} |
|
29 |
|
1
|
30 |
/************* |
74
|
31 |
* Constants * |
|
32 |
*************/ |
79
|
33 |
define('ROWAMOUNT', $ROWAMOUNT); |
1
|
34 |
|
|
35 |
if (isset($_GET["start"])) { |
79
|
36 |
define('ROWSTART', (($_GET["start"] - 1) * 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 |
|
|
59 |
|
1
|
60 |
/************* |
|
61 |
* Includes * |
|
62 |
*************/ |
|
63 |
|
|
64 |
require_once("error.inc.php"); |
|
65 |
require_once("auth.inc.php"); |
3
|
66 |
require_once("i18n.inc.php"); |
1
|
67 |
require_once("users.inc.php"); |
|
68 |
require_once("dns.inc.php"); |
|
69 |
require_once("record.inc.php"); |
|
70 |
|
82
|
71 |
$db = dbConnect(); |
|
72 |
doAuthenticate(); |
|
73 |
|
1
|
74 |
|
|
75 |
/************* |
|
76 |
* Functions * |
|
77 |
*************/ |
|
78 |
|
|
79 |
/* |
|
80 |
* Display the page option: [1] [2] .. [n] |
|
81 |
*/ |
|
82 |
|
|
83 |
function show_pages($amount,$rowamount,$id='') |
|
84 |
{ |
|
85 |
if ($amount > $rowamount) { |
|
86 |
if (!isset($_GET["start"])) $_GET["start"]=1; |
82
|
87 |
echo _('Show page') . ":<br>"; |
1
|
88 |
for ($i=1;$i<=ceil($amount / $rowamount);$i++) { |
|
89 |
if ($_GET["start"] == $i) { |
|
90 |
echo "[ <b>".$i."</b> ] "; |
|
91 |
} else { |
|
92 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i; |
|
93 |
if ($id!='') echo "&id=".$id; |
|
94 |
echo "\">".$i."</a> ] "; |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
/* |
|
101 |
* Display the alphabetic option: [0-9] [a] [b] .. [z] |
|
102 |
*/ |
|
103 |
|
29
|
104 |
function show_letters($letterstart,$userid=true) |
1
|
105 |
{ |
82
|
106 |
echo _('Show zones beginning with') . ":<br>"; |
29
|
107 |
|
|
108 |
$letter = "[[:digit:]]"; |
77
|
109 |
if ($letterstart == "1") |
29
|
110 |
{ |
|
111 |
echo "[ <span class=\"lettertaken\">0-9</span> ] "; |
|
112 |
} |
|
113 |
elseif (zone_letter_start($letter,$userid)) |
|
114 |
{ |
32
|
115 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=1\">0-9</a> ] "; |
29
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
echo "[ <span class=\"letternotavailble\">0-9</span> ] "; |
|
120 |
} |
1
|
121 |
|
29
|
122 |
foreach (range('a','z') as $letter) |
|
123 |
{ |
|
124 |
if ($letter == $letterstart) |
|
125 |
{ |
|
126 |
echo "[ <span class=\"lettertaken\">".$letter."</span> ] "; |
|
127 |
} |
|
128 |
elseif (zone_letter_start($letter,$userid)) |
|
129 |
{ |
|
130 |
echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] "; |
|
131 |
} |
|
132 |
else |
|
133 |
{ |
|
134 |
echo "[ <span class=\"letternotavailble\">".$letter."</span> ] "; |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
function zone_letter_start($letter,$userid=true) |
|
140 |
{ |
|
141 |
global $db; |
55
|
142 |
global $sql_regexp; |
82
|
143 |
$query = "SELECT |
|
144 |
domains.id AS domain_id, |
|
145 |
zones.owner, |
|
146 |
domains.name AS domainname |
|
147 |
FROM domains |
|
148 |
LEFT JOIN zones ON domains.id=zones.domain_id |
107
|
149 |
WHERE substring(domains.name,1,1) ".$sql_regexp." ".$db->quote("^".$letter); |
82
|
150 |
$db->setLimit(1); |
|
151 |
$result = $db->query($query); |
29
|
152 |
$numrows = $result->numRows(); |
82
|
153 |
if ( $numrows == "1" ) { |
29
|
154 |
return 1; |
82
|
155 |
} else { |
29
|
156 |
return 0; |
|
157 |
} |
1
|
158 |
} |
|
159 |
|
82
|
160 |
function error($msg) { |
|
161 |
if ($msg) { |
|
162 |
echo " <div class=\"error\">Error: " . $msg . "</div>\n"; |
|
163 |
} else { |
|
164 |
echo " <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n"; |
1
|
165 |
} |
|
166 |
} |
|
167 |
|
82
|
168 |
function success($msg) { |
|
169 |
if ($msg) { |
|
170 |
echo " <div class=\"success\">" . $msg . "</div>\n"; |
|
171 |
} else { |
|
172 |
echo " <div class=\"success\">" . _('Something has been successfully performed. What exactly, however, will remain a mystery.') . "</div>\n"; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
|
1
|
177 |
/* |
|
178 |
* Something has been done nicely, display a message and a back button. |
|
179 |
*/ |
|
180 |
function message($msg) |
|
181 |
{ |
|
182 |
include_once("header.inc.php"); |
|
183 |
?> |
71
|
184 |
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2><?php echo _('Success!'); ?></H2> |
1
|
185 |
<BR> |
|
186 |
<FONT STYLE="font-weight: Bold"> |
|
187 |
<P> |
71
|
188 |
<?php |
1
|
189 |
if($msg) |
|
190 |
{ |
|
191 |
echo nl2br($msg); |
|
192 |
} |
|
193 |
else |
|
194 |
{ |
4
|
195 |
echo _('Successful!'); |
1
|
196 |
} |
|
197 |
?> |
|
198 |
</P> |
|
199 |
<BR> |
|
200 |
<P> |
71
|
201 |
<a href="javascript:history.go(-1)"><< <?php echo _('back'); ?></a></FONT> |
1
|
202 |
</P> |
|
203 |
</TD></TR></TABLE></P> |
71
|
204 |
<?php |
1
|
205 |
include_once("footer.inc.php"); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/* |
|
210 |
* Reroute a user to a cleanpage of (if passed) arg |
|
211 |
*/ |
|
212 |
|
|
213 |
function clean_page($arg='') |
|
214 |
{ |
|
215 |
if (!$arg) |
|
216 |
{ |
|
217 |
header("Location: ".$_SERVER["PHP_SELF"]."?time=".time()); |
|
218 |
exit; |
|
219 |
} |
|
220 |
else |
|
221 |
{ |
|
222 |
if (preg_match('!\?!si', $arg)) |
|
223 |
{ |
|
224 |
$add = "&time="; |
|
225 |
} |
|
226 |
else |
|
227 |
{ |
|
228 |
$add = "?time="; |
|
229 |
} |
|
230 |
header("Location: $arg$add".time()); |
|
231 |
exit; |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
function get_status($res) |
|
237 |
{ |
|
238 |
if ($res == '0') |
|
239 |
{ |
4
|
240 |
return "<FONT CLASS=\"inactive\">" . _('Inactive') . "</FONT>"; |
1
|
241 |
} |
|
242 |
elseif ($res == '1') |
|
243 |
{ |
4
|
244 |
return "<FONT CLASS=\"active\">" . _('Active') . "</FONT>"; |
1
|
245 |
} |
|
246 |
} |
|
247 |
|
|
248 |
function parse_template_value($val, $domain, $webip, $mailip) |
|
249 |
{ |
|
250 |
$val = str_replace('##DOMAIN##', $domain, $val); |
|
251 |
$val = str_replace('##WEBIP##', $webip, $val); |
|
252 |
$val = str_replace('##MAILIP##', $mailip, $val); |
|
253 |
return $val; |
|
254 |
} |
|
255 |
|
|
256 |
|
|
257 |
/* |
|
258 |
* Validates an email address. |
|
259 |
* Checks if there is something before the at '@' sign and its followed by a domain and a tld of minimum 2 |
|
260 |
* and maximum of 4 characters. |
|
261 |
*/ |
|
262 |
function is_valid_email($email) |
|
263 |
{ |
|
264 |
if(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.([a-z]{2,6}$)", $email)) |
|
265 |
{ |
|
266 |
return false; |
|
267 |
} |
|
268 |
return true; |
|
269 |
} |
82
|
270 |
|
|
271 |
|
|
272 |
function v_num($string) { |
|
273 |
if (!eregi("^[0-9]+$", $string)) { |
|
274 |
return false ; |
|
275 |
} else { |
|
276 |
return true ; |
|
277 |
} |
|
278 |
} |
|
279 |
|
90
|
280 |
// Debug print |
91
|
281 |
function debug_print($var) { |
82
|
282 |
echo "<pre style=\"border: 2px solid blue;\">\n"; |
91
|
283 |
if (is_array($var)) { print_r($var) ; } else { echo $var ; } |
82
|
284 |
echo "</pre>\n"; |
|
285 |
} |
|
286 |
|
1
|
287 |
?> |