source: trunk/login.php @ 35

Revision 35, 16.2 KB checked in by niltonneto, 17 years ago (diff)

Melhoria na segurança, na parte de alteração de senha.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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        $phpgw_info = array();
15        $submit = False;                        // set to some initial value
16
17        $GLOBALS['phpgw_info']['flags'] = array(
18                'disable_Template_class' => True,
19                'login'                  => True,
20                'currentapp'             => 'login',
21                'noheader'               => True
22        );
23
24        if(file_exists('./header.inc.php'))
25        {
26                include('./header.inc.php');
27                if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)
28                {
29                        if ($_SERVER['HTTPS'] != 'on')
30                        {
31                                Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
32                                exit;
33                        }
34                }
35                       
36                if(function_exists('CreateObject'))
37                {
38                        $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
39                }
40                else
41                {
42                        Header('Location: setup/index.php');
43                        exit;
44                }
45        }
46        else
47        {
48                Header('Location: setup/index.php');
49                exit;
50        }
51
52        $GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['login_template_set'];
53        $tmpl = CreateObject('phpgwapi.Template', $GLOBALS['phpgw_info']['server']['template_dir']);
54
55        // read the images from the login-template-set, not the (maybe not even set) users template-set
56        $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
57
58        // This is used for system downtime, to prevent new logins.
59        if($GLOBALS['phpgw_info']['server']['deny_all_logins'])
60        {
61                $deny_msg=lang('Oops! You caught us in the middle of system maintainance.<br/>
62                Please, check back with us shortly.');
63
64                $tmpl->set_file(array
65                (
66                        'login_form' => 'login_denylogin.tpl'
67                ));
68
69                $tmpl->set_var('template_set','default');
70                $tmpl->set_var('deny_msg',$deny_msg);
71                $tmpl->pfp('loginout','login_form');
72                exit;
73        }
74        $tmpl->set_file(array('login_form' => 'login.tpl'));
75
76        // !! NOTE !!
77        // Do NOT and I repeat, do NOT touch ANYTHING to do with lang in this file.
78        // If there is a problem, tell me and I will fix it. (jengo)
79
80        // whoooo scaring
81
82        // ServerID => Identify the Apache Frontend.
83        if($GLOBALS['phpgw_info']['server']['usecookies'] == True && $GLOBALS['phpgw_info']['server']['use_frontend_id'])
84        {
85                $GLOBALS['phpgw']->session->phpgw_setcookie('serverID', $GLOBALS['phpgw_info']['server']['use_frontend_id']);
86        }
87
88
89        function check_logoutcode($code)
90        {
91                switch($code)
92                {
93                        case 1:
94                                return lang('You have been successfully logged out');
95                               
96                        case 2:
97                                return lang('Sorry, your login has expired');
98                               
99                        case 4:
100                                return lang('Cookies are required to login to this site.');
101                               
102                        case 5:
103                                return '<font color="FF0000">' . lang('Bad login or password') . '</font>';
104                               
105                        case 98:
106                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
107                               
108                        case 99:
109                                return '<font color="FF0000">' . lang('Blocked, too many attempts') . '</font>';
110                               
111                        case 10:
112                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
113                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
114                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
115
116                                //fix for bug php4 expired sessions bug
117                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4')
118                                {
119                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
120                                }
121
122                                return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>';
123                               
124                        default:
125                                return '&nbsp;';
126                }
127        }
128       
129        /* Program starts here */
130
131        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
132        {
133                $submit = True;
134                $login  = $_SERVER['PHP_AUTH_USER'];
135                $passwd = $_SERVER['PHP_AUTH_PW'];
136                $passwd_type = 'text';
137        }
138        else
139        {
140                $passwd = $_POST['passwd'];
141                $passwd_type = $_POST['passwd_type'];
142        }
143
144        # Apache + mod_ssl style SSL certificate authentication
145        # Certificate (chain) verification occurs inside mod_ssl
146        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
147        {
148                # an X.509 subject looks like:
149                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
150                # the username is deliberately lowercase, to ease LDAP integration
151                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
152                # skip the part in front of the first '/' (nothing)
153                while($sslattrib = next($sslattribs))
154                {
155                        list($key,$val) = explode('=',$sslattrib);
156                        $sslattributes[$key] = $val;
157                }
158
159                if(isset($sslattributes['Email']))
160                {
161                        $submit = True;
162
163                        # login will be set here if the user logged out and uses a different username with
164                        # the same SSL-certificate.
165                        if(!isset($_POST['login'])&&isset($sslattributes['Email']))
166                        {
167                                $login = $sslattributes['Email'];
168                                # not checked against the database, but delivered to authentication module
169                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
170                        }
171                }
172                unset($key);
173                unset($val);
174                unset($sslattributes);
175        }
176
177        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
178        {
179/////   Início - Código temporário: Para renomeação de login com organização para sem. //////
180/*              $common = CreateObject('phpgwapi.common');
181                $ldap_conn = $common->ldapConnect();
182                $justthese = array("uid");
183                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
184                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
185                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
186                if ($ldap_info['count'] != 0) // Verifica se o login existe sem organização.
187                {
188                        $_POST['login'] = $_POST['user'];
189                }
190                ldap_close($ldap_conn);*/
191///     Fim - Código temporário: Para renomeação de login com organização para sem. //////
192                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
193                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
194                {
195                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
196                }
197               
198                // don't get login data again when $submit is true
199                if($submit == false)
200                {
201                        $login = $_POST['login'];
202                }
203               
204                if(strstr($login,'@') === False && isset($_POST['logindomain']))
205                {
206                        $login .= '@' . $_POST['logindomain'];
207                }
208                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
209                {
210                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
211                }
212                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
213
214                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
215                {
216                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
217                }
218                else
219                {
220                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
221                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
222                        {
223                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
224                        }
225
226                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
227                        {
228                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
229                        }
230                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
231                        if (!$forward)
232                        {
233                                $extra_vars['cd'] = 'yes';
234                                $forward = '/home.php';
235                        }
236                        else
237                        {
238                                list($forward,$extra_vars) = explode('?',$forward,2);
239                        }
240                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
241                        {
242                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
243                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
244                        }
245                        else
246                        {
247                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
248                        }
249                }
250        }
251        else
252        {
253                // !!! DONT CHANGE THESE LINES !!!
254                // If there is something wrong with this code TELL ME!
255                // Commenting out the code will not fix it. (jengo)
256                if(isset($_COOKIE['last_loginid']))
257                {
258                        $accounts = CreateObject('phpgwapi.accounts');
259                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
260
261                        if($prefs->account_id)
262                        {
263                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
264                        }
265                }
266                if ($_GET['lang'])
267                {
268                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
269                }
270                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
271                {
272                        // If the lastloginid cookies isn't set, we will default to the first language,
273                        // the users browser accepts.
274                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
275                        /*
276                        if(strlen($lang) > 2)
277                        {
278                                $lang = substr($lang,0,2);
279                        }
280                        */
281                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
282                }
283                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
284
285                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
286                $GLOBALS['phpgw']->translation->add_app('login');
287                $GLOBALS['phpgw']->translation->add_app('loginscreen');
288                if(lang('loginscreen_message') == 'loginscreen_message*')
289                {
290                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
291                }
292                if(lang('loginscreen_message') != 'loginscreen_message*')
293                {
294                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
295                }
296        }
297
298        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
299        {
300//              Início - Temporário: Para período de adaptação dos usuários, usando sem organização.
301//              $organization_select =  "<tr><td width='96' class='loginLabel' align='right'>".lang("organization").":&nbsp;</td>".
302//              $organization_select .= "<td align='left' style='font-weight:bold' class='loginLabel' colspan=2><a style='font-weight:normal;font-decoration:none;text-decoration:none' href='javascript:void(0)' onclick='alert(\"Não é preciso mais selecionar a Organização.\\r\\n Digite apenas o usuário e a senha!\")' onmouseover='this.style.cursor=\"help\"'> automático</a></td></tr>";
303//              Fim - Temporário: Para período de adaptação dos usuários, usando sem organização.               
304                $organization_select = "<tr><td width=\"66\" class=\"loginLabel\">";
305                $organization_select .= lang("organization").":</td>";
306                $organization_select .="<td width=\"135\">";                                                                                   
307                $organization_select .="<select name=\"organization\">\n";             
308               
309                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
310                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
311               
312                for ($i=0; $i<count($organizations); $i++)
313                {
314                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
315                }
316               
317                $arrayOrganization = $tmp_array;               
318                ksort($arrayOrganization);
319               
320                foreach($arrayOrganization
321                         as $organization_name => $organization_vars)
322                {
323                        $organization_select .= '<option value="' . $organization_name . '"';
324
325                        if($organization_name == $_COOKIE['last_organization'])
326                        {
327                                $organization_select .= ' selected';
328                        }
329                        $organization_select .= '>' . $organization_vars . "</option>\n";
330                }
331                $organization_select .= "</select>\n";
332                $organization_select .="</td><td>&nbsp;</td></tr>";
333                $tmpl->set_var('select_organization',$organization_select);
334        }
335               
336        $domain_select = '&nbsp;';
337        $last_loginid = $_COOKIE['last_loginid'];
338        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
339        {
340                $domain_select = "<select name=\"logindomain\">\n";
341                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
342                {
343                        $domain_select .= '<option value="' . $domain_name . '"';
344
345                        if($domain_name == $_COOKIE['last_domain'])
346                        {
347                                $domain_select .= ' selected';
348                        }
349                        $domain_select .= '>' . $domain_name . "</option>\n";
350                }
351                $domain_select .= "</select>\n";
352        }
353        elseif($last_loginid !== '')
354        {
355                reset($GLOBALS['phpgw_domain']);
356                list($default_domain) = each($GLOBALS['phpgw_domain']);
357
358                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
359                {
360                        $last_loginid .= '@' . $_COOKIE['last_domain'];
361                }
362        }
363        $tmpl->set_var('select_domain',$domain_select);
364
365        foreach($_GET as $name => $value)
366        {
367                if(ereg('phpgw_',$name))
368                {
369                        $extra_vars .= '&' . $name . '=' . urlencode($value);
370                }
371        }
372
373        if($extra_vars)
374        {
375                $extra_vars = '?' . substr($extra_vars,1);
376        }
377
378        /********************************************************\
379        * Check is the registration app is installed, activated  *
380        * And if the register link must be placed                *
381        \********************************************************/
382       
383        $cnf_reg = createobject('phpgwapi.config','registration');
384        $cnf_reg->read_repository();
385        $config_reg = $cnf_reg->config_data;
386
387        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
388        {
389                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
390        }
391
392        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
393
394        $tmpl->set_var('register_link',$reg_link);
395        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
396        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
397        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
398        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
399        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
400        $tmpl->set_var('cookie',$last_loginid);
401
402        $tmpl->set_var('lang_username',lang('username'));
403        $tmpl->set_var('lang_password',lang('password'));
404        $tmpl->set_var('lang_login',lang('login'));
405
406        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
407        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
408        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
409        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
410
411        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
412                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
413
414        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
415        {
416                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
417        }
418        else
419        {
420                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
421        }
422        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
423        if (substr($var['logo_url'],0,4) != 'http')
424        {
425                $var['logo_url'] = 'http://'.$var['logo_url'];
426        }
427        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
428        $tmpl->set_var($var);
429
430        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
431        {
432                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
433                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
434                uasort($langs,'strcasecmp');
435                foreach ($langs as $key => $name)       // if we have a translation use it
436                {
437                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
438                }
439                $select_lang .= "\n</select>\n";
440                $tmpl->set_var(array(
441                        'lang_language' => lang('Language'),
442                        'select_language' => $select_lang,
443                ));
444        }
445        else
446        {
447                $tmpl->set_block('login_form','language_select');
448                $tmpl->set_var('language_select','');
449        }
450
451        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
452
453        $tmpl->pfp('loginout','login_form');
454?>
Note: See TracBrowser for help on using the repository browser.