source: companies/serpro/login.php @ 903

Revision 903, 49.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

RevLine 
[903]1<?php
2
3        //Valida a existencia do cookie, antes de grava-lo
4if(isset($_COOKIE['contador']))
5        {
6        $valor_cookie = $_COOKIE['contador'];
7        if($_POST['user'] && $_POST['passwd'])
8                {
9                $valor_cookie = $valor_cookie + 1;
10                setcookie("contador", $valor_cookie,0);
11                }
12        }
13        //Cookie inexistente: tenta gravar um
14        else
15        {
16        if (setcookie("contador", 1,0))
17                //echo "OK, cookie gravado.";
18                $valor_cookie = 1;
19                else
20                //echo "Nao gravou o cookie";
21                $valor_cookie = "9999"; // forca captcha
22        }
23// logout, inicia contador novamente.....
24if($_GET['cd']=='1' || $_COOKIE['sessionid'] || $_GET['cd'] == 10)
25        {
26        $valor_cookie = 1;
27        setcookie("contador", 1,0);
28        }
29        /**************************************************************************\
30        * eGroupWare login                                                         *
31        * http://www.egroupware.org                                                *
32        * Originaly written by Dan Kuykendall <seek3r@phpgroupware.org>            *
33        *                      Joseph Engo    <jengo@phpgroupware.org>             *
34        * --------------------------------------------                             *
35        *  This program is free software; you can redistribute it and/or modify it *
36        *  under the terms of the GNU General Public License as published by the   *
37        *  Free Software Foundation; either version 2 of the License, or (at your  *
38        *  option) any later version.                                              *
39        \**************************************************************************/
40
41$phpgw_info = array();
42$submit = False; // set to some initial value
43$GLOBALS['phpgw_info']['flags'] = array(
44        'disable_Template_class' => True,
45        'login'                  => True,
46        'currentapp'             => 'login',
47        'noheader'               => True
48);
49if(file_exists('./header.inc.php'))
50        {
51        include('./header.inc.php');
52        if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)
53                {
54                if ($_SERVER['HTTPS'] != 'on')
55                        {
56                        Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
57                        exit;
58                        }
59                }
60        if(function_exists('CreateObject'))
61                {
62                $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
63                }
64                else
65                {
66                Header('Location: setup/index.php');
67                exit;
68                }
69        }
70        else
71        {
72        Header('Location: setup/index.php');
73        exit;
74        }
75$GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['login_template_set'];
76$tmpl = CreateObject('phpgwapi.Template', $GLOBALS['phpgw_info']['server']['template_dir']);
77// read the images from the login-template-set, not the (maybe not even set) users template-set
78$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
79// This is used for system downtime, to prevent new logins.
80if($GLOBALS['phpgw_info']['server']['deny_all_logins'])
81        {
82        $deny_msg=lang('Oops! You caught us in the middle of system maintainance.<br/>
83        Please, check back with us shortly.');
84        $tmpl->set_file(array
85        (
86                'login_form' => 'login_denylogin.tpl'
87        ));
88        $tmpl->set_var('template_set','default');
89        $tmpl->set_var('deny_msg',$deny_msg);
90        $tmpl->pfp('loginout','login_form');
91        exit;
92        }
93$tmpl->set_file(array('login_form' => 'login.tpl'));
94// !! NOTE !!
95// Do NOT and I repeat, do NOT touch ANYTHING to do with lang in this file.
96// If there is a problem, tell me and I will fix it. (jengo)
97// whoooo scaring
98
99if($GLOBALS['phpgw_info']['server']['usecookies'] == True)
100        {
101        $GLOBALS['phpgw']->session->phpgw_setcookie('serverID', '1024');
102        //GLOBALS['phpgw']->session->phpgw_setcookie('eGroupWareLoginTime', time());
103        }
104
105/*
106        if($_GET['cd'] != 10 && $GLOBALS['phpgw_info']['server']['usecookies'] == False)
107        {
108                $GLOBALS['phpgw']->session->setcookie('sessionid');
109                $GLOBALS['phpgw']->session->setcookie('kp3');
110                $GLOBALS['phpgw']->session->setcookie('domain');
111        }
112*/
113
114/* This is not working yet because I need to figure out a way to clear the $cd =1
115        if(isset($_SERVER['PHP_AUTH_USER']) && $_GET['cd'] == '1')
116        {
117                Header('HTTP/1.0 401 Unauthorized');
118                Header('WWW-Authenticate: Basic realm="phpGroupWare"');
119                echo 'You have to re-authentificate yourself';
120                exit;
121        }
122*/
123
124function grava_senha_criptografada_com_certificado_no_ldap($aux_uid,$aux_senha)
125{   
126
127require_once('./seguranca/classes/CertificadoB.php');
128
129$ldap_context = $GLOBALS['phpgw_info']['server']['ldap_context'];
130$ldap_servidor = $GLOBALS['phpgw_info']['server']['ldap_host'];
131$ldap_dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
132$ldap_passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
133
134    $cc=ldap_connect($ldap_servidor);
135
136    //  bind ..
137    $sr=ldap_bind($cc,$ldap_dn,$ldap_passwd); 
138
139    $filtro = 'uid='.$aux_uid;
140
141    // Pesquisa uid no LDAP
142    $sr=ldap_search($cc, $ldap_context,$filtro); 
143
144    // Pega resultado ....
145    $info = ldap_get_entries($cc, $sr);
146 
147    // Tem de achar só uma entrada.....ao menos uma....
148    if($info["count"]!=1)
149    {
150        ldap_close($cc);
151
152        return false;
153    }
154
155if(!$info[0]["usercertificate"][0])
156    {
157        //Usuario sem certificado cadastrado
158        ldap_close($cc);
159        return false;
160    }
161
162$a = new certificadoB();
163$R = $a->encriptar_senha($aux_senha,$info[0]["usercertificate"][0]);
164if(!$R)
165    {
166        ldap_close($cc);
167        return false;
168    }
169$user_info = array();
170$aux1 = $info[0]["dn"];
171$user_info['cryptpassword'] = $R;
172ldap_modify($cc,$aux1,$user_info);
173
174ldap_close($cc);
175
176return true;
177}
178
179
180function check_logoutcode($code)
181        {
182                switch($code)
183                {
184                        case 1:
185                                return lang('You have been successfully logged out');
186                                break;
187                        case 2:
188                                return lang('Sorry, your login has expired');
189                                break;
190                        case 4:
191                                return lang('Cookies are required to login to this site.');
192                                break;
193                        case 5:
194                                return '<font color="FF0000">' . lang('Bad login or password') . '</font>';
195                                break;
196                        case 200:
197                                return '<font color="FF0000">' . lang('Invalid code') . '</font>';
198                                break;
199                        case 202:
200                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
201                                break;
202                        case 203:
203                                return '<font color="FF0000">' . lang('New Password and Confirm Password doesnt are equal') . '</font>';
204                                break;
205                        case 204:
206                                return '<font color="FF0000">' . lang('New Password and Current Password are similar') . '</font>';
207                                break;
208                        case 205:
209                                return '<font color="FF0000">' . lang('Your password must contain %1 or more letters', $GLOBALS['phpgw_info']['server']['num_letters_userpass']) . '</font>';
210                                break;
211                        case 206:
212                                return '<font color="FF0000">' . lang('Your password is very simple, use numbers, uppercase, lowercase and special characters') . '</font>';
213                                break;
214                        case 207:
215                                return '<font color="FF0000">' . lang('Your password contains characters not allowed') . '</font>';
216                                break;
217                        case 208:
218                                return '<font color="FF0000">' . lang('New password with more than three consecutives equals caracteres') . '</font>';
219                                break;
220                        case 209:
221                                return '<font color="0000FF">' . lang('password has been updated') . '</font>';
222                                break;
223                        case 98:
224                                $valor_cookie = 1;
225                                setcookie("contador", 1,0);
226                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
227                                break;
228                        case 99:
229                                return '<font color="FF0000">' . lang('Blocked, too many attempts') . '</font>';
230                                break;
231                        case 10:
232                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
233                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
234                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
235
236                                //fix for bug php4 expired sessions bug
237                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4')
238                                {
239                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
240                                }
241
242                                return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>';
243                                break;
244                        default:
245                                return '&nbsp;';
246                }
247        }
248
249/* Program starts here */
250
251if($_POST['user'])
252        {
253                # Usuario tem de ser alfanumerico, e pode ter '-_.' .... 
254                $test_testx = str_replace('-','',$_POST['user']);
255                $test_testy = str_replace('.','',$test_testx);
256                $test_test = str_replace('_','',$test_testy);
257                if(!ctype_alnum($test_test))
258                        {
259                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
260                                exit();
261                        }
262        }
263
264if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
265        {
266        $submit = True;
267        $login  = $_SERVER['PHP_AUTH_USER'];
268        $passwd = $_SERVER['PHP_AUTH_PW'];
269        $passwd_type = 'text';
270        }
271        else
272        {
273        $passwd = $_POST['passwd'];
274        $passwd_type = $_POST['passwd_type'];
275        }
276
277        # Apache + mod_ssl style SSL certificate authentication
278        # Certificate (chain) verification occurs inside mod_ssl
279        //$GLOBALS['phpgw_info']['server']['auth_type'] = 'sqlssl';
280
281if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
282        {
283                # an X.509 subject looks like:
284                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
285                # the username is deliberately lowercase, to ease LDAP integration
286                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
287                # skip the part in front of the first '/' (nothing)
288                //$sslattributes['Email'] = $GLOBALS['certificado']->dados['email'];
289        while($sslattrib = next($sslattribs))
290                {
291                list($key,$val) = explode('=',$sslattrib);
292                $sslattributes[$key] = $val;
293                }
294        if(isset($sslattributes['Email']))
295                {
296                $submit = True;
297                # login will be set here if the user logged out and uses a different username with
298                # the same SSL-certificate.
299                if(!isset($_POST['login'])&&isset($sslattributes['Email']))
300                        {
301                        $login = $sslattributes['Email'];
302                        # not checked against the database, but delivered to authentication module
303                        $passwd = $_SERVER['SSL_CLIENT_S_DN'];
304                        }
305                }
306        unset($key);
307        unset($val);
308        unset($sslattributes);
309        }
310$ldap_info="";
311if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
312        {
313        // Primeiro testa o captcha....se houver......
314        if( $GLOBALS['phpgw_info']['server']['captcha']==1)
315                {
316                if(isset($_POST['codigo']))
317                        {
318                        if ($_SESSION['CAPTCHAString'] != strtoupper($_POST['codigo']))
319                                {
320                                if (isset($_POST['npasswd']))
321                                        {
322                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=200&ts=202'));
323                                        }
324                                        else
325                                        {
326                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=200'));
327                                        }
328                                }
329                        unset($_SESSION['CAPTCHAString']);
330                        }
331                }
332
333
334        //Faz uma busca inicial por atributos no ldap para que os resultados sejam utilizados pelo restante do programa
335        //Utilizando um diretorio corporativo, o dn do usuario pode estar localizado em qualquer ramo do diretorio
336        //system('echo "Login: bind em ldap" >> /tmp/controle');
337        $common = CreateObject('phpgwapi.common');
338        $ldap_conn = $common->ldapConnect(); //bind como Admin para buscar o atributo de expiracao e o dn do usuario
339        if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
340                {
341                $justthese = array($GLOBALS['phpgw_info']['server']['atributoexpiracao']);
342                }
343                else
344                {
345                $justthese = array("phpgwaccountexpires");
346                }
347        $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
348        $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
349        $ldap_info  = ldap_get_entries($ldap_conn, $ldap_search);
350        ldap_close($ldap_conn);
351        // Testa os cpos de troca de senha, se existem
352        if($_POST['npasswd'] || $_POST['cnpasswd'])
353                {
354                // Default number of letters = 8
355                if (!$GLOBALS['phpgw_info']['server']['num_letters_userpass'])
356                        $GLOBALS['phpgw_info']['server']['num_letters_userpass'] = 8;
357                        // Default number of special letters = 1
358                        if (!$GLOBALS['phpgw_info']['server']['num_special_letters_userpass'])
359                        $GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] = 1;
360                        if(strlen($_POST['npasswd']) < $GLOBALS['phpgw_info']['server']['num_letters_userpass'])
361                                {
362                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=205&ts=202'));
363                                }
364                        // nova senha e confirma nova senha devem ser iguais ...
365                        if($_POST['npasswd']  != $_POST['cnpasswd'])
366                                {
367                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=203&ts=202'));
368                                }
369                        if (!(ereg ("(^[a-zA-Z_.\-\!@#$%&*+=|]*)$", $_POST['npasswd'] ) or
370                                ereg ("(^[0-9_.\-\!@#$%&*+=|]*)$", $_POST['npasswd'] ) or
371                                ereg ("(^[a-zA-Z0-9]*)$", $_POST['npasswd'] )  or
372                                ereg ("(^[a-zA-Z0-9_.\-\!@#$%&*+=|]*)$", $_POST['npasswd'] )))
373                                {
374                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=207&ts=202'));
375                                }
376                        for ($j=0 ; $j<(strlen($_POST['npasswd'])-2); $j++)
377                                {
378                                if ($_POST['npasswd'][$j]==$_POST['npasswd'][$j+1] && $_POST['npasswd'][$j]==$_POST['npasswd'][$j+2])
379                                        {
380                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=208&ts=202'));
381                                        break;
382                                        }
383                                }
384                        $similar=false;
385                        for ($j=0 ; $j<8; $j++)
386                                {
387                                        for ($k=0 ; $k<8; $k++)
388                                                {
389                                                if (similar_text(substr($_POST['passwd'],$j,3),substr($_POST['npasswd'],$k,3))>2)
390                                                        {
391                                                        $similar=true;
392                                                        }
393                                                }
394                                }
395                        // a nova senha e a senha atual nao podem ser "similares" ...
396                        if ($similar || $_POST['passwd']  == $_POST['npasswd'])
397                                {
398                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=204&ts=202'));
399                                }
400                        // complexidade da senha
401                        $passcomplex=0;
402                        if (ereg('[a-zA-Z]',$_POST['npasswd'])) {$passcomplex=$passcomplex+1;}
403                        if (ereg('[0-9]',$_POST['npasswd'])) {$passcomplex=$passcomplex+1;}
404                        if (ereg('[^0-9a-zA-Z]',$_POST['npasswd'])) {$passcomplex=$passcomplex+1;}
405                        if ($passcomplex < 2)
406                                {
407                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=206&ts=202'));
408                                }
409                        //Tentando fazer bind com o dn do usuario
410                        $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
411                        if (!$ldap_conn)
412                                {
413                                printf("<b>Error: Can't bind to LDAP server!");
414                                die;
415                                }
416                        $dn=$ldap_info[0]['dn'];
417                        //system('echo "'.ldap_errno($ldap_conn).'" >>/tmp/controle');
418                        //Tenta fazer bind no diretorio, se nao conseguir, verifica se a negacao de autenticacao foi por causa de uma expiracao de senhas
419                        //system('echo "Dn para bind: '.$ldap_info[0]['dn'].'" >>/tmp/controle');
420                        if (!ldap_bind($ldap_conn,$ldap_info[0]['dn'],$_POST['passwd']))
421                                {
422                                //Verificando se a negacao de bind foi proveniente de uma expiracao de senha
423                                //system('echo "NAO conseguiu dar bind" >>/tmp/controle');
424                                $now=time();
425                                //Verificando se a senha esta expirada
426                                $expired=false;
427                                if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
428                                        {
429                                        //system('echo "Atributo de expiracao configurado." >>/tmp/controle');
430                                        //system('echo "now: '.$now.'" >>/tmp/controle');
431                                        //system('echo "atributo de expiracao: '.strtotime($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0]).'" >>/tmp/controle');
432                                        //if (strtotime($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0])<$now)
433                        system('echo "chegou" >>/tmp/controle');
434                        if (($ldap_info[0]["phpgwaccountexpires"][0]!="-1")&&(strtotime($ldap_info[0]["phpgwaccountexpires"][0])<$now))
435                                                {
436                                                //system('echo "Encontrou atributo expirado" >>/tmp/controle');
437                                                $expired=true;
438                                                }
439                                        }
440                                        else
441                                        {
442
443                                        //Se o atributo de expiracao nao estiver configurado pressupoe que eh unixtime (phpgwaccountexpires)
444                        if (($ldap_info[0]["phpgwaccountexpires"][0]!="-1")&&(strtotime($ldap_info[0]["phpgwaccountexpires"][0])<$now))
445                                                {
446                                                //system('echo "Encontrou atributo expirado - phpgwaccoutexpires" >>/tmp/controle');
447                                                $expired=true;
448                                                }
449                                        }
450                                if ($expired)
451                                        {
452                                        //A negacao de bind proveio de uma expiracao de senhas.
453                                        //Providencia a troca de senhas e, se configurado, também o ajuste do atributo de expiracao.
454                                        //system('echo "vai chamar o change_password" >>/tmp/controle');
455                                        if($GLOBALS['phpgw']->auth->change_password_user($passwd, $_POST['npasswd'],$dn,true))
456                                                {
457                                                //A troca de senhas funcionou
458                                                //system('echo "Login: troca de senhas OK" >>/tmp/controle');
459                                                if($GLOBALS['phpgw_info']['server']['diretorioescravo'])
460                                                        {
461                                                        //Tempo necessario para que o slave receba a atualizacao.
462                                                        sleep(1);
463                                                        }
464                                                // TESTA SE DEVE CIFRAR A SENHA COM CHAVE PUBLICA DO CERTIFICADO (PARA LOGIN COM CERTIFICADO)...
465                                                if($GLOBALS['phpgw_info']['server']['certificado'])
466                                                {
467                                                if(!$GLOBALS['phpgw_info']['server']['atributousuarios'] or $GLOBALS['phpgw_info']['server']['atributousuarios'] == "person")
468                                                {
469                                                        $RR = grava_senha_criptografada_com_certificado_no_ldap($_POST['user'],$_POST['npasswd']);
470                                                }
471                                                }
472                                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/logout.php?cd=209');
473                                                }
474                                                else
475                                                {
476                                                //Direciona para senha incorreta na tela de troca de senhas
477                                                //system('echo "Login: troca de senhas PROBLEMA" >>/tmp/controle');
478                                                $GLOBALS['phpgw']->redirect("" . '/login.php?cd=5&ts=202');
479                                                }
480                                        }
481                                        else
482                                        {
483                                        //A senha digitada estava incorreta
484                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=5&ts=202');
485                                        }
486                                }
487                                else
488                                {
489                                //Usuario executou autenticacao no diretorio - a expiracao so pode ter vindo de uma politica de expiracao do proprio expresso
490                                //system('echo "SIM conseguiu dar bind" >>/tmp/controle');
491                                if($GLOBALS['phpgw_info']['server']['politicasenhas']=='expresso')
492                                        {
493                                        //Se a politica de senhas for do Expresso eh necessario verificar se o usuario estah expirado
494                                        $now=time();
495                                        $common1 = CreateObject('phpgwapi.common');
496                                        $ldap_conn1 = $common1->ldapConnect();
497                                        if ($GLOBALS['phpgw_info']['server']['num_days_pwd_validate'])
498                                                {
499                                                $aux=$GLOBALS['phpgw_info']['server']['num_days_pwd_validate'];
500                                                }
501                                                else
502                                                {
503                                                $aux=90;
504                                                }
505                                        //$entry['phpgwaccountexpires'] = $now + ($aux * 86400);
506                                        if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
507                                                {
508                                                if(substr($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0],-1,1) == "Z")
509                                                        {
510                                                        if($GLOBALS['phpgw_info']['server']['politicasenhas']=='expresso')
511                                                                {
512                                                                //quando a data de expiracao estah no formato yyyymmddhhmmssZ
513                                                                $entry[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = strftime("%Y%m%d%H%M%SZ", $now + ($aux * 86400));
514                                                                }
515                                                        }
516                                                        else
517                                                        {
518                                                        if($GLOBALS['phpgw_info']['server']['politicasenhas']=='expresso')
519                                                                {
520                                                                //Outro atributo ldap que, assim como o phpgwaccounttype, tambem contem hora em formato unix
521                                                                $entry[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = $now + ($aux * 86400);
522                                                                }
523                                                        }
524                                                }
525                                                else
526                                                {
527                                                //Se a política for no diretorio nao precisa alterar o atributo de expiracao
528                                                if($GLOBALS['phpgw_info']['server']['politicasenhas']=='expresso')
529                                                        {
530                                                        $entry['phpgwaccountexpires'] = $now + ($aux * 86400);
531                                                        }
532                                                }
533                                        ldap_mod_replace($ldap_conn1,$ldap_info[0]['dn'], $entry);
534                                        }
535                                }
536                }
537
538        if ($ldap_info['count'] != 0)
539                {
540                $_POST['login'] = $_POST['user'];
541                }
542        ldap_close($ldap_conn);
543        if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
544                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
545                {
546                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
547                }
548        if($submit == false)
549                {
550                $login = $_POST['login'];
551                }
552        if(strstr($login,'@') === False && isset($_POST['logindomain']))
553                {
554                $login .= '@' . $_POST['logindomain'];
555                }
556                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
557                        {
558                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
559                        }
560        //--------------------------------------------------------------------------------------------------
561        //LOGIN
562        //--------------------------------------------------------------------------------------------------
563        //echo "Usuario ==> ".$login."    senha ==> ".$passwd;
564        //system('echo "Login: tentou criar sessao" >> /tmp/controle');
565        //Tantando criar a sessao
566        $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
567        if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
568                {
569                //A sessao nao pode ser criada. Verificando quais os possiveis motivos
570                //system('echo "Nao tem sessao" >> /tmp/controle');
571                if ($GLOBALS['phpgw']->session->cd_reason == 99)
572                        {
573                        //fazendo o redirecionamento para o caso de bloqueio de por excesso de tentativas erradas
574                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason.'&ts=99');
575                        }
576                        else
577                        {
578                        //Verifica se o codigo de erro ldap 49, que o session traduz para cd_reason=5, é proveniente de uma expiracao de senhas. Neste caso, mesmo se o usuário digitar a senha errada, devolve-se a informacao de expiracao. O código de erro  "5" também é retornado quando não é encontrado o usuário na base ldap
579                        if ($GLOBALS['phpgw']->session->cd_reason == 5)
580                                {
581                                //system('echo "Retornou erro 49" >>/tmp/controle');
582                                //Buscando o atributo de expiracao no ldap
583                                $lc = $common->ldapConnect();
584                                if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
585                                        {
586                                        $justthese = array("uid",$GLOBALS['phpgw_info']['server']['atributoexpiracao']);
587                                        }
588                                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
589                                $ldap_search = ldap_search($lc, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
590                                $ldap_info = ldap_get_entries($lc, $ldap_search);
591                                ldap_close($lc);
592                                //Verificando se a senha está expirada
593                                if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
594                                        {
595                                        //Analisa a expiracao atraves do tempo da maquina
596                                        $now=time();
597                                        //Se o atributo de expiracao nao existir pode ser por causa da nao existencia do usuario no ldap
598                                        //Verifica o tipo do formato do tempo de expiracao para concluir se a senha está expirada ou não.
599                                        if (($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0])&&(substr($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0],-1,1) == "Z"))
600                                                {
601                                                if (strtotime($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0] < $now))
602                                                        {
603                                                        //Senha do usuario estah expirada, pressupoe-se que colocou a senha certa, pois o erro do ldap eh o mesmo (49)
604                                                        //system('echo "Detectou expiracao de senhas: " >>/tmp/controle');
605                                                        if(isset($GLOBALS['phpgw_info']['server']['webserver_url']))
606                                                                {
607                                                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=98&ts=202');
608                                                                }
609                                                                else
610                                                                {
611                                                                //Entra aqui em duas ocasioes - quando expirado:
612                                                                        //login errado na tela sem troca de senhas
613                                                                        //troca de senhas com a senha atual errada
614                                                                if(isset($_POST['npasswd']))
615                                                                        {
616                                                                        //Nao logou porque o usuario estah com a senha expirada - troca de senhas
617                                                                        //Pode ter errado a senha também.
618                                                                        //system('echo "NAO Achou a url - tela troca de senhas: " >>/tmp/controle');
619                                                                        $GLOBALS['phpgw']->redirect_link("" . '/logout.php?cd=5&ts=202');
620                                                                        }
621                                                                        else
622                                                                        {
623                                                                        //Nao logou porque o usuario estah com a senha expirada - tela inicial
624                                                                        //Para o caso de usuario que tenta se logar na tela inicial com a senha expirada
625                                                                        //system('echo "NAO Achou a url - tela inicial: " >>/tmp/controle'); //funciona
626                                                                        $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=98&ts=202'); //funciona
627                                                                        }
628                                                                }
629                                                        }
630                                                        else
631                                                        {
632                                                        //senha do usuario nao estah expirada e, como o ldap deu login invalido, ocorreu erro de senha
633                                                        //system('echo "NAO estah expirado: " >>/tmp/controle');
634                                                        if(isset($_POST['npasswd']))
635                                                                {
636                                                                     $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=5&ts=202');
637                                                                }
638                                                                else
639                                                                {
640                                                                     $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=5');
641                                                                }
642
643                                                        }
644                                                }
645                                                else
646                                                {
647                                                //Caso do atributo de expiracao de senhas estar no formato unixtime
648                                                if (($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0])&&($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0] < $now)&&($ldap_info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0]!="-1"))
649                                                        {
650                                                        //Senha do usuario estah expirada, pressupoe-se que colocou a senha certa, pois o erro do ldap eh o mesmo (49)
651                                                        //system('echo "Detectou expiracao de senhas: " >>/tmp/controle');
652                                                        if(isset($GLOBALS['phpgw_info']['server']['webserver_url']))
653                                                                {
654                                                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=98&ts=202');
655                                                                }
656                                                                else
657                                                                {
658                                                                //Entra aqui em duas ocasioes - quando expirado:
659                                                                        //login errado na tela sem troca de senhas
660                                                                        //troca de senhas com a senha atual errada
661                                                                if(isset($_POST['npasswd']))
662                                                                        {
663                                                                        //Nao logou porque o usuario estah com a senha expirada - troca de senhas
664                                                                        //Pode ter errado a senha também.
665                                                                        //system('echo "NAO Achou a url - tela troca de senhas: " >>/tmp/controle');
666                                                                        $GLOBALS['phpgw']->redirect_link("" . '/logout.php?cd=5&ts=202');
667                                                                        }
668                                                                        else
669                                                                        {
670                                                                        //Nao logou porque o usuario estah com a senha expirada - tela inicial
671                                                                        //Para o caso de usuario que tenta se logar na tela inicial com a senha expirada
672                                                                        //system('echo "NAO Achou a url - tela inicial: " >>/tmp/controle'); //funciona
673                                                                        $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=98&ts=202'); //funciona
674                                                                        }
675                                                                }
676                                                        }
677                                                        else
678                                                        {
679                                                        //senha do usuario nao estah expirada e, como o ldap deu login invalido, ocorreu erro de senha
680                                                        //system('echo "NAO estah expirado: " >>/tmp/controle');
681                                                        if(isset($_POST['npasswd']))
682                                                                {
683                                                                     $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=5&ts=202');
684                                                                }
685                                                                else
686                                                                {
687                                                                     $GLOBALS['phpgw']->redirect_link("" . '/login.php?cd=5');
688                                                                }
689                                                        }
690                                                }
691                                        }
692                                }
693                                else
694                                {
695                                if ($GLOBALS['phpgw']->session->cd_reason == 98)
696                                        {
697                                        //fazendo o redirecionamento para o caso de bloqueio de por excesso de tentativas erradas
698                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason.'&ts=202');
699                                        }
700                                        else
701                                        {
702                                        // trocasenha soh vai existir qdo o form for gerado via chamada anterior com com "cd=202"
703                                        if($_POST['cdx']=='202' )
704                                                {
705                                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason.'&ts=202');
706                                                }
707                                                else
708                                                {
709                                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
710                                                }
711                                        }
712                                }
713                        }
714                }
715                else
716                {
717                //Realiza a troca de senhas caso a política seja local, ou seja, caso o diretorio continue autenticando o usuario com a senha expirada.
718                //system('echo "Encontrou número de sessao" >> /tmp/controle');
719                // Atencao: se existir o cpo "npasswd"  providencia a troca da senha do usuario....
720                if($_POST['npasswd'])
721                        {
722                        //system('echo "entrou no change" >> /tmp/controle');
723                        //$GLOBALS['phpgw']->auth->change_password($passwd, $_POST['npasswd']);
724                        if($GLOBALS['phpgw_info']['server']['politicasenhas']=='expresso')
725                                {
726                                $GLOBALS['phpgw']->auth->change_password_user($passwd, $_POST['npasswd'],$dn,false);
727                                }
728                                else
729                                {
730                                $GLOBALS['phpgw']->auth->change_password_user($passwd, $_POST['npasswd'],$dn,true);
731                                }
732                        // TESTA SE DEVE CIFRAR A SENHA COM CHAVE PUBLICA DO CERTIFICADO (PARA LOGIN COM CERTIFICADO)...
733                        if($GLOBALS['phpgw_info']['server']['certificado'])
734                        {
735                        if(!$GLOBALS['phpgw_info']['server']['atributousuarios'] or $GLOBALS['phpgw_info']['server']['atributousuarios'] == "person")
736                                {
737                                        $RR = grava_senha_criptografada_com_certificado_no_ldap($_POST['user'],$_POST['npasswd']);
738                                }
739                        }
740                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/logout.php?cd=209');
741                        }
742                if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
743                        $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
744                        {
745                        $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
746                        }
747                if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
748                        {
749                        $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
750                        }
751                $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
752                if (!$forward)
753                        {
754                        $extra_vars['cd'] = 'yes';
755                        $forward = '/home.php';
756                        }
757                else
758                        {
759                        list($forward,$extra_vars) = explode('?',$forward,2);
760                        }
761                if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
762                        {
763                        $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
764                        echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
765                        }
766                else
767                        {
768                        $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
769                        }
770                }
771        }
772        else
773        {
774        // !!! DONT CHANGE THESE LINES !!!
775        // If there is something wrong with this code TELL ME!
776        // Commenting out the code will not fix it. (jengo)
777        if(isset($_COOKIE['last_loginid']))
778                {
779                $accounts = CreateObject('phpgwapi.accounts');
780                $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
781
782                if($prefs->account_id)
783                        {
784                        $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
785                        }
786                }
787        if ($_GET['lang'])
788                {
789                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
790                }
791        elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
792                {
793                // If the lastloginid cookies isn't set, we will default to the first language,
794                // the users browser accepts.
795                list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
796                /*
797                if(strlen($lang) > 2)
798                {
799                        $lang = substr($lang,0,2);
800
801                }
802                */
803                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
804                }
805        #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
806        $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
807        $GLOBALS['phpgw']->translation->add_app('login');
808        $GLOBALS['phpgw']->translation->add_app('loginscreen');
809        if(lang('loginscreen_message') == 'loginscreen_message*')
810                {
811                $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
812                }
813        if(lang('loginscreen_message') != 'loginscreen_message*')
814                {
815                $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
816                }
817        }
818if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
819        {
820        $organization_select = "<tr><td width=\"66\" class=\"loginLabel\">";
821        $organization_select .= lang("organization").":</td>";
822        $organization_select .="<td width=\"135\">";
823        $organization_select .="<select name=\"organization\">\n";
824        $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
825        $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
826        for ($i=0; $i<count($organizations); $i++)
827                {
828                $tmp_array[strtolower($organizations[$i])] = $organizations[$i];
829                }
830        $arrayOrganization = $tmp_array;
831        ksort($arrayOrganization);
832        foreach($arrayOrganization as $organization_name => $organization_vars)
833                {
834                $organization_select .= '<option value="' . $organization_name . '"';
835                if($organization_name == $_COOKIE['last_organization'])
836                        {
837                        $organization_select .= ' selected';
838                        }
839                $organization_select .= '>' . $organization_vars . "</option>\n";
840                }
841        $organization_select .= "</select>\n";
842        $organization_select .="</td><td>&nbsp;</td></tr>";
843        $tmpl->set_var('select_organization',$organization_select);
844        }
845$domain_select = '&nbsp;';
846$last_loginid = $_COOKIE['last_loginid'];
847if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
848        {
849        $domain_select = "<select name=\"logindomain\">\n";
850        foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
851                {
852                $domain_select .= '<option value="' . $domain_name . '"';
853                if($domain_name == $_COOKIE['last_domain'])
854                        {
855                        $domain_select .= ' selected';
856                        }
857                $domain_select .= '>' . $domain_name . "</option>\n";
858                }
859        $domain_select .= "</select>\n";
860        }
861        elseif($last_loginid !== '')
862                {
863                reset($GLOBALS['phpgw_domain']);
864                list($default_domain) = each($GLOBALS['phpgw_domain']);
865                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
866                        {
867                        $last_loginid .= '@' . $_COOKIE['last_domain'];
868                        }
869                }
870$tmpl->set_var('select_domain',$domain_select);
871foreach($_GET as $name => $value)
872        {
873        if(ereg('phpgw_',$name))
874                {
875                $extra_vars .= '&' . $name . '=' . urlencode($value);
876                }
877        }
878if($extra_vars)
879        {
880        $extra_vars = '?' . substr($extra_vars,1);
881        }
882
883        /********************************************************\
884        * Check is the registration app is installed, activated  *
885        * And if the register link must be placed                *
886        \********************************************************/
887
888$cnf_reg = createobject('phpgwapi.config','registration');
889$cnf_reg->read_repository();
890$config_reg = $cnf_reg->config_data;
891
892if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
893        {
894        $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
895        }
896$GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
897$tmpl->set_var('register_link',$reg_link);
898$tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
899$tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
900$tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
901$tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
902$tmpl->set_var('cd',check_logoutcode($_GET['cd']));
903$tmpl->set_var('cd_field',$_GET['cd']);
904$tmpl->set_var('cookie',$last_loginid);
905$tmpl->set_var('lang_password',lang('password'));
906$tmpl->set_var('lang_login',lang('login'));
907
908$aux_captcha = '';
909// soh mostra o captcha se for login sem certificado....
910if($GLOBALS['phpgw_info']['server']['captcha'] && $_GET['cd']!='300' )
911        {
912                if($valor_cookie > $GLOBALS['phpgw_info']['server']['num_badlogin'])
913                        {
914                                $aux_captcha = '<tr><td colspan=1 class="codigoLabel" width="100" style="padding-left: 15px; padding-top: 10px; padding-right: 5px" ><img src="./seguranca/captcha.php" title="'.lang('Security code').'" alt="'.lang('Security code').'" width="70"  ><b>----></b></td> <td align="right"  style="padding-right: 10px"><input name="codigo" type="text" size="18"  title="'.lang('Type the security code').'"></td> </tr>';
915                                $tmpl->set_var('captcha',$aux_captcha);
916                        }
917        }
918
919if ($_GET['ts']=='202')
920        {
921        $tmpl->set_var('cdx','202');
922        $tmpl->set_var('yn','display:yes');
923        $tmpl->set_var('lang_username',lang('username'));
924        $tmpl->set_var('CPF','<input name="user" size="18" value="" MAXLENGTH="30">');
925        $senha = ' <td width="153" class="loginLabel">'.lang('password').'&nbsp;</td>
926                                <td width="105"><input name="passwd" type="password" size="18" onKeyDown="javascript:submitIt(event)"></td>';
927        $tmpl->set_var('senha',$senha);
928        $aux_html = '<tr>
929                                <td width="140" class="loginLabel" >'.lang('New Password').'</td>
930                                <td width="105"><input name="npasswd" type="password" size="18" ><br></td>
931                                </tr>
932                                <tr>
933                                <td width="155" class="loginLabel" >'.lang('Confirm New Password').'</td>
934                                <td width="105"><input name="cnpasswd" type="password" size="18" ><br></td>
935                                </tr>';
936        $tmpl->set_var('trocasenha',$aux_html);
937        $tmpl->set_var('botao','<input type="submit" value="' . lang('signin') .'" name="submitit" class="button" onClick="javascript:setLogin()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
938        }
939else
940        {
941        # aqui vai colocar a applet; ATENCAO: TEM DE TESTAR SE O STIO FOI CONFIGURADO PARA TRATAR CERTIFICADO DIGITAL - VER NO HEADER._INC.PHP
942        /*if($GLOBALS['phpgw_info']['server']['certificado']==1)
943        {
944                $cod_applet = '<tr><td colspan=2 align="CENTER">
945                                        <object style="display:yes" id="login_applet"
946                                        classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="300" height="125">
947                                        <param name="type" value="application/x-java-applet;version=1.4">
948                                        <param name="code" value="br.gov.serpro.ui.LoginApplet.class">
949                                        <param name="mayscript" value="true">
950                                        <param name="archive" value="ExpressoCert.jar">
951                                        <comment>
952                                        <embed code="br.gov.serpro.ui.LoginApplet.class" archive="./ExpressoCert.jar"
953                                        type="application/x-java-applet;version=1.4" width="300" height="125" mayscript="true" >
954                                        <noembed>
955                                        No Java Support.
956                                        </noembed>
957                                        </embed>
958                                        </comment>
959                                        </object>
960                                        </td></tr> ';
961                $tmpl->set_var('applet',$cod_applet);
962                $tmpl->set_var('CPF','<input type="hidden" name="user" size="18"  >');
963                $tmpl->set_var('senha','<td width="105"><input name="passwd" type="hidden" size="18" ></td>');
964                $tmpl->set_var('yn','display: none');
965        }
966        else
967        {*/
968                if ($_GET['cd']=='300' && $GLOBALS['phpgw_info']['server']['certificado']==1){
969                        //Zera o Cookie contador, responsavel pelo captcha
970                        $valor_cookie = 1;
971                        setcookie("contador", 1,0);
972                        $link_alterna_login = '<a title="Link para acesso sem Certificado Digital" href="login.php"><font color="#2030F0" face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>' . lang('Access without Digital Certificate') . '</b></font></a><br>';
973                        $tmpl->set_var('yn','display:yes');
974                        $tmpl->set_var('lang_username','');
975                        $tmpl->set_var('CPF','<input name="user" type="hidden" size="18" value="" MAXLENGTH="30">');
976                        $senha = '<tr><td colspan=2 align="center"><img border=0 src="phpgwapi/templates/serpro/images/acao.gif"/></td></tr><td width="153" class="CertLabel">Acessando o Certificado Digital.</td>
977                                                <td><input name="passwd" type="hidden" size="18" onKeyDown="javascript:submitIt(event)"></td>';
978                        $tmpl->set_var('senha',$senha);
979                        $tmpl->set_var('botao','');
980
981                        // gera paramero com tokens suportados ....
982                        $var_tokens = '';
983                        for($ii = 1; $ii < 11; $ii++)
984                                {
985                                        if($GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'])
986                                                $var_tokens .= $GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'] . ',';
987                                }
988
989                        if(!$var_tokens)
990                                {
991                                        $var_tokens = 'ePass2000Lx;/usr/lib/libepsng_p11.so,ePass2000Win;c:/windows/system32/ngp11v211.dll';
992                                }
993                        $param1 = "
994                                                '<param name=\"token\" value=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\"> ' +
995                                               ";
996                        $param2 = "
997                                                'token=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\" ' +
998                                               ";
999                               
1000                        $cod_applet =
1001
1002/*    // com debug ativado
1003            '<script type="text/javascript">
1004                                        if (navigator.userAgent.match(\'MSIE\')){
1005                                                document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
1006                                                \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
1007                                                \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
1008                                                \'<param name="code" value="LoginApplet.class"> \' +
1009                                                \'<param name="locale" value="' . $lang . '"> \' +
1010                                                \'<param name="mayscript" value="true"> \' + '
1011                                                . $param1
1012                                                . ' \'<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"> \' +
1013                        \'<param name="debug" value="true"> \' +
1014                                                \'</object>\');
1015                                        }
1016                                        else {
1017                                                document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" code="LoginApplet.class" locale="' . $lang . '"\' +
1018                                                \'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" \' + '
1019                                                . $param2
1020                                                . ' \'type="application/x-java-applet;version=1.5" debug= "true" mayscript > \' +
1021                                                \'<noembed> \' +
1022                                                \'No Java Support. \' +
1023                                                \'</noembed> \' +
1024                                                \'</embed> \');
1025                                        }
1026                                </script>';
1027*/
1028            // sem debug ativado
1029            '<script type="text/javascript">
1030                                        if (navigator.userAgent.match(\'MSIE\')){
1031                                                document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
1032                                                \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
1033                                                \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
1034                                                \'<param name="code" value="LoginApplet.class"> \' +
1035                                                \'<param name="locale" value="' . $lang . '"> \' +
1036                                                \'<param name="mayscript" value="true"> \' + '
1037                                                . $param1
1038                                                . ' \'<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"> \' +
1039                                                \'</object>\');
1040                                        }
1041                                        else {
1042                                                document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" code="LoginApplet.class" locale="' . $lang . '"\' +
1043                                                \'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" \' + '
1044                                                . $param2 
1045                                                . ' \'type="application/x-java-applet;version=1.5" mayscript > \' +
1046                                                \'<noembed> \' +
1047                                                \'No Java Support. \' +
1048                                                \'</noembed> \' +
1049                                                \'</embed> \');
1050                                        }
1051                                </script>';
1052
1053
1054                }
1055
1056                else{
1057                        if($GLOBALS['phpgw_info']['server']['certificado']==1)
1058                        {
1059                                $link_alterna_login = '<img border=0 style="margin: 0px; padding: 0px" src="phpgwapi/templates/serpro/images/lock1_icon.gif"/><a title="' . lang('Link to use digital certificate') . '" href="login.php?cd=300" style="margin: 0px; padding: 0px"><font color="#2030F0" face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>' . lang('Logon with my digital certificate') . '</b></font></a><br>';
1060                        }
1061                        $tmpl->set_var('yn','display:yes');
1062                        $tmpl->set_var('lang_username',lang('username'));
1063                        $tmpl->set_var('CPF','<input name="user" size="18" value="" MAXLENGTH="30">');
1064                        $senha = ' <td width="153" class="loginLabel">'.lang('password').'&nbsp;</td>
1065                                                <td width="105"><input name="passwd" type="password" size="18" onKeyDown="javascript:submitIt(event)"></td>';
1066                        $tmpl->set_var('senha',$senha);
1067                        $tmpl->set_var('botao','<input type="submit" value="' . lang('signin') .'" name="submitit" class="button" onClick="javascript:setLogin()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
1068
1069                        $cod_applet = '&nbsp;';
1070                        $tmpl->set_var('applet',$cod_applet);
1071
1072                }
1073                /*
1074                else
1075                {
1076                        $tmpl->set_var('yn','display:yes');
1077                        $tmpl->set_var('lang_username',lang('username'));
1078                        $tmpl->set_var('CPF','<input name="user" size="18" value="" MAXLENGTH="30" >');
1079                        $senha = ' <td width="153" class="loginLabel">'.lang('password').'&nbsp;</td>
1080                                                <td width="105"><input name="passwd" type="password" size="18" onKeyDown="javascript:submitIt(event)"></td>';
1081                        $tmpl->set_var('senha',$senha);
1082                        $tmpl->set_var('botao','<input type="submit" value="' . lang('signin') .'" name="submitit" class="button" onClick="javascript:setLogin()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
1083
1084                        $cod_applet = '&nbsp;';
1085                        $tmpl->set_var('applet',$cod_applet);
1086                }
1087                */
1088                $tmpl->set_var('applet',$cod_applet);
1089                $tmpl->set_var('link_alterna_login',$link_alterna_login);
1090               
1091        //}
1092    }
1093
1094$tmpl->set_var('xhelp1',lang('Click to help'));
1095$tmpl->set_var('xhelp2',lang('Click to help'));
1096
1097$tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
1098$tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
1099$tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
1100$tmpl->set_var('login_caixa_bg_color',($GLOBALS['phpgw_info']['server']['login_caixa_bg_color']?$GLOBALS['phpgw_info']['server']['login_caixa_bg_color']:'FFFFFF'));
1101$tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
1102if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
1103        {
1104        $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
1105        }
1106else
1107        {
1108        $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'');
1109        }
1110
1111        if (substr($GLOBALS['phpgw_info']['server']['imagem_de_fundo'],0,4) == 'http')
1112        {
1113        $var['imagem_de_fundo'] = $GLOBALS['phpgw_info']['server']['imagem_de_fundo'];
1114        }
1115else
1116        {
1117        #$var['imagem_de_fundo'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['imagem_de_fundo']?$GLOBALS['phpgw_info']['server']['imagem_de_fundo']:'back.jpg');
1118        $var['imagem_de_fundo'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['imagem_de_fundo']);
1119        }
1120$var['imagem_de_fundo_exibicao'] = ($GLOBALS['phpgw_info']['server']['imagem_de_fundo_exibicao'] != ''?$GLOBALS['phpgw_info']['server']['imagem_de_fundo_exibicao']:"background-repeat:repeat-x; overflow:auto;overflow-x:hidden;");
1121$var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
1122if (substr($var['logo_url'],0,4) != 'http')
1123        {
1124        $var['logo_url'] = 'http://'.$var['logo_url'];
1125        }
1126$var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
1127
1128 // {logo_imagem}
1129//  <a href="{logo_url}" title="{logo_title}" style="text-decoration: none;" target="_blank"><img src="{logo_file}"  border="0" style="margin-top: 5px; width: 300px; height: 200px;"/></a>
1130if($var['logo_file'] == '')
1131{
1132  $var['logo_imagem'] = '';
1133}
1134else
1135{
1136  $var['logo_imagem'] = '<a href="'.$var['logo_url'].'" title="'.$var['logo_title'].'" style="text-decoration: none;" target="_blank"><img src="'.$var['logo_file'].'"  border="0" style="margin-top: 5px; width: 200px; height: 134px;"/></a>';
1137}
1138$tmpl->set_var($var);
1139if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
1140        {
1141        $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
1142        $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
1143        uasort($langs,'strcasecmp');
1144        foreach ($langs as $key => $name)       // if we have a translation use it
1145                {
1146                $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
1147                }
1148        $select_lang .= "\n</select>\n";
1149        $tmpl->set_var(array(
1150                'lang_language' => lang('Language'),
1151                'select_language' => $select_lang,
1152        ));
1153        }
1154        else
1155        {
1156        $tmpl->set_block('login_form','language_select');
1157        $tmpl->set_var('language_select','');
1158        }
1159$tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
1160$tmpl->set_var('vserpro','<font color="#9a9a9a" face="Verdana, Arial, Helvetica, sans-serif" size="1">V - '.$GLOBALS['phpgw_info']['server']['versions']['header'].'-'.$GLOBALS['phpgw_info']['server']['versao-Serpro'].'</font>');
1161
1162$assinaminfazenda = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/serpro/images/AssinaMinFazenda2.gif' ;
1163$brasil = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/serpro/images/brasil2.gif' ;
1164$tmpl->set_var('assinaminfazenda',$assinaminfazenda);
1165$tmpl->set_var('brasil',$brasil);
1166
1167if($GLOBALS['phpgw_info']['server']['alimentador_rss'])  // http://serpronet.serpro/serpauta/RSS
1168 {
1169        require_once('./seguranca/simplepie.inc');
1170        $feed = new SimplePie();
1171
1172        $feed->set_feed_url($GLOBALS['phpgw_info']['server']['alimentador_rss']);   //  alimentador_rss
1173        $feed->set_output_encoding('iso-8859-1');
1174        $feed->set_timeout(30);
1175        $feed->enable_cache(false);
1176        $feed->init();
1177
1178        // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
1179        $feed->handle_content_type();
1180        $rss_titulo = $feed->get_title();
1181        if(!$rss_titulo)
1182        {
1183                // Continua pegando a msg de erro, mas nao vai exibir nada.....
1184                //$rss_titulo = $feed->error();
1185                $rss_titulo = 'N&atilde;o foi poss&iacute;vel contatar alimentador das not&iacute;cias.';
1186        }
1187        else
1188        {
1189                $aux_rss ='<div class="container">
1190                        <div class="titulo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Not&iacute;cias - Fonte: ' . $rss_titulo . '</div>';
1191
1192                $numero_max = 1;
1193                foreach ($feed->get_items() as $item):
1194                        $aux_1 = $item->get_permalink();
1195                        $aux_2 = $item->get_title();
1196                        $aux_3 = $item->get_date('d/m/Y - H:i');
1197                        $aux_rss = $aux_rss . '<div class="item">
1198                                <h2 style="margin: 0px"><a href="' . $aux_1 . '"   target="_blank">' . $aux_2 . '</a></h2>
1199                                <p style="margin: 0px;font-size: 8">' . $aux_3 . '</p></div>';
1200                        $numero_max = $numero_max+1;
1201                        if($numero_max>7) break;
1202                endforeach;
1203
1204                $aux_rss = $aux_rss . '</div>';
1205                $feed->__destruct();
1206                $tmpl->set_var('rss',$aux_rss);
1207                //  posiciona_login
1208                if($GLOBALS['phpgw_info']['server']['posiciona_login'])
1209                {
1210                        $tmpl->set_var('float_rss','float:left;');       // left
1211                }
1212                else
1213                {
1214                        $tmpl->set_var('float_rss','float:right;');      // right
1215                }
1216        }
1217 }
1218 
1219$tmpl->pfp('loginout','login_form');
1220
1221?>
1222
Note: See TracBrowser for help on using the repository browser.