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.

Email prob

Discussion in 'cPanel Developers' started by PHPEcono, Feb 2, 2009.

  1. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys,
    I created a comunaty website that has a custome made webmail systeme integrated into it. Everytime a member registers, an email account is created.

    Works greate ... but i am facing a problem.

    I don't know why, but seems there's a lot of pepol using the "Lost my password" option. Works great for the website but how can i make it change the email account at the same time with out knowing the old pass.
     
  2. hzJayJ

    hzJayJ Well-Known Member

    Joined:
    Nov 14, 2008
    Messages:
    76
    Likes Received:
    1
    Trophy Points:
    8
    You can login to your cpanel account and under email>>Email Accounts, you can see the option to change password for each account. You can enter the new password and there is no need to specify the old password to reset.
     
  3. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    ummm lol ? i don't wana be mean hzJayJ but this is the developper forum ... of course i ment using php to do it :p
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You would need to change the primary contact email on the account prior to somehow triggering the reset password function. The reset password function does not have an API counterpart that I am currently aware of.
     
  5. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    This is what i am working on

    $postfields = "email=" . $_POST['email'] . "&domain=" . $domain . "&password=" . $_POST['password1'] . '&quota=1';
    $popPost = curl_init();
    $url = "http://" . $username . ":" . $password . "@" . $domain . ":2082/frontend/" . $theme . "/mail/dopasswdpop.html?" . $postfields;
    curl_setopt($popPost, CURLOPT_URL, $url);
    curl_setopt($popPost, CURLOPT_POST, 1);
    curl_setopt($popPost, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($popPost, CURLOPT_TIMEOUT, 15);
    $popPost_result = curl_exec ($popPost);
    curl_close ($popPost);

    $start = strpos($popPost_result, '<b>Account');
    $end = strpos($popPost_result, '<!-- pre tag ended here -->');
    $responce = substr($popPost_result, $start, $end-$start);
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I recommend using our APIs instead of manually trying to post data to a HTML page is very likely to change.

    You would call the API2 function for changing the contact information via our XML API. You can learn more about this process at:

    http://www.cPanel.net/plugins/xmlapi

    The URL you would user is:
    Code:
    /xml-api/cpanel?user=[COLOR="RoyalBlue"]USERNAME[/COLOR]&xmlin=<cpanelaction><module>CustInfo</module><func>savecontactinfo</func><args><email>[COLOR="RoyalBlue"]first@example.com[/COLOR]</email><second_email>[COLOR="RoyalBlue"]second@example.com[/COLOR]</second_email><notify_disk_limit>[COLOR="RoyalBlue"]1[/COLOR]</notify_disk_limit><notify_bandwidth_limit>[COLOR="RoyalBlue"]1[/COLOR]</notify_bandwidth_limit><notify_email_quota_limit>[COLOR="RoyalBlue"]0[/COLOR]</notify_email_quota_limit></args></cpanelaction>
    The blue text represents the variable values. USERNAME is the cPanel username, first@example.com is the primary contact where email is sent to, second@example.com is the secondary email and the remaining settings control the notifications they receive.

    Note, leaving any of these arguments empty will result in a default value of an empty string (for strings) or 0 (for numbers) being applied.


    An alternate way of implementing the functionality you want to implement (sending a new password to someone other than the person on the account) would be to simply create a password, set it as the password via our APIs and email that password via your script.

    Note, sending passwords in plain text (such as via email) is generally considered poor security practice as plain text passwords are relatively easily intercepted while in transit.
     
  7. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Hmm ... I am not sure I understand your way ... I need to change the guy’s password into the new one the user asks for after there email is checked with out any humain intervention.

    1. The user forgets his password
    2. He clicks on forget
    3. He enters his email
    4. A link with a safe md5 string is saved to the DB and sent to his email
    5. He clicks on the link
    6. The generated md5 code is compared to the one in the DB
    7. An automated temporary password is created and sent to his email. Client is auto logged and prompted to change his password.

    What I need to do is automatically change the email password to keep the one for the site synchronized with the one for the email account.

    It all needs to be done with out any human intervention...

    If that’s not possible to do at the moment, can I request that new feature for the next WHM update?

    In the mean time I guess my only way would be to manually post the data to dopasswdpop.html
     
    #7 PHPEcono, Feb 5, 2009
    Last edited: Feb 5, 2009
  8. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Ah, webmail :). I thought we were talking about mailing back the cPanel user's password.

    Setting a webmail password can be done through our APIs. As for trapping password changes performed via the webmail interface, take a look at /usr/local/cpanel/hooks/README.

    The API1 call for changing a mail password is:

    <cpanel Email="passwdpop(email, password, quota, domain)">

    Note, the email parameter is simply the part of the email before @ so with someone@example.com, email would be 'someone' and domain would be 'example.com'

    password is the password and the quota is the user's email quota.

    This can be called via the XML API as described at: http://cpanel.net/plugins/xmlapi/cpanel.html
     
  9. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Yeah that looks more like what i need thx :)
    Is the quota value in KB or MB?
     
  10. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The quota value is specified in MB.
     
  11. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Hmm i don't get it ...

    PHP:
    // Change email password
    $cpusername '***';
    $cppassword '***';
    $host '***';

    $request '/xml-api/cpanel?user=$cpusername&xmlin=<cpanel Email="passwdpop('.$customers[username].'@***.***, '.$_POST[pass1].', 250, '.$host.')">';

    $ch curl_init();
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_URL"http://$host:2082" $request);  
    curl_setopt($chCURLOPT_USERPWD"$cpusername:$cppassword");

    $result curl_exec($ch);  
    curl_close($ch);

    // DDDDEEEEBBBBUUUUGGGG
    $Name "***"//senders name
    $email "***"//senders e-mail adress
    $mail_body "Email debugger\n\n$result"//mail body
    $subject "Email debugger"//subject
    $header "From: "$Name " <" $email ">\r\n"//optional headerfields
    mail("***"$subject$mail_body$header); //mail command :)
    /////////////////////////////////////////////////////////////////////////////
    This is the error i get by email when i try using this...

    Code:
    <cpanelresult><data><result>0</result><reason>Unknown Error</reason></data></cpanelresult>
    Unknown Error ... not really helping lol
     
  12. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I strongly recommend you familiarize yourself with the XML API. We have documentation for the XML API on our website at:

    http://www.cPanel.net/plugins/xmlapi

    Here are a few things you should be aware of:
    • The XML API works over the WHM ports, not the cPanel ports
    • You do not append API1 and API2 tags to the end of /xml-api/ to use them. You must use the appropriate XML API function call: cpanel.
    • passwdpop(), if any parameter contains an @, then you are not using that API call properly. The email address is split into its component parts: email, domain. email is the part before @, domain is the part after @.

    For example, I want to change the password of an email account test@example.com with a 25mb quota to SomePass, I would use this if I wanted to do this from outside the cPanel interface:

    Code:
    /xml-api/cpanel?user=[COLOR="RoyalBlue"]username[/COLOR]&xmlin=<cpanelaction><module>Email</module><func>passwdpop</func><apiversion>1</apiversion><args>[COLOR="RoyalBlue"]test[/COLOR]</args><args>[COLOR="RoyalBlue"]somepass[/COLOR]</args><args>[COLOR="RoyalBlue"]25[/COLOR]</args><args>[COLOR="RoyalBlue"]example.com[/COLOR]</args></cpanelaction>
    Where username is the cPanel username.
     
    #12 cPanelDavidG, Feb 5, 2009
    Last edited: Feb 5, 2009
  13. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    hmm well i found 2 errors ... cpanel?user='.$cpusername.'
    and i was also using ***@***.*** for the username when you said to use only the part before the @

    But i still get the same problem

    <cpanelresult><data><result>0</result><reason>Unknown Error</reason></data></cpanelresult>

    The string i am using looks like
    Code:
    /xml-api/cpanel?user=***&xmlin=<cpanel Email="passwdpop(***, ***, 250, ***)">
    All the data seems to be posted the right way as provided above

    PHP:
    // Change email password
    $cpusername '***';
    $cppassword '***';
    $host '***';

    $request '/xml-api/cpanel?user='.$cpusername.'&xmlin=<cpanel Email="passwdpop('.$customers[username].', '.$_POST[pass1].', 250, '.$host.')">';

    $ch curl_init();
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_URL"http://$host:2082" $request);  
    curl_setopt($chCURLOPT_USERPWD"$cpusername:$cppassword");

    $result curl_exec($ch);  
    curl_close($ch);

    // DDDDEEEEBBBBUUUUGGGG
    $Name "***"//senders name
    $email "***"//senders e-mail adress
    $mail_body "Email debugger\n\n$result"//mail body
    $subject "Email debugger"//subject
    $header "From: "$Name " <" $email ">\r\n"//optional headerfields
    mail("***"$subject$mail_body$header); //mail command :)
     
    #13 PHPEcono, Feb 5, 2009
    Last edited: Feb 5, 2009
  14. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    oh sorry i missed your post hehe let me do the changes and see if that does it.

    Thx bro ;-)
     
  15. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    This time i get no error ... but for some reason the password of the email is not changed ...

    PHP:
    //////////////////////////////////////////////////////////////////////////
    // Change email password
    $cpusername 'root';
    $cppassword '***';
    $host '***';

    $request '/xml-api/cpanel?user='.$cpusername.'&xmlin=<cpanelaction><module>Email</module><func>passwdpop</func><apiversion>1</apiversion><args>'.$customers[username].'</args><args>'.$_POST[pass1].'</args><args>250</args><args>'.$host.'</args></cpanelaction>';

    $ch curl_init();
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_URL"http://$host:2086" $request);  
    curl_setopt($chCURLOPT_USERPWD"$cpusername:$cppassword");

    $result curl_exec($ch);  
    curl_close($ch);

    // DDDDEEEEBBBBUUUUGGGG
    $Name "***"//senders name
    $email "***"//senders e-mail adress
    $mail_body "Email debugger\n\n$result\n\n$request"//mail body
    $subject "Email debugger"//subject
    $header "From: "$Name " <" $email ">\r\n"//optional headerfields
    mail("***"$subject$mail_body$header); //mail command :)
    /////////////////////////////////////////////////////////////////////////////
    One thing intresting abbou this is in the email debugger, $result is null but $request sends a valid xml-api string

    Code:
    /xml-api/cpanel?user=root&xmlin=<cpanelaction><module>Email</module><func>passwdpop</func><apiversion>1</apiversion><args>patrick</args><args>123456789</args><args>250</args><args>****</args></cpanelaction>
     
  16. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    ok well looks like i got it working. Thx for your help bro. This is a lot better then the code i was gona use.
     
Loading...

Share This Page