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