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