Push Tracker
ria-ran--sim-drop/portal/js/script.js
A ashkan@beigi.net 8672b0de6b Add Phase-1 eSIM provisioning implementation
Full working closed-loop eSIM provisioning stack (spec in claude.md / plan/):
Flask API, SQLite subscriber store, credential/profile generator, Open5GS
and free5gc core adapters, captive portal, operational scripts, systemd
units, network configs, and a 44-test suite.

Profile generation currently returns a mock JSON profile; real SGP.22
generation via pySim is the planned Phase-2 upgrade.

Fixes two bugs found while getting the suite green:
- generate_imsi hardcoded a 10-digit MSIN, producing 16-digit IMSIs for a
  3-digit MNC; MSIN length is now 15 - len(mcc) - len(mnc).
- check_rate_limit compared timestamps as strings across mismatched formats
  (SQLite CURRENT_TIMESTAMP vs Python isoformat); both sides now normalized
  via SQLite datetime() so the window check is chronologically correct.

Add .gitignore for venv, caches, runtime config.yaml, and databases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 05:56:31 +00:00

62 lines
1.7 KiB
JavaScript

'use strict';
const STATES = ['idle', 'loading', 'success', 'error'];
function showState(name) {
STATES.forEach(function(s) {
var el = document.getElementById('state-' + s);
if (el) el.hidden = (s !== name);
});
}
function showError(msg) {
var el = document.getElementById('error-message');
if (el) el.textContent = msg;
showState('error');
}
async function activate() {
showState('loading');
try {
var res = await fetch('/api/provision', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
// MAC address left empty — server resolves it via ARP from client IP
body: JSON.stringify({ mac_address: '' }),
});
var data;
try { data = await res.json(); } catch (_) { data = {}; }
if (res.status === 429) {
showError(data.error || 'You already have an eSIM for this network. Only one per device per hour.');
return;
}
if (!res.ok) {
showError(data.error || 'Server error (' + res.status + '). Please try again.');
return;
}
// Wire up download link
var link = document.getElementById('download-link');
if (link && data.profile_url) {
link.href = data.profile_url;
}
showState('success');
} catch (err) {
showError('Could not reach the server. Make sure you are connected to the WiFi network.');
}
}
document.addEventListener('DOMContentLoaded', function() {
var btnActivate = document.getElementById('btn-activate');
var btnRetry = document.getElementById('btn-retry');
if (btnActivate) btnActivate.addEventListener('click', activate);
if (btnRetry) btnRetry.addEventListener('click', function() { showState('idle'); });
});