Add mail users using php?

mattbates

Registered
Jul 31, 2002
2
0
151
I've recently acquired hosting and CPanel 4 is used. I would like to be able to create a PHP script that can create email accounts - so specified users can 'activate' their membership and get a mail account created. I know that the server is running cppop however I do not know how users are specifically stored/authenticated and whether there are any current PHP modules out there to achieve this?

I would appreciate any help.
 

F1RULZ

Registered
Jul 29, 2002
1
0
151
Here hope it helps

This should help you:

&?
if ($submit){


//Username, root directory NO TRAILING SLASH
$home_directory = &/home/username&;

// Mailbox path
$mail_path = &$home_directory/mail&;

$p_directory = &$home_directory/etc&;

$newuser = &$formusername&;
$usrPassword = &$formpass&;


chmod (&$p_directory/passwd&, 0755);
chmod (&$p_directory/shadow&, 0755);
chmod (&$p_directory/quota&, 0755);


if (is_dir(&$mail_path/$newuser&)){ echo &username taken, please try again&; die; }
mkdir (&$mail_path/$newuser&,0770);
mkdir (&$mail_path/$newuser/uploads&,0770);
mkdir (&$mail_path/$newuser/addressbook&,0770);


$mailfile = fopen(&$p_directory/passwd&,'a');
$shadowfile = fopen(&$p_directory/shadow&,'a');
$quotafile = fopen(&$p_directory/quota&,'a');



$mail = &$newuser:x:xxxxx:xxx::$home_directory:/bin/bash\n&;

$shadow = &$newuser:& . crypt($usrPassword, $usrPassword) . &:::::::\n&;
// convert quota to bytes, If you dont want them to set there own quota you can delete the $formquota variable, and put in a figure, ie. 5 and then remove the form compontent, allowing you to add quota.
$formquot = $formquota * 1048576;


$quota = &$newuser:$formquot&;

fputs($mailfile, $mail);
fputs($shadowfile, $shadow);
fputs($quotafile, $quota);
fclose($quotafile);
fclose($mailfile);
fclose($shadowfile);
echo &Account Created Successfully!&;
}
else
{
?&
&html&
&center&&h4&Create New Mail User&/h4&&p&
&form method=post&
Username: &input type=text name=formusername&&br&
Password: &input type=password name=formpass&&br&
Quota in MB: &input type=text name=formquota&&br&
&input type=submit name=submit value=Submit&
&?
}
?&



Hope that helps you. I didnt write the script, someone called James did, I cant quive youa n other details as I dont ahve them
 

tonybsilva

Registered
Sep 7, 2002
1
0
151
I Wan't to create email acconts.

Whene i try to use the script i get.
Warning: chmod failed: Permission denied in /home/viaocean/public_html/joe.php on line 19

Warning: chmod failed: Permission denied in /home/viaocean/public_html/joe.php on line 20

Warning: chmod failed: Permission denied in /home/viaocean/public_html/joe.php on line 21

Warning: stat failed for /home/viaocean/mail/big_larry (errno=13 - Permission denied) in /home/viaocean/public_html/joe.php on line 24

Warning: mkdir() failed (Permission denied) in /home/viaocean/public_html/joe.php on line 25

Warning: mkdir() failed (Permission denied) in /home/viaocean/public_html/joe.php on line 26

Warning: mkdir() failed (Permission denied) in /home/viaocean/public_html/joe.php on line 27

Warning: fopen(&/home/viaocean/etc/passwd&, &a&) - Permission denied in /home/viaocean/public_html/joe.php on line 30

Warning: fopen(&/home/viaocean/etc/shadow&, &a&) - Permission denied in /home/viaocean/public_html/joe.php on line 31

Warning: fopen(&/home/viaocean/etc/quota&, &a&) - Permission denied in /home/viaocean/public_html/joe.php on line 32

Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 45

Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 46

Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 47

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 48

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 49

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/viaocean/public_html/joe.php on line 50
 

powerhouse

Well-Known Member
Nov 5, 2001
93
0
306
Ok
Is their a script like this in Perl?

I can't get this one to work.

Isn't their a way to make a script, either in PHP, or in Perl that will create a email account with the new features, any domain name pointed, parked or added on?

Is it possible?

For instance:

if you have mydomain.com setup as a hosted account, and mydomain.net pointed to it,

