Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: ikaris on February 09, 2009, 09:17:23 PM

Title: Change Password for QmailAdmin / roundcube0.2stable
Post by: ikaris on February 09, 2009, 09:17:23 PM
Base on:
 http://wheaties.us/blog/2008/12/21/change-password-roundcube/

alter function ( roundcube/program/steps/settings/password.inc ):


function rcube_save_password($current_password,$new_password)
{
        global $OUTPUT, $RCMAIL;

        $emailuser=$_SESSION['username'];

        //$db = rcmail::get_instance()->get_dbh();

        // YOU MUST CHANGE THIS QUERY LINE TO MATCH YOUR DATABASE SETTINGS !!!!!
        //$passwordquery = "UPDATE database.table SET password_field =ENCRYPT('".$new_password."') WHERE user_name = '".$emailuser."';";  

        //$db->query($passwordquery);

        //console("email: $emailuser");
        //console("current password: $current_password");
        //console("New password: $new_password");

        //set POST variables
        $url = 'http://localhost/qmailadmin/index.cgi/passwd/';

        $fields = array(
                'address'=>urlencode($emailuser),
                'oldpass'=>urlencode($current_password),
                'newpass1'=>urlencode($new_password),
                'newpass2'=>urlencode($new_password),
                );

        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string,'&');

        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POST,count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_HEADER,0);  // DO NOT RETURN HTTP HEADERS
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  // RETURN THE CONTENTS OF THE CALL

        //execute post
        //console("Curl: $url$fields_string");
        $result = curl_exec($ch);

        ob_start();
        header("Content-Type: text/html");
        $Temp_Output = ltrim(rtrim(trim(strip_tags(trim(preg_replace ( "/\s\s+/" , " " , html_entity_decode($result)))),"\n\t\r\h\v\0 ")), "%20");
        $Temp_Output = ereg_replace (' +', ' ', trim($Temp_Output));
        $Temp_Output = ereg_replace("[\r\t\n]","",$Temp_Output);

        /* The \b in the pattern indicates a word boundary, so only the distinct
         * word "web" is matched, and not a word partial like "webbing" or "cobweb" */
        if (preg_match("/\bsuccessfully\b/i", $Temp_Output)) {

                //console ("Temp_Out : $Temp_Output");

                $_SESSION['password'] = encrypt_password($new_password);

                $OUTPUT->show_message('successfullysaved', 'confirmation');
        } else {
                //console ("Temp_Out : $Temp_Output");
                $error_msg= explode(':',$Temp_Output);
                //console ("Error msg : $error_msg[0]");
                $OUTPUT->show_message("$error_msg[0]", 'error');
                //$OUTPUT->show_message('errorsaving', 'error');
        }

        //console ("Temp_Out : $Temp_Output");
        $Final_Out=ob_get_clean();
        //console ("Final_Out : $Final_Out");

        //close connection
        curl_close($ch);
}


(http://www.ingeniarte.com/images/rc-password.gif)
Title: Change Password for QmailAdmin / roundcube0.2stable
Post by: ikaris on February 09, 2009, 09:23:09 PM
ups :D

Base on: wheaties.us || Andy and Natasha Wheatley's Blog (http://wheaties.us/blog/2008/12/21/change-password-roundcube/)