25d45e20268c1a9d58884714183f0e976e6b48a4
[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 // reduces the files included in init.php
16 $sInitLocation = 'login';
17
18 /**
19 * Include the SquirrelMail initialization file.
20 */
21 require('../include/init.php');
22
23
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'functions/imap_general.php');
26 require_once(SM_PATH . 'functions/forms.php');
27
28 /**
29 * $squirrelmail_language is set by a cookie when the user selects
30 * language and logs out
31 */
32 set_up_language($squirrelmail_language, TRUE, TRUE);
33
34 /**
35 * In case the last session was not terminated properly, make sure
36 * we get a new one, but make sure we preserve session_expired_*
37 */
38 if ( !empty($_SESSION['session_expired_post']) && !empty($_SESSION['session_expired_location']) ) {
39 $sep = $_SESSION['session_expired_post'];
40 $sel = $_SESSION['session_expired_location'];
41
42 sqsession_destroy();
43 @sqsession_is_active();
44 $_SESSION=array();
45 sqsession_register($sep, 'session_expired_post');
46 sqsession_register($sel, 'session_expired_location');
47 } else {
48 sqsession_destroy();
49 @sqsession_is_active();
50 $_SESSION=array();
51 }
52
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 */
58 if($imap_auth_mech == 'login') {
59 /**
60 * detect disabled login, only when imapServerAddress contains
61 * server address and not mapping. See sqimap_get_user_server()
62 */
63 if (substr($imapServerAddress, 0, 4) != "map:") {
64 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
65 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
66 sqimap_logout($imap);
67 if ($logindisabled) {
68 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
69 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
70 if (!$use_imap_tls) {
71 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
72 }
73 $string .= _("Please contact your system administrator and report this error.");
74 error_box($string);
75 // display footer (closes html tags) and stop script execution
76 $oTemplate->display('footer.tpl');
77 exit;
78 }
79 }
80 }
81
82 do_hook('login_cookie', $null);
83
84 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
85
86 //FIXME: should be part of the template, not the core!
87 /* Output the javascript onload function. */
88 $header = "<script type=\"text/javascript\">\n" .
89 "<!--\n".
90 " function squirrelmail_loginpage_onload() {\n".
91 " var textElements = 0;\n".
92 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
93 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
94 " textElements++;\n".
95 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
96 " document.forms[0].elements[i].focus();\n".
97 " break;\n".
98 " }\n".
99 " }\n".
100 " }\n".
101 " }\n".
102 "// -->\n".
103 "</script>\n";
104
105 if (@file_exists($theme[$theme_default]['PATH']))
106 @include ($theme[$theme_default]['PATH']);
107
108 if (! isset($color) || ! is_array($color)) {
109 // Add default color theme, if theme loading fails
110 $color = array();
111 $color[0] = '#dcdcdc'; /* light gray TitleBar */
112 $color[1] = '#800000'; /* red */
113 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
114 $color[4] = '#ffffff'; /* white Normal Background */
115 $color[7] = '#0000cc'; /* blue Links */
116 $color[8] = '#000000'; /* black Normal text */
117 }
118 /**
119 * send out all the cookies
120 */
121 sqsetcookieflush();
122
123 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
124
125
126 //FIXME: need to remove *ALL* HTML from this file!
127
128 /* If they don't have a logo, don't bother.. */
129 $logo_str = '';
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 $logo_str = '<img src="'.$org_logo.'" ' .
143 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
144 $width_and_height .
145 'class="sqm_loginImage" /><br />'."\n";
146 }
147
148 $sm_attribute_str = '';
149 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
150 $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
151 _("By the SquirrelMail Project Team")."<br />\n";
152 }
153
154 if(sqgetGlobalVar('mailtodata', $mailtodata)) {
155 $mailtofield = addHidden('mailtodata', $mailtodata);
156 } else {
157 $mailtofield = '';
158 }
159
160 $password_field = addPwField('secretkey');
161 $login_extra = addHidden('js_autodetect_results', SMPREF_JS_OFF).
162 $mailtofield .
163 addHidden('just_logged_in', '1');
164
165 session_write_close();
166
167 $oTemplate->assign('logo_str', $logo_str);
168 $oTemplate->assign('logo_path', $org_logo);
169 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
170 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
171 $oTemplate->assign('login_field_value', $loginname_value);
172 $oTemplate->assign('login_extra', $login_extra);
173
174 echo '<body onLoad="squirrelmail_loginpage_onload()">'."\n";
175 echo '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
176 do_hook('login_top', $null);
177
178 $oTemplate->display('login.tpl');
179
180 echo "</form>\n";
181 do_hook('login_bottom', $null);
182
183 // Turn off delayed error handling to make sure all errors are dumped.
184 $oErrorHandler->setDelayedErrors(false);
185
186 $oTemplate->display('footer.tpl');
187 ?>