- Security: Fix possible cross site scripting through the right_main
[squirrelmail.git] / src / login.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * login.php -- simple login screen
5 *
35586184 6 * This a simple login screen. Some housekeeping is done to clean
7 * cookies and find language.
8 *
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
8e2ed807 14
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
86725763 19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
22require_once(SM_PATH . 'functions/strings.php');
23require_once(SM_PATH . 'config/config.php');
24require_once(SM_PATH . 'functions/i18n.php');
25require_once(SM_PATH . 'functions/plugin.php');
26require_once(SM_PATH . 'functions/constants.php');
27require_once(SM_PATH . 'functions/page_header.php');
28require_once(SM_PATH . 'functions/html.php');
a32985a5 29require_once(SM_PATH . 'functions/global.php');
ea348fd3 30require_once(SM_PATH . 'functions/imap_general.php');
a34d6890 31require_once(SM_PATH . 'functions/forms.php');
98f2ee76 32
8f6f9ba5 33/**
98f2ee76 34 * $squirrelmail_language is set by a cookie when the user selects
35 * language and logs out
36 */
5e2b6751 37set_up_language($squirrelmail_language, TRUE, TRUE);
d4e84069 38
85b454a0 39/**
40 * Find out the base URI to set cookies.
41 */
f3bc099d 42if (!function_exists('sqm_baseuri')){
86725763 43 require_once(SM_PATH . 'functions/display_messages.php');
f3bc099d 44}
45$base_uri = sqm_baseuri();
8e2ed807 46
98f2ee76 47/*
48 * In case the last session was not terminated properly, make sure
49 * we get a new one.
50 */
5250f7e7 51
69146537 52sqsession_destroy();
dd13b825 53sqsession_start();
98f2ee76 54header('Pragma: no-cache');
55
8f6f9ba5 56/**
91e0dccc 57 * This detects if the IMAP server has logins disabled, and if so,
8f6f9ba5 58 * squelches the display of the login form and puts up a message
59 * explaining the situation.
60 */
6d611a76 61if($imap_auth_mech == 'login') {
c0c5cf6a 62 /**
f8a1ed5a 63 * detect disabled login, only when imapServerAddress contains
c0c5cf6a 64 * server address and not mapping. See sqimap_get_user_server()
65 */
66 if (substr($imapServerAddress, 0, 4) != "map:") {
67 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
68 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
69 sqimap_logout($imap);
70 if ($logindisabled) {
71 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
72 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
73 if (!$use_imap_tls) {
74 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
75 }
76 $string .= _("Please contact your system administrator and report this error.");
77 error_box($string,$color);
78 exit;
6d611a76 79 }
ea348fd3 80 }
ea348fd3 81}
82
98f2ee76 83do_hook('login_cookie');
84
bca2d025 85$loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
86
98f2ee76 87/* Output the javascript onload function. */
88
d68323ff 89$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
98f2ee76 90 "<!--\n".
91 " function squirrelmail_loginpage_onload() {\n".
03ccb49b 92 " var textElements = 0;\n".
93 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
94 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
95 " textElements++;\n".
96 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
97 " document.forms[0].elements[i].focus();\n".
98 " break;\n".
99 " }\n".
100 " }\n".
101 " }\n".
98f2ee76 102 " }\n".
103 "// -->\n".
104 "</script>\n";
dfb94cac 105
106if (@file_exists($theme[$theme_default]['PATH']))
107 @include ($theme[$theme_default]['PATH']);
108
832dc1e2 109if (! isset($color) || ! is_array($color)) {
110 // Add default color theme, if theme loading fails
111 $color = array();
112 $color[0] = '#dcdcdc'; /* light gray TitleBar */
113 $color[1] = '#800000'; /* red */
114 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
115 $color[4] = '#ffffff'; /* white Normal Background */
116 $color[7] = '#0000cc'; /* blue Links */
117 $color[8] = '#000000'; /* black Normal text */
118}
119
98f2ee76 120displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
121
2e394e36 122echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
ae958cd3 123 "\n" . '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value=\'' . SMPREF_JS_ON .'\';">' . "\n";
98f2ee76 124
0fce910a 125$username_form_name = 'login_username';
126$password_form_name = 'secretkey';
98f2ee76 127do_hook('login_top');
128
78b2428e 129/* If they don't have a logo, don't bother.. */
130if (isset($org_logo) && $org_logo) {
131 /* Display width and height like good little people */
132 $width_and_height = '';
133 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
134 $org_logo_width>0) {
135 $width_and_height = " width=\"$org_logo_width\"";
136 }
137 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
138 $org_logo_height>0) {
139 $width_and_height .= " height=\"$org_logo_height\"";
140 }
98f2ee76 141}
3fde693b 142
c67e4479 143if(sqgetGlobalVar('mailto', $mailto)) {
a34d6890 144 $rcptaddress = addHidden('mailto', $mailto);
c67e4479 145} else {
146 $rcptaddress = '';
147}
1cac3b9b 148echo html_tag( 'table',
8e2ed807 149 html_tag( 'tr',
150 html_tag( 'td',
151 '<center>'.
78b2428e 152 ( isset($org_logo) && $org_logo
153 ? '<img src="' . $org_logo . '" alt="' .
154 sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
155 ' /><br />' . "\n"
156 : '' ).
8a97a070 157 ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
8b5c49cd 158 '<small>' . _("SquirrelMail Webmail Application") . '<br />' ."\n".
8bc594ba 159 ' ' . _("By the SquirrelMail Project Team") . '<br /></small>' . "\n" ) .
8e2ed807 160 html_tag( 'table',
161 html_tag( 'tr',
162 html_tag( 'td',
163 '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
dfb94cac 164 'center', $color[0] )
8e2ed807 165 ) .
166 html_tag( 'tr',
167 html_tag( 'td', "\n" .
168 html_tag( 'table',
169 html_tag( 'tr',
170 html_tag( 'td',
171 _("Name:") ,
172 'right', '', 'width="30%"' ) .
173 html_tag( 'td',
134e4174 174 addInput($username_form_name, $loginname_value),
8e2ed807 175 'left', '', 'width="*"' )
176 ) . "\n" .
177 html_tag( 'tr',
178 html_tag( 'td',
179 _("Password:") ,
180 'right', '', 'width="30%"' ) .
181 html_tag( 'td',
134e4174 182 addPwField($password_form_name).
183 addHidden('js_autodetect_results', SMPREF_JS_OFF).
c67e4479 184 $rcptaddress .
134e4174 185 addHidden('just_logged_in', '1'),
a2b193bc 186 'left', '', 'width="*"' )
16436d92 187 ) .
188 concat_hook_function('login_form') ,
a2b193bc 189 'center', $color[4], 'border="0" width="100%"' ) ,
190 'left', $color[4] )
191 ) .
192 html_tag( 'tr',
193 html_tag( 'td',
194 '<center>'. addSubmit(_("Login")) .'</center>',
195 'left' )
196 ),
197 '', $color[4], 'border="0" width="350"' ) . '</center>',
198 'center' )
199 ) ,
200 '', $color[4], 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
cbaf4cf1 201echo '</form>' . "\n";
98f2ee76 202
203do_hook('login_bottom');
a2b193bc 204
134e4174 205?>
dd13b825 206</body></html>