Ignore:
Timestamp:
09/13/10 15:01:56 (14 years ago)
Author:
rafaelraymundo
Message:

Ticket #1237 - Atualizados componentes de suporte ao uso do Certificado Digital.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/security/certs_xml.php

    r1174 r3232  
    11<?php 
     2        $GLOBALS['phpgw_info'] = array(); 
     3        $GLOBALS['phpgw_info']['flags'] = array('noheader'   => True,'nonavbar'   => True,'currentapp' => 'admin'); 
     4        include('../header.inc.php'); 
    25        require_once('classes/CertificadoB.php'); 
     6        $xml  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 
    37        // pega caminho completo do arquivo de CAS.. 
    4         $path3 =$GLOBALS['CAs']; 
     8        $path3 =$GLOBALS['CAs']; 
    59        // se não pude acessar o arquivo com certificados retornar ..... 
    6         if(!is_file($path3)) exit(); 
    7         $xml  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 
     10        if(!is_file($path3)) 
     11            { 
     12                $xml .= '<certificados><cert><item>' . $path3 .  '</item><nome>Path para pasta com certificados esta invalida</nome><validade></validade></cert></certificados>'; 
     13                Header('Content-type: application/xml; charset=utf-8'); 
     14                echo $xml; 
     15                exit(); 
     16            } 
    817        $todos_certificados = ler_certificados_CAS($path3); 
    918        $CB = new CertificadoB(); 
    10         if($_REQUEST['id']) 
    11                 { 
    12                         if($_REQUEST['id'] != 'A') 
    13                                 { 
    14                                         // id indica o certificado solicitado .... 
    15                                         $aux = explode('-',$_REQUEST['id']); 
    16                                         if(count($aux) > 1) 
    17                                                 { 
    18                                                         $id =$aux[0]; 
    19                                                         $id = $id -1; 
    20                                                 } 
    21                                         else 
    22                                                 { 
    23                                                         $id = 0; 
    24                                                 } 
    25                                         // Pega o certificado solicitado ... 
    26                                         $certificado = $todos_certificados[$id]; 
    27                                         // Vai parsear, e gerar o xml ... 
    28                                         $CB -> certificado($certificado); 
    29                                         // Pega o xml com os dados do certificado .. 
    30                                         $xml .= $CB -> dados_xml; 
    31                                 } 
    32                         else 
    33                                 { 
    34                                         // Requisitado todo o conteudo do arquivo de CAs .. 
    35                                         $item = 1; 
    36                                         $xml .= "<certs>"; 
    37                                         foreach($todos_certificados as $certificado) 
    38                                                 { 
    39                                                         $CB -> certificado($certificado); 
    40                                                         $df = $CB -> dados['FIM_VALIDADE']; 
    41                                                         $xml .= '<certs>'; 
    42                                                         $xml .= '  <nome>' .  
    43                                                                                         $item++ . ' - ' .  
    44                                                                                         $CB->dados['SUBJECT']['CN'] . 
    45                                                                                         '  ( Expira Em: ;' . substr($df,0,4) .  
    46                                                                                         '/' .  
    47                                                                                         substr($df,4,2) .  
    48                                                                                         '/' .  
    49                                                                                         substr($df,6,2) .  
    50                                                                                         '  -  ' .  
    51                                                                                         substr($df,8,2) .  
    52                                                                                         ':' .  
    53                                                                                         substr($df,10,2) .  
    54                                                                                         ':' .  
    55                                                                                         substr($df,12,2) .  
    56                                                                                         ' GMT )' .  
    57                                                                         '</nome>';  
    58                                                         $xml .= '</certs>'; 
    59                                                 } 
    60                                         $xml .= "</certs>";  
    61                                 } 
    62                 } 
     19        //$_POST['id'] = 'A'; 
     20        if($_POST['id']) 
     21            { 
     22                if($_POST['id'] != 'A') 
     23                    { 
     24                        // id indica o certificado solicitado .... 
     25                        $aux = explode('-',$_POST['id']); 
     26                        if(count($aux) > 1) 
     27                            { 
     28                                $id =$aux[0]; 
     29                                $id = $id -1; 
     30                            } 
     31                        else 
     32                            { 
     33                                $id = 0; 
     34                            } 
     35                        // Pega o certificado solicitado ... 
     36                        $certificado = $todos_certificados[$id]; 
     37                        // Vai parsear, e gerar o xml ... 
     38                        $CB -> certificado($certificado); 
     39                        // Pega o xml com os dados do certificado .. 
     40                        $xml .= $CB -> dados_xml; 
     41                    } 
     42                else 
     43                    { 
     44                        // Requisitado todo o conteudo do arquivo de CAs .. 
     45                        $item = 1; 
     46                        $processados = array(); 
     47                        $xml .= "<certificados>"; 
     48                        //$xml .= '<cert><item>0</item><nome>Parametro  xxxxxxxxxx xxxxxxxxxxxxxxxxxxxx invalido.</nome><validade>  asdad </validade></cert>'; 
     49                         
     50                        foreach($todos_certificados as $certificado) 
     51                            { 
     52                                $CB -> certificado($certificado); 
     53                                $df = $CB -> dados['FIM_VALIDADE']; 
     54                                $xml .= '<cert>'; 
     55                                $xml .= '<item>' . $item++ . '</item>'; 
     56                                $xml .= '  <nome>' . $CB->dados['SUBJECT']['CN'] . '</nome>'; 
     57                                if($processados[$CB->dados['SUBJECT']['CN']]) 
     58                                    { 
     59                                        $alerta = '<font color="#FF0000"><b>DUPLICADO (veja o item ' . $processados[$CB->dados['SUBJECT']['CN']] . ' acima) </b></font>'; 
     60                                    } 
     61                                else 
     62                                    { 
     63                                        $alerta = ''; 
     64                                        $processados[$CB->dados['SUBJECT']['CN']] = $item-1; 
     65                                    } 
     66                                $xml .= '<validade> ' . $alerta . ' Valido ate ' . substr($df,0,4) . '/' . substr($df,4,2) . 
     67                                                '/' . 
     68                                                substr($df,6,2) . 
     69                                                '  -  ' . 
     70                                                substr($df,8,2) . 
     71                                                ':' . 
     72                                                substr($df,10,2) . 
     73                                                ':' . 
     74                                                substr($df,12,2) . 
     75                                        ' GMT' . '</validade>'; 
     76                                $xml .= '</cert>'; 
     77                            } 
     78                          
     79                          
     80                        $xml .= "</certificados>"; 
     81 
     82                    } 
     83            } 
    6384        else  
    64                 { 
    65                         exit();  
    66                 } 
     85            { 
     86                $xml .= '<certificados><cert><item>99</item><nome>Parametro invalido.</nome><validade> </validade></cert></certificados>'; 
     87            } 
    6788        # Fecha o processamento de geracao do xml  com um CABEÇALHO 
    68         Header('Content-type: application/xml; charset=utf-8');  
     89        Header('Content-type: application/xml; charset=utf-8'); 
    6990        echo $xml; 
    7091    ?> 
Note: See TracChangeset for help on using the changeset viewer.