Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: igeoffi on June 27, 2006, 01:59:00 AM

Title: RoundCube Webmail 0.1-beta changepassword patch
Post by: igeoffi on June 27, 2006, 01:59:00 AM
REPOST
originally posted by poison

this patch/plugin will allow you to change your password

please note: i did not make/create this hack therefore i am not offering any support for this hack or any gurantee that this hack will work for you

Quote
When I was deploying the new corporate mailserver I needed to re-install the webmail client. We used to work with SquirrelMail (http://www.squirrelmail.org/), a very decent and extendable webmail client. But we all know that the UI of SquirrelMail is ugly, really ugly.

So after some googling I came across this new great webmail client named RoundCube (http://www.roundcube.net/). This is a new fully featured AJAX-based webmail client with a very slick UI. From the first moment I saw that RoundCube was the way to go.

After I did the installation and played around with the webclient I wanted to extend it and give the ability to my users to change their password. The basic idea was to add a tab ‘Password’ in the settings window. Since I’ve configured my mailserver (postfix) with mysql (user fields are created dynamically) it’s just a matter of updating the correct row in the database and reconnect to the IMAP server (courier-imap).
The only problem is that the framework of RoundCube is creap, and I mean really crap. It took me 6 hours to create the tab and the underlaying forms / code. Not because I work that slow but because it’s not intuitive and you have to mess in 5 files in order to add a new action (Ok, I only worked at night on it so my mind wasn’t that clear but anyway).
Below I’ve attached the patch, so if some of you want to make your own tab you can read through the patch and see how it works.

It uses an external script (ext/change_password_function.inc) with one function in it: change_password_function ($user, $currentpass, $newpass).
In my case, it just updates the postfix mailbox database but you can modify this code to fit your needs (eg. if you use the courierpassd you can connect to the password-daemon and change the user’s password here).
Enjoy it,
Nicolas

download: click here (http://www.poison.be/wp-content/uploads/2006/05/roundcubemail-0.1beta-changepassword.patch)

Source: http://www.poison.be/?p=8
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: SKaero on June 27, 2006, 02:17:24 AM
Thanks For posting this, It will be a good tool!
Title: Little change in change_password_function.inc to work with vpopmail (mysql)
Post by: Hunteru on July 08, 2006, 09:51:53 PM
I made a few changes in the original file to work with vpopmail (mysql).

Code: [Select]
<?php

/*
 +-----------------------------------------------------------------------+
 | program/steps/settings/change_password.inc              |
 |                                    |
 | This file is part of the RoundCube Webmail client           |
 | Copyright (C) 2005, RoundCube Dev. - Switzerland           |
 | Licensed under the GNU GPL                      |
 |                                    |
 | PURPOSE:                               |
 |  Show edit form for a identity record or to add a new one      |
 |                                    |
 +-----------------------------------------------------------------------+
 | Author: Nicolas Van Eenaeme <nicolas@poison.be>            |
 +-----------------------------------------------------------------------+

 $Id: edit_identity.inc,v 1.1 2006/05/21 05:19:43 roundcube Exp $

*/

 // The host of the database
 
define ('RCUBE_EXT_CHANGE_PASS_HOST''localhost');

 
// The username to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_USER''user');

 
// The password to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_PASS''password');

 
// The name of the database
 
define ('RCUBE_EXT_CHANGE_PASS_NAME''vpopmail');

 
// The update query. You can use '%clear%' for the clear password,
 //                '%md5%'  for the md5 encrypted password,
 //                '%user%'  for the username,
 //                '%old%'  for the old password and
 //                '%oldmd5%' for the old md5 encrypted password.
 
define ('RCUBE_EXT_CHANGE_PASS_UPDATEQUERY''UPDATE vpopmail SET pw_clear_passwd = &quot;%clear%&quot;, pw_passwd = &quot;%md5%&quot; WHERE pw_name = &quot;%user%&quot; AND pw_passwd = &quot;%oldmd5%&quot; AND pw_domain = &quot;%domain%&quot;');

 
// The select query (needed to verify the md5.
 
define ('RCUBE_EXT_CHANGE_PASS_SELECTQUERY''SELECT pw_passwd FROM vpopmail WHERE pw_name = &quot;%user%&quot; AND pw_domain = &quot;%domain%&quot;');

 function 
split_user ($user)
  {
   list(
$s_user$s_domain) = split('[@]'$user);
   return array(
$s_user,$s_domain);
  }

 function 
change_password_function ($s_user$currentpass$newpass)
  {
list ($user$domain) = split_user ($s_user);

  
$dbh =& mysql_connect (RCUBE_EXT_CHANGE_PASS_HOSTRCUBE_EXT_CHANGE_PASS_USERRCUBE_EXT_CHANGE_PASS_PASS);
  if (!
is_resource ($dbh))
   return 
FALSE;

  if (!
mysql_select_db (RCUBE_EXT_CHANGE_PASS_NAME$dbh))
   return 
FALSE;

  
$q str_replace (array ('%user%''%domain%'), array ($user$domain), RCUBE_EXT_CHANGE_PASS_SELECTQUERY);
 
  
$dbr =& mysql_query ($q$dbh);
  if (!
is_resource ($dbr))
   return 
FALSE;

  
$data mysql_fetch_row ($dbr);
  
mysql_free_result ($dbr);

  
$newpassmd5 crypt ($newpass$data[0]);
  
$currentpassmd5 crypt ($currentpass$data[0]);
  
$q str_replace (array ('%user%''%domain%''%clear%''%md5%''%old%''%oldmd5%'), array ($user$domain$newpass$newpassmd5$currentpass$currentpassmd5), RCUBE_EXT_CHANGE_PASS_UPDATEQUERY);

  
$dbr =& mysql_query ($q$dbh);
  if (!
$dbr || mysql_affected_rows ($dbh) != 1)
    return 
FALSE;

  
mysql_close ($dbh);
  return 
TRUE;
  }

?>


Thx for the original tool. 8)
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: chadsmith on July 30, 2006, 02:37:21 AM
Here are the changes if you are using Roundcube with hMailServer...

Code: [Select]
<?php

/*
 +-----------------------------------------------------------------------+
 | program/steps/settings/change_password.inc              |
 |                                    |
 | This file is part of the RoundCube Webmail client           |
 | Copyright (C) 2005, RoundCube Dev. - Switzerland           |
 | Licensed under the GNU GPL                      |
 |                                    |
 | PURPOSE:                               |
 |  Show edit form for a identity record or to add a new one      |
 |                                    |
 +-----------------------------------------------------------------------+
 | Author: Nicolas Van Eenaeme <nicolas@poison.be>            |
 +-----------------------------------------------------------------------+

 $Id: edit_identity.inc,v 1.1 2006/05/21 05:19:43 roundcube Exp $

*/

 // The host of the database
 
define ('RCUBE_EXT_CHANGE_PASS_HOST''localhost');

 
// The username to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_USER''user');

 
// The password to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_PASS''password');

 
// The name of the database
 
define ('RCUBE_EXT_CHANGE_PASS_NAME''database');

 
// The update query. You can use '%clear%' for the clear password,
 //                '%md5%'  for the md5 encrypted password,
 //                '%user%'  for the username,
 //                '%old%'  for the old password and
 //                '%oldmd5%' for the old md5 encrypted password.
 
define ('RCUBE_EXT_CHANGE_PASS_UPDATEQUERY''UPDATE hm_accounts SET accountpassword = &quot;%md5%&quot; WHERE accountaddress = &quot;%user%&quot; AND accountpassword = &quot;%oldmd5%&quot;');

 
// The select query (needed to verify the md5.
 
define ('RCUBE_EXT_CHANGE_PASS_SELECTQUERY''SELECT accountpassword FROM hm_accounts WHERE accountaddress = &quot;%user%&quot;');


 function 
change_password_function ($user$currentpass$newpass)
  {
  
$dbh =& mysql_connect (RCUBE_EXT_CHANGE_PASS_HOSTRCUBE_EXT_CHANGE_PASS_USERRCUBE_EXT_CHANGE_PASS_PASS);
  if (!
is_resource ($dbh))
   return 
FALSE;

  if (!
mysql_select_db (RCUBE_EXT_CHANGE_PASS_NAME$dbh))
   return 
FALSE;

  
$q str_replace ('%user%'$userRCUBE_EXT_CHANGE_PASS_SELECTQUERY);
  
$dbr =& mysql_query ($q$dbh);
  if (!
is_resource ($dbr))
   return 
FALSE;

  
$data mysql_fetch_row ($dbr);
  
mysql_free_result ($dbr);

  
$newpassmd5 md5($newpass);
  
$currentpassmd5 md5($currentpass);
  
$q str_replace (array ('%user%''%clear%''%md5%''%old%''%oldmd5%'), array ($user$newpass$newpassmd5$currentpass$currentpassmd5), RCUBE_EXT_CHANGE_PASS_UPDATEQUERY);

  
$dbr =& mysql_query ($q$dbh);
  if (!
$dbr || mysql_affected_rows ($dbh) != 1)
    return 
FALSE;

  
mysql_close ($dbh);
  return 
TRUE;
  }

?>
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: Rick on August 14, 2006, 12:40:51 AM
I can use one of these Password patches if my server uses Qmail? I use a Virtual Server provided by a hosting company and can access the backend via Plesk configurations. The server comes with Horde (ugly interface) to handle "webmail functions." I am using RoundCube for my site members, but have to refer them to Horde to be able make a password change on their own. Can one of these patched noted here allow my members to change their email through RoundCube.  If the change is made via RoundCube/MySQL, does it change it everywhere like Horde does or just on MySQL? Sorry, if I should know this. I would love to just forget Horde, but it is the only option I have at the moment to let members change their own PWs.

Any advice or suggestions will be greatly apprecaited.  -- Rick
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: 123123 on August 14, 2006, 11:40:57 AM
can someone tell how to install the patch ;/

when i press download i get this :

Quote
diff -ruN roundcubemail-0.1beta.orig/ext/change_password_function.inc roundcubemail-0.1beta/ext/change_password_function.inc
--- roundcubemail-0.1beta.orig/ext/change_password_function.inc   1970-01-01 01:00:00.000000000 +0100
+++ roundcubemail-0.1beta/ext/change_password_function.inc   2006-05-21 05:19:43.000000000 +0200
@@ -0,0 +1,74 @@
++
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/settings/change_password.inc              |
+ |                                    |
+ | This file is part of the RoundCube Webmail client           |
+ | Copyright (C) 2005, RoundCube Dev. - Switzerland           |
+ | Licensed under the GNU GPL                      |
+ |                                    |
+ | PURPOSE:                               |
+ |  Show edit form for a identity record or to add a new one      |
+ |                                    |
+ +-----------------------------------------------------------------------+
+ | Author: Nicolas Van Eenaeme            |
+ +-----------------------------------------------------------------------+
+
+ $Id: edit_identity.inc,v 1.1 2006/05/21 05:19:43 roundcube Exp $
+
+*/
+
+ // The host of the database
+ define ('RCUBE_EXT_CHANGE_PASS_HOST', 'localhost');
+
+ // The username to connect to the database
+ define ('RCUBE_EXT_CHANGE_PASS_USER', 'postfix');
+
+ // The password to connect to the database
+ define ('RCUBE_EXT_CHANGE_PASS_PASS', 'password');
+
+ // The name of the database
+ define ('RCUBE_EXT_CHANGE_PASS_NAME', 'postfix');
+
+ // The update query. You can use '%clear%' for the clear password,
+ //                '%md5%'  for the md5 encrypted password,
+ //                '%user%'  for the username,
+ //                '%old%'  for the old password and
+ //                '%oldmd5%' for the old md5 encrypted password.
+ define ('RCUBE_EXT_CHANGE_PASS_UPDATEQUERY', 'UPDATE mailbox SET password = "%md5%" WHERE username = "%user%" AND password = "%oldmd5%"');
+
+ // The select query (needed to verify the md5.
+ define ('RCUBE_EXT_CHANGE_PASS_SELECTQUERY', 'SELECT password FROM mailbox WHERE username = "%user%"');
+
+
+ function change_password_function ($user, $currentpass, $newpass)
+  {
+  $dbh =& mysql_connect (RCUBE_EXT_CHANGE_PASS_HOST, RCUBE_EXT_CHANGE_PASS_USER, RCUBE_EXT_CHANGE_PASS_PASS);
+  if (!is_resource ($dbh))
+   return FALSE;
+
+  if (!mysql_select_db (RCUBE_EXT_CHANGE_PASS_NAME, $dbh))
+   return FALSE;
+
+  $q = str_replace ('%user%', $user, RCUBE_EXT_CHANGE_PASS_SELECTQUERY);
+  $dbr =& mysql_query ($q, $dbh);
+  if (!is_resource ($dbr))
+   return FALSE;
+
+  $data = mysql_fetch_row ($dbr);
+  mysql_free_result ($dbr);
+
+  $newpassmd5 = crypt ($newpass, $data[0]);
+  $currentpassmd5 = crypt ($currentpass, $data[0]);
+  $q = str_replace (array ('%user%', '%clear%', '%md5%', '%old%', '%oldmd5%'), array ($user, $newpass, $newpassmd5, $currentpass, $currentpassmd5), RCUBE_EXT_CHANGE_PASS_UPDATEQUERY);
+
+  $dbr =& mysql_query ($q, $dbh);
+  if (!$dbr || mysql_affected_rows ($dbh) != 1)
+    return FALSE;
+
+  mysql_close ($dbh);
+  return TRUE;
+  }
+
+?>
diff -ruN roundcubemail-0.1beta.orig/index.php roundcubemail-0.1beta/index.php
--- roundcubemail-0.1beta.orig/index.php   2006-02-21 00:29:13.000000000 +0100
+++ roundcubemail-0.1beta/index.php   2006-05-21 03:46:20.000000000 +0200
@@ -330,6 +330,8 @@
  if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || $_action=='create-folder' || $_action=='delete-folder')
   include('program/steps/settings/manage_folders.inc');
 
+ if ($_action=='password' || $_action=='change-password')
+  include('program/steps/settings/change_password.inc');
  }
 
 
