Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,873 members, 7,813,977 topics. Date: Tuesday, 30 April 2024 at 11:11 PM

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

Nairaland Forum / Science/Technology / Webmasters / Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: (16224 Views)

What Do You Think About Nigeria Having An Association Controlling Blogging / How To Add PHP Scripts To Blogger / Complete Tutorials On Designing A Wapka.m0bi Site.(codes/scripts Etc) (2) (3) (4)

(1) (2) (Reply) (Go Down)

Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 1:11am On Jan 08, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by OmniPotens(m): 8:48am On Jan 08, 2009
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
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 2:05pm On Jan 08, 2009
I am still waiting - i wonder if the topic is boring - or maybe ppl prefer not to validate their forms
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by josyisback(m): 3:04pm On Jan 08, 2009
yes guy, am interested. please ride on,
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by kelvin22(m): 4:13pm On Jan 08, 2009
I always like your bpost. Guy please continue
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 10:00pm On Jan 08, 2009
Let Us Start The Emails First


mail.class.php

<?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==""wink {$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"wink;$pos=strpos("$res","$box"wink;
if($pos===false) {$verify=false;} else {$verify=true;}
return $verify;
}

function getquota($box) {
if($box==""wink {$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"wink);
if(!strpos($result,$box)) {$space=array ('usage' => "0", 'quota' => "0", 'percent' => "0%"wink;return $space;}

$pos1=strpos("$result","$box"wink;$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"wink;$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"wink;
return $space;
}



function getboxes() {
function retrieve($line) {$pos1=strpos("$line","email="wink;$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"wink;
$chunks = spliti ("\n", $res);
foreach ($chunks as $line) {if(strpos("$line","dodelpop.html?email="wink!=false) {$boxes[]=retrieve($line);}}
return $boxes;
}


function erasebox($box) {
if($box==""wink {$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"wink;
}

function createbox($box,$password,$quota) {
if($box==""wink {$box=$this->mailbox;}
if($password==""wink {$password=$this->password;}
if($quota==""wink {$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"wink;$pos=strpos("$res","already exists"wink;
if($pos===false) {$verify=true;} else {$verify=false;}
return "$verify";
}

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

} ///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

<?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

<?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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by OmniPotens(m): 3:06am On Jan 09, 2009
See this other approach that I used then. Verify that it also works.

cpmail_class.php

<?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"wink;
    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


<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"wink;

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

echo $cpanel->create($_POST['euser'],$_POST['epass'],"20"wink;
}
?>
</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,
*/
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by josyisback(m): 8:36am On Jan 09, 2009
Nice work guys,am still waiting 4 d hosting part cos i host wit bluehost and would like to distribute my unlimited disk space
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 6:58pm On Jan 09, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by josyisback(m): 3:03pm On Jan 11, 2009
Ok,bt it might stil be useful. So just drop am.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 4:35pm On Jan 11, 2009
No problemo - we shall continue later on in the week.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by allimercy: 12:53am On Jan 12, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 1:51am On Jan 12, 2009
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
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by josyisback(m): 3:31pm On Jan 22, 2009
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?
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 7:04pm On Jan 22, 2009
I think u should talk to ur admin to remove your php from safe mode - let's see wat omni has to say about that.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by josyisback(m): 1:49pm On Jan 23, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by OmniPotens(m): 4:10pm On Jan 23, 2009
josyisback:

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
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 6:14pm On Jan 23, 2009
@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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 2:15pm On Feb 19, 2009
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 ur 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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 3:29am On Feb 20, 2009
Thanks for the contribution jare.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by aloymdu: 9:43pm On Aug 11, 2009
Anybody please post the php script to change the ftp password in bluehost, without using contol pannel
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 10:09pm On Aug 11, 2009
Looks like you are tryin to hack someone down. . . not my style

1 Like

Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by aloymdu: 5:03am On Aug 12, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 4:44pm On Aug 12, 2009
I do not know the solution to your question, since i have never used bluehost before. .
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by OmniPotens(m): 11:40pm On Aug 12, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 12:25am On Aug 13, 2009
very suspicous, why would you want to programmatically change password? without accessing the cpanel?
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by allimercy: 6:47am On Aug 13, 2009
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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by biggjoe(m): 7:06pm On Aug 13, 2009
allimercy:

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.
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by knop431: 4:37pm On Oct 12, 2009
abeg guys i am flotting
abeg i need some one that knows how to hack very well
this is my email:knop431@yahoo.com
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 5:22pm On Oct 13, 2009
Did you see hacking anywhere is my profile?
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by hostmot(f): 3:00am On Oct 14, 2009
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)
Re: Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: by Nobody: 6:21am On Mar 10, 2010
Now i remember we did not even get to the dbase and subdomains. But i remember they all follow the same principles. If you can
figure out how to create the emails, then you can probably do subdomains too.

(1) (2) (Reply)

Facebook Is To Get A 'dislike' Button, Says Mark Zuckerberg / Better Alternatives To Paypal / Blogging Is A More Lucrative Job Than Banking – Laila Ijeoma, CEO, Lailasblog

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 53
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.