[1174] | 1 | var num = 0;
|
---|
| 2 | var titulo = '';
|
---|
| 3 |
|
---|
| 4 | function msgWin(msg,w,h,params)
|
---|
| 5 | {
|
---|
| 6 | var winl = (screen.width - w ) / 2;
|
---|
| 7 | var wint = (screen.height - h) / 2;
|
---|
| 8 | var parm = "width=" + w + ",height=" + h + ",top=" + wint + ",left=" + winl + params;
|
---|
| 9 | win3 = window.open("","12345" + num,parm);
|
---|
| 10 | num = num + 1;
|
---|
| 11 | win3.document.writeln(msg);
|
---|
| 12 | win3.focus();
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | function Um_Certificado(valor)
|
---|
| 16 | {
|
---|
| 17 | if(valor.length < 2) { return; }
|
---|
| 18 | //verifica se o browser tem suporte a ajax
|
---|
| 19 | try
|
---|
| 20 | {
|
---|
| 21 | ajax = new ActiveXObject("Microsoft.XMLHTTP");
|
---|
| 22 | }
|
---|
| 23 | catch(e)
|
---|
| 24 | {
|
---|
| 25 | try
|
---|
| 26 | {
|
---|
| 27 | ajax = new ActiveXObject("Msxml2.XMLHTTP");
|
---|
| 28 | }
|
---|
| 29 | catch(ex)
|
---|
| 30 | {
|
---|
| 31 | try
|
---|
| 32 | {
|
---|
| 33 | ajax = new XMLHttpRequest();
|
---|
| 34 | }
|
---|
| 35 | catch(exc)
|
---|
| 36 | {
|
---|
| 37 | alert("Esse browser não tem recursos para uso do Ajax");
|
---|
| 38 | ajax = null;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | //se tiver suporte ajax
|
---|
| 44 | if(ajax)
|
---|
| 45 | {
|
---|
| 46 | titulo = valor;
|
---|
| 47 | ajax.open("POST", "certs_xml.php", true);
|
---|
| 48 | ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
---|
| 49 | ajax.onreadystatechange = function()
|
---|
| 50 | {
|
---|
| 51 | //enquanto estiver processando...emite a msg de carregando
|
---|
| 52 | //if(ajax.readyState == 1)
|
---|
| 53 | // {
|
---|
| 54 | // //idOpcao.innerHTML = "Obtendo Certificados ...! ";
|
---|
| 55 | // }
|
---|
| 56 | //após ser processado - chama função processa_um_certificado que vai varrer os dados
|
---|
| 57 | if(ajax.readyState == 4 )
|
---|
| 58 | {
|
---|
| 59 | if(ajax.responseXML)
|
---|
| 60 | {
|
---|
| 61 | processa_um_certificado(ajax.responseXML);
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | //caso não seja um arquivo XML emite a mensagem abaixo
|
---|
| 66 | msg = 'Não foi possível obter dados do certificado.' + '<br/><br/><div align="center"><INPUT type="button" value="Fechar" onClick="window.close()">';
|
---|
| 67 | parms = ",scrollbars=1";
|
---|
| 68 | msgWin(msg,450,200,parms)
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | //passa o código do certificado desejado...
|
---|
| 73 | var params = "id="+valor;
|
---|
| 74 | ajax.send(params);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | function processa_um_certificado(obj)
|
---|
| 79 | {
|
---|
| 80 | // Tab com tags que deve exibir sho o nome....
|
---|
| 81 | var TBtags = new Array( "EMISSOR_CAMINHO_COMPLETO", "SUBJECT" , "CRLDISTRIBUTIONPOINTS" , "KEYUSAGE" );
|
---|
| 82 | //pega a tag certificado
|
---|
| 83 | var dataArray = obj.getElementsByTagName("certificado");
|
---|
| 84 | //total de elementos contidos na tag
|
---|
| 85 | if(dataArray.length > 0)
|
---|
| 86 | {
|
---|
| 87 | var novo = "<head><title>" + titulo + "</title></head><body><font size=2><h3 align=center ><font color=#0000EE>Dados do certificado</font></h3>";
|
---|
| 88 | //percorre o arquivo XML para extrair os dados
|
---|
| 89 | for(var i = 0 ; i < dataArray.length ; i++)
|
---|
| 90 | {
|
---|
| 91 | var item = dataArray[i];
|
---|
| 92 | var cc = item.getElementsByTagName("*");
|
---|
| 93 | len = 0;
|
---|
| 94 | for(var j = 0 ; j < cc.length ; j++)
|
---|
| 95 | {
|
---|
| 96 | //contéudo dos campos no arquivo XML
|
---|
| 97 | var tag = cc[j].nodeName
|
---|
| 98 | if(tag == "CA") continue; // skipa tag CA ....
|
---|
| 99 | var xflag = 0;
|
---|
| 100 | for(var iz = 0;iz< TBtags.length;iz++)
|
---|
| 101 | {
|
---|
| 102 | if(TBtags[iz] == tag) xflag = 1;
|
---|
| 103 | }
|
---|
| 104 | // Testa se deve exibir o valor da tag..
|
---|
| 105 | if(xflag ==1 )
|
---|
| 106 | {
|
---|
| 107 | var nome = "<b>" +tag +":</b> ";
|
---|
| 108 | }
|
---|
| 109 | else
|
---|
| 110 | {
|
---|
| 111 | // Testa o browser para usar a propriedade correta ...
|
---|
| 112 | if (navigator.userAgent.match('MSIE'))
|
---|
| 113 | {
|
---|
| 114 | var conteudo = cc[j].text;
|
---|
| 115 | }
|
---|
| 116 | else
|
---|
| 117 | {
|
---|
| 118 | var conteudo = cc[j].textContent;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | if(conteudo == "1")
|
---|
| 122 | {
|
---|
| 123 | conteudo = "Sim.";
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | if(conteudo == "")
|
---|
| 127 | {
|
---|
| 128 | conteudo = "Não.";
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | switch(tag)
|
---|
| 132 | {
|
---|
| 133 |
|
---|
| 134 | case "INICIO_VALIDADE":
|
---|
| 135 | {
|
---|
| 136 | var aux = conteudo.substr(0,4) + "/" + conteudo.substr(4,2) + "/" + conteudo.substr(6,2) + " - " + conteudo.substr(8,2) + ":" + conteudo.substr(10,2) + ":" + conteudo.substr(12,2) + " GMT";
|
---|
| 137 | conteudo = aux;
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 | case "FIM_VALIDADE":
|
---|
| 141 | {
|
---|
| 142 | var aux = conteudo.substr(0,4) + "/" + conteudo.substr(4,2) + "/" + conteudo.substr(6,2) + " - " + conteudo.substr(8,2) + ":" + conteudo.substr(10,2) + ":" + conteudo.substr(12,2) + " GMT";
|
---|
| 143 | conteudo = aux;
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | default:
|
---|
| 147 | {
|
---|
| 148 | break;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | var nome = "<b>" + tag +":</b> " + conteudo;
|
---|
| 152 | }
|
---|
| 153 | novo = novo + nome + '<br/>';
|
---|
| 154 | len = len + 24;
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | msg = novo + '<br/><br/><div align="center"><INPUT type="button" value="Fechar" onClick="window.close()"></font></body>';
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | //caso o XML volte vazio, printa a mensagem abaixo
|
---|
| 162 | msg = 'Não foi possível obter dados do certificado.' + '<br/><br/><div align="center"><INPUT type="button" value="Fechar" onClick="window.close()"></font></body>';
|
---|
| 163 | len =200;
|
---|
| 164 | }
|
---|
| 165 | parms = ",scrollbars=1";
|
---|
| 166 | num = num + 1;
|
---|
| 167 | msgWin(msg,450,len,parms)
|
---|
| 168 | }
|
---|
| 169 | |
---|