Fix IP in ProvaService.ts and Add PUBLIC_URL
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
8dfe0d6f94
commit
c96175b578
7 files changed
+643
-286
No files matched your search
@@ -458,23 +458,56 @@ export class ReportGenerator {
|
||||
this.drawLabelValue(page, "Idioma:", idioma, y, helvetica, helveticaBold);
|
||||
y -= 15;
|
||||
|
||||
// IP - CORRIGIDO PARA EVITAR N/A
|
||||
const ip = data.metadata?.ipAddress ||
|
||||
data.metadata?.connectionInfo?.ip ||
|
||||
data.metadata?.connectionInfo?.socketAddress ||
|
||||
"::1";
|
||||
this.drawLabelValue(page, "IP:", ip, y, helvetica, helveticaBold);
|
||||
y -= 15;
|
||||
|
||||
// Porta - CORRIGIDA PARA EVITAR N/A
|
||||
const porta = data.metadata?.clientPort ||
|
||||
data.metadata?.connectionInfo?.socketPort;
|
||||
this.drawLabelValue(page, "Porta:", String(porta || 61465), y, helvetica, helveticaBold);
|
||||
// IP - Usar o X-Forwarded-For ou outras fontes confiáveis, evitando IPs locais
|
||||
let displayIp = '127.0.0.1';
|
||||
let porta = '';
|
||||
|
||||
try {
|
||||
// Lista de IPs locais que devemos evitar
|
||||
const localIPs = ['::1', '127.0.0.1', 'localhost', '::ffff:127.0.0.1', '::ffff:10.15.0.1'];
|
||||
|
||||
// Aplicar a mesma lógica que funcionou no VerificarProva.tsx
|
||||
if (data.metadata?.headers && data.metadata.headers['x-forwarded-for']) {
|
||||
displayIp = data.metadata.headers['x-forwarded-for'].split(',')[0].trim();
|
||||
console.log('Usando IP do header x-forwarded-for:', displayIp);
|
||||
}
|
||||
else if (data.metadata?.connectionInfo?.forwardedIp) {
|
||||
displayIp = data.metadata.connectionInfo.forwardedIp;
|
||||
console.log('Usando forwardedIp da connectionInfo:', displayIp);
|
||||
}
|
||||
else if (data.metadata?.ipAddress && !localIPs.includes(data.metadata.ipAddress)) {
|
||||
displayIp = data.metadata.ipAddress;
|
||||
console.log('Usando ipAddress:', displayIp);
|
||||
}
|
||||
|
||||
// Porta - pegar a porta do cliente e garantir que seja exibida
|
||||
porta = String(data.metadata?.clientPort ||
|
||||
data.metadata?.connectionInfo?.socketPort ||
|
||||
data.metadata?.porta ||
|
||||
'');
|
||||
|
||||
if (porta === '0' || !porta) {
|
||||
porta = '';
|
||||
}
|
||||
|
||||
console.log('IP e porta detectados para relatório:', { displayIp, porta });
|
||||
} catch (error) {
|
||||
console.error('Erro ao processar IP e porta para relatório:', error);
|
||||
}
|
||||
|
||||
// Mostrar IP com valor sempre significativo
|
||||
this.drawLabelValue(page, "IP:", displayIp, y, helvetica, helveticaBold);
|
||||
y -= 15;
|
||||
|
||||
// Mostrar porta apenas se tiver um valor significativo
|
||||
if (porta && porta !== '0') {
|
||||
this.drawLabelValue(page, "Porta:", porta, y, helvetica, helveticaBold);
|
||||
y -= 15;
|
||||
}
|
||||
|
||||
// Família IP - CORRIGIDA PARA EVITAR N/A
|
||||
const familia = data.metadata?.connectionInfo?.remoteFamily ||
|
||||
(ip.includes(':') ? 'IPv6' : 'IPv4');
|
||||
(displayIp.includes(':') ? 'IPv6' : 'IPv4');
|
||||
this.drawLabelValue(page, "Família IP:", familia, y, helvetica, helveticaBold);
|
||||
y -= 15;
|
||||
|
||||
@@ -991,4 +1024,45 @@ export class ReportGenerator {
|
||||
|
||||
return yPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrai o endereço IP real do cliente de várias fontes possíveis
|
||||
* @param ipAddress IP básico
|
||||
* @param forwardedIp IP encaminhado
|
||||
* @param xForwardedFor Header X-Forwarded-For
|
||||
* @returns O IP mais confiável encontrado
|
||||
*/
|
||||
private extractRealClientIP(ipAddress?: string, forwardedIp?: string, xForwardedFor?: string): string {
|
||||
// Lista de IPs locais/internos que devem ser evitados
|
||||
const localIPs = ['::1', '127.0.0.1', 'localhost', '::ffff:127.0.0.1', '::ffff:10.15.0.1'];
|
||||
|
||||
// Verificar primeiro X-Forwarded-For (mais confiável em ambientes de produção)
|
||||
if (xForwardedFor) {
|
||||
const ips = xForwardedFor.split(',').map(ip => ip.trim());
|
||||
if (ips.length > 0 && !localIPs.includes(ips[0])) {
|
||||
return ips[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Verificar IP encaminhado (usado em alguns proxies)
|
||||
if (forwardedIp && !localIPs.includes(forwardedIp)) {
|
||||
return forwardedIp;
|
||||
}
|
||||
|
||||
// Verificar IP básico
|
||||
if (ipAddress && !localIPs.includes(ipAddress)) {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
// Se chegamos aqui e temos um X-Forwarded-For, mesmo que seja um IP local, usá-lo
|
||||
if (xForwardedFor) {
|
||||
const ips = xForwardedFor.split(',').map(ip => ip.trim());
|
||||
if (ips.length > 0) {
|
||||
return ips[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Retornar IP básico se não encontrar melhor
|
||||
return ipAddress || '0.0.0.0';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user