]> git.donarmstrong.com Git - roundcube.git/blob - plugins/password/drivers/ximss.php
Imported Debian patch 0.5.2+dfsg-1
[roundcube.git] / plugins / password / drivers / ximss.php
1 <?php
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 1
16  * @author Erik Meitner <erik wanderings.us>
17  */
18  
19 function password_save($pass, $newpass)
20 {
21
22   $rcmail = rcmail::get_instance();
23   
24   $sock = stream_socket_client("tcp://".$rcmail->config->get('password_ximss_host').":".$rcmail->config->get('password_ximss_port'), $errno, $errstr, 30) ;
25   if( $sock === FALSE )
26   {
27     return PASSWORD_CONNECT_ERROR;
28   }
29   
30   // send all requests at once(pipelined)
31   fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");
32   fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'"  />'."\0");
33   fwrite( $sock, '<bye id="A003" />'."\0");
34
35   //example responses
36   //  <session id="A001" urlID="4815-vN2Txjkggy7gjHRD10jw" userName="user@example.com"/>\0
37   //  <response id="A001"/>\0
38   //  <response id="A002"/>\0
39   //  <response id="A003"/>\0
40   // or an error:
41   //  <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0
42
43   $responseblob = '';
44   while (!feof($sock)) {
45     $responseblob .= fgets($sock, 1024);
46   }
47
48   fclose($sock);
49   
50   foreach( explode( "\0",$responseblob) as $response )
51   {
52     $resp = simplexml_load_string("<xml>".$response."</xml>");
53
54     if( $resp->response[0]['id'] == 'A001' )
55     {
56       if( isset( $resp->response[0]['errorNum'] ) )
57       {
58         return PASSWORD_CONNECT_ERROR;
59       }  
60     }
61     else if( $resp->response[0]['id'] == 'A002' )
62     {
63       if( isset( $resp->response[0]['errorNum'] ))
64       {
65         return PASSWORD_ERROR;
66       }  
67     }
68     else if( $resp->response[0]['id'] == 'A003' )
69     {
70       if( isset($resp->response[0]['errorNum'] ))
71       {
72         //There was a problem during logout(This is probably harmless)
73       }  
74     }
75   } //foreach
76
77   return PASSWORD_SUCCESS;
78   
79 }
80   
81 ?>