Adding template for error box.
[squirrelmail.git] / src / login.php
... / ...
CommitLineData
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 */
19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
22require_once(SM_PATH . 'functions/global.php');
23require_once(SM_PATH . 'functions/strings.php');
24require_once(SM_PATH . 'config/config.php');
25require_once(SM_PATH . 'functions/i18n.php');
26require_once(SM_PATH . 'functions/plugin.php');
27require_once(SM_PATH . 'functions/constants.php');
28require_once(SM_PATH . 'functions/page_header.php');
29require_once(SM_PATH . 'functions/html.php');
30require_once(SM_PATH . 'functions/imap_general.php');
31require_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 */
37set_up_language($squirrelmail_language, TRUE, TRUE);
38
39/**
40 * Find out the base URI to set cookies.
41 */
42$base_uri = sqm_baseuri();
43
44/*
45 * In case the last session was not terminated properly, make sure
46 * we get a new one.
47 */
48
49sqsession_destroy();
50/**
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
55 */
56@sqsession_start();
57header('Pragma: no-cache');
58
59/**
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.
63 */
64if($imap_auth_mech == 'login') {
65 /**
66 * detect disabled login, only when imapServerAddress contains
67 * server address and not mapping. See sqimap_get_user_server()
68 */
69 if (substr($imapServerAddress, 0, 4) != "map:") {
70 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
71 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
72 sqimap_logout($imap);
73 if ($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 />';
76 if (!$use_imap_tls) {
77 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
78 }
79 $string .= _("Please contact your system administrator and report this error.");
80 error_box($string,$color);
81 exit;
82 }
83 }
84}
85
86/*
87 * Initialize the template object and custom error handler object
88 */
89include_once(SM_PATH . 'class/template/template.class.php');
90include_once(SM_PATH . 'class/error.class.php');
91
92/*
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.
96 */
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'] );
102
103$oTemplate = new Template($sTplDir);
104$oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl');
105
106do_hook('login_cookie');
107
108$loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
109
110/* Output the javascript onload function. */
111$header = "<script type=\"text/javascript\">\n" .
112 "<!--\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".
120 " break;\n".
121 " }\n".
122 " }\n".
123 " }\n".
124 " }\n".
125 "// -->\n".
126 "</script>\n";
127
128if (@file_exists($theme[$theme_default]['PATH']))
129 @include ($theme[$theme_default]['PATH']);
130
131if (! isset($color) || ! is_array($color)) {
132 // Add default color theme, if theme loading fails
133 $color = array();
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 */
140}
141
142displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
143
144
145/* If they don't have a logo, don't bother.. */
146$logo_str = '';
147if (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) &&
151 $org_logo_width>0) {
152 $width_and_height = " width=\"$org_logo_width\"";
153 }
154 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
155 $org_logo_height>0) {
156 $width_and_height .= " height=\"$org_logo_height\"";
157 }
158
159 $logo_str = '<img src="'.$org_logo.'" ' .
160 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
161 $width_and_height .
162 'class="sqm_loginImage" ' .
163 ' /><br />'."\n";
164}
165
166$sm_attribute_str = '';
167if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
168 $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
169 _("By the SquirrelMail Project Team")."<br />\n";
170}
171
172$username_form_name = 'login_username';
173$password_form_name = 'secretkey';
174
175if(sqgetGlobalVar('mailto', $mailto)) {
176 $rcptaddress = addHidden('mailto', $mailto);
177} else {
178 $rcptaddress = '';
179}
180
181$password_field = addPwField($password_form_name).
182 addHidden('js_autodetect_results', SMPREF_JS_OFF).
183 $rcptaddress .
184 addHidden('just_logged_in', '1');
185
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")));
193
194$oTemplate->display('login.tpl');
195?>