feat: add hotspot admin panel and harden payment provisioning
build-image / build-push (push) Failing after 1m36s

This commit is contained in:
jfeng committed 2026-10-22 14:01:08 +00:00
1 parent fb3135d18f
commit ebb2d1d792
25 files changed
+832 -686

No files matched your search

+32 -6
View File
@@ -602,6 +602,7 @@
let toastTimer = null;
let selectedPlanId = null;
let mpDevice = null;
let checkoutBusy = false;
const $ = (id) => document.getElementById(id);
@@ -690,6 +691,9 @@
}
async function checkout(planId) {
if (checkoutBusy) return;
checkoutBusy = true;
$('payerNext').disabled = true;
try {
const payerName = $('payerName').value.trim();
const payerEmail = $('payerEmail').value.trim();
@@ -705,6 +709,7 @@
if (data.error) throw new Error(data.error);
currentPaymentId = data.paymentId;
sessionStorage.setItem('paymentId', currentPaymentId);
$('payTitle').textContent = data.planName + ' · ' + money(data.price);
$('qrImg').src = data.qrCodeBase64 ? 'data:image/png;base64,' + data.qrCodeBase64 : '';
$('copiaCola').textContent = data.copiaCola || '';
@@ -715,6 +720,9 @@
pollTimer = setInterval(verify, 6000);
} catch (e) {
toast('Erro: ' + e.message);
} finally {
checkoutBusy = false;
$('payerNext').disabled = false;
}
}
@@ -730,6 +738,7 @@
btn.disabled = true;
try {
const res = await fetch('/api/status/' + encodeURIComponent(currentPaymentId));
if (!res.ok) throw new Error('Falha na consulta');
const data = await res.json();
if (data.status === 'paid' && data.voucher) {
clearInterval(pollTimer); pollTimer = null;
@@ -763,7 +772,7 @@
$('payerNext').addEventListener('click', () => checkout(selectedPlanId));
// ===== Login no hotspot (voucher) =====
const HS_LOGIN = 'http://10.10.10.1/login';
let HS_LOGIN = 'http://10.10.10.1/login';
function hsUrl(user, pass) {
return HS_LOGIN + '?username=' + encodeURIComponent(user) + '&password=' + encodeURIComponent(pass);
@@ -777,13 +786,22 @@
const u = $('hsUser').value.trim();
const p = $('hsPass').value;
if (!u || !p) { toast('Informe usuário e senha'); return; }
window.location.href = hsUrl(u, p);
hotspotLogin(u, p);
});
$('hsAutoLogin').addEventListener('click', () => {
window.location.href = hsUrl($('vUser').textContent, $('vPass').textContent);
hotspotLogin($('vUser').textContent, $('vPass').textContent);
});
function hotspotLogin(user, pass, destination) {
const form = document.createElement('form');
form.method = 'POST'; form.action = HS_LOGIN;
for (const [name, value] of Object.entries({ username: user, password: pass, ...(destination ? { dst: destination } : {}) })) {
const field = document.createElement('input'); field.type = 'hidden'; field.name = name; field.value = value; form.append(field);
}
document.body.append(form); form.submit();
}
// ===== Internet temporaria para pagar (login automatico no hotspot) =====
async function startFreeAccess() {
if (!mac) return;
@@ -796,7 +814,11 @@
body: JSON.stringify({ mac }),
});
const d = await res.json();
if (d.loginUrl) window.location.href = d.loginUrl;
if (!res.ok) { sessionStorage.removeItem('freeTried'); return; }
if (d.loginUrl) {
const target = new URL(d.loginUrl);
hotspotLogin(target.searchParams.get('username'), target.searchParams.get('password'), target.searchParams.get('dst'));
}
} catch { /* segue */ }
}
@@ -805,14 +827,18 @@
const res = await fetch('/api/config');
const d = await res.json();
if (d.ssid) $('ssidLabel').textContent = d.ssid;
if (/^(?:\d{1,3}\.){3}\d{1,3}$/.test(d.hotspotIp)) HS_LOGIN = 'http://' + d.hotspotIp + '/login';
} catch { /* usa padrao */ }
}
if (new URLSearchParams(location.search).get('free') === '1') sessionStorage.setItem('freeOk', '1');
loadSiteConfig();
loadSiteConfig().then(startFreeAccess);
loadPlans();
startFreeAccess();
if (sessionStorage.getItem('paymentId')) {
currentPaymentId = sessionStorage.getItem('paymentId');
verify();
}
</script>
</body>
</html>