summaryrefslogtreecommitdiff
path: root/program
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 /program
parent05a631a43c1950fc99f817cb50e4184dc0696663 (diff)
- Support dynamic hostname (%d/%n) variables in configuration options (#1485438)
Diffstat (limited to 'program')
-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
5 files changed, 24 insertions, 7 deletions
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;