Web Hosting Talk







View Full Version : subdomain+php+cpanel


kmarada
03-07-2004, 12:20 PM
Hello everybody,
Im trying to create a subdomain in a script php.
I want to put this script php in the cron job cpanel so every 5 min it create a new subdoamin.

But I dont find anything about it.
Anyone knows how to create a subdomain in php?
Or how I create a subdoamin without cpanel?

Thanks to all answers.
Gerald

rrdega
03-07-2004, 08:36 PM
Though it can probably be made cleaner/better, here's a function I am using to create subdomains in cPanel. It should be easily "mungable" to be used from cron:

// Add Subdomain to a WHM/cPanel account
function cPanelAddSubdomain($subdomain, $fq_newDomainName) {
// Get the cPanel Host, UserID, Pwd, and Theme
require getWedsiteDir()."/config/cpanel_config.php";
$authstr = "$CP_userid:$CP_pwd";
$pass = base64_encode($authstr);

$subdomainCreated = false;
$socket = fsockopen($CP_host,2082,$errno,$errstr);
if (!$socket) {
$subdomainCreated = false;
echo "$errstr ($errno)<br />\n";
} else {
fputs($socket,"POST /frontend/$CP_theme/subdomain/doadddomain.html?domain=$subdomain&rootdomain=$CP_host\r\n");
fputs($socket,"HTTPS/1.0\r\n");
fputs($socket,"Host: $CP_host\r\n");
fputs($socket,"Authorization: Basic $pass \r\n");
fputs($socket,"Connection: close\r\n\r\n");

while (!feof($socket)) {
fgets($socket,4096);
}
fclose($socket);

// Test its creation...
if (touch(getWebRoot()."/$subdomain/subdomain_setup_test.delete_me")) {
unlink(getWebRoot()."/$subdomain/subdomain_setup_test.delete_me");
$subdomainCreated = true;
} else {
$subdomainCreated = false;
}
}
return($subdomainCreated);
}

kmarada
03-08-2004, 12:03 AM
Cool. Thanks rrdega

Is it possible to use:

Authorization: Basic $pass

in the head() to got into Cpanel by form?

rrdega
03-08-2004, 08:01 AM
In general, you do not want to pass the cPanel UserId/Pwd in POST data, as it will be sent (more or less) in clear text, and potentially accessible to hackers. Putting these in a seperate file, locked down via permissions, and located outside the "web addressable" space, helps to mitigate the risks...