Roundcube Community Forum

Release Support => Pending Issues => Topic started by: ricardo777 on February 18, 2016, 03:10:49 PM

Title: Not functioning include_host_config
Post by: ricardo777 on February 18, 2016, 03:10:49 PM
Hello,

As the title says I do not get the function include_host_config to work.

I have tried almost everything like using many hostnames and checking the hostname in the mysql database without success.

The option include_host_config does not work for me.

Using 1.2 beta release.

Does someone know a solution, it looks like the include_host_config ignores and do not use the file I have set like:

Code: [Select]
$config['include_host_config'] = array(
  'mail.domain.nl' => 'filename.inc.php',
    'domain.nl' => 'filename.inc.php'
//);
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 19, 2016, 02:54:14 AM
those lines are linvalid and would generate a php error but i'm going to assume thats a typo in your post rather than in the config.

the array keys you are using. are they the host name part of the url that you use to access roundcube?
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 19, 2016, 03:09:03 AM
Thank you for the reply.

Sorry I had comment out the whole 3 lines but forgot 1 line to remove the // when posting this is the correct lines

Code: [Select]
$config['include_host_config'] = array(
  'mail.domain.nl' => 'filename.inc.php',
    'domain.nl' => 'filename.inc.php'
);

I have also tried using include host config true and created the host name config files but that options did not worked also.

I am failing to understand why it does not work.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 19, 2016, 05:34:13 AM
please double check that the file permissions on your config files are correct, that PHP can read them.

else I think you might have to dig around in program/lib/Roundcube/rcube_config.php to see why it isnt loading them because it does not log errors for that. There are 2 functions in there: load_host_config and then right after it load_from_file which do the work.
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 19, 2016, 11:40:26 AM
Hello,

I see in the code that it merges the config files, is it not a replace thingy?

Meaning when a same config is in the master config and also in the host name config which config options is choosen?

Also file permission is set correctly I have checked it.

Only thing I can think is that it merges and it takes the master file instead of hostname config, I need to check this.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 20, 2016, 01:38:35 AM
Quote
Meaning when a same config is in the master config and also in the host name config which config options is choosen?

you do not need to repeat the options in both files. in the host config file you only put what is different from the main one.

one does not replace the other, they are combined. say for example in your main config file you have product_name set to `my webmail` but when people use a certain url you want the name to come up as `company webmail` then you'd add a host config file and put set product_name equal to `company webmail` in it.
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 20, 2016, 11:10:18 AM
Hello,

Thank you for the help.

I have tested some things but it still do not work I have this in the hostname config:

Code: [Select]
<?php

// ----------------------------------
// IMAP
// ----------------------------------
// The mail 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.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// 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
// 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'] = 'ssldomaintest.%s';

I have also a option default_host in the main config file for all the other domains.

I want to use default_host on 1 domain only for te right ssl hostname but I do not get include_host_config to function.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 02:57:55 AM
can i please check 1 thing:

Code: [Select]
$config['default_host'] = 'ssldomaintest.%s';
the default_host config option holds the address of your IMAP server not the address of your Roundcube installation. Its the server that Roundcube connects to to get your mail.
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 03:49:38 AM
I used that for that for testing I have one domain that uses 1 other server for connection the issue that I have is:

Now it connects via mail.hostname

But I want to use SSL the server uses ssl with another hostname so php imap and smtp would not let me connect because the host name is not corresponding with the SSL certificate.

I wanted to use another config file for the domain and set the right imap and smtp hostname that correspond with the right ssl domain and hostname so I can connect. At the moment I am now connection without ssl because it does not work with.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 04:09:40 AM
Cool. Just had to double check.

I think then you have to go back to the code in rcube_config and add some debug lines to identify why your host config file is not being read. You can use `rcube::write_log('debug', 'my message...');`
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 04:38:59 AM
Will try it out, my php skills are not very great :-X

Also I now see you are from the contextmenu plugin, great ;)
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 04:46:48 AM
I have changed the config to:

