Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 23, 2009, 07:55 AM
431084 members and 298150 Topics
Latest Member: SmenseGam
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: OmniPotens, yawa-ti-de)  |  Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:  (Read 1522 views)
*dhtml
Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« on: January 08, 2009, 01:11 AM »

Yo - I was thinking it is about time to reveal some of the tips and tricks of cpanel hosting to you guys. Maybe I am outdated there - or maybe I am wrong - not again. Anyway, there are some ways you can make php do stuffs on cpanel like create/remove email accounts, create databases, subdomains, email redirections. In short, almost all of those operations u have to do when you log into your cpanel, you can automate with PHP.

I dont know if i am making any sense, if I am, I need at least 3 positive responses to continue this thread.
@moderate - if this thread does not move forward - u may please delete it to free up space.
OmniPotens (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #1 on: January 08, 2009, 08:48 AM »

Just as will always as how you get people to have an email address from you domain when they sign up for any of your seminar programs. I think it is time for them to learn that here.

Opps! My client with a sample of this email thing running has got an expired domain name  Grin WIll get it running again for him if he complies. You know with what  Wink Then, I'll point it for a sample here.

Where's my stop watch? 'Tsays 2 more to go
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #2 on: January 08, 2009, 02:05 PM »

I am still waiting - i wonder if the topic is boring - or maybe ppl prefer not to validate their forms
josyisback (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #3 on: January 08, 2009, 03:04 PM »

yes guy, am interested. please ride on,
kelvin22
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #4 on: January 08, 2009, 04:13 PM »

I always like your bpost. Guy please continue
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #5 on: January 08, 2009, 10:00 PM »

Let Us Start The Emails First


mail.class.php
Code:
<?php
//mailclass starts
include_once 'server.php';

class 
Mailclass {

function 
Mailclass() {
$this->server=$GLOBALS['server'];
$this->admin_user=$GLOBALS['admin_user'];
$this->admin_pass=$GLOBALS['admin_pass'];
$this->quota=$GLOBALS['quota'];

//setup defaults
 
$mailbox="default";  //default username
 
$password="pass";  //default password


$this->mailbox=$mailbox;         
$this->password=$password
}

function 
debug() {
echo 
"<li>server: $this->server</li><li>admin_user: $this->admin_user</li><li>admin_pass: $this->admin_pass</li>";
}

function 
verbox($box) {
 if(
$box=="") {$box=$this->mailbox;}  //default is preset mailbox
 
$box=">$box@$this->server";
 
$lnk="http://$this->admin_user:$this->admin_pass@$this->server:2082/frontend/x/mail/pops.html";
 
$res=file_get_contents("$lnk");$pos=strpos("$res","$box");
 if(
$pos===false) {$verify=false;} else {$verify=true;}
 return 
$verify;
}

function 
getquota($box) {
 if(
$box=="") {$box=$this->mailbox;}  //default is preset mailbox
 
$box=">$box@$this->server";
$lnk="http://$this->admin_user:$this->admin_pass@$this->server:2082/frontend/x/mail/pops.html?extras=disk";
$result=strtolower(file_get_contents("$lnk"));
if(!
strpos($result,$box)) {$space=array ('usage'  => "0"'quota'  => "0"'percent'  => "0%");return $space;}

$pos1=strpos("$result","$box");$pos2=strpos("$result","dodelpop.html",$pos1);$line=substr($result,$pos1,$pos2-$pos1);
$pos=strpos("$line","$box",3);$line=substr($line,$pos+strlen($box),strlen($line));
$pos=strpos("$line","<a");$line=strip_tags(substr($line,0,$pos));
$chunks spliti ("&nbsp;m"$line);$usage=trim($chunks[0]);
$quota=trim($chunks[1]);
$percent=($usage/$quota) * 100;
$percent=round($percent,1);
$space=array ('usage'  => "$usage"'quota'  => "$quota"'percent'  => "$percent");
 return 
$space;
}



function 
getboxes() {
  function 
retrieve($line) {$pos1=strpos("$line","email=");$pos1+=6;$pos2=strpos("$line",'&',$pos1);$line=substr($line,$pos1,$pos2-$pos1);return "$line";}
 
$lnk="http://$this->admin_user:$this->admin_pass@$this->server:2082/frontend/x/mail/pops.html";
 
$boxes=array();  //mailboxes
 
$res=file_get_contents("$lnk");
  
$chunks spliti ("\n"$res);
 foreach (
$chunks as $line) {if(strpos("$line","dodelpop.html?email=")!=false) {$boxes[]=retrieve($line);}}
 return 
$boxes;
}


function 
erasebox($box) {
 if(
$box=="") {$box=$this->mailbox;}  //default is preset mailbox
 
$lnk="http://$this->admin_user:$this->admin_pass@$this->server:2082/frontend/x/mail/realdelpop.html?email=$box&domain=$this->server";
 
$thrash=file_get_contents("$lnk");
}

function 
createbox($box,$password,$quota) {
 if(
$box=="") {$box=$this->mailbox;}  
 if(
$password=="") {$password=$this->password;}  
 if(
$quota=="") {$quota=$this->quota;}  
$lnk="http://$this->admin_user:$this->admin_pass@$this->server:2082/frontend/x/mail/doaddpop.html?email=$box&domain=$this->server&password=$password&quota=$quota";
$res=file_get_contents("$lnk");$pos=strpos("$res","already exists");
 if(
$pos===false) {$verify=true;} else {$verify=false;}
return 
"$verify";
}

function 
createboxex($box) {return $this->createbox($box,"","");}

///mailclass ends
?>


This is the base class for the emails - i made this class some years ago - i am not going to edit it - at all! even though the codes are rather too long
and are not optimized - i was just learning php then - if u can optimize them, no problemo.

server.php
Code:
<?php
//admin config
$server="mysite.com";
$admin_user="dhtml";
$admin_pass="007";
$quota="20";

//do not edit
$GLOBALS['server']=$server;
$GLOBALS['admin_user']=$admin_user;
$GLOBALS['admin_pass']=$admin_pass;
$GLOBALS['quota']=$quota;
?>

That should be explanatory i think.

Now the usage.


mail.usage.php
Code:
<?php
include_once 'mail.class.php';

$mailclass=new Mailclass();
$box="wale";
//$mailclass->createbox($box,$box,'1');
//if($mailclass->verbox($box)) {echo "$box is valid";} else {echo "$box is not valid";}

//$mailclass->createbox($box,$box,'1');

$space=$mailclass->getquota($box);
$usage=$space['usage'];
$quota=$space['quota'];
$percent=$space['percent'];

echo 
"Usage: $usage of $quota. $percent";
//foreach($mailclass->getboxes() as $box) {
//echo "<li>$box";
//}
?>


This was the sample script i used to test the script then - i did not modify anything.

To create a mailbox like wale@mysite.com, u need
create.php

$mailclass=new Mailclass();
$box="wale";
$mailclass->createbox($box,$box,'1');


To check if a box exist

$box="wale";
if($mailclass->verbox($box)) {echo "$box is valid";} else {echo "$box is not valid";}

I am feeling sleepy, we will continue this another time, u should be able to follow the script, it is short and
the coding convention is not so complex.
OmniPotens (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #6 on: January 09, 2009, 03:06 AM »

See this other approach that I used then. Verify that it also works.

cpmail_class.php

Quote
<?php

//definding main class
class cpmail{
  //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 cpmail($cpuser,$cppass,$cpdomain,$cpskin='x'){
    $this->cpuser=$cpuser;
    $this->cppass=$cppass;
    $this->cpdomain=$cpdomain;
    $this->cpskin=$cpskin;
 
  }

  //now create email account, function takes three arguments
  /*
  $euser = email id
  $epass = email password
  $equota = mailbox allocated size
  */
  function create($euser,$epass,$equota){
    $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/mail/doaddpop.html?quota=".$equota."&email=".$euser."&domain=".$this->cpdomain."&password=".$epass;
    $f = fopen($path,"r");
    if (!$f) {
      return('Cannot create email account. Possible reasons: "fopen" function not allowed on your server, PHP is running in SAFE mode');
    }

    //check if the account exists
    while (!feof ($f)) {
      $line = fgets ($f, 1024);
      if (ereg ("already exists!", $line, $out)) {
        return('Such email account already exists.');
      }
    }
    fclose($f);
    //return success message
    return "Email account created.";
}
}

?>



Sample Usuage

Quote
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>cPanel Email Creator</title>
</head>

<body>

<p><b><font size="5">Cpanel Email 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 Email Accounts</b></td>
        </tr>
        <tr>
            <td width="78">
            <p align="right">Username:</td>
            <td><input type="text" name="euser" size="20"></td>
        </tr>
        <tr>
            <td width="78">
            <p align="right">Password:</td>
            <td><input type="password" name="epass" size="20"></td>
        </tr>
        <tr>
            <td width="78"> </td>
            <td><input type="submit" value="Create New Account" name="create"></td>
        </tr>
    </table>
</form>
<p> </p>
<?php
if(isset($_POST['create'])){

//include class file
require_once('cpmail_class.php');

/*
  instanceiate class & pass three arguments cpanelusername, cpanelpassword,yourdomainname,cpanelskin
  if you don't pass cpanelskin argument, default will be x
*/

$cpanel=new cpmail("rubdnet","secret2001","rubd.net","rvblue");

//call create function and you have to pass three arguments as follows:
//emailid, password, quota

echo $cpanel->create($_POST['euser'],$_POST['epass'],"20");
}
?>
</body>
</html>

NB: You can still try adding in captcha to it against bots signing up for email aliases.

/*
After work you sleep and not
after work, work continues again
but my NL status asks for extension
so I'm back to bed now,
*/
josyisback (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #7 on: January 09, 2009, 08:36 AM »

Nice work guys,am still waiting 4 d hosting part cos i host wit bluehost and would like to distribute my unlimited disk space
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #8 on: January 09, 2009, 06:58 PM »

I am on leave right now (means i am not with my laptop - so i cant do so much till next weekend) - i am not sure if bluehost will support the same thing - the codes i am giving out is strictly for cpanel - it is an indirect technique utilizing the framework of cpanel to achieve these tasks. It is indirect because even I do not even know how it is being done by cpanel scripts - we are just manipulating our way to get the task done - the word is "automated submission" - more like bots/robots.
josyisback (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #9 on: January 11, 2009, 03:03 PM »

Ok,bt it might stil be useful. So just drop am.
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #10 on: January 11, 2009, 04:35 PM »

No problemo - we shall continue later on in the week.
allimercy
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #11 on: January 12, 2009, 12:53 AM »

I will make this simple for you when I have the authorization from here. Very simple steps without the use of any code I guess.
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #12 on: January 12, 2009, 01:51 AM »

Authorization is not required - this is not my space - i am just a poster at the "same" level as you. You are free to post anything anywhere - as long as it is useful - the readers will determine that.
I am here to teach coding, but as a programmer it is your duty to know as many methods of solving a problem as possible and to select the one that is best suited for the job at hand.
If you have anything useful please post it - if it is good - then your image will be boosted
josyisback (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #13 on: January 22, 2009, 03:31 PM »

hello omnipotent,i tried your script out but it said that php is on safe mode on my server.what should i do to it next?
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #14 on: January 22, 2009, 07:04 PM »

I think u should talk to your admin to remove your php from safe mode - let's see wat omni has to say about that.
josyisback (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #15 on: January 23, 2009, 01:49 PM »

its bluehost,i know the would never remove it from safe mode. I want to work on omni's script so that members of joscityweb.com can be able to create mails in the site.
OmniPotens (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #16 on: January 23, 2009, 04:10 PM »

Quote from: josyisback on January 22, 2009, 03:31 PM
hello omnipotent,i tried your script out but it said that php is on safe mode on my server.what should i do to it next?

Not feeling too fine. Read through this then see if it helps.

http://www.webhostgear.com/166.html
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #17 on: January 23, 2009, 06:14 PM »

@Omni - only the admin can do that
@joy - there are many ways of creatin mailboxes on servers - u can search the web - imap functions is what they are called.
Problem is that most web admins block these methods - u can still try them - i hope one of them will work - i dont hav a bluehost cpanel or i might hav looked for loopholes to create the mailboxes.
webdezzi (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #18 on: February 19, 2009, 02:15 PM »

I dont think this addition will be out of place, so lazy me, i cant read all comments.

You might want to add a sendmail to the error logic, for instance,
way back, i used that same script by omni and without my knowledge, the hosting company changed the skin from "x" to "x2".

I got calls from my client saying the email part of the site is no longer working.

So adding mail(something something) will let you know when something goes wrong.
another problem could arise is you change the cpanel password, then you have to update the script.

Bluehost is same as hostmonster. thats what these hosting companies do these days.

I use hostmonster and they use custom skin

my urls look something like this
http://mydomain.com:2082/frontend/hostmonster/mail/doaddpop.html

the same $_GET arrays will work but they use post method. It shud still work as i guess they are getting your submissions from $_REQUEST

if josyisback can provide you with his URL i guess it will be bluehost instead of hostmonster

another thing, i will recommend modifying the error message to list all possible scenarios.
Thanks for giving out this piece, It will help so many developers here.
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #19 on: February 20, 2009, 03:29 AM »

Thanks for the contribution jare.
aloy_mdu
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #20 on: August 11, 2009, 09:43 PM »

Anybody please post the php script to change the ftp password in bluehost, without using contol pannel
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #21 on: August 11, 2009, 10:09 PM »

Looks like you are tryin to hack someone down. . . not my style
aloy_mdu
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #22 on: August 12, 2009, 05:03 AM »

Hi I don't want to hack anything. I have an hosting space in bluehost with SSH.  If you want to know more details I will explain.

*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #23 on: August 12, 2009, 04:44 PM »

I do not know the solution to your question, since i have never used bluehost before. .
OmniPotens (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #24 on: August 12, 2009, 11:40 PM »

I thought bluehost is the hosting company's name or i'm i wrong? If it's the company's name then what platform are they running? But my mind is not settled on your quest here. Really suspicious. No matter the platform being ran, get into the hosting panel and change things from in there. Just too simple and straight forward.
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #25 on: August 13, 2009, 12:25 AM »

very suspicous, why would you want to programmatically change password? without accessing the cpanel?
allimercy
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #26 on: August 13, 2009, 06:47 AM »

Sometimes, the so called wise man is the foolish man,  the bible confirmed that as well. The intention of a wicked man is always be revealed to God's own people.

I will stop here.
biggjoe (m)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #27 on: August 13, 2009, 07:06 PM »

Quote from: allimercy on August 13, 2009, 06:47 AM
Sometimes, the so called wise man is the foolish man, the bible confirmed that as well. The intention of a wicked man is always be revealed to God's own people.

I will stop here.

Like dhtml said before, if you want to post, post, stop talking in riddles.

We deal with codes here not riddles.
knop431
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #28 on: October 12, 2009, 04:37 PM »

abeg guys i am flotting 
abeg i need some one that knows how to hack very well
this is my email:knop431@yahoo.com
*dhtml
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #29 on: October 13, 2009, 05:22 PM »

Did you see hacking anywhere is my profile?
hostmot (f)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains:
« #30 on: October 14, 2009, 03:00 AM »

If you are thinking of changing any sensitive thing in cpanel, then you would have to use ssh (Secure Shell).

Accessing a webserver or webhosting account through ssh is not hacking as long as you own the server/account and ssh access has been granted by your webhost.

You should however be careful security-wise due to the amount of actions an intruder can carry out through ssh. Most hackers actually try to bruteforce their way through the default ssh port rather than steal your cpanel or ftp passwords.

Also, you should precisely know the commands you would run as the wrong commands can cause unprecedented problems on your website.

Olawunmi,
Sales Rep, Hostmot (www.hostmot.com)

 Comment On This Site I Designed: TheStreetHawker.com  Forum Help Needed  Need Script, Or Any Solution For Website Design Task!  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.