[454] | 1 | <?php |
---|
| 2 | //TODO: Trocar name="login" para name="user" no campo username |
---|
[3492] | 3 | |
---|
[454] | 4 | $phpgw_info = array(); |
---|
| 5 | $submit = False; |
---|
| 6 | |
---|
| 7 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 8 | 'disable_Template_class' => True, |
---|
| 9 | 'login' => True, |
---|
| 10 | 'currentapp' => 'login', |
---|
| 11 | 'currentdir' => '/mobile', |
---|
| 12 | 'noheader' => True |
---|
| 13 | ); |
---|
[1851] | 14 | |
---|
| 15 | include('../header.inc.php'); |
---|
| 16 | include('./mobile_header.inc.php'); |
---|
[454] | 17 | $GLOBALS['sessionid'] = @$_GET['sessionid'] ? $_GET['sessionid'] : @$_COOKIE['sessionid']; |
---|
[1851] | 18 | |
---|
[454] | 19 | if(isset($GLOBALS['sessionid']) && $_GET['cd'] != 10 && $_GET['cd'] != 1) |
---|
[1851] | 20 | start_prefered_app(); |
---|
[3553] | 21 | |
---|
| 22 | if ($GLOBALS['phpgw_info']['server']['use_https'] > 0) { |
---|
| 23 | if ($_SERVER['HTTPS'] != 'on') { |
---|
| 24 | $proxies=explode(',',$_SERVER['HTTP_X_FORWARDED_HOST']); |
---|
| 25 | $fwConstruct = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $proxies[0] : $_SERVER['HTTP_HOST']; |
---|
[1851] | 26 | Header('Location: https://' . $fwConstruct . '/' . $_SERVER['REQUEST_URI']); |
---|
[454] | 27 | exit; |
---|
[3553] | 28 | } |
---|
[454] | 29 | } |
---|
[1851] | 30 | |
---|
| 31 | $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions'); |
---|
| 32 | $GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT.$GLOBALS['phpgw_info']['flags']['currentdir'].'/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']; |
---|
[3483] | 33 | $tmpl = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
[454] | 34 | $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set']; |
---|
| 35 | $tmpl->set_file(array('login_form' => 'login.tpl')); |
---|
[3553] | 36 | $tmpl->set_block('login_form','page'); |
---|
| 37 | $tmpl->set_block('login_form','success_message'); |
---|
| 38 | $tmpl->set_block('login_form','error_message'); |
---|
| 39 | |
---|
| 40 | //verificando a mensagem erro ou sucesso |
---|
| 41 | $cd = check_logoutcode($_GET['cd']); |
---|
[3571] | 42 | $tmpl->set_var('message', $cd); |
---|
[3553] | 43 | |
---|
| 44 | if(trim($cd) != "") |
---|
[3571] | 45 | $tmpl->parse('message_box', (($_GET['cd'] == 1) ? 'success_message' : 'error_message') ,true); |
---|
[3553] | 46 | |
---|
[3484] | 47 | $tmpl->set_var('css',CreateObject("mobile.mobiletemplate")->get_mobile_css()); |
---|
[1851] | 48 | |
---|
[454] | 49 | function check_logoutcode($code) { |
---|
| 50 | switch($code) { |
---|
| 51 | case 1: |
---|
| 52 | logout(); |
---|
| 53 | return lang('You have been successfully logged out'); |
---|
| 54 | case 2: |
---|
| 55 | return lang('Sorry, your login has expired'); |
---|
| 56 | case 4: |
---|
| 57 | return lang('Cookies are required to login to this site.'); |
---|
| 58 | case 5: |
---|
[3553] | 59 | return lang('Bad login or password'); |
---|
[454] | 60 | case 6: |
---|
[3553] | 61 | return lang('Your password has expired, and you do not have access to change it'); |
---|
[454] | 62 | case 98: |
---|
[3553] | 63 | return lang('Account is expired'); |
---|
[454] | 64 | case 99: |
---|
[3553] | 65 | return lang('Blocked, too many attempts'); |
---|
[454] | 66 | case 10: |
---|
| 67 | $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid'); |
---|
| 68 | $GLOBALS['phpgw']->session->phpgw_setcookie('kp3'); |
---|
| 69 | $GLOBALS['phpgw']->session->phpgw_setcookie('domain'); |
---|
| 70 | if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4') { |
---|
| 71 | $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID); |
---|
| 72 | } |
---|
[3553] | 73 | return lang('Your session could not be verified.'); |
---|
[454] | 74 | default: |
---|
[3553] | 75 | return ''; |
---|
[454] | 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER'])) { |
---|
| 80 | $submit = True; |
---|
| 81 | $login = $_SERVER['PHP_AUTH_USER']; |
---|
| 82 | $passwd = $_SERVER['PHP_AUTH_PW']; |
---|
| 83 | $passwd_type = 'text'; |
---|
| 84 | } |
---|
| 85 | else { |
---|
| 86 | $passwd = $_POST['passwd']; |
---|
| 87 | $passwd_type = $_POST['passwd_type']; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) { |
---|
| 91 | if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' && |
---|
| 92 | !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN'])){ |
---|
| 93 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link($GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php','cd=5')); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | if(!$submit) |
---|
| 97 | $login = $_POST['login']; |
---|
| 98 | |
---|
| 99 | $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u'); |
---|
| 100 | |
---|
| 101 | if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid']){ |
---|
| 102 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason); |
---|
| 103 | } |
---|
[1851] | 104 | else{ |
---|
[623] | 105 | start_prefered_app(); |
---|
[454] | 106 | } |
---|
| 107 | } |
---|
| 108 | elseif ($_GET['lang']) { |
---|
| 109 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang']; |
---|
| 110 | } |
---|
| 111 | elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id) { |
---|
| 112 | list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
---|
| 113 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset()); |
---|
| 117 | $tmpl->set_var('cookie',$last_loginid); |
---|
[3553] | 118 | $tmpl->set_var('lang_username', lang('username')); |
---|
| 119 | $tmpl->set_var('lang_password', lang('password')); |
---|
| 120 | $tmpl->set_var('lang_login', lang('login')); |
---|
| 121 | $tmpl->set_var('lang_notices', lang('notices')); |
---|
[454] | 122 | $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']); |
---|
| 123 | $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']); |
---|
| 124 | $tmpl->set_var('language_select',''); |
---|
| 125 | $tmpl->set_var($var); |
---|
| 126 | $tmpl->set_block('login_form','language_select'); |
---|
[3553] | 127 | $tmpl->pfp('loginout','page'); |
---|
[454] | 128 | |
---|
[1851] | 129 | function logout(){ |
---|
[454] | 130 | $verified = $GLOBALS['phpgw']->session->verify(); |
---|
| 131 | if ($verified) |
---|
| 132 | { |
---|
| 133 | if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid'])) |
---|
| 134 | { |
---|
| 135 | $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']); |
---|
| 136 | while ($file = readdir($dh)) |
---|
| 137 | { |
---|
| 138 | if ($file != '.' && $file != '..') |
---|
| 139 | { |
---|
| 140 | unlink($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid'] . SEP . $file); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | rmdir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']); |
---|
| 144 | } |
---|
| 145 | $GLOBALS['phpgw']->hooks->process('logout'); |
---|
| 146 | $GLOBALS['phpgw']->session->destroy($GLOBALS['sessionid'],$GLOBALS['kp3']); |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | ?> |
---|