Page 1 of 1

Cpanel Account termination scripting

Posted: Wed May 20, 2009 10:29 pm
by tahsinz
Hi,

It will be great if anybody can help me regarding cpanel account termination scripting in php. Obviously I have WHM account and privilege to create and termination cpanel account. However, I can create user connecting with WHM using php. The code is provided for reference.

Code: Select all

<?
 
$whm_user   = "root";      // reseller username
$whm_pass   = "password";  // the password you use to login to WHM
 
 
$whm_host   = $_SERVER['HTTP_HOST'];
 
function getVar($name, $def = '') {
  if (isset($_REQUEST[$name]))
    return $_REQUEST[$name];
  else
    return $def;
}
 
// Domain name of new hosting account
// To create subdomain just pass full subdomain name
if (!isset($user_domain)) {
  $user_domain = getVar('domain');
}
 
// Username of the new hosting account
if (!isset($user_name)) {
  $user_name = getVar('user');
}
 
// Password for the new hosting account
if (!isset($user_pass)) {
  $user_pass = getVar('password');
}
 
// New hosting account Package
if (!isset($user_plan)) {
  $user_plan = getVar('package');
}
 
// Contact email
if (!isset($user_email)) {
  $user_email = getVar('email');
}
 
// if parameters passed then create account
if (!empty($user_name)) {
 
  // create account on the cPanel server
  $script = "http://{$whm_user}:{$whm_pass}@{$whm_host}:2086/scripts/wwwacct";
  $params = "?plan={$user_plan}&domain={$user_domain}&username={$user_name}&password={$user_pass}&contactemail={$user_email}";
  $result = file_get_contents($script.$params);
 
  // output result
  echo "RESULT: " . $result;
}
// otherwise show input form
else {
$frm = <<<EOD
<html>
<head>
  <title>cPanel/WHM Account Creator</title>
  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>
  <style>
    input { border: 1px solid black; }
  </style>
<form method="post">
<h3>cPanel/WHM Account Creator</h3>
<table border="0">
<tr><td>Domain:</td><td><input name="domain" size="30"></td><td>Subdomain or domain, without www</td></tr>
<tr><td>Username:</td><td><input name="user" size="30"></td><td>Username to be created</td></tr>
<tr><td>Password:</td><td><input name="password" size="30"></td><td></td></tr>
<tr><td>Package:</td><td><input name="package" size="30"></td><td>Package (hosting plan) name. Make sure you cpecify existing package</td></tr>
<tr><td>Contact Email:</td><td><input name="email" size="30"></td><td></td></tr>
<tr><td colspan="3"><br /><input type="submit" value="Create Account"></td></tr>
</table>
</form>
</body>
</html>
EOD;
echo $frm;
?>

Re: Cpanel Account termination scripting

Posted: Tue May 26, 2009 12:07 pm
by tahsinz
Finally I found the solution for suspending the cpanel user. Please find below the code (if required)

Code: Select all

function suspend_account($user_name,$reason)
    {
    // Updating my User DB //
    $user= new Do_profile();
    
    $user->UserID=$user_name;
    $user->Status="Suspended";
    $user->status_update();
    
    // Performing WHM suspend user action
    $whm_user   = "reseller";      // reseller username
    $whm_pass   = "password";  // the password you use to login to WHM
 
    $whm_host   = $_SERVER['HTTP_HOST']
    $script = "http://{$whm_user}:{$whm_pass}@{$whm_host}:2086/scripts2/suspendacct";
    $params = "?domain={$user_name}&user={$user_name}&suspend-user=Suspend&reason={$reason}";
    //echo $script.$params;
    $result = file_get_contents($script.$params);
    //file($script.$params) or die(file_get_contents($script.$params));
    echo "RESULT: " . $result;
    }