<?php



// cpanel user
define(&#39;CPANELUSER&#39;,&#39;user&#39;

// cpanel password
define(&#39;CPANELPASS&#39;,&#39;pass&#39;

// name of the subdomains list file.
// file format may be 1 column or 2 columns divided with semicilon (
// Example for two columns:
// rootdomain1;subdomain1
// rootdomain1;subdomain2
// Example for one columns:
// subdomain1
// subdomain2
define(&#39;INPUT_FILE&#39;,&#39;domains.txt&#39;

// cPanel skin (mainly "x")

// to know it for sure
define(&#39;CPANEL_SKIN&#39;,&#39;x&#39;

// Default domain (subdomains will be created for this domain)
// Will be used if not passed via parameter and not set in subdomains file
define(&#39;DOMAIN&#39;,&#39;&#39;



function getVar($name, $def = &#39;&#39 {
if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != &#39;&#39)
return $_REQUEST[$name];
else
return $def;
}

$cpaneluser=getVar(&#39;cpaneluser&#39;, CPANELUSER);
$cpanelpass=getVar(&#39;cpanelpass&#39;, CPANELPASS);
$cpanel_skin = getVar(&#39;cpanelskin&#39;, CPANEL_SKIN);

if (isset($_REQUEST["subdomain"])) {
// get parameters passed via URL or form, emulate string from file
$doms = array( getVar(&#39;domain&#39;, DOMAIN) . ";" . $_REQUEST["subdomain"]);
if (getVar(&#39;domain&#39;, DOMAIN) == &#39;&#39 die("You must specify domain name");
}
else {
// open file with domains list
$doms = @file(INPUT_FILE);
if (!$doms) {
// file does not exist, show input form
echo "
Cannot find input file with subdomains information. It is ok if you are not creating subdomains from file.

Tip: leave field empty to use default value you have specified in the script&#39;s code.

<form method=&#39;post&#39;>
Subdomain:<input name=&#39;subdomain&#39;>

Domain:<input name=&#39;domain&#39;>

cPanel User:<input name=&#39;cpaneluser&#39;>

cPanel Password:<input name=&#39;cpanelpass&#39;>

cPanel Skin:<input name=&#39;cpanelskin&#39;>

<input type=&#39;submit&#39; value=&#39;Create Subdomain&#39; style=&#39;border:1px solid black&#39;>
</form>";
die();
}
}

// create subdomain
function subd($host,$port,$ownername,$passw,$request) {

$sock = fsockopen(&#39;localhost&#39;,2082);
if(!$sock) {
print(&#39;Socket error&#39;
exit();
}

$authstr = "$ownername:$passw";
$pass = base64_encode($authstr);
$in = "GET $request\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";

fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose( $sock );

return $result;
}

foreach($doms as $dom) {
$lines = explode(&#39;;&#39;,$dom);
if (count($lines) == 2) {
// domain and subdomain passed
$domain = trim($lines[0]);
$subd = trim($lines[1]);
}
else {
// only subdomain passed
$domain = getVar(&#39;domain&#39;, DOMAIN);
$subd = trim($lines[0]);
}
// http://&#91;domainhere]:2082/frontend/x/...n.html?domain=[subdomain here]&rootdomain=[domain here]
$request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
$result = subd(&#39;localhost&#39;,2082,$cpaneluser,$cpanelp ass,$request);
$show = strip_tags($result);
echo $show;
}

?>