I wanted to have a minimal and simple possibility to let the users change their passwords themselfs for zarafa. Best would be to have it as a webpage. I found a nice discussion about it here. Thus the php code from samu is made for Zarafa 6, I can validate that it is also working in version 7.1.5 beta, thanks to the stable mapi-api the script is using.

I just took the code and pasted it into a php file like mentioned in the post. The easiest solution for me was to put it in /usr/share/zarafa-webapp to have it available as https://host/webapp/change_password.php. Working perfectly. Thanks to samu for sharing it.

 Attention: If a user changes his password by this script, imap feature is getting disabled for him.

The script for documentation purpose:

<?php
require("mapi/mapi.util.php");
require("mapi/mapicode.php");
require("mapi/mapidefs.php");
require("mapi/mapitags.php");
require("mapi/mapiguid.php");

error_reporting(E_ALL);

$username = isset($_POST["username"])?$_POST["username"]:null;
$fullname = isset($_POST["fullname"])?$_POST["fullname"]: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){
        $session = mapi_logon_zarafa($username,$password);
        if ($session == false) {
                printf ("logon failed with error %x \n",mapi_last_hresult());
                print "$username and $password \n";

        } else {
                $stores = mapi_getmsgstorestable($session);
                $storeslist = mapi_table_queryallrows($stores);
                $store = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]);

                $user = mapi_zarafa_getuser($store, $username);
                $ok = false;
                $updname = true;
                if(($fullname == null) || (strlen($fullname) < 2)){
                        $fullname = $user['fullname'];
                        $updname = false;
                }
                if(mapi_zarafa_setuser($store,$user["userid"],$username,$fullname,$user["emailaddress"],$newpassword, 0, $user["admin"])){
                        echo "

ok
";

                }else{
                        echo "failed";
                }
                if (mapi_last_hresult()!=0){
                        echo "Error: 0x".dechex(mapi_last_hresult());
                        echo "<input type=\"button\" value=\"Try Again\" onClick=\"javascript:history.go(-1);\">\n";
                }else{
                        echo "changed";
                        echo "</p>
\n";
                        echo "<input type=\"button\" value=\"Close\" onClick=\"javascript:window.close();\">\n";
                }
        }

}else{
        header("Content-type: text/html; charset=utf-8");
?>
<html>
        <head>
                <title>Zarafa WebAccess</title>
                <link rel="stylesheet" type="text/css" href="client/layout/css/login.css">
                <link rel="icon" href="client/layout/img/favicon.ico"  type="image/x-icon">
                <link rel="shortcut icon" href="client/layout/img/favicon.ico" type="image/x-icon">     
                <script type="text/javascript">
                        window.onload = function(){
                                document.getElementById("username").focus();
                        }
                </script>
        </head>
        <body class="login">
                <table id="layout">
                        <tr><td>
                                <div id="login_main">
                                        <form action="change_password.php" method="post">
                                                <div id="login_data">
                                                <table id="form_fields">
                                                        <tr>
                                                                <th><label for="username"><?=_("Name")?>:</label></th>
                                                                <td><input type="text" name="username" id="username" class="inputelement"></td>
                                                        </tr>
                                                        <!--
                                                        <tr>
                                                                <th><label for="fullname">Fullname:</label></th>
                                                                <td><input type="text" name="fullname" id="fullname" class="inputelement"></td>
                                                        </tr>
                                                        -->
                                                        <tr>
                                                                <th><label for="oldpass">Old <?=_("Password")?>:</label></th>
                                                                <td><input type="password" name="password" class="inputelement"></td>
                                                        </tr>
                                                        <tr>    <th><label for="newpass">New <?=_("Password")?>:</label></th>
                                                                <td><input type="password" name="newpassword" class="inputelement"></td>
                                                        </tr>
                                                        <tr>
                                                                <th><label for="newpass">Again:</label></th>
                                                                <td><input type="password" name="newpassword2" class="inputelement"></td>
                                                        </tr>
                                                        <tr>
                                                                <td></td>
                                                                <td><input id="submitbutton" type="submit" value=<?=_("Change")?>></td>
                                                        </tr>
                                                </table>
                                                </div>
                                        </form>
                                </div>
                        </td></tr>
                </table>
        </body>
</html>

<?php  
}
?>

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden .