diff --git a/CHANGELOG b/CHANGELOG index baa960fc4..11eb86b30 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,6 +30,7 @@ CHANGELOG Roundcube Webmail - subscriptions_option: show \\Noselect folders greyed out (#5621) - Add option to not indent quoted text on top-posting reply (#5105) - Removed global $CONFIG variable +- Password: Support host variables in password_db_dsn option (#5955) - Password: Automatic virtualmin domain setting, removed password_virtualmin_format option (#5759) - Support AUTHENTICATE LOGIN for IMAP connections (#5563) - Support LDAP GSSAPI authentication (#5703) diff --git a/plugins/password/composer.json b/plugins/password/composer.json index 3cc0c397f..5e7bb549c 100644 --- a/plugins/password/composer.json +++ b/plugins/password/composer.json @@ -3,7 +3,7 @@ "type": "roundcube-plugin", "description": "Password Change for Roundcube. Plugin adds a possibility to change user password using many methods (drivers) via Settings/Password tab.", "license": "GPLv3+", - "version": "4.2", + "version": "4.3", "authors": [ { "name": "Aleksander Machniak", diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist index 76dc47104..5376eb631 100644 --- a/plugins/password/config.inc.php.dist +++ b/plugins/password/config.inc.php.dist @@ -83,6 +83,12 @@ $config['password_disabled'] = false; // ------------------ // PEAR database DSN for performing the query. By default // Roundcube DB settings are used. +// Supported replacement variables: +// %h - user's IMAP hostname +// %n - hostname ($_SERVER['SERVER_NAME']) +// %t - hostname without the first part +// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part) +// %z - IMAP domain (IMAP hostname without the first part) $config['password_db_dsn'] = ''; // The SQL query used to change the password. diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php index 9659fa0e0..eeea0c59d 100644 --- a/plugins/password/drivers/sql.php +++ b/plugins/password/drivers/sql.php @@ -35,7 +35,7 @@ class rcube_sql_password } if ($dsn = $rcmail->config->get('password_db_dsn')) { - $db = rcube_db::factory($dsn, '', false); + $db = rcube_db::factory(self::parse_dsn($dsn), '', false); $db->set_debug((bool)$rcmail->config->get('sql_debug')); } else { @@ -169,4 +169,23 @@ class rcube_sql_password return PASSWORD_ERROR; } + + /** + * Parse DSN string and replace host variables + */ + protected static function parse_dsn($dsn) + { + if (strpos($dsn, '%')) { + // parse DSN and replace variables in hostname + $parsed = rcube_db::parse_dsn($dsn); + $host = rcube_utils::parse_host($parsed['hostspec']); + + // build back the DSN string + if ($host != $parsed['hostspec']) { + $dsn = str_replace('@' . $parsed['hostspec'], '@' . $host, $dsn); + } + } + + return $dsn; + } }