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