source: trunk/login.php @ 72

Revision 72, 15.7 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • 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 6:
106                                return '<font color="FF0000">' . lang('Your password has expired, and you do not have access to change it') . '</font>';
107                               
108                        case 98:
109                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
110                               
111                        case 99:
112                                return '<font color="FF0000">' . lang('Blocked, too many attempts') . '</font>';
113                               
114                        case 10:
115                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
116                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
117                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
118
119                                //fix for bug php4 expired sessions bug
120                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4')
121                                {
122                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
123                                }
124
125                                return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>';
126                               
127                        default:
128                                return '&nbsp;';
129                }
130        }
131       
132        /* Program starts here */
133
134        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
135        {
136                $submit = True;
137                $login  = $_SERVER['PHP_AUTH_USER'];
138                $passwd = $_SERVER['PHP_AUTH_PW'];
139                $passwd_type = 'text';
140        }
141        else
142        {
143                $passwd = $_POST['passwd'];
144                $passwd_type = $_POST['passwd_type'];
145        }
146
147        # Apache + mod_ssl style SSL certificate authentication
148        # Certificate (chain) verification occurs inside mod_ssl
149        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
150        {
151                # an X.509 subject looks like:
152                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
153                # the username is deliberately lowercase, to ease LDAP integration
154                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
155                # skip the part in front of the first '/' (nothing)
156                while($sslattrib = next($sslattribs))
157                {
158                        list($key,$val) = explode('=',$sslattrib);
159                        $sslattributes[$key] = $val;
160                }
161
162                if(isset($sslattributes['Email']))
163                {
164                        $submit = True;
165
166                        # login will be set here if the user logged out and uses a different username with
167                        # the same SSL-certificate.
168                        if(!isset($_POST['login'])&&isset($sslattributes['Email']))
169                        {
170                                $login = $sslattributes['Email'];
171                                # not checked against the database, but delivered to authentication module
172                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
173                        }
174                }
175                unset($key);
176                unset($val);
177                unset($sslattributes);
178        }
179
180        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
181        {
182/////   Início - Código temporário: Para renomeação de login com organização para sem. //////
183/*              $common = CreateObject('phpgwapi.common');
184                $ldap_conn = $common->ldapConnect();
185                $justthese = array("uid");
186                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
187                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
188                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
189                if ($ldap_info['count'] != 0) // Verifica se o login existe sem organização.
190                {
191                        $_POST['login'] = $_POST['user'];
192                }
193                ldap_close($ldap_conn);*/
194///     Fim - Código temporário: Para renomeação de login com organização para sem. //////
195                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
196                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
197                {
198                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
199                }
200               
201                // don't get login data again when $submit is true
202                if($submit == false)
203                {
204                        $login = $_POST['login'];
205                }
206               
207                if(strstr($login,'@') === False && isset($_POST['logindomain']))
208                {
209                        $login .= '@' . $_POST['logindomain'];
210                }
211                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
212                {
213                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
214                }
215                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
216
217                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
218                {
219                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
220                }
221                else
222                {
223                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
224                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
225                        {
226                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
227                        }
228
229                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
230                        {
231                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
232                        }
233                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
234                        if (!$forward)
235                        {
236                                $extra_vars['cd'] = 'yes';
237                                $forward = '/home.php';
238                        }
239                        else
240                        {
241                                list($forward,$extra_vars) = explode('?',$forward,2);
242                        }
243                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
244                        {
245                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
246                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
247                        }
248                        else
249                        {
250                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
251                        }
252                }
253        }
254        else
255        {
256                // !!! DONT CHANGE THESE LINES !!!
257                // If there is something wrong with this code TELL ME!
258                // Commenting out the code will not fix it. (jengo)
259                if(isset($_COOKIE['last_loginid']))
260                {
261                        $accounts = CreateObject('phpgwapi.accounts');
262                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
263
264                        if($prefs->account_id)
265                        {
266                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
267                        }
268                }
269                if ($_GET['lang'])
270                {
271                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
272                }
273                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
274                {
275                        // If the lastloginid cookies isn't set, we will default to the first language,
276                        // the users browser accepts.
277                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
278                        /*
279                        if(strlen($lang) > 2)
280                        {
281                                $lang = substr($lang,0,2);
282                        }
283                        */
284                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
285                }
286                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
287
288                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
289                $GLOBALS['phpgw']->translation->add_app('login');
290                $GLOBALS['phpgw']->translation->add_app('loginscreen');
291                if(lang('loginscreen_message') == 'loginscreen_message*')
292                {
293                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
294                }
295                if(lang('loginscreen_message') != 'loginscreen_message*')
296                {
297                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
298                }
299        }
300
301        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
302        {
303                $organization_select = "<tr><td width=\"66\" class=\"loginLabel\">";
304                $organization_select .= lang("organization").":</td>";
305                $organization_select .="<td width=\"135\">";                                                                                   
306                $organization_select .="<select name=\"organization\">\n";             
307               
308                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
309                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
310               
311                for ($i=0; $i<count($organizations); $i++)
312                {
313                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
314                }
315               
316                $arrayOrganization = $tmp_array;               
317                ksort($arrayOrganization);
318               
319                foreach($arrayOrganization
320                         as $organization_name => $organization_vars)
321                {
322                        $organization_select .= '<option value="' . $organization_name . '"';
323
324                        if($organization_name == $_COOKIE['last_organization'])
325                        {
326                                $organization_select .= ' selected';
327                        }
328                        $organization_select .= '>' . $organization_vars . "</option>\n";
329                }
330                $organization_select .= "</select>\n";
331                $organization_select .="</td><td>&nbsp;</td></tr>";
332                $tmpl->set_var('select_organization',$organization_select);
333        }
334               
335        $domain_select = '&nbsp;';
336        $last_loginid = $_COOKIE['last_loginid'];
337        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
338        {
339                $domain_select = "<select name=\"logindomain\">\n";
340                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
341                {
342                        $domain_select .= '<option value="' . $domain_name . '"';
343
344                        if($domain_name == $_COOKIE['last_domain'])
345                        {
346                                $domain_select .= ' selected';
347                        }
348                        $domain_select .= '>' . $domain_name . "</option>\n";
349                }
350                $domain_select .= "</select>\n";
351        }
352        elseif($last_loginid !== '')
353        {
354                reset($GLOBALS['phpgw_domain']);
355                list($default_domain) = each($GLOBALS['phpgw_domain']);
356
357                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
358                {
359                        $last_loginid .= '@' . $_COOKIE['last_domain'];
360                }
361        }
362        $tmpl->set_var('select_domain',$domain_select);
363
364        foreach($_GET as $name => $value)
365        {
366                if(ereg('phpgw_',$name))
367                {
368                        $extra_vars .= '&' . $name . '=' . urlencode($value);
369                }
370        }
371
372        if($extra_vars)
373        {
374                $extra_vars = '?' . substr($extra_vars,1);
375        }
376
377        /********************************************************\
378        * Check is the registration app is installed, activated  *
379        * And if the register link must be placed                *
380        \********************************************************/
381       
382        $cnf_reg = createobject('phpgwapi.config','registration');
383        $cnf_reg->read_repository();
384        $config_reg = $cnf_reg->config_data;
385
386        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
387        {
388                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
389        }
390
391        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
392
393        $tmpl->set_var('register_link',$reg_link);
394        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
395        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
396        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
397        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
398        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
399        $tmpl->set_var('cookie',$last_loginid);
400
401        $tmpl->set_var('lang_username',lang('username'));
402        $tmpl->set_var('lang_password',lang('password'));
403        $tmpl->set_var('lang_login',lang('login'));
404
405        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
406        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
407        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
408        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
409
410        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
411                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
412
413        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
414        {
415                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
416        }
417        else
418        {
419                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
420        }
421        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
422        if (substr($var['logo_url'],0,4) != 'http')
423        {
424                $var['logo_url'] = 'http://'.$var['logo_url'];
425        }
426        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
427        $tmpl->set_var($var);
428
429        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
430        {
431                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
432                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
433                uasort($langs,'strcasecmp');
434                foreach ($langs as $key => $name)       // if we have a translation use it
435                {
436                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
437                }
438                $select_lang .= "\n</select>\n";
439                $tmpl->set_var(array(
440                        'lang_language' => lang('Language'),
441                        'select_language' => $select_lang,
442                ));
443        }
444        else
445        {
446                $tmpl->set_block('login_form','language_select');
447                $tmpl->set_var('language_select','');
448        }
449
450        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
451
452        $tmpl->pfp('loginout','login_form');
453?>
Note: See TracBrowser for help on using the repository browser.