Last active
December 17, 2021 17:07
-
-
Save g3d/f7b912fc72dc080855021b44ee2346f0 to your computer and use it in GitHub Desktop.
Modified version of http://www.zubrag.com/scripts/cpanel-subdomains-creator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
############################################################### | |
# cPanel Subdomains Creator 1.1 | |
############################################################### | |
# Visit http://www.zubrag.com/scripts/ for updates | |
############################################################### | |
# | |
# Can be used in 3 ways: | |
# 1. just open script in browser and fill the form | |
# 2. pass all info via url and form will not appear | |
# Sample: cpanel_subdomains.php?cpaneluser=USER&cpanelpass=PASSWORD&domain=DOMAIN&subdomain=SUBDOMAIN | |
# 3. list subdomains in file. In this case you must provide all the defaults below | |
# | |
# Note: you can omit any parameter, except "subdomain". | |
# When omitted, default value specified below will be taken | |
############################################################### | |
// cpanel user | |
define('CPANELUSER','user'); | |
// cpanel password | |
define('CPANELPASS','pass'); | |
// 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('INPUT_FILE','domains.txt'); | |
// cPanel skin (mainly "x") | |
// Check http://www.zubrag.com/articles/determine-cpanel-skin.php | |
// to know it for sure | |
define('CPANEL_SKIN','paper_lantern'); | |
// Default domain (subdomains will be created for this domain) | |
// Will be used if not passed via parameter and not set in subdomains file | |
define('DOMAIN',''); | |
/////////////// END OF INITIAL SETTINGS //////////////////////// | |
//////////////////////////////////////////////////////////////// | |
function getVar($name, $def = '') { | |
if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != '')) | |
return $_REQUEST[$name]; | |
else | |
return $def; | |
} | |
$cpaneluser=getVar('cpaneluser', CPANELUSER); | |
$cpanelpass=getVar('cpanelpass', CPANELPASS); | |
$cpanel_skin = getVar('cpanelskin', CPANEL_SKIN); | |
if (isset($_REQUEST["subdomain"])) { | |
// get parameters passed via URL or form, emulate string from file | |
$doms = array( getVar('domain', DOMAIN) . ";" . $_REQUEST["subdomain"]); | |
if (getVar('domain', DOMAIN) == '') 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.<br> | |
Tip: leave field empty to use default value you have specified in the script's code.<br> | |
<form method='post'> | |
Subdomain:<input name='subdomain'><br> | |
Domain:<input name='domain'><br> | |
cPanel User:<input name='cpaneluser'><br> | |
cPanel Password:<input name='cpanelpass'><br> | |
cPanel Skin:<input name='cpanelskin'><br> | |
<input type='submit' value='Create Subdomain' style='border:1px solid black'> | |
</form>"; | |
die(); | |
} | |
} | |
// create subdomain | |
function subd($host,$port,$ownername,$passw,$request) { | |
$errno = ""; | |
$errstr = ""; | |
$context = stream_context_create(); | |
$result = stream_context_set_option($context, 'ssl', 'verify_peer', false); | |
$result = stream_context_set_option($context, 'ssl', 'verify_host', false); | |
$result = stream_context_set_option($context, 'ssl', 'allow_self_signed', true); | |
// host of cert, need to provide if you are getting self-signed cert and using ip as host | |
// if you are getting error - replace $host with correct host string | |
$result = stream_context_set_option($context, 'ssl', 'CN_match', $host); | |
$sock = stream_socket_client('ssl://' . $host . ':' . $port, $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $context); | |
if(!$sock) { | |
print('Socket error'); | |
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(';',$dom); | |
if (count($lines) == 2) { | |
// domain and subdomain passed | |
$domain = trim($lines[0]); | |
$subd = trim($lines[1]); | |
} | |
else { | |
// only subdomain passed | |
$domain = getVar('domain', DOMAIN); | |
$subd = trim($lines[0]); | |
} | |
// https://[host here]:[port here]/cpsess1611018255/frontend/paper_lantern/subdomain/doadddomain.html?rootdomain=[domain here]&domain=[subdomain here] | |
// Don't forget to sign in into your cpanel and check if you have the same prefix (cpsess1611018255) | |
$request = "/cpsess1611018255/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd"; | |
// 2083 - port of cpanel, can be 2082 or any other | |
// If host of your cpanel is different from your domain, please replace it with string in line below | |
$result = subd($domain,2083,$cpaneluser,$cpanelpass,$request); | |
$show = strip_tags($result); | |
echo $show; | |
} | |
?> |
That's work for me, thanks👍👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting following error
stream_socket_client(): Failed to enable crypto in cpanel-subdomains-creator.php on line 98