Code: [Select]
    /**
     * Load a host-specific config file if configured
     * This will merge the host specific configuration with the given one
     */
    private function load_host_config()
    {
        if (empty($this->prop['include_host_config'])) {
            return;
        }

        foreach (array('HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR') as $key) {
            $fname = null;
            $name  = $_SERVER[$key];
rcube::write_log('debug', 'loadhost');

            if (!$name) {
                continue;
rcube::write_log('debug', 'loadhost');
            }

            if (is_array($this->prop['include_host_config'])) {
                $fname = $this->prop['include_host_config'][$name];
rcube::write_log('debug', 'loadhost');
            }
            else {
                $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $name) . '.inc.php';
rcube::write_log('debug', 'loadhost');
            }

            if ($fname && $this->load_from_file($fname)) {
                return;
rcube::write_log('debug', 'loadhost');
            }
        }
    }

The only thing in the debug file is:

Code: [Select]
[21-Feb-2016 10:42:56 +0100]: loadhost[/code
 No error or anything else.

Am I doing it incorrectly?
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 05:22:17 AM
Sorry for the third reply.

I have updated to the latest github version without solution.

I have test rcube::write_log('debug', 'loadhost'); per function if etc..

I looks like the function is running I can see al the debug per function.

Wich hostname I need to use for the domain is it:

mail.domain.nl
or only the domain?

now I use both but is still does not work.

I have checked the table: users>mail_host and that is correct and is in the load_config array.

I also removed the user in the users table but still is uses the standard mail_host and not the one in the hostname config file.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 05:23:42 AM
first i'd change that first log line to `rcube::write_log('debug', $name);` so you can see what its actually looking for. that $name should match a key in your host file config array
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 05:32:43 AM
Hello,

Firstly thank you help really appreciate it.

I have changed it and this is the output:

Code: [Select]
[21-Feb-2016 11:30:57 +0100]: mail.roundcubeinstallation.nl
[21-Feb-2016 11:30:57 +0100]: IP of the roundcubeinstallation

I have changed the domain and IP
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 05:39:44 AM
Another reply

I have changed name to fname and it looks for the ip as hostname:

Code: [Select]
[21-Feb-2016 11:36:42 +0100]: mail.domain.nl.inc.php
[21-Feb-2016 11:36:42 +0100]: NULL
[21-Feb-2016 11:36:42 +0100]: IPofrounducbeinstallation.inc.php

Is this something I have in my config file that it looks for the IP or Hostname of the roundcubeinstallation? the domain I am using is not on the roundcube installation.

Here is my configfile:

Code: [Select]
<?php
/* Local configuration for Roundcube Webmail */

// PEAR database DSN for read/write operations
// format is db_provider://user:password@host/database 
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// currently supported db_providers: mysql, mysqli, pgsql, sqlite, mssql or sqlsrv
$config['db_dsnw'] = '';

$config['include_host_config'] = array(
  
'mail.domain.nl' => 'mail.domain.inc.php',
  
'domain.nl' => 'mail.domain.inc.php',
  
'h1.domain.nl' => 'mail.domain.inc.php'
);

$config['include_host_config'] = true;

// ----------------------------------
// USER PREFERENCES
// ----------------------------------

// Use this charset as fallback for message decoding
$config['default_charset'] = 'ISO-8859-1';

// skin name: folder from skins/
$config['skin'] = 'outlook';

// use this timezone to display date/time
// valid timezone identifers are listed here: php.net/manual/en/timezones.php
// 'auto' will use the browser's timezone settings
$config['timezone'] = 'auto';

// prefer displaying HTML messages
$config['prefer_html'] = true;

// display remote inline images
// 0 - Never, always ask
// 1 - Ask if sender is not in address book
// 2 - Always show inline images
$config['show_images'] = 1;

// save copies of compose messages in the browser's local storage
// for recovery in case of browser crashes and session timeout.
$config['compose_save_localstorage'] = true;

// ----------------------------------
// IMAP
// ----------------------------------
// The mail 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.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// 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
// 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'] = 'mail.%s';

// ----------------------------------
// SMTP
// ----------------------------------
// 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
// 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
//$config['smtp_server'] = 'tls://%h';
$config['smtp_server'] = '%h';

// SMTP username (if required) if you use %u as the username Roundcube
// will use the current username for login
$config['smtp_user'] = '%u';

// SMTP password (if required) if you use %p as the password Roundcube
// will use the current user's password for login
$config['smtp_pass'] = '%p';

// SMTP port (default is 25; use 587 for STARTTLS or 465 for the
// deprecated SSL over SMTP (aka SMTPS))
//$config['smtp_port'] = 587;

// provide an URL where a user can get support for this Roundcube installation
// PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
$config['support_url'] = 'http://domain.nl/support';

// replace Roundcube logo with this image
// specify an URL relative to the document root of this Roundcube installation
$config['skin_logo'] = 'https://domain.nl/images/logo/domain_RC_2.png';

// use this folder to store log files (must be writeable for apache user)
// This is used by the 'file' log driver.
$config['log_dir'] = '/home/domainmail/domains/domain.nl/public_html/logs/';

// use this folder to store temp files (must be writeable for apache user)
$config['temp_dir'] = '/home/domainmail/domains/domain.nl/public_html/temp';

// enforce connections over https
// with this option enabled, all non-secure connections will be redirected.
// set the port for the ssl connection as value of this option if it differs from the default 443
$config['force_https'] = true;

// Session lifetime in minutes
$config['session_lifetime'] = 15;

// Session domain: .example.org
$config['session_domain'] = 'mail.domain.nl';

// Session name. Default: 'roundcube_sessid'
$config['session_name'] = 'maildomain_sessid';

// Session authentication cookie name. Default: 'roundcube_sessauth'
$config['session_auth_name'] = 'maildomain_sessauth';

// Session path. Defaults to PHP session.cookie_path setting.
$config['session_path'] = null;

// Backend to use for session storage. Can either be 'db' (default), 'memcache' or 'php'
// If set to 'memcache', a list of servers need to be specified in 'memcache_hosts'
// Make sure the Memcache extension (http://pecl.php.net/package/memcache) version >= 2.0.0 is installed
// Setting this value to 'php' will use the default session save handler configured in PHP
$config['session_storage'] = 'db';

// e.g. array( 'localhost:11211', '192.168.1.12:11211', 'unix:///var/tmp/memcached.sock' );
// check client IP in session athorization
$config['ip_check'] = true;

// this key is used to encrypt the users imap password which is stored
// in the session record (and the client cookie if remember password is enabled).
// please provide a string of exactly 24 chars.
$config['des_key'] = '';

// use this name to compose page titles
$config['product_name'] = 'domain Webmail';

// ----------------------------------
// PLUGINS
// ----------------------------------
// List of active plugins (in plugins/ directory)

$config['plugins'] = array('contextmenu''persistent_login''archive','attachment_reminder''managesieve''markasjunk''password');

// the default locale setting (leave empty for auto-detection)
// RFC1766 formatted language name like en_US, de_DE, de_CH, fr_FR, pt_BR
$config['language'] = 'nl';

//Custom
$config['quota_zero_as_unlimited'] = true;

// compose html formatted messages by default
// 0 - never, 1 - always, 2 - on reply to HTML message, 3 - on forward or reply to HTML message
$config['htmleditor'] = 1;

// save compose message every 300 seconds (5min)
$config['draft_autosave'] = 60;

// default setting if preview pane is enabled
$config['preview_pane'] = true;

// Encoding of long/non-ascii attachment names:
// 0 - Full RFC 2231 compatible
// 1 - RFC 2047 for 'name' and RFC 2231 for 'filename' parameter (Thunderbird's default)
// 2 - Full 2047 compatible
$config['mime_param_folding'] = 0;

// lifetime of message cache
// possible units: s, m, h, d, w
$config['message_cache_lifetime'] = '10d';

// ----------------------------------
// LOGGING/DEBUGGING
// ----------------------------------

// system error reporting, sum of: 1 = log; 4 = show, 8 = trace
$config['debug_level'] = 1;

// log driver:  'syslog' or 'file'.
$config['log_driver'] = 'file';

// date format for log entries
// (read http://php.net/manual/en/function.date.php for all format characters)  
$config['log_date_format'] = 'd-M-Y H:i:s O';

// Syslog ident string to use, if using the 'syslog' log driver.
$config['syslog_id'] = 'roundcube';

// Syslog facility to use, if using the 'syslog' log driver.
// For possible values see installer or http://php.net/manual/en/function.openlog.php
$config['syslog_facility'] = LOG_USER;

// Activate this option if logs should be written to per-user directories.
// Data will only be logged if a directry <log_dir>/<username>/ exists and is writable.
$config['per_user_logging'] = false;

// Log sent messages to <log_dir>/sendmail or to syslog
$config['smtp_log'] = true;

// Log successful/failed logins to <log_dir>/userlogins or to syslog
$config['log_logins'] = true;

// Log session authentication errors to <log_dir>/session or to syslog
$config['log_session'] = false;

// Log SQL queries to <log_dir>/sql or to syslog
$config['sql_debug'] = false;

// Log IMAP conversation to <log_dir>/imap or to syslog
$config['imap_debug'] = false;

// Log LDAP conversation to <log_dir>/ldap or to syslog
$config['ldap_debug'] = false;

// Log SMTP conversation to <log_dir>/smtp or to syslog
$config['smtp_debug'] = true;

// IMAP AUTH type (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or null to use
// best server supported one)
$config['imap_auth_type'] = null;

// display these folders separately in the mailbox list.
// these folders will also be displayed with localized names
$rcmail_config['default_folders'] = array('INBOX''INBOX.Drafts''INBOX.Sent''INBOX.Trash''INBOX.Archive');

// automatically create the above listed default folders on login
$rcmail_config['create_default_folders'] = true;

// protect the default folders from renames, deletes, and subscription changes
$config['protect_default_folders'] = true;

//Custom special folders// store draft message is this mailbox

// leave blank if draft messages should not be stored
// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP)
$config['drafts_mbox'] = 'INBOX.Drafts';

// store spam messages in this mailbox
// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP)
$config['junk_mbox'] = 'INBOX.spam';

// store sent message is this mailbox
// leave blank if sent messages should not be stored
// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP)
$config['sent_mbox'] = 'INBOX.Sent';

// move messages to this folder when deleting them
// leave blank if they should be deleted directly
// NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP)
$config['trash_mbox'] = 'INBOX.Trash';

// archief mailbox voor plugin archive
$config['archive_mbox'] = 'INBOX.archive';

// Type of IMAP indexes cache. Supported values: 'db', 'apc' and 'memcache'.
$config['imap_cache'] = 'db';

// Enables messages cache. Only 'db' cache is supported.
// This requires an IMAP server that supports QRESYNC and CONDSTORE
// extensions (RFC7162). See synchronize() in program/lib/Roundcube/rcube_imap_cache.php
// for further info, or if you experience syncing problems.
$config['messages_cache'] = true;

// Lifetime of IMAP indexes cache. Possible units: s, m, h, d, w
$config['imap_cache_ttl'] = '10d';

// Lifetime of messages cache. Possible units: s, m, h, d, w
$config['messages_cache_ttl'] = '10d';

// Maximum cached message size in kilobytes.
// Note: On MySQL this should be less than (max_allowed_packet - 30%)
$config['messages_cache_threshold'] = 50;

$rcmail_config['quota_zero_as_unlimited'] = true;

// default messages sort column. Use empty value for default server's sorting, 
// or 'arrival', 'date', 'subject', 'from', 'to', 'fromto', 'size', 'cc'
$config['message_sort_col'] = '';

// Make use of the built-in spell checker. It is based on GoogieSpell.
// Since Google only accepts connections over https your PHP installatation
// requires to be compiled with Open SSL support
$config['enable_spellcheck'] = true;

// Enables spellchecker exceptions dictionary.
// Setting it to 'shared' will make the dictionary shared by all users.
$config['spellcheck_dictionary'] = false;

// Set the spell checking engine. Possible values:
// - 'googie'  - the default (also used for connecting to Nox Spell Server, see 'spellcheck_uri' setting)
// - 'pspell'  - requires the PHP Pspell module and aspell installed
// - 'enchant' - requires the PHP Enchant module
// - 'atd'     - install your own After the Deadline server or check with the people at http://www.afterthedeadline.com before using their API
// Since Google shut down their public spell checking service, the default settings
// connect to http://spell.roundcube.net which is a hosted service provided by Roundcube.
// You can connect to any other googie-compliant service by setting 'spellcheck_uri' accordingly.
$config['spellcheck_engine'] = 'googie';
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 05:42:12 AM
great so in your main roundcube config file you should have a line like this:
Code: [Select]
$config['include_host_config'] = array('mail.roundcubeinstallation.nl' => 'test.inc.php');assuming you always use the url to access Roundcube then you do not need to add an entry for the IP as well.

Then in test.inc.php you put your alt value for default_host.
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 05:47:04 AM
Ok now it works for the domain and all other.

How can I for example use the config file for 1 domain like

domain1.com for the hostname config, that would connect to an external ssl server via a set hostname in the domain1.inc.php config file.

Al the other domains like domain.com needs to connect to the roundcubeinstallation server.

The option:
Code: [Select]
$config['include_host_config'] = array('mail.roundcubeinstallation.nl' => 'test.inc.php');
will set that all the domain use the config file not domain1.com only.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 05:57:44 AM
When you say domain what exactly are you referring to as domain?

The include_host_config option works based on the host name used to access roundcube, eg. mail.roundcubeinstallation.nl
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 06:23:17 AM
When you say domain what exactly are you referring to as domain?

The include_host_config option works based on the host name used to access roundcube, eg. mail.roundcubeinstallation.nl

Ah you say include_host_config is based on the website used? Then I misunderstand the function.

I thought it was based on the hostname of the username not the roundcube access url.

What I am looking for, it that imap and smtp connect to the server hostname (what is in the ssl certificate) and not the domain mail.domain.com

Or I need include_host based on the username login, not the website. I use 1 website for all the logins.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 21, 2016, 06:34:07 AM
Quote
Ah you say include_host_config is based on the website used?
that's correct.

There are some macros in the config file for things based on all or part of the username but as you found they are limited in how much they can change the config. Changing config based on individual usernames is not something roundcube is built for.

If you can setup a second address for the website just for testing then you could use the include_host_config option. Without that then I think you'd have to write a plugin. There are hooks for imap connect and smtp connect and you could change what it does based on the username But you said that you PHP skills are not great. So if possible I would think that setting up a test url would be better. You do not need a separate roundcube installation just an alias to your existing site.
Title: Re: Not functioning include_host_config
Post by: ricardo777 on February 21, 2016, 06:49:41 AM
Ok thank you, for all the help and information.

Can you write a plugin and how many will it costs? if you have interest you can PM me.
Title: Re: Not functioning include_host_config
Post by: JohnDoh on February 22, 2016, 11:49:17 AM
I'm not really into making plugins to order but I might be able to give you a few pointers. I'll PM you. I don't want to post half working code in public space.
Title: Re: Not functioning include_host_config
Post by: noface0711 on March 11, 2016, 05:44:53 AM
I think then you have to go back to the code in rcube_config and add some debug lines to identify why your host config file is not being read. You can use `rcube::write_log('debug', 'my message...');`
Title: Re: Not functioning include_host_config
Post by: ricardo777 on March 11, 2016, 09:41:24 AM
I have a solution thanks to: JohnDoh :)