4 * login.php -- simple login screen
6 * This a simple login screen. Some housekeeping is done to clean
7 * cookies and find language.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'functions/global.php');
23 require_once(SM_PATH
. 'functions/strings.php');
24 require_once(SM_PATH
. 'config/config.php');
25 require_once(SM_PATH
. 'functions/i18n.php');
26 require_once(SM_PATH
. 'functions/plugin.php');
27 require_once(SM_PATH
. 'functions/constants.php');
28 require_once(SM_PATH
. 'functions/page_header.php');
29 require_once(SM_PATH
. 'functions/html.php');
30 require_once(SM_PATH
. 'functions/imap_general.php');
31 require_once(SM_PATH
. 'functions/forms.php');
34 * $squirrelmail_language is set by a cookie when the user selects
35 * language and logs out
37 set_up_language($squirrelmail_language, TRUE, TRUE);
40 * Find out the base URI to set cookies.
42 $base_uri = sqm_baseuri();
45 * In case the last session was not terminated properly, make sure
51 * PHP bug. http://bugs.php.net/11643 (warning, spammed bug tracker) and
52 * http://bugs.php.net/13834
53 * SID constant is not destroyed in PHP 4.1.2, 4.2.3 and maybe other
54 * versions. Produces warning on login page. Bug should be fixed only in 4.3.0
57 header('Pragma: no-cache');
60 * This detects if the IMAP server has logins disabled, and if so,
61 * squelches the display of the login form and puts up a message
62 * explaining the situation.
64 if($imap_auth_mech == 'login') {
66 * detect disabled login, only when imapServerAddress contains
67 * server address and not mapping. See sqimap_get_user_server()
69 if (substr($imapServerAddress, 0, 4) != "map:") {
70 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
71 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
74 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
75 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
77 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
79 $string .= _("Please contact your system administrator and report this error.");
80 error_box($string,$color);
87 * Initialize the template object and custom error handler object
89 include_once(SM_PATH
. 'class/template/template.class.php');
90 include_once(SM_PATH
. 'class/error.class.php');
93 * $sTplDir is not initialized when a user is not logged in, so we will use
94 * the config file defaults here. If the neccesary variables are net set,
95 * force a default value.
97 $aTemplateSet = ( !isset($aTemplateSet) ?
array() : $aTemplateSet );
98 $templateset_default = ( !isset($templateset_default) ?
0 : $templateset_default );
99 $sTplDir = ( !isset($aTemplateSet[$templateset_default]['PATH']) ?
100 SM_PATH
. 'templates/default/' :
101 $aTemplateSet[$templateset_default]['PATH'] );
103 $oTemplate = new Template($sTplDir);
104 $oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl');
106 do_hook('login_cookie');
108 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ?
htmlspecialchars($loginname) : '');
110 /* Output the javascript onload function. */
111 $header = "<script type=\"text/javascript\">\n" .
113 " function squirrelmail_loginpage_onload() {\n".
114 " var textElements = 0;\n".
115 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
116 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
117 " textElements++;\n".
118 " if (textElements == " . (isset($loginname) ?
2 : 1) . ") {\n".
119 " document.forms[0].elements[i].focus();\n".
128 if (@file_exists
($theme[$theme_default]['PATH']))
129 @include
($theme[$theme_default]['PATH']);
131 if (! isset($color) ||
! is_array($color)) {
132 // Add default color theme, if theme loading fails
134 $color[0] = '#dcdcdc'; /* light gray TitleBar */
135 $color[1] = '#800000'; /* red */
136 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
137 $color[4] = '#ffffff'; /* white Normal Background */
138 $color[7] = '#0000cc'; /* blue Links */
139 $color[8] = '#000000'; /* black Normal text */
142 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
145 /* If they don't have a logo, don't bother.. */
147 if (isset($org_logo) && $org_logo) {
148 /* Display width and height like good little people */
149 $width_and_height = '';
150 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
152 $width_and_height = " width=\"$org_logo_width\"";
154 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
155 $org_logo_height>0) {
156 $width_and_height .= " height=\"$org_logo_height\"";
159 $logo_str = '<img src="'.$org_logo.'" ' .
160 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
162 'class="sqm_loginImage" ' .
166 $sm_attribute_str = '';
167 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
168 $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
169 _("By the SquirrelMail Project Team")."<br />\n";
172 $username_form_name = 'login_username';
173 $password_form_name = 'secretkey';
175 if(sqgetGlobalVar('mailto', $mailto)) {
176 $rcptaddress = addHidden('mailto', $mailto);
181 $password_field = addPwField($password_form_name).
182 addHidden('js_autodetect_results', SMPREF_JS_OFF
).
184 addHidden('just_logged_in', '1');
186 $oTemplate->assign('color', $color);
187 $oTemplate->assign('logo_str', $logo_str);
188 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
189 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
190 $oTemplate->assign('login_field', addInput($username_form_name, $loginname_value));
191 $oTemplate->assign('password_field', $password_field);
192 $oTemplate->assign('submit_field', addSubmit(_("Login")));
194 $oTemplate->display('login.tpl');