Skip to content

Commit ce7f989

Browse files
Implement OID processing and result display
Added a PHP script to process OID data from POST requests, convert hex values, and sanitize inputs. The script generates an HTML table displaying the results for various OIDs related to Brazilian digital certificates.
1 parent 90e2e62 commit ce7f989

1 file changed

Lines changed: 314 additions & 0 deletions

File tree

PHP/calcular.php

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
<?php
2+
3+
//echo var_dump($_POST); // Debug
4+
5+
function converteHex($data){
6+
7+
if (empty($data) || !is_string($data)) {
8+
return 'Vazio';
9+
}
10+
11+
$hexValues = explode(" ", trim($data));
12+
$result = "";
13+
14+
foreach ($hexValues as $hex) {
15+
$hex = trim($hex);
16+
if (!empty($hex) && ctype_xdigit($hex)) {
17+
$result .= chr(hexdec($hex));
18+
}
19+
}
20+
21+
return $result;
22+
23+
}
24+
25+
function sanitizaEntrada($data){
26+
27+
if (!is_string($data)) {
28+
return 'Vazio';
29+
}
30+
31+
return htmlspecialchars(trim($data), ENT_QUOTES, 'UTF-8');
32+
33+
}
34+
35+
function processaPost($post, $key) {
36+
37+
if (!isset($post[$key])) {
38+
return 'Vazio';
39+
}
40+
41+
$valor = $post[$key];
42+
43+
// Se contiver hex, converte; senão, apenas sanitiza
44+
$convertido = converteHex($valor);
45+
46+
return sanitizaEntrada($convertido ?: $valor);
47+
48+
}
49+
50+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
51+
52+
$oid_2_16_76_1_3_1 = processaPost($_POST, 'oid_2_16_76_1_3_1');
53+
$oid_2_16_76_1_3_2 = processaPost($_POST, 'oid_2_16_76_1_3_2');
54+
$oid_2_16_76_1_3_3 = processaPost($_POST, 'oid_2_16_76_1_3_3');
55+
$oid_2_16_76_1_3_4 = processaPost($_POST, 'oid_2_16_76_1_3_4');
56+
$oid_2_16_76_1_3_5 = processaPost($_POST, 'oid_2_16_76_1_3_5');
57+
$oid_2_16_76_1_3_6 = processaPost($_POST, 'oid_2_16_76_1_3_6');
58+
$oid_2_16_76_1_3_7 = processaPost($_POST, 'oid_2_16_76_1_3_7');
59+
$oid_2_16_76_1_3_8 = processaPost($_POST, 'oid_2_16_76_1_3_8');
60+
61+
}
62+
63+
?>
64+
65+
<!DOCTYPE html>
66+
<html lang="pt-BR">
67+
<head>
68+
<meta charset="UTF-8">
69+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
70+
<title>Resposta de OIDs</title>
71+
<style>
72+
* {
73+
margin: 0;
74+
padding: 0;
75+
box-sizing: border-box;
76+
}
77+
78+
body {
79+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
80+
background-color: #f5f7fa;
81+
min-height: 100vh;
82+
padding: 20px;
83+
}
84+
85+
.container {
86+
max-width: 1200px;
87+
margin: 0 auto;
88+
}
89+
90+
h1 {
91+
color: #1a1a1a;
92+
margin-bottom: 8px;
93+
text-align: center;
94+
font-size: 28px;
95+
}
96+
97+
.subtitle {
98+
text-align: center;
99+
color: #666;
100+
margin-bottom: 30px;
101+
font-size: 14px;
102+
}
103+
104+
/* Tabela */
105+
table {
106+
width: 100%;
107+
border-collapse: collapse;
108+
background: white;
109+
border-radius: 8px;
110+
overflow: hidden;
111+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
112+
}
113+
114+
thead {
115+
background-color: #2c3e50;
116+
color: white;
117+
}
118+
119+
th {
120+
padding: 16px;
121+
text-align: left;
122+
font-weight: 600;
123+
font-size: 13px;
124+
letter-spacing: 0.5px;
125+
text-transform: uppercase;
126+
}
127+
128+
td {
129+
padding: 14px 16px;
130+
border-bottom: 1px solid #e8eaed;
131+
font-size: 13px;
132+
color: #444;
133+
}
134+
135+
tbody tr {
136+
transition: background-color 0.2s ease;
137+
}
138+
139+
tbody tr:nth-child(even) {
140+
background-color: #f9fafb;
141+
}
142+
143+
tbody tr:hover {
144+
background-color: #f0f4f8;
145+
}
146+
147+
/* Coluna OID */
148+
.oid-code {
149+
font-family: 'Monaco', 'Menlo', monospace;
150+
font-weight: 600;
151+
color: #0066cc;
152+
background-color: #f0f7ff;
153+
padding: 4px 8px;
154+
border-radius: 4px;
155+
font-size: 12px;
156+
}
157+
158+
/* Coluna Nome Técnico */
159+
.tech-name {
160+
font-weight: 500;
161+
color: #1a1a1a;
162+
}
163+
164+
/* Coluna Conteúdo */
165+
.description {
166+
color: #666;
167+
line-height: 1.4;
168+
}
169+
170+
/* Coluna Resultado */
171+
.result {
172+
font-family: 'Monaco', 'Menlo', monospace;
173+
background-color: #f0f7ff;
174+
padding: 4px 8px;
175+
border-radius: 4px;
176+
color: #0066cc;
177+
font-weight: 500;
178+
}
179+
180+
.result:empty::before {
181+
content: '—';
182+
color: #ccc;
183+
}
184+
185+
/* Responsivo */
186+
@media (max-width: 768px) {
187+
body {
188+
padding: 12px;
189+
}
190+
191+
h1 {
192+
font-size: 22px;
193+
}
194+
195+
table {
196+
font-size: 12px;
197+
}
198+
199+
th, td {
200+
padding: 10px 8px;
201+
}
202+
203+
.oid-code,
204+
.result {
205+
padding: 3px 6px;
206+
font-size: 11px;
207+
}
208+
}
209+
</style>
210+
</head>
211+
<body>
212+
<div class="container">
213+
<h1>Resposta de OIDs</h1>
214+
<p class="subtitle">Certificado Digital Brasileiro</p>
215+
216+
<table>
217+
<thead>
218+
<tr>
219+
<th style="width: 12%;">OID</th>
220+
<th style="width: 18%;">Nome Técnico</th>
221+
<th style="width: 50%;">Conteúdo</th>
222+
<th style="width: 20%;">Resultado</th>
223+
</tr>
224+
</thead>
225+
<tbody>
226+
<tr>
227+
<td><span class="oid-code">2.16.76.1.3.1</span></td>
228+
<td class="tech-name">Dados de Pessoa Física</td>
229+
<td class="description">Data de nascimento, CPF, PIS/PASEP/CI, RG</td>
230+
<td class="result"><?php echo $oid_2_16_76_1_3_1 ?? ''; ?></td>
231+
</tr>
232+
<tr>
233+
<td><span class="oid-code">2.16.76.1.3.2</span></td>
234+
<td class="tech-name">Nome da Pessoa Jurídica/Responsável</td>
235+
<td class="description">Nome da pessoa responsável pelo certificado</td>
236+
<td class="result"><?php echo $oid_2_16_76_1_3_2 ?? ''; ?></td>
237+
</tr>
238+
<tr>
239+
<td><span class="oid-code">2.16.76.1.3.3</span></td>
240+
<td class="tech-name">CNPJ</td>
241+
<td class="description">Cadastro Nacional da Pessoa Jurídica</td>
242+
<td class="result"><?php $cpf = $oid_2_16_76_1_3_3 ?? ''; echo preg_replace('/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/', '$1.$2.$3.$4-$5', $cpf); ?></td>
243+
</tr>
244+
<tr>
245+
<td><span class="oid-code">2.16.76.1.3.4</span></td>
246+
<td class="tech-name">Dados da Pessoa Jurídica</td>
247+
<td class="description">Data de nascimento, CPF, NIS/PIS/PASEP/CI, RG, siglas e UF</td>
248+
<td class="result">
249+
250+
<?php
251+
$numero = $oid_2_16_76_1_3_4 ?? '';
252+
$numero = preg_replace('/\D/', '', $numero); // Remove caracteres não-numéricos
253+
254+
// Extrair partes
255+
$data = substr($numero, 0, 8); // 09061977
256+
$cpf = substr($numero, 8, 11); // 90161386091
257+
$nis = substr($numero, 19, 11); // 12345678901 (NIS/PIS/PASEP/CI)
258+
$rg = substr($numero, 30, 15); // 123456789012345 (RG)
259+
$orgao = substr($numero, 45, 2); // XX (Órgão expedidor)
260+
$uf = substr($numero, 47, 2); // XX (UF)
261+
262+
// Formatar data (DDMMYYYY -> DD/MM/YYYY)
263+
$data_formatada = substr($data, 0, 2) . '/' . substr($data, 2, 2) . '/' . substr($data, 4, 4);
264+
265+
// Formatar CPF (11 dígitos -> XXX.XXX.XXX-XX)
266+
$cpf_formatado = preg_replace('/(\d{3})(\d{3})(\d{3})(\d{2})/', '$1.$2.$3-$4', $cpf);
267+
268+
// Formatar NIS/PIS/PASEP/CI (11 dígitos -> XXX.XXXXX.XX-X)
269+
$nis_formatado = preg_replace('/(\d{3})(\d{5})(\d{2})(\d{1})/', '$1.$2.$3-$4', $nis);
270+
271+
// Formatar RG (15 dígitos -> XX.XXXXXX.XXX-XX)
272+
$rg_formatado = preg_replace('/(\d{2})(\d{6})(\d{3})(\d{2})(\d{2})/', '$1.$2.$3-$4 $5', $rg);
273+
274+
// Montar saída final
275+
echo $data_formatada . ' ' .
276+
$cpf_formatado . ' ' .
277+
$nis_formatado . ' ' .
278+
$rg_formatado . ' ' .
279+
strtoupper($orgao) . ' ' .
280+
strtoupper($uf);
281+
282+
?>
283+
284+
</td>
285+
</tr>
286+
<tr>
287+
<td><span class="oid-code">2.16.76.1.3.5</span></td>
288+
<td class="tech-name">Título de Eleitor</td>
289+
<td class="description">Inscrição eleitoral, zona, seção, município e UF</td>
290+
<td class="result"><?php echo $oid_2_16_76_1_3_5 ?? ''; ?></td>
291+
</tr>
292+
<tr>
293+
<td><span class="oid-code">2.16.76.1.3.6</span></td>
294+
<td class="tech-name">CEI Pessoa Física</td>
295+
<td class="description">Cadastro Específico do INSS para pessoas físicas</td>
296+
<td class="result"><?php echo $oid_2_16_76_1_3_6 ?? ''; ?></td>
297+
</tr>
298+
<tr>
299+
<td><span class="oid-code">2.16.76.1.3.7</span></td>
300+
<td class="tech-name">CEI Pessoa Jurídica</td>
301+
<td class="description">Cadastro Específico do INSS para pessoas jurídicas</td>
302+
<td class="result"><?php echo $oid_2_16_76_1_3_7 ?? ''; ?></td>
303+
</tr>
304+
<tr>
305+
<td><span class="oid-code">2.16.76.1.3.8</span></td>
306+
<td class="tech-name">Nome Social CNPJ</td>
307+
<td class="description">Razão social da pessoa jurídica</td>
308+
<td class="result"><?php echo $oid_2_16_76_1_3_8 ?? ''; ?></td>
309+
</tr>
310+
</tbody>
311+
</table>
312+
</div>
313+
</body>
314+
</html>

0 commit comments

Comments
 (0)