Modified poppassd.php3

Patrick Boutilier boutilpj@ednet.ns.ca
Tue, 17 Oct 2000 11:44:55 -0300


---------------------- multipart/mixed attachment
Hello,

I modified poppassd.php3 to work with a mysql database containing the
userid/passwords of the IMAP accounts.

I called the file mysqlpass.php3 and it makes a direct change to the
mysql database instead of using an intermediate server. I put the
function and config parts in mysqlpass.php3 instead of lib/db.mysql and
defaults.php3 so I wouldn't have to keep adding them everytime an
upgraded is done.

This works with IMP 2.2.3 and I hope someone else will find it of use.

I have named my attachment mysqlpass.txt

---------------------- multipart/mixed attachment
<?php

/*
  
  File: poppassd.php3
  Author: oliver
  Revision: 1.0
  Date: 1999/01/04
  
  Copyright 1999, 2000 Oliver M. Bolzer <oliver@gol.com>
  
  You should have received a copy of the GNU Public
  License along with this package; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
  
*/

if (!defined('HORDE_LIB')) include '../lib/horde.lib';
require './lib/imp.lib';           /* IMPlib is the IMP function library  */
require '../config/horde.php3';
require './config/defaults.php3';  /* Defaults configuration file */
require './config/html.php3';
require './config/lang.php3';
error_reporting($default->error_level);
$language = select_lang();
require './lib/postconf.php3';
require "./locale/$language/passwd.lang";
require './locale/local/passwd.lang';


/* Define database values for password change */

$default->db_name2 = school; 	/* Database that contains authentication information */
$default->db_table = user;		/* Table in the databse */
$default->db_user_field = userid; 	/* User field */
$default->db_passwd_field = passwd; 	/* Password field */

/* add help in future */
/* require "./help/defines/passwd.help"; */

/* read the current session; exit if there isn't a valid one */
page_open(array('sess' => 'HordeSession'));
page_close();
if (!isset($imp) || !is_object($imp)) { header("Location: login.php3?reason=logout"); exit; }
$imp->unpickle();

/* doctype */
require "$default->include_dir/doctype.inc";

/* Define imp_change_password function */

function imp_change_password ($old_pass, $new_pass, $username) {
    global $default;

    /* post: changes $oldpass to $newpass
           returns true on success and false on failure
        */

    if (!($db = mysql_pconnect($default->db_server_name, $default->db_user_name, $default->db_password))) { return false; }
    if (!($imp = mysql_select_db($default->db_name2, $db))) { return false; }
    if (!($result = mysql_db_query($default->db_name2, "update $default->db_table set $default->db_passwd_field = '$new_pass' 
	where $default->db_user_field ='$username'",$db))) { return false; }
    
    return true;
}

/* run through ActionIDs */
if (isset($actionID)) {
	switch ($actionID) {
	case NO_ACTION:
		break;
    
	case PASSWD_INPUT:
		include "$default->include_dir/passwd/poppassd_input.inc";
		break;
    
	case PASSWD_DISALLOW:
		$errortype = 'nopermission';
		include "$default->include_dir/passwd/poppassd_error.inc";
		break;
    
	case PASSWD_CHANGE:	        /* now we change the passwd */
		/* error checking */
		if (!($username == $imp->user)) {
			$errortype = 'username';
			include "$default->include_dir/passwd/poppassd_error.inc";
		}
		if (strcmp($old_pass, $imp->pass) != 0) {
			$errortype = 'old_pass';
			include "$default->include_dir/passwd/poppassd_error.inc";
		}
		if (strlen($new_pass) <= 4) {
			$errortype = 'short_pass';
			include "$default->include_dir/passwd/poppassd_error.inc";
		}
		if (strcmp($new_pass, $new_pass2) != 0) {
			$errortype = 'new_pass_ne';
			include "$default->include_dir/passwd/poppassd_error.inc";
		}
/* 
		if ($errortype) {
			return;
		}
*/
    
		/* OK, the input data seems to be OK, connect */

			$passd = imp_change_password ($old_pass, $new_pass, $username);
		if (!$passd){
				print "Whoops. Database config error";
} else {
			/* yeah, password changed, user must re-login */
			echo '<script language=javascript>
            window.location="login.php3?reason=chpass";
            </script>';
			exit;
}
		break;
    
	default:
		include "$default->include_dir/passwd/poppassd_input.inc";
	}
} else {
  include "$default->include_dir/passwd/poppassd_input.inc";
}

?>

---------------------- multipart/mixed attachment--