Author Topic: passwd change error  (Read 7148 times)

Offline MAO

  • Newbie
  • *
  • Posts: 5
passwd change error
« on: June 03, 2008, 12:20:32 AM »
PLZ Help !!!
postfix
dovecot
mysql (database type like in http://workaround.org/articles/ispmail-etch/ )

nano /var/www/email/program/steps/settings/passwd.inc
Code: [Select]

<?php

$db_server 
= &quot;localhost&quot;;
$db_user = &quot;mailuser&quot;;
$db_password = &quot;xxxxxxxxx&quot;;
$db_database = &quot;mailserver&quot;;

function 
dbConnect()
{
    global 
$db_server$db_user$db_password$db_database;

    if (!
mysql_connect($db_server$db_user$db_password)) {
        
WriteError(&quot;Can't connect to DB!&quot;);
    }
    if(!mysql_select_db($db_database)) {
        WriteError(&quot;Can'
t select DB: &quot; . $db_database);
    }
}

function 
dbClose()
{
    if(!
mysql_close()) {
        
WriteError(&quot;Can't close session with DB!&quot;);
    }
}

function WriteError($error)
{
    $message = $error;
    if ($mysql_error == mysql_error()) {
        $message .= &quot;<br /><em>&quot; . $mysql_error . &quot;</em>&quot;;
        print $message;
    }
    die;
}

dbConnect();

function CheckCurrentPasswd($curpasswd, $uname, $domain)
{

    global $CONFIG, $_SESSION, $OUTPUT;

    $sql = &quot;SELECT password FROM virtual_users WHERE user = '
$uname' AND domain_id = '$domain'&quot;;
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);

    if ($curpasswd == $row[&quot;password&quot;]) {

        return true;


    } elseif ($curpasswd != $row[&quot;password&quot;]) {

        return false;

    }

}

function rcmail_save_passwd($curpasswd, $newpasswd)
{

    global $CONFIG, $_SESSION, $OUTPUT;

    $curpasswd = trim($curpasswd);
    $newpasswd = trim($newpasswd);

    $data = explode('
@', $_SESSION['username']);
    $uname = $data[0];
    $domain = $data[1];

    if (CheckCurrentPasswd($curpasswd, $uname, $domain) == true) {

        $sql_update = &quot;UPDATE virtual_users SET password = ENCRYPT('
$newpasswd') WHERE user = '$uname' AND domain_id = '$domain'&quot;;
        $result_update = mysql_query($sql_update);

        if ($result_update == true) {

            return true;

        } elseif ($result_update == false) {

            return false;

        }

    } elseif (CheckCurrentPasswd($curpasswd, $uname, $domain) == false) {

        return false;

    }

}

function rcmail_passwd_form($attrib)
{

    global $CONFIG, $OUTPUT;

    list($form_start, $form_end) = get_form_tags($attrib, '
save-passwd');
    unset($attrib['
form']);

    if (!$attrib['
id'])
    $attrib['
id'] = 'rcmSavepassword';

    // allow the following attributes to be added to the <table> tag
    $attrib_str = create_attrib_string($attrib, array('
style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));

    // return the complete edit form as table
    $out = &quot;$form_start<table&quot; . $attrib_str . &quot;>\n\n&quot;;

    $a_show_cols = array('
curpasswd'   => array('type' => 'text'), 'newpasswd'   => array('type' => 'text'), 'confpasswd'   => array('type' => 'text'));

    // show current password field
    $field_id = '
curpasswd';
    $input_curpasswd = new passwordfield(array('
name' => '_curpasswd', 'id' => $field_id, 'size' => 30));

    $out .= sprintf(&quot;<tr><td class=\&quot;title\&quot;><label for=\&quot;%s\&quot;>%s</label></td><td>%s</td></tr>\n&quot;, $field_id, rep_specialchars_output(rcube_label('
curpasswd')), $input_curpasswd->show($CONFIG['curpasswd']));

    // show new password selection
    $field_id = '
newpasswd';
    $input_newpasswd = new passwordfield(array('
name' => '_newpasswd', 'id' => $field_id, 'size' => 30));

    $out .= sprintf(&quot;<tr><td class=\&quot;title\&quot;><label for=\&quot;%s\&quot;>%s</label></td><td>%s</td></tr>\n&quot;, $field_id, rep_specialchars_output(rcube_label('
newpasswd')), $input_newpasswd->show($CONFIG['newpasswd']));

    // show confirm password selection
    $field_id = '
confpasswd';
    $input_confpasswd = new passwordfield(array('
name' => '_confpasswd', 'id' => $field_id, 'size' => 30));

    $out .= sprintf(&quot;<tr><td class=\&quot;title\&quot;><label for=\&quot;%s\&quot;>%s</label></td><td>%s</td></tr>\n&quot;, $field_id, rep_specialchars_output(rcube_label('
confpasswd')), $input_confpasswd->show($CONFIG['confpasswd']));

    $out .= &quot;\n</table>$form_end&quot;;

    return $out;
}

// Handle user request
if ($_action=='
save-passwd')
{

    if (!isset($_POST['
_curpasswd']))
    $OUTPUT->show_message('
errorsaving', 'error');
    else if (!isset($_POST['
_newpasswd']))
    $OUTPUT->show_message('
errorsaving', 'error');
    else if (rcmail_save_passwd(get_input_value('
_curpasswd', RCUBE_INPUT_POST), get_input_value('_newpasswd', RCUBE_INPUT_POST))){
        $OUTPUT->show_message('
successfullysaved', 'confirmation');
    } else

    $OUTPUT->show_message('
errorsaving', 'error');

    // overwrite action variable
    rcmail_overwrite_action('
passwd');

}

rcube_add_label('
nocurrentpassword');
rcube_add_label('
nopassword');
rcube_add_label('
passwordinconsistency');
parse_template('
passwd');

dbClose();

?>



Offline SniZ

  • Newbie
  • *
  • Posts: 1
passwd change error
« Reply #1 on: June 04, 2008, 09:22:51 AM »
gimme the all code or where you take sources of plugin

Offline MAO

  • Newbie
  • *
  • Posts: 5
All Code !!!
« Reply #2 on: June 04, 2008, 09:34:29 AM »
HI! here is all code:


# In file /program/js/app.js
Code: [Select]

# Replace Line 264 with
        this.enable_command('preferences', 'identities', 'save', 'folders', 'passwd', true);

# Insert after Line 274
        if (this.env.action=='passwd' || this.env.action=='save-passwd')
          {
          var input_curpasswd = rcube_find_object('_curpasswd');
          var input_newpasswd = rcube_find_object('_newpasswd');
          var input_confpasswd = rcube_find_object('_confpasswd');
          if (input_curpasswd && input_curpasswd.value=='')
              input_curpasswd.focus();
          else if (input_confpasswd)
              input_confpasswd.focus();

          this.enable_command('save-passwd', true);
          }

# Insert after old Line 932 new Line 945
        break;

      case 'passwd':
        this.goto_url('passwd');
        break;

      case 'save-passwd':
        var input_curpasswd = rcube_find_object('_curpasswd');
        var input_newpasswd = rcube_find_object('_newpasswd');
        var input_confpasswd = rcube_find_object('_confpasswd');
        if (input_curpasswd && input_curpasswd.value=='')
            {
                alert(this.get_label('nocurrentpassword'));
                input_curpasswd.focus();
            }
        else if ((input_newpasswd && input_newpasswd.value=='') && (input_confpasswd && input_confpasswd.value==''))
            {
                alert(this.get_label('nopassword'));
                input_newpasswd.focus();
            }
        else if ((input_newpasswd && input_confpasswd) && ( input_newpasswd.value != input_confpasswd.value))
            {
                alert(this.get_label('passwordinconsistency'));
                input_newpasswd.focus();
            }
        else
                this.gui_objects.editform.submit();

# -------------------------------------------------------------------------------------------------------------

# In file /program/localizations/en_US/labels.inc
Code: [Select]

# Insert before the last line

$labels['changepasswd']  = 'Change Password';
$labels['curpasswd']  = 'Current Password';
$labels['newpasswd']  = 'New Password';
$labels['confpasswd']  = 'Confirm New Password';

# -------------------------------------------------------------------------------------------------------------

# In file /program/localizations/en_US/messages.inc
Code: [Select]

# Insert after line 78

$messages['nocurrentpassword'] = "Please input current password.";
$messages['nopassword'] = "Please input new password.";
$messages['passwordinconsistency'] = "Inconsistency of password, please try again.";


# -------------------------------------------------------------------------------------------------------------

# In file /skins/default/includes/settingstabs.html
Code: [Select]

# Insert after Line 2


# -------------------------------------------------------------------------------------------------------------

# Add File /skins/default/templates/passwd.html that contains
Code: [Select]



   
        <roundcube:object name="pagetitle" />
       
       
   
   

       
       
       

       

           


           

               

               



           

       


       

   


# -------------------------------------------------------------------------------------------------------------

# In File index.php
Code: [Select]

# Insert after line that reads:   include_once('program/steps/settings/func.inc'); (about line 343)

  if (($_action=='passwd') or ($_action=='save-passwd'))
    include('program/steps/settings/passwd.inc');

# -------------------------------------------------------------------------------------------------------------

# In file /program/steps/settings/func.inc
Code: [Select]

// register UI objects
$OUTPUT->add_handlers(array(
  'userprefs' => 'rcmail_user_prefs_form',
  'itentitieslist' => 'rcmail_identities_list',
  'userpasswd' => 'rcmail_passwd_form'
));

# -------------------------------------------------------------------------------------------------------------

passwd.inc file top

Offline MAO

  • Newbie
  • *
  • Posts: 5
passwd change error
« Reply #3 on: June 04, 2008, 09:38:30 AM »
Quote from: SniZ;12378
gimme the all code or where you take sources of plugin


HI! here is all code:


# In file /program/js/app.js
Code: [Select]

# Replace Line 264 with
        this.enable_command('preferences', 'identities', 'save', 'folders', 'passwd', true);

# Insert after Line 274
        if (this.env.action=='passwd' || this.env.action=='save-passwd')
          {
          var input_curpasswd = rcube_find_object('_curpasswd');
          var input_newpasswd = rcube_find_object('_newpasswd');
          var input_confpasswd = rcube_find_object('_confpasswd');
          if (input_curpasswd && input_curpasswd.value=='')
              input_curpasswd.focus();
          else if (input_confpasswd)
              input_confpasswd.focus();

          this.enable_command('save-passwd', true);
          }

# Insert after old Line 932 new Line 945
        break;

      case 'passwd':
        this.goto_url('passwd');
        break;

      case 'save-passwd':
        var input_curpasswd = rcube_find_object('_curpasswd');
        var input_newpasswd = rcube_find_object('_newpasswd');
        var input_confpasswd = rcube_find_object('_confpasswd');
        if (input_curpasswd && input_curpasswd.value=='')
            {
                alert(this.get_label('nocurrentpassword'));
                input_curpasswd.focus();
            }
        else if ((input_newpasswd && input_newpasswd.value=='') && (input_confpasswd && input_confpasswd.value==''))
            {
                alert(this.get_label('nopassword'));
                input_newpasswd.focus();
            }
        else if ((input_newpasswd && input_confpasswd) && ( input_newpasswd.value != input_confpasswd.value))
            {
                alert(this.get_label('passwordinconsistency'));
                input_newpasswd.focus();
            }
        else
                this.gui_objects.editform.submit();


# In file /program/localizations/en_US/labels.inc
Code: [Select]

# Insert before the last line

$labels['changepasswd']  = 'Change Password';
$labels['curpasswd']  = 'Current Password';
$labels['newpasswd']  = 'New Password';
$labels['confpasswd']  = 'Confirm New Password';


# In file /program/localizations/en_US/messages.inc
Code: [Select]

# Insert after line 78

$messages['nocurrentpassword'] = "Please input current password.";
$messages['nopassword'] = "Please input new password.";
$messages['passwordinconsistency'] = "Inconsistency of password, please try again.";


# In file /skins/default/includes/settingstabs.html
Code: [Select]

# Insert after Line 2



# Add File /skins/default/templates/passwd.html that contains
Code: [Select]



   
        <roundcube:object name="pagetitle" />
       
       
   
   

       
       
       

       

           


           

               

               



           

       


       

   



# In File index.php
Code: [Select]

# Insert after line that reads:   include_once('program/steps/settings/func.inc'); (about line 343)

  if (($_action=='passwd') or ($_action=='save-passwd'))
    include('program/steps/settings/passwd.inc');


# In file /program/steps/settings/func.inc
Code: [Select]

// register UI objects
$OUTPUT->add_handlers(array(
  'userprefs' => 'rcmail_user_prefs_form',
  'itentitieslist' => 'rcmail_identities_list',
  'userpasswd' => 'rcmail_passwd_form'
));

# -------------------------------------------------------------------------------------------------------------

passwd.inc file top

Offline MAO

  • Newbie
  • *
  • Posts: 5
passwd change error
« Reply #4 on: June 10, 2008, 01:53:34 AM »
Sombody Help me Please !!!

Offline rodti

  • Newbie
  • *
  • Posts: 4
passwd change error
« Reply #5 on: December 10, 2008, 08:53:18 AM »
This won't work because the 'domain_id' field is a numeric reference to the 'virtual_domains' table, not the domain name itself.