|
|
|
@@ -0,0 +1,476 @@
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
<title>GenieACS Firmware Pusher</title>
|
|
|
|
|
<style>
|
|
|
|
|
:root {
|
|
|
|
|
--bg: #0f1117;
|
|
|
|
|
--surface: #1a1d27;
|
|
|
|
|
--border: #2a2d3a;
|
|
|
|
|
--text: #e4e4e7;
|
|
|
|
|
--text-dim: #71717a;
|
|
|
|
|
--accent: #3b82f6;
|
|
|
|
|
--accent-hover: #2563eb;
|
|
|
|
|
--success: #22c55e;
|
|
|
|
|
--error: #ef4444;
|
|
|
|
|
--warning: #f59e0b;
|
|
|
|
|
}
|
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
body {
|
|
|
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
|
|
|
background: var(--bg);
|
|
|
|
|
color: var(--text);
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
}
|
|
|
|
|
.card {
|
|
|
|
|
background: var(--surface);
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
padding: 2rem;
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: 480px;
|
|
|
|
|
}
|
|
|
|
|
.logo {
|
|
|
|
|
font-size: 1.5rem;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
margin-bottom: 0.25rem;
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
}
|
|
|
|
|
.subtitle {
|
|
|
|
|
color: var(--text-dim);
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
|
}
|
|
|
|
|
.field {
|
|
|
|
|
margin-bottom: 1.25rem;
|
|
|
|
|
}
|
|
|
|
|
label {
|
|
|
|
|
display: block;
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
color: var(--text-dim);
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
letter-spacing: 0.05em;
|
|
|
|
|
}
|
|
|
|
|
select, input {
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 0.625rem 0.875rem;
|
|
|
|
|
background: var(--bg);
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
color: var(--text);
|
|
|
|
|
font-size: 0.9rem;
|
|
|
|
|
transition: border-color 0.15s;
|
|
|
|
|
appearance: none;
|
|
|
|
|
}
|
|
|
|
|
select:focus, input:focus {
|
|
|
|
|
outline: none;
|
|
|
|
|
border-color: var(--accent);
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2371717a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
|
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
|
background-position: right 0.875rem center;
|
|
|
|
|
padding-right: 2.5rem;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
.btn {
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 0.75rem 1rem;
|
|
|
|
|
background: var(--accent);
|
|
|
|
|
color: #fff;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
font-size: 0.9rem;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: background 0.15s, opacity 0.15s;
|
|
|
|
|
}
|
|
|
|
|
.btn:hover { background: var(--accent-hover); }
|
|
|
|
|
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
|
.btn.loading { position: relative; }
|
|
|
|
|
.btn.loading::after {
|
|
|
|
|
content: '';
|
|
|
|
|
display: inline-block;
|
|
|
|
|
width: 1em; height: 1em;
|
|
|
|
|
border: 2px solid rgba(255,255,255,0.3);
|
|
|
|
|
border-top-color: #fff;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
animation: spin 0.6s linear infinite;
|
|
|
|
|
margin-left: 0.5em;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
}
|
|
|
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
|
|
|
.status {
|
|
|
|
|
margin-top: 1.25rem;
|
|
|
|
|
padding: 0.875rem 1rem;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
font-size: 0.85rem;
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.status.show { display: block; }
|
|
|
|
|
.status.ok { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
|
|
|
|
|
.status.err { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--error); }
|
|
|
|
|
.status.info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: var(--accent); }
|
|
|
|
|
.status .task-id { font-family: monospace; font-size: 0.8em; color: var(--text-dim); }
|
|
|
|
|
.version-tag {
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0.75rem;
|
|
|
|
|
right: 1rem;
|
|
|
|
|
font-size: 0.7rem;
|
|
|
|
|
color: var(--text-dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Login screen */
|
|
|
|
|
.login-screen .main-ui { display: none; }
|
|
|
|
|
.main-ui .login-screen { display: none; }
|
|
|
|
|
.login-screen {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
.login-screen .logo { font-size: 2rem; margin-bottom: 0.5rem; }
|
|
|
|
|
.login-screen .subtitle { margin-bottom: 2rem; }
|
|
|
|
|
.login-screen .field { text-align: left; }
|
|
|
|
|
.lock-icon {
|
|
|
|
|
font-size: 2.5rem;
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Device / firmware info badges */
|
|
|
|
|
.badge {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
font-size: 0.7rem;
|
|
|
|
|
padding: 0.15rem 0.4rem;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
background: rgba(59,130,246,0.15);
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
margin-left: 0.5rem;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
}
|
|
|
|
|
.fw-info { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }
|
|
|
|
|
hr.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
|
|
|
|
|
.inline-field { display: flex; gap: 0.75rem; }
|
|
|
|
|
.inline-field .field { flex: 1; }
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
<!-- LOGIN SCREEN -->
|
|
|
|
|
<div class="card login-screen" id="loginScreen">
|
|
|
|
|
<div class="lock-icon">🔐</div>
|
|
|
|
|
<div class="logo">GenieACS Firmware Pusher</div>
|
|
|
|
|
<div class="subtitle">Enter your GenieACS credentials to continue</div>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Username</label>
|
|
|
|
|
<input type="text" id="inUser" value="admin" autocomplete="username" spellcheck="false" />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Password</label>
|
|
|
|
|
<input type="password" id="inPass" autocomplete="current-password" spellcheck="false" />
|
|
|
|
|
</div>
|
|
|
|
|
<button class="btn" id="btnConnect" onclick="connect()">Connect</button>
|
|
|
|
|
<div class="status" id="loginStatus"></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- MAIN UI -->
|
|
|
|
|
<div class="card main-ui" id="mainUI">
|
|
|
|
|
<div class="logo">GenieACS Firmware Pusher</div>
|
|
|
|
|
<div class="subtitle">
|
|
|
|
|
<span id="connectedAs">Connected</span>
|
|
|
|
|
<button onclick="logout()" style="background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:0.75rem;margin-left:0.5rem;text-decoration:underline;">disconnect</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<hr class="divider">
|
|
|
|
|
|
|
|
|
|
<div class="inline-field">
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Device</label>
|
|
|
|
|
<select id="selDevice">
|
|
|
|
|
<option value="">— Loading devices… —</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="fw-info" id="devInfo"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>
|
|
|
|
|
Firmware
|
|
|
|
|
<span class="badge" id="fwCount"></span>
|
|
|
|
|
</label>
|
|
|
|
|
<select id="selFw">
|
|
|
|
|
<option value="">— Loading files… —</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="fw-info" id="fwInfo"></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button class="btn" id="btnPush" onclick="pushFirmware()" disabled>
|
|
|
|
|
Push Firmware
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<div class="status" id="statusBox"></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="version-tag">GenieACS Firmware Pusher v1.0</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
const NBI = 'https://nbi.yoda.ddnsgeek.com';
|
|
|
|
|
|
|
|
|
|
// ── Auth helpers ───────────────────────────────────────────
|
|
|
|
|
function getCreds() {
|
|
|
|
|
return { user: sessionStorage.getItem('nbi_user'), pass: sessionStorage.getItem('nbi_pass') };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function b64auth() {
|
|
|
|
|
const { user, pass } = getCreds();
|
|
|
|
|
return 'Basic ' + btoa(user + ':' + pass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function logout() {
|
|
|
|
|
sessionStorage.removeItem('nbi_user');
|
|
|
|
|
sessionStorage.removeItem('nbi_pass');
|
|
|
|
|
document.getElementById('mainUI').classList.remove('main-ui');
|
|
|
|
|
document.getElementById('mainUI').classList.add('login-screen');
|
|
|
|
|
document.getElementById('loginScreen').classList.add('login-screen');
|
|
|
|
|
document.getElementById('loginScreen').style.display = '';
|
|
|
|
|
document.getElementById('inPass').value = '';
|
|
|
|
|
clearStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── API helpers ────────────────────────────────────────────
|
|
|
|
|
async function api(path, method = 'GET', body = null) {
|
|
|
|
|
const opts = {
|
|
|
|
|
method,
|
|
|
|
|
headers: { 'Authorization': b64auth(), 'Content-Type': 'application/json' }
|
|
|
|
|
};
|
|
|
|
|
if (body) opts.body = JSON.stringify(body);
|
|
|
|
|
const r = await fetch(NBI + path, opts);
|
|
|
|
|
if (r.status === 401) throw new Error('AUTH');
|
|
|
|
|
if (r.status === 204) return null;
|
|
|
|
|
return r.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Login ──────────────────────────────────────────────────
|
|
|
|
|
async function connect() {
|
|
|
|
|
const user = document.getElementById('inUser').value.trim();
|
|
|
|
|
const pass = document.getElementById('inPass').value;
|
|
|
|
|
if (!user || !pass) { showStatus('loginStatus', 'Please enter username and password.', 'err'); return; }
|
|
|
|
|
|
|
|
|
|
const btn = document.getElementById('btnConnect');
|
|
|
|
|
btn.classList.add('loading'); btn.disabled = true;
|
|
|
|
|
clearStatus('loginStatus');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Test auth by fetching devices
|
|
|
|
|
const test = await fetch(NBI + '/devices?projection=_id', {
|
|
|
|
|
headers: { 'Authorization': 'Basic ' + btoa(user + ':' + pass) }
|
|
|
|
|
});
|
|
|
|
|
if (test.status === 401) throw new Error('Invalid credentials');
|
|
|
|
|
if (!test.ok) throw new Error('Server error: ' + test.status);
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('nbi_user', user);
|
|
|
|
|
sessionStorage.setItem('nbi_pass', pass);
|
|
|
|
|
|
|
|
|
|
document.getElementById('loginScreen').style.display = 'none';
|
|
|
|
|
document.getElementById('mainUI').classList.add('main-ui');
|
|
|
|
|
document.getElementById('connectedAs').textContent = 'Connected as ' + user;
|
|
|
|
|
|
|
|
|
|
await loadDevices();
|
|
|
|
|
await loadFiles();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
if (e.message === 'AUTH' || e.message === 'Invalid credentials') {
|
|
|
|
|
showStatus('loginStatus', 'Invalid username or password.', 'err');
|
|
|
|
|
} else {
|
|
|
|
|
showStatus('loginStatus', 'Cannot reach GenieACS NBI API: ' + e.message, 'err');
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
btn.classList.remove('loading'); btn.disabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Load devices ───────────────────────────────────────────
|
|
|
|
|
async function loadDevices() {
|
|
|
|
|
const sel = document.getElementById('selDevice');
|
|
|
|
|
const info = document.getElementById('devInfo');
|
|
|
|
|
sel.innerHTML = '<option value="">Loading…</option>';
|
|
|
|
|
try {
|
|
|
|
|
const devs = await api('/devices?projection=InternetGatewayDevice.');
|
|
|
|
|
sel.innerHTML = '';
|
|
|
|
|
if (!devs || devs.length === 0) {
|
|
|
|
|
sel.innerHTML = '<option value="">No devices found</option>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Sort: online first, then by ID
|
|
|
|
|
devs.sort((a, b) => {
|
|
|
|
|
const ia = a._id.toLowerCase(), ib = b._id.toLowerCase();
|
|
|
|
|
return ia.localeCompare(ib);
|
|
|
|
|
});
|
|
|
|
|
for (const d of devs) {
|
|
|
|
|
const serial = d._id.includes('-') ? d._id.split('-').pop() : d._id;
|
|
|
|
|
const igd = d.InternetGatewayDevice || {};
|
|
|
|
|
const sw = igd.DeviceInfo?.SoftwareVersion?._value || '—';
|
|
|
|
|
const url = igd.ManagementServer?.ConnectionRequestURL?._value || '';
|
|
|
|
|
const online = url && !url.includes('://0.') ? '🟢' : '⚫';
|
|
|
|
|
const opt = document.createElement('option');
|
|
|
|
|
opt.value = d._id;
|
|
|
|
|
opt.textContent = `${online} ${serial} (${sw})`;
|
|
|
|
|
sel.appendChild(opt);
|
|
|
|
|
}
|
|
|
|
|
sel.addEventListener('change', onDevChange);
|
|
|
|
|
onDevChange();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
sel.innerHTML = '<option value="">Error loading devices</option>';
|
|
|
|
|
info.textContent = e.message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDevChange() {
|
|
|
|
|
const btn = document.getElementById('btnPush');
|
|
|
|
|
const sel = document.getElementById('selDevice');
|
|
|
|
|
const info = document.getElementById('devInfo');
|
|
|
|
|
const fw = document.getElementById('selFw');
|
|
|
|
|
info.textContent = '';
|
|
|
|
|
btn.disabled = !sel.value || !fw.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Load firmware files ─────────────────────────────────────
|
|
|
|
|
async function loadFiles() {
|
|
|
|
|
const sel = document.getElementById('selFw');
|
|
|
|
|
const count = document.getElementById('fwCount');
|
|
|
|
|
const info = document.getElementById('fwInfo');
|
|
|
|
|
sel.innerHTML = '<option value="">Loading…</option>';
|
|
|
|
|
try {
|
|
|
|
|
const files = await api('/files');
|
|
|
|
|
sel.innerHTML = '';
|
|
|
|
|
if (!files || files.length === 0) {
|
|
|
|
|
sel.innerHTML = '<option value="">No firmware files uploaded</option>';
|
|
|
|
|
count.textContent = '0';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
count.textContent = files.length + ' file' + (files.length !== 1 ? 's' : '');
|
|
|
|
|
// Sort by version descending
|
|
|
|
|
files.sort((a, b) => {
|
|
|
|
|
const va = (a.version || '0').split('.').map(Number);
|
|
|
|
|
const vb = (b.version || '0').split('.').map(Number);
|
|
|
|
|
for (let i = 0; i < Math.max(va.length, vb.length); i++) {
|
|
|
|
|
const na = va[i] || 0, nb = vb[i] || 0;
|
|
|
|
|
if (na !== nb) return nb - na;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
for (const f of files) {
|
|
|
|
|
const opt = document.createElement('option');
|
|
|
|
|
opt.value = f.fileName;
|
|
|
|
|
const ver = f.version || f.fileName.match(/R(\d+[\d.]*)/)?.[1] || '—';
|
|
|
|
|
const sz = f.size ? fmtSize(f.size) : '';
|
|
|
|
|
opt.textContent = f.version ? `R${f.version}${sz ? ' (' + sz + ')' : ''}` : f.fileName;
|
|
|
|
|
opt.dataset.version = f.version || '';
|
|
|
|
|
opt.dataset.size = f.size || '';
|
|
|
|
|
sel.appendChild(opt);
|
|
|
|
|
}
|
|
|
|
|
sel.addEventListener('change', onFwChange);
|
|
|
|
|
onFwChange();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
sel.innerHTML = '<option value="">Error loading files</option>';
|
|
|
|
|
info.textContent = e.message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onFwChange() {
|
|
|
|
|
const sel = document.getElementById('selFw');
|
|
|
|
|
const btn = document.getElementById('btnPush');
|
|
|
|
|
const info = document.getElementById('fwInfo');
|
|
|
|
|
const opt = sel.options[sel.selectedIndex];
|
|
|
|
|
if (opt && opt.value) {
|
|
|
|
|
const sz = opt.dataset.size ? fmtSize(parseInt(opt.dataset.size)) : '';
|
|
|
|
|
info.textContent = opt.value + (sz ? ' · ' + sz : '');
|
|
|
|
|
} else {
|
|
|
|
|
info.textContent = '';
|
|
|
|
|
}
|
|
|
|
|
btn.disabled = !document.getElementById('selDevice').value || !sel.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Push firmware ──────────────────────────────────────────
|
|
|
|
|
async function pushFirmware() {
|
|
|
|
|
const devId = document.getElementById('selDevice').value;
|
|
|
|
|
const fileName = document.getElementById('selFw').value;
|
|
|
|
|
const btn = document.getElementById('btnPush');
|
|
|
|
|
const status = document.getElementById('statusBox');
|
|
|
|
|
|
|
|
|
|
if (!devId || !fileName) return;
|
|
|
|
|
|
|
|
|
|
clearStatus();
|
|
|
|
|
btn.classList.add('loading'); btn.disabled = true;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const task = await api('/devices/' + encodeURIComponent(devId) + '/tasks', 'POST', {
|
|
|
|
|
name: 'download',
|
|
|
|
|
fileType: '1 Firmware Upgrade Image',
|
|
|
|
|
fileName: fileName,
|
|
|
|
|
productClass: 'GigaSpire'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (task && task.name === 'download') {
|
|
|
|
|
showStatus('statusBox',
|
|
|
|
|
`✓ Firmware push queued successfully. Task ID: <span class="task-id">${task.id}</span>`,
|
|
|
|
|
'ok');
|
|
|
|
|
} else {
|
|
|
|
|
showStatus('statusBox', '✓ Task created: ' + JSON.stringify(task).slice(0, 100), 'ok');
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {
|
|
|
|
|
if (e.message === 'AUTH') {
|
|
|
|
|
showStatus('statusBox', 'Session expired. Please reconnect.', 'err');
|
|
|
|
|
setTimeout(logout, 1500);
|
|
|
|
|
} else {
|
|
|
|
|
showStatus('statusBox', 'Failed to push firmware: ' + e.message, 'err');
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
btn.classList.remove('loading'); btn.disabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── UI helpers ─────────────────────────────────────────────
|
|
|
|
|
function showStatus(id, html, type) {
|
|
|
|
|
const el = document.getElementById(id);
|
|
|
|
|
el.innerHTML = html;
|
|
|
|
|
el.className = 'status show ' + type;
|
|
|
|
|
}
|
|
|
|
|
function clearStatus(id = 'statusBox') {
|
|
|
|
|
const el = document.getElementById(id);
|
|
|
|
|
if (el) { el.className = 'status'; el.innerHTML = ''; }
|
|
|
|
|
}
|
|
|
|
|
function fmtSize(bytes) {
|
|
|
|
|
if (!bytes) return '';
|
|
|
|
|
if (bytes >= 1e9) return (bytes/1e9).toFixed(1) + ' GB';
|
|
|
|
|
if (bytes >= 1e6) return (bytes/1e6).toFixed(0) + ' MB';
|
|
|
|
|
return (bytes/1e3).toFixed(0) + ' KB';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Boot ──────────────────────────────────────────────────
|
|
|
|
|
(function init() {
|
|
|
|
|
const { user, pass } = getCreds();
|
|
|
|
|
if (user && pass) {
|
|
|
|
|
// Restore session
|
|
|
|
|
document.getElementById('inUser').value = user;
|
|
|
|
|
document.getElementById('loginScreen').style.display = 'none';
|
|
|
|
|
document.getElementById('mainUI').classList.add('main-ui');
|
|
|
|
|
document.getElementById('connectedAs').textContent = 'Connected as ' + user;
|
|
|
|
|
loadDevices().then(loadFiles).catch(() => logout());
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('loginScreen').classList.add('login-screen');
|
|
|
|
|
}
|
|
|
|
|
// Enter key on password field
|
|
|
|
|
document.getElementById('inPass').addEventListener('keydown', e => {
|
|
|
|
|
if (e.key === 'Enter') connect();
|
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|