now you can use Cpanel to create [email protected]
or [email protected]

So, is their a way to have a script create the account, using a form to get the information needed to create the account, such as the form in the Cpanel that CREATES the actual accounts?

Thank you.
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
yes this is quite easily possible in PHP, using sockets to login to an account and do the mail creation, let me know if you need further info, thanks
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
pah, you know I normally get paid for this kind of thing ;)
i'll sort something out as soon as possible (probably tomorrow as Im GMT here and im going to bed ;) ) but I will try to have some code to show you in time for tomorrow,
thanks
 

henrychoo

Registered
Dec 2, 2001
2
0
301
[quote:32e00fb401][i:32e00fb401]Originally posted by jimcarter[/i:32e00fb401]
pah, you know I normally get paid for this kind of thing ;)
[/quote:32e00fb401]

Maybe with enough script you may sell it as a customisable API running on port80 and for other web application integration and charge $5/month ;)

Thanks in advance.
 

Snarf

Active Member
Mar 29, 2002
26
0
301
I would also like this....the script above didn't work for me eithier even after cmod ....does anyone have something that will work and would part with it for free :)
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
here you go!
$host = &www.domain.com&;
$socket = fsockopen($host,2082);
$user = &cpaneluser&;
$password = &cpanelpass&;
$authstr = &$user:$password&;
$pass = base64_encode($authstr);
$in = &GET /frontend/default/mail/doaddpop.html?email=emailaddress&domain=domain.com&password=emailpassword&quota=10 HTTP/1.0\r\nAuthorization: Basic $pass \r\n&;

fputs($socket,$in);
fclose( $socket );

it may be a little slow but it definitely works, and I suppose this means that you can use it do any command really,
 
Last edited:

Snarf

Active Member
Mar 29, 2002
26
0
301
Well I was looking for a full script actually :) php preferred .

You know if there is anything like that out there :p ?
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
that is a php script, just put in side the &? and ?&
there isnt anything like this available unfortunately
 

Snarf

Active Member
Mar 29, 2002
26
0
301
Ok I tried the php script in the first post and the only thing that don't seem to be working is the chmod of the etc. dir. on a certain domain.

Do I have to be logged in to the cpanel to do this or ftp. What I want is for my users to beable to signup for any email account by just filling out a form.

?
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
you can change the script to include a form quite easily
&?
if ($submit){
$host = &www.domain.com&;
$domain = &domain.com&;
$socket = fsockopen($host,2082);
$user = &cpaneluser&;
$password = &cpanelpass&;
$authstr = &$user:$password&;
$pass = base64_encode($authstr);
$in = &GET /frontend/default/mail/doaddpop.html?email=$email&domain=$domain&password=$password&quota=$quota HTTP/1.0\r\nAuthorization: Basic $pass \r\n&;

fputs($socket,$in);
fclose( $socket );
}
else {
?&
&form method=post&
Username:&input type=text name=email&&br&
Password:&input type=password name=password&&br&
Quota:&input type=text name=quota&
&input type=submit name=submit&
&?
}
?&

this should work, if you want a proper full custom system you would have to pay a developer really, unless you can find someone who is really nice to change my code :)
 
B

bdraco

Guest
If you are running suid to the owner of the domain

set REMOTE_USER to your username and run

use /usr/local/cpanel/cpanel-email

# /usr/local/cpanel/cpanel-email
cpanel-email: usage
addpop &popuser& &password& &quota& &domain&
delpop &popuser& 0 &domain&
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
[quote:0ea411234c][i:0ea411234c]Originally posted by jimcarter[/i:0ea411234c]

you can change the script to include a form quite easily
&?
if ($submit){
$host = &www.domain.com&;
$domain = &domain.com&;
$socket = fsockopen($host,2082);
$user = &cpaneluser&;
$password = &cpanelpass&;
$authstr = &$user:$password&;
$pass = base64_encode($authstr);
$in = &GET /frontend/default/mail/doaddpop.html?email=$email&domain=$domain&password=$password&a=$quota HTTP/1.0\r\nAuthorization: Basic $pass \r\n&;

fputs($socket,$in);
fclose( $socket );
}
else {
?&

this should work, if you want a proper full custom system you would have to pay a developer really, unless you can find someone who is really nice to change my code :)
[/quote:0ea411234c]
I got a blank page (no error messages) but the mail account was not added.