1
+ − 1
<?
+ − 2
session_start ();
+ − 3
// +--------------------------------------------------------------------+
+ − 4
// | PowerAdmin |
+ − 5
// +--------------------------------------------------------------------+
+ − 6
// | Copyright (c) 1997-2002 The PowerAdmin Team |
+ − 7
// +--------------------------------------------------------------------+
+ − 8
// | This source file is subject to the license carried by the overal |
+ − 9
// | program PowerAdmin as found on http://poweradmin.sf.net |
+ − 10
// | The PowerAdmin program falls under the QPL License: |
+ − 11
// | http://www.trolltech.com/developer/licensing/qpl.html |
+ − 12
// +--------------------------------------------------------------------+
+ − 13
// | Authors: Roeland Nieuwenhuis <trancer <AT> trancer <DOT> nl> |
+ − 14
// | Sjeemz <sjeemz <AT> sjeemz <DOT> nl> |
+ − 15
// +--------------------------------------------------------------------+
+ − 16
+ − 17
// Filename: toolkit.inc.php
+ − 18
// Startdate: 26-10-2002
+ − 19
// Description: general functions needed on a large variety of locations.
+ − 20
// Kills the db.inc.php.
+ − 21
// If you include this file you include the whole 'backend'
+ − 22
//
+ − 23
// $Id: toolkit.inc.php,v 1.13 2003/02/24 01:46:31 azurazu Exp $
+ − 24
//
+ − 25
+ − 26
/*************
+ − 27
* Constants *
+ − 28
*************/
+ − 29
+ − 30
define ( ROWAMOUNT , 500 );
+ − 31
+ − 32
if ( isset ( $_GET [ "start" ])) {
+ − 33
define ( ROWSTART , (( $_GET [ "start" ] - 1 ) * ROWAMOUNT ));
+ − 34
} else {
+ − 35
define ( ROWSTART , 0 );
+ − 36
}
+ − 37
+ − 38
if ( isset ( $_GET [ "letter" ])) {
+ − 39
define ( LETTERSTART , $_GET [ "letter" ]);
+ − 40
$_SESSION [ "letter" ] = $_GET [ "letter" ];
+ − 41
} elseif ( isset ( $_SESSION [ "letter" ])) {
+ − 42
define ( LETTERSTART , $_SESSION [ "letter" ]);
+ − 43
} else {
+ − 44
define ( LETTERSTART , "a" );
+ − 45
}
+ − 46
+ − 47
if ( !@ include_once ( "config.inc.php" ))
+ − 48
{
6
+ − 49
error ( _ ( 'You have to create a config.inc.php!' ) );
1
+ − 50
}
+ − 51
+ − 52
if ( is_file ( dirname ( __FILE__ ) . '/../install.php' ))
+ − 53
{
6
+ − 54
error ( _ ( 'You have to remove install.php before this program will run' ) );
1
+ − 55
}
+ − 56
+ − 57
if ( is_file ( dirname ( __FILE__ ) . '/../migrator.php' ))
+ − 58
{
6
+ − 59
error ( _ ( 'You have to remove migrator.php before this program will run' ) );
1
+ − 60
}
+ − 61
+ − 62
/* Database connection */
+ − 63
+ − 64
require_once ( "database.inc.php" );
+ − 65
// Generates $db variable to access database.
+ − 66
+ − 67
/*************
+ − 68
* Includes *
+ − 69
*************/
+ − 70
+ − 71
require_once ( "error.inc.php" );
+ − 72
require_once ( "auth.inc.php" );
3
+ − 73
require_once ( "i18n.inc.php" );
1
+ − 74
require_once ( "users.inc.php" );
+ − 75
require_once ( "dns.inc.php" );
+ − 76
require_once ( "record.inc.php" );
+ − 77
+ − 78
+ − 79
/*************
+ − 80
* Functions *
+ − 81
*************/
+ − 82
+ − 83
/*
+ − 84
* Display the page option: [1] [2] .. [n]
+ − 85
*/
+ − 86
+ − 87
function show_pages ( $amount , $rowamount , $id = '' )
+ − 88
{
+ − 89
if ( $amount > $rowamount ) {
+ − 90
if ( ! isset ( $_GET [ "start" ])) $_GET [ "start" ] = 1 ;
4
+ − 91
echo "<br /><br />" . _ ( 'Show page' ) . " " ;
1
+ − 92
for ( $i = 1 ; $i <= ceil ( $amount / $rowamount ); $i ++ ) {
+ − 93
if ( $_GET [ "start" ] == $i ) {
+ − 94
echo "[ <b>" . $i . "</b> ] " ;
+ − 95
} else {
+ − 96
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?start=" . $i ;
+ − 97
if ( $id != '' ) echo "&id=" . $id ;
+ − 98
echo " \" >" . $i . "</a> ] " ;
+ − 99
}
+ − 100
}
+ − 101
echo "</small>" ;
+ − 102
}
+ − 103
}
+ − 104
+ − 105
/*
+ − 106
* Display the alphabetic option: [0-9] [a] [b] .. [z]
+ − 107
*/
+ − 108
+ − 109
function show_letters ( $letterstart , $doms )
+ − 110
{
+ − 111
foreach ( $doms as $dom ) {
+ − 112
if ( is_numeric ( $dom [ "name" ][ 0 ])) {
+ − 113
$letter_taken [ "0" ] = 1 ;
+ − 114
} else {
+ − 115
$letter_taken [ $dom [ "name" ][ 0 ]] = 1 ;
+ − 116
}
+ − 117
}
+ − 118
4
+ − 119
echo _ ( 'Show domains beginning with:' ) . "<br />" ;
1
+ − 120
if ( $letterstart == 1 ) {
+ − 121
echo "[ <b>0-9</b> ] " ;
+ − 122
} elseif ( $letter_taken [ "0" ] != 1 ) {
+ − 123
echo "[ 0-9 ] " ;
+ − 124
} else {
+ − 125
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=1 \" >0-9</a> ] " ;
+ − 126
}
+ − 127
+ − 128
foreach ( range ( 'a' , 'z' ) as $letter ) {
+ − 129
if ( $letterstart === $letter ) {
+ − 130
echo "[ <b>" . $letter . "</b> ] " ;
+ − 131
} elseif ( $letter_taken [ $letter ] != 1 ) {
+ − 132
echo "[ <span style= \" color:#999 \" >" . $letter . "</span> ] " ;
+ − 133
} else {
+ − 134
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=" . $letter . " \" >" . $letter . "</a> ] " ;
+ − 135
}
+ − 136
}
+ − 137
}
+ − 138
+ − 139
/*
+ − 140
* Print a nice useraimed error.
+ − 141
*/
+ − 142
function error ( $msg )
+ − 143
{
+ − 144
// General function for printing critical errors.
+ − 145
if ( $msg )
+ − 146
{
+ − 147
include_once ( "header.inc.php" );
+ − 148
?>
4
+ − 149
<P><TABLE CLASS="error"><TR><TD CLASS="error"><H2> <? echo _ ( 'Oops! An error occured!' ); ?> </H2>
1
+ − 150
<BR>
4
+ − 151
<FONT STYLE="font-weight: Bold"> <? = nl2br ( $msg ) ?> <BR><BR><a href="javascript:history.go(-1)"><< <? echo _ ( 'back' ); ?> </a></FONT><BR></TD></TR></TABLE></P>
1
+ − 152
<?
+ − 153
include_once ( "footer.inc.php" );
+ − 154
die ();
+ − 155
}
+ − 156
else
+ − 157
{
+ − 158
include_once ( "footer.inc.php" );
+ − 159
die ( "No error specified!" );
+ − 160
}
+ − 161
}
+ − 162
+ − 163
/*
+ − 164
* Something has been done nicely, display a message and a back button.
+ − 165
*/
+ − 166
function message ( $msg )
+ − 167
{
+ − 168
include_once ( "header.inc.php" );
+ − 169
?>
4
+ − 170
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2> <? echo _ ( 'Success!' ); ?> </H2>
1
+ − 171
<BR>
+ − 172
<FONT STYLE="font-weight: Bold">
+ − 173
<P>
+ − 174
<?
+ − 175
if ( $msg )
+ − 176
{
+ − 177
echo nl2br ( $msg );
+ − 178
}
+ − 179
else
+ − 180
{
4
+ − 181
echo _ ( 'Successful!' );
1
+ − 182
}
+ − 183
?>
+ − 184
</P>
+ − 185
<BR>
+ − 186
<P>
4
+ − 187
<a href="javascript:history.go(-1)"><< <? echo _ ( 'back' ); ?> </a></FONT>
1
+ − 188
</P>
+ − 189
</TD></TR></TABLE></P>
+ − 190
<?
+ − 191
include_once ( "footer.inc.php" );
+ − 192
}
+ − 193
+ − 194
+ − 195
/*
+ − 196
* Reroute a user to a cleanpage of (if passed) arg
+ − 197
*/
+ − 198
+ − 199
function clean_page ( $arg = '' )
+ − 200
{
+ − 201
if ( ! $arg )
+ − 202
{
+ − 203
header ( "Location: " . $_SERVER [ "PHP_SELF" ] . "?time=" . time ());
+ − 204
exit ;
+ − 205
}
+ − 206
else
+ − 207
{
+ − 208
if ( preg_match ( '!\?!si' , $arg ))
+ − 209
{
+ − 210
$add = "&time=" ;
+ − 211
}
+ − 212
else
+ − 213
{
+ − 214
$add = "?time=" ;
+ − 215
}
+ − 216
header ( "Location: $arg$add " . time ());
+ − 217
exit ;
+ − 218
}
+ − 219
}
+ − 220
+ − 221
function level ( $l )
+ − 222
{
+ − 223
if ( $_SESSION [ "level" ] >= $l )
+ − 224
{
+ − 225
return 1 ;
+ − 226
}
+ − 227
else
+ − 228
{
+ − 229
return 0 ;
+ − 230
}
+ − 231
}
+ − 232
+ − 233
function xs ( $zoneid )
+ − 234
{
+ − 235
global $db ;
+ − 236
if ( is_numeric ( $zoneid ) && is_numeric ( $_SESSION [ "level" ]))
+ − 237
{
+ − 238
$result = $db -> query ( "SELECT id FROM zones WHERE owner=" . $_SESSION [ "userid" ] . " AND domain_id= $zoneid " );
+ − 239
$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" );
+ − 240
+ − 241
if ( $result -> numRows () == 1 || $_SESSION [ "level" ] >= 5 )
+ − 242
{
+ − 243
$_SESSION [ $zoneid . "_ispartial" ] = 0 ;
+ − 244
return true ;
+ − 245
}
+ − 246
elseif ( $result_extra -> numRows () == 1 )
+ − 247
{
+ − 248
$_SESSION [ $zoneid . "_ispartial" ] = 1 ;
+ − 249
return true ;
+ − 250
}
+ − 251
else
+ − 252
{
+ − 253
return false ;
+ − 254
}
+ − 255
}
+ − 256
else
+ − 257
{
+ − 258
return false ;
+ − 259
}
+ − 260
}
+ − 261
+ − 262
function get_status ( $res )
+ − 263
{
+ − 264
if ( $res == '0' )
+ − 265
{
4
+ − 266
return "<FONT CLASS= \" inactive \" >" . _ ( 'Inactive' ) . "</FONT>" ;
1
+ − 267
}
+ − 268
elseif ( $res == '1' )
+ − 269
{
4
+ − 270
return "<FONT CLASS= \" active \" >" . _ ( 'Active' ) . "</FONT>" ;
1
+ − 271
}
+ − 272
}
+ − 273
+ − 274
function parse_template_value ( $val , $domain , $webip , $mailip )
+ − 275
{
+ − 276
$val = str_replace ( '##DOMAIN##' , $domain , $val );
+ − 277
$val = str_replace ( '##WEBIP##' , $webip , $val );
+ − 278
$val = str_replace ( '##MAILIP##' , $mailip , $val );
+ − 279
return $val ;
+ − 280
}
+ − 281
+ − 282
+ − 283
/*
+ − 284
* Validates an email address.
+ − 285
* Checks if there is something before the at '@' sign and its followed by a domain and a tld of minimum 2
+ − 286
* and maximum of 4 characters.
+ − 287
*/
+ − 288
function is_valid_email ( $email )
+ − 289
{
+ − 290
if ( ! eregi ( "^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])* \\ .([a-z]{2,6}$)" , $email ))
+ − 291
{
+ − 292
return false ;
+ − 293
}
+ − 294
return true ;
+ − 295
}
+ − 296
?>