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
{
+ − 49
error ( "You have to create a config.inc.php!" );
+ − 50
}
+ − 51
+ − 52
if ( is_file ( dirname ( __FILE__ ) . '/../install.php' ))
+ − 53
{
+ − 54
error ( "You have to remove install.php before this program will run" );
+ − 55
}
+ − 56
+ − 57
if ( is_file ( dirname ( __FILE__ ) . '/../migrator.php' ))
+ − 58
{
+ − 59
error ( "You have to remove migrator.php before this program will run" );
+ − 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" );
+ − 73
require_once ( "users.inc.php" );
+ − 74
require_once ( "dns.inc.php" );
+ − 75
require_once ( "record.inc.php" );
+ − 76
+ − 77
+ − 78
/*************
+ − 79
* Functions *
+ − 80
*************/
+ − 81
+ − 82
/*
+ − 83
* Display the page option: [1] [2] .. [n]
+ − 84
*/
+ − 85
+ − 86
function show_pages ( $amount , $rowamount , $id = '' )
+ − 87
{
+ − 88
if ( $amount > $rowamount ) {
+ − 89
if ( ! isset ( $_GET [ "start" ])) $_GET [ "start" ] = 1 ;
+ − 90
echo "<br /><br />Show page " ;
+ − 91
for ( $i = 1 ; $i <= ceil ( $amount / $rowamount ); $i ++ ) {
+ − 92
if ( $_GET [ "start" ] == $i ) {
+ − 93
echo "[ <b>" . $i . "</b> ] " ;
+ − 94
} else {
+ − 95
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?start=" . $i ;
+ − 96
if ( $id != '' ) echo "&id=" . $id ;
+ − 97
echo " \" >" . $i . "</a> ] " ;
+ − 98
}
+ − 99
}
+ − 100
echo "</small>" ;
+ − 101
}
+ − 102
}
+ − 103
+ − 104
/*
+ − 105
* Display the alphabetic option: [0-9] [a] [b] .. [z]
+ − 106
*/
+ − 107
+ − 108
function show_letters ( $letterstart , $doms )
+ − 109
{
+ − 110
foreach ( $doms as $dom ) {
+ − 111
if ( is_numeric ( $dom [ "name" ][ 0 ])) {
+ − 112
$letter_taken [ "0" ] = 1 ;
+ − 113
} else {
+ − 114
$letter_taken [ $dom [ "name" ][ 0 ]] = 1 ;
+ − 115
}
+ − 116
}
+ − 117
+ − 118
echo "Show domains beginning with: <br />" ;
+ − 119
if ( $letterstart == 1 ) {
+ − 120
echo "[ <b>0-9</b> ] " ;
+ − 121
} elseif ( $letter_taken [ "0" ] != 1 ) {
+ − 122
echo "[ 0-9 ] " ;
+ − 123
} else {
+ − 124
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=1 \" >0-9</a> ] " ;
+ − 125
}
+ − 126
+ − 127
foreach ( range ( 'a' , 'z' ) as $letter ) {
+ − 128
if ( $letterstart === $letter ) {
+ − 129
echo "[ <b>" . $letter . "</b> ] " ;
+ − 130
} elseif ( $letter_taken [ $letter ] != 1 ) {
+ − 131
echo "[ <span style= \" color:#999 \" >" . $letter . "</span> ] " ;
+ − 132
} else {
+ − 133
echo "[ <a href= \" " . $_SERVER [ "PHP_SELF" ] . "?letter=" . $letter . " \" >" . $letter . "</a> ] " ;
+ − 134
}
+ − 135
}
+ − 136
}
+ − 137
+ − 138
/*
+ − 139
* Print a nice useraimed error.
+ − 140
*/
+ − 141
function error ( $msg )
+ − 142
{
+ − 143
// General function for printing critical errors.
+ − 144
if ( $msg )
+ − 145
{
+ − 146
include_once ( "header.inc.php" );
+ − 147
?>
+ − 148
<P><TABLE CLASS="error"><TR><TD CLASS="error"><H2>Oops! An error occured!</H2>
+ − 149
<BR>
+ − 150
<FONT STYLE="font-weight: Bold"> <? = nl2br ( $msg ) ?> <BR><BR><a href="javascript:history.go(-1)"><< back</a></FONT><BR></TD></TR></TABLE></P>
+ − 151
<?
+ − 152
include_once ( "footer.inc.php" );
+ − 153
die ();
+ − 154
}
+ − 155
else
+ − 156
{
+ − 157
include_once ( "footer.inc.php" );
+ − 158
die ( "No error specified!" );
+ − 159
}
+ − 160
}
+ − 161
+ − 162
/*
+ − 163
* Something has been done nicely, display a message and a back button.
+ − 164
*/
+ − 165
function message ( $msg )
+ − 166
{
+ − 167
include_once ( "header.inc.php" );
+ − 168
?>
+ − 169
<P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2>Success!</H2>
+ − 170
<BR>
+ − 171
<FONT STYLE="font-weight: Bold">
+ − 172
<P>
+ − 173
<?
+ − 174
if ( $msg )
+ − 175
{
+ − 176
echo nl2br ( $msg );
+ − 177
}
+ − 178
else
+ − 179
{
+ − 180
echo "Successful!" ;
+ − 181
}
+ − 182
?>
+ − 183
</P>
+ − 184
<BR>
+ − 185
<P>
+ − 186
<a href="javascript:history.go(-1)"><< back</a></FONT>
+ − 187
</P>
+ − 188
</TD></TR></TABLE></P>
+ − 189
<?
+ − 190
include_once ( "footer.inc.php" );
+ − 191
}
+ − 192
+ − 193
+ − 194
/*
+ − 195
* Reroute a user to a cleanpage of (if passed) arg
+ − 196
*/
+ − 197
+ − 198
function clean_page ( $arg = '' )
+ − 199
{
+ − 200
if ( ! $arg )
+ − 201
{
+ − 202
header ( "Location: " . $_SERVER [ "PHP_SELF" ] . "?time=" . time ());
+ − 203
exit ;
+ − 204
}
+ − 205
else
+ − 206
{
+ − 207
if ( preg_match ( '!\?!si' , $arg ))
+ − 208
{
+ − 209
$add = "&time=" ;
+ − 210
}
+ − 211
else
+ − 212
{
+ − 213
$add = "?time=" ;
+ − 214
}
+ − 215
header ( "Location: $arg$add " . time ());
+ − 216
exit ;
+ − 217
}
+ − 218
}
+ − 219
+ − 220
function level ( $l )
+ − 221
{
+ − 222
if ( $_SESSION [ "level" ] >= $l )
+ − 223
{
+ − 224
return 1 ;
+ − 225
}
+ − 226
else
+ − 227
{
+ − 228
return 0 ;
+ − 229
}
+ − 230
}
+ − 231
+ − 232
function xs ( $zoneid )
+ − 233
{
+ − 234
global $db ;
+ − 235
if ( is_numeric ( $zoneid ) && is_numeric ( $_SESSION [ "level" ]))
+ − 236
{
+ − 237
$result = $db -> query ( "SELECT id FROM zones WHERE owner=" . $_SESSION [ "userid" ] . " AND domain_id= $zoneid " );
+ − 238
$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" );
+ − 239
+ − 240
if ( $result -> numRows () == 1 || $_SESSION [ "level" ] >= 5 )
+ − 241
{
+ − 242
$_SESSION [ $zoneid . "_ispartial" ] = 0 ;
+ − 243
return true ;
+ − 244
}
+ − 245
elseif ( $result_extra -> numRows () == 1 )
+ − 246
{
+ − 247
$_SESSION [ $zoneid . "_ispartial" ] = 1 ;
+ − 248
return true ;
+ − 249
}
+ − 250
else
+ − 251
{
+ − 252
return false ;
+ − 253
}
+ − 254
}
+ − 255
else
+ − 256
{
+ − 257
return false ;
+ − 258
}
+ − 259
}
+ − 260
+ − 261
function get_status ( $res )
+ − 262
{
+ − 263
if ( $res == '0' )
+ − 264
{
+ − 265
return "<FONT CLASS= \" inactive \" >Inactive</FONT>" ;
+ − 266
}
+ − 267
elseif ( $res == '1' )
+ − 268
{
+ − 269
return "<FONT CLASS= \" active \" >Active</FONT>" ;
+ − 270
}
+ − 271
}
+ − 272
+ − 273
function parse_template_value ( $val , $domain , $webip , $mailip )
+ − 274
{
+ − 275
$val = str_replace ( '##DOMAIN##' , $domain , $val );
+ − 276
$val = str_replace ( '##WEBIP##' , $webip , $val );
+ − 277
$val = str_replace ( '##MAILIP##' , $mailip , $val );
+ − 278
return $val ;
+ − 279
}
+ − 280
+ − 281
+ − 282
/*
+ − 283
* Validates an email address.
+ − 284
* Checks if there is something before the at '@' sign and its followed by a domain and a tld of minimum 2
+ − 285
* and maximum of 4 characters.
+ − 286
*/
+ − 287
function is_valid_email ( $email )
+ − 288
{
+ − 289
if ( ! eregi ( "^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])* \\ .([a-z]{2,6}$)" , $email ))
+ − 290
{
+ − 291
return false ;
+ − 292
}
+ − 293
return true ;
+ − 294
}
+ − 295
?>