Password: Support host variables in password_db_dsn option (#5955)

pull/5960/head
Aleksander Machniak 7 years ago
parent afa03008c7
commit 148ccda88a

@ -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)

@ -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",

@ -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.

@ -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;
}
}

Loading…
Cancel
Save