Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/setup.php
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>web://cp setup script</title>
<meta name="description" content="web://cp setup script">
<style type="text/css">
<!--
/* Body Style */
body	{ font-family: Arial;  font-size:16px; margin: 0; background-color:#F5F5F5; }

/* <a> Links Style */
a	{ text-decoration:underline; 
	  color:#2d2d2d;
	}
a:hover	{ text-decoration:underline; 
	  color:#464646;
	}

/* web://cp use the following classes */

/* Font Style & Types */
.small	{ font-size:11px; }
.normal	{ font-size:16px; }
.big	{ font-size:18px; }

/* Table Style */
.tbltop {background-color: #5B7B9C; color: #f5f5f5; font-size: 17px; font: bold; text-align: right}
.row1 	{ background-color:#e9e9e9; }
.row2	{ background-color:#E2EAF2; }
.tblbg {background-color: #DADADA}
-->
</style>
<script language='JavaScript' src='script.js'></script>
</head>
<body><br>
<div align='center'><big>web://cp setup script</big></div><br>

<?
// Set these vbls null if not set - supresses warnings with reporting level E_ALL:
$check_vbls=array(
	"username",
	"cp",
	"lang",
	"framed",
	"framename",
	"number",
	"user",
	"data",
	"bandwidth"
);

foreach($check_vbls as $vbl){
	!isset($$vbl) && $$vbl="";
}

// include needed filed if necessary
if ($cfg['httpd_mode'] != 'webcp') {
	$tmp = "config.inc.php";
	include($tmp);
	$tmp = "functions.inc.phps";
	include($tmp);
}

// load default language
include("lang/".$cfg['defaultlang'].".phps");

// can't connect to database server
if (!@mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass'])) {
	echo "<div align='center'>Error: Web://cp is not configured correctly. Please check your settings.</div></body></html>";
	return false;
}

// database doesnt exist
if (!@mysql_select_db($cfg['dbname'])) {
	echo "<div align='center'>Error: You must create the Web://cp database before you can continue.</div></body></html>";
	return false;
}

// database exists but tables haven't been imported  
$dbp = mysql_query("SHOW TABLES FROM ".$cfg['dbname']);
if (mysql_num_rows($dbp) === 0) {  
	echo "<div align='center'>Error:  You must import the Web://cp sql file before you can continue.</div></body></html>";
	return false;
}

// If there are any users set already, die.
$dbp = mysql_query("SELECT username FROM users");
if (mysql_num_rows($dbp)) {
	echo "<div align='center'>Error:  You cannot run the setup script once a user has been created; setup aborted.</div></body></html>";
	return false;
}
	
$cp = 'server';
$url = 'newaccount';
$current_url = 'setup.php';

// reload default language
include("lang/".$cfg['defaultlang'].".phps");

// load and parse default skin
include("parser.inc.phps");

// If data is set (i.e the submit button has been hit)
if (isset($data)) {
	if (is_array($data)) {
		// remove spaces and slashes.
		while (list($key, $val) = each($data)) {
			if ($key != 'serverside')
				$data[$key] = trim(stripslashes($val));
		}
		$error = reseller("create",$data,$return);
		if ($error)
			echo "<br>&nbsp;&nbsp; ".implode("<br>\n&nbsp;&nbsp; ",$error)."<br>\n";
		else {
			echo "<br><div align='center'>".$T['reseller created']."<a href='./?cp=reseller&number=$return' target='_top'><b>".$data['name']."</b></a>.</div>\n";
			
			// if domain is set, attempt to create domain
			if ($data['domain']) {
				if (ereg("[:space:]",$data['ip'])) {
					$ip = split("([[:space:]]+,?|[[:space:]]*,)",$data['ip']);
					$data['ip'] = $ip[0];
				}
				$data['ip_addr'] = $data['ip'];
				unset($tmp);
				foreach($data['serverside'] AS $key=>$val) {
					if ($val == 'on')
						$tmp[$key] = 'off';
					else
						$tmp[$key] = 'na';
				}
				$data['serverside'] = $tmp;
				$data['users'] = $data['domusers'];
				$data['hd'] = $data['domhd'];
				$data['transfer'] = $data['domtransfer'];
				$data['subdomains'] = $data['domsubdomains'];
				$data['pointers'] = $data['dompointers'];
				$data['databases'] = $data['domdatabases'];
				$data['bandwidth'] = $data['dombandwidth'];
				$data['defaultroot'] = "/".$data['hostname']."/".$cfg['webname']."/%USER%";
				$data['type'] = 'domain';
				$data['id'] = $return;

				$error = domain("create",$data,$return);
				if ($error)
					echo "<br>&nbsp;&nbsp; ".implode("<br>\n&nbsp;&nbsp; ",$error)."<br>\n";
				else {
					echo "<br><div align='center'>".$T['domain created']."<a href='./?cp=domain&number=$return' target='_top'><b>".$data['hostname'].".".$data['domain']."</b></a>.</div>\n";
					
					// if username is set, attempt to create user
					if ($data['username']) {
						// ** HACK ** This sleep code should be replaced with a cycle to check for creation of the domain with a reasonable timeout
						// sleep 2 seconds to let the domain be created
						sleep(5);
						
						$data['aliases'] = $data['usraliases'];
						$data['type'] = 'standard';
						$data['level'] = 0;
						$data['id'] = $return;
						unset($data['root']);
						
						$error = user("create",$data);
						if ($error)
							echo "<br>&nbsp;&nbsp; ".implode("<br>\n&nbsp;&nbsp; ",$error)."<br>\n";
						else
							echo "<br><div align='center'>".$T['user created']."<a href='./?cp=personal&number=$return&user=".$data['username']."' target='_top'><b>".$data['username']."</b></a>.</div>\n";
					}
				}
			}
		}
	}
}
?>
<br>
<!-- RESELLER CREATION -->
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="2" class="tbltop">&nbsp;<?=$T[$cp][$url];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Name'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[name]" size="25" maxlength="255" value="<? !empty($data) && print $data['name'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Email'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[email]" size="25" maxlength="255" value="<? !empty($data) && print $data['email'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['IP Address'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<textarea name="data[ip]" cols="19" rows="3" wrap="virtual"><?if (!empty($data) && $data['ip']) echo $data['ip']; else echo $SERVER_ADDR;?></textarea>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Domains'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domains]" size="5" maxlength="255" value="<? if(!empty($data) && $data['domains']) echo intval($data['domains']); else echo 25;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Subdomains'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[subdomains]" size="5" maxlength="255" value="<? if(!empty($data) && $data['subdomains']) echo intval($data['subdomains']); else echo 150;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Pointers'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[pointers]" size="5" maxlength="255" value="<? if(!empty($data) && $data['pointers']) echo intval($data['pointers']); else echo 50;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['HD Quota'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[hd]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['hd'])) echo intval($data['hd']); else echo 2500;?>"> <?=$T['mb'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Users'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[users]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['users'])) echo intval($data['users']); else echo 500;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Databases'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[databases]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['databases'])) echo intval($data['databases']); else echo 50;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Transfer'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[transfer]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['transfer'])) echo intval($data['transfer']); else echo 10;?>"> <?=$T['gb'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Shell Access'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="radio" name="data[shell]" value="on"> <?=$T['on'];?>&nbsp;&nbsp;<input type="radio" name="data[shell]" value="off" checked> <?=$T['off'];?>&nbsp;</td>
	</tr>
	<? if ($cfg['bandwidth']) { ?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Bandwidth'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[bandwidth]" size="5" maxlength="255" value="<? if($data['bandwidth']) echo intval($data['bandwidth']); else echo '0';?>"> <?=$T['kbps'];?>&nbsp;</td>
	</tr>
	<? } ?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Server Side Options'];?>&nbsp;</b></td>
		<td class="row2"><table border="0" cellpadding="0" cellspacing="0">
		<?
		if (strstr($cfg['sslang'],",")) $sslang = explode(",",$cfg['sslang']);
		else $sslang[0] = $cfg['sslang'];

		$j = 0;
		while (isset($sslang[$j])) {
			unset($check);
			 if (!empty($data['serverside'][trim($sslang[$j])]) && $data['serverside'][trim($sslang[$j])]=="on"){
				$check['on'] = ' checked';
				$check['off'] = '';
			}
			else {
				$check['off'] = ' checked';
				$check['on'] = '';
			}

			echo "<tr><td class='small'>&nbsp;<b>".$T['ss'][trim($sslang[$j])]."</b>&nbsp;</td><td class='small'>\n";
			echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" value="on"'.$check['on'].'>'.$T['on'];
			echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" value="off"'.$check['off'].'>'.$T['off'];
			echo "\n</td></tr>\n";
			++$j;
		}
		?></table></tr>
</table>
</td></tr></table><br>

</td></tr></table>
</div>
<!-- DOMAIN CREATION -->
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="2" class="tbltop">&nbsp;<?=$T['reseller']['newdomain'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Hostname'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[hostname]" size="25" maxlength="255" value="<? if(empty($data) || !$data['hostname']) echo "www"; else echo $data['hostname'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Domain Name'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domain]" size="25" maxlength="255" value="<? if(!empty($data) && $data['domain']) print $data['domain'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Users'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domusers]" size="5" maxlength="255" value="<? if(!empty($data) && $data['users']) echo intval($data['users']); else echo 10;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['HD Quota'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domhd]" size="5" maxlength="255" value="<? if(!empty($data) && $data['hd']) echo intval($data['hd']); else echo 50;?>"> <?=$T['mb'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Transfer Quota'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domtransfer]" size="5" maxlength="255" value="<? if(!empty($data) && $data['domtransfer']) echo intval($data['domtransfer']); else echo 2;?>"> <?=$T['gb'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Subdomains'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domsubdomains]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['domsubdomains'])) echo intval($data['domsubdomains']); else echo 2;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Pointers'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[dompointers]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['dompointers'])) echo intval($data['dompointers']); else echo 1;?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Databases'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domdatabases]" size="5" maxlength="255" value="<? if(!empty($data) && isset($data['domdatabases'])) echo intval($data['domdatabases']); else echo 5;?>">&nbsp;</td>
	</tr>
	<? if ($cfg['bandwidth']) { ?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Bandwidth'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[dombandwidth]" size="5" maxlength="255" value="<? if(!empty($data) && $data['dombandwidth']) echo intval($data['dombandwidth']); else echo '0';?>"> <?=$T['kbps'];?>&nbsp;</td>
	</tr>
	<? } ?>
</table>
</td></tr></table><br>

</td></tr></table>
</div>
<!-- USER CREATION -->
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="2" class="tbltop">&nbsp;<?=$T[$cp][$url];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Username'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[username]" size="25" maxlength="255" value="<?if(!empty($data) && $data['username']) echo $data['username']; else echo 'admin';?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Password'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[password]" size="25" maxlength="255" value="<?if(!empty($data) && $data['password']) print $data['password'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['E-Mail Aliases'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<textarea name="data[usraliases]" cols="20" rows="3" wrap="virtual"><?if (!empty($data) && $data['usraliases']) echo trim($data['usraliases']); else echo 'admin, root';?></textarea>&nbsp;</td>
	</tr>
	<tr>
		<? // get available languages
		if (strstr($cfg['lang'],",")) {
			$language = explode(",",$cfg['lang']);
		}
		else $language[1] = $cfg['lang'];
		?>
		<td class="row1"><b>&nbsp;<?=$T['Language'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<select name="data[lang]">
		<? do {
			echo '<option value="'.trim(current($language)).'"';
			if (current($language) == $userdata['lang']) echo " SELECTED";
			echo '> '.$T[current($language)].'</option>';
			echo "\n";
		} while(next($language)); ?>
           	</select>&nbsp;</td>
	</tr>
</table>
</td></tr></table><br>
<div align="right"><input type="submit" value="Submit"></div>
</td></tr></table>
</form>
</div>
</body>
</html>
Return current item: web-cp - Web Hosting Control Panel