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