The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add mail users using php?

Discussion in 'E-mail Discussions' started by mattbates, Jul 31, 2002.

  1. mattbates

    mattbates Registered

    Joined:
    Jul 31, 2002
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  2. F1RULZ

    F1RULZ Registered

    Joined:
    Jul 29, 2002
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  3. tonybsilva

    tonybsilva Registered

    Joined:
    Sep 7, 2002
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  4. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    you need to chmod the mail directories and files for the script to work
     
  5. powerhouse

    powerhouse Well-Known Member

    Joined:
    Nov 5, 2001
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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 joe@mydomain.net
    or joe@mydomain.com

    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.
     
  6. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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
     
  7. henrychoo

    henrychoo Registered

    Joined:
    Dec 2, 2001
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi jimcater,

    Can you show us how?:)
     
  8. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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
     
  9. henrychoo

    henrychoo Registered

    Joined:
    Dec 2, 2001
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    [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.
     
  10. Snarf

    Snarf Active Member

    Joined:
    Mar 29, 2002
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    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 :)
     
  11. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
  12. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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,
     
    #12 jimcarter, Sep 14, 2002
    Last edited: Oct 31, 2003
  13. Snarf

    Snarf Active Member

    Joined:
    Mar 29, 2002
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    Well I was looking for a full script actually :) php preferred .

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

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    that is a php script, just put in side the &? and ?&
    there isnt anything like this available unfortunately
     
  15. Snarf

    Snarf Active Member

    Joined:
    Mar 29, 2002
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    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.

    ?
     
  16. Snarf

    Snarf Active Member

    Joined:
    Mar 29, 2002
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    opps pushed refresh :(
     
  17. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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 :)
     
  18. bdraco

    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&
     
  19. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    [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.
     
  20. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    check the $in = line, yours seems to be different than the one that I posted
     
Loading...

Share This Page