cgnat: fix search topsapp active2
Signed-off-by: Rodrigo Martins <rodrigo@martinsevieira.adv.br>
This commit is contained in:
1 parent
18e08ec6c2
commit
0ae32bb1a1
3 files changed
+84
-20
No files matched your search
+41
-8
@@ -9057,7 +9057,8 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consulta conexões ATIVAS agora para o IP privado CGNAT (status: on)
|
* Consulta conexões ATIVAS agora para o IP privado CGNAT
|
||||||
|
* Usa ObterClientesServicos com conexao: "online" e filtra por IP
|
||||||
*/
|
*/
|
||||||
async handleCgnatConsultarAtivas(chatId, privateIP) {
|
async handleCgnatConsultarAtivas(chatId, privateIP) {
|
||||||
await this.bot.sendMessage(chatId,
|
await this.bot.sendMessage(chatId,
|
||||||
@@ -9065,7 +9066,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
{ parse_mode: 'Markdown' }
|
{ parse_mode: 'Markdown' }
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.topsapp.obterAcessosPorEstacao(privateIP, null, null, '', 'on');
|
const result = await this.topsapp.buscarConexaoAtivaPorIp(privateIP);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
await this.bot.sendMessage(chatId,
|
await this.bot.sendMessage(chatId,
|
||||||
@@ -9075,9 +9076,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const acessos = result.data?.dados || [];
|
if (result.total === 0) {
|
||||||
|
|
||||||
if (acessos.length === 0) {
|
|
||||||
await this.bot.sendMessage(chatId,
|
await this.bot.sendMessage(chatId,
|
||||||
`ℹ️ Nenhuma conexão ativa encontrada para o IP \`${privateIP}\` no momento.`,
|
`ℹ️ Nenhuma conexão ativa encontrada para o IP \`${privateIP}\` no momento.`,
|
||||||
{ parse_mode: 'Markdown' }
|
{ parse_mode: 'Markdown' }
|
||||||
@@ -9085,11 +9084,11 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._exibirAcessosCgnat(chatId, privateIP, acessos, '🟢 Conexões ativas');
|
await this._exibirConexoesAtivasCgnat(chatId, privateIP, result.dados);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exibe os acessos CGNAT e oferece botão para ver dados do cliente
|
* Exibe histórico de acessos CGNAT (ObterClientesServicosAcessos)
|
||||||
*/
|
*/
|
||||||
async _exibirAcessosCgnat(chatId, privateIP, acessos, titulo) {
|
async _exibirAcessosCgnat(chatId, privateIP, acessos, titulo) {
|
||||||
let msg = `🌐 *${titulo} — \`${privateIP}\`*\n\n`;
|
let msg = `🌐 *${titulo} — \`${privateIP}\`*\n\n`;
|
||||||
@@ -9110,7 +9109,6 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
|
|
||||||
await this.bot.sendMessage(chatId, msg, { parse_mode: 'Markdown' });
|
await this.bot.sendMessage(chatId, msg, { parse_mode: 'Markdown' });
|
||||||
|
|
||||||
// Se único login, oferecer busca no TopSapp
|
|
||||||
const logins = [...new Set(acessos.slice(0, 10).map(a => a.usuario).filter(Boolean))];
|
const logins = [...new Set(acessos.slice(0, 10).map(a => a.usuario).filter(Boolean))];
|
||||||
if (logins.length === 1) {
|
if (logins.length === 1) {
|
||||||
const keyboard = {
|
const keyboard = {
|
||||||
@@ -9125,6 +9123,41 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exibe conexões ativas CGNAT (ObterClientesServicos com conexao: online)
|
||||||
|
*/
|
||||||
|
async _exibirConexoesAtivasCgnat(chatId, privateIP, servicos) {
|
||||||
|
let msg = `🟢 *Conexões ativas — \`${privateIP}\`*\n\n`;
|
||||||
|
|
||||||
|
for (const s of servicos.slice(0, 10)) {
|
||||||
|
msg += `👤 *${s.usuario || '—'}*\n`;
|
||||||
|
if (s.nome_cliente || s.cliente) msg += ` 🏷️ Cliente: ${s.nome_cliente || s.cliente}\n`;
|
||||||
|
msg += ` 🖥️ IP: \`${s.ip || '—'}\`\n`;
|
||||||
|
if (s.descricao) msg += ` 📦 Plano: ${s.descricao}\n`;
|
||||||
|
if (s.status) msg += ` 🔄 Status: ${s.status}\n`;
|
||||||
|
msg += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (servicos.length > 10) {
|
||||||
|
msg += `_... e mais ${servicos.length - 10} registro(s)._\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bot.sendMessage(chatId, msg, { parse_mode: 'Markdown' });
|
||||||
|
|
||||||
|
const logins = [...new Set(servicos.slice(0, 10).map(s => s.usuario).filter(Boolean))];
|
||||||
|
if (logins.length === 1) {
|
||||||
|
const keyboard = {
|
||||||
|
inline_keyboard: [[
|
||||||
|
{ text: `🔍 Ver dados de ${logins[0]}`, callback_data: `buscar_cgnat_user_${logins[0]}` },
|
||||||
|
{ text: '❌ Fechar', callback_data: 'cancel_action' }
|
||||||
|
]]
|
||||||
|
};
|
||||||
|
await this.bot.sendMessage(chatId, '💡 Deseja ver os dados cadastrais do cliente?', {
|
||||||
|
reply_markup: keyboard
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reiniciar ONU Datacom — busca em todas as OLTs
|
* Reiniciar ONU Datacom — busca em todas as OLTs
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1018,6 +1018,18 @@ class TopSappAPI {
|
|||||||
}, instance, credentials);
|
}, instance, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listar conexões ativas (ObterClientesServicos com conexao: "online")
|
||||||
|
*/
|
||||||
|
async obterConexoesAtivas(instance, credentials) {
|
||||||
|
const session = await this.getValidSession(instance, credentials);
|
||||||
|
return this.makeRequest('ObterClientesServicos', {
|
||||||
|
idUsuario: session.idUsuario,
|
||||||
|
conexao: 'online',
|
||||||
|
calcDadosAcesso: true
|
||||||
|
}, instance, credentials);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcular similaridade entre duas strings (algoritmo de Jaro-Winkler simplificado)
|
* Calcular similaridade entre duas strings (algoritmo de Jaro-Winkler simplificado)
|
||||||
*/
|
*/
|
||||||
|
|||||||
+31
-12
@@ -1331,13 +1331,8 @@ class TopSappManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Busca acessos por estação/IP privado CGNAT no TopSapp
|
* Busca acessos por estação/IP privado CGNAT no TopSapp
|
||||||
* @param {string} estacao - IP privado (ex: 100.110.0.5) ou nome da estação
|
|
||||||
* @param {string|null} dataInicial - formato dd/mm/yyyy (ignorado se status='on')
|
|
||||||
* @param {string|null} dataFinal - formato dd/mm/yyyy (ignorado se status='on')
|
|
||||||
* @param {string} location
|
|
||||||
* @param {string} status - 'on' para listar apenas conexões ativas (ignora período)
|
|
||||||
*/
|
*/
|
||||||
async obterAcessosPorEstacao(estacao, dataInicial, dataFinal, location = '', status = null) {
|
async obterAcessosPorEstacao(estacao, dataInicial, dataFinal, location = '') {
|
||||||
if (!this.isReady()) {
|
if (!this.isReady()) {
|
||||||
return { success: false, error: 'TopSapp não está configurado' };
|
return { success: false, error: 'TopSapp não está configurado' };
|
||||||
}
|
}
|
||||||
@@ -1345,18 +1340,42 @@ class TopSappManager {
|
|||||||
const credentials = this.config.getCredentialsByLocation(location);
|
const credentials = this.config.getCredentialsByLocation(location);
|
||||||
const instance = this.api.getInstanceByLocation(location);
|
const instance = this.api.getInstanceByLocation(location);
|
||||||
const params = { estacao };
|
const params = { estacao };
|
||||||
if (status) {
|
if (dataInicial) params.dataInicial = dataInicial;
|
||||||
params.status = status;
|
if (dataFinal) params.dataFinal = dataFinal;
|
||||||
} else {
|
|
||||||
if (dataInicial) params.dataInicial = dataInicial;
|
|
||||||
if (dataFinal) params.dataFinal = dataFinal;
|
|
||||||
}
|
|
||||||
return await this.api.obterAcessos(params, instance, credentials);
|
return await this.api.obterAcessos(params, instance, credentials);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: error.message };
|
return { success: false, error: error.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca qual serviço está usando um IP privado CGNAT agora (conexões ativas)
|
||||||
|
*/
|
||||||
|
async buscarConexaoAtivaPorIp(privateIP, location = '') {
|
||||||
|
if (!this.isReady()) {
|
||||||
|
return { success: false, error: 'TopSapp não está configurado' };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const credentials = this.config.getCredentialsByLocation(location);
|
||||||
|
const instance = this.api.getInstanceByLocation(location);
|
||||||
|
const result = await this.api.obterConexoesAtivas(instance, credentials);
|
||||||
|
|
||||||
|
if (!result.success) return result;
|
||||||
|
|
||||||
|
const todos = result.data?.dados || [];
|
||||||
|
const encontrados = todos.filter(s => s.ip === privateIP);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
dados: encontrados,
|
||||||
|
total: encontrados.length,
|
||||||
|
instance: result.instance
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TopSappManager;
|
module.exports = TopSappManager;
|
||||||
Reference in new issue
Block a user