source: sandbox/2.2.0.2/security/security-cas.php @ 3377

Revision 3377, 7.9 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1310 - Traduções para msgs emitidas com uso do certificado digital.

  • Property svn:executable set to *
Line 
1<?php
2        $GLOBALS['phpgw_info'] = array();
3        $GLOBALS['phpgw_info']['flags']['currentapp'] = 'admin';
4        include('../header.inc.php');
5        require_once('classes/CertificadoB.php');
6        require_once('security-lib.php');
7        $msgs_alertas = '';
8        $path1 = $GLOBALS['arquivos_crls'];
9        $path2 = $GLOBALS['log'];
10        $path3 = $GLOBALS['CAs'];
11        if(!is_dir(dirname($path3)))
12        {
13            echo lang('Erro.') . ' ' . lang('Configuration file not found in server.');
14            exit();
15        }
16        $dir = dirname($path3);
17        /*
18        if($_POST['arquivo'] & $_POST['caminho'] )
19        {
20            if(substr($_POST['arquivo'],0,25) != '--Selecione um arquivo co')
21            {
22                $path3 = $_POST['arquivo'];
23                $dir = $_POST['caminho'];
24            }
25        }
26        */
27       
28        if ($_FILES['file'])
29            {
30                if($_FILES['file']['tmp_name'])
31                    {
32                        $saida = array();
33                        $arquivo = $_FILES['file']['tmp_name'];
34                        $w = file_get_contents($arquivo);
35                        if(strpos($w,'-----BEGIN CERTIFICATE-----') === false)
36                            {
37                                $w = '';
38                                if(count(explode(chr(0x0A),$w)) < 7 )
39                                    {
40                                        // Convertendo DER para PEM (Entrada deve ser um certificado x509).
41                                        $w = shell_exec('openssl x509 -inform DER -in ' . $arquivo . ' 2>&1');
42                                    }
43                                if(count(explode(chr(0x0A),$w)) < 7 )
44                                    {
45                                        // Convertendo PKCS7 para PEM (Entrada deve ser PEM iniciando com -----BEGIN PKCS7----- ).
46                                        $w = shell_exec('openssl pkcs7 -inform PEM -outform PEM -print_certs -in ' . $arquivo . ' 2>&1');
47                                    }
48                                if(count(explode(chr(0x0A),$w)) < 7 )
49                                    {
50                                        // Convertendo p7b para PEM ( Entrada deve ser DER).
51                                        $w =  shell_exec('openssl pkcs7 -inform DER -outform PEM -print_certs -in ' . $arquivo . ' 2>&1');
52                                    }
53                                if(count(explode(chr(0x0A),$w)) < 7 )
54                                    {
55                                        $msgs_alertas .= lang('File') . ' '. $_FILES['file']['name'] . lang('not processed. Invalid format') . '.<br/>';
56                                    }
57                            }
58                        if(!$msgs_alertas)
59                            {
60                                $conteudo = '';
61                                $saida = explode(chr(0x0A),$w);
62                                foreach ($saida as $linha)
63                                    {
64                                        if($linha != '')
65                                            {
66                                                if(substr($linha,0,7) != 'subject' && substr($linha,0,6) != 'issuer')
67                                                    {
68                                                        $conteudo .= $linha . chr(0x0A);
69                                                    }
70                                            }
71                                    }
72                                $todos = ler_certificados_CAS($conteudo,true);
73                                $conteudo = '';
74                                foreach ($todos as $cert)
75                                    {
76                                        // Trata sho certificados de CA?
77                                        $a = new certificadoB();
78                                        $a->certificado($cert);
79                                        if($a->dados['CA'])
80                                            {
81                                                $conteudo .= chr(0x0D) . chr(0x0A) . $cert;
82                                                $msgs_alertas .= lang('Certificate added to') . ' ' . $a->dados['NOME'] . ' .<br/>';
83                                            }
84                                    }
85                                if($conteudo)
86                                    {
87                                        $novo_nome = gera_nome_arquivo_bkp($path3);
88                                        if($novo_nome != $path3)
89                                            {
90                                                $ret = salva_arquivo_bkp($path3,$novo_nome);
91                                                if($ret == 0)
92                                                    {
93                                                        file_put_contents($path3,$conteudo,FILE_APPEND);
94                                                        $msgs_alertas .= lang('File updated and save') . '.';
95                                                    }
96                                                else
97                                                    {
98                                                        $msgs_alertas .= lang('Failure on save file (CD04). The requested operation is not concluded') . '.<br/>';
99                                                    }
100                                            }
101                                        else
102                                            {
103                                                $msgs_alertas .= lang('Failure on save file (CD03). The requested operation is not concluded') . '.<br/>';
104                                            }
105                                    }
106                                 else
107                                     {
108                                        $msgs_alertas .= lang('ACs certificates not found') . '.';
109                                     }
110                            }
111                    }
112            }
113       
114        echo '<script type="text/javascript" src="certificados.js"></script>';
115        echo '<div style="padding-left:90px" >';
116        echo '<form id="frm3" enctype="multipart/form-data" method="post" action="' . $_SERVER["PHP_SELF"] . '">';
117        echo '<a href="../security/security_admin.php" style="text-decoration:none"><input type="button" value="' . lang('Back') . '"/></a>';
118        $aux99 = explode('/',$path3);
119        $path3 = $aux99[count($aux99)-1];
120        echo '<br/><br/>';
121        echo '<div id="msgs"/>';
122        echo $msgs_alertas;
123        echo '</div>';
124        echo '<div id="files"/>';
125        echo '<h4 style="color: #000066">' . lang('Choose a file with CAs to add') . ':<h5>';
126        echo '<input id="file" type="file" name="file" />';
127        echo '&nbsp;&nbsp;&nbsp;&nbsp;';
128        echo '<input type="button" name="adicionar" value="' . lang('Add') . '" onclick="javascript:Submete_Cas(\'frm3\',\'' . lang('Add file contents to ACs file') . ' ?\')" />';
129        echo '</div>';
130        echo '</form>';
131        echo '<h2 id="titulo1" style="color: #000066">' . lang('Certificates in') . ' ' . $path3 . ' :</h2>';
132        echo '<div id="xdiv1" style="border: #000000 1px solid; overflow: auto; width: 870px; height: 160px; white-space: pre;  padding: 3px; " >';
133        echo '<br/><font color="#000066"><b> ' . lang('Loading ...') . '</b></font>';
134        echo '</div>';
135        echo '<br/><pre>';
136        echo '<div id="xdiv2" style="border: #000000 1px solid; overflow: auto; width: 870px; height: 180px; white-space: pre;  padding: 3px; " >';
137        echo '<br/><font color="#000066"><b> ' . lang('Loading ...') . '</b></font>';
138        echo '</div></pre>';
139        echo '<br/>';
140        echo '<a href="../security/security_admin.php" style="text-decoration:none"><input type="button" value="' . lang('Back') . '"/></a>';
141        echo '<div>';
142        echo '<script type="text/javascript"> Lista_de_Certificados(\'' . $path3 . '\'); </script>';
143       
144 ?>
Note: See TracBrowser for help on using the repository browser.