--- roundcubemail-0.1beta.orig/program/include/main.inc   2006-02-21 00:29:13.000000000 +0100
+++ roundcubemail-0.1beta/program/include/main.inc   2006-05-20 02:04:38.000000000 +0200
@@ -1072,7 +1072,8 @@
     'identityform' => 'rcube_identity_form',
     'foldersubscription' => 'rcube_subscription_form',
     'createfolder' => 'rcube_create_folder_form',
-    'composebody' => 'rcmail_compose_body'
+    'composebody' => 'rcmail_compose_body',
+    'changepassform' => 'rcmail_change_pass_form'
    );
 
   
diff -ruN roundcubemail-0.1beta.orig/program/js/app.js roundcubemail-0.1beta/program/js/app.js
--- roundcubemail-0.1beta.orig/program/js/app.js   2006-02-19 21:21:58.000000000 +0100
+++ roundcubemail-0.1beta/program/js/app.js   2006-05-21 15:37:23.000000000 +0200
@@ -194,7 +194,7 @@
 
 
    case 'settings':
-    this.enable_command('preferences', 'identities', 'save', 'folders', true);
+    this.enable_command('preferences', 'identities', 'save', 'folders', 'password', true);
     
     if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity')
      this.enable_command('edit', 'add', 'delete', true);
