cPanel Subdomain V2 script doesnt create the ftp account!!

Discussion in 'Programming' started by caringangel, Sep 5, 2008.

  1. #1
    Can some one help me out i found this free sub domain + ftp user creation script on the internet so i tested it out, filled out all the the info need to connect to my cpanel and tested it out, It created the sub domain then
    gave me this error when attempting to create the ftp user account
    "Sub domain created successfully
    There may be some error while creating FTP account."

    A little help here?

    I have the script code if you want to look at it

    Code for index.php

    <?php
    /*
    This is the example script for cpsubdomain class
    */
    
    ?>
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>cPanel Subdomain Creator</title>
    </head>
    
    <body>
    
    <p><b><font size="5">Cpanel Subdomain Creator</font></b></p>
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    
    	<table border="0" width="52%" style="border-collapse: collapse">
    		<tr>
    			<td colspan="2">
    			<p align="left"><b>Create Sub-domain:</b></td>
    		</tr>
    		<tr>
    			<td style="text-align: right; width: 92px;">
    			Sub-domain:</td>
    			<td>
    			<input type="text" name="subdomain" size="20" style="width: 166px"></td>
    		</tr>
    		<tr>
    			<td style="width: 92px">FTP Password</td>
    			<td>
    			<input type="text" name="ftppass" size="20" style="width: 166px"></td>
    		</tr>
    		<tr>
    			<td style="width: 92px"></td>
    			<td>
    			<input type="submit" value="Create New Subdomain" name="create" style="width: 165px"></td>
    		</tr>
    	</table>
    </form>
    <?php
    if(isset($_POST['create'])){
    //you can implement some security measure to ensure that the form is submitted from your domain
    
     //include class file
     require_once('class.php');
     
     /*
      instanciate class & pass three arguments cpanelusername, cpanelpassword,yourdomainname,cpanelskin
     */
     
     
     $cpanel=new cpsubdomain("my_user","my_pass","my_site","rvblue"); 
     
     //cpanel username, cpanel password, domain name, cpanel theme
     //cpanel theme may be 'x', 'rvblue' etc.
     /*
       See following URL to know how to determine your cPanel skin 
      http://www.zubrag.com/articles/determine-cpanel-skin.php 
      if you don't pass cpanelskin argument, default will be x. Thanks to this website.
     */
      
     //call create function and you have to pass subdomain parameter
    
     echo $cpanel->createSD($_POST['subdomain']);
     echo '<br/>';
     //call createFTP method and provide params ftp username,ftp password, quota.
     //if quota is not passed or blank, default is 20MB
     echo $cpanel->createFTP($_POST['subdomain'],$_POST['ftppass'],"20");
    }
    ?>
    </body>
    
    </html>
    
    Code (markup):
    Code for class.php

    <?php 
    
    //definding main class 
    class cpsubdomain{ 
      //declare public variables 
      var $cpuser;    // cPanel username 
      var $cppass;        // cPanel password 
      var $cpdomain;      // cPanel domain or IP 
      var $cpskin;        // cPanel skin. Mostly x or x2. 
       
      //defining constructor 
      function cpsubdomain($cpuser,$cppass,$cpdomain,$cpskin='x'){ 
        $this->cpuser=$cpuser; 
        $this->cppass=$cppass; 
        $this->cpdomain=$cpdomain; 
        $this->cpskin=$cpskin; 
    
      } 
       
    
      //function for creating subdomain 
       
      function createSD($esubdomain){ 
          //checking whether the subdomain is exists 
          $subdomain=$esubdomain.".".$this->cpdomain; 
          $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/subdomain/index.html"; 
    	    $f = fopen($path,"r"); 
    	    if (!$f) { 
    	      return('Can\'t open cPanel'); 
    	    } 
    	
    	    //check if the account exists 
    	    while (!feof ($f)) { 
    	      $line = fgets ($f, 1024); 
    	      if (ereg ($subdomain, $line, $out)) { 
    	        return('Such subdomain already exists. Subdomain Creation aborted.'); 
    	      } 
    	    } 
    	    fclose($f); //close the file resource 
    	     
    	     
    	    //subdomain does not already exist. So proceed to creating it 
    	    $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/subdomain/doadddomain.html?domain=".$esubdomain."&rootdomain=".$this->cpdomain; 
    	    $f = fopen($path,"r"); 
    	    if (!$f) { 
    	      return('Can\'t open cPanel.'); 
    	    } 
    	
    	    //check if the subdomain added 
    	    while (!feof ($f)) { 
    	      $line = fgets ($f, 1024); 
    	      if (ereg ("has been added.", $line, $out)) { 
    	        return('Subdomain created successfully'); 
    	      } 
    	    } 
    	    fclose($f); //close the file resource 
    	    //return success message 
    	    return "There may be some error while creating subdomain."; 
         
    	} //end of function
    	
    	function createFTP($ftpuser,$ftppass,$ftpquota=20)
    	{
    		//login=testing&password=12345&quota=20&homedir=testing
    		//for security purpose, I set homedirectory to the same name of ftpuser
    		//if you want to provide access to root directory, set $homedir="/"
    		$params="login=$ftpuser&password=$ftppass&quota=$ftpquota&homedir=$ftpuser";
    	
    		//checking whether the subdomain is exists 
    		$ftp=$ftpuser."@".$this->cpdomain; 
    		$path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/ftp/accounts.html"; 
    		$f = fopen($path,"r"); 
    		if (!$f) { 
    		  return('Can\'t open cPanel'); 
    		} 
    		
    		//check if the account exists 
    		while (!feof ($f)) { 
    		  $line = fgets ($f, 1024); 
    		  if (ereg ($ftp, $line, $out)) { 
    		    return('Such FTP account already exists. FTP Creation aborted.'); 
    		  } 
    		} 
    		fclose($f); //close the file resource 
    		
    		//not duplicate FTP account, so proceed to creating it
    		$path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/ftp/doaddftp.html?$params"; 
    	    $f = fopen($path,"r"); 
    	    if (!$f) { 
    	      return('Can\'t open cPanel.'); 
    	    } 
    	
    	    //check if the FTP account added 
    	    while (!feof ($f)) { 
    	      $line = fgets ($f, 1024); 
    	      if (ereg ("was sucessfully created", $line, $out)) { 
    	        return('The FTP account was created successfully'); 
    	      } 
    	    } 
    	    fclose($f); //close the file resource 
    	    //return success message 
    	    return "There may be some error while creating FTP account."; 
    	}//end of createFTP function
    	
    } 
    
    ?> 
    Code (markup):
     
    caringangel, Sep 5, 2008 IP