Thomas Bruederli
2013-06-20 07c6c69eca8751c0e96a846afb30c24ab2638b1f
commit | author | age
48e9c1 1 <?php
T 2 /**
3  * Communigate driver for the Password Plugin for Roundcube 
4  *
5  * Tested with Communigate Pro 5.1.2
6  *
7  * Configuration options:
8  *   password_ximss_host - Host name of Communigate server
9  *   password_ximss_port - XIMSS port on Communigate server
10  *
11  *
12  * References:
13  *   http://www.communigate.com/WebGuide/XMLAPI.html
14  *
15  * @version 2.0
16  * @author Erik Meitner <erik wanderings.us>
17  */
18
19 class rcube_ximss_password
20 {
21     function save($pass, $newpass)
22     {
23         $rcmail = rcmail::get_instance();
24
25         $host = $rcmail->config->get('password_ximss_host');
26         $port = $rcmail->config->get('password_ximss_port');
27         $sock = stream_socket_client("tcp://$host:$port", $errno, $errstr, 30);
28
29         if ($sock === FALSE) {
30             return PASSWORD_CONNECT_ERROR;
31         }
32
33         // send all requests at once(pipelined)
34         fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");
35         fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'"  />'."\0");
36         fwrite( $sock, '<bye id="A003" />'."\0");
37
38   //example responses
39   //  <session id="A001" urlID="4815-vN2Txjkggy7gjHRD10jw" userName="user@example.com"/>\0
40   //  <response id="A001"/>\0
41   //  <response id="A002"/>\0
42   //  <response id="A003"/>\0
43   // or an error:
44   //  <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0
45
46         $responseblob = '';
47         while (!feof($sock)) {
48             $responseblob .= fgets($sock, 1024);
49         }
50
51         fclose($sock);
52
53         foreach( explode( "\0",$responseblob) as $response ) {
54             $resp = simplexml_load_string("<xml>".$response."</xml>");
55
56             if( $resp->response[0]['id'] == 'A001' ) {
57                 if( isset( $resp->response[0]['errorNum'] ) ) {
58                     return PASSWORD_CONNECT_ERROR;
59                 }
60             }
61             else if( $resp->response[0]['id'] == 'A002' ) {
62                 if( isset( $resp->response[0]['errorNum'] )) {
63                     return PASSWORD_ERROR;
64                 }
65             }
66             else if( $resp->response[0]['id'] == 'A003' ) {
67                 if( isset($resp->response[0]['errorNum'] )) {
68                     //There was a problem during logout(This is probably harmless)
69                 }
70             }
71         } //foreach
72
73         return PASSWORD_SUCCESS;
74
75     }
76 }