source: trunk/phpgwapi/templates/classic/login_classic.php @ 7673

Revision 7673, 14.0 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • 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        function check_logoutcode($code)
15        {
16                switch($code)
17                {
18                        case 1:
19                                return lang('You have been successfully logged out');
20                               
21                        case 2:
22                                return lang('Sorry, your login has expired');
23                               
24                        case 4:
25                                return lang('Cookies are required to login to this site.');
26                               
27                        case 5:
28                                return '<font color="FF0000">' . lang('Bad login or password') . '</font>';
29
30                        case 6:
31                                return '<font color="FF0000">' . lang('Your password has expired, and you do not have access to change it') . '</font>';
32                               
33                        case 98:
34                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
35                               
36                        case 99:
37                                return '<font color="FF0000">' . lang('Blocked, too many attempts(%1)! Retry in %2 minute(s)',$GLOBALS['phpgw_info']['server']['num_unsuccessful_id'],$GLOBALS['phpgw_info']['server']['block_time']) . '</font>';
38                               
39                        case 10:
40                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
41                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
42                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
43
44                                //fix for bug php4 expired sessions bug
45                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4')
46                                {
47                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
48                                }
49
50                                return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>';
51                               
52                        default:
53                                return '&nbsp;';
54                }
55        }
56       
57        /* Program starts here */
58
59        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
60        {
61                $submit = True;
62                $login  = $_SERVER['PHP_AUTH_USER'];
63                $passwd = $_SERVER['PHP_AUTH_PW'];
64                $passwd_type = 'text';
65        }
66        else
67        {
68                $passwd = $_POST['passwd'];
69                $passwd_type = $_POST['passwd_type'];
70        }
71
72        # Apache + mod_ssl style SSL certificate authentication
73        # Certificate (chain) verification occurs inside mod_ssl
74        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
75        {
76                # an X.509 subject looks like:
77                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
78                # the username is deliberately lowercase, to ease LDAP integration
79                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
80                # skip the part in front of the first '/' (nothing)
81                while($sslattrib = next($sslattribs))
82                {
83                        list($key,$val) = explode('=',$sslattrib);
84                        $sslattributes[$key] = $val;
85                }
86
87                if(isset($sslattributes['Email']))
88                {
89                        $submit = True;
90
91                        # login will be set here if the user logged out and uses a different username with
92                        # the same SSL-certificate.
93                        if(!isset($_POST['login'])&&isset($sslattributes['Email']))
94                        {
95                                $login = $sslattributes['Email'];
96                                # not checked against the database, but delivered to authentication module
97                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
98                        }
99                }
100                unset($key);
101                unset($val);
102                unset($sslattributes);
103        }
104
105        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
106        {
107                if($_POST['user']) {
108                        if($GLOBALS['phpgw_info']['server']['use_prefix_organization']) {
109                                $common = CreateObject('phpgwapi.common');
110                                $ldap_conn = $common->ldapConnect();
111                                $justthese = array("uid");
112                                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
113                                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
114                                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
115                                ldap_close($ldap_conn);
116                                if ($ldap_info['count'] != 0) {
117                                        $_POST['login'] = $_POST['user'];
118                                }
119                        }
120                        else
121                                $_POST['login'] = $_POST['user'];
122                }
123                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
124                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
125                {
126                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
127                }
128               
129                // don't get login data again when $submit is true
130                if($submit == false)
131                {
132                        $login = $_POST['login'];
133                }
134               
135                if(strstr($login,'@') === False && isset($_POST['logindomain']))
136                {
137                        $login .= '@' . $_POST['logindomain'];
138                }
139                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
140                {
141                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
142                }
143                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
144
145                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
146                {
147                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
148                }
149                else
150                {
151                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
152                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
153                        {
154                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
155                        }
156
157                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
158                        {
159                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
160                        }
161                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
162                        if (!$forward)
163                        {
164                                $extra_vars['cd'] = 'yes';
165                                $forward = '/home.php';
166                        }
167                        else
168                        {
169                                list($forward,$extra_vars) = explode('?',$forward,2);
170                        }
171                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
172                        {
173                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
174                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
175                        }
176                        else
177                        {
178                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
179                        }
180                }
181        }
182        else
183        {
184                // !!! DONT CHANGE THESE LINES !!!
185                // If there is something wrong with this code TELL ME!
186                // Commenting out the code will not fix it. (jengo)
187                if(isset($_COOKIE['last_loginid']))
188                {
189                        $accounts = CreateObject('phpgwapi.accounts');
190                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
191
192                        if($prefs->account_id)
193                        {
194                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
195                        }
196                }
197               
198                $_GET['lang'] = addslashes($_GET['lang']);
199                if ($_GET['lang'])
200                {
201                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
202                }
203                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
204                {
205                        // If the lastloginid cookies isn't set, we will default to the first language,
206                        // the users browser accepts.
207                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
208                        /*
209                        if(strlen($lang) > 2)
210                        {
211                                $lang = substr($lang,0,2);
212                        }
213                        */
214                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
215                }
216                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
217
218                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
219                $GLOBALS['phpgw']->translation->add_app('login');
220                $GLOBALS['phpgw']->translation->add_app('loginscreen');
221                if(lang('loginscreen_message') == 'loginscreen_message*')
222                {
223                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
224                }
225                if(lang('loginscreen_message') != 'loginscreen_message*')
226                {
227                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
228                }
229        }
230
231        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
232        {
233                $organization_select = "<tr><td width=\"96\" class=\"loginLabel\">";
234                $organization_select .= lang("organization").":&nbsp;</td>";
235                $organization_select .= "<td width=\"135\">";                                                           
236                $organization_select .= "<select name=\"organization\">\n";             
237               
238                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
239                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
240
241        $organizations_count = count($organizations);
242                for ($i=0; $i<$organizations_count; ++$i)
243                {
244                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
245                }
246               
247                $arrayOrganization = $tmp_array;               
248                ksort($arrayOrganization);
249               
250                foreach($arrayOrganization
251                         as $organization_name => $organization_vars)
252                {
253                        $organization_select .= '<option value="' . $organization_name . '"';
254
255                        if($organization_name == $_COOKIE['last_organization'])
256                        {
257                                $organization_select .= ' selected';
258                        }
259                        $organization_select .= '>' . $organization_vars . "</option>\n";
260                }
261                $organization_select .= "</select>\n";
262                $organization_select .="</td><td>&nbsp;</td></tr>";
263                $tmpl->set_var('select_organization',$organization_select);
264        }
265               
266        $domain_select = '&nbsp;';
267        $last_loginid = $_COOKIE['last_loginid'];
268        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
269        {
270                $domain_select = "<select name=\"logindomain\">\n";
271                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
272                {
273                        $domain_select .= '<option value="' . $domain_name . '"';
274
275                        if($domain_name == $_COOKIE['last_domain'])
276                        {
277                                $domain_select .= ' selected';
278                        }
279                        $domain_select .= '>' . $domain_name . "</option>\n";
280                }
281                $domain_select .= "</select>\n";
282        }
283        elseif($last_loginid !== '')
284        {
285                reset($GLOBALS['phpgw_domain']);
286                list($default_domain) = each($GLOBALS['phpgw_domain']);
287
288                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
289                {
290                        $last_loginid .= '@' . $_COOKIE['last_domain'];
291                }
292        }
293        $tmpl->set_var('select_domain',$domain_select);
294
295        foreach($_GET as $name => $value)
296        {
297                if(preg_match('/phpgw_/',$name))
298                {
299                        $extra_vars .= '&' . $name . '=' . urlencode($value);
300                }
301        }
302
303        if($extra_vars)
304        {
305                $extra_vars = '?' . substr($extra_vars,1);
306        }
307
308        /********************************************************\
309        * Check is the registration app is installed, activated  *
310        * And if the register link must be placed                *
311        \********************************************************/
312       
313        $cnf_reg = createobject('phpgwapi.config','registration');
314        $cnf_reg->read_repository();
315        $config_reg = $cnf_reg->config_data;
316
317        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
318        {
319                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
320        }
321
322        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
323
324        $tmpl->set_var('register_link',$reg_link);
325        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
326        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
327        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
328        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
329        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
330        $tmpl->set_var('cookie',$last_loginid);
331
332        $tmpl->set_var('lang_username',lang('username'));
333        $tmpl->set_var('lang_password',lang('password'));
334        $tmpl->set_var('lang_login',lang('login'));
335
336        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
337        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
338        $GLOBALS['phpgw']->translation->add_app('loginhelp',$_GET['lang']);             
339        if(lang('loginhelp_message') != 'loginhelp_message*' && trim(lang('loginhelp_message')) != ""){                                 
340                $tmpl->set_var('lang_help',lang("Help"));       
341        }
342        else
343                $tmpl->set_var('display_help','none');
344        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
345        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
346
347        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
348                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
349
350        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
351        {
352                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
353        }
354        else
355        {
356                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
357        }
358        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
359        if (substr($var['logo_url'],0,4) != 'http')
360        {
361                $var['logo_url'] = 'http://'.$var['logo_url'];
362        }
363        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
364        $tmpl->set_var($var);
365
366        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
367        {
368                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
369                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
370                uasort($langs,'strcasecmp');
371                foreach ($langs as $key => $name)       // if we have a translation use it
372                {
373                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
374                }
375                $select_lang .= "\n</select>\n";
376                $tmpl->set_var(array(
377                        'lang_language' => lang('Language'),
378                        'select_language' => $select_lang,
379                ));
380        }
381        else
382        {
383                $tmpl->set_block('login_form','language_select');
384                $tmpl->set_var('language_select','');
385        }
386
387        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
388
389        $tmpl->pfp('loginout','login_form');
390?>
Note: See TracBrowser for help on using the repository browser.