@@ -205,6 +205,9 @@
     if (this.env.action=='folders')
      this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'delete-folder', true);
     
+    if (this.env.action=='password')
+     this.enable_command('change-password', true);
+    
     var identities_list = this.gui_objects.identitieslist;
     if (identities_list)
      this.init_identitieslist(identities_list);
@@ -946,6 +949,41 @@
      this.delete_folder(props);
     break;
 
+   case 'password':
+    location.href = this.env.comm_path+'&_action=password';
+    break;
+
+   case 'change-password':
+    if (this.gui_objects.editform)
+     {
+     var input_currentpass = rcube_find_object('_currentpass');
+     var input_newpass = rcube_find_object('_newpass');
+     var input_confirmpass = rcube_find_object('_confirmpass');
+
+     if (input_currentpass.value == "")
+      {
+      alert(this.get_label('nocurrentpasswarning'));
+      input_currentpass.focus();
+      break;
+      }
+
+     if (input_newpass.value == "")
+      {
+      alert(this.get_label('nonewpasswarning'));
+      input_newpass.focus();
+      break;
+      }
+
+     if (input_newpass.value != input_confirmpass.value)
+      {
+      alert(this.get_label('nomatchpasswarning'));
+      input_confirmpass.focus();
+      break;
+      }
+
+     this.gui_objects.editform.submit();
+     }
+    break;
    }
 
   return obj ? false : true;
