[3232] | 1 | <?php
|
---|
| 2 | $GLOBALS['phpgw_info'] = array();
|
---|
| 3 | $GLOBALS['phpgw_info']['flags'] = array('noheader' => True,'nonavbar' => True,'currentapp' => 'admin');
|
---|
| 4 | include('../header.inc.php');
|
---|
| 5 | require_once('classes/CertificadoB.php');
|
---|
| 6 | require_once('security-lib.php');
|
---|
| 7 |
|
---|
| 8 | Header('Content-type: application/xml; charset=utf-8');
|
---|
| 9 | // Se nao puder identificar o certificado e ou o arquivo, retornar .....
|
---|
| 10 | if(!$_POST['arquivo'] || !$_POST['id'])
|
---|
| 11 | {
|
---|
| 12 | echo "<certificados>NOK1</certificados>";
|
---|
| 13 | exit();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | // pega caminho completo do arquivo de CAS..
|
---|
| 17 | $path_parts = pathinfo($GLOBALS['CAs']);
|
---|
| 18 | $path3 = $path_parts['dirname'] . '/' . $_POST['arquivo'];
|
---|
| 19 | $todos_certificados = ler_certificados_CAS($path3);
|
---|
| 20 | $flg = 0;
|
---|
| 21 | $aux = '';
|
---|
| 22 |
|
---|
| 23 | foreach ($todos_certificados as $key => $value)
|
---|
| 24 | {
|
---|
| 25 | // Se for o mesmo id vai desprezar o certificado.
|
---|
| 26 | if($key != $_POST['id']-1)
|
---|
| 27 | {
|
---|
| 28 | if($aux == '')
|
---|
| 29 | {
|
---|
| 30 | $aux .= $value;
|
---|
| 31 | }
|
---|
| 32 | else
|
---|
| 33 | {
|
---|
| 34 | $aux .= chr(0x0D) . chr(0x0A) . $value;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | else
|
---|
| 38 | {
|
---|
| 39 | $flg = 1;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | if($flg == 0)
|
---|
| 44 | {
|
---|
| 45 | // Nao foi possivel executar a operacao solicitada...
|
---|
| 46 | echo "<certificados>NOK2" . $path3 . "</certificados>";
|
---|
| 47 | exit();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | // Primeiro salva o arquivo original.
|
---|
| 51 | $novo_nome = gera_nome_arquivo_bkp($path3);
|
---|
| 52 | if($novo_nome == $path3)
|
---|
| 53 | {
|
---|
| 54 | echo "<certificados>NOK" . 'Falhou ao salvar arquivo (CD01)' . "</certificados>";
|
---|
| 55 | exit();
|
---|
| 56 | }
|
---|
| 57 | $ret = salva_arquivo_bkp($path3,$novo_nome);
|
---|
| 58 | if($ret != 0)
|
---|
| 59 | {
|
---|
| 60 | echo "<certificados>NOK" . 'Falhou ao salvar arquivo (CD02)' . "</certificados>";
|
---|
| 61 | exit();
|
---|
| 62 | }
|
---|
| 63 | // Agora salva o arquaivo alterado.....
|
---|
| 64 | file_put_contents($path3, $aux);
|
---|
| 65 | echo "<certificados>OK" . $path3 . "</certificados>";
|
---|
| 66 | ?>
|
---|
| 67 |
|
---|
| 68 |
|
---|