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
138
+ − 50
$valid_tlds = array (
+ − 51
"ac" , "ad" , "ae" , "aero" , "af" , "ag" , "ai" , "al" , "am" , "an" , "ao" , "aq" , "ar" ,
+ − 52
"arpa" , "as" , "asia" , "at" , "au" , "aw" , "ax" , "az" , "ba" , "bb" , "bd" , "be" ,
+ − 53
"bf" , "bg" , "bh" , "bi" , "biz" , "bj" , "bm" , "bn" , "bo" , "br" , "bs" , "bt" , "bv" ,
+ − 54
"bw" , "by" , "bz" , "ca" , "cat" , "cc" , "cd" , "cf" , "cg" , "ch" , "ci" , "ck" , "cl" ,
+ − 55
"cm" , "cn" , "co" , "com" , "coop" , "cr" , "cu" , "cv" , "cx" , "cy" , "cz" , "de" , "dj" ,
+ − 56
"dk" , "dm" , "do" , "dz" , "ec" , "edu" , "ee" , "eg" , "er" , "es" , "et" , "eu" , "fi" ,
+ − 57
"fj" , "fk" , "fm" , "fo" , "fr" , "ga" , "gb" , "gd" , "ge" , "gf" , "gg" , "gh" , "gi" ,
+ − 58
"gl" , "gm" , "gn" , "gov" , "gp" , "gq" , "gr" , "gs" , "gt" , "gu" , "gw" , "gy" , "hk" ,
+ − 59
"hm" , "hn" , "hr" , "ht" , "hu" , "id" , "ie" , "il" , "im" , "in" , "info" , "int" , "io" ,
+ − 60
"iq" , "ir" , "is" , "it" , "je" , "jm" , "jo" , "jobs" , "jp" , "ke" , "kg" , "kh" , "ki" ,
+ − 61
"km" , "kn" , "kp" , "kr" , "kw" , "ky" , "kz" , "la" , "lb" , "lc" , "li" , "lk" , "lr" ,
+ − 62
"ls" , "lt" , "lu" , "lv" , "ly" , "ma" , "mc" , "md" , "me" , "mg" , "mh" , "mil" , "mk" ,
+ − 63
"ml" , "mm" , "mn" , "mo" , "mobi" , "mp" , "mq" , "mr" , "ms" , "mt" , "mu" , "museum" ,
+ − 64
"mv" , "mw" , "mx" , "my" , "mz" , "na" , "name" , "nc" , "ne" , "net" , "nf" , "ng" , "ni" ,
+ − 65
"nl" , "no" , "np" , "nr" , "nu" , "nz" , "om" , "org" , "pa" , "pe" , "pf" , "pg" , "ph" ,
+ − 66
"pk" , "pl" , "pm" , "pn" , "pr" , "pro" , "ps" , "pt" , "pw" , "py" , "qa" , "re" , "ro" ,
+ − 67
"rs" , "ru" , "rw" , "sa" , "sb" , "sc" , "sd" , "se" , "sg" , "sh" , "si" , "sj" , "sk" ,
+ − 68
"sl" , "sm" , "sn" , "so" , "sr" , "st" , "su" , "sv" , "sy" , "sz" , "tc" , "td" , "tel" ,
+ − 69
"tf" , "tg" , "th" , "tj" , "tk" , "tl" , "tm" , "tn" , "to" , "tp" , "tr" , "travel" ,
+ − 70
"tt" , "tv" , "tw" , "tz" , "ua" , "ug" , "uk" , "um" , "us" , "uy" , "uz" , "va" , "vc" ,
+ − 71
"ve" , "vg" , "vi" , "vn" , "vu" , "wf" , "ws" , "xn--0zwm56d" , "xn--11b5bs3a9aj6g" ,
+ − 72
"xn--80akhbyknj4f" , "xn--9t4b11yi5a" , "xn--deba0ad" , "xn--g6w251d" ,
+ − 73
"xn--hgbk6aj7f53bba" , "xn--hlcj6aya9esc7a" , "xn--jxalpdlp" , "xn--kgbechtv" ,
+ − 74
"xn--zckzah" , "ye" , "yt" , "yu" , "za" , "zm" , "zw" );
+ − 75
+ − 76
1
+ − 77
/* Database connection */
+ − 78
+ − 79
require_once ( "database.inc.php" );
+ − 80
// Generates $db variable to access database.
+ − 81
13
+ − 82
+ − 83
// Array of the available zone types
+ − 84
$server_types = array ( "MASTER" , "SLAVE" , "NATIVE" );
+ − 85
136
+ − 86
// $rtypes - array of possible record types
193
+ − 87
$rtypes = array ( 'A' , 'AAAA' , 'CNAME' , 'HINFO' , 'MX' , 'NAPTR' , 'NS' , 'PTR' , 'SOA' , 'SPF' , 'SRV' , 'SSHFP' , 'TXT' );
136
+ − 88
+ − 89
// If fancy records is enabled, extend this field.
+ − 90
if ( $dns_fancy ) {
193
+ − 91
$rtypes [ 14 ] = 'URL' ;
+ − 92
$rtypes [ 15 ] = 'MBOXFW' ;
136
+ − 93
}
+ − 94
+ − 95
// $template - array of records that will be applied when adding a new zone file
+ − 96
$template = array (
+ − 97
array (
+ − 98
+ − 99
"name" => "##DOMAIN##" ,
+ − 100
"type" => "SOA" ,
+ − 101
"content" => " $dns_ns1 $dns_hostmaster 0" ,
+ − 102
"ttl" => " $dns_ttl " ,
+ − 103
"prio" => ""
+ − 104
),
+ − 105
array (
+ − 106
"name" => "##DOMAIN##" ,
+ − 107
"type" => "NS" ,
+ − 108
"content" => " $dns_ns1 " ,
+ − 109
"ttl" => " $dns_ttl " ,
+ − 110
"prio" => ""
+ − 111
),
+ − 112
array (
+ − 113
"name" => "##DOMAIN##" ,
+ − 114
"type" => "NS" ,
+ − 115
"content" => " $dns_ns2 " ,
+ − 116
"ttl" => " $dns_ttl " ,
+ − 117
"prio" => ""
+ − 118
),
+ − 119
array (
+ − 120
"name" => "www.##DOMAIN##" ,
+ − 121
"type" => "A" ,
+ − 122
"content" => "##WEBIP##" ,
+ − 123
"ttl" => " $dns_ttl " ,
+ − 124
"prio" => ""
+ − 125
),
+ − 126
array (
+ − 127
"name" => "##DOMAIN##" ,
+ − 128
"type" => "A" ,
+ − 129
"content" => "##WEBIP##" ,
+ − 130
"ttl" => " $dns_ttl " ,
+ − 131
"prio" => ""
+ − 132
),
+ − 133
array (
+ − 134
"name" => "mail.##DOMAIN##" ,
+ − 135
"type" => "A" ,
+ − 136
"content" => "##MAILIP##" ,
+ − 137
"ttl" => " $dns_ttl " ,
+ − 138
"prio" => ""
+ − 139
),
+ − 140
array (
+ − 141
"name" => "localhost.##DOMAIN##" ,
+ − 142
"type" => "A" ,
+ − 143
"content" => "127.0.0.1" ,
+ − 144
"ttl" => " $dns_ttl " ,
+ − 145
"prio" => ""
+ − 146
),
+ − 147
array (
+ − 148
"name" => "##DOMAIN##" ,
+ − 149
"type" => "MX" ,
+ − 150
"content" => "mail.##DOMAIN##" ,
+ − 151
"ttl" => " $dns_ttl " ,
+ − 152
"prio" => "10"
+ − 153
)
+ − 154
);
+ − 155
13
+ − 156
1
+ − 157
/*************
+ − 158
* Includes *
+ − 159
*************/
+ − 160
+ − 161
require_once ( "error.inc.php" );
+ − 162
require_once ( "auth.inc.php" );
3
+ − 163
require_once ( "i18n.inc.php" );
1
+ − 164
require_once ( "users.inc.php" );
+ − 165
require_once ( "dns.inc.php" );
+ − 166
require_once ( "record.inc.php" );
+ − 167
82
+ − 168
$db = dbConnect ();
+ − 169
doAuthenticate ();
+ − 170
1
+ − 171
+ − 172
/*************
+ − 173
* Functions *
+ − 174
*************/
+ − 175
+ − 176
/*
+ − 177
* Display the page option: [1] [2] .. [n]
+ − 178
*/
+ − 179
+ − 180
function show_pages ( $amount , $rowamount , $id = '' )
+ − 181
{
+ − 182
if ( $amount > $rowamount ) {
+ − 183
if ( ! isset ( $_GET [ "start" ])) $_GET [ "start" ] = 1 ;
82
+ − 184
echo _ ( 'Show page' ) . ":<br>" ;
1
+ − 185
for ( $i = 1 ; $i <= ceil ( $amount / $rowamount ); $i ++ ) {
+ − 186
if ( $_GET [ "start" ] == $i ) {
+ − 187
echo "[ <b>" . $i . "</b> ] " ;
+ − 188
} else {
+ − 189
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?start=" . $i ;
+ − 190
if ( $id != '' ) echo "&id=" . $id ;
+ − 191
echo " \" >" . $i . "</a> ] " ;
+ − 192
}
+ − 193
}
+ − 194
}
+ − 195
}
+ − 196
+ − 197
/*
+ − 198
* Display the alphabetic option: [0-9] [a] [b] .. [z]
+ − 199
*/
+ − 200
29
+ − 201
function show_letters ( $letterstart , $userid = true )
1
+ − 202
{
82
+ − 203
echo _ ( 'Show zones beginning with' ) . ":<br>" ;
29
+ − 204
+ − 205
$letter = "[[:digit:]]" ;
77
+ − 206
if ( $letterstart == "1" )
29
+ − 207
{
+ − 208
echo "[ <span class= \" lettertaken \" >0-9</span> ] " ;
+ − 209
}
+ − 210
elseif ( zone_letter_start ( $letter , $userid ))
+ − 211
{
32
+ − 212
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=1 \" >0-9</a> ] " ;
29
+ − 213
}
+ − 214
else
+ − 215
{
+ − 216
echo "[ <span class= \" letternotavailble \" >0-9</span> ] " ;
+ − 217
}
1
+ − 218
29
+ − 219
foreach ( range ( 'a' , 'z' ) as $letter )
+ − 220
{
+ − 221
if ( $letter == $letterstart )
+ − 222
{
+ − 223
echo "[ <span class= \" lettertaken \" >" . $letter . "</span> ] " ;
+ − 224
}
+ − 225
elseif ( zone_letter_start ( $letter , $userid ))
+ − 226
{
+ − 227
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=" . $letter . " \" >" . $letter . "</a> ] " ;
+ − 228
}
+ − 229
else
+ − 230
{
+ − 231
echo "[ <span class= \" letternotavailble \" >" . $letter . "</span> ] " ;
+ − 232
}
+ − 233
}
+ − 234
}
+ − 235
+ − 236
function zone_letter_start ( $letter , $userid = true )
+ − 237
{
+ − 238
global $db ;
55
+ − 239
global $sql_regexp ;
82
+ − 240
$query = "SELECT
+ − 241
domains.id AS domain_id,
+ − 242
zones.owner,
+ − 243
domains.name AS domainname
+ − 244
FROM domains
+ − 245
LEFT JOIN zones ON domains.id=zones.domain_id
192
+ − 246
WHERE substring(domains.name,1,1) " . $sql_regexp . " " . $db -> quote ( "^" . $letter , 'text' );
82
+ − 247
$db -> setLimit ( 1 );
+ − 248
$result = $db -> query ( $query );
29
+ − 249
$numrows = $result -> numRows ();
82
+ − 250
if ( $numrows == "1" ) {
29
+ − 251
return 1 ;
82
+ − 252
} else {
29
+ − 253
return 0 ;
+ − 254
}
1
+ − 255
}
+ − 256
82
+ − 257
function error ( $msg ) {
+ − 258
if ( $msg ) {
+ − 259
echo " <div class= \" error \" >Error: " . $msg . "</div> \n " ;
+ − 260
} else {
+ − 261
echo " <div class= \" error \" >" . _ ( 'An unknown error has occurred.' ) . "</div> \n " ;
1
+ − 262
}
+ − 263
}
+ − 264
82
+ − 265
function success ( $msg ) {
+ − 266
if ( $msg ) {
+ − 267
echo " <div class= \" success \" >" . $msg . "</div> \n " ;
+ − 268
} else {
+ − 269
echo " <div class= \" success \" >" . _ ( 'Something has been successfully performed. What exactly, however, will remain a mystery.' ) . "</div> \n " ;
+ − 270
}
+ − 271
}
+ − 272
+ − 273
1
+ − 274
/*
+ − 275
* Something has been done nicely, display a message and a back button.
+ − 276
*/
+ − 277
function message ( $msg )
+ − 278
{
+ − 279
include_once ( "header.inc.php" );
+ − 280
?>
71
+ − 281
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2> <?php echo _ ( 'Success!' ); ?> </H2>
1
+ − 282
<BR>
+ − 283
<FONT STYLE="font-weight: Bold">
+ − 284
<P>
71
+ − 285
<?php
1
+ − 286
if ( $msg )
+ − 287
{
+ − 288
echo nl2br ( $msg );
+ − 289
}
+ − 290
else
+ − 291
{
4
+ − 292
echo _ ( 'Successful!' );
1
+ − 293
}
+ − 294
?>
+ − 295
</P>
+ − 296
<BR>
+ − 297
<P>
71
+ − 298
<a href="javascript:history.go(-1)"><< <?php echo _ ( 'back' ); ?> </a></FONT>
1
+ − 299
</P>
+ − 300
</TD></TR></TABLE></P>
71
+ − 301
<?php
1
+ − 302
include_once ( "footer.inc.php" );
+ − 303
}
+ − 304
+ − 305
+ − 306
/*
+ − 307
* Reroute a user to a cleanpage of (if passed) arg
+ − 308
*/
+ − 309
+ − 310
function clean_page ( $arg = '' )
+ − 311
{
+ − 312
if ( ! $arg )
+ − 313
{
+ − 314
header ( "Location: " . $_SERVER [ "PHP_SELF" ] . "?time=" . time ());
+ − 315
exit ;
+ − 316
}
+ − 317
else
+ − 318
{
+ − 319
if ( preg_match ( '!\?!si' , $arg ))
+ − 320
{
+ − 321
$add = "&time=" ;
+ − 322
}
+ − 323
else
+ − 324
{
+ − 325
$add = "?time=" ;
+ − 326
}
+ − 327
header ( "Location: $arg$add " . time ());
+ − 328
exit ;
+ − 329
}
+ − 330
}
+ − 331
+ − 332
+ − 333
function get_status ( $res )
+ − 334
{
+ − 335
if ( $res == '0' )
+ − 336
{
4
+ − 337
return "<FONT CLASS= \" inactive \" >" . _ ( 'Inactive' ) . "</FONT>" ;
1
+ − 338
}
+ − 339
elseif ( $res == '1' )
+ − 340
{
4
+ − 341
return "<FONT CLASS= \" active \" >" . _ ( 'Active' ) . "</FONT>" ;
1
+ − 342
}
+ − 343
}
+ − 344
+ − 345
function parse_template_value ( $val , $domain , $webip , $mailip )
+ − 346
{
+ − 347
$val = str_replace ( '##DOMAIN##' , $domain , $val );
+ − 348
$val = str_replace ( '##WEBIP##' , $webip , $val );
+ − 349
$val = str_replace ( '##MAILIP##' , $mailip , $val );
+ − 350
return $val ;
+ − 351
}
+ − 352
+ − 353
176
+ − 354
function is_valid_email ( $address ) {
+ − 355
$fields = split ( "@" , $address , 2 );
+ − 356
if (( ! eregi ( "^[0-9a-z]([-_.]?[0-9a-z])*$" , $fields [ 0 ])) || ! is_valid_hostname_fqdn ( $fields [ 1 ], 0 )) {
1
+ − 357
return false ;
+ − 358
}
+ − 359
return true ;
+ − 360
}
82
+ − 361
+ − 362
+ − 363
function v_num ( $string ) {
+ − 364
if ( ! eregi ( "^[0-9]+$" , $string )) {
+ − 365
return false ;
+ − 366
} else {
+ − 367
return true ;
+ − 368
}
+ − 369
}
+ − 370
90
+ − 371
// Debug print
91
+ − 372
function debug_print ( $var ) {
82
+ − 373
echo "<pre style= \" border: 2px solid blue; \" > \n " ;
91
+ − 374
if ( is_array ( $var )) { print_r ( $var ) ; } else { echo $var ; }
82
+ − 375
echo "</pre> \n " ;
+ − 376
}
+ − 377
1
+ − 378
?>