From 1904fa71046fd1782b9a3b61bd408cf779824500 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 09 Oct 2009 12:04:01 -0400
Subject: [PATCH] - Added XIMSS (Communigate) driver for Password plugin

---
 CHANGELOG                            |    1 
 plugins/password/drivers/ximss.php   |   81 ++++++++++++++++++++++++++++++++++++++++
 plugins/password/README              |   16 ++++++--
 plugins/password/config.inc.php.dist |    9 ++++
 4 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 2d0930c..05ca7b0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG RoundCube Webmail
 ===========================
 
+- Added XIMSS (Communigate) driver for Password plugin
 - Fix newly attached files are not saved in drafts w/o editing any text (#1486202)
 - Added attachment upload indicator with parallel upload (#1486058)
 - Use default_charset for bodies of messages without charset definition (#1486187)
diff --git a/plugins/password/README b/plugins/password/README
index ac725f8..c7e8203 100644
--- a/plugins/password/README
+++ b/plugins/password/README
@@ -32,6 +32,7 @@
  2.4.	LDAP (ldap)
  2.5.	DirectAdmin Control Panel
  2.6.   cPanel
+ 2.7.   XIMSS (Communigate)
  3.	Driver API
 
 
@@ -157,8 +158,8 @@
  2.3. Poppassd/Courierpassd (poppassd)
  -------------------------------------
 
- You can specify which host to connect to via `password_pop_host` and
- what port via `password_pop_port`. See config.inc.php file for more info.
+ You can specify which host to connect to via 'password_pop_host' and
+ what port via 'password_pop_port'. See config.inc.php file for more info.
 
 
  2.4. LDAP (ldap)
@@ -170,8 +171,8 @@
  2.5. DirectAdmin Control Panel
  -------------------------------------
 
- You can specify which host to connect to via `password_directadmin_host` 
- and what port via `password_direactadmin_port`. See config.inc.php file 
+ You can specify which host to connect to via 'password_directadmin_host' 
+ and what port via 'password_direactadmin_port'. See config.inc.php file 
  for more info.
 
 
@@ -182,6 +183,13 @@
  interface. See config.inc.php file for more info.
 
 
+ 2.7. XIMSS (Communigate)
+ -------------------------------------
+
+ You can specify which host and port to connect to via 'password_ximss_host' 
+ and 'password_ximss_port'. See config.inc.php file for more info.
+
+
  3. Driver API
  -------------
 
diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist
index d311948..b9e3b91 100644
--- a/plugins/password/config.inc.php.dist
+++ b/plugins/password/config.inc.php.dist
@@ -179,4 +179,13 @@
 // The cPanel theme in use
 $rcmail_config['password_cpanel_theme'] = 'x';
 
+
+// XIMSS (Communigate server) Driver options
+// -----------------------------------------
+// Host name of the Communigate server
+$rcmail_config['password_ximss_host'] = 'mail.example.com';
+
+// XIMSS port on Communigate server
+$rcmail_config['password_ximss_port'] = 11024;
+
 ?>
diff --git a/plugins/password/drivers/ximss.php b/plugins/password/drivers/ximss.php
new file mode 100644
index 0000000..94aba18
--- /dev/null
+++ b/plugins/password/drivers/ximss.php
@@ -0,0 +1,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;
+  
+}
+  
+?>
\ No newline at end of file

--
Gitblit v1.9.1