From: Jérémy Bobbio Date: Sat, 18 Jun 2011 19:26:07 +0000 (+0200) Subject: Imported Upstream version 0.5.1 X-Git-Url: https://git.donarmstrong.com/?p=roundcube.git;a=commitdiff_plain;h=315a64971ff1249e4d5884f309fab5ddbfe55cc6 Imported Upstream version 0.5.1 --- diff --git a/CHANGELOG b/CHANGELOG index 3a24db1..8674726 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,40 @@ CHANGELOG Roundcube Webmail =========================== +RELEASE 0.5.1 +------------- +- Fix handling of attachments with invalid content type (#1487767) +- Add workaround for DBMail's bug http://www.dbmail.org/mantis/view.php?id=881 (#1487766) +- Use IMAP's ID extension (RFC2971) to print more info into debug log +- Security: add optional referer check to prevent CSRF in GET requests +- Fix email_dns_check setting not used for identities/contacts (#1487740) +- Fix ICANN example addresses doesn't validate (#1487742) +- Security: protect login form submission from CSRF +- Security: prevent from relaying malicious requests through modcss.inc +- Fix handling of non-image attachments in multipart/related messages (#1487750) +- Fix IDNA support when IDN/INTL modules are in use (#1487742) +- Fix handling of invalid HTML comments in messages (#1487759) +- Fix parsing FETCH response for very long headers (#1487753) +- Fix add/remove columns in message list when message_sort_order isn't set (#1487751) +- Fix settings UI on IE 6 (#1487724) +- Remove double borders in folder listing (#1487713) +- Separate full message headers UI element from headers table (#1487715) +- Add part MIME ID to message_part_* hooks (#1487718) +- Updated PEAR::Net_Socket to 1.0.10 +- Updated PEAR::Net_IDNA2 to 0.1.1 +- Fix handling of comments inside an email address spec. (#1487673) +- Show full mail subject as title when hovering a cut subject link (#1487128) +- Fix randomly disappearing folders list in IE (#1487704) +- Fix list column add/removal in IE (#1487703) +- Fix login redirect issues (#1487686) +- Require PHP 5.2.1 or greater +- Fix %h/%z variables in username_domain option (#1487701) +- Workaround for setting charset in case of malformed bodystructure response (#1487700) +- Fix impossible to subscribe to protected folders (#1487656) +- Fix setting timezone in Preferences (#1487705) + +RELEASE 0.5 +----------- - Fix double-login/session issue (#1487104) - Wrap HTML parts with and add Doctype declaration (#1487098) - Make rcube_autoload silently skip unknown classes (#1487109) diff --git a/INSTALL b/INSTALL index 8216343..956fb24 100644 --- a/INSTALL +++ b/INSTALL @@ -11,7 +11,7 @@ REQUIREMENTS * The Apache or Lighttpd Webserver * .htaccess support allowing overrides for DirectoryIndex -* PHP Version 5.2 or greater including +* PHP Version 5.2.1 or greater including - PCRE, DOM, JSON, XML, Session, Sockets (required) - Libiconv - Multibyte String (mbstring) @@ -22,6 +22,7 @@ REQUIREMENTS - MDB2 2.5.0 or newer - Mail_Mime 1.8.1 or newer - Net_SMTP 1.4.2 or newer + - Net_IDNA2 0.1.1 or newer - Auth_SASL 1.0.3 or newer * php.ini options (see .htaccess file): - error_reporting E_ALL & ~E_NOTICE (or lower) diff --git a/INSTALL.orig b/INSTALL.orig deleted file mode 100644 index eb83997..0000000 --- a/INSTALL.orig +++ /dev/null @@ -1,231 +0,0 @@ -INTRODUCTION -============ - -This file describes the basic steps to install Roundcube Webmail on your -web server. For additional information, please also consult the project's -wiki page at http://trac.roundcube.net/wiki - - -REQUIREMENTS -============ - -* The Apache or Lighttpd Webserver -* .htaccess support allowing overrides for DirectoryIndex -* PHP Version 5.2 or greater including - - PCRE, DOM, JSON, XML, Session, Sockets (required) - - libiconv (recommended) - - mbstring, fileinfo, mcrypt (optional) -* PEAR packages distributed with Roundcube or external: - - MDB2 2.5.0 or newer - - Mail_Mime 1.8.1 or newer - - Net_SMTP 1.4.2 or newer - - Auth_SASL 1.0.3 or newer -* php.ini options (see .htaccess file): - - error_reporting E_ALL & ~E_NOTICE (or lower) - - memory_limit > 16MB (increase as suitable to support large attachments) - - file_uploads enabled (for attachment upload features) - - session.auto_start disabled - - zend.ze1_compatibility_mode disabled - - suhosin.session.encrypt disabled - - mbstring.func_overload disabled -* PHP compiled with OpenSSL to connect to IMAPS and to use the spell checker -* A MySQL (4.0.8 or newer), PostgreSQL, MSSQL database engine - or the SQLite extension for PHP -* One of the above databases with permission to create tables -* An SMTP server (recommended) or PHP configured for mail delivery - - -INSTALLATION -============ - -1. Decompress and put this folder somewhere inside your document root -2. Make sure that the following directories (and the files within) - are writable by the webserver - - /temp - - /logs -3. Create a new database and a database user for Roundcube (see DATABASE SETUP) -4. Point your browser to http://url-to-roundcube/installer/ -5. Follow the instructions of the install script (or see MANUAL CONFIGURATION) -6. After creating and testing the configuration, remove the installer directory -7. Done! - - -CONFIGURATION HINTS -=================== - -Roundcube writes internal errors to the 'errors' log file located in the logs -directory which can be configured in config/main.inc.php. If you want ordinary -PHP errors to be logged there as well, enable the 'php_value error_log' line -in the .htaccess file and set the path to the log file accordingly. - -By default the session_path settings of PHP are not modified by Roundcube. -However if you want to limit the session cookies to the directory where -Roundcube resides you can uncomment and configure the according line -in the .htaccess file. - - -DATABASE SETUP -============== - -Note: Database for Roundcube must use UTF-8 character set. - -* MySQL -------- -Setting up the mysql database can be done by creating an empty database, -importing the table layout and granting the proper permissions to the -roundcube user. Here is an example of that procedure: - -# mysql -> CREATE DATABASE roundcubemail /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost - IDENTIFIED BY 'password'; -> quit - -# mysql roundcubemail < SQL/mysql.initial.sql - -Note 1: 'password' is the master password for the roundcube user. It is strongly -recommended you replace this with a more secure password. Please keep in -mind: You need to specify this password later in 'config/db.inc.php'. - - -* SQLite --------- -You need sqlite 2 (preferably 2.8) to setup the sqlite db -(sqlite 3.x also doesn't work at the moment). Here is -an example how you can setup the sqlite.db for roundcube: - -# sqlite -init SQL/sqlite.initial.sql sqlite.db -Loading resources from SQL/sqlite.initial.sql -SQLite version 2.8.16 -Enter ".help" for instructions -sqlite> .exit -# chmod o+rw sqlite.db - -Make sure your configuration points to the sqlite.db file and that the -webserver can write to the file and the directory containing the file. - - -* PostgreSQL ------------- -To use Roundcube with PostgreSQL support you have to follow these -simple steps, which have to be done as the postgres system user (or -which ever is the database superuser): - -$ createuser roundcube -$ createdb -O roundcube -E UNICODE roundcubemail -$ psql roundcubemail - -roundcubemail =# ALTER USER roundcube WITH PASSWORD 'the_new_password'; -roundcubemail =# \c - roundcube -roundcubemail => \i SQL/postgres.initial.sql - -All this has been tested with PostgreSQL 8.x and 7.4.x. Older -versions don't have a -O option for the createdb, so if you are -using that version you'll have to change ownership of the DB later. - - -Database cleaning ------------------ -Do keep your database slick and clean we recommend to periodically execute -bin/cleandb.sh which finally removes all records that are marked as deleted. -Best solution is to install a cronjob running this script daily. - - - -MANUAL CONFIGURATION -==================== - -First of all, rename the files config/*.inc.php.dist to config/*.inc.php. -You can then change these files according to your environment and your needs. -Details about the config parameters can be found in the config files. -See http://trac.roundcube.net/wiki/Howto_Install for even more guidance. - -You can also modify the default .htaccess file. This is necessary to -increase the allowed size of file attachments, for example: - php_value upload_max_filesize 2M - - -UPGRADING -========= - -If you already have a previous version of Roundcube installed, -please refer to the instructions in UPGRADING guide. - - -OPTIMISING -========== - -There are two forms of optimisation here, compression and caching, both aimed -at increasing an end user's experience using Roundcube Webmail. Compression -allows the static web pages to be delivered with less bandwidth. The index.php -of Roundcube Webmail already enables compression on its output. The settings -below allow compression to occur for all static files. Caching sets HTTP -response headers that enable a user's web client to understand what is static -and how to cache it. - -The caching directives used are: - * Etags - sets at tag so the client can request is the page has changed - * Cache-control - defines the age of the page and that the page is 'public' - This enables clients to cache javascript files that don't have private - information between sessions even if using HTTPS. It also allows proxies - to share the same cached page between users. - * Expires - provides another hint to increase the lifetime of static pages. - -For more information refer to RFC 2616. - -Side effects: -------------- -These directives are designed for production use. If you are using this in -a development environment you may get horribly confused if your webclient -is caching stuff that you changed on the server. Disabling the expires -parts below should save you some grief. - -If you are changing the skins, it is recommended that you copy content to -a different directory apart from 'default'. - -Apache: -------- -To enable these features in apache the following modules need to be enabled: - * mod_deflate - * mod_expires - * mod_headers - -The optimisation is already included in the .htaccess file in the top -directory of your installation. - -If you are using Apache version 2.2.9 and later, in the .htaccess file -change the 'append' word to 'merge' for a more correct response. Keeping -as 'append' shouldn't cause any problems though changing to merge will -eliminate the possibility of duplicate 'public' headers in Cache-control. - -Lighttpd: ---------- -With Lightty the addition of Expire: tags by mod_expire is incompatible with -the addition of "Cache-control: public". Using Cache-control 'public' is -used below as it is assumed to give a better caching result. - -Enable modules in server.modules: - "mod_setenv" - "mod_compress" - -Mod_compress is a server side cache of compressed files to improve its performance. - -$HTTP["host"] == "www.example.com" { - - static-file.etags = "enable" - # http://redmine.lighttpd.net/projects/lighttpd/wiki/Etag.use-mtimeDetails - etag.use-mtime = "enable" - - # http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModSetEnv - $HTTP["url"] =~ "^/roundcubemail/(plugins|skins|program)" { - setenv.add-response-header = ( "Cache-Control" => "public, max-age=2592000") - } - - # http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModCompress - # set compress.cache-dir to somewhere outside the docroot. - compress.cache-dir = var.statedir + "/cache/compress" - - compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml", "image/gif", "image/png") -} - - diff --git a/SQL/mysql.update.sql b/SQL/mysql.update.sql index 2af0a47..aaab43f 100644 --- a/SQL/mysql.update.sql +++ b/SQL/mysql.update.sql @@ -131,3 +131,5 @@ ALTER TABLE `users` ADD UNIQUE `username` (`username`, `mail_host`); ALTER TABLE `contacts` MODIFY `email` varchar(255) NOT NULL; +TRUNCATE TABLE `messages`; + diff --git a/SQL/postgres.update.sql b/SQL/postgres.update.sql index 444caf6..2f4498d 100644 --- a/SQL/postgres.update.sql +++ b/SQL/postgres.update.sql @@ -88,3 +88,4 @@ DROP INDEX users_username_id_idx; ALTER TABLE users ADD UNIQUE (username, mail_host); ALTER TABLE contacts ALTER email TYPE varchar(255); +TRUNCATE messages; diff --git a/SQL/sqlite.update.sql b/SQL/sqlite.update.sql index 3286939..6f2acf9 100644 --- a/SQL/sqlite.update.sql +++ b/SQL/sqlite.update.sql @@ -180,3 +180,5 @@ INSERT INTO contacts (contact_id, user_id, changed, del, name, email, firstname, CREATE INDEX ix_contacts_user_id ON contacts(user_id, email); DROP TABLE contacts_tmp; +DELETE FROM messages; + diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist index 144ca77..ea0092b 100644 --- a/config/main.inc.php.dist +++ b/config/main.inc.php.dist @@ -213,6 +213,9 @@ $rcmail_config['ip_check'] = false; // There have been problems reported with this feature. $rcmail_config['double_auth'] = false; +// check referer of incoming requests +$rcmail_config['referer_check'] = false; + // 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. diff --git a/index.php b/index.php index 57bcc64..883faa6 100644 --- a/index.php +++ b/index.php @@ -2,9 +2,9 @@ /* +-------------------------------------------------------------------------+ | Roundcube Webmail IMAP Client | - | Version 0.5 | + | Version 0.5.1 | | | - | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland | + | Copyright (C) 2005-2011, Roundcube Dev. - Switzerland | | | | This program is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License version 2 | @@ -23,7 +23,7 @@ | Author: Thomas Bruederli | +-------------------------------------------------------------------------+ - $Id: index.php 4408 2011-01-12 15:54:35Z thomasb $ + $Id: index.php 4509 2011-02-09 10:51:50Z thomasb $ */ @@ -75,6 +75,8 @@ $RCMAIL->action = $startup['action']; // try to log in if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { + $request_valid = $_SESSION['temp'] && $RCMAIL->check_request(RCUBE_INPUT_POST, 'login'); + // purge the session in case of new login when a session already exists $RCMAIL->kill_session(); @@ -84,13 +86,14 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { 'pass' => get_input_value('_pass', RCUBE_INPUT_POST, true, $RCMAIL->config->get('password_charset', 'ISO-8859-1')), 'cookiecheck' => true, + 'valid' => $request_valid, )); // check if client supports cookies if ($auth['cookiecheck'] && empty($_COOKIE)) { $OUTPUT->show_message("cookiesdisabled", 'warning'); } - else if ($_SESSION['temp'] && !$auth['abort'] && + else if ($auth['valid'] && !$auth['abort'] && !empty($auth['host']) && !empty($auth['user']) && $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) { // create new session ID @@ -104,12 +107,17 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { rcmail_log_login(); // restore original request parameters - $query = array('_task' => 'mail'); - if ($url = get_input_value('_url', RCUBE_INPUT_POST)) + $query = array(); + if ($url = get_input_value('_url', RCUBE_INPUT_POST)) { parse_str($url, $query); + + // prevent endless looping on login page + if ($query['_task'] == 'login') + unset($query['_task']); + } // allow plugins to control the redirect url after login success - $redir = $RCMAIL->plugins->exec_hook('login_after', $query); + $redir = $RCMAIL->plugins->exec_hook('login_after', $query + array('_task' => 'mail')); unset($redir['abort']); // send redirect @@ -118,15 +126,15 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { else { $error_code = is_object($IMAP) ? $IMAP->get_error_code() : -1; - $OUTPUT->show_message($error_code < -1 ? 'imaperror' : 'loginfailed', 'warning'); + $OUTPUT->show_message($error_code < -1 ? 'imaperror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning'); $RCMAIL->plugins->exec_hook('login_failed', array( 'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user'])); $RCMAIL->kill_session(); } } -// end session -else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id'])) { +// end session (after optional referer check) +else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id']) && (!$RCMAIL->config->get('referer_check') || rcube_check_referer())) { $userdata = array('user' => $_SESSION['username'], 'host' => $_SESSION['imap_host'], 'lang' => $RCMAIL->user->language); $OUTPUT->show_message('loggedout'); $RCMAIL->logout_actions(); @@ -162,7 +170,7 @@ if (empty($RCMAIL->user->ID)) { ); } - $OUTPUT->set_env('task', 'login'); + $RCMAIL->set_task('login'); $OUTPUT->send('login'); } // CSRF prevention @@ -182,6 +190,14 @@ else { $OUTPUT->show_message('invalidrequest', 'error'); $OUTPUT->send($RCMAIL->task); } + + // check referer if configured + if (!$request_check_whitelist[$RCMAIL->action] && $RCMAIL->config->get('referer_check') && !rcube_check_referer()) { + raise_error(array( + 'code' => 403, + 'type' => 'php', + 'message' => "Referer check failed"), true, true); + } } // handle special actions diff --git a/installer/check.php b/installer/check.php index 7fa4d95..0ba5f58 100644 --- a/installer/check.php +++ b/installer/check.php @@ -68,7 +68,7 @@ echo 'imap) - $this->imap_init(); - - if ($_SESSION['imap_host'] && !$this->imap->conn->connected()) { - if (!$this->imap->connect($_SESSION['imap_host'], $_SESSION['username'], $this->decrypt($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl'])) { - if ($this->output) - $this->output->show_message($this->imap->get_error_code() == -1 ? 'imaperror' : 'sessionerror', 'error'); - } - else { - $this->set_imap_prop(); - return $this->imap->conn; - } - } - - return false; - } - - - /** - * Create session object and start the session. - */ - public function session_init() - { - // session started (Installer?) - if (session_id()) - return; - - $lifetime = $this->config->get('session_lifetime', 0) * 60; - - // set session domain - if ($domain = $this->config->get('session_domain')) { - ini_set('session.cookie_domain', $domain); - } - // set session garbage collecting time according to session_lifetime - if ($lifetime) { - ini_set('session.gc_maxlifetime', $lifetime * 2); - } - - ini_set('session.cookie_secure', rcube_https_check()); - ini_set('session.name', 'roundcube_sessid'); - ini_set('session.use_cookies', 1); - ini_set('session.use_only_cookies', 1); - ini_set('session.serialize_handler', 'php'); - - // use database for storing session data - $this->session = new rcube_session($this->get_dbh(), $lifetime); - - $this->session->register_gc_handler('rcmail_temp_gc'); - if ($this->config->get('enable_caching')) - $this->session->register_gc_handler('rcmail_cache_gc'); - - // start PHP session (if not in CLI mode) - if ($_SERVER['REMOTE_ADDR']) - session_start(); - - // set initial session vars - if (!isset($_SESSION['auth_time'])) { - $_SESSION['auth_time'] = time(); - $_SESSION['temp'] = true; - } - } - - - /** - * Configure session object internals - */ - public function session_configure() - { - if (!$this->session) - return; - - $lifetime = $this->config->get('session_lifetime', 0) * 60; - - // set keep-alive/check-recent interval - if ($keep_alive = $this->config->get('keep_alive')) { - // be sure that it's less than session lifetime - if ($lifetime) - $keep_alive = min($keep_alive, $lifetime - 30); - $keep_alive = max(60, $keep_alive); - $this->session->set_keep_alive($keep_alive); - } - } - - - /** - * Perfom login to the IMAP server and to the webmail service. - * This will also create a new user entry if auto_create_user is configured. - * - * @param string IMAP user name - * @param string IMAP password - * @param string IMAP host - * @return boolean True on success, False on failure - */ - function login($username, $pass, $host=NULL) - { - $user = NULL; - $config = $this->config->all(); - - if (!$host) - $host = $config['default_host']; - - // Validate that selected host is in the list of configured hosts - if (is_array($config['default_host'])) { - $allowed = false; - foreach ($config['default_host'] as $key => $host_allowed) { - if (!is_numeric($key)) - $host_allowed = $key; - if ($host == $host_allowed) { - $allowed = true; - break; - } - } - if (!$allowed) - return false; - } - else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host'])) - return false; - - // parse $host URL - $a_host = parse_url($host); - if ($a_host['host']) { - $host = $a_host['host']; - $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; - if (!empty($a_host['port'])) - $imap_port = $a_host['port']; - else if ($imap_ssl && $imap_ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143)) - $imap_port = 993; - } - - $imap_port = $imap_port ? $imap_port : $config['default_port']; - - /* Modify username with domain if required - Inspired by Marco - */ - // Check if we need to add domain - if (!empty($config['username_domain']) && strpos($username, '@') === false) { - if (is_array($config['username_domain']) && isset($config['username_domain'][$host])) - $username .= '@'.rcube_parse_host($config['username_domain'][$host]); - else if (is_string($config['username_domain'])) - $username .= '@'.rcube_parse_host($config['username_domain']); - } - - // Convert username to lowercase. If IMAP backend - // is case-insensitive we need to store always the same username (#1487113) - if ($config['login_lc']) { - $username = mb_strtolower($username); - } - - // try to resolve email address from virtuser table - if (strpos($username, '@') && ($virtuser = rcube_user::email2user($username))) { - $username = $virtuser; - } - - // Here we need IDNA ASCII - // Only rcube_contacts class is using domain names in Unicode - $host = idn_to_ascii($host); - if (strpos($username, '@')) { - // lowercase domain name - list($local, $domain) = explode('@', $username); - $username = $local . '@' . mb_strtolower($domain); - $username = idn_to_ascii($username); - } - - // user already registered -> overwrite username - if ($user = rcube_user::query($username, $host)) - $username = $user->data['username']; - - if (!$this->imap) - $this->imap_init(); - - // try IMAP login - if (!($imap_login = $this->imap->connect($host, $username, $pass, $imap_port, $imap_ssl))) { - // try with lowercase - $username_lc = mb_strtolower($username); - if ($username_lc != $username) { - // try to find user record again -> overwrite username - if (!$user && ($user = rcube_user::query($username_lc, $host))) - $username_lc = $user->data['username']; - - if ($imap_login = $this->imap->connect($host, $username_lc, $pass, $imap_port, $imap_ssl)) - $username = $username_lc; - } - } - - // exit if IMAP login failed - if (!$imap_login) - return false; - - $this->set_imap_prop(); - - // user already registered -> update user's record - if (is_object($user)) { - // create default folders on first login - if (!$user->data['last_login'] && $config['create_default_folders']) - $this->imap->create_default_folders(); - $user->touch(); - } - // create new system user - else if ($config['auto_create_user']) { - if ($created = rcube_user::create($username, $host)) { - $user = $created; - // create default folders on first login - if ($config['create_default_folders']) - $this->imap->create_default_folders(); - } - else { - raise_error(array( - 'code' => 600, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Failed to create a user record. Maybe aborted by a plugin?" - ), true, false); - } - } - else { - raise_error(array( - 'code' => 600, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Acces denied for new user $username. 'auto_create_user' is disabled" - ), true, false); - } - - // login succeeded - if (is_object($user) && $user->ID) { - $this->set_user($user); - - // set session vars - $_SESSION['user_id'] = $user->ID; - $_SESSION['username'] = $user->data['username']; - $_SESSION['imap_host'] = $host; - $_SESSION['imap_port'] = $imap_port; - $_SESSION['imap_ssl'] = $imap_ssl; - $_SESSION['password'] = $this->encrypt($pass); - $_SESSION['login_time'] = mktime(); - - if (isset($_REQUEST['_timezone']) && $_REQUEST['_timezone'] != '_default_') - $_SESSION['timezone'] = floatval($_REQUEST['_timezone']); - - // force reloading complete list of subscribed mailboxes - $this->imap->clear_cache('mailboxes'); - - return true; - } - - return false; - } - - - /** - * Set root dir and last stored mailbox - * This must be done AFTER connecting to the server! - */ - public function set_imap_prop() - { - $this->imap->set_charset($this->config->get('default_charset', RCMAIL_CHARSET)); - - if ($default_folders = $this->config->get('default_imap_folders')) { - $this->imap->set_default_mailboxes($default_folders); - } - if (isset($_SESSION['mbox'])) { - $this->imap->set_mailbox($_SESSION['mbox']); - } - if (isset($_SESSION['page'])) { - $this->imap->set_page($_SESSION['page']); - } - } - - - /** - * Auto-select IMAP host based on the posted login information - * - * @return string Selected IMAP host - */ - public function autoselect_host() - { - $default_host = $this->config->get('default_host'); - $host = null; - - if (is_array($default_host)) { - $post_host = get_input_value('_host', RCUBE_INPUT_POST); - - // direct match in default_host array - if ($default_host[$post_host] || in_array($post_host, array_values($default_host))) { - $host = $post_host; - } - - // try to select host by mail domain - list($user, $domain) = explode('@', get_input_value('_user', RCUBE_INPUT_POST)); - if (!empty($domain)) { - foreach ($default_host as $imap_host => $mail_domains) { - if (is_array($mail_domains) && in_array($domain, $mail_domains)) { - $host = $imap_host; - break; - } - } - } - - // take the first entry if $host is still an array - if (empty($host)) { - $host = array_shift($default_host); - } - } - else if (empty($default_host)) { - $host = get_input_value('_host', RCUBE_INPUT_POST); - } - else - $host = rcube_parse_host($default_host); - - return $host; - } - - - /** - * Get localized text in the desired language - * - * @param mixed Named parameters array or label name - * @return string Localized text - */ - public function gettext($attrib, $domain=null) - { - // load localization files if not done yet - if (empty($this->texts)) - $this->load_language(); - - // extract attributes - if (is_string($attrib)) - $attrib = array('name' => $attrib); - - $nr = is_numeric($attrib['nr']) ? $attrib['nr'] : 1; - $name = $attrib['name'] ? $attrib['name'] : ''; - - // check for text with domain - if ($domain && ($text_item = $this->texts[$domain.'.'.$name])) - ; - // text does not exist - else if (!($text_item = $this->texts[$name])) { - return "[$name]"; - } - - // make text item array - $a_text_item = is_array($text_item) ? $text_item : array('single' => $text_item); - - // decide which text to use - if ($nr == 1) { - $text = $a_text_item['single']; - } - else if ($nr > 0) { - $text = $a_text_item['multiple']; - } - else if ($nr == 0) { - if ($a_text_item['none']) - $text = $a_text_item['none']; - else if ($a_text_item['single']) - $text = $a_text_item['single']; - else if ($a_text_item['multiple']) - $text = $a_text_item['multiple']; - } - - // default text is single - if ($text == '') { - $text = $a_text_item['single']; - } - - // replace vars in text - if (is_array($attrib['vars'])) { - foreach ($attrib['vars'] as $var_key => $var_value) - $text = str_replace($var_key[0]!='$' ? '$'.$var_key : $var_key, $var_value, $text); - } - - // format output - if (($attrib['uppercase'] && strtolower($attrib['uppercase']=='first')) || $attrib['ucfirst']) - return ucfirst($text); - else if ($attrib['uppercase']) - return mb_strtoupper($text); - else if ($attrib['lowercase']) - return mb_strtolower($text); - - return $text; - } - - - /** - * Load a localization package - * - * @param string Language ID - */ - public function load_language($lang = null, $add = array()) - { - $lang = $this->language_prop(($lang ? $lang : $_SESSION['language'])); - - // load localized texts - if (empty($this->texts) || $lang != $_SESSION['language']) { - $this->texts = array(); - - // handle empty lines after closing PHP tag in localization files - ob_start(); - - // get english labels (these should be complete) - @include(INSTALL_PATH . 'program/localization/en_US/labels.inc'); - @include(INSTALL_PATH . 'program/localization/en_US/messages.inc'); - - if (is_array($labels)) - $this->texts = $labels; - if (is_array($messages)) - $this->texts = array_merge($this->texts, $messages); - - // include user language files - if ($lang != 'en' && is_dir(INSTALL_PATH . 'program/localization/' . $lang)) { - include_once(INSTALL_PATH . 'program/localization/' . $lang . '/labels.inc'); - include_once(INSTALL_PATH . 'program/localization/' . $lang . '/messages.inc'); - - if (is_array($labels)) - $this->texts = array_merge($this->texts, $labels); - if (is_array($messages)) - $this->texts = array_merge($this->texts, $messages); - } - - ob_end_clean(); - - $_SESSION['language'] = $lang; - } - - // append additional texts (from plugin) - if (is_array($add) && !empty($add)) - $this->texts += $add; - } - - - /** - * Read directory program/localization and return a list of available languages - * - * @return array List of available localizations - */ - public function list_languages() - { - static $sa_languages = array(); - - if (!sizeof($sa_languages)) { - @include(INSTALL_PATH . 'program/localization/index.inc'); - - if ($dh = @opendir(INSTALL_PATH . 'program/localization')) { - while (($name = readdir($dh)) !== false) { - if ($name[0] == '.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name)) - continue; - - if ($label = $rcube_languages[$name]) - $sa_languages[$name] = $label; - } - closedir($dh); - } - } - - return $sa_languages; - } - - - /** - * Check the auth hash sent by the client against the local session credentials - * - * @return boolean True if valid, False if not - */ - function authenticate_session() - { - // advanced session authentication - if ($this->config->get('double_auth')) { - $now = time(); - $valid = ($_COOKIE['sessauth'] == $this->get_auth_hash(session_id(), $_SESSION['auth_time']) || - $_COOKIE['sessauth'] == $this->get_auth_hash(session_id(), $_SESSION['last_auth'])); - - // renew auth cookie every 5 minutes (only for GET requests) - if (!$valid || ($_SERVER['REQUEST_METHOD']!='POST' && $now - $_SESSION['auth_time'] > 300)) { - $_SESSION['last_auth'] = $_SESSION['auth_time']; - $_SESSION['auth_time'] = $now; - rcmail::setcookie('sessauth', $this->get_auth_hash(session_id(), $now), 0); - } - } - else { - $valid = $this->config->get('ip_check') ? $_SERVER['REMOTE_ADDR'] == $this->session->get_ip() : true; - } - - // check session filetime - $lifetime = $this->config->get('session_lifetime'); - $sess_ts = $this->session->get_ts(); - if (!empty($lifetime) && !empty($sess_ts) && $sess_ts + $lifetime*60 < time()) { - $valid = false; - } - - return $valid; - } - - - /** - * Destroy session data and remove cookie - */ - public function kill_session() - { - $this->plugins->exec_hook('session_destroy'); - - $this->session->remove(); - $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true); - rcmail::setcookie('sessauth', '-del-', time() - 60); - $this->user->reset(); - } - - - /** - * Do server side actions on logout - */ - public function logout_actions() - { - $config = $this->config->all(); - - // on logout action we're not connected to imap server - if (($config['logout_purge'] && !empty($config['trash_mbox'])) || $config['logout_expunge']) { - if (!$this->authenticate_session()) - return; - - $this->imap_connect(); - } - - if ($config['logout_purge'] && !empty($config['trash_mbox'])) { - $this->imap->clear_mailbox($config['trash_mbox']); - } - - if ($config['logout_expunge']) { - $this->imap->expunge('INBOX'); - } - } - - - /** - * Function to be executed in script shutdown - * Registered with register_shutdown_function() - */ - public function shutdown() - { - if (is_object($this->imap)) - $this->imap->close(); - - if (is_object($this->smtp)) - $this->smtp->disconnect(); - - foreach ($this->books as $book) - if (is_object($book)) - $book->close(); - - // before closing the database connection, write session data - if ($_SERVER['REMOTE_ADDR']) - session_write_close(); - - // write performance stats to logs/console - if ($this->config->get('devel_mode')) { - if (function_exists('memory_get_usage')) - $mem = show_bytes(memory_get_usage()); - if (function_exists('memory_get_peak_usage')) - $mem .= '/'.show_bytes(memory_get_peak_usage()); - - $log = $this->task . ($this->action ? '/'.$this->action : '') . ($mem ? " [$mem]" : ''); - if (defined('RCMAIL_START')) - rcube_print_time(RCMAIL_START, $log); - else - console($log); - } - } - - - /** - * Generate a unique token to be used in a form request - * - * @return string The request token - */ - public function get_request_token() - { - $key = $this->task; - - if (!$_SESSION['request_tokens'][$key]) - $_SESSION['request_tokens'][$key] = md5(uniqid($key . mt_rand(), true)); - - return $_SESSION['request_tokens'][$key]; - } - - - /** - * Check if the current request contains a valid token - * - * @param int Request method - * @return boolean True if request token is valid false if not - */ - public function check_request($mode = RCUBE_INPUT_POST) - { - $token = get_input_value('_token', $mode); - return !empty($token) && $_SESSION['request_tokens'][$this->task] == $token; - } - - - /** - * Create unique authorization hash - * - * @param string Session ID - * @param int Timestamp - * @return string The generated auth hash - */ - private function get_auth_hash($sess_id, $ts) - { - $auth_string = sprintf('rcmail*sess%sR%s*Chk:%s;%s', - $sess_id, - $ts, - $this->config->get('ip_check') ? $_SERVER['REMOTE_ADDR'] : '***.***.***.***', - $_SERVER['HTTP_USER_AGENT']); - - if (function_exists('sha1')) - return sha1($auth_string); - else - return md5($auth_string); - } - - - /** - * Encrypt using 3DES - * - * @param string $clear clear text input - * @param string $key encryption key to retrieve from the configuration, defaults to 'des_key' - * @param boolean $base64 whether or not to base64_encode() the result before returning - * - * @return string encrypted text - */ - public function encrypt($clear, $key = 'des_key', $base64 = true) - { - if (!$clear) - return ''; - /*- - * Add a single canary byte to the end of the clear text, which - * will help find out how much of padding will need to be removed - * upon decryption; see http://php.net/mcrypt_generic#68082 - */ - $clear = pack("a*H2", $clear, "80"); - - if (function_exists('mcrypt_module_open') && - ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, ""))) - { - $iv = $this->create_iv(mcrypt_enc_get_iv_size($td)); - mcrypt_generic_init($td, $this->config->get_crypto_key($key), $iv); - $cipher = $iv . mcrypt_generic($td, $clear); - mcrypt_generic_deinit($td); - mcrypt_module_close($td); - } - else { - @include_once('lib/des.inc'); - - if (function_exists('des')) { - $des_iv_size = 8; - $iv = $this->create_iv($des_iv_size); - $cipher = $iv . des($this->config->get_crypto_key($key), $clear, 1, 1, $iv); - } - else { - raise_error(array( - 'code' => 500, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Could not perform encryption; make sure Mcrypt is installed or lib/des.inc is available" - ), true, true); - } - } - - return $base64 ? base64_encode($cipher) : $cipher; - } - - /** - * Decrypt 3DES-encrypted string - * - * @param string $cipher encrypted text - * @param string $key encryption key to retrieve from the configuration, defaults to 'des_key' - * @param boolean $base64 whether or not input is base64-encoded - * - * @return string decrypted text - */ - public function decrypt($cipher, $key = 'des_key', $base64 = true) - { - if (!$cipher) - return ''; - - $cipher = $base64 ? base64_decode($cipher) : $cipher; - - if (function_exists('mcrypt_module_open') && - ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, ""))) - { - $iv_size = mcrypt_enc_get_iv_size($td); - $iv = substr($cipher, 0, $iv_size); - - // session corruption? (#1485970) - if (strlen($iv) < $iv_size) - return ''; - - $cipher = substr($cipher, $iv_size); - mcrypt_generic_init($td, $this->config->get_crypto_key($key), $iv); - $clear = mdecrypt_generic($td, $cipher); - mcrypt_generic_deinit($td); - mcrypt_module_close($td); - } - else { - @include_once('lib/des.inc'); - - if (function_exists('des')) { - $des_iv_size = 8; - $iv = substr($cipher, 0, $des_iv_size); - $cipher = substr($cipher, $des_iv_size); - $clear = des($this->config->get_crypto_key($key), $cipher, 0, 1, $iv); - } - else { - raise_error(array( - 'code' => 500, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Could not perform decryption; make sure Mcrypt is installed or lib/des.inc is available" - ), true, true); - } - } - - /*- - * Trim PHP's padding and the canary byte; see note in - * rcmail::encrypt() and http://php.net/mcrypt_generic#68082 - */ - $clear = substr(rtrim($clear, "\0"), 0, -1); - - return $clear; - } - - /** - * Generates encryption initialization vector (IV) - * - * @param int Vector size - * @return string Vector string - */ - private function create_iv($size) - { - // mcrypt_create_iv() can be slow when system lacks entrophy - // we'll generate IV vector manually - $iv = ''; - for ($i = 0; $i < $size; $i++) - $iv .= chr(mt_rand(0, 255)); - return $iv; - } - - /** - * Build a valid URL to this instance of Roundcube - * - * @param mixed Either a string with the action or url parameters as key-value pairs - * @return string Valid application URL - */ - public function url($p) - { - if (!is_array($p)) - $p = array('_action' => @func_get_arg(0)); - - $task = $p['_task'] ? $p['_task'] : ($p['task'] ? $p['task'] : $this->task); - $p['_task'] = $task; - unset($p['task']); - - $url = './'; - $delm = '?'; - foreach (array_reverse($p) as $key => $val) - { - if (!empty($val)) { - $par = $key[0] == '_' ? $key : '_'.$key; - $url .= $delm.urlencode($par).'='.urlencode($val); - $delm = '&'; - } - } - return $url; - } - - - /** - * Helper method to set a cookie with the current path and host settings - * - * @param string Cookie name - * @param string Cookie value - * @param string Expiration time - */ - public static function setcookie($name, $value, $exp = 0) - { - if (headers_sent()) - return; - - $cookie = session_get_cookie_params(); - - setcookie($name, $value, $exp, $cookie['path'], $cookie['domain'], - rcube_https_check(), true); - } -} - - diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php index 66d7b67..19e1be3 100644 --- a/program/include/rcube_config.php +++ b/program/include/rcube_config.php @@ -15,7 +15,7 @@ | Author: Thomas Bruederli | +-----------------------------------------------------------------------+ - $Id: rcube_config.php 4363 2010-12-22 19:17:47Z alec $ + $Id: rcube_config.php 4509 2011-02-09 10:51:50Z thomasb $ */ @@ -287,7 +287,7 @@ class rcube_config $domain = rcube_parse_host($this->prop['mail_domain']); if ($encode) - $domain = idn_to_ascii($domain); + $domain = rcube_idn_to_ascii($domain); return $domain; } diff --git a/program/include/rcube_html_page.php b/program/include/rcube_html_page.php index a3cec3f..e279f1f 100644 --- a/program/include/rcube_html_page.php +++ b/program/include/rcube_html_page.php @@ -15,7 +15,7 @@ | Author: Thomas Bruederli | +-----------------------------------------------------------------------+ - $Id: rcube_html_page.php 4015 2010-09-29 16:47:05Z alec $ + $Id: rcube_html_page.php 4469 2011-01-29 14:55:12Z thomasb $ */ @@ -28,11 +28,13 @@ class rcube_html_page { protected $scripts_path = ''; protected $script_files = array(); + protected $css_files = array(); protected $scripts = array(); protected $charset = RCMAIL_CHARSET; protected $script_tag_file = "\n"; protected $script_tag = ""; + protected $link_css_file = "\n"; protected $default_template = "\n\n\n"; protected $title = ''; @@ -61,6 +63,9 @@ class rcube_html_page if (in_array($file, $sa_files)) { return; } + + $sa_files[] = $file; + if (!is_array($this->script_files[$position])) { $this->script_files[$position] = array(); } @@ -82,6 +87,16 @@ class rcube_html_page } } + /** + * Link an external css file + * + * @param string File URL + */ + public function include_css($file) + { + $this->css_files[] = $file; + } + /** * Add HTML code to the page header * @@ -163,52 +178,53 @@ class rcube_html_page } // replace specialchars in content - $__page_title = Q($this->title, 'show', FALSE); - $__page_header = $__page_body = $__page_footer = ''; + $page_title = Q($this->title, 'show', FALSE); + $page_header = ''; + $page_footer = ''; // include meta tag with charset if (!empty($this->charset)) { if (!headers_sent()) { header('Content-Type: text/html; charset=' . $this->charset); } - $__page_header = 'charset . '" />'."\n"; + $page_header = 'charset . '" />'."\n"; } // definition of the code to be placed in the document header and footer if (is_array($this->script_files['head'])) { foreach ($this->script_files['head'] as $file) { - $__page_header .= sprintf($this->script_tag_file, $file); + $page_header .= sprintf($this->script_tag_file, $file); } } $head_script = $this->scripts['head_top'] . $this->scripts['head']; if (!empty($head_script)) { - $__page_header .= sprintf($this->script_tag, $head_script); + $page_header .= sprintf($this->script_tag, $head_script); } if (!empty($this->header)) { - $__page_header .= $this->header; + $page_header .= $this->header; } if (is_array($this->script_files['foot'])) { foreach ($this->script_files['foot'] as $file) { - $__page_footer .= sprintf($this->script_tag_file, $file); + $page_footer .= sprintf($this->script_tag_file, $file); } } if (!empty($this->scripts['foot'])) { - $__page_footer .= sprintf($this->script_tag, $this->scripts['foot']); + $page_footer .= sprintf($this->script_tag, $this->scripts['foot']); } if (!empty($this->footer)) { - $__page_footer .= $this->footer; + $page_footer .= $this->footer; } // find page header if ($hpos = stripos($output, '')) { - $__page_header .= "\n"; + $page_header .= "\n"; } else { if (!is_numeric($hpos)) { @@ -220,49 +236,43 @@ class rcube_html_page } $hpos++; } - $__page_header = "\n$__page_title\n$__page_header\n\n"; + $page_header = "\n$page_title\n$page_header\n\n"; } // add page hader if ($hpos) { - $output = substr($output,0,$hpos) . $__page_header . substr($output,$hpos,strlen($output)); + $output = substr($output,0,$hpos) . $page_header . substr($output,$hpos,strlen($output)); } else { - $output = $__page_header . $output; + $output = $page_header . $output; } - // find page body - if ($bpos = stripos($output, '')+7; - } - - // add page body - if ($bpos && $__page_body) { - $output = substr($output,0,$bpos) . "\n$__page_body\n" . substr($output,$bpos,strlen($output)); - } - - // find and add page footer + // add page footer if (($fpos = strripos($output, '')) || ($fpos = strripos($output, ''))) { - $output = substr($output, 0, $fpos) . "$__page_footer\n" . substr($output, $fpos); + $output = substr($output, 0, $fpos) . "$page_footer\n" . substr($output, $fpos); } else { - $output .= "\n".$__page_footer; + $output .= "\n".$page_footer; } - // reset those global vars - $__page_header = $__page_footer = ''; + // add css files in head, before scripts, for speed up with parallel downloads + if (!empty($this->css_files) && + (($pos = stripos($output, '