copyright update
[squirrelmail.git] / src / login.php
1 <?php
2
3 /**
4 * login.php -- simple login screen
5 *
6 * This a simple login screen. Some housekeeping is done to clean
7 * cookies and find language.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'functions/strings.php');
23 require_once(SM_PATH . 'config/config.php');
24 require_once(SM_PATH . 'functions/i18n.php');
25 require_once(SM_PATH . 'functions/plugin.php');
26 require_once(SM_PATH . 'functions/constants.php');
27 require_once(SM_PATH . 'functions/page_header.php');
28 require_once(SM_PATH . 'functions/html.php');
29 require_once(SM_PATH . 'functions/global.php');
30 require_once(SM_PATH . 'functions/imap_general.php');
31 require_once(SM_PATH . 'functions/forms.php');
32
33 /**
34 * $squirrelmail_language is set by a cookie when the user selects
35 * language and logs out
36 */
37 set_up_language($squirrelmail_language, TRUE, TRUE);
38
39 /**
40 * Find out the base URI to set cookies.
41 */
42 if (!function_exists('sqm_baseuri')){
43 require_once(SM_PATH . 'functions/display_messages.php');
44 }
45 $base_uri = sqm_baseuri();
46
47 /*
48 * In case the last session was not terminated properly, make sure
49 * we get a new one.
50 */
51
52 sqsession_destroy();
53 sqsession_start();
54 header('Pragma: no-cache');
55
56 /**
57 * This detects if the IMAP server has logins disabled, and if so,
58 * squelches the display of the login form and puts up a message
59 * explaining the situation.
60 */
61 if($imap_auth_mech == 'login') {
62 /**
63 * detect disabled login, only when imapServerAddress contains
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;
79 }
80 }
81 }
82
83 do_hook('login_cookie');
84
85 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
86
87 /* Output the javascript onload function. */
88
89 $header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
90 "<!--\n".
91 " function squirrelmail_loginpage_onload() {\n".
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".
102 " }\n".
103 "// -->\n".
104 "</script>\n";
105
106 if (@file_exists($theme[$theme_default]['PATH']))
107 @include ($theme[$theme_default]['PATH']);
108
109 if (! 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
120 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
121
122 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
123 "\n" . '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value=\'' . SMPREF_JS_ON .'\';">' . "\n";
124
125 $username_form_name = 'login_username';
126 $password_form_name = 'secretkey';
127 do_hook('login_top');
128
129 /* If they don't have a logo, don't bother.. */
130 if (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 }
141 }
142
143 if(sqgetGlobalVar('mailto', $mailto)) {
144 $rcptaddress = addHidden('mailto', $mailto);
145 } else {
146 $rcptaddress = '';
147 }
148 echo html_tag( 'table',
149 html_tag( 'tr',
150 html_tag( 'td',
151 '<center>'.
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 : '' ).
157 ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
158 '<small>' . _("SquirrelMail Webmail Application") . '<br />' ."\n".
159 ' ' . _("By the SquirrelMail Project Team") . '<br /></small>' . "\n" ) .
160 html_tag( 'table',
161 html_tag( 'tr',
162 html_tag( 'td',
163 '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
164 'center', $color[0] )
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',
174 addInput($username_form_name, $loginname_value),
175 'left', '', 'width="*"' )
176 ) . "\n" .
177 html_tag( 'tr',
178 html_tag( 'td',
179 _("Password:") ,
180 'right', '', 'width="30%"' ) .
181 html_tag( 'td',
182 addPwField($password_form_name).
183 addHidden('js_autodetect_results', SMPREF_JS_OFF).
184 $rcptaddress .
185 addHidden('just_logged_in', '1'),
186 'left', '', 'width="*"' )
187 ) .
188 concat_hook_function('login_form') ,
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%"' );
201 echo '</form>' . "\n";
202
203 do_hook('login_bottom');
204
205 ?>
206 </body></html>