Add mail users using php?

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
&?
if ($submit){
$host = &www.1337ster.com&;
$domain = &1337ster.com&;
$socket = fsockopen($host,2082);
$user = &jimmyc&;
$password = &859780barryw&;
$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 value=submit&
&?
}
?&


i made an error in the form code sorry,
all fixed, works fine for me
 

Snarf

Active Member
Mar 29, 2002
26
0
301
the script i was talking about that the onlu problem is chmoding dirs is

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


i did what it says to do in the 2 post of this thread but this part is where it fails any idea's


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

moronhead

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

&?
if ($submit){
$host = &www.1337ster.com&;
$domain = &1337ster.com&;
$socket = fsockopen($host,2082);
$user = &jimmyc&;
$password = &859780barryw&;
$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 {
?&
.......

i made an error in the form code sorry,
all fixed, works fine for me[/quote:8d1f8f2bb9]
It still doesn't work. What was the difference between this one and the one you posted earlier?
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
the only difference was in the form submit button, i changed it from &input type=submit name=submit& to &input type=text name=submit value=submit&
works for me with the exact code what I posted
 

Snarf

Active Member
Mar 29, 2002
26
0
301
do you have to chmod anything with this ?

Because when I try to use it I get a blank screen and that is it...it don't create anything :(
 

moronhead

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

the only difference was in the form submit button, i changed it from ...... works for me with the exact code what I posted[/quote:30c7ae1cfe]
There a couple of problems with what you're saying. One is, you can't press a button if the input type is text! Second is, you are using the same $password variable for both the cpanelpass and mailbox password.

Even when these are corrected the script doesn't work.
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
heh i thought I had corrected that,
but, like I said before that exact code works perfectly for me, ive created 10 accounts with that code and all of the accounts work, and for some really strange reason it still worked without the corrections which you pointed out
 

rpmws

Well-Known Member
Aug 14, 2001
1,787
10
318
back woods of NC, USA
[quote:944c3a88e5][i:944c3a88e5]Originally posted by Snarf[/i:944c3a88e5]

:( I wish it worked on my server :(

Does anyone have one that will work ?[/quote:944c3a88e5]

Chad,

Have you tried changing the permissions on the php file? The form? This thing worked for me first try.
 

Snarf

Active Member
Mar 29, 2002
26
0
301
I haven't changed any permissions :(

the permissions on the file when I upload before I run are 644 which that is the same as the other php files I am running.

Should the form be in a different file like Html and posting to the script you made or all in one ?

Right now I have it all in one.

I pull the file up (example: file name mailtest.php)
in my browser type in the username, pw and quota
hit submit and it goes stait to a blank white screen nothing more.

it acts like it is not finding th eaddpop file or something or maybe not logging in.

I mean is there something I can add to teh script to debug it to see exactly where the problem is ?

I would really love to have this script work good so my users and signup for a free email account for the domain in question.
 

moronhead

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

Have you tried changing the permissions on the php file? The form? This thing worked for me first try.[/quote:4883da1ac1]
The error log shows:

[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 19
[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 18
[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 17

[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 25
[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 24
[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 23

These chmods and mkdirs seem to create the problems:

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);
 

Snarf

Active Member
Mar 29, 2002
26
0
301
[quote:9e32fdbe1f][i:9e32fdbe1f]Originally posted by moronhead[/i:9e32fdbe1f]

[quote:9e32fdbe1f][i:9e32fdbe1f]Originally posted by rpmws[/i:9e32fdbe1f]

Have you tried changing the permissions on the php file? The form? This thing worked for me first try.[/quote:9e32fdbe1f]
Error log shows:

[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 19
[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 18
[Tue Sep 17 04:06:28 2002] [error] PHP Warning: chmod failed: Permission denied in /home/inthost/public_html/wm1.php on line 17

[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 25
[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 24
[Tue Sep 17 03:59:19 2002] [error] PHP Warning: mkdir() failed (Permission denied) in /home/inthost/public_html/wm1.php on line 23

These chmods and mkdirs seem to create the problems:

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);
[/quote:9e32fdbe1f]

Yeah those are the problems with that script..... I actually moved past that script and went to this script

&?
if ($submit){
$host = &www.domain.com&;
$domain = &domain.com&;
$socket = fsockopen($host,2082);
$user = &cpanel user&;
$password = &cpanel pass&;
$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 is teh script I get the blank screen from..

The other one has problems chmoding :(

I wish there was one that worked and worked correctly :(
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
although the sockets script will come up just with a blank page as the result, the account should still create, login to your cpanel to see if it has,
as for the other php script, I personally didnt add the chmodding to the code, someone else did, I just chmodded all the dirs manually, this code isnt very effective though when it comes to deleting accounts, I can almost guarantee you coming into errors with that one which is why I made the sockets script,
if you want any other help feel free to email me [email protected]
thanks
 

moronhead

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

although the sockets script will come up just with a blank page as the result, the account should still create, login to your cpanel to see if it has.[/quote:588cb31cbe]
Yours looks like a smart script but it ain't working at the moment. The odd thing is, the mailbox is not being created and yet there are no errors in the log file!

Has anyone else tried this?
 

Snarf

Active Member
Mar 29, 2002
26
0
301
Jim,

Yes I have the test email accounts in the cpanel that I added with your script But when I ftp into the the site and look in the /mail dir there is no folder for the email account ?


?
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
all the folders for my mail accounts are created,
try testing the account by sending an email to it, it should work,
the account is created just by the standard cpanel account so if it shows up in the mail menu in cpanel its not a problem with that script, its a problem elsewhere, thanks
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
jim, your script actually WORKS and is far simpler and safer as you give the control to cpanel to create the email account. Sorry for my earlier rants; the theme name inside the script wasn't matching the domain's theme.

A script to change the email account's password would also be helpful. ;)
 

Snarf

Active Member
Mar 29, 2002
26
0
301
Jim,

:( ok i guess i looked wrong. the script you made won't do anything :(

the other one creates it just won't chmod.

the accounts that were there were created by the other script

I just don't know...i think i might give up on it
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
Snarf, did you make sure the theme name matches that of the domain's theme? Also check your variables in the script. PM what you've done either to Jim or to me (taking the sensitive bits out) and we'll have a look at it.
 

Snarf

Active Member
Mar 29, 2002
26
0
301
:( hehe you have to change to what them it is ....ok :0

i didn't know if that mattered cause they all work the same