diff -ruN roundcubemail-0.1beta.orig/program/localization/en_US/labels.inc roundcubemail-0.1beta/program/localization/en_US/labels.inc
--- roundcubemail-0.1beta.orig/program/localization/en_US/labels.inc   2006-02-04 19:05:36.000000000 +0100
+++ roundcubemail-0.1beta/program/localization/en_US/labels.inc   2006-05-21 03:53:49.000000000 +0200
@@ -179,6 +179,12 @@
 $labels['newitem'] = 'New item';
 $labels['edititem'] = 'Edit item';
 
+$labels['changepassword'] = 'Change your password';
+
+$labels['currentpass'] = 'Current password';
+$labels['newpass'] = 'New password';
+$labels['confirmpass'] = 'Confirm new password';
+
 $labels['setdefault'] = 'Set default';
 $labels['language'] = 'Language';
 $labels['timezone'] = 'Time zone';
diff -ruN roundcubemail-0.1beta.orig/program/localization/en_US/messages.inc roundcubemail-0.1beta/program/localization/en_US/messages.inc
--- roundcubemail-0.1beta.orig/program/localization/en_US/messages.inc   2006-01-25 21:10:12.000000000 +0100
+++ roundcubemail-0.1beta/program/localization/en_US/messages.inc   2006-05-21 14:46:15.000000000 +0200
@@ -88,4 +88,12 @@
 
 $messages['nosearchname'] = 'Please enter a contact name or email address';
 
+$messages['nocurrentpasswarning'] = 'Please enter your current password';
+
+$messages['nonewpasswarning'] = 'Please enter your new password';
+
+$messages['nomatchpasswarning'] = 'The new password and it\'s confirmation doesn\'t match';
+
+$messages['invalidpassword'] = 'Your current password is invalid';
+
 ?>
