When the data stream wasn't ending with \r\n the finalize stream function
[squirrelmail.git] / src / login.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * login.php -- simple login screen
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This a simple login screen. Some housekeeping is done to clean
10 * cookies and find language.
11 *
12 * $Id$
8f6f9ba5 13 * @package squirrelmail
35586184 14 */
8e2ed807 15
8f6f9ba5 16/** Path for SquirrelMail required files. */
86725763 17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
20require_once(SM_PATH . 'functions/strings.php');
21require_once(SM_PATH . 'config/config.php');
22require_once(SM_PATH . 'functions/i18n.php');
23require_once(SM_PATH . 'functions/plugin.php');
24require_once(SM_PATH . 'functions/constants.php');
25require_once(SM_PATH . 'functions/page_header.php');
26require_once(SM_PATH . 'functions/html.php');
a32985a5 27require_once(SM_PATH . 'functions/global.php');
ea348fd3 28require_once(SM_PATH . 'functions/imap_general.php');
98f2ee76 29
8f6f9ba5 30/**
98f2ee76 31 * $squirrelmail_language is set by a cookie when the user selects
32 * language and logs out
33 */
5e2b6751 34set_up_language($squirrelmail_language, TRUE, TRUE);
d4e84069 35
85b454a0 36/**
37 * Find out the base URI to set cookies.
38 */
f3bc099d 39if (!function_exists('sqm_baseuri')){
86725763 40 require_once(SM_PATH . 'functions/display_messages.php');
f3bc099d 41}
42$base_uri = sqm_baseuri();
8e2ed807 43
98f2ee76 44/*
45 * In case the last session was not terminated properly, make sure
46 * we get a new one.
47 */
5250f7e7 48
69146537 49sqsession_destroy();
50
98f2ee76 51header('Pragma: no-cache');
52
8f6f9ba5 53/**
54 * This detects if the IMAP server has logins disabled, and if so,
55 * squelches the display of the login form and puts up a message
56 * explaining the situation.
57 */
6d611a76 58if($imap_auth_mech == 'login') {
59 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
60 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
61 sqimap_logout($imap);
62 if ($logindisabled) {
63 $string = "The IMAP server is reporting that logins are disabled.<br>";
64 if (!$use_imap_tls) {
65 $string .= "The use of TLS may allow SquirrelMail to login.<br>";
66 }
67 $string .= "Please contact your system administrator.";
68 error_box($string,$color);
69 exit;
ea348fd3 70 }
ea348fd3 71}
72
98f2ee76 73do_hook('login_cookie');
74
75/* Output the javascript onload function. */
76
d68323ff 77$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
98f2ee76 78 "<!--\n".
79 " function squirrelmail_loginpage_onload() {\n".
03ccb49b 80 " var textElements = 0;\n".
81 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
82 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
83 " textElements++;\n".
84 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
85 " document.forms[0].elements[i].focus();\n".
86 " break;\n".
87 " }\n".
88 " }\n".
89 " }\n".
98f2ee76 90 " }\n".
91 "// -->\n".
92 "</script>\n";
dfb94cac 93
94if (@file_exists($theme[$theme_default]['PATH']))
95 @include ($theme[$theme_default]['PATH']);
96
98f2ee76 97displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
98
2e394e36 99echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
ae958cd3 100 "\n" . '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value=\'' . SMPREF_JS_ON .'\';">' . "\n";
98f2ee76 101
0fce910a 102$username_form_name = 'login_username';
103$password_form_name = 'secretkey';
98f2ee76 104do_hook('login_top');
105
5250f7e7 106$loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
98f2ee76 107
78b2428e 108/* If they don't have a logo, don't bother.. */
109if (isset($org_logo) && $org_logo) {
110 /* Display width and height like good little people */
111 $width_and_height = '';
112 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
113 $org_logo_width>0) {
114 $width_and_height = " width=\"$org_logo_width\"";
115 }
116 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
117 $org_logo_height>0) {
118 $width_and_height .= " height=\"$org_logo_height\"";
119 }
98f2ee76 120}
3fde693b 121
c67e4479 122if(sqgetGlobalVar('mailto', $mailto)) {
123 $rcptaddress = '<input type="hidden" name="mailto" value="' . urlencode($mailto) . '" />' . "\n";
124} else {
125 $rcptaddress = '';
126}
1cac3b9b 127echo html_tag( 'table',
8e2ed807 128 html_tag( 'tr',
129 html_tag( 'td',
130 '<center>'.
78b2428e 131 ( isset($org_logo) && $org_logo
132 ? '<img src="' . $org_logo . '" alt="' .
133 sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
134 ' /><br />' . "\n"
135 : '' ).
8a97a070 136 ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
d68323ff 137 '<small>' . sprintf (_("SquirrelMail version %s"), $version) . '<br />' ."\n".
138 ' ' . _("By the SquirrelMail Development Team") . '<br /></small>' . "\n" ) .
8e2ed807 139 html_tag( 'table',
140 html_tag( 'tr',
141 html_tag( 'td',
142 '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
dfb94cac 143 'center', $color[0] )
8e2ed807 144 ) .
145 html_tag( 'tr',
146 html_tag( 'td', "\n" .
147 html_tag( 'table',
148 html_tag( 'tr',
149 html_tag( 'td',
150 _("Name:") ,
151 'right', '', 'width="30%"' ) .
152 html_tag( 'td',
d68323ff 153 '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />' ,
8e2ed807 154 'left', '', 'width="*"' )
155 ) . "\n" .
156 html_tag( 'tr',
157 html_tag( 'td',
158 _("Password:") ,
159 'right', '', 'width="30%"' ) .
160 html_tag( 'td',
d68323ff 161 '<input type="password" name="' . $password_form_name . '" />' . "\n" .
ae958cd3 162 '<input type="hidden" name="js_autodetect_results" value="'.SMPREF_JS_OFF.'" />' . "\n" .
c67e4479 163 $rcptaddress .
d68323ff 164 '<input type="hidden" name="just_logged_in" value="1" />' . "\n",
8e2ed807 165 'left', '', 'width="*"' )
166 ) ,
dfb94cac 167 'center', $color[4], 'border="0" width="100%"' ) ,
168 'left', $color[4] )
8e2ed807 169 ) .
170 html_tag( 'tr',
171 html_tag( 'td',
d68323ff 172 '<center><input type="submit" value="' . _("Login") . '" /></center>',
8e2ed807 173 'left' )
174 ),
dfb94cac 175 '', $color[4], 'border="0" width="350"' ) . '</center>',
8e2ed807 176 'center' )
177 ) ,
dfb94cac 178'', $color[4], 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
98f2ee76 179do_hook('login_form');
cbaf4cf1 180echo '</form>' . "\n";
98f2ee76 181
182do_hook('login_bottom');
8e2ed807 183echo "</body>\n".
184 "</html>\n";
dcc1cc82 185?>