[3232] | 1 | <?php |
---|
| 2 | |
---|
| 3 | function salva_arquivo_bkp($nome_atual,$novo_nome) |
---|
| 4 | { |
---|
| 5 | if(!is_file($nome_atual)) return; |
---|
| 6 | $path_parts = pathinfo($novo_nome); |
---|
| 7 | if(!is_dir($path_parts['dirname'])) return; |
---|
| 8 | if(is_file($novo_nome)) return; |
---|
| 9 | $cmd = 'cp -p ' . $nome_atual . ' ' . $novo_nome; |
---|
| 10 | $ret = system($cmd,$status); |
---|
| 11 | return $status; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | function gera_nome_arquivo_bkp($path3) |
---|
| 15 | { |
---|
| 16 | if(!is_file($path3)) return NULL; |
---|
| 17 | /* |
---|
| 18 | $tab = 'ABCDEFGHIJKLMNOPQRSTUVXYZW'; |
---|
| 19 | $i = rand(0,25); |
---|
[7655] | 20 | for($a1=0;$a1<3;++$a1) |
---|
[3232] | 21 | { |
---|
| 22 | $i = rand(0,25); |
---|
| 23 | $xx .= substr($tab,$i,1); |
---|
| 24 | } |
---|
| 25 | */ |
---|
| 26 | $partes = explode('.',$path3); |
---|
| 27 | /* |
---|
| 28 | if($partes[1]) |
---|
| 29 | { |
---|
| 30 | $novo = $partes[0] . '-' . date('ymd-His') . '-' . $xx . '.' . $partes[1]; |
---|
| 31 | } |
---|
| 32 | else |
---|
| 33 | { |
---|
| 34 | $novo = $partes[0] . '-' . date('ymd-His') . '-' . $xx; |
---|
| 35 | } |
---|
| 36 | */ |
---|
| 37 | if($partes[1]) |
---|
| 38 | { |
---|
| 39 | $novo = $partes[0] . '~' . '.' . $partes[1]; |
---|
| 40 | } |
---|
| 41 | else |
---|
| 42 | { |
---|
| 43 | $novo = $partes[0] . '~'; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | return $novo; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | function ler_arquivos_de_uma_pasta($dir) |
---|
| 50 | { |
---|
| 51 | // Abre um diretorio conhecido, e lista nome dos arquivos... |
---|
| 52 | $retorno = array(); |
---|
| 53 | if (is_dir($dir)) |
---|
| 54 | { |
---|
| 55 | $dh = opendir($dir); |
---|
| 56 | while (($file = readdir($dh)) !== false) |
---|
| 57 | { |
---|
| 58 | if($file[0] != '.') $retorno[] = $file; |
---|
| 59 | } |
---|
| 60 | closedir($dh); |
---|
| 61 | } |
---|
| 62 | return $retorno; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | function Gerar_Estruturas_Certificados($todos_certificados) |
---|
| 66 | { |
---|
| 67 | if(!is_array($todos_certificados)) return array(); |
---|
| 68 | $item = 1; |
---|
| 69 | //$x_conta = 1; |
---|
| 70 | $aux_emissores= array(); |
---|
| 71 | $tab_certs = array(); |
---|
| 72 | $CB = new CertificadoB(); |
---|
| 73 | foreach($todos_certificados as $certificados) |
---|
| 74 | { |
---|
| 75 | $CB -> certificado($certificados); |
---|
| 76 | |
---|
| 77 | $proprietario = $CB->dados['SUBJECT']['CN']; |
---|
| 78 | $df = $CB->dados['FIM_VALIDADE']; |
---|
| 79 | $di = $CB->dados['INICIO_VALIDADE']; |
---|
| 80 | if(gmdate("YmdHis") > $df) |
---|
| 81 | { |
---|
| 82 | $cor = '<label style="color: #FF0000" >Expirado em: </label>'; |
---|
| 83 | $dt_df_x = 'Expirado em: '; |
---|
| 84 | } |
---|
| 85 | else |
---|
| 86 | { |
---|
| 87 | $cor = '<label>Valido até </label>'; |
---|
| 88 | $dt_df_x = 'Valido até '; |
---|
| 89 | } |
---|
| 90 | $dt_df = substr($df,0,4) . '/' . substr($df,4,2) . '/' . substr($df,6,2) . ' - ' . substr($df,8,2) . ':' . substr($df,10,2) . ':' . substr($df,12,2) . ' GMT'; |
---|
| 91 | $info = $cor . $dt_df; |
---|
| 92 | $info = '<font size="1"' . $info . '</font>'; |
---|
| 93 | // Armazena alguns dados do certificado. $tabs_certs esta na mesma ordem em que os certificados aparecem no arquivo todos.cer..... |
---|
| 94 | $tab_certs[$proprietario]['item'] = $item++; |
---|
| 95 | $tab_certs[$proprietario]['certificado'] = $certificados; |
---|
| 96 | $tab_certs[$proprietario]['emissor'] = $CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN']; |
---|
| 97 | $tab_certs[$proprietario]['fim_validade'] = $info; |
---|
| 98 | $tab_certs[$proprietario]['inicio_validade'] = $di; |
---|
| 99 | if($CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN'] != $CB->dados['SUBJECT']['CN']) |
---|
| 100 | { |
---|
| 101 | // Se nao he um auto assinado (identifica um raiz), salva emissor , faz a chave a tdata de inicio de validade do certificado... |
---|
| 102 | $aux_emissores[$di][$CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN']][$CB->dados['SUBJECT']['CN']] = '9' ; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | // ordena certificados pela data de inicio de validade ...... |
---|
| 106 | ksort($aux_emissores); |
---|
| 107 | return array($aux_emissores,$tab_certs); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | ?> |
---|