diff -ruN roundcubemail-0.1beta.orig/program/steps/settings/change_password.inc roundcubemail-0.1beta/program/steps/settings/change_password.inc
--- roundcubemail-0.1beta.orig/program/steps/settings/change_password.inc   1970-01-01 01:00:00.000000000 +0100
+++ roundcubemail-0.1beta/program/steps/settings/change_password.inc   2006-05-21 14:46:33.000000000 +0200
@@ -0,0 +1,103 @@
++
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/settings/change_password.inc              |
+ |                                    |
+ | This file is part of the RoundCube Webmail client           |
+ | Copyright (C) 2005, RoundCube Dev. - Switzerland           |
+ | Licensed under the GNU GPL                      |
+ |                                    |
+ | PURPOSE:                               |
+ |  Change the current password into a new one             |
+ |                                    |
+ +-----------------------------------------------------------------------+
+ | Author: Nicolas Van Eenaeme            |
+ +-----------------------------------------------------------------------+
+
+ $Id: edit_identity.inc,v 1.1 2006/05/21 14:46:33 roundcube Exp $
+
+*/
+
+// init IAMP connection
+rcmail_imap_init(TRUE);
+
+if ($_POST['_action'] == 'change-password')
+ {
+ include ('ext/change_password_function.inc');
+ if ($_SESSION['password'] != encrypt_passwd($_POST['_currentpass']))
+  {
+  show_message('invalidpassword', 'error');
+  }
+ elseif (false || change_password_function ($_SESSION['username'], $_POST['_currentpass'], $_POST['_newpass']))
+  {
+  $IMAP->pass = $_POST['_newpass'];
+  $IMAP->reconnect ();
+  $_SESSION['password'] = encrypt_passwd($_POST['_newpass']);
+
+  show_message('successfullysaved', 'confirmation');
+  }
+ else
+  show_message('errorsaving', 'error');
+
+  // go to next step
+  $_action = 'password';
+
+  // overwrite action variable
+  $OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action));
+  }
+
+ $PAGE_TITLE = rcube_label('changepassword');
+
+
+function rcmail_change_pass_form($attrib)
+ {
+ global $IDENTITY_RECORD, $JS_OBJECT_NAME;
+
+ // add some labels to client
+ rcube_add_label('nocurrentpasswarning');
+ rcube_add_label('nonewpasswarning');
+ rcube_add_label('nomatchpasswarning');
+
+ list($form_start, $form_end) = get_form_tags($attrib, 'change-password');
+ unset($attrib['form']);
+
+
+ // return the complete edit form as table
+ $out = "$form_start\n\n";
+
+ // show the current password field
+ $field_id = 'rcmfd_currentpass';
+ $input_currentpass = new passwordfield(array('name' => '_currentpass', 'id' => $field_id, 'size' => 20));
+
+ $out .= sprintf("\n",
+         $field_id,
+         rep_specialchars_output(rcube_label('currentpass')),
+         $input_currentpass->show());
+
+ // show the new password field
+ $field_id = 'rcmfd_newpass';
+ $input_newpass = new passwordfield(array('name' => '_newpass', 'id' => $field_id, 'size' => 20));
+
+ $out .= sprintf("\n",
+         $field_id,
+         rep_specialchars_output(rcube_label('newpass')),
+         $input_newpass->show());
+
+ // show the confirm password field
+ $field_id = 'rcmfd_confirmpass';
+ $input_confirmpass = new passwordfield(array('name' => '_confirmpass', 'id' => $field_id, 'size' => 20));
+
+ $out .= sprintf("\n",
+         $field_id,
+         rep_specialchars_output(rcube_label('confirmpass')),
+         $input_confirmpass->show());
+
+ $out .= "\n
%s
%s
%s
$form_end";
+
+ return $out;
+ }
+
+
+ parse_template('changepassword');
+?>
\ No newline at end of file
diff -ruN roundcubemail-0.1beta.orig/skins/default/includes/settingstabs.html roundcubemail-0.1beta/skins/default/includes/settingstabs.html
--- roundcubemail-0.1beta.orig/skins/default/includes/settingstabs.html   2005-09-25 16:18:58.000000000 +0200
+++ roundcubemail-0.1beta/skins/default/includes/settingstabs.html   2006-05-17 20:12:34.000000000 +0200
@@ -1,3 +1,4 @@
 

 
+
 

diff -ruN roundcubemail-0.1beta.orig/skins/default/templates/changepassword.html roundcubemail-0.1beta/skins/default/templates/changepassword.html
--- roundcubemail-0.1beta.orig/skins/default/templates/changepassword.html   1970-01-01 01:00:00.000000000 +0100
+++ roundcubemail-0.1beta/skins/default/templates/changepassword.html   2006-05-21 03:33:05.000000000 +0200
@@ -0,0 +1,27 @@
+
+
+
+<roundcube:object name="pagetitle" />
+
+
+
+
+
+
+
+
+
+

+

+
+

+
+
+



+

+

+
+
+
+
+


what i have to do next??
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: ric on August 14, 2006, 08:43:36 PM
Installed this patch with beta2, works well.

Quote
123123,
what i have to do next??

123123, you can either using a patching program to apply the patch or edit the files by hand, what mailserver are you using?
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: 123123 on August 15, 2006, 03:33:40 AM
i have no idea what program to use. i use cpanel. maybe someone have seperate files of this plugin and know what changes must be done in other files?
Title: Re: Little change in change_password_function.inc to work with vpopmail (mysql)
Post by: mike413 on August 16, 2006, 01:00:43 PM
Quote from: Hunteru
I made a few changes in the original file to work with vpopmail (mysql).

