[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 | ); |
---|
[4116] | 14 | |
---|
[1851] | 15 | include('../header.inc.php'); |
---|
| 16 | include('./mobile_header.inc.php'); |
---|
[454] | 17 | $GLOBALS['sessionid'] = @$_GET['sessionid'] ? $_GET['sessionid'] : @$_COOKIE['sessionid']; |
---|
[4116] | 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); |
---|
[4116] | 46 | //detect if the user has a mobile browser |
---|
| 47 | |
---|
| 48 | $browser = CreateObject('mobile.browser'); |
---|
| 49 | |
---|
| 50 | switch ($browser->get_platform()) { |
---|
| 51 | case browser::PLATFORM_IPHONE: |
---|
| 52 | case browser::PLATFORM_IPOD: |
---|
| 53 | case browser::PLATFORM_IPAD: |
---|
| 54 | case browser::PLATFORM_BLACKBERRY: |
---|
| 55 | case browser::PLATFORM_NOKIA: |
---|
| 56 | case browser::PLATFORM_ANDROID: |
---|
| 57 | $tmpl->set_var('os_browser',$browser->get_platform()); |
---|
| 58 | break; |
---|
| 59 | default: |
---|
| 60 | $tmpl->set_var('os_browser',false); |
---|
| 61 | //$tmpl->set_var('os_browser',$browser->get_platform()); |
---|
| 62 | break; |
---|
| 63 | } |
---|
[1851] | 64 | |
---|
[454] | 65 | function check_logoutcode($code) { |
---|
| 66 | switch($code) { |
---|
| 67 | case 1: |
---|
| 68 | logout(); |
---|
| 69 | return lang('You have been successfully logged out'); |
---|
[4116] | 70 | |
---|
[454] | 71 | case 2: |
---|
| 72 | return lang('Sorry, your login has expired'); |
---|
[4116] | 73 | |
---|
[454] | 74 | case 4: |
---|
| 75 | return lang('Cookies are required to login to this site.'); |
---|
[4116] | 76 | |
---|
[454] | 77 | case 5: |
---|
[3553] | 78 | return lang('Bad login or password'); |
---|
[454] | 79 | case 6: |
---|
[3553] | 80 | return lang('Your password has expired, and you do not have access to change it'); |
---|
[454] | 81 | case 98: |
---|
[3553] | 82 | return lang('Account is expired'); |
---|
[454] | 83 | case 99: |
---|
[3553] | 84 | return lang('Blocked, too many attempts'); |
---|
[454] | 85 | case 10: |
---|
| 86 | $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid'); |
---|
| 87 | $GLOBALS['phpgw']->session->phpgw_setcookie('kp3'); |
---|
| 88 | $GLOBALS['phpgw']->session->phpgw_setcookie('domain'); |
---|
| 89 | if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4') { |
---|
| 90 | $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID); |
---|
| 91 | } |
---|
[3553] | 92 | return lang('Your session could not be verified.'); |
---|
[454] | 93 | default: |
---|
[3553] | 94 | return ''; |
---|
[454] | 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER'])) { |
---|
| 99 | $submit = True; |
---|
| 100 | $login = $_SERVER['PHP_AUTH_USER']; |
---|
| 101 | $passwd = $_SERVER['PHP_AUTH_PW']; |
---|
| 102 | $passwd_type = 'text'; |
---|
| 103 | } |
---|
[4116] | 104 | // Automatic login from browser cookies |
---|
| 105 | elseif(get_var('lem',array('GET','COOKIE')) && get_var('pem',array('GET','COOKIE'))) |
---|
| 106 | { |
---|
| 107 | if(!$_GET['cd'] || $_GET['cd'] == '1' || $_GET['cd'] == '10') { |
---|
| 108 | $submit = True; |
---|
| 109 | $login = base64_decode(get_var('lem',array('GET','COOKIE'))); |
---|
| 110 | $passwd = base64_decode(get_var('pem',array('GET','COOKIE'))); |
---|
| 111 | $passwd_type = 'text'; |
---|
| 112 | } |
---|
| 113 | else { |
---|
| 114 | $GLOBALS['phpgw']->session->phpgw_setcookie('lem'); |
---|
| 115 | $GLOBALS['phpgw']->session->phpgw_setcookie('pem'); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
[454] | 119 | else { |
---|
| 120 | $passwd = $_POST['passwd']; |
---|
| 121 | $passwd_type = $_POST['passwd_type']; |
---|
| 122 | } |
---|
| 123 | |
---|
[4116] | 124 | if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) |
---|
| 125 | { |
---|
| 126 | if( !get_var('pem',array('GET','COOKIE')) && getenv('REQUEST_METHOD') != 'POST' |
---|
| 127 | && $_SERVER['REQUEST_METHOD'] != 'POST' && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN'])) |
---|
| 128 | { |
---|
[454] | 129 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link($GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php','cd=5')); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | if(!$submit) |
---|
[4116] | 133 | { |
---|
[454] | 134 | $login = $_POST['login']; |
---|
[4116] | 135 | } |
---|
[454] | 136 | |
---|
| 137 | $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u'); |
---|
| 138 | |
---|
| 139 | if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid']){ |
---|
| 140 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason); |
---|
| 141 | } |
---|
[4116] | 142 | else |
---|
| 143 | { |
---|
| 144 | if(isset($_POST['max_resolution']) && $_POST['max_resolution'] > 600) |
---|
| 145 | { |
---|
[3731] | 146 | $GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app'] = 'mobilemail'; |
---|
| 147 | $GLOBALS['phpgw']->session->appsession('mobile.layout','mobile','mini_desktop'); |
---|
[4116] | 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
[3731] | 151 | $GLOBALS['phpgw']->session->appsession('mobile.layout','mobile','mini_mobile'); |
---|
| 152 | } |
---|
| 153 | |
---|
[3892] | 154 | $preferences = $GLOBALS['phpgw']->preferences->read(); |
---|
| 155 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail'] = $preferences['expressoMail']; |
---|
| 156 | |
---|
[4116] | 157 | if($_POST['save_login'] == 'yes') |
---|
| 158 | { |
---|
| 159 | // Time to keep values into cookies |
---|
| 160 | $ttl = time()+15552000; // Six Months |
---|
| 161 | $GLOBALS['phpgw']->session->phpgw_setcookie('lem', base64_encode(strtolower($login)),$ttl); // lem = login |
---|
| 162 | $GLOBALS['phpgw']->session->phpgw_setcookie('pem', base64_encode($passwd), $ttl); // pem = password |
---|
| 163 | } |
---|
[623] | 164 | start_prefered_app(); |
---|
[454] | 165 | } |
---|
| 166 | } |
---|
| 167 | elseif ($_GET['lang']) { |
---|
| 168 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang']; |
---|
| 169 | } |
---|
| 170 | elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id) { |
---|
| 171 | list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
---|
| 172 | $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset()); |
---|
| 176 | $tmpl->set_var('cookie',$last_loginid); |
---|
[3553] | 177 | $tmpl->set_var('lang_username', lang('username')); |
---|
| 178 | $tmpl->set_var('lang_password', lang('password')); |
---|
| 179 | $tmpl->set_var('lang_login', lang('login')); |
---|
| 180 | $tmpl->set_var('lang_notices', lang('notices')); |
---|
[454] | 181 | $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']); |
---|
| 182 | $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']); |
---|
| 183 | $tmpl->set_var('language_select',''); |
---|
| 184 | $tmpl->set_var($var); |
---|
| 185 | $tmpl->set_block('login_form','language_select'); |
---|
[3553] | 186 | $tmpl->pfp('loginout','page'); |
---|
[454] | 187 | |
---|
[4116] | 188 | function logout() |
---|
| 189 | { |
---|
[454] | 190 | $verified = $GLOBALS['phpgw']->session->verify(); |
---|
| 191 | if ($verified) |
---|
| 192 | { |
---|
| 193 | if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid'])) |
---|
| 194 | { |
---|
| 195 | $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']); |
---|
| 196 | while ($file = readdir($dh)) |
---|
| 197 | { |
---|
| 198 | if ($file != '.' && $file != '..') |
---|
| 199 | { |
---|
| 200 | unlink($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid'] . SEP . $file); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | rmdir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']); |
---|
| 204 | } |
---|
| 205 | $GLOBALS['phpgw']->hooks->process('logout'); |
---|
| 206 | $GLOBALS['phpgw']->session->destroy($GLOBALS['sessionid'],$GLOBALS['kp3']); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | ?> |
---|