The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Suspend account page

Discussion in 'cPanel Developers' started by deviantlinux, Feb 26, 2008.

  1. deviantlinux

    deviantlinux Member

    Joined:
    Feb 26, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    I wrote this script a while ago, thought I would post it here for anyone who needs something similar. This will take input for the domain to suspend (subdomain.yourhosting.com) and will get XML output and suspend the domain. It needs PHP 5.0 or later.

    Code:
    <?php
    /* 
    *   This code written by deviantlinux.
    * -------------------------------------------------------
    *   Description:
    *   This was written so a user can enter a domain they need to suspend,
    *   and using the XML api that cPanel provides, it will get info on that
    *   particular domain, grab the user name, and suspend the domain using
    *   a URL.
    *
    * -------------------------------------------------------
    *
    *   Requirements:
    *   This code requires PHP 5.0 or later, because
    *   of the simplexml_load_file function.
    *
    * 
    */
    //------------------------------------------------------------
    //                  You MUST edit the following!
    // ------------------------------------------------------------
    //
    $mySite = "Mysite.com"; // Your domain name
    $myCpanelLoc = "mysitehosting.com:2086"; // Your cPanel WHM website
    $cPanelUser = "root"; // Your cPanel username (usually root)
    $cPanelPass = "mypass321"; // Your cPanel Password
    $myEmail = "billing@mysite.com";
    
    $acctdomain = $_POST['domain'];
    $reason = $_POST['reason'];
    
    if (!isset($_POST['submit'])) { 
    // Show main page before submit is hit.
    ?>
    
    <html>
    <head>
    <title>Suspend a domain</title>
    </head>
    
    <body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
    
    <div align="center">
    <h2>Suspend a domain</h2>
    <b><? echo $mySite; ?></b>
    </div>
    
    <table width="100%" height="18" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td align="center"></td>
    </tr>
    </table>
    
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <form  method="post" action="<? echo $PHP_SELF; ?>">
      <tr>
        <td width="35%"><b><font color="red">*</font>&nbsp;Domain to suspend:</b></td>
        <td><input type="text" name="domain" style="border:2px solid black;width:200px;"></td>
      </tr>
      <tr>
        <td width="35%"><b>Reason:</b></td>
        <td><input type="text" name="reason" style="border:2px solid black;width:200px;"></td>
      </tr>
    </table>
    
    <br>
    
    <div align="center">
    <input type="submit" value="Send" name="submit">&nbsp;&nbsp;
    <input type="reset" value="Reset">
    </form>
    </div>
    
    <? 
    } else 
    {
    $acctdomain = $_POST['domain'];
    $reason = $_POST['reason'];
    
    if($acctdomain=="")
      {
        echo "<div align='center'>";
          echo "You didn't fill in a required field!<br>";
          echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
        echo "</div>";
      }
    
    elseif($acctdomain!="")
      {
    // Action to grab raw XML data from cPanel XML api, and get user name from inputted domain.
    $request_url = "http://$cPanelUser:$cPanelPass@$myCpanelLoc/xml-api/listaccts?searchtype=domain&search=$acctdomain";
    $xml = simplexml_load_file($request_url) or die("Error: XML feed not loading.  Please notify a system administrator!");
    
    // Now exchange XML data for individual strings.
    $user = $xml->acct->user;
    $domain = $xml->acct->domain;
    $disklimit = $xml->acct->disklimit;
    $diskused = $xml->acct->diskused;
    $email = $xml->acct->email;
    $ip = $xml->acct->ip;
    $owner = $xml->acct->owner;
    $partition = $xml->acct->partition;
    $plan = $xml->acct->plan;
    $startdate = $xml->acct->startdate;
    $theme = $xml->acct->theme;
    $unix_startdate = $xml->acct->unix_startdate;
    
    echo "<h2>Account Suspension</h2>";
    echo "User data obtained.<br>";
    
    // Email our suspendee to let him know
    $subject = "Account suspended at $mySite";
    $message = "Hello,\n\n
    This email is to let you know that your site $domain, hosted at 
    $mySite has been suspended.  Please contact us as soon as possible 
    so we can discuss your options.
    
    
    Username: $user
    Domain: $domain
    Account Plan: $plan
    Account Start Date: $startdate
    
    
    Regards,
    $mySite";
    $headers = "From: $myEmail";
    mail($email,$subject,$message,$headers);
    
    // Show info...
    echo "Email sent to <b>$user</b> at address <b>$email</b>.<br><br>";
    echo "Suspending domain <b>$domain</b>...<br><br>";
    
    // Replace spaces with %20 for successful URL load
    $reason = ereg_replace(" ","%20",$reason2);
    $script = "http://$cPanelUser:$cPanelPass@$myCpanelLoc/scripts2/suspendacct?domain=$user&user=$user&reason=$reason2&suspend-domain=Suspend";
    $result = file_get_contents($script);
    
    echo "<font color='green'><b>Account has been suspended!</b></font>";
    
    echo "<br><br>";
    
    // Show close window button
    echo "<div align='center'>";
    echo "<form>";
    echo "<input type='button' value='Close Window' onClick='window.close()'>";
    echo "</form>";
      }
    
    }
    ?>
    
    </body>
    </html>
     
    #1 deviantlinux, Feb 26, 2008
    Last edited: Mar 26, 2009
  2. inverter

    inverter Registered

    Joined:
    Nov 24, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Can you do this without logging in. I would love to use but...

    So what if your website in hacked? Now they have your WHM user name and password.


     
Loading...

Share This Page