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