Home
Zarafa Passwort ändern ? How-To

If you are using the db plugin you could make a simple webpage with PHP to do this, for example:




<?php
error_reporting
(E_ALL);

$username = isset($_POST["username"])?$_POST["username"]:null;
$password = isset($_POST["password"])?$_POST["password"]:null;
$newpassword = isset($_POST["newpassword"])?$_POST["newpassword"]:null;
$newpassword2 = isset($_POST["newpassword2"])?$_POST["newpassword2"]:null;

if ($username!=null && $password!=null && $newpassword!=null && $newpassword2==$newpassword){
        $stores = mapi_openmsgstore_zarafa($username,$password);
        $store = $stores[0];

        $user = mapi_zarafa_getuser($store, $username);
        $ok = false;
        if(mapi_zarafa_setuser($store,$user["userid"],$user["fullname"],$user["emailaddress"],$newpassword, 0, $user["admin"])){
                echo "success ";

        }else{
                echo "failed";
        }
        if (mapi_last_hresult()!=0){
                echo "Error: 0x".dechex(mapi_last_hresult());
        }else{
                echo "changed";
        }

}else{
        echo '
                <form action="change_password.php" method="post">
                        <table>
                                <tr><th>Username:</th><td><input type="text" name="username"></td></tr>
                                <tr><th>Old Password:</th><td><input type="password" name="password"></td></tr>
                                <tr><th>New Password:</th><td><input type="password" name="newpassword"></td></tr>
                                <tr><th>Again:</th><td><input type="password" name="newpassword2"></td></tr>
                                <tr><td colspan=2><input type="submit" value="Change password"></td></tr>
                        </table>
                </form>
        '
;
}
?>

I was looking for something like this, but I had to make the following change to get it to work for me:
Code: Select all
if(mapi_zarafa_setuser($store,$user["userid"],$user["fullname"],$user["emailaddress"],$newpassword, 0, $user["admin"])){

added $username to the vars passed to mapi_zarafa_setuser:
Code: Select all
if(mapi_zarafa_setuser($store,$user["userid"],$username,$user["fullname"],$user["emailaddress"],$newpassword, 0, $user["admin"])){

diff -urN webaccess_org/client/layout/dialogs/modal/password.php webaccess/client/layout/dialogs/modal/password.php
--- webaccess_org/client/layout/dialogs/modal/password.php	1970-01-01 01:00:00.000000000 +0100
+++ webaccess/client/layout/dialogs/modal/password.php	2009-03-22 16:47:51.000000000 +0100
@@ -0,0 +1,87 @@
+<?php
+
+function getDialogTitle(){
+	return _("Change password"); // use gettext here
+}
+
+
+function getBody() { 
+	global $task;
+
+	if(!isset($_POST['user'])) {
+	    echo "<p><script type=\"text/javascript\">\n";
+
+	    echo "var username;\n";
+	    echo "if(window.dialogArguments) username = window.dialogArguments.parentWindow.webclient.username;\n";
+	    echo "else username = window.opener.webclient.username;\n";
+
+	    echo "function valinput() {\n";
+	    echo "if(document.pass.password.value==\"\") { alert('Type old password!'); return false; }\n";
+	    echo "if(document.pass.newpassword.value==\"\") { alert('Type new password!'); return false; }\n";
+	    echo "if(document.pass.newpassword2.value==\"\") { alert('Retype new password!'); return false; }\n";
+	    echo "if(document.pass.newpassword.value !== document.pass.newpassword2.value) { alert('Passwords don\'t match!'); return false; }\n";
+	    echo "return true;\n";
+	    echo "}\n";
+
+	    echo "document.write('Change password for user: <b>'+username+'</b></p>');\n";
+	    echo "document.write('<form name=\"pass\" action=\"'+DIALOG_URL+'task=password_modal\" method=\"post\" onSubmit=\"return valinput();\">');\n";
+	    echo "document.write('<input type=\"hidden\" name=\"user\" value=\"'+username+'\">');\n";
+	    echo "</script><table>\n";
+	    echo "<tr><th align=\"right\">Old password:</th><td><input type=\"password\" name=\"password\"></td></tr>\n";
+	    echo "<tr><th align=\"right\">New password:</th><td><input type=\"password\" name=\"newpassword\"></td></tr>\n";
+	    echo "<tr><th align=\"right\">Retype password:</th><td><input type=\"password\" name=\"newpassword2\"></td></tr>\n";
+	    echo "<tr><td align=\"right\" colspan=2> </td></tr>\n";
+	    echo "<tr><td align=\"right\" colspan=2> </td></tr>\n";
+	    echo "<tr><td align=\"center\"><input type=\"button\" value=\"Close\" onClick=\"javascript:window.close()\"></td>\n";
+	    echo "<td align=\"center\"><input type=\"submit\" value=\"Change password\"></td></tr>\n";
+	    echo "</table></form>\n";
+	} else {
+
+	    echo "<p>";
+
+	    function ldap_change($user, $pass, $newpass) {
+		$ldapconfig['host'] = 'ldap://localhost:389';
+		$ldapconfig['basedn'] = 'dc=basedc,dc=com';
+
+		if(!($ds=@ldap_connect($ldapconfig['host']))) { echo "Error connecting to: ".$ldapconfig['host']; return false; }
+		if(!($r =@ldap_search($ds, $ldapconfig['basedn'], 'uid='.$user))) { echo "Error searching LDAP."; return false; }
+		$result = @ldap_get_entries($ds, $r);
+		if((isset($result[0])) && ($result[0])) {
+		    if(@ldap_bind($ds, $result[0]['dn'], $pass)) {
+			mt_srand((double)microtime()*1000000);
+			$salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand());
+			$entry["userPassword"] = "{SSHA}" . base64_encode(pack("H*", sha1($newpass . $salt)) . $salt);
+			if(ldap_modify($ds, $result[0]['dn'], $entry)) {
+			    return true;
+			}
+		    }
+		}
+
+		echo "Could not bind to LDAP. Incorrect password?";
+		return false;
+
+	    }
+
+	    if(ldap_change($_POST['user'], $_POST['password'], $_POST['newpassword'])) {
+		echo "Password changed for user <b>".$_POST['user']."</b>.";
+	    }
+
+	    echo "</p><br>\n";
+	    echo "<input type=\"button\" value=\"Close\" onClick=\"javascript:window.close();\">\n";
+	}
+
+	echo "<!-- $task -->\n";
+    } // getBody
+
+function getMenuButtons(){
+	return array(
+			"close"=>array(
+				'id'=>"close",
+				'name'=>_("Close"),
+				'title'=>_("Close window"),
+				'callback'=>'function(){window.close();}'
+			)
+		);
+}
+
+?>
diff -urN webaccess_org/client/layout/dialogs/settings/tabs/preferences.php webaccess/client/layout/dialogs/settings/tabs/preferences.php
--- webaccess_org/client/layout/dialogs/settings/tabs/preferences.php	2009-03-03 16:50:04.000000000 +0100
+++ webaccess/client/layout/dialogs/settings/tabs/preferences.php	2009-03-22 16:48:31.000000000 +0100
@@ -127,6 +127,14 @@
</tr>
</table>
</fieldset>
+	<fieldset>
+		<legend><?=_("Password")?></legend>
+		<table class="options">
+			<tr>
+				<th colspan="2"><input type="button" value="Change password" onClick="webclient.openModalDialog(null, 'password', DIALOG_URL+'task=password_modal', 280, 300);"></th>
+			</tr>
+		</table>
+	</fieldset>
<?php } 
 
< zurück   weiter >