diff --git a/backend/public/index.html b/backend/public/index.html
index 8176bea..a8e0b46 100644
--- a/backend/public/index.html
+++ b/backend/public/index.html
@@ -578,7 +578,7 @@
- Toque no botão Conectar agora abaixo
- - Se pedir, conecte em Convidados-Pix
+ - Se pedir, conecte na rede Wi-Fi
- Pronto: seu acesso já estará liberado
@@ -656,7 +656,7 @@
$('view-voucher').classList.toggle('hidden', view !== 'voucher');
if (view !== 'pay' && pollTimer) { clearInterval(pollTimer); pollTimer = null; }
if (view !== 'pay' && freeTimer) { clearInterval(freeTimer); freeTimer = null; }
- if (view === 'pay' && !freeTimer) { freeTimer = setInterval(startFreeAccess, 45000); }
+ if (view === 'pay' && !freeTimer) { freeTimer = setInterval(startFreeAccess, 120000); }
window.scrollTo({ top: 0, behavior: 'instant' in window ? 'auto' : 'auto' });
}
@@ -806,6 +806,15 @@
} catch { /* segue */ }
}
+ async function loadSiteConfig() {
+ try {
+ const res = await fetch('/api/config');
+ const d = await res.json();
+ if (d.ssid) $('ssidLabel').textContent = d.ssid;
+ } catch { /* usa padrao */ }
+ }
+
+ loadSiteConfig();
loadPlans();
startFreeAccess();
diff --git a/backend/src/config.js b/backend/src/config.js
index 0976443..79bc9f0 100644
--- a/backend/src/config.js
+++ b/backend/src/config.js
@@ -15,7 +15,8 @@ const config = {
server: process.env.MIKROTIK_SERVER || 'guest-hotspot',
},
port: parseInt(process.env.PORT || '3000', 10),
- freeAccessSeconds: Number(process.env.FREE_ACCESS_SECONDS || 90),
+ freeAccessSeconds: Number(process.env.FREE_ACCESS_SECONDS || 600),
+ ssidName: process.env.SSID_NAME || 'Internet Gratis',
baseUrl: process.env.BASE_URL || 'http://192.168.3.100:3000',
adminToken: process.env.ADMIN_TOKEN || 'dev-token',
dataDir: process.env.DATA_DIR || path.join(__dirname, '..', 'data'),
diff --git a/backend/src/index.js b/backend/src/index.js
index 441a284..4f620d0 100644
--- a/backend/src/index.js
+++ b/backend/src/index.js
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
import config from './config.js';
import { initDb, getDb, saveDb, genCode } from './db.js';
import { initMp, createPixPayment, getPaymentStatus, cancelOrder, validCpf } from './mp.js';
-import { createHotspotUser, allowPaymentAccess, revokePaymentAccess } from './ros.js';
+import { createHotspotUser, allowPaymentAccess, revokePaymentAccess, paymentAccessStatus } from './ros.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
@@ -71,6 +71,14 @@ app.post('/api/access/start', async (req, res) => {
}
});
+app.get('/api/access/status/:mac', async (req, res) => {
+ try {
+ res.json(await paymentAccessStatus(req.params.mac));
+ } catch (e) {
+ res.status(500).json({ error: e.message });
+ }
+});
+
// ===== Reconciliacao manual (caso o webhook falhe) =====
app.post('/api/reconcile', async (req, res) => {
const { orderId } = req.body || {};
@@ -81,6 +89,10 @@ app.post('/api/reconcile', async (req, res) => {
res.json({ status: payment.status, voucher: payment.voucher, orderId: payment.mpId });
});
+app.get('/api/config', (req, res) => {
+ res.json({ ssid: config.ssidName, freeSeconds: config.freeAccessSeconds });
+});
+
app.get('/api/plans', (req, res) => {
res.json(getDb().plans.filter((p) => p.active));
});
diff --git a/backend/src/ros.js b/backend/src/ros.js
index 7c192f2..25858e1 100644
--- a/backend/src/ros.js
+++ b/backend/src/ros.js
@@ -138,11 +138,21 @@ export async function createHotspotUser(name, password, profile, uptime) {
// para o convidado abrir o app do banco e pagar o PIX.
async function hostAddressByMac(mac) {
+ const pick = (replies, key) => {
+ for (const row of replies || []) {
+ const v = row.find((w) => w.startsWith(key));
+ if (v) return v.slice(key.length);
+ }
+ return null;
+ };
try {
const replies = await rosCommand(['/ip/hotspot/host/print', `?mac-address=${mac}`]);
- const row = (replies || [])[0] || [];
- const addr = row.find((w) => w.startsWith('=address='));
- return addr ? addr.slice(9) : null;
+ const addr = pick(replies, '=address=');
+ if (addr) return addr;
+ } catch { /* segue */ }
+ try {
+ const leases = await rosCommand(['/ip/dhcp-server/lease/print', `?mac-address=${mac}`]);
+ return pick(leases, '=address=');
} catch {
return null;
}
@@ -170,6 +180,25 @@ export async function allowPaymentAccess(mac, speed = '3M/3M') {
return { ip, mac };
}
+function pickField(row, key) {
+ const v = (row || []).find((w) => w.startsWith(key));
+ return v ? v.slice(key.length) : null;
+}
+
+export async function paymentAccessStatus(mac) {
+ const out = { mac, binding: null, ip: null, active: null };
+ try {
+ const b = await rosCommand(['/ip/hotspot/ip-binding/print', `?mac-address=${mac}`]);
+ if (b && b.length) out.binding = { type: pickField(b[0], '=type='), comment: pickField(b[0], '=comment=') };
+ } catch { /* ignora */ }
+ out.ip = await hostAddressByMac(mac);
+ try {
+ const a = await rosCommand(['/ip/hotspot/active/print', `?mac-address=${mac}`]);
+ if (a && a.length) out.active = { address: pickField(a[0], '=address='), uptime: pickField(a[0], '=uptime=') };
+ } catch { /* ignora */ }
+ return out;
+}
+
export async function revokePaymentAccess(mac) {
if (!mac) return;
try {