NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   Add subdomain in cPanel via PHP (http://www.namepros.com/code/296341-add-subdomain-in-cpanel-via-php.html)

AzN 02-19-2007 10:34 PM

Add subdomain in cPanel via PHP
 
There was someone looking for this, so I took DeViAnThans3's script and modified it.
http://www.namepros.com/code/275464...t-creation.html


PHP Code:
<?php
/* based on DeViAnThans3's whm script
no warranty is held for use of script  */  

/* HOW TO INSTALL
1 - Save this code as a PHP file (or any file, as long as the server recognizes it as PHP)
2 - Change the configuration part in this file, save it, and upload to your server
3 - Create an empty .txt file in notepad, call it cookie.txt, upload it to your server.
4 - Is your server a unix-like server? CHMOD that file to 777.
    This is not need for windows servers.
*/

// get domain info
$d = $_GET['d'];
$s = $_GET['s'];


// Configure
define("WHM_USER", "cpanel-username"); // cPanel username
define("WHM_PASS", "cpanel-pass"); // cPanel password
define("WHM_DOMAIN", "yourdomainhere");   // IP or hostname could be enterred here

// The new account settings!
// Go to line 75 in this file, and change everything to suit your needs.


// cURL class: Thanks to Sean Huber
class CURL {
   var
$callback = false;

function
setCallback($func_name) {
   
$this->callback = $func_name;
}

function
doRequest($method, $url, $vars) {
   
$ch = curl_init();
   
curl_setopt($ch, CURLOPT_URL, $url);
   
curl_setopt($ch, CURLOPT_HEADER, 1);
   
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
   
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
   
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
   if (
$method == 'POST') {
       
curl_setopt($ch, CURLOPT_POST, 1);
       
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
   }
   
$data = curl_exec($ch);
   
curl_close($ch);
   if (
$data) {
       if (
$this->callback)
       {
           
$callback = $this->callback;
           
$this->callback = false;
           return
call_user_func($callback, $data);
       } else {
           return
$data;
       }
   } else {
       return
curl_error($ch);
   }
}

function
get($url) {
   return
$this->doRequest('GET', $url, 'NULL');
}

function
post($url, $vars) {
   return
$this->doRequest('POST', $url, $vars);
}
}

// Initialize cURL library
$curl = new CURL;

$text = $curl->get("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/");

// Create account now
// First going to this form; required, else wont work
$text = $curl->get("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/frontend/x2/subdomain/doadddomain.html?");

// Fine! Set the options now. refer to original post on usage guide
$options = "domain=".$s."&rootdomain=".$d."";

// And post it!
$text = $curl->post("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/frontend/x2/subdomain/doadddomain.html?", $options);

// Eventually you can output the text here
echo $text;
?>


No warranty provided for script usage.
No copyright or licensing required.

Simply call the php file with ?d=(your main domain)&s=(subdomain wanted)
Ex: .php?d=namepros.com&s=chat
This will set up chat.namepros.com

RegisterRants 02-19-2007 10:39 PM

Yeah, I was looking for this ;)

The problem is that I do not want to install cURL on my server...all the c99 stuff that's out there, ya know?


All times are GMT -7. The time now is 09:07 AM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0