summaryrefslogtreecommitdiff
path: root/plugins/password/drivers/ximss.php
blob: 94aba18741fd35bf25c14fb5d33b2d5f11b37e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
 * Communigate driver for the Password Plugin for Roundcube 
 *
 * Tested with Communigate Pro 5.1.2
 *
 * Configuration options:
 *   password_ximss_host - Host name of Communigate server
 *   password_ximss_port - XIMSS port on Communigate server
 *
 *
 * References:
 *   http://www.communigate.com/WebGuide/XMLAPI.html
 *
 * @version 1
 * @author Erik Meitner <erik wanderings.us>
 */
 
function password_save($pass, $newpass)
{

  $rcmail = rcmail::get_instance();
  
  $sock = stream_socket_client("tcp://".$rcmail->config->get('password_ximss_host').":".$rcmail->config->get('password_ximss_port'), $errno, $errstr, 30) ;
  if( $sock === FALSE )
  {
    return PASSWORD_CONNECT_ERROR;
  }
  
  // send all requests at once(pipelined)
  fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");
  fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'"  />'."\0");
  fwrite( $sock, '<bye id="A003" />'."\0");

  //example responses
  //  <session id="A001" urlID="4815-vN2Txjkggy7gjHRD10jw" userName="user@example.com"/>\0
  //  <response id="A001"/>\0
  //  <response id="A002"/>\0
  //  <response id="A003"/>\0
  // or an error:
  //  <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0

  $responseblob = '';
  while (!feof($sock)) {
    $responseblob .= fgets($sock, 1024);
  }

  fclose($sock);
  
  foreach( explode( "\0",$responseblob) as $response )
  {
    $resp = simplexml_load_string("<xml>".$response."</xml>");

    if( $resp->response[0]['id'] == 'A001' )
    {
      if( isset( $resp->response[0]['errorNum'] ) )
      {
        return PASSWORD_CONNECT_ERROR;
      }  
    }
    else if( $resp->response[0]['id'] == 'A002' )
    {
      if( isset( $resp->response[0]['errorNum'] ))
      {
        return PASSWORD_ERROR;
      }  
    }
    else if( $resp->response[0]['id'] == 'A003' )
    {
      if( isset($resp->response[0]['errorNum'] ))
      {
        //There was a problem during logout(This is probably harmless)
      }  
    }
  } //foreach

  return PASSWORD_SUCCESS;
  
}
  
?>