The use of 'user' as a column name no longer causes errors in SquirrelMail/PostgreSQL
[squirrelmail.git] / plugins / change_password / backend / vmailmgrd.php
index 9575954e694fe36d93f3af06d2e5d55c1f9a89fe..c905b13d3926b6becb273e09779d694581ff72e4 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Change password vmailmgrd backend
  *
@@ -20,7 +21,9 @@
  * Backend might require functions, that are available only in SquirrelMail
  * v.1.5.1 and v.1.4.4.
  *
- * @author Tomas Kuliavas <tokul@users.sourceforge.net>
+ * @author Tomas Kuliavas <tokul at users.sourceforge.net>
+ * @copyright 2005-2010 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @link http://www.vmailmgr.org vmailmgr site
  * @package plugins
@@ -73,15 +76,15 @@ $cpw_vmailmgrd_8bitpw=false;
 /* end of backend configuration */
 
 /** load configuration from config.php */
-if ( isset($vmailmgrd) && is_array($vmailmgrd) && !empty($vmailmgrd) ) {
-    if (isset($vmailmgrd['vmail_inc_path']))
-        $vmail_inc_path=$vmailmgrd['vmail_inc_path'];
-    if (isset($vmailmgrd['vm_tcphost']))
-        $vm_tcphost=$vmailmgrd['vm_tcphost'];
-    if (isset($vmailmgrd['vm_tcphost_port']))
-        $vm_tcphost_port=$vmailmgrd['vm_tcphost_port'];
-    if (isset($vmailmgrd['cpw_vmailmgrd_8bitpw']))
-        $cpw_vmailmgrd_8bitpw=$vmailmgrd['cpw_vmailmgrd_8bitpw'];
+if ( isset($cpw_vmailmgrd) && is_array($cpw_vmailmgrd) && !empty($cpw_vmailmgrd) ) {
+    if (isset($cpw_vmailmgrd['vmail_inc_path']))
+        $vmail_inc_path=$cpw_vmailmgrd['vmail_inc_path'];
+    if (isset($cpw_vmailmgrd['vm_tcphost']))
+        $vm_tcphost=$cpw_vmailmgrd['vm_tcphost'];
+    if (isset($cpw_vmailmgrd['vm_tcphost_port']))
+        $vm_tcphost_port=$cpw_vmailmgrd['vm_tcphost_port'];
+    if (isset($cpw_vmailmgrd['8bitpw']))
+        $cpw_vmailmgrd_8bitpw=$cpw_vmailmgrd['8bitpw'];
 }
 
 
@@ -101,24 +104,13 @@ $squirrelmail_plugin_hooks['change_password_init']['vmailmgrd'] =
  * is displayed to the user.
  */
 function cpw_vmailmgrd_init(){
-    global $vmail_inc_path, $color, $username;
-
-    /**
-     * If SM_PATH isn't defined, define it.  Required to include files.
-     * @ignore
-     */
-    if (!defined('SM_PATH'))  {
-        define('SM_PATH','../../../');
-    }
-
-    // load error_box() function
-    include_once(SM_PATH . 'functions/display_messages.php');
+    global $vmail_inc_path, $username, $oTemplate;
 
     if ($vmail_inc_path=='' || ! file_exists($vmail_inc_path)) {
         // $vmail_inc_path is not set or file does not exist
-        error_box(_("Incorrent path to vmail.inc file."),$color);
+        error_box(_("Incorrent path to vmail.inc file."));
         // close html and stop script execution
-        echo "</body></html>\n";
+        $oTemplate->display('footer.tpl');
         exit();
     }
 
@@ -126,17 +118,17 @@ function cpw_vmailmgrd_init(){
 
     if (! function_exists('vchpass')) {
         // included vmail.inc does not have required functions.
-        error_box(_("Invalid or corrupted vmail.inc file."),$color);
+        error_box(_("Invalid or corrupted vmail.inc file."));
         // close html and stop script execution
-        echo "</body></html>\n";
+        $oTemplate->display('footer.tpl');
         exit();
     }
 
     if (! preg_match("/(.*)\@(.*)/", $username)) {
         // username does not match vmailmgr syntax
-        error_box(_("Invalid user."),$color);
+        error_box(_("Invalid user."));
         // close html and stop script execution
-        echo "</body></html>\n";
+        $oTemplate->display('footer.tpl');
         exit();
     }
 }
@@ -185,7 +177,7 @@ function cpw_vmailmgrd_dochange($data)
     $vmgrd_response2 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$newpw);
     if ($vmgrd_response2[0]!=0) {
         // TODO: add vmail.inc error message parser.
-        array_push($msgs, $vmgrd_response2[1]);
+        array_push($msgs, cpw_i18n_vmail_response($vmgrd_response2[1]));
     }
 
     return $msgs;
@@ -210,4 +202,87 @@ function cpw_vmailmgrd_passwd($user,$domain,$oldpass,$newpass) {
 
     return vchpass($domain,$oldpass,$user,$newpass);
 }
-?>
\ No newline at end of file
+
+/**
+ * Function is used to translate messages returned by vmailmgr
+ * php library and vmailmgr daemon.
+ * @param string $string vmailmrgd message.
+ * @return string translated string.
+ */
+function cpw_i18n_vmail_response($string) {
+    if ($string=='Empty domain') {
+        // block one: vchpass responses
+        $ret = _("Empty domain");
+    } elseif ($string=='Empty domain password') {
+        $ret = _("Empty domain password");
+    } elseif ($string=='Empty username') {
+        $ret = _("Empty username");
+    } elseif ($string=='Empty new password') {
+        $ret = _("Empty new password");
+/*
+ * block is disabled in order to reduce load on translators.
+ * these error messages should be very rare.
+    } elseif ($string=='Invalid or unknown base user or domain') {
+        // block two: vmailmgr daemon strings
+        $ret = _("Invalid or unknown base user or domain");
+    } elseif ($string=='Invalid or unknown virtual user') {
+        $ret = _("Invalid or unknown virtual user");
+    } elseif ($string=='Invalid or incorrect password') {
+        $ret = _("Invalid or incorrect password");
+    } elseif ($string=='Unknown operation to stat') {
+        $ret = _("Unknown operation to stat");
+    } elseif (preg_match("/^Incorrect number of parameters to command (.+)/",$string,$match)) {
+        $ret = sprintf(_("Incorrect number of parameters to command %s"),$match[1]);
+    } elseif (preg_match("/^Invalid or unknown domain name: (.+)/",$string,$match)) {
+        $ret = sprintf(_("Invalid or unknown domain name: %s"),$match[1]);
+    } elseif ($string=='Invalid operation') {
+        $ret = _("Invalid operation");
+    } elseif (preg_match("/^Invalid or unknown base user name: (.+)/",$string,$match)) {
+        $ret = sprintf(_("Invalid or unknown base user name: %s"),$match[1]);
+    } elseif ($string=='Invalid or incorrect password') {
+        $ret = _("Invalid or incorrect password");
+    } elseif ($string=='Base user has no virtual password table') {
+        $ret = _("Base user has no virtual password table");
+    } elseif ($string=='Failed while writing initial OK response') {
+        $ret = _("Failed while writing initial OK response");
+    } elseif ($string=='Failed while writing list entry') {
+        $ret = _("Failed while writing list entry");
+    } elseif ($string=='Internal error -- userpass && !mustexist') {
+        $ret = _("Internal error -- userpass && !mustexist");
+    } elseif ($string=='Invalid or unknown base user or domain') {
+        $ret = _("Invalid or unknown base user or domain");
+    } elseif ($string=='Incorrect password') {
+        $ret = CPW_INVALID_PW;
+    } elseif ($string=='User name does not refer to a virtual user') {
+        $ret = _("User name does not refer to a virtual user");
+    } elseif ($string=='Invalid or unknown virtual user') {
+        $ret = _("Invalid or unknown virtual user");
+    } elseif ($string=='Virtual user already exists') {
+        $ret = _("Virtual user already exists");
+    } elseif ($string=='Timed out waiting for remote') {
+        $ret = _("Timed out waiting for remote");
+    } elseif ($string=='Connection to client lost') {
+        $ret = _("Connection to client lost");
+    } elseif ($string=="Couldn't decode the command string") {
+        $ret = _("Couldn't decode the command string");
+    } elseif ($string=='Empty command string') {
+        $ret = _("Empty command string");
+    } elseif ($string=='Error decoding a command parameter') {
+        $ret = _("Error decoding a command parameter");
+    } elseif ($string=='read system call failed or was interrupted') {
+        $ret = _("read system call failed or was interrupted");
+    } elseif ($string=='Short read while reading protocol header') {
+        $ret = _("Short read while reading protocol header");
+    } elseif ($string=='Invalid protocol from client') {
+        $ret = _("Invalid protocol from client");
+    } elseif ($string=='Short read while reading message data') {
+        $ret = _("Short read while reading message data");
+    } elseif ($string=='Error writing response') {
+        $ret = _("Error writing response");
+*/
+    } else {
+        // return unknown strings
+        $ret = $string;
+    }
+    return $ret;
+}