rename squirrelmail_rpc.php to rpc.php, it doesn't make much sense to
[squirrelmail.git] / src / login.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * login.php -- simple login screen
5 *
35586184 6 * This a simple login screen. Some housekeeping is done to clean
7 * cookies and find language.
8 *
4b5049de 9 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
8e2ed807 14
ebd2391c 15/** This is the login page */
16define('PAGE_NAME', 'login');
17
202bcbcc 18// reduces the files included in init.php
19$sInitLocation = 'login';
20
30967a1e 21/**
202bcbcc 22 * Include the SquirrelMail initialization file.
30967a1e 23 */
202bcbcc 24require('../include/init.php');
25
86725763 26
27/* SquirrelMail required files. */
ea348fd3 28require_once(SM_PATH . 'functions/imap_general.php');
a34d6890 29require_once(SM_PATH . 'functions/forms.php');
98f2ee76 30
8f6f9ba5 31/**
98f2ee76 32 * $squirrelmail_language is set by a cookie when the user selects
33 * language and logs out
34 */
5e2b6751 35set_up_language($squirrelmail_language, TRUE, TRUE);
d4e84069 36
c6f28eb1 37/**
98f2ee76 38 * In case the last session was not terminated properly, make sure
c6f28eb1 39 * we get a new one, but make sure we preserve session_expired_*
98f2ee76 40 */
c6f28eb1 41if ( !empty($_SESSION['session_expired_post']) && !empty($_SESSION['session_expired_location']) ) {
42 $sep = $_SESSION['session_expired_post'];
43 $sel = $_SESSION['session_expired_location'];
44
45 sqsession_destroy();
66c7cd3f 46 @sqsession_is_active();
c6f28eb1 47 $_SESSION=array();
48 sqsession_register($sep, 'session_expired_post');
49 sqsession_register($sel, 'session_expired_location');
50} else {
51 sqsession_destroy();
52 @sqsession_is_active();
53 $_SESSION=array();
54}
98f2ee76 55
8f6f9ba5 56/**
91e0dccc 57 * This detects if the IMAP server has logins disabled, and if so,
8f6f9ba5 58 * squelches the display of the login form and puts up a message
59 * explaining the situation.
60 */
6d611a76 61if($imap_auth_mech == 'login') {
c0c5cf6a 62 /**
f8a1ed5a 63 * detect disabled login, only when imapServerAddress contains
c0c5cf6a 64 * server address and not mapping. See sqimap_get_user_server()
65 */
66 if (substr($imapServerAddress, 0, 4) != "map:") {
67 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
68 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
69 sqimap_logout($imap);
70 if ($logindisabled) {
71 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
72 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
73 if (!$use_imap_tls) {
74 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
75 }
76 $string .= _("Please contact your system administrator and report this error.");
1b858d86 77 error_box($string);
78 // display footer (closes html tags) and stop script execution
79 $oTemplate->display('footer.tpl');
c0c5cf6a 80 exit;
6d611a76 81 }
ea348fd3 82 }
ea348fd3 83}
84
6e515418 85do_hook('login_cookie', $null);
98f2ee76 86
bca2d025 87$loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
88
6e515418 89//FIXME: should be part of the template, not the core!
98f2ee76 90/* Output the javascript onload function. */
2c92ea9d 91$header = "<script type=\"text/javascript\">\n" .
98f2ee76 92 "<!--\n".
93 " function squirrelmail_loginpage_onload() {\n".
03ccb49b 94 " var textElements = 0;\n".
95 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
96 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
97 " textElements++;\n".
98 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
99 " document.forms[0].elements[i].focus();\n".
100 " break;\n".
101 " }\n".
102 " }\n".
103 " }\n".
98f2ee76 104 " }\n".
105 "// -->\n".
106 "</script>\n";
dfb94cac 107
108if (@file_exists($theme[$theme_default]['PATH']))
109 @include ($theme[$theme_default]['PATH']);
110
832dc1e2 111if (! isset($color) || ! is_array($color)) {
112 // Add default color theme, if theme loading fails
113 $color = array();
114 $color[0] = '#dcdcdc'; /* light gray TitleBar */
115 $color[1] = '#800000'; /* red */
116 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
117 $color[4] = '#ffffff'; /* white Normal Background */
118 $color[7] = '#0000cc'; /* blue Links */
119 $color[8] = '#000000'; /* black Normal text */
120}
121
c5330196 122displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
98f2ee76 123
98f2ee76 124
6e515418 125
78b2428e 126/* If they don't have a logo, don't bother.. */
c5330196 127$logo_str = '';
78b2428e 128if (isset($org_logo) && $org_logo) {
b86f98e4 129
78b2428e 130 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
131 $org_logo_width>0) {
0173ad29 132 $width = $org_logo_width;
efb5bde8 133 } else {
0173ad29 134 $width = '';
78b2428e 135 }
136 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
137 $org_logo_height>0) {
0173ad29 138 $height = $org_logo_height;
efb5bde8 139 } else {
0173ad29 140 $height = '';
78b2428e 141 }
0173ad29 142
b86f98e4 143 $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
0173ad29 144 $width, $height, '', 'sqm_loginImage');
145
c5330196 146}
147
148$sm_attribute_str = '';
beebd508 149if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
3e6b917e 150 $sm_attribute_str = _("SquirrelMail Webmail")."\n" .
2e9a4e86 151 _("By the SquirrelMail Project Team");
98f2ee76 152}
3fde693b 153
7e2ff844 154if(sqgetGlobalVar('mailtodata', $mailtodata)) {
155 $mailtofield = addHidden('mailtodata', $mailtodata);
c67e4479 156} else {
7e2ff844 157 $mailtofield = '';
c67e4479 158}
c5330196 159
84d10885 160$password_field = addPwField('secretkey');
2f04c558 161$login_extra = addHidden('js_autodetect_results', SMPREF_JS_OFF).
7e2ff844 162 $mailtofield .
31633bef 163 addHidden('just_logged_in', '1');
c5330196 164
202bcbcc 165session_write_close();
166
3f087701 167$oTemplate->assign('logo_str', $logo_str);
84d10885 168$oTemplate->assign('logo_path', $org_logo);
c5330196 169$oTemplate->assign('sm_attribute_str', $sm_attribute_str);
6f4080b1 170// i18n: The %s represents the service provider's name
c5330196 171$oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
6f4080b1 172// i18n: The %s represents the service provider's name
173$oTemplate->assign('org_logo_str', sprintf (_("The %s logo"), $org_name));
2f04c558 174$oTemplate->assign('login_field_value', $loginname_value);
3f087701 175$oTemplate->assign('login_extra', $login_extra);
2f04c558 176
0173ad29 177//FIXME: need to remove *ALL* HTML from this file!
3b4dece1 178echo '<body onload="squirrelmail_loginpage_onload()">'."\n";
179echo '<form action="redirect.php" method="post" onsubmit="document.forms[0].js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
6e515418 180do_hook('login_top', $null);
c5330196 181
182$oTemplate->display('login.tpl');
f5dcd7f3 183
0173ad29 184//FIXME: need to remove *ALL* HTML from this file!
2f04c558 185echo "</form>\n";
6e515418 186do_hook('login_bottom', $null);
2f04c558 187
f5dcd7f3 188// Turn off delayed error handling to make sure all errors are dumped.
84d10885 189$oErrorHandler->setDelayedErrors(false);
f5dcd7f3 190
f5dcd7f3 191$oTemplate->display('footer.tpl');