2fea9d046537e942fc77f1ae0d54f28b4fe7e7d4
[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.
37 */
38 sqsession_destroy();
39 sqsession_is_active();
40 $_SESSION=array();
41
42
43 /**
44 * PHP bug. http://bugs.php.net/11643 (warning, spammed bug tracker) and
45 * http://bugs.php.net/13834
46 * SID constant is not destroyed in PHP 4.1.2, 4.2.3 and maybe other
47 * versions. Produces warning on login page. Bug should be fixed only in 4.3.0
48 */
49
50 //exit;
51 /**
52 * This detects if the IMAP server has logins disabled, and if so,
53 * squelches the display of the login form and puts up a message
54 * explaining the situation.
55 */
56 if($imap_auth_mech == 'login') {
57 /**
58 * detect disabled login, only when imapServerAddress contains
59 * server address and not mapping. See sqimap_get_user_server()
60 */
61 if (substr($imapServerAddress, 0, 4) != "map:") {
62 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
63 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
64 sqimap_logout($imap);
65 if ($logindisabled) {
66 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
67 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
68 if (!$use_imap_tls) {
69 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
70 }
71 $string .= _("Please contact your system administrator and report this error.");
72 error_box($string,$color);
73 exit;
74 }
75 }
76 }
77
78 do_hook('login_cookie');
79
80 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
81
82 /* Output the javascript onload function. */
83 $header = "<script type=\"text/javascript\">\n" .
84 "<!--\n".
85 " function squirrelmail_loginpage_onload() {\n".
86 " var textElements = 0;\n".
87 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
88 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
89 " textElements++;\n".
90 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
91 " document.forms[0].elements[i].focus();\n".
92 " break;\n".
93 " }\n".
94 " }\n".
95 " }\n".
96 " }\n".
97 "// -->\n".
98 "</script>\n";
99
100 if (@file_exists($theme[$theme_default]['PATH']))
101 @include ($theme[$theme_default]['PATH']);
102
103 if (! isset($color) || ! is_array($color)) {
104 // Add default color theme, if theme loading fails
105 $color = array();
106 $color[0] = '#dcdcdc'; /* light gray TitleBar */
107 $color[1] = '#800000'; /* red */
108 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
109 $color[4] = '#ffffff'; /* white Normal Background */
110 $color[7] = '#0000cc'; /* blue Links */
111 $color[8] = '#000000'; /* black Normal text */
112 }
113
114 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
115
116
117 /* If they don't have a logo, don't bother.. */
118 $logo_str = '';
119 if (isset($org_logo) && $org_logo) {
120 /* Display width and height like good little people */
121 $width_and_height = '';
122 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
123 $org_logo_width>0) {
124 $width_and_height = " width=\"$org_logo_width\"";
125 }
126 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
127 $org_logo_height>0) {
128 $width_and_height .= " height=\"$org_logo_height\"";
129 }
130
131 $logo_str = '<img src="'.$org_logo.'" ' .
132 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
133 $width_and_height .
134 'class="sqm_loginImage" ' .
135 ' /><br />'."\n";
136 }
137
138 $sm_attribute_str = '';
139 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
140 $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
141 _("By the SquirrelMail Project Team")."<br />\n";
142 }
143
144 $username_form_name = 'login_username';
145 $password_form_name = 'secretkey';
146
147 if(sqgetGlobalVar('mailto', $mailto)) {
148 $rcptaddress = addHidden('mailto', $mailto);
149 } else {
150 $rcptaddress = '';
151 }
152
153 $password_field = addPwField($password_form_name).
154 addHidden('js_autodetect_results', SMPREF_JS_OFF).
155 $rcptaddress .
156 addHidden('just_logged_in', '1');
157
158 session_write_close();
159
160 $oTemplate->assign('color', $color);
161 $oTemplate->assign('logo_str', $logo_str);
162 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
163 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
164 $oTemplate->assign('login_field', addInput($username_form_name, $loginname_value));
165 $oTemplate->assign('password_field', $password_field);
166 $oTemplate->assign('submit_field', addSubmit(_("Login")));
167
168 $oTemplate->display('login.tpl');
169 ?>