Code: [Select]
<?php

/*
 +-----------------------------------------------------------------------+
 | program/steps/settings/change_password.inc              |
 |                                   |
 | This file is part of the RoundCube Webmail client          |
 | Copyright (C) 2005, RoundCube Dev. - Switzerland           |
 | Licensed under the GNU GPL                      |
 |                                   |
 | PURPOSE:                               |
 | Show edit form for a identity record or to add a new one      |
 |                                   |
 +-----------------------------------------------------------------------+
 | Author: Nicolas Van Eenaeme <nicolas@poison.be>           |
 +-----------------------------------------------------------------------+

 $Id: edit_identity.inc,v 1.1 2006/05/21 05:19:43 roundcube Exp $

*/

 // The host of the database
 
define ('RCUBE_EXT_CHANGE_PASS_HOST''localhost');

 
// The username to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_USER''user');

 
// The password to connect to the database
 
define ('RCUBE_EXT_CHANGE_PASS_PASS''password');

 
// The name of the database
 
define ('RCUBE_EXT_CHANGE_PASS_NAME''vpopmail');

 
// The update query. You can use '%clear%' for the clear password,
 //               '%md5%'  for the md5 encrypted password,
 //               '%user%' for the username,
 //               '%old%'  for the old password and
 //               '%oldmd5%' for the old md5 encrypted password.
 
define ('RCUBE_EXT_CHANGE_PASS_UPDATEQUERY''UPDATE vpopmail SET pw_clear_passwd = &quot;%clear%&quot;, pw_passwd = &quot;%md5%&quot; WHERE pw_name = &quot;%user%&quot; AND pw_passwd = &quot;%oldmd5%&quot; AND pw_domain = &quot;%domain%&quot;');

 
// The select query (needed to verify the md5.
 
define ('RCUBE_EXT_CHANGE_PASS_SELECTQUERY''SELECT pw_passwd FROM vpopmail WHERE pw_name = &quot;%user%&quot; AND pw_domain = &quot;%domain%&quot;');

 function 
split_user ($user)
  {
   list(
$s_user$s_domain) = split('[@]'$user);
   return array(
$s_user,$s_domain);
  }

 function 
change_password_function ($s_user$currentpass$newpass)
  {
list ($user$domain) = split_user ($s_user);

  
$dbh =& mysql_connect (RCUBE_EXT_CHANGE_PASS_HOSTRCUBE_EXT_CHANGE_PASS_USERRCUBE_EXT_CHANGE_PASS_PASS);
  if (!
is_resource ($dbh))
   return 
FALSE;

  if (!
mysql_select_db (RCUBE_EXT_CHANGE_PASS_NAME$dbh))
   return 
FALSE;

  
$q str_replace (array ('%user%''%domain%'), array ($user$domain), RCUBE_EXT_CHANGE_PASS_SELECTQUERY);
 
 
$dbr =& mysql_query ($q$dbh);
  if (!
is_resource ($dbr))
   return 
FALSE;

  
$data mysql_fetch_row ($dbr);
  
mysql_free_result ($dbr);

  
$newpassmd5 crypt ($newpass$data[0]);
  
$currentpassmd5 crypt ($currentpass$data[0]);
  
$q str_replace (array ('%user%''%domain%''%clear%''%md5%''%old%''%oldmd5%'), array ($user$domain$newpass$newpassmd5$currentpass$currentpassmd5), RCUBE_EXT_CHANGE_PASS_UPDATEQUERY);

  
$dbr =& mysql_query ($q$dbh);
  if (!
$dbr || mysql_affected_rows ($dbh) != 1)
    return 
FALSE;

  
mysql_close ($dbh);
  return 
TRUE;
  }

?>


Thx for the original tool. 8)

Thanks you so mush for your PATCH, that work fine for me with the beta2.
But just one problem found:
when i have applied the patch, i found one error in the result with the file program/include/main.inc.rej

Code: [Select]
***************
*** 1072,1078 ****
     'identityform' => 'rcube_identity_form',
     'foldersubscription' => 'rcube_subscription_form',
     'createfolder' => 'rcube_create_folder_form',
-     'composebody' => 'rcmail_compose_body'
    );


--- 1072,1079 ----
     'identityform' => 'rcube_identity_form',
     'foldersubscription' => 'rcube_subscription_form',
     'createfolder' => 'rcube_create_folder_form',
+     'composebody' => 'rcmail_compose_body',
+     'changepassform' => 'rcmail_change_pass_form'
    );

