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) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
@@ -9065,7 +9066,7 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
|
||||
const result = await this.topsapp.obterAcessosPorEstacao(privateIP, null, null, '', 'on');
|
||||
const result = await this.topsapp.buscarConexaoAtivaPorIp(privateIP);
|
||||
|
||||
if (!result.success) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
@@ -9075,9 +9076,7 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
return;
|
||||
}
|
||||
|
||||
const acessos = result.data?.dados || [];
|
||||
|
||||
if (acessos.length === 0) {
|
||||
if (result.total === 0) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`ℹ️ Nenhuma conexão ativa encontrada para o IP \`${privateIP}\` no momento.`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
@@ -9085,11 +9084,11 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
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) {
|
||||
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' });
|
||||
|
||||
// Se único login, oferecer busca no TopSapp
|
||||
const logins = [...new Set(acessos.slice(0, 10).map(a => a.usuario).filter(Boolean))];
|
||||
if (logins.length === 1) {
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user