[1718] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare login * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Originaly written by Dan Kuykendall <seek3r@phpgroupware.org> * |
---|
| 6 | * Joseph Engo <jengo@phpgroupware.org> * |
---|
| 7 | * Updated by Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br> * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \**************************************************************************/ |
---|
| 13 | |
---|
| 14 | function check_logoutcode($code) |
---|
| 15 | { |
---|
| 16 | switch($code) |
---|
| 17 | { |
---|
| 18 | case 1: |
---|
| 19 | return lang('You have been successfully logged out'); |
---|
| 20 | |
---|
| 21 | case 2: |
---|
| 22 | return lang('Sorry, your login has expired'); |
---|
| 23 | |
---|
| 24 | case 4: |
---|
| 25 | return lang('Cookies are required to login to this site.'); |
---|
| 26 | |
---|
| 27 | case 5: |
---|
| 28 | return '<font color="FF0000">' . lang('Bad login or password') . '</font>'; |
---|
| 29 | |
---|
| 30 | case 6: |
---|
| 31 | return '<font color="FF0000">' . lang('Your password has expired, and you do not have access to change it') . '</font>'; |
---|
| 32 | |
---|
| 33 | case 98: |
---|
| 34 | return '<font color="FF0000">' . lang('Account is expired') . '</font>'; |
---|
| 35 | |
---|
| 36 | case 99: |
---|
| 37 | return '<font color="FF0000">' . lang('Blocked, too many attempts') . '</font>'; |
---|
| 38 | |
---|
| 39 | case 10: |
---|
| 40 | $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid'); |
---|
| 41 | $GLOBALS['phpgw']->session->phpgw_setcookie('kp3'); |
---|
| 42 | $GLOBALS['phpgw']->session->phpgw_setcookie('domain'); |
---|
| 43 | |
---|
| 44 | //fix for bug php4 expired sessions bug |
---|
| 45 | if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4') |
---|
| 46 | { |
---|
| 47 | $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>'; |
---|
| 51 | |
---|
| 52 | default: |
---|
| 53 | return ' '; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /* Program starts here */ |
---|
| 58 | |
---|
| 59 | if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER'])) |
---|
| 60 | { |
---|
| 61 | $submit = True; |
---|
| 62 | $login = $_SERVER['PHP_AUTH_USER']; |
---|
| 63 | $passwd = $_SERVER['PHP_AUTH_PW']; |
---|
| 64 | $passwd_type = 'text'; |
---|
| 65 | } |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | $passwd = $_POST['passwd']; |
---|
| 69 | $passwd_type = $_POST['passwd_type']; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | # Apache + mod_ssl style SSL certificate authentication |
---|
| 73 | # Certificate (chain) verification occurs inside mod_ssl |
---|
| 74 | if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd'])) |
---|
| 75 | { |
---|
| 76 | # an X.509 subject looks like: |
---|
| 77 | # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/ |
---|
| 78 | # the username is deliberately lowercase, to ease LDAP integration |
---|
| 79 | $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']); |
---|
| 80 | # skip the part in front of the first '/' (nothing) |
---|
| 81 | while($sslattrib = next($sslattribs)) |
---|
| 82 | { |
---|
| 83 | list($key,$val) = explode('=',$sslattrib); |
---|
| 84 | $sslattributes[$key] = $val; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if(isset($sslattributes['Email'])) |
---|
| 88 | { |
---|
| 89 | $submit = True; |
---|
| 90 | |
---|
| 91 | # login will be set here if the user logged out and uses a different username with |
---|
| 92 | # the same SSL-certificate. |
---|
| 93 | if(!isset($_POST['login'])&&isset($sslattributes['Email'])) |
---|
| 94 | { |
---|
| 95 | $login = $sslattributes['Email']; |
---|
| 96 | # not checked against the database, but delivered to authentication module |
---|
| 97 | $passwd = $_SERVER['SSL_CLIENT_S_DN']; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | unset($key); |
---|
| 101 | unset($val); |
---|
| 102 | unset($sslattributes); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) |
---|
| 106 | { |
---|
| 107 | if($_POST['user']) { |
---|
| 108 | if($GLOBALS['phpgw_info']['server']['use_prefix_organization']) { |
---|
| 109 | $common = CreateObject('phpgwapi.common'); |
---|
| 110 | $ldap_conn = $common->ldapConnect(); |
---|
| 111 | $justthese = array("uid"); |
---|
| 112 | $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))"; |
---|
| 113 | $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 114 | $ldap_info = ldap_get_entries($ldap_conn, $ldap_search); |
---|
| 115 | ldap_close($ldap_conn); |
---|
| 116 | if ($ldap_info['count'] != 0) { |
---|
| 117 | $_POST['login'] = $_POST['user']; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | $_POST['login'] = $_POST['user']; |
---|
| 122 | } |
---|
| 123 | if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' && |
---|
| 124 | !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN'])) |
---|
| 125 | { |
---|
| 126 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5')); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // don't get login data again when $submit is true |
---|
| 130 | if($submit == false) |
---|
| 131 | { |
---|
| 132 | $login = $_POST['login']; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | if(strstr($login,'@') === False && isset($_POST['logindomain'])) |
---|
| 136 | { |
---|
| 137 | $login .= '@' . $_POST['logindomain']; |
---|
| 138 | } |
---|
| 139 | elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']])) |
---|
| 140 | { |
---|
| 141 | $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain']; |
---|
| 142 | } |
---|
| 143 | $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u'); |
---|
| 144 | |
---|
| 145 | if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid']) |
---|
| 146 | { |
---|
| 147 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason); |
---|
| 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) && |
---|
| 152 | $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) |
---|
| 153 | { |
---|
| 154 | $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session'); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles']) |
---|
| 158 | { |
---|
| 159 | $GLOBALS['phpgw']->translation->autoload_changed_langfiles(); |
---|
| 160 | } |
---|
| 161 | $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward']; |
---|
| 162 | if (!$forward) |
---|
| 163 | { |
---|
| 164 | $extra_vars['cd'] = 'yes'; |
---|
| 165 | $forward = '/home.php'; |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | list($forward,$extra_vars) = explode('?',$forward,2); |
---|
| 170 | } |
---|
| 171 | if ($GLOBALS['phpgw_info']['server']['use_https'] != 2) |
---|
| 172 | { |
---|
| 173 | $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes')); |
---|
| 174 | echo "<script language='Javascript1.3'>location.href='".$forward."'</script>"; |
---|
| 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | $GLOBALS['phpgw']->redirect_link($forward,$extra_vars); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | else |
---|
| 183 | { |
---|
| 184 | // !!! DONT CHANGE THESE LINES !!! |
---|
| 185 | // If there is something wrong with this code TELL ME! |
---|
| 186 | // Commenting out the code will not fix it. (jengo) |
---|
| 187 | if(isset($_COOKIE['last_loginid'])) |
---|
| 188 | { |
---|
| 189 | $accounts = CreateObject('phpgwapi.accounts'); |
---|
| 190 | $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid'])); |
---|
| 191 | |
---|
| 192 | if($prefs->account_id) |
---|
| 193 | { |
---|
| 194 | $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository(); |
---|
| 195 | } |
---|
| 196 | } |
---|
[1934] | 197 | |
---|
| 198 | $_GET['lang'] = addslashes($_GET['lang']); |
---|
[1718] | 199 | if ($_GET['lang']) |
---|
| 200 | { |
---|
| 201 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang']; |
---|
| 202 | } |
---|
| 203 | elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id) |
---|
| 204 | { |
---|
| 205 | // If the lastloginid cookies isn't set, we will default to the first language, |
---|
| 206 | // the users browser accepts. |
---|
| 207 | list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
---|
| 208 | /* |
---|
| 209 | if(strlen($lang) > 2) |
---|
| 210 | { |
---|
| 211 | $lang = substr($lang,0,2); |
---|
| 212 | } |
---|
| 213 | */ |
---|
| 214 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang; |
---|
| 215 | } |
---|
| 216 | #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>'; |
---|
| 217 | |
---|
| 218 | $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs |
---|
| 219 | $GLOBALS['phpgw']->translation->add_app('login'); |
---|
| 220 | $GLOBALS['phpgw']->translation->add_app('loginscreen'); |
---|
| 221 | if(lang('loginscreen_message') == 'loginscreen_message*') |
---|
| 222 | { |
---|
| 223 | $GLOBALS['phpgw']->translation->add_app('loginscreen','en'); // trying the en one |
---|
| 224 | } |
---|
| 225 | if(lang('loginscreen_message') != 'loginscreen_message*') |
---|
| 226 | { |
---|
| 227 | $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message'))); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | if($GLOBALS['phpgw_info']['server']['use_prefix_organization']) |
---|
| 232 | { |
---|
| 233 | $organization_select = "<tr><td width=\"96\" class=\"loginLabel\">"; |
---|
| 234 | $organization_select .= lang("organization").": </td>"; |
---|
| 235 | $organization_select .= "<td width=\"135\">"; |
---|
| 236 | $organization_select .= "<select name=\"organization\">\n"; |
---|
| 237 | |
---|
| 238 | $obj_organization = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 239 | $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']); |
---|
| 240 | |
---|
| 241 | for ($i=0; $i<count($organizations); $i++) |
---|
| 242 | { |
---|
| 243 | $tmp_array[strtolower($organizations[$i])] = $organizations[$i]; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | $arrayOrganization = $tmp_array; |
---|
| 247 | ksort($arrayOrganization); |
---|
| 248 | |
---|
| 249 | foreach($arrayOrganization |
---|
| 250 | as $organization_name => $organization_vars) |
---|
| 251 | { |
---|
| 252 | $organization_select .= '<option value="' . $organization_name . '"'; |
---|
| 253 | |
---|
| 254 | if($organization_name == $_COOKIE['last_organization']) |
---|
| 255 | { |
---|
| 256 | $organization_select .= ' selected'; |
---|
| 257 | } |
---|
| 258 | $organization_select .= '>' . $organization_vars . "</option>\n"; |
---|
| 259 | } |
---|
| 260 | $organization_select .= "</select>\n"; |
---|
| 261 | $organization_select .="</td><td> </td></tr>"; |
---|
| 262 | $tmpl->set_var('select_organization',$organization_select); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | $domain_select = ' '; |
---|
| 266 | $last_loginid = $_COOKIE['last_loginid']; |
---|
| 267 | if($GLOBALS['phpgw_info']['server']['show_domain_selectbox']) |
---|
| 268 | { |
---|
| 269 | $domain_select = "<select name=\"logindomain\">\n"; |
---|
| 270 | foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars) |
---|
| 271 | { |
---|
| 272 | $domain_select .= '<option value="' . $domain_name . '"'; |
---|
| 273 | |
---|
| 274 | if($domain_name == $_COOKIE['last_domain']) |
---|
| 275 | { |
---|
| 276 | $domain_select .= ' selected'; |
---|
| 277 | } |
---|
| 278 | $domain_select .= '>' . $domain_name . "</option>\n"; |
---|
| 279 | } |
---|
| 280 | $domain_select .= "</select>\n"; |
---|
| 281 | } |
---|
| 282 | elseif($last_loginid !== '') |
---|
| 283 | { |
---|
| 284 | reset($GLOBALS['phpgw_domain']); |
---|
| 285 | list($default_domain) = each($GLOBALS['phpgw_domain']); |
---|
| 286 | |
---|
| 287 | if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain'])) |
---|
| 288 | { |
---|
| 289 | $last_loginid .= '@' . $_COOKIE['last_domain']; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | $tmpl->set_var('select_domain',$domain_select); |
---|
| 293 | |
---|
| 294 | foreach($_GET as $name => $value) |
---|
| 295 | { |
---|
| 296 | if(ereg('phpgw_',$name)) |
---|
| 297 | { |
---|
| 298 | $extra_vars .= '&' . $name . '=' . urlencode($value); |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | if($extra_vars) |
---|
| 303 | { |
---|
| 304 | $extra_vars = '?' . substr($extra_vars,1); |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | /********************************************************\ |
---|
| 308 | * Check is the registration app is installed, activated * |
---|
| 309 | * And if the register link must be placed * |
---|
| 310 | \********************************************************/ |
---|
| 311 | |
---|
| 312 | $cnf_reg = createobject('phpgwapi.config','registration'); |
---|
| 313 | $cnf_reg->read_repository(); |
---|
| 314 | $config_reg = $cnf_reg->config_data; |
---|
| 315 | |
---|
| 316 | if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True') |
---|
| 317 | { |
---|
| 318 | $reg_link=' <a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>'; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set']; |
---|
| 322 | |
---|
| 323 | $tmpl->set_var('register_link',$reg_link); |
---|
| 324 | $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset()); |
---|
| 325 | $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars); |
---|
| 326 | $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/'); |
---|
| 327 | $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']); |
---|
| 328 | $tmpl->set_var('cd',check_logoutcode($_GET['cd'])); |
---|
| 329 | $tmpl->set_var('cookie',$last_loginid); |
---|
| 330 | |
---|
| 331 | $tmpl->set_var('lang_username',lang('username')); |
---|
| 332 | $tmpl->set_var('lang_password',lang('password')); |
---|
| 333 | $tmpl->set_var('lang_login',lang('login')); |
---|
| 334 | |
---|
| 335 | $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']); |
---|
| 336 | $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']); |
---|
[1863] | 337 | $GLOBALS['phpgw']->translation->add_app('loginhelp',$_GET['lang']); |
---|
| 338 | if(lang('loginhelp_message') != 'loginhelp_message*' && trim(lang('loginhelp_message')) != ""){ |
---|
| 339 | $tmpl->set_var('lang_help',lang("Help")); |
---|
| 340 | } |
---|
| 341 | else |
---|
| 342 | $tmpl->set_var('display_help','none'); |
---|
[1718] | 343 | $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF')); |
---|
| 344 | $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591')); |
---|
| 345 | |
---|
| 346 | if($GLOBALS['phpgw_info']['server']['use_frontend_name']) |
---|
| 347 | $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']); |
---|
| 348 | |
---|
| 349 | if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http') |
---|
| 350 | { |
---|
| 351 | $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file']; |
---|
| 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo'); |
---|
| 356 | } |
---|
| 357 | $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org'; |
---|
| 358 | if (substr($var['logo_url'],0,4) != 'http') |
---|
| 359 | { |
---|
| 360 | $var['logo_url'] = 'http://'.$var['logo_url']; |
---|
| 361 | } |
---|
| 362 | $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org'; |
---|
| 363 | $tmpl->set_var($var); |
---|
| 364 | |
---|
| 365 | if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection']) |
---|
| 366 | { |
---|
| 367 | $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">'; |
---|
| 368 | $langs = $GLOBALS['phpgw']->translation->get_installed_langs(); |
---|
| 369 | uasort($langs,'strcasecmp'); |
---|
| 370 | foreach ($langs as $key => $name) // if we have a translation use it |
---|
| 371 | { |
---|
| 372 | $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>'; |
---|
| 373 | } |
---|
| 374 | $select_lang .= "\n</select>\n"; |
---|
| 375 | $tmpl->set_var(array( |
---|
| 376 | 'lang_language' => lang('Language'), |
---|
| 377 | 'select_language' => $select_lang, |
---|
| 378 | )); |
---|
| 379 | } |
---|
| 380 | else |
---|
| 381 | { |
---|
| 382 | $tmpl->set_block('login_form','language_select'); |
---|
| 383 | $tmpl->set_var('language_select',''); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : '')); |
---|
| 387 | |
---|
| 388 | $tmpl->pfp('loginout','login_form'); |
---|
| 389 | ?> |
---|