So, i have edited the main.inc and i have added
Code: [Select]
'changepassform' => 'rcmail_change_pass_form' at the line 1236 (// USER SETTINGS) like this:
Code: [Select]
   // USER SETTINGS
    'userprefs' => 'rcmail_user_prefs_form',
    'itentitieslist' => 'rcmail_identities_list',
    'identityframe' => 'rcmail_identity_frame',
    'identityform' => 'rcube_identity_form',
    'foldersubscription' => 'rcube_subscription_form',
    'createfolder' => 'rcube_create_folder_form',
    'renamefolder' => 'rcube_rename_folder_form',
    'composebody' => 'rcmail_compose_body',
    'changepassform' => 'rcmail_change_pass_form'

And now, that work.

Thanks you.
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: 123123 on August 16, 2006, 01:04:27 PM
how to apply the patch? HELP please :(
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: mike413 on August 17, 2006, 02:32:19 AM
Quote from: 123123
how to apply the patch? HELP please :(

hi,

Go to your RoundCube webmail directory and do that at the command line:
Code: [Select]
wget [url]http://www.poison.be/wp-content/uploads/2006/05/roundcubemail-0.1beta-changepassword.patch[/url]
To apply the patch:

Code: [Select]
patch -p1 < roundcubemail-0.1beta-changepassword.patch
That all.

Regards.

Mike.

Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: 123123 on August 17, 2006, 11:00:56 AM
sorry but i dont understanf :( i am using host with cpanel, so where i have to enter these comand lines? thanks in advance
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: mike413 on August 17, 2006, 04:01:55 PM
Quote from: 123123
sorry but i dont understanf :( i am using host with cpanel, so where i have to enter these comand lines? thanks in advance

ah ok, sorry!

I don't know cpanel. My last post is for the Linux user that have an access to the command line.

Sorry again 123123.

Mike.
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: tickus on August 29, 2006, 04:53:44 PM
When I try to change the password I get the following error. 'An error occured while saving' Why might I be getting this.

Thanks

___________
Tickus
http://www.tickus.com (http://www.tickus.com)
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: pensive612 on September 06, 2006, 05:17:36 AM
i get the same error...

any ideas?
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: rgonzalez on September 11, 2006, 11:24:42 AM
what if the user/pass is stored in a corporate ms-sql database..? can I rewrite mysql_connect to eqivalent php mssql_connect...? keeping the logic is my concern, how to access the database should be irrelevant if the logic is not affected while doing so.

am I on the right track here..?

regards and thanks for a real webmail interface !
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: ledhed on September 21, 2006, 02:22:32 PM
I decided to upgrade to beta2.
I applied this patch to roundcube-beta2, and all seems to have gone well except that when I go to change my password, there are no fields to change the password.

I had this patch working on the previous version of Roundcube.

Any ideas???

(http://ledhed.net/junk/RC-ChPass.jpg)


-LedHed
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: bozhe on September 22, 2006, 02:13:11 PM
When I got the error 'An error occured while saving' I checked the logs/errors file which told me 'PHP Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'postfix'@'localhost' (using password: YES) in /opt/lampp/htdocs/rc/ext/change_password_function.inc on line 47' . I checked that location and it seems one is supposed to enter info about the mysql database of the imap server (assumed to be postfix). I hope that this info help others in solving this problem ('An error occured while saving'). Unfortunately, the imap server I use is a squirrelmail server, which uses a mysql database but I dont think that passwords are stored there (squirrelmail, at least the way it's set up by me, uses the servers user database in /etc/passwd and /etc/shadow).
 I am not a programmer; Is there a way to modify the change_password_function to change a squirelmail password which is actually a linux system password?(when we change user's passwords, we [the system admins] have to log on to the linux/squirrel mail server and use the passwd command).
 This is a great add-on to roundcube; if only it could be easily configured to change passwords on a few types of imap servers (postfix, squirrelmail, exim, etc.) with various database configurations (mysql, postgres,ldap, etc) it would be a MAGNIFICENT add-on.

 bozhe
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: dfitch on September 22, 2006, 02:44:14 PM
Thanks for the Contrib, works great with beta2 and hMailServer!! ;)
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: kali on September 23, 2006, 04:03:35 PM
Quote from: bozhe
I am not a programmer; Is there a way to modify the change_password_function to change a squirelmail password which is actually a linux system password?(when we change user's passwords, we [the system admins] have to log on to the linux/squirrel mail server and use the passwd command).
 This is a great add-on to roundcube; if only it could be easily configured to change passwords on a few types of imap servers (postfix, squirrelmail, exim, etc.) with various database configurations (mysql, postgres,ldap, etc) it would be a MAGNIFICENT add-on.

 bozhe

Hi Bozhe,

See my thread on "changing /etc/shadow" password plug-in. It works and is finalized (and I have it in production). Just as a note - different imap servers maintain user data differently. Cyrus IMAP keeps it in the sasl database (non-local users) and therefore pretty easy to change. Others keep mysql databases for user id/pw. UW-imap and other services like samba, ftp etc. require you have "local users" and changing those passwords is not as easy (requiring that user access - as in setuid - or root access). This is difficult to impossible for the web server to do and is best achieved with cgi. This is how squirrel did it - and how I approached it.

If you are running local users - and want pw change functionality built right into the preferences tab - check this thread - try it and let me know if you have any comment!!

http://roundcubeforum.net/forum/index.php?topic=551.msg2925#msg2925
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: bozhe on September 25, 2006, 12:12:10 PM
Thank you, kali, for the info and for taking the time to respond to my post. I will try out what you suggest and let you know what happens.

 bozhe :)
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: bozhe on October 03, 2006, 01:25:50 PM
Hi Kali,

 Your changepassword patch worked wonderfully. Thank you so much for writing what is an elegant and bug-free (I haven't found any) patch.

bozhe

 
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: kali on October 03, 2006, 02:53:54 PM
Quote from: bozhe
Hi Kali,

 Your changepassword patch worked wonderfully. Thank you so much for writing what is an elegant and bug-free (I haven't found any) patch.

bozhe

Thanks bozhe! 8)

I'm hoping that - like some other webmail apps - the RC "owners" can set up a plugin area where links to various plugins (downloads and updates) could be found - rather than having to search through postings on the forum.
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: jeeth on October 04, 2006, 06:04:53 AM
Quote from: SKaero
Thanks For posting this, It will be a good tool!

I have chaged the function rcmail_save_passwd() in file program/steps/settings/passwd.inc , which now can accept the imap password change through the port 106, let me know if it is usefull.

Thanks
jeeth
-----------------------------------------------------------------
function rcmail_save_passwd($new_pw){
 global $CONFIG, $_SESSION;
 $poppassd_server = "localhost"; //imap server address

 $old_pw = decrypt_passwd($_SESSION['password']);
 $username = $_SESSION['username'];

 $pop_socket = fsockopen($poppassd_server, 106, $errno, $errstr);
  if (!$pop_socket) {
    $messages[] = _("ERROR") . ': ' . "$errstr ($errno)";
    return FALSE;
    return $messages;
  }

  cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
  if(!preg_match('/^2\d\d/', $result) ) {
    cpw_poppassd_closeport($pop_socket, $messages, $debug);
    return FALSE;
    return $messages;
  }

  fputs($pop_socket, "user $username\r\n");
  cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
  if(!preg_match('/^[23]\d\d/', $result) ) {
    cpw_poppassd_closeport($pop_socket, $messages, $debug);
    return FALSE;
    return $messages;
  }


 fputs($pop_socket, "pass $old_pw\r\n");
  cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
  if(!preg_match('/^[23]\d\d/', $result) ) {
    cpw_poppassd_closeport($pop_socket, $messages, $debug);
    return FALSE;
    return $messages;
  }
 fputs($pop_socket, "newpass $new_pw\r\n");
  cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
  cpw_poppassd_closeport($pop_socket, $messages, $debug);
   $_SESSION['password'] = encrypt_passwd($new_pw);
  if(!preg_match('/^2\d\d/', $result) ) {
    return FALSE;
    return $messages;
  }

  return TRUE;

}
//-- following function have been added ---//

function cpw_poppassd_closeport($pop_socket, &$messages, $debug = 0) {
  if ($debug) {
    array_push($messages, _("Closing Connection"));
  }
  fputs($pop_socket, "quit\r\n");
  fclose($pop_socket);
}

function cpw_poppassd_readfb($pop_socket, &$result, &$messages, $debug = 0) {
  $strResp = '';
  $result = '';

  if (!feof($pop_socket)) {
   $strResp = fgets($pop_socket, 1024);
   $result = substr(trim($strResp), 0, 3); // 200, 500
   if(!preg_match('/^[23]\d\d/', $result) || $debug) {
     $messages[] = "--> $strResp";
   }
  }
}
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: fredanthony on October 12, 2006, 04:29:51 PM
Quote from: ledhed
I decided to upgrade to beta2.
I applied this patch to roundcube-beta2, and all seems to have gone well except that when I go to change my password, there are no fields to change the password.

I had this patch working on the previous version of Roundcube.

Any ideas???

(http://ledhed.net/junk/RC-ChPass.jpg)


-LedHed

Yep, I got the same issue, latest install no form fileds showing, only the save button.
Title: Re: RoundCube Webmail 0.1-beta changepassword patch
Post by: knarph on October 28, 2006, 02:40:30 AM
Quote from: jeeth
I have chaged the function rcmail_save_passwd() in file program/steps/settings/passwd.inc , which now can accept the imap password change through the port 106, let me know if it is usefull.

Thanks
jeeth

I've applied this patch to roundcubemail 0.1b2 and made it available for download. It should be a way simpler install for those of you who had trouble applying jeeth's patch.

You can find the tarball at http://iacovino.org/ (http://iacovino.org/)