diff options
author | Aleksander Machniak <alec@alec.pl> | 2021-12-07 17:07:54 +0300 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2021-12-07 17:07:54 +0300 |
commit | 893216cb297268d222ae49099e6654a304b72e3f (patch) | |
tree | 417fc69e5e91a743c0a9675fe30132de237860d4 | |
parent | 9aa6789c6527f22592ceb1a4829d759cf924f83e (diff) |
Unified and simplified services connection options (#8310)
-rw-r--r-- | CHANGELOG.md | 19 | ||||
-rwxr-xr-x | bin/deluser.sh | 2 | ||||
-rw-r--r-- | config/config.inc.php.sample | 32 | ||||
-rw-r--r-- | config/defaults.inc.php | 27 | ||||
-rw-r--r-- | installer/client.js | 4 | ||||
-rw-r--r-- | installer/config.php | 42 | ||||
-rw-r--r-- | installer/test.php | 44 | ||||
-rwxr-xr-x | plugins/enigma/bin/import_keys.sh | 2 | ||||
-rw-r--r-- | plugins/http_authentication/config.inc.php.dist | 2 | ||||
-rw-r--r-- | plugins/krb_authentication/config.inc.php.dist | 2 | ||||
-rw-r--r-- | plugins/managesieve/Changelog | 4 | ||||
-rw-r--r-- | plugins/managesieve/config.inc.php.dist | 13 | ||||
-rw-r--r-- | plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php | 39 | ||||
-rw-r--r-- | program/include/rcmail.php | 47 | ||||
-rw-r--r-- | program/include/rcmail_install.php | 12 | ||||
-rw-r--r-- | program/include/rcmail_output_html.php | 2 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_ldap.php | 14 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_smtp.php | 42 | ||||
-rw-r--r-- | tests/Browser/README.md | 2 | ||||
-rw-r--r-- | tests/Browser/bootstrap.php | 6 |
20 files changed, 154 insertions, 203 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 54b42990d..b55e801b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,25 @@ ## Unreleased +- Unified and simplified services connection options (#8310): + 1. IMAP: + - renamed `default_host` to `imap_host` + - removed `default_port` option (non-standard port can be set via `imap_host`) + - set "tls://localhost:143" as a default for `imap_host` + 2. SMTP: + - renamed `smtp_server` to `smtp_host` + - removed `smtp_port` option (non-standard port can be set via `smtp_host`) + - set "tls://localhost:587" as a default for `smtp_host` + 3. LDAP: + - removed `port` option from `ldap_public` array (non-standard port can be set via `host`) + - removed `use_tls` option from `ldap_public` array (use tls:// prefix in `host`) + 4. Managesieve: + - removed `managesieve_port` option (non-standard port can be set via `managesieve_host`) + - removed `managesieve_usetls` option (tls:// prefix in `managesieve_host` have to be used) +- Plugin API: Removed `smtp_port` parameter in `smtp_connect` hook +- Plugin API: Renamed `smtp_server` parameter to `smtp_host` in `smtp_connect` hook +- Plugin API: Removed `port` parameter in `managesieve_connect` hook +- Plugin API: Removed `usetls` parameter in `managesieve_connect` hook - Added support for PHP 8.1 (#8151) - Dropped support for PHP < 7.3 (#7976) - Dropped support for strftime-like format (with % sign) in date and time format configuration diff --git a/bin/deluser.sh b/bin/deluser.sh index 9797af139..7dcf94432 100755 --- a/bin/deluser.sh +++ b/bin/deluser.sh @@ -68,7 +68,7 @@ if (empty($username)) { } if (empty($args['host'])) { - $hosts = $rcmail->config->get('default_host', ''); + $hosts = $rcmail->config->get('imap_host', ''); if (is_string($hosts)) { $args['host'] = $hosts; } diff --git a/config/config.inc.php.sample b/config/config.inc.php.sample index 89d41b5cf..e4581cb18 100644 --- a/config/config.inc.php.sample +++ b/config/config.inc.php.sample @@ -27,35 +27,13 @@ $config = []; // or (Windows): 'sqlite:///C:/full/path/to/sqlite.db' $config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail'; -// The IMAP host chosen to perform the log-in. -// Leave blank to show a textbox at login, give a list of hosts -// to display a pulldown menu or set one host as string. -// Enter hostname with prefix ssl:// to use Implicit TLS, or use -// prefix tls:// to use STARTTLS. -// Supported replacement variables: -// %n - hostname ($_SERVER['SERVER_NAME']) -// %t - hostname without the first part -// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part) -// %s - domain name after the '@' from e-mail address provided at login screen -// For example %n = mail.domain.tld, %t = domain.tld -$config['default_host'] = 'localhost'; +// IMAP host chosen to perform the log-in. +// See defaults.inc.php for the option description. +$config['imap_host'] = 'tls://localhost:143'; // SMTP server host (for sending mails). -// Enter hostname with prefix ssl:// to use Implicit TLS, or use -// prefix tls:// to use STARTTLS. -// 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) -// For example %n = mail.domain.tld, %t = domain.tld -// To specify different SMTP servers for different IMAP hosts provide an array -// of IMAP host (no prefix or port) and SMTP server e.g. ['imap.example.com' => 'smtp.example.net'] -$config['smtp_server'] = 'localhost'; - -// SMTP port. Use 25 for cleartext, 465 for Implicit TLS, or 587 for STARTTLS (default) -$config['smtp_port'] = 587; +// See defaults.inc.php for the option description. +$config['smtp_host'] = 'tls://localhost:587'; // SMTP username (if required) if you use %u as the username Roundcube // will use the current username for login diff --git a/config/defaults.inc.php b/config/defaults.inc.php index ab2f0a077..74e8a6b24 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -131,11 +131,12 @@ $config['redis_debug'] = false; // IMAP // ---------------------------------- -// The IMAP host chosen to perform the log-in. +// The IMAP host (and optionally port number) chosen to perform the log-in. // Leave blank to show a textbox at login, give a list of hosts // to display a pulldown menu or set one host as string. // Enter hostname with prefix ssl:// to use Implicit TLS, or use // prefix tls:// to use STARTTLS. +// If port number is omitted it will be set to 993 (for ssl://) or 143 otherwise. // Supported replacement variables: // %n - hostname ($_SERVER['SERVER_NAME']) // %t - hostname without the first part @@ -144,10 +145,7 @@ $config['redis_debug'] = false; // For example %n = mail.domain.tld, %t = domain.tld // WARNING: After hostname change update of mail_host column in users table is // required to match old user data records with the new host. -$config['default_host'] = 'localhost'; - -// TCP port used for IMAP connections -$config['default_port'] = 143; +$config['imap_host'] = 'tls://localhost:143'; // IMAP authentication method (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or null). // Use 'IMAP' to authenticate with IMAP LOGIN command. @@ -257,9 +255,10 @@ $config['messages_cache_threshold'] = 50; // SMTP // ---------------------------------- -// SMTP server host (for sending mails). +// SMTP server host (and optional port number) for sending mails. // Enter hostname with prefix ssl:// to use Implicit TLS, or use // prefix tls:// to use STARTTLS. +// If port number is omitted it will be set to 465 (for ssl://) or 587 otherwise. // Supported replacement variables: // %h - user's IMAP hostname // %n - hostname ($_SERVER['SERVER_NAME']) @@ -269,10 +268,7 @@ $config['messages_cache_threshold'] = 50; // For example %n = mail.domain.tld, %t = domain.tld // To specify different SMTP servers for different IMAP hosts provide an array // of IMAP host (no prefix or port) and SMTP server e.g. ['imap.example.com' => 'smtp.example.net'] -$config['smtp_server'] = 'localhost'; - -// SMTP port. Use 25 for cleartext, 465 for Implicit TLS, or 587 for STARTTLS (default) -$config['smtp_port'] = 587; +$config['smtp_host'] = 'tls://localhost:587'; // SMTP username (if required) if you use %u as the username Roundcube // will use the current username for login @@ -388,8 +384,8 @@ $config['oauth_login_redirect'] = false; // - use https://<your-roundcube-url>/index.php/login/oauth as redirect URL // - grant permissions to Microsoft Graph API "IMAP.AccessAsUser.All", "SMTP.Send", "User.Read" and "offline_access" -// $config['default_host'] = 'ssl://outlook.office365.com'; -// $config['smtp_server'] = 'ssl://smtp.office365.com'; +// $config['imap_host'] = 'ssl://outlook.office365.com'; +// $config['smtp_host'] = 'ssl://smtp.office365.com'; // $config['oauth_provider'] = 'outlook'; // $config['oauth_provider_name'] = 'Outlook.com'; @@ -1031,9 +1027,9 @@ $config['ldap_public']['Verisign'] = [ // %z - IMAP domain (IMAP hostname without the first part) // For example %n = mail.domain.tld, %t = domain.tld // Note: Host can also be a full URI e.g. ldaps://hostname.local:636 (for SSL) - 'hosts' => array('directory.verisign.com'), - 'port' => 389, - 'use_tls' => false, + // Note: If port number is omitted, it will be set to 636 (for ldaps://) or 389 otherwise. + // Note: To enable TLS use tls:// prefix + 'hosts' => array('directory.verisign.com:389'), 'ldap_version' => 3, // using LDAPv3 'network_timeout' => 10, // The timeout (in seconds) for connect + bind attempts. This is only supported in PHP >= 5.3.0 with OpenLDAP 2.x 'user_specific' => false, // If true the base_dn, bind_dn and bind_pass default to the user's IMAP login. @@ -1421,7 +1417,6 @@ $config['mdn_requests'] = 0; $config['mdn_default'] = 0; // Delivery Status Notification checkbox default state -// Note: This can be used only if smtp_server is non-empty $config['dsn_default'] = 0; // Place replies in the folder of the message being replied to diff --git a/installer/client.js b/installer/client.js index a2bdc89e2..e08ce22fa 100644 --- a/installer/client.js +++ b/installer/client.js @@ -28,7 +28,7 @@ function addhostfield() var input = document.createElement('input'); var link = document.createElement('a'); - input.name = '_default_host[]'; + input.name = '_imap_host[]'; input.size = '30'; link.href = '#'; link.onclick = function() { removehostfield(this.parentNode); return false }; @@ -46,5 +46,3 @@ function removehostfield(row) var container = document.getElementById('defaulthostlist'); container.removeChild(row); } - - diff --git a/installer/config.php b/installer/config.php index 6e9050bb6..d922fe66b 100644 --- a/installer/config.php +++ b/installer/config.php @@ -175,8 +175,7 @@ $select_spell->add('ATD', 'atd'); echo $select_spell->show($RCI->is_post ? $_POST['_spellcheck_engine'] : 'pspell'); ?> -<label for="cfgspellcheckengine">Which spell checker to use</label><br /> - +<div>Which spell checker to use</div> <p class="hint">Googie implies that the message content will be sent to external server to check the spelling.</p> </dd> @@ -322,13 +321,12 @@ echo $input_prefix->show($RCI->getprop('db_prefix')); <fieldset> <legend>IMAP Settings</legend> <dl class="configblock" id="cgfblockimap"> -<dt class="propname">default_host</dt> +<dt class="propname">imap_host</dt> <dd> -<div>The IMAP host(s) chosen to perform the log-in</div> <div id="defaulthostlist"> <?php -$text_imaphost = new html_inputfield(['name' => '_default_host[]', 'size' => 30]); +$text_imaphost = new html_inputfield(['name' => '_imap_host[]', 'size' => 30]); $default_hosts = $RCI->get_hostlist(); if (empty($default_hosts)) { @@ -348,18 +346,8 @@ foreach ($default_hosts as $host) { </div> <div><a href="javascript:addhostfield()" class="addlink" title="Add another field">add</a></div> -<p class="hint">Leave blank to show a textbox at login. To use SSL/IMAPS connection, type ssl://hostname</p> -</dd> - -<dt class="propname">default_port</dt> -<dd> -<?php - -$text_imapport = new html_inputfield(['name' => '_default_port', 'size' => 6, 'id' => 'cfgimapport']); -echo $text_imapport->show($RCI->getprop('default_port')); - -?> -<div>TCP port used for IMAP connections</div> +<div>The IMAP host(s) chosen to perform the log-in</div> +<p class="hint">Leave blank to show a textbox at login. To use SSL/STARTTLS connection add ssl:// or tls:// prefix. It can also contain the port number, e.g. tls://imap.domain.tld:143. </dd> <dt class="propname">username_domain</dt> @@ -451,28 +439,16 @@ echo $text_junkmbox->show($RCI->getprop('junk_mbox')); <fieldset> <legend>SMTP Settings</legend> <dl class="configblock" id="cgfblocksmtp"> -<dt class="propname">smtp_server</dt> +<dt class="propname">smtp_host</dt> <dd> <?php -$text_smtphost = new html_inputfield(['name' => '_smtp_server', 'size' => 30, 'id' => 'cfgsmtphost']); -echo $text_smtphost->show($RCI->getprop('smtp_server', 'localhost')); +$text_smtphost = new html_inputfield(['name' => '_smtp_host', 'size' => 30, 'id' => 'cfgsmtphost']); +echo $text_smtphost->show($RCI->getprop('smtp_host', 'localhost:587')); ?> <div>Use this host for sending mails</div> - -<p class="hint">To use SSL connection, set ssl://smtp.host.com.</p> -</dd> - -<dt class="propname">smtp_port</dt> -<dd> -<?php - -$text_smtpport = new html_inputfield(['name' => '_smtp_port', 'size' => 6, 'id' => 'cfgsmtpport']); -echo $text_smtpport->show($RCI->getprop('smtp_port')); - -?> -<div>SMTP port (default is 587)</div> +<p class="hint">To use SSL/STARTTLS connection add ssl:// or tls:// prefix. It can also contain the port number, e.g. tls://smtp.domain.tld:587.</p> </dd> <dt class="propname">smtp_user/smtp_pass</dt> diff --git a/installer/test.php b/installer/test.php index 97b88d429..10179b7e9 100644 --- a/installer/test.php +++ b/installer/test.php @@ -274,13 +274,13 @@ else { echo "<br/>"; } -$smtp_hosts = $RCI->get_hostlist('smtp_server'); +$smtp_hosts = $RCI->get_hostlist('smtp_host'); if (!empty($smtp_hosts)) { - $smtp_host_field = new html_select(['name' => '_smtp_host', 'id' => 'smtp_server']); + $smtp_host_field = new html_select(['name' => '_smtp_host', 'id' => 'smtp_host']); $smtp_host_field->add($smtp_hosts, $smtp_hosts); } else { - $smtp_host_field = new html_inputfield(['name' => '_smtp_host', 'id' => 'smtp_server']); + $smtp_host_field = new html_inputfield(['name' => '_smtp_host', 'id' => 'smtp_host']); } $user = $RCI->getprop('smtp_user', '(none)'); @@ -311,14 +311,10 @@ else { <table> <tbody> <tr> - <td><label for="smtp_server">Server</label></td> + <td><label for="smtp_host">Host</label></td> <td><?php echo $smtp_host_field->show(isset($_POST['_smtp_host']) ? $_POST['_smtp_host'] : ''); ?></td> </tr> <tr> - <td><label for="smtp_port">Port</label></td> - <td><?php echo rcube::Q($RCI->getprop('smtp_port')); ?></td> - </tr> - <tr> <td><label for="smtp_user">Username</label></td> <td><?php echo $user; ?></td> </tr> @@ -340,7 +336,6 @@ if (isset($_POST['sendmail'])) { echo '<p>Trying to send email...<br />'; $smtp_host = trim($_POST['_smtp_host']); - $smtp_port = $RCI->getprop('smtp_port'); $from = rcube_utils::idn_to_ascii(trim($_POST['_from'])); $to = rcube_utils::idn_to_ascii(trim($_POST['_to'])); @@ -372,7 +367,7 @@ if (isset($_POST['sendmail'])) { $head = $mail_object->txtHeaders($send_headers); $SMTP = new rcube_smtp(); - $SMTP->connect($smtp_host, $smtp_port, $CONFIG['smtp_user'], $CONFIG['smtp_pass']); + $SMTP->connect($smtp_host, null, $CONFIG['smtp_user'], $CONFIG['smtp_pass']); $status = $SMTP->send_mail($headers['From'], $headers['To'], $head, $body); $smtp_response = $SMTP->get_response(); @@ -433,21 +428,17 @@ $pass_field = new html_passwordfield(['name' => '_pass', 'id' => 'imappass']); <table> <tbody> <tr> - <td><label for="imaphost">Server</label></td> + <td><label for="imaphost">Host</label></td> <td><?php echo $host_field->show(isset($_POST['_host']) ? $_POST['_host'] : ''); ?></td> </tr> <tr> - <td>Port</td> - <td><?php echo $RCI->getprop('default_port'); ?></td> + <td><label for="imapuser">Username</label></td> + <td><?php echo $user_field->show(isset($_POST['_user']) ? $_POST['_user'] : ''); ?></td> + </tr> + <tr> + <td><label for="imappass">Password</label></td> + <td><?php echo $pass_field->show(); ?></td> </tr> - <tr> - <td><label for="imapuser">Username</label></td> - <td><?php echo $user_field->show(isset($_POST['_user']) ? $_POST['_user'] : ''); ?></td> - </tr> - <tr> - <td><label for="imappass">Password</label></td> - <td><?php echo $pass_field->show(); ?></td> - </tr> </tbody> </table> @@ -458,19 +449,14 @@ if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user echo '<p>Connecting to ' . rcube::Q($_POST['_host']) . '...<br />'; $imap_host = trim($_POST['_host']); - $imap_port = $RCI->getprop('default_port'); + $imap_port = 143; $imap_ssl = false; - $a_host = parse_url($imap_host); + $a_host = parse_url($imap_host); if ($a_host['host']) { $imap_host = $a_host['host']; $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls'])) ? $a_host['scheme'] : null; - if (isset($a_host['port'])) { - $imap_port = $a_host['port']; - } - else if ($imap_ssl && $imap_ssl != 'tls' && (!$imap_port || $imap_port == 143)) { - $imap_port = 993; - } + $imap_port = $a_host['port'] ?? ($imap_ssl && $imap_ssl != 'tls' ? 993 : 143); } $imap_host = rcube_utils::idn_to_ascii($imap_host); diff --git a/plugins/enigma/bin/import_keys.sh b/plugins/enigma/bin/import_keys.sh index e190a7a93..7caf06636 100755 --- a/plugins/enigma/bin/import_keys.sh +++ b/plugins/enigma/bin/import_keys.sh @@ -86,7 +86,7 @@ function get_host($args) global $rcmail; if (empty($args['host'])) { - $hosts = $rcmail->config->get('default_host', ''); + $hosts = $rcmail->config->get('imap_host', ''); if (is_string($hosts)) { $args['host'] = $hosts; } diff --git a/plugins/http_authentication/config.inc.php.dist b/plugins/http_authentication/config.inc.php.dist index 0940dee1f..3aa380270 100644 --- a/plugins/http_authentication/config.inc.php.dist +++ b/plugins/http_authentication/config.inc.php.dist @@ -5,5 +5,5 @@ // Default mail host to log-in using user/password from HTTP Authentication. // This is useful if the users are free to choose arbitrary mail hosts (or // from a list), but have one host they usually want to log into. -// Unlike $config['default_host'] this must be a string! +// Unlike $config['imap_host'] this must be a string! $config['http_authentication_host'] = ''; diff --git a/plugins/krb_authentication/config.inc.php.dist b/plugins/krb_authentication/config.inc.php.dist index b1c1ffb9e..18370015a 100644 --- a/plugins/krb_authentication/config.inc.php.dist +++ b/plugins/krb_authentication/config.inc.php.dist @@ -6,7 +6,7 @@ // Default mail host to log-in using user/password from HTTP Authentication. // This is useful if the users are free to choose arbitrary mail hosts (or // from a list), but have one host they usually want to log into. -// Unlike $config['default_host'] this must be a string! +// Unlike $config['imap_host'] this must be a string! $config['krb_authentication_host'] = ''; // GSSAPI security context. diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 53b5e56bc..b11efde34 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,3 +1,7 @@ +- Removed managesieve_usetls option (in favor of the scheme prefix in managesieve_host) +- Plugin API: Removed `port` parameter in `managesieve_connect` hook +- Plugin API: Removed `usetls` parameter in `managesieve_connect` hook + * version 9.4 [2021-06-06] ----------------------------------------------------------- - Add ability to remove 'redirect' option from UI (#7922) diff --git a/plugins/managesieve/config.inc.php.dist b/plugins/managesieve/config.inc.php.dist index 4e5042fb8..354709586 100644 --- a/plugins/managesieve/config.inc.php.dist +++ b/plugins/managesieve/config.inc.php.dist @@ -1,15 +1,14 @@ <?php -// managesieve server port. When empty the port will be determined automatically -// using getservbyname() function, with 4190 as a fallback. -$config['managesieve_port'] = null; - -// managesieve server address, default is localhost. +// Managesieve server host (and optional port). Default: localhost. // Replacement variables supported in host name: // %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 +// If port is omitted it will be determined automatically using getservbyname() +// function, with 4190 as a fallback. +// Note: Add tls:// prefix to enable TLS $config['managesieve_host'] = 'localhost'; // authentication method. Can be CRAM-MD5, DIGEST-MD5, PLAIN, LOGIN, EXTERNAL @@ -24,10 +23,6 @@ $config['managesieve_auth_cid'] = null; // Optional managesieve authentication password to be used for imap_auth_cid $config['managesieve_auth_pw'] = null; -// use or not TLS for managesieve server connection -// Note: tls:// prefix in managesieve_host is also supported -$config['managesieve_usetls'] = false; - // Connection socket context options // See http://php.net/manual/en/context.ssl.php // The example below enables server certificate validation diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 49f9d310d..dd2bc0046 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -165,29 +165,13 @@ class rcube_sieve_engine */ public function connect($username, $password) { - // Get connection parameters $host = $this->rc->config->get('managesieve_host', 'localhost'); - $port = $this->rc->config->get('managesieve_port'); - $tls = $this->rc->config->get('managesieve_usetls', false); - $host = rcube_utils::parse_host($host); - $host = rcube_utils::idn_to_ascii($host); - - // remove tls:// prefix, set TLS flag - if (($host = preg_replace('|^tls://|i', '', $host, 1, $cnt)) && $cnt) { - $tls = true; - } - - if (empty($port)) { - $port = getservbyname('sieve', 'tcp') ?: self::PORT; - } $plugin = $this->rc->plugins->exec_hook('managesieve_connect', [ 'user' => $username, 'password' => $password, 'host' => $host, - 'port' => $port, - 'usetls' => $tls, 'auth_type' => $this->rc->config->get('managesieve_auth_type'), 'disabled' => $this->rc->config->get('managesieve_disabled_extensions'), 'debug' => $this->rc->config->get('managesieve_debug', false), @@ -198,17 +182,32 @@ class rcube_sieve_engine 'gssapi_cn' => null, ]); + $url = parse_url($plugin['host']); + $tls = false; + + if (!empty($url['host'])) { + $host = $url['host']; + $port = $url['port'] ?? null; + $tls = !empty($url['scheme']) && $url['scheme'] === 'tls'; + } + + if (empty($port)) { + $port = getservbyname('sieve', 'tcp') ?: self::PORT; + } + + $host = rcube_utils::idn_to_ascii($host); + // Handle per-host socket options - rcube_utils::parse_socket_options($plugin['socket_options'], $plugin['host']); + rcube_utils::parse_socket_options($plugin['socket_options'], $host); // try to connect to managesieve server and to fetch the script $this->sieve = new rcube_sieve( $plugin['user'], $plugin['password'], - $plugin['host'], - $plugin['port'], + $host, + $port, $plugin['auth_type'], - $plugin['usetls'], + $tls, $plugin['disabled'], $plugin['debug'], $plugin['auth_cid'], diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 941d073a1..87ad2d3cb 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -669,8 +669,7 @@ class rcmail extends rcube return false; } - $default_host = $this->config->get('default_host'); - $default_port = $this->config->get('default_port'); + $imap_host = $this->config->get('imap_host', 'tls://localhost:143'); $username_domain = $this->config->get('username_domain'); $login_lc = $this->config->get('login_lc', 2); @@ -682,45 +681,33 @@ class rcmail extends rcube // host is validated in rcmail::autoselect_host(), so here // we'll only handle unset host (if possible) - if (!$host && !empty($default_host)) { - if (is_array($default_host)) { - $key = key($default_host); - $host = is_numeric($key) ? $default_host[$key] : $key; + if (!$host && !empty($imap_host)) { + if (is_array($imap_host)) { + $key = key($imap_host); + $host = is_numeric($key) ? $imap_host[$key] : $key; } else { - $host = $default_host; + $host = $imap_host; } - - $host = rcube_utils::parse_host($host); } + $host = rcube_utils::parse_host($host); + if (!$host) { $this->login_error = self::ERROR_INVALID_HOST; return false; } // parse $host URL - $a_host = parse_url($host); - $ssl = false; - $port = null; - - if (!empty($a_host['host'])) { - $host = $a_host['host']; - - if (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl', 'imaps', 'tls'])) { - $ssl = $a_host['scheme']; - } - - if (!empty($a_host['port'])) { - $port = $a_host['port']; - } - else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143)) { - $port = 993; - } - } + $url = parse_url($host); + $ssl = false; + $port = 143; - if (empty($port)) { - $port = $default_port; + if (!empty($url['host'])) { + $host = $url['host']; + $scheme = $url['scheme'] ?? null; + $ssl = in_array($scheme, ['ssl', 'imaps', 'tls']) ? $scheme : false; + $port = $url['port'] ?? ($ssl && $ssl != 'tls' ? 993 : 143); } // Check if we need to add/force domain to username @@ -969,7 +956,7 @@ class rcmail extends rcube */ public function autoselect_host() { - $default_host = $this->config->get('default_host'); + $default_host = $this->config->get('imap_host'); $host = null; if (is_array($default_host)) { diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php index 21c7bbebb..80fa9ff3f 100644 --- a/program/include/rcmail_install.php +++ b/program/include/rcmail_install.php @@ -38,7 +38,7 @@ class rcmail_install public $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])'; public $bool_config_props = []; - public $local_config = ['db_dsnw', 'default_host', 'support_url', 'des_key', 'plugins']; + public $local_config = ['db_dsnw', 'imap_host', 'support_url', 'des_key', 'plugins']; public $obsolete_config = ['db_backend', 'db_max_length', 'double_auth', 'preview_pane', 'debug_level', 'referer_check']; public $replaced_config = [ 'skin_path' => 'skin', @@ -50,6 +50,8 @@ class rcmail_install 'top_posting' => 'reply_mode', 'keep_alive' => 'refresh_interval', 'min_keep_alive' => 'min_refresh_interval', + 'default_host' => 'imap_host', + 'smtp_server' => 'smtp_host', ]; // list of supported database drivers @@ -223,7 +225,7 @@ class rcmail_install else if ($prop == 'smtp_auth_type' && $value == '0') { $value = ''; } - else if ($prop == 'default_host' && is_array($value)) { + else if ($prop == 'imap_host' && is_array($value)) { $value = self::_clean_array($value); if (count($value) <= 1) { $value = $value[0]; @@ -600,13 +602,13 @@ class rcmail_install * * @return array Clean list with imap/smtp hosts */ - public function get_hostlist($prop = 'default_host') + public function get_hostlist($prop = 'imap_host') { $hosts = (array) $this->getprop($prop); $out = []; $imap_host = ''; - if ($prop == 'smtp_server') { + if ($prop == 'smtp_host') { // Set the imap host name for the %h macro $default_hosts = $this->get_hostlist(); $imap_host = !empty($default_hosts) ? $default_hosts[0] : ''; @@ -614,7 +616,7 @@ class rcmail_install foreach ($hosts as $key => $name) { if (!empty($name)) { - if ($prop == 'smtp_server') { + if ($prop == 'smtp_host') { // SMTP host array uses `IMAP host => SMTP host` format $host = $name; } diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index 4315fe65e..b13f6266b 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -2302,7 +2302,7 @@ EOF; */ protected function login_form($attrib) { - $default_host = $this->config->get('default_host'); + $default_host = $this->config->get('imap_host'); $autocomplete = (int) $this->config->get('login_autocomplete'); $username_filter = $this->config->get('login_username_filter'); $_SESSION['temp'] = true; diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php index 0b4fc6112..6ed5027e1 100644 --- a/program/lib/Roundcube/rcube_ldap.php +++ b/program/lib/Roundcube/rcube_ldap.php @@ -300,6 +300,20 @@ class rcube_ldap extends rcube_addressbook // with OpenLDAP 2.x ldap_connect() always succeeds but ldap_bind will fail if host isn't reachable // see http://www.php.net/manual/en/function.ldap-connect.php foreach ((array) $this->prop['hosts'] as $host) { + $this->ldap->option_set('use_tls', false); + + // Parse host specification into the format expected by Net_LDAP3 (ldap_connect) + $url = parse_url($host); + if (!empty($url['host'])) { + $host = $url['host']; + $scheme = $url['scheme'] ?? 'ldap'; + $port = $url['port'] ?? ($scheme === 'ldaps' ? 636 : 389); + + $host = sprintf('%s://%s:%d', $scheme === 'ldaps' ? 'ldaps' : 'ldap', $host, $port); + + $this->ldap->option_set('use_tls', $scheme === 'tls'); + } + // skip host if connection failed if (!$this->ldap->connect($host)) { continue; diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php index 584027eae..f31c07120 100644 --- a/program/lib/Roundcube/rcube_smtp.php +++ b/program/lib/Roundcube/rcube_smtp.php @@ -58,7 +58,7 @@ class rcube_smtp $this->error = $this->response = null; if (!$host) { - $host = $rcube->config->get('smtp_server'); + $host = $rcube->config->get('smtp_host', 'tls://localhost:587'); if (is_array($host)) { if (array_key_exists($_SESSION['storage_host'], $host)) { $host = $host[$_SESSION['storage_host']]; @@ -70,11 +70,15 @@ class rcube_smtp } } } + else if (!empty($port) && !empty($host) && !preg_match('/:\d+$/', $host)) { + $host = "{$host}:{$port}"; + } + + $host = rcube_utils::parse_host($host); // let plugins alter smtp connection config $CONFIG = $rcube->plugins->exec_hook('smtp_connect', [ - 'smtp_server' => $host, - 'smtp_port' => $port ?: $rcube->config->get('smtp_port', 587), + 'smtp_host' => $host, 'smtp_user' => $user !== null ? $user : $rcube->config->get('smtp_user', '%u'), 'smtp_pass' => $pass !== null ? $pass : $rcube->config->get('smtp_pass', '%p'), 'smtp_auth_cid' => $rcube->config->get('smtp_auth_cid'), @@ -88,28 +92,22 @@ class rcube_smtp 'gssapi_cn' => null, ]); - $smtp_host = rcube_utils::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; - $smtp_host_url = parse_url($smtp_host); + $smtp_host = $CONFIG['smtp_host'] ?: 'localhost'; + $smtp_port = 587; + $use_tls = false; - // overwrite port - if (isset($smtp_host_url['host']) && isset($smtp_host_url['port'])) { - $smtp_host = $smtp_host_url['host']; - $smtp_port = $smtp_host_url['port']; - } + $url = parse_url($smtp_host); - // re-write smtp host - if (isset($smtp_host_url['host']) && isset($smtp_host_url['scheme'])) { - $smtp_host = sprintf('%s://%s', $smtp_host_url['scheme'], $smtp_host_url['host']); - } + if (!empty($url['host'])) { + $smtp_host = $url['host']; + $scheme = $url['scheme'] ?? null; + $smtp_port = $url['port'] ?? ($scheme === 'ssl' ? 465 : 587); + $use_tls = $scheme === 'tls'; - // remove TLS prefix and set flag to enable TLS later - $use_tls = false; - if (preg_match('#^tls://#i', $smtp_host)) { - $smtp_host = preg_replace('#^tls://#i', '', $smtp_host); - $use_tls = true; + // re-add the ssl:// prefix + if ($scheme === 'ssl') { + $smtp_host = "ssl://{$smtp_host}"; + } } // Handle per-host socket options diff --git a/tests/Browser/README.md b/tests/Browser/README.md index 1edd357d8..b761e6eba 100644 --- a/tests/Browser/README.md +++ b/tests/Browser/README.md @@ -28,7 +28,7 @@ php tests/Browser/install.php [version] Create a config file named `config-test.inc.php` in the Roundcube config dir. That file should provide specific `db_dsnw` and -`default_host` values for testing purposes as well as the credentials of a +`imap_host` values for testing purposes as well as the credentials of a valid IMAP user account used for running the tests with. Add these config options used by the Browser tests: diff --git a/tests/Browser/bootstrap.php b/tests/Browser/bootstrap.php index 3a0e4415c..54114991a 100644 --- a/tests/Browser/bootstrap.php +++ b/tests/Browser/bootstrap.php @@ -109,7 +109,7 @@ class bootstrap private static function init_db_user($db) { $rcmail = rcmail::get_instance(); - $imap_host = $rcmail->config->get('default_host'); + $imap_host = $rcmail->config->get('imap_host'); if ($host = parse_url($imap_host, PHP_URL_HOST)) { $imap_host = $host; @@ -152,12 +152,12 @@ class bootstrap self::$imap_ready = false; } - $imap_host = $rcmail->config->get('default_host'); + $imap_host = $rcmail->config->get('imap_host'); $a_host = parse_url($imap_host); if (!empty($a_host['host'])) { $imap_host = $a_host['host']; $imap_ssl = isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls']); - $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143); + $imap_port = $a_host['port'] ?? ($imap_ssl ? 993 : 143); } else { $imap_port = 143; |