summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-06-03 08:02:12 +0000
committeralecpl <alec@alec.pl>2010-06-03 08:02:12 +0000
commitbb8721aaeb4961f0dee8ca250749906e01a8f6a8 (patch)
tree743b5444c38d9903331079e95bf99b42c83ba3b0
parent05a631a43c1950fc99f817cb50e4184dc0696663 (diff)
- Support dynamic hostname (%d/%n) variables in configuration options (#1485438)
-rw-r--r--CHANGELOG1
-rw-r--r--config/main.inc.php.dist20
-rw-r--r--program/include/main.inc16
-rw-r--r--program/include/rcmail.php4
-rw-r--r--program/include/rcube_config.php8
-rw-r--r--program/include/rcube_ldap.php1
-rw-r--r--program/include/rcube_smtp.php2
7 files changed, 44 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index ebcfbd16d..b4c4391db 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail
===========================
+- Support dynamic hostname (%d/%n) variables in configuration options (#1485438)
- Add 'messages_list' hook (#1486266)
- Add request* event triggers in http_post/http_request (#1486054)
- Fix use RFC-compliant line-delimiter when saving messages on IMAP (#1486712)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 0b39d76f5..34a976306 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -61,6 +61,10 @@ $rcmail_config['smtp_debug'] = false;
// leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
+// Supported replacement variables:
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['default_host'] = '';
// TCP port used for IMAP connections
@@ -90,7 +94,11 @@ $rcmail_config['imap_timeout'] = 0;
// SMTP server host (for sending mails).
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// If left blank, the PHP mail() function is used
-// Use %h variable as replacement for user's IMAP hostname
+// Supported replacement variables:
+// %h - user's IMAP hostname
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['smtp_server'] = '';
// SMTP port (default is 25; 465 for SSL)
@@ -176,6 +184,11 @@ $rcmail_config['username_domain'] = '';
// This domain will be used to form e-mail addresses of new users
// Specify an array with 'host' => 'domain' values to support multiple hosts
+// Supported replacement variables:
+// %h - user's IMAP hostname
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['mail_domain'] = '';
// Password charset.
@@ -374,6 +387,11 @@ $rcmail_config['ldap_public'] = array();
*
$rcmail_config['ldap_public']['Verisign'] = array(
'name' => 'Verisign.com',
+ // Replacement variables supported in host names:
+ // %h - user's IMAP hostname
+ // %n - http hostname ($_SERVER['SERVER_NAME'])
+ // %d - domain (http hostname without the first part)
+ // For example %n = mail.domain.tld, %d = domain.tld
'hosts' => array('directory.verisign.com'),
'port' => 389,
'use_tls' => false,
diff --git a/program/include/main.inc b/program/include/main.inc
index 6a8179127..e8e92161d 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1532,6 +1532,7 @@ function rcube_https_check($port=null, $use_https=true)
return false;
}
+
// for backward compatibility
function rcube_sess_unset($var_name=null)
{
@@ -1541,6 +1542,21 @@ function rcube_sess_unset($var_name=null)
}
+// Replaces hostname variables
+function rcube_parse_host($name)
+{
+ // %n - host
+ $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']);
+ // %d - domain name without first part, e.g. %d=mail.domain.tld, %m=domain.tld
+ $d = preg_replace('/^[^\.]+\./', '', $n);
+ // %h - IMAP host
+ $h = $_SESSION['imap_host'];
+
+ $name = str_replace(array('%n', '%d', '%h'), array($n, $d, $h), $name);
+ return $name;
+}
+
+
/**
* E-mail address validation
*/
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 652dbd00c..20b7bf7c9 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -575,7 +575,7 @@ class rcmail
if (!$allowed)
return false;
}
- else if (!empty($config['default_host']) && $host != $config['default_host'])
+ else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host']))
return false;
// parse $host URL
@@ -743,7 +743,7 @@ class rcmail
$host = get_input_value('_host', RCUBE_INPUT_POST);
}
else
- $host = $default_host;
+ $host = rcube_parse_host($default_host);
return $host;
}
diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index bd53517c1..eb2e088c4 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -277,12 +277,12 @@ class rcube_config
$domain = $this->prop['mail_domain'][$host];
}
else if (!empty($this->prop['mail_domain']))
- $domain = $this->prop['mail_domain'];
-
+ $domain = rcube_parse_host($this->prop['mail_domain']);
+
return $domain;
}
-
-
+
+
/**
* Getter for error state
*
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 307e43ee2..63c193ff6 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -99,6 +99,7 @@ class rcube_ldap extends rcube_addressbook
foreach ($this->prop['hosts'] as $host)
{
+ $host = rcube_parse_host($host);
$this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]");
if ($lc = @ldap_connect($host, $this->prop['port']))
diff --git a/program/include/rcube_smtp.php b/program/include/rcube_smtp.php
index 447143500..4525502db 100644
--- a/program/include/rcube_smtp.php
+++ b/program/include/rcube_smtp.php
@@ -73,7 +73,7 @@ class rcube_smtp
'smtp_timeout' => $RCMAIL->config->get('smtp_timeout'),
));
- $smtp_host = str_replace('%h', $_SESSION['imap_host'], $CONFIG['smtp_server']);
+ $smtp_host = rcube_parse_host($CONFIG['smtp_server']);
// when called from Installer it's possible to have empty $smtp_host here
if (!$smtp_host) $smtp_host = 'localhost';
$smtp_port = is_numeric($CONFIG['smtp_port']) ? $CONFIG['smtp_port'] : 25;