Update index.js
Browse files
index.js
CHANGED
|
@@ -98,6 +98,7 @@ function initializeServer() {
|
|
| 98 |
<a href="/qr">📱 QR Code</a>
|
| 99 |
<a href="/health">💚 Health</a>
|
| 100 |
<a href="/stats">📊 Stats</a>
|
|
|
|
| 101 |
</div>
|
| 102 |
</div>
|
| 103 |
</body>
|
|
@@ -109,24 +110,52 @@ function initializeServer() {
|
|
| 109 |
app.get('/qr', async (req, res) => {
|
| 110 |
try {
|
| 111 |
const qr = botCore.getQRCode();
|
|
|
|
| 112 |
|
| 113 |
if (!qr) {
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
<
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
const img = await QRCode.toDataURL(qr, { errorCorrectionLevel: 'H', scale: 10 });
|
| 129 |
-
|
| 130 |
res.send(`
|
| 131 |
<html>
|
| 132 |
<head>
|
|
@@ -204,6 +233,38 @@ function initializeServer() {
|
|
| 204 |
}
|
| 205 |
});
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
// ═══ Rota: Verificar Privilégios ═══
|
| 208 |
app.post('/check-privileges', (req, res) => {
|
| 209 |
try {
|
|
|
|
| 98 |
<a href="/qr">📱 QR Code</a>
|
| 99 |
<a href="/health">💚 Health</a>
|
| 100 |
<a href="/stats">📊 Stats</a>
|
| 101 |
+
<a href="/reset-auth" onclick="return confirm('Isso vai desconectar o bot e exigir novo login. Continuar?')">🔄 Reset Auth</a>
|
| 102 |
</div>
|
| 103 |
</div>
|
| 104 |
</body>
|
|
|
|
| 110 |
app.get('/qr', async (req, res) => {
|
| 111 |
try {
|
| 112 |
const qr = botCore.getQRCode();
|
| 113 |
+
const status = botCore.getStatus();
|
| 114 |
|
| 115 |
if (!qr) {
|
| 116 |
+
// Se não tem QR mas também não está conectado, precisa de login
|
| 117 |
+
if (!status.isConnected) {
|
| 118 |
+
return res.send(`
|
| 119 |
+
<html>
|
| 120 |
+
<head><style>
|
| 121 |
+
body { background: #000; color: #ff4444; font-family: monospace; text-align: center; padding: 50px; }
|
| 122 |
+
.warning { color: #ffaa00; font-size: 18px; margin: 20px 0; }
|
| 123 |
+
</style></head>
|
| 124 |
+
<body>
|
| 125 |
+
<h1>🔄 AGUARDANDO CONEXÃO</h1>
|
| 126 |
+
<p>Bot não está conectado ao WhatsApp.</p>
|
| 127 |
+
<div class="warning">
|
| 128 |
+
<p>📱 Se você nunca logou, escaneie o QR code quando aparecer.</p>
|
| 129 |
+
<p>🔄 Se já logou antes, as credenciais podem ter expirado.</p>
|
| 130 |
+
<p>⏰ Tente novamente em alguns segundos...</p>
|
| 131 |
+
</div>
|
| 132 |
+
<p><a href="/" style="color: #0f0;">← Voltar</a></p>
|
| 133 |
+
<script>
|
| 134 |
+
setTimeout(() => { location.reload(); }, 5000);
|
| 135 |
+
</script>
|
| 136 |
+
</body>
|
| 137 |
+
</html>
|
| 138 |
+
`);
|
| 139 |
+
} else {
|
| 140 |
+
// Já está conectado
|
| 141 |
+
return res.send(`
|
| 142 |
+
<html>
|
| 143 |
+
<head><style>
|
| 144 |
+
body { background: #000; color: #0f0; font-family: monospace; text-align: center; padding: 50px; }
|
| 145 |
+
</style></head>
|
| 146 |
+
<body>
|
| 147 |
+
<h1>✅ BOT CONECTADO!</h1>
|
| 148 |
+
<p>Nenhum QR Code necessário agora.</p>
|
| 149 |
+
<p>Status: ${status.botJid ? 'Online' : 'Conectando...'}</p>
|
| 150 |
+
<p><a href="/" style="color: #0f0;">← Voltar</a></p>
|
| 151 |
+
</body>
|
| 152 |
+
</html>
|
| 153 |
+
`);
|
| 154 |
+
}
|
| 155 |
}
|
| 156 |
|
| 157 |
const img = await QRCode.toDataURL(qr, { errorCorrectionLevel: 'H', scale: 10 });
|
| 158 |
+
|
| 159 |
res.send(`
|
| 160 |
<html>
|
| 161 |
<head>
|
|
|
|
| 233 |
}
|
| 234 |
});
|
| 235 |
|
| 236 |
+
// ═══ Rota: Reset de autenticação (força novo login) ═══
|
| 237 |
+
app.post('/reset-auth', (req, res) => {
|
| 238 |
+
try {
|
| 239 |
+
const fs = require('fs');
|
| 240 |
+
const authPath = botCore.config.AUTH_FOLDER;
|
| 241 |
+
|
| 242 |
+
if (fs.existsSync(authPath)) {
|
| 243 |
+
fs.rmSync(authPath, { recursive: true, force: true });
|
| 244 |
+
botCore.isConnected = false;
|
| 245 |
+
botCore.currentQR = null;
|
| 246 |
+
botCore.BOT_JID = null;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Reinicia a conexão
|
| 250 |
+
setTimeout(() => {
|
| 251 |
+
botCore.connect().catch(err => console.error('Erro ao reconectar:', err));
|
| 252 |
+
}, 1000);
|
| 253 |
+
|
| 254 |
+
res.json({
|
| 255 |
+
status: 'success',
|
| 256 |
+
message: 'Credenciais resetadas. Faça login novamente.',
|
| 257 |
+
timestamp: new Date().toISOString()
|
| 258 |
+
});
|
| 259 |
+
} catch (error) {
|
| 260 |
+
res.status(500).json({
|
| 261 |
+
status: 'error',
|
| 262 |
+
message: 'Erro ao resetar autenticação',
|
| 263 |
+
error: error.message
|
| 264 |
+
});
|
| 265 |
+
}
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
// ═══ Rota: Verificar Privilégios ═══
|
| 269 |
app.post('/check-privileges', (req, res) => {
|
| 270 |
try {
|