Today Cyrus 2.2.2-BETA with SASL Initial Client response was released so it
[squirrelmail.git] / src / login.php
1 <?php
2
3 /**
4 * login.php -- simple login screen
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This a simple login screen. Some housekeeping is done to clean
10 * cookies and find language.
11 *
12 * $Id$
13 */
14
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'functions/strings.php');
20 require_once(SM_PATH . 'config/config.php');
21 require_once(SM_PATH . 'functions/i18n.php');
22 require_once(SM_PATH . 'functions/plugin.php');
23 require_once(SM_PATH . 'functions/constants.php');
24 require_once(SM_PATH . 'functions/page_header.php');
25 require_once(SM_PATH . 'functions/html.php');
26 require_once(SM_PATH . 'functions/global.php');
27 require_once(SM_PATH . 'functions/imap_general.php');
28
29 /*
30 * $squirrelmail_language is set by a cookie when the user selects
31 * language and logs out
32 */
33 set_up_language($squirrelmail_language, TRUE, TRUE);
34
35 /**
36 * Find out the base URI to set cookies.
37 */
38 if (!function_exists('sqm_baseuri')){
39 require_once(SM_PATH . 'functions/display_messages.php');
40 }
41 $base_uri = sqm_baseuri();
42
43 /*
44 * In case the last session was not terminated properly, make sure
45 * we get a new one.
46 */
47
48 sqsession_destroy();
49
50 header('Pragma: no-cache');
51
52 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
53 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
54 sqimap_logout($imap);
55 if ($logindisabled) {
56 $string = "The IMAP server is reporting that logins are disabled.<br>";
57 if (!$use_imap_tls) {
58 $string .= "The use of TLS may allow SquirrelMail to login.<br>";
59 }
60 $string .= "Please contact your system administrator.";
61 error_box($string,$color);
62 exit;
63 }
64
65 do_hook('login_cookie');
66
67 /* Output the javascript onload function. */
68
69 $header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
70 "<!--\n".
71 " function squirrelmail_loginpage_onload() {\n".
72 " document.forms[0].js_autodetect_results.value = '" . SMPREF_JS_ON . "';\n".
73 " var textElements = 0;\n".
74 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
75 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
76 " textElements++;\n".
77 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
78 " document.forms[0].elements[i].focus();\n".
79 " break;\n".
80 " }\n".
81 " }\n".
82 " }\n".
83 " }\n".
84 "// -->\n".
85 "</script>\n";
86
87 if (@file_exists($theme[$theme_default]['PATH']))
88 @include ($theme[$theme_default]['PATH']);
89
90 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
91
92 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
93 "\n" . '<form action="redirect.php" method="post">' . "\n";
94
95 $username_form_name = 'login_username';
96 $password_form_name = 'secretkey';
97 do_hook('login_top');
98
99 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
100
101 /* If they don't have a logo, don't bother.. */
102 if (isset($org_logo) && $org_logo) {
103 /* Display width and height like good little people */
104 $width_and_height = '';
105 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
106 $org_logo_width>0) {
107 $width_and_height = " width=\"$org_logo_width\"";
108 }
109 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
110 $org_logo_height>0) {
111 $width_and_height .= " height=\"$org_logo_height\"";
112 }
113 }
114
115 if(sqgetGlobalVar('mailto', $mailto)) {
116 $rcptaddress = '<input type="hidden" name="mailto" value="' . urlencode($mailto) . '" />' . "\n";
117 } else {
118 $rcptaddress = '';
119 }
120 echo html_tag( 'table',
121 html_tag( 'tr',
122 html_tag( 'td',
123 '<center>'.
124 ( isset($org_logo) && $org_logo
125 ? '<img src="' . $org_logo . '" alt="' .
126 sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
127 ' /><br />' . "\n"
128 : '' ).
129 ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
130 '<small>' . sprintf (_("SquirrelMail version %s"), $version) . '<br />' ."\n".
131 ' ' . _("By the SquirrelMail Development Team") . '<br /></small>' . "\n" ) .
132 html_tag( 'table',
133 html_tag( 'tr',
134 html_tag( 'td',
135 '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
136 'center', $color[0] )
137 ) .
138 html_tag( 'tr',
139 html_tag( 'td', "\n" .
140 html_tag( 'table',
141 html_tag( 'tr',
142 html_tag( 'td',
143 _("Name:") ,
144 'right', '', 'width="30%"' ) .
145 html_tag( 'td',
146 '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />' ,
147 'left', '', 'width="*"' )
148 ) . "\n" .
149 html_tag( 'tr',
150 html_tag( 'td',
151 _("Password:") ,
152 'right', '', 'width="30%"' ) .
153 html_tag( 'td',
154 '<input type="password" name="' . $password_form_name . '" />' . "\n" .
155 '<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF" />' . "\n" .
156 $rcptaddress .
157 '<input type="hidden" name="just_logged_in" value="1" />' . "\n",
158 'left', '', 'width="*"' )
159 ) ,
160 'center', $color[4], 'border="0" width="100%"' ) ,
161 'left', $color[4] )
162 ) .
163 html_tag( 'tr',
164 html_tag( 'td',
165 '<center><input type="submit" value="' . _("Login") . '" /></center>',
166 'left' )
167 ),
168 '', $color[4], 'border="0" width="350"' ) . '</center>',
169 'center' )
170 ) ,
171 '', $color[4], 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
172 do_hook('login_form');
173 echo '</form>' . "\n";
174
175 do_hook('login_bottom');
176 echo "</body>\n".
177 "</html>\n";
178 ?>