From 760630169b355181586bd6e286c2cffe2d15a9c6 Mon Sep 17 00:00:00 2001 From: tokul Date: Tue, 29 Mar 2005 13:22:16 +0000 Subject: [PATCH] * removed need to modify backend files. everything is controlled with config.php overrides. * config.php file moved to config_default.php. * site configuration can be stored in config/ or plugin's directories. * added code that switches to change_password domain, if plugin is used in 1.4.x. * merak curl test is moved to init function. * use $cpw_ prefix for all configuration overrides in order to avoid using generic names. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9154 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/change_password/README | 99 ++++++++++++++++--- plugins/change_password/backend/merak.php | 43 ++++++-- plugins/change_password/backend/mysql.php | 12 ++- plugins/change_password/backend/poppassd.php | 13 +-- plugins/change_password/backend/vmailmgrd.php | 18 ++-- .../{config.php => config_default.php} | 0 plugins/change_password/options.php | 56 +++++++++-- plugins/change_password/setup.php | 25 ++++- 8 files changed, 213 insertions(+), 53 deletions(-) rename plugins/change_password/{config.php => config_default.php} (100%) diff --git a/plugins/change_password/README b/plugins/change_password/README index 765e3481..e09edbc6 100644 --- a/plugins/change_password/README +++ b/plugins/change_password/README @@ -26,8 +26,10 @@ REQUIREMENTS: CONFIGURATION Edit the file config.php to set the backend you want to use. -Probably, you need to set some config vars in the backend too -(backend/.php). + +Backends can use special arrays that override default values set +in backend/.php. Check description of backend that +you use. BACKENDS - ldap @@ -45,41 +47,73 @@ BACKENDS Default settings are supplied in backends/mysql.php. You do not have to change any configuration vars in - backend/mysql.php - instead, create an array in config.php - containing the variable you want to override, for example: + backend/mysql.php - instead, create an $cpw_mysql array in + config.php containing the variable you want to override, + for example: To override the server name ($mysql_server), you would add - $mysql['server'] = 'remote_servername'; + $cpw_mysql['server'] = 'remote_servername'; to config.php. + See more information in "About mysql backend" chapter. - merak Default settings are supplied in backends/merak.php. + Site configuration is controlled in config.php $cpw_merak + array. You can use 'url','selfpage' and 'action' array + keys to override default values. + + * 'url' + override sets address of merak interface. URL is used + by webserver's libraries. If it points at localhost, + plugin tries to connect to administrative interface on + same machine that hosts squirrelmail scripts. + Defaults to 'http://localhost:32000/'. + + * 'selfpage' + override sets page that is used to change password. + Defaults to 'self.html'. + + * 'action' + override sets action that is used during password change. + Defaults to 'self_edit'. + + For example: + $cpw_merak['url']='http://example.com:32000'; + - poppassd Default settings are supplied in backends/poppassd.php. + Site configuration is controlled in config.php $cpw_poppassd + array. You can use 'server' array key to override address + of poppassd server. Backend uses address of imap server, if + variable is set to empty string. It uses address of imap + server by default. + + For example: + $cpw_poppassd['server'] = 'remote_servername'; - vmailmgrd Default settings are supplied in backends/vmailmgrd.php. - Site configuration is controlled in config.php $vmailmgrd + Site configuration is controlled in config.php $cpw_vmailmgrd array. Backend uses 'vmail_inc_path', 'vm_tcphost', - 'vm_tcphost_port' and 'cpw_vmailmgrd_8bitpw' array keys. + 'vm_tcphost_port' and '8bitpw' array keys. 'vmail_inc_path' sets path to vmail.inc. 'vm_tcphost' sets vmailmgrd tcp service ip address or dns name. Plugin uses vmailmgrd socket, if it is not set. 'vm_tcphost_port' sets port of vmailmrgd service. Plugin uses port 322, if it is - not set. 'cpw_vmailmgrd_8bitpw' controls use of 8bit - passwords. If it is not set, interface does not allow new - passwords with 8bit symbols. + not set. '8bitpw' controls use of 8bit passwords. If it + is not set, interface does not allow new passwords with + 8bit symbols. - $vmailmgrd['vmail_inc_path'] setting is required. + $cpw_vmailmgrd['vmail_inc_path'] setting is required. AUTHORS: @@ -103,8 +137,8 @@ ABOUT LDAP BACKEND overrides port of ldap server. Defaults to 389. * 'basedn' - (required) ldap basedn used for binding to ldap server. Empty - string blocks use of backend. Defaults to empty string. + (required) ldap basedn used for binding to ldap server. If set to + empty string, blocks use of backend. Defaults to empty string. * 'connect_opts' controls LDAP_OPT_* settings that are set with ldap_set_option() @@ -150,7 +184,7 @@ ABOUT LDAP BACKEND - smd5 - used name 'smd5'. Implemented in php mhash extension functions. Minimal php version = 4.0.4. - sha - used name 'sha'. Implemented in php mhash extension functions - and php 4.3.0+ sha1() function. mhash extension is used only wheh + and php 4.3.0+ sha1() function. mhash extension is used only when sha1() function is unavailable. - ssha - used name 'ssha'. Implemented in php mhash extension functions. Minimal php version = 4.0.4. @@ -194,5 +228,42 @@ ABOUT LDAP BACKEND $cpw_ldap['base_dn']='ou=users,dc=example,dc=com'; // sets base dn $cpw_ldap['connect_opts']['PROTOCOL_VERSION']=3; // forces v3 bind protocol +------------------- +ABOUT MYSQL BACKEND +------------_------ + List of supported overrides: + * 'server' + address of MySQL server. Defaults to localhost. + + * 'database' + database that stores user information. Defaults to 'email'. + + * 'table' + database table that stores user information. Defaults to 'users'. + + * 'userid_field' + field that stores user's ID. Defaults to 'id'. + + * 'password_field' + field that stores password. Defaults to 'password'. + + * 'manager_id' + username that is used to log into MySQL with (must have rights). + Defaults to 'email_admin'. + + * 'manager_pw' + password that is used to log into MySQL. + + * 'saslcrypt' + boolean value that controls use of SASL (MySQL) crypt in passwords. + It is not enabled by default. + + * 'unixcrypt' + boolean value that controls use of unix crypt() in passwords. + Setting is ignored, if saslcrypt is enabled. It is not enabled + by default. + +If saslcrypt and unixcrypt are not enabled, plugin defaults to plaintext +passwords. $Id$ diff --git a/plugins/change_password/backend/merak.php b/plugins/change_password/backend/merak.php index 3670a36e..4b21172b 100644 --- a/plugins/change_password/backend/merak.php +++ b/plugins/change_password/backend/merak.php @@ -20,11 +20,45 @@ $merak_url = "http://localhost:32000/"; $merak_selfpage = "self.html"; $merak_action = "self_edit"; -// NO NEED TO CHANGE ANYTHING BELOW THIS LINE +// get overrides from config. +if ( isset($cpw_merak) && is_array($cpw_merak) && !empty($cpw_merak) ) { + foreach ( $cpw_merak as $key => $value ) { + if ( isset(${'merak_'.$key}) ) + ${'merak_'.$key} = $value; + } +} global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['change_password_dochange']['merak'] = 'cpw_merak_dochange'; +$squirrelmail_plugin_hooks['change_password_init']['merak'] = + 'cpw_merak_init'; + +/** + * Check if php install has all required extensions. + */ +function cpw_merak_init() { + global $color; + + /** + * 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'); + + if (!function_exists('curl_init')) { + // user_error('Curl module NOT available!', E_USER_ERROR); + error_box(_("PHP Curl extension is NOT available! Unable to change password!"),$color); + // close html and stop script execution + echo "\n"; + exit(); + } +} /** * This is the function that is specific to your backend. It takes @@ -51,13 +85,6 @@ function cpw_merak_dochange($data) global $merak_url, $merak_selfpage, $merak_action; - if (!function_exists('curl_init')) { - - // user_error('Curl module NOT available!', E_USER_ERROR); - array_push($msgs, _("Curl module NOT available! Unable to change password!")); - return $msgs; - } - $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $merak_url . $merak_selfpage); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); diff --git a/plugins/change_password/backend/mysql.php b/plugins/change_password/backend/mysql.php index 63b0020e..d71b89cb 100644 --- a/plugins/change_password/backend/mysql.php +++ b/plugins/change_password/backend/mysql.php @@ -14,7 +14,7 @@ global $mysql_server, $mysql_database, $mysql_table, $mysql_userid_field, $mysql_password_field, $mysql_manager_id, $mysql_manager_pw, - $mysql_saslcrypt, $mysql_unixcrypt, $mysql; + $mysql_saslcrypt, $mysql_unixcrypt, $cpw_mysql; // Initialize defaults $mysql_server = 'localhost'; @@ -33,17 +33,16 @@ $mysql_manager_pw = 'xxxxxxx'; $mysql_saslcrypt = 0; // use MySQL password() function $mysql_unixcrypt = 0; // use UNIX crypt() function -if ( isset($mysql) && is_array($mysql) && !empty($mysql) ) +// get overrides from config. +if ( isset($cpw_mysql) && is_array($cpw_mysql) && !empty($cpw_mysql) ) { - foreach ( $mysql as $key => $value ) + foreach ( $cpw_mysql as $key => $value ) { if ( isset(${'mysql_'.$key}) ) ${'mysql_'.$key} = $value; } } -// NO NEED TO CHANGE ANYTHING BELOW THIS LINE - global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['change_password_dochange']['mysql'] = 'cpw_mysql_dochange'; @@ -75,6 +74,7 @@ function cpw_mysql_dochange($data) $mysql_password_field, $mysql_manager_id, $mysql_manager_pw, $mysql_saslcrypt, $mysql_unixcrypt; + // TODO: allow to choose between mysql_connect() and mysql_pconnect() functions. $ds = mysql_pconnect($mysql_server, $mysql_manager_id, $mysql_manager_pw); if (! $ds) { array_push($msgs, _("Cannot connect to Database Server, please try later!")); @@ -93,6 +93,7 @@ function cpw_mysql_dochange($data) if ($mysql_saslcrypt) { $query_string .= '=password("'.mysql_escape_string($curpw).'")'; } elseif ($mysql_unixcrypt) { + // FIXME: why password field name is used for salting $query_string .= '=encrypt("'.mysql_escape_string($curpw).'", '.$mysql_password_field . ')'; } else { $query_string .= '="' . mysql_escape_string($curpw) . '"'; @@ -119,6 +120,7 @@ function cpw_mysql_dochange($data) if ($mysql_saslcrypt) { $update_string .= '=password("'.mysql_escape_string($newpw).'")'; } elseif ($mysql_unixcrypt) { + // FIXME: use random salt when you create new password $update_string .= '=encrypt("'.mysql_escape_string($newpw).'", '.$mysql_password_field . ')'; } else { $update_string .= '="' . mysql_escape_string($newpw) . '"'; diff --git a/plugins/change_password/backend/poppassd.php b/plugins/change_password/backend/poppassd.php index 7e3b6842..280238b0 100644 --- a/plugins/change_password/backend/poppassd.php +++ b/plugins/change_password/backend/poppassd.php @@ -21,21 +21,14 @@ global $poppassd_server; $poppassd_server = ''; +/* get overrides from config.php */ +if (isset($cpw_poppassd['server'])) $poppassd_server=$cpw_poppassd['server']; + /** * Define here the name of your password changing function. */ global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['change_password_dochange']['poppassd'] = 'cpw_poppassd_dochange'; -$squirrelmail_plugin_hooks['change_password_init']['template'] = 'cpw_poppassd_init'; - - -/** - * Use this function to do any backend-specific initialization, - * e.g. checking requirements, before the password change form - * is displayed to the user. - */ -function cpw_poppassd_init() { -} /** * This is the function that is specific to your backend. It takes diff --git a/plugins/change_password/backend/vmailmgrd.php b/plugins/change_password/backend/vmailmgrd.php index e8527d5d..47909eea 100644 --- a/plugins/change_password/backend/vmailmgrd.php +++ b/plugins/change_password/backend/vmailmgrd.php @@ -73,15 +73,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']; } diff --git a/plugins/change_password/config.php b/plugins/change_password/config_default.php similarity index 100% rename from plugins/change_password/config.php rename to plugins/change_password/config_default.php diff --git a/plugins/change_password/options.php b/plugins/change_password/options.php index 3a9d69c2..a62fd363 100644 --- a/plugins/change_password/options.php +++ b/plugins/change_password/options.php @@ -14,13 +14,39 @@ /** @ignore */ define('SM_PATH','../../'); -require_once (SM_PATH . 'include/validate.php'); -require_once (SM_PATH . 'functions/page_header.php'); -require_once (SM_PATH . 'plugins/change_password/functions.php'); -require_once (SM_PATH . 'plugins/change_password/config.php'); -require_once (SM_PATH . 'functions/forms.php'); +include_once (SM_PATH . 'include/validate.php'); +include_once (SM_PATH . 'plugins/change_password/functions.php'); +include_once (SM_PATH . 'functions/forms.php'); -// you must load backend configuration here in order to get working change_password_init hook. +/** load default config */ +if (file_exists(SM_PATH . 'plugins/change_password/config_default.php')) { + include_once (SM_PATH . 'plugins/change_password/config_default.php'); +} else { + // somebody decided to remove default config + $cpw_backend = 'template'; + $cpw_pass_min_length = 4; + $cpw_pass_max_length = 25; + $cpw_require_ssl = FALSE; +} + +/** + * prevent possible corruption of configuration overrides in + * register_globals=on and preloaded php scripts. + */ +$cpw_ldap=array(); +$cpw_merak=array(); +$cpw_mysql=array(); +$cpw_poppassd=array(); +$cpw_vmailmgrd=array(); + +/** load site config */ +if (file_exists(SM_PATH . 'config/change_password_config.php')) { + include_once (SM_PATH . 'config/change_password_config.php'); +} elseif (file_exists(SM_PATH . 'plugins/change_password/config.php')) { + include_once (SM_PATH . 'plugins/change_password/config.php'); +} + +// must load backend libraries here in order to get working change_password_init hook. if (file_exists(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php')) { include_once(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php'); } @@ -28,6 +54,12 @@ if (file_exists(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php' /* the form was submitted, go for it */ if(sqgetGlobalVar('cpw_go', $cpw_go, SQ_POST)) { + // SM14 code: use change_password gettext domain binding for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('change_password',SM_PATH . 'locale'); + textdomain('change_password'); + } + /* perform basic checks */ $Messages = cpw_check_input(); @@ -35,10 +67,22 @@ if(sqgetGlobalVar('cpw_go', $cpw_go, SQ_POST)) { if(count($Messages) == 0) { $Messages = cpw_do_change(); } + + // SM14 code: use change_password gettext domain binding for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('squirrelmail',SM_PATH . 'locale'); + textdomain('squirrelmail'); + } } displayPageHeader($color, 'None'); +// SM14 code: use change_password gettext domain binding for 1.4.x +if (! check_sm_version(1,5,0)) { + bindtextdomain('change_password',SM_PATH . 'locale'); + textdomain('change_password'); +} + do_hook('change_password_init'); ?> diff --git a/plugins/change_password/setup.php b/plugins/change_password/setup.php index 9b7ca21b..cc550f67 100644 --- a/plugins/change_password/setup.php +++ b/plugins/change_password/setup.php @@ -30,12 +30,24 @@ function squirrelmail_plugin_init_change_password() { function change_password_optpage() { global $optpage_blocks; + // SM14 code: use change_password gettext domain binding for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('change_password',SM_PATH . 'locale'); + textdomain('change_password'); + } + $optpage_blocks[] = array( 'name' => _("Change Password"), 'url' => '../plugins/change_password/options.php', 'desc' => _("Use this to change your email password."), 'js' => FALSE ); + + // SM14 code: revert to squirrelmail domain for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('squirrelmail',SM_PATH . 'locale'); + textdomain('squirrelmail'); + } } /** @@ -45,10 +57,21 @@ function change_password_optpage() { function change_password_loadinfo() { global $optpage, $optpage_name; if ($optpage=='change_password') { + // SM14 code: use change_password gettext domain binding for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('change_password',SM_PATH . 'locale'); + textdomain('change_password'); + } + // i18n: is displayed after "Successfully Saved Options:" $optpage_name=_("User's Password"); - } + // SM14 code: revert to squirrelmail domain for 1.4.x + if (! check_sm_version(1,5,0)) { + bindtextdomain('squirrelmail',SM_PATH . 'locale'); + textdomain('squirrelmail'); + } + } } /** -- 2.25.1