source: trunk/phpgwapi/templates/news/login_news.php @ 7839

Revision 7839, 15.1 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #3335 - Modificado o template news para a utilização de um plugin para slider

  • 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        require_once "logout_code.php";
15
16        /* Program starts here */
17        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
18        {
19                $submit = True;
20                $login  = $_SERVER['PHP_AUTH_USER'];
21                $passwd = $_SERVER['PHP_AUTH_PW'];
22                $passwd_type = 'text';
23        }
24        else
25        {
26                $passwd = $_POST['passwd'];
27                $passwd_type = $_POST['passwd_type'];
28        }
29
30        # Apache + mod_ssl style SSL certificate authentication
31        # Certificate (chain) verification occurs inside mod_ssl
32        if( $GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']) )
33        {
34                # an X.509 subject looks like:
35                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
36                # the username is deliberately lowercase, to ease LDAP integration
37                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
38                # skip the part in front of the first '/' (nothing)
39                while($sslattrib = next($sslattribs))
40                {
41                        list($key,$val) = explode('=',$sslattrib);
42                        $sslattributes[$key] = $val;
43                }
44
45                if(isset($sslattributes['Email']))
46                {
47                        $submit = True;
48
49                        # login will be set here if the user logged out and uses a different username with
50                        # the same SSL-certificate.
51                        if( !isset($_POST['login']) && isset($sslattributes['Email']) )
52                        {
53                                $login = $sslattributes['Email'];
54                                # not checked against the database, but delivered to authentication module
55                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
56                        }
57                }
58                unset($key);
59                unset($val);
60                unset($sslattributes);
61        }
62
63    if( isset( $_GET[ 'cd' ] ) && ( $_GET['cd']=='1' || $_GET['cd'] == 10 ) )
64        {
65                $_SESSION['contador_captcha'] = 0;
66        }
67
68        if( isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit )
69        {
70            // Primeiro testa o captcha....se houver......
71        if( $GLOBALS['phpgw_info']['server']['captcha'] == 1 )
72                {
73                        if( $_SESSION['contador_captcha'] > $GLOBALS['phpgw_info']['server']['num_badlogin'] )
74                        {
75                                if ($_SESSION['CAPTCHAString'] != trim(strtoupper($_POST['codigo'])))
76                                {
77                                        if(!$_GET['cd'])
78                                        {
79                                                $_GET['cd'] = '200';
80                                        }
81                                }
82                               
83                                unset($_SESSION['CAPTCHAString']);
84                        }
85                }
86               
87                if( $_POST['user'] )
88                {
89                        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
90                        {
91                                $common         = CreateObject('phpgwapi.common');
92                                $ldap_conn      = $common->ldapConnect();
93                                $justthese      = array("uid");
94                                $filter         = "(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
95                                $ldap_search    = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
96                                $ldap_info              = ldap_get_entries($ldap_conn, $ldap_search);
97                               
98                                ldap_close($ldap_conn);
99                               
100                                if( $ldap_info['count'] != 0 )
101                                {
102                                        $_POST['login'] = $_POST['user'];
103                                }
104                        }
105                        else
106                        {
107                                $_POST['login'] = $_POST['user'];
108                        }
109                }
110               
111                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
112                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
113                {
114            if(!$_GET['cd'])
115            {
116                $_GET['cd'] = '5';
117            }
118                }
119               
120                // don't get login data again when $submit is true
121                if( $submit == false )
122                {
123                        $login = $_POST['login'];
124                }
125               
126                if( strstr($login,'@') === False && isset($_POST['logindomain']) )
127                {
128                        $login .= '@' . $_POST['logindomain'];
129                }
130                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
131                {
132                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
133                }
134               
135                if( !$_GET['cd'] )
136                {
137                        $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
138                }
139
140                if( !isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'] )
141                {
142                        If(!$_GET['cd']) $_GET['cd'] = $GLOBALS['phpgw']->session->cd_reason;
143                }
144                else
145                {
146                        if( $_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
147                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] )
148                        {
149                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
150                        }
151
152                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
153                        {
154                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
155                        }
156                       
157                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
158                       
159                        if ( !$forward )
160                        {
161                                $extra_vars['cd'] = 'yes';
162                                $forward = '/home.php';
163                        }
164                        else
165                        {
166                                list($forward,$extra_vars) = explode('?',$forward,2);
167                        }
168                       
169                        if( $GLOBALS['phpgw_info']['server']['use_https'] != 2 )
170                        {
171                                //Modificacao feita para que o Expresso redirecione para o primeiro proxy caso haja um encadeamento de mais de um proxy.
172                                //$forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
173                                $forward = 'http://' . nearest_to_me() . $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
183        // Incrementar Contador para o Uso do Captcha
184    $_SESSION['contador_captcha']++;
185
186        // !!! DONT CHANGE THESE LINES !!!
187        // If there is something wrong with this code TELL ME!
188        // Commenting out the code will not fix it. (jengo)
189        if( isset( $_COOKIE['last_loginid'] ) )
190        {
191                $accounts = CreateObject('phpgwapi.accounts');
192
193                $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
194
195                if($prefs->account_id)
196                {
197                        $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
198                }
199        }
200       
201        $_GET['lang'] = addslashes($_GET['lang']);
202       
203        if ($_GET['lang'])
204        {
205                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
206        }
207        elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
208        {
209                // If the lastloginid cookies isn't set, we will default to the first language,
210                // the users browser accepts.
211                list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
212                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
213        }
214
215        $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
216        $GLOBALS['phpgw']->translation->add_app('login');
217        $GLOBALS['phpgw']->translation->add_app('loginscreen');
218
219        // OUs LDAP
220        $show_Organization = "none";
221       
222        if( $GLOBALS['phpgw_info']['server']['use_prefix_organization'] )
223        {
224                $show_Organization = "block";
225
226                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
227               
228                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
229               
230                for ($i=0; $i<count($organizations); $i++)
231                {
232                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
233                }
234               
235                $arrayOrganization = $tmp_array;               
236               
237                ksort($arrayOrganization);
238               
239                foreach($arrayOrganization as $organization_name => $organization_vars)
240                {
241                        $organization_select .= '<option value="' . $organization_name . '"';
242
243                        if( $organization_name == $_COOKIE['last_organization'] )
244                        {
245                                $organization_select .= ' selected';
246                        }
247                        $organization_select .= '>' . $organization_vars . "</option>\n";
248                }
249
250                $tmpl->set_var('select_organization',$organization_select);
251        }
252
253        $tmpl->set_var( 'show_organization', $show_Organization );
254               
255        $domain_select = '&nbsp;';
256
257        $last_loginid = $_COOKIE['last_loginid'];
258       
259        if( $GLOBALS['phpgw_info']['server']['show_domain_selectbox'] )
260        {
261                $domain_select = "<select name=\"logindomain\">\n";
262               
263                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
264                {
265                        $domain_select .= '<option value="' . $domain_name . '"';
266
267                        if($domain_name == $_COOKIE['last_domain'])
268                        {
269                                $domain_select .= ' selected';
270                        }
271                        $domain_select .= '>' . $domain_name . "</option>\n";
272                }
273                $domain_select .= "</select>\n";
274        }
275        elseif($last_loginid !== '')
276        {
277                reset($GLOBALS['phpgw_domain']);
278               
279                list($default_domain) = each($GLOBALS['phpgw_domain']);
280
281                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
282                {
283                        $last_loginid .= '@' . $_COOKIE['last_domain'];
284                }
285        }
286
287        $tmpl->set_var('select_domain',$domain_select);
288
289        foreach($_GET as $name => $value)
290        {
291                if(ereg('phpgw_',$name))
292                {
293                        $extra_vars .= '&' . $name . '=' . urlencode($value);
294                }
295        }
296
297        if( is_string( $extra_vars ) )
298        {
299                $extra_vars = '?' . substr($extra_vars,1);
300        }
301
302        /********************************************************\
303        * Check is the registration app is installed, activated  *
304        * And if the register link must be placed                *
305        \********************************************************/
306       
307        $cnf_reg = createobject('phpgwapi.config','registration');
308        $cnf_reg->read_repository();
309        $config_reg = $cnf_reg->config_data;
310
311        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
312        {
313                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
314        }
315
316        $template = $GLOBALS['phpgw_info']['login_template_set'];
317
318        $GLOBALS['phpgw_info']['server']['template_set'] = $template;
319
320        $tmpl->set_var('register_link',$reg_link);
321        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
322        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
323        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
324        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
325        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
326        $tmpl->set_var('cookie',$last_loginid);
327
328        $tmpl->set_var('lang_username',lang('username'));
329        $tmpl->set_var('lang_password',lang('password'));
330        $tmpl->set_var('lang_login',lang('login'));
331
332        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
333        $tmpl->set_var('template_set', $template);
334
335        // Keyboard Virtual
336        $tmpl->set_var('show_kbd',$GLOBALS['phpgw_info']['server']['login_virtual_keyboard']);
337
338        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
339
340        // soh mostra o captcha se for login sem certificado....
341        if($GLOBALS['phpgw_info']['server']['captcha'] && $_GET['cd']!='300' )
342        {
343                $aux_captcha = '<input type="hidden" name="'.session_name().'"  value="'.session_id().'">';
344
345                if( $_SESSION['contador_captcha'] > $GLOBALS['phpgw_info']['server']['num_badlogin'] )
346                {
347                        $aux_captcha = '<div>'
348                           .'<img id="id_captcha" src="./security/captcha.php?' . session_name() . '=' . session_id() . '" title="'.lang('Security code').'" alt="'.lang('Security code').'" style="position:static;">'
349                           .'<input class="input" type="text" maxlength="50" size="15" name="codigo" id="codigo" value="" >'
350                           .'<input type="hidden" name="' . session_name() . '"  value="' . session_id() . '" >'
351                           .'</div>';
352                }
353
354                $tmpl->set_var('captcha',$aux_captcha);
355        }
356
357        // Testa se deve incluir applet para login com certificado......
358        if ( $_GET['cd']=='300' && $GLOBALS['phpgw_info']['server']['certificado'] == 1 )
359        {
360                //Zera o Cookie contador, responsavel pelo captcha
361                $_SESSION['contador_captcha'] = 0;
362                $link_alterna_login = '<img src="phpgwapi/templates/default/images/warning.gif"/><a href="login.php">' . lang('Access without Digital Certificate') . '</a>';
363                $tmpl->set_var('show','none');
364                $tmpl->set_var('action','<div id="action"><img style="border:0px;margin:31px 0px 58px 0px;" src="phpgwapi/templates/default/images/acao.gif" /></div>');
365                // gera parametro com tokens suportados ....
366                $var_tokens = '';
367               
368                for($ii = 1; $ii < 11; $ii++)
369                {
370                        if($GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'])
371                                $var_tokens .= $GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'] . ',';
372                }
373
374                if(!$var_tokens)
375                {
376                        $var_tokens = 'ePass2000Lx;/usr/lib/libepsng_p11.so,ePass2000Win;c:/windows/system32/ngp11v211.dll';
377                }
378               
379                $param1 = "'<param name=\"token\" value=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\">'+";
380                $param2 = "'token=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\" ' +";
381
382                $cod_applet =
383            // sem debug ativado
384            '<script type="text/javascript">
385                                        if (navigator.userAgent.match(\'MSIE\')){
386                                                document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
387                                                \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
388                                                \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
389                                                \'<param name="codebase" value="/security/">\' +
390                                                \'<param name="code" value="LoginApplet.class"> \' +
391                                                \'<param name="locale" value="' . $lang . '"> \' +
392                                                \'<param name="mayscript" value="true"> \' + '
393                                                . $param1
394                                                . ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
395                                                \'</object>\');
396                                        }
397                                        else {
398                                                document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $lang . '"\' +
399                                                \'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
400                                                . $param2 
401                                                . ' \'type="application/x-java-applet;version=1.5" mayscript > \' +
402                                                \'<noembed> \' +
403                                                \'No Java Support. \' +
404                                                \'</noembed> \' +
405                                                \'</embed> \');
406                                        }
407                                </script>';
408
409        }
410        else
411        {
412                if($GLOBALS['phpgw_info']['server']['certificado']==1)
413                {
414                        $tmpl->set_var('show','yes');
415                        $link_alterna_login = '<img src="phpgwapi/templates/default/images/lock1_icon.gif"/><a title="' . lang('Link to use digital certificate') . '" href="login.php?cd=300">' . lang('Logon with my digital certificate') . '</a>';
416                }
417                $tmpl->set_var('lang_username',lang('username'));
418                $tmpl->set_var('action','');
419                $cod_applet = '';
420        }
421
422        $tmpl->set_var('applet',$cod_applet);
423        $tmpl->set_var('link_alterna_login',$link_alterna_login);
424
425        $tmpl->set_var('dir_root', 'http://' . nearest_to_me() . '/');
426        if(is_file(dirname( __FILE__ ) . '/../../../infodist/ultima-revisao-svn.php'))
427        include_once(dirname( __FILE__ ) . '/../../../infodist/ultima-revisao-svn.php');
428        if(isset($ultima_revisao)) $tmpl->set_var('ultima_rev','<br>' . $ultima_revisao);
429
430        // Adiciona código personalizado de outro template
431        // que esteja utilizando o login_default.php
432        if(is_file('.'.$template_dir.'/login.inc.php'))
433        {
434                include_once('.'.$template_dir.'/login.inc.php');
435        }
436
437        $tmpl->pfp('loginout','login_form');
438
439?>
Note: See TracBrowser for help on using the repository browser.