From 1038d554e41b4007461a0c74a89625fd03107f7f Mon Sep 17 00:00:00 2001 From: svncommit <devs@roundcube.net> Date: Thu, 20 Oct 2005 13:33:39 -0400 Subject: [PATCH] --- program/include/main.inc | 119 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 95 insertions(+), 24 deletions(-) diff --git a/program/include/main.inc b/program/include/main.inc index 7173917..b4b2aa9 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -30,7 +30,7 @@ // check client $BROWSER = rcube_browser(); - + // load config file include_once('config/main.inc.php'); $CONFIG = is_array($rcmail_config) ? $rcmail_config : array(); @@ -54,10 +54,13 @@ // prepare DB connection + require_once('include/rcube_'.(empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']).'.inc'); + $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr']); + $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql'; // we can use the database for storing session data - if (is_object($DB)) + if (is_object($DB) && $DB->db_provider!='sqlite') include_once('include/session.inc'); @@ -219,7 +222,7 @@ $javascript = "var $JS_OBJECT_NAME = new rcube_webmail();\n"; $javascript .= "$JS_OBJECT_NAME.set_env('comm_path', '$COMM_PATH');\n"; - if ($_GET['_framed'] || $_POST['_framed']) + if (!empty($GLOBALS['_framed'])) $javascript .= "$JS_OBJECT_NAME.set_env('framed', true);\n"; $OUTPUT->add_script($javascript); @@ -232,26 +235,43 @@ function rcmail_login($user, $pass, $host=NULL) { global $CONFIG, $IMAP, $DB, $sess_user_lang; + $user_id = NULL; if (!$host) $host = $CONFIG['default_host']; - // exit if IMAP login failed - if (!($imap_login = $IMAP->connect($host, $user, $pass))) - return FALSE; - // query if user already registered - $sql_result = $DB->query(sprintf("SELECT user_id, language, preferences - FROM %s - WHERE username='%s' AND mail_host='%s'", + $sql_result = $DB->query(sprintf("SELECT user_id, username, language, preferences + FROM %s + WHERE mail_host='%s' AND (username='%s' OR alias='%s')", get_table_name('users'), - $user, $host)); + addslashes($host), + addslashes($user), + addslashes($user))); - // user already registered + // user already registered -> overwrite username if ($sql_arr = $DB->fetch_assoc($sql_result)) { $user_id = $sql_arr['user_id']; - + $user = $sql_arr['username']; + } + + // 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'))) ? TRUE : FALSE; + $imap_port = isset($a_host['post']) ? $a_host['post'] : ($imap_ssl ? 993 : $CONFIG['default_port']); + } + + // exit if IMAP login failed + if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) + return FALSE; + + // user already registered + if ($user_id && !empty($sql_arr)) + { // get user prefs if (strlen($sql_arr['preferences'])) { @@ -303,7 +323,8 @@ (created, last_login, username, mail_host) VALUES (NOW(), NOW(), '%s', '%s')", get_table_name('users'), - $user, $host)); + addslashes($user), + addslashes($host))); if ($user_id = $DB->insert_id()) { @@ -316,8 +337,8 @@ VALUES (%d, '1', '%s', '%s')", get_table_name('identities'), $user_id, - $user_name, - $user_email)); + addslashes($user_name), + addslashes($user_email))); // get existing mailboxes $a_mailboxes = $IMAP->list_mailboxes(); @@ -330,6 +351,14 @@ if ($CONFIG['trash_mbox'] && !in_array_nocase($CONFIG['trash_mbox'], $a_mailboxes)) $IMAP->create_mailbox($CONFIG['trash_mbox'], TRUE); } + else + { + raise_error(array('code' => 500, + 'type' => 'php', + 'line' => __LINE__, + 'file' => __FILE__, + 'message' => "Failed to create new user"), TRUE, FALSE); + } return $user_id; } @@ -339,7 +368,7 @@ { global $OUTPUT, $JS_OBJECT_NAME, $REMOTE_REQUEST; - $framed = ($_GET['framed'] || $_POST['_framed']); + $framed = $GLOBALS['_framed']; $command = sprintf("display_message('%s', '%s');", addslashes(rep_specialchars_output(rcube_label($message))), $type); @@ -359,8 +388,13 @@ function console($msg, $type=1) { - print $msg; - print "\n<hr>\n"; + if ($GLOBALS['REMOTE_REQUEST']) + print "// $msg\n"; + else + { + print $msg; + print "\n<hr>\n"; + } } @@ -390,6 +424,33 @@ exit; } + +// read directory program/localization/ and return a list of available languages +function rcube_list_languages() + { + global $CONFIG, $INSTALL_PATH; + static $sa_languages = array(); + + if (!sizeof($sa_languages)) + { + @include_once($INSTLL_PATH.'program/localization/index.inc'); + + if ($dh = @opendir($INSTLL_PATH.'program/localization')) + { + while (($name = readdir($dh)) !== false) + { + if ($name{0}=='.' || !is_dir($INSTLL_PATH.'program/localization/'.$name)) + continue; + + if ($label = $rcube_languages[$name]) + $sa_languages[$name] = $label ? $label : $name; + } + closedir($dh); + } + } + + return $sa_languages; + } @@ -639,7 +700,7 @@ // create and register a button function rcube_button($attrib) { - global $CONFIG, $OUTPUT, $JS_OBJECT_NAME; + global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $BROWSER; static $sa_buttons = array(); static $s_button_count = 100; @@ -696,7 +757,14 @@ if ($attrib['alt']) $attrib['alt'] = rep_specialchars_output(rcube_label($attrib['alt'])); - + + // set title to alt attribute for IE browsers + if ($BROWSER['ie'] && $attrib['title'] && !$attrib['alt']) + { + $attrib['alt'] = $attrib['title']; + unset($attrib['title']); + } + // add empty alt attribute for XHTML compatibility if (!isset($attrib['alt'])) $attrib['alt'] = ''; @@ -788,7 +856,7 @@ $table .= "<thead><tr>\n"; foreach ($a_show_cols as $col) - $table .= '<td class="'.$col.'">' . rcube_label($col) . "</td>\n"; + $table .= '<td class="'.$col.'">' . rep_specialchars_output(rcube_label($col)) . "</td>\n"; $table .= "</tr></thead>\n<tbody>\n"; @@ -837,7 +905,7 @@ $input = new textfield($attrib); // use value from post - if ($_POST[$fname]) + if (!empty($_POST[$fname])) $value = $_POST[$fname]; $out = $input->show($value); @@ -963,7 +1031,10 @@ if (is_array($CONFIG['default_host'])) { $select_host = new select(array('name' => '_host')); - $select_host->add($CONFIG['default_host']); + + foreach ($CONFIG['default_host'] as $key => $value) + $select_host->add($value, (is_numeric($key) ? $value : $key)); + $fields['host'] = $select_host->show($_POST['_host']); } else if (!strlen($CONFIG['default_host'])) -- Gitblit v1.9.1