feat: liberacao de 10min para pagamento, status de acesso e SSID configuravel
build-image / build-push (push) Failing after 41s

This commit is contained in:
jfeng committed 2026-10-22 08:56:40 -03:00
1 parent 53cca4ecc8
commit de5c483dca
4 files changed
+58 -7

No files matched your search

+11 -2
View File
@@ -578,7 +578,7 @@
<ol class="steps">
<li>Toque no botão <strong>Conectar agora</strong> abaixo</li>
<li>Se pedir, conecte em <strong>Convidados-Pix</strong></li>
<li>Se pedir, conecte na rede <strong id="ssidLabel">Wi-Fi</strong></li>
<li>Pronto: seu acesso já estará liberado</li>
</ol>
@@ -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();
</script>
+2 -1
View File
@@ -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'),
+13 -1
View File
@@ -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));
});
+32 -3
View File
@@ -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 {