d3abfc28fd1477231eadacf438b6b470efa4a8e9
[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-2007 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 /** This is the login page */
16 define('PAGE_NAME', 'login');
17
18 // reduces the files included in init.php
19 $sInitLocation = 'login';
20
21 /**
22 * Include the SquirrelMail initialization file.
23 */
24 require('../include/init.php');
25
26
27 /* SquirrelMail required files. */
28 require_once(SM_PATH . 'functions/imap_general.php');
29 require_once(SM_PATH . 'functions/forms.php');
30
31 /**
32 * $squirrelmail_language is set by a cookie when the user selects
33 * language and logs out
34 */
35 set_up_language($squirrelmail_language, TRUE, TRUE);
36
37 /**
38 * In case the last session was not terminated properly, make sure
39 * we get a new one, but make sure we preserve session_expired_*
40 */
41 if ( !empty($_SESSION['session_expired_post']) && !empty($_SESSION['session_expired_location']) ) {
42 $sep = $_SESSION['session_expired_post'];
43 $sel = $_SESSION['session_expired_location'];
44
45 sqsession_destroy();
46 @sqsession_is_active();
47 $_SESSION=array();
48 sqsession_register($sep, 'session_expired_post');
49 sqsession_register($sel, 'session_expired_location');
50 } else {
51 sqsession_destroy();
52 @sqsession_is_active();
53 $_SESSION=array();
54 }
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);
78 // display footer (closes html tags) and stop script execution
79 $oTemplate->display('footer.tpl');
80 exit;
81 }
82 }
83 }
84
85 do_hook('login_cookie', $null);
86
87 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
88
89 //FIXME: should be part of the template, not the core!
90 /* Output the javascript onload function. */
91 $header = "<script type=\"text/javascript\">\n" .
92 "<!--\n".
93 " function squirrelmail_loginpage_onload() {\n".
94 " var textElements = 0;\n".
95 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
96 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
97 " textElements++;\n".
98 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
99 " document.forms[0].elements[i].focus();\n".
100 " break;\n".
101 " }\n".
102 " }\n".
103 " }\n".
104 " }\n".
105 "// -->\n".
106 "</script>\n";
107
108 if (@file_exists($theme[$theme_default]['PATH']))
109 @include ($theme[$theme_default]['PATH']);
110
111 if (! isset($color) || ! is_array($color)) {
112 // Add default color theme, if theme loading fails
113 $color = array();
114 $color[0] = '#dcdcdc'; /* light gray TitleBar */
115 $color[1] = '#800000'; /* red */
116 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
117 $color[4] = '#ffffff'; /* white Normal Background */
118 $color[7] = '#0000cc'; /* blue Links */
119 $color[8] = '#000000'; /* black Normal text */
120 }
121
122 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
123
124
125
126 /* If they don't have a logo, don't bother.. */
127 $logo_str = '';
128 if (isset($org_logo) && $org_logo) {
129
130 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
131 $org_logo_width>0) {
132 $width = $org_logo_width;
133 } else {
134 $width = '';
135 }
136 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
137 $org_logo_height>0) {
138 $height = $org_logo_height;
139 } else {
140 $height = '';
141 }
142
143 $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
144 $width, $height, '', 'sqm_loginImage');
145
146 }
147
148 $sm_attribute_str = '';
149 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
150 $sm_attribute_str = _("SquirrelMail Webmail")."\n" .
151 _("By the SquirrelMail Project Team");
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 // i18n: The %s represents the service provider's name
171 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
172 // i18n: The %s represents the service provider's name
173 $oTemplate->assign('org_logo_str', sprintf (_("The %s logo"), $org_name));
174 $oTemplate->assign('login_field_value', $loginname_value);
175 $oTemplate->assign('login_extra', $login_extra);
176
177 //FIXME: need to remove *ALL* HTML from this file!
178 echo '<body onload="squirrelmail_loginpage_onload()">'."\n";
179 echo '<form action="redirect.php" method="post" onsubmit="document.forms[0].js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
180 do_hook('login_top', $null);
181
182 $oTemplate->display('login.tpl');
183
184 //FIXME: need to remove *ALL* HTML from this file!
185 echo "</form>\n";
186 do_hook('login_bottom', $null);
187
188 // Turn off delayed error handling to make sure all errors are dumped.
189 $oErrorHandler->setDelayedErrors(false);
190
191 $oTemplate->display('footer.tpl');