Network hub hook (Marty 2026-11-16): sign out everywhere, hub blocks and erases end sessions here; "Sign out everywhere" button
hubevents.js (new, byte-identical in VBB, DLB, ViralAdBlitz, DownlineHydra, 5xYourTeam): POST /api/hub/events, signed by the hub with HUB_SECRET (same hook InstantAdPay and LinkSpin take). member.signedout and member.blocked: the person is looked up by hub id (/v1/resolve, signed as bannerline) and every session of their main wallet or any contract wallet ends. member.erased: matched by the wallet SHA-256s the hub now sends with the event. Only sessions made before the event end (a replay never signs anyone out twice); a failed hub lookup answers 503 so the hub resends. Off with HUB_HOOK=0. Admin status: hubEvents (counts only). My Spots: "Sign out everywhere" next to Sign out (POST /api/auth/logout-everywhere -> networksso.signOutEverywhere, then every session of this wallet here ends). my.js?v=z2. Smoke section 9 (refused signatures, signedout in two browsers, replay, older event, blocked, erased by wallet hash, other events, hub down -> 503 -> resent, Sign out everywhere, admin view): 145/145 with UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+135
@@ -0,0 +1,135 @@
|
||||
// Network hub events for a wallet site (Marty 2026-11-16, "Yes do 1 and 2"). Byte-identical in Viral Banner Blitz, Downline Banners,
|
||||
// ViralAdBlitz, DownlineHydra and 5xYourTeam (like networksso.js): copy it whole, never edit one copy alone.
|
||||
//
|
||||
// The hub tells every hooked site what changed (POST /api/hub/events, the same hook InstantAdPay and LinkSpin take): X-Hub-Ts +
|
||||
// X-Hub-Sig = hex HMAC-SHA256(HUB_SECRET, ts + newline + raw body), 5-minute window. The hub only moves its cursor after a 2xx and
|
||||
// may send an event twice. This site acts on three events and ignores every other one:
|
||||
// member.signedout "Sign out everywhere" on any network site
|
||||
// member.blocked the hub blocked the person
|
||||
// member.erased the hub erased the person ({emailHash, walletHashes}: the person is gone from the hub, so no lookup)
|
||||
// Each one ends that person's sessions here. A wallet site keys sessions by wallet, so the person is mapped through the hub:
|
||||
// POST /v1/resolve {id} (signed as HUB_SITE) gives their main wallet and every contract wallet (contractWallets). An erased
|
||||
// person cannot be looked up any more: the event carries the SHA-256 of each of their wallets (and of their email) instead.
|
||||
// Only sessions made BEFORE the event end (a fresh sign-in after it stays), so a replay can never sign anyone out twice.
|
||||
// A failed lookup answers 503 so the hub sends the batch again; after 5 tries an event is set aside in the log.
|
||||
// Nothing here sends mail, posts or touches a banner, a payout or the chain: it only ends sign-in sessions.
|
||||
//
|
||||
// init({ dataDir, site, end }) where end({ type, personId, at, wallets, walletHashes, emailHash, match }) ends the sessions and
|
||||
// answers how many; match(session-like {address?, email?, wallet?, hubId?}) is the shared test (wallet, wallet hash, email
|
||||
// hash, hub id). Off when HUB_HOOK=0, or without HUB_URL and a 32+ character HUB_SECRET (then the route answers 404).
|
||||
'use strict';
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const WALLET_RE = /^0x[0-9a-f]{40}$/, HASH_RE = /^[0-9a-f]{64}$/;
|
||||
const TRIES = 5, KEEP = 3000, SKEW = 2000;
|
||||
const ACTS = new Set(['member.signedout', 'member.blocked', 'member.erased']);
|
||||
let R = null, st = null, chain_ = Promise.resolve();
|
||||
const SECRET = () => String(process.env.HUB_SECRET || '').trim();
|
||||
const BASE = () => String(process.env.HUB_URL || '').trim().replace(/\/+$/, '');
|
||||
const SITE = () => String(process.env.HUB_SITE || (R && R.site) || '').trim().toLowerCase();
|
||||
const on = () => !/^(0|false|no|off)$/i.test(String(process.env.HUB_HOOK || '').trim()) && /^https?:\/\/[a-z0-9.:-]+$/i.test(BASE()) && SECRET().length >= 32;
|
||||
const lc = v => String(v == null ? '' : v).trim().toLowerCase();
|
||||
const sha = v => crypto.createHash('sha256').update(lc(v)).digest('hex');
|
||||
const FILE = () => path.join(R.dataDir, 'hubevents.json');
|
||||
|
||||
function load() {
|
||||
if (st) return st;
|
||||
try { st = JSON.parse(fs.readFileSync(FILE(), 'utf8')); } catch (e) { st = null; }
|
||||
if (!st || typeof st !== 'object') st = {};
|
||||
st.done = st.done || {}; st.tries = st.tries || {}; st.log = st.log || [];
|
||||
st.stats = Object.assign({ batches: 0, events: 0, ended: 0, ignored: 0, skipped: 0, gaveUp: 0, refused: 0 }, st.stats || {});
|
||||
return st;
|
||||
}
|
||||
function save() { if (!R || !R.dataDir) return; try { const t = FILE() + '.tmp'; fs.writeFileSync(t, JSON.stringify(load())); fs.renameSync(t, FILE()); } catch (e) { console.error('hubevents save', e.message); } }
|
||||
function note(x) { const s = load(); s.log.push(Object.assign({ ts: Date.now() }, x)); if (s.log.length > 200) s.log = s.log.slice(-200); }
|
||||
function init(deps) { R = deps || {}; load(); }
|
||||
|
||||
const sign = (ts, raw) => crypto.createHmac('sha256', SECRET()).update(String(ts) + '\n' + raw).digest('hex');
|
||||
function verify(headers, raw) {
|
||||
if (SECRET().length < 32) return false;
|
||||
const ts = String(headers['x-hub-ts'] || ''), sig = String(headers['x-hub-sig'] || '');
|
||||
if (!/^\d{10,16}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 5 * 60000 || !/^[0-9a-f]{64}$/.test(sig)) return false;
|
||||
const want = sign(ts, raw);
|
||||
return crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig));
|
||||
}
|
||||
// the hub person by hub id (null = the hub does not know them); throws when the hub does not answer
|
||||
async function resolveId(id) {
|
||||
const raw = JSON.stringify({ id }); const ts = String(Date.now());
|
||||
const r = await fetch(BASE() + '/v1/resolve', { method: 'POST', body: raw, signal: AbortSignal.timeout(10000),
|
||||
headers: { 'Content-Type': 'application/json', 'X-Hub-Site': SITE(), 'X-Hub-Ts': ts, 'X-Hub-Sig': sign(ts, raw) } });
|
||||
if (r.status !== 200) throw new Error('hub resolve ' + r.status);
|
||||
const j = await r.json(); return j && j.person && typeof j.person === 'object' ? j.person : null;
|
||||
}
|
||||
// every wallet the hub holds for a person: the main wallet and each contract's wallet
|
||||
function walletsOf(p) {
|
||||
const out = new Set(); if (!p) return [];
|
||||
if (WALLET_RE.test(lc(p.wallet))) out.add(lc(p.wallet));
|
||||
for (const w of Object.values(p.contractWallets || {})) if (WALLET_RE.test(lc(w))) out.add(lc(w));
|
||||
return [...out];
|
||||
}
|
||||
// the shared test: does this session / member belong to the person?
|
||||
function matcher(who) {
|
||||
const ws = new Set(who.wallets || []), hs = new Set(who.walletHashes || []), eh = who.emailHash || null, id = who.personId || null;
|
||||
return x => {
|
||||
if (!x) return false;
|
||||
for (const w of [x.address, x.wallet, x.hubWallet]) { const v = lc(w); if (WALLET_RE.test(v) && (ws.has(v) || hs.has(sha(v)))) return true; }
|
||||
if (eh && x.email && sha(x.email) === eh) return true;
|
||||
if (id && (x.hubId === id || x.key === id)) return true;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
async function apply(ev) {
|
||||
if (!ACTS.has(ev.type) || !ev.personId) return 'ignored';
|
||||
const who = { type: ev.type, personId: String(ev.personId), at: Number(ev.at) || Date.now(), wallets: [], walletHashes: [], emailHash: null };
|
||||
if (ev.type === 'member.erased') {
|
||||
const d = ev.data || {};
|
||||
who.walletHashes = (Array.isArray(d.walletHashes) ? d.walletHashes : []).map(lc).filter(h => HASH_RE.test(h)).slice(0, 50);
|
||||
who.emailHash = HASH_RE.test(lc(d.emailHash)) ? lc(d.emailHash) : null;
|
||||
} else {
|
||||
const p = await resolveId(who.personId); // throws: the hub sends it again
|
||||
if (!p) return 'ignored';
|
||||
who.wallets = walletsOf(p);
|
||||
}
|
||||
who.before = who.at + SKEW; // sessions made after the event are fresh sign-ins and stay
|
||||
who.match = matcher(who);
|
||||
const n = Number(await R.end(who)) || 0;
|
||||
note({ type: ev.type, seq: ev.seq, sessions: n });
|
||||
if (n) { load().stats.ended += n; return 'applied'; }
|
||||
return 'none';
|
||||
}
|
||||
function prune() {
|
||||
const s = load(); const seqs = Object.keys(s.done).map(Number).sort((a, b) => a - b);
|
||||
for (const q of seqs.slice(0, Math.max(0, seqs.length - KEEP))) delete s.done[q];
|
||||
}
|
||||
async function handle(events) {
|
||||
const s = load(); s.stats.batches++; let failed = null;
|
||||
for (const ev of Array.isArray(events) ? events : []) {
|
||||
const seq = Number(ev && ev.seq); if (!seq) continue;
|
||||
if (s.done[seq]) { s.stats.skipped++; continue; }
|
||||
s.stats.events++;
|
||||
try {
|
||||
const r = await apply(ev);
|
||||
s.done[seq] = Date.now(); delete s.tries[seq];
|
||||
if (r === 'ignored') s.stats.ignored++;
|
||||
} catch (e) {
|
||||
s.tries[seq] = (s.tries[seq] || 0) + 1;
|
||||
console.error('hubevents', seq, ev.type, e.message);
|
||||
if (s.tries[seq] >= TRIES) { s.done[seq] = Date.now(); delete s.tries[seq]; s.stats.gaveUp++; note({ type: 'gave-up', seq, event: ev.type, error: String(e.message).slice(0, 160) }); continue; }
|
||||
failed = e; break;
|
||||
}
|
||||
}
|
||||
prune(); save();
|
||||
return failed ? { status: 503, body: { error: 'retry' } } : { status: 200, body: { ok: true } };
|
||||
}
|
||||
// the POST /api/hub/events handler -> { status, body }. Batches run one at a time.
|
||||
function receive(headers, raw) {
|
||||
if (!R || !on()) return Promise.resolve({ status: 404, body: { error: 'not found' } });
|
||||
if (!verify(headers || {}, String(raw || ''))) { load().stats.refused++; return Promise.resolve({ status: 401, body: { error: 'unauthorized' } }); }
|
||||
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return Promise.resolve({ status: 400, body: { error: 'bad json' } }); }
|
||||
const run = chain_.then(() => handle(b && b.events)); chain_ = run.catch(() => {}); return run;
|
||||
}
|
||||
function view() { const s = load(); return { on: on(), stats: s.stats, waiting: Object.keys(s.tries).length, log: s.log.slice(-20) }; }
|
||||
|
||||
module.exports = { init, receive, view, on, verify, walletsOf, matcher, sha, _reset: () => { st = null; chain_ = Promise.resolve(); } };
|
||||
@@ -17,6 +17,7 @@
|
||||
return;
|
||||
}
|
||||
$('outBtn').onclick = async () => { await BL.post('/api/auth/logout'); location.reload(); };
|
||||
$('outAllBtn').onclick = async () => { $('outAllBtn').disabled = true; await BL.post('/api/auth/logout-everywhere'); location.reload(); };
|
||||
async function load() {
|
||||
const d = await BL.getJSON('/api/my');
|
||||
if (d.error) return BL.status(d.error, 'err');
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@
|
||||
<section class="hero"><h1>My Spots</h1><p class="lead">Your spots, your images and links, and every payment the contract sent you.</p></section>
|
||||
<div class="card" id="signin" hidden><h3>Sign in with your wallet</h3><p class="muted small">You sign a short message. It is free and cannot move funds or approve anything.</p><button class="btn" id="signBtn">Sign in</button></div>
|
||||
<div id="dash" hidden>
|
||||
<div class="card"><div class="row" style="justify-content:space-between"><div><span class="muted small">Signed in as</span> <span class="mono" id="me"></span></div><button class="btn quiet small" id="outBtn">Sign out</button></div>
|
||||
<div class="card"><div class="row" style="justify-content:space-between"><div><span class="muted small">Signed in as</span> <span class="mono" id="me"></span></div><span class="row" style="gap:8px"><button class="btn quiet small" id="outBtn">Sign out</button><button class="btn quiet small" id="outAllBtn" title="Ends your network sign-in on every network site">Sign out everywhere</button></span></div>
|
||||
<div class="grid2" style="margin-top:12px" id="stats"></div></div><div id="zMySpots"></div>
|
||||
<div class="card"><h3>Your share link</h3><p class="muted small">People who join through this link have you as their sponsor. It is set once, on their first spot.</p>
|
||||
<div class="field"><input id="share" readonly></div><button class="btn sec small" id="copyBtn">Copy link</button></div>
|
||||
@@ -43,7 +43,7 @@
|
||||
</main>
|
||||
<script src="/assets/common.js?v=20261115nr"></script>
|
||||
<script src="/assets/wallet.js?v=1"></script>
|
||||
<script src="/assets/my.js?v=z1"></script>
|
||||
<script src="/assets/my.js?v=z2"></script>
|
||||
<script src="/assets/chat.js?v=1" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+40
-1
@@ -27,7 +27,7 @@ let pass = 0, fail = 0; const procs = [];
|
||||
const ok = (cond, what, extra) => { if (cond) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (extra !== undefined ? ' -> ' + JSON.stringify(extra).slice(0, 300) : '')); } };
|
||||
// stand-in network hub (POST /v1/resolve, signed as bannerline) and stand-in InstantAdPay member lookup (the fallback when the
|
||||
// hub is unreachable). HUB.people: {id, username, wallet, sponsorId}; HUB.down makes every hub call fail with 503.
|
||||
const HUB = { people: [], down: false, calls: 0, badSig: 0 }; const HUB_PORT = APP_PORT + 7, HUB_SECRET = 'b'.repeat(40);
|
||||
const HUB = { people: [], down: false, calls: 0, badSig: 0, got: [] }; const HUB_PORT = APP_PORT + 7, HUB_SECRET = 'b'.repeat(40);
|
||||
const IAPNET = new Map(); const IAP_PORT = APP_PORT + 8;
|
||||
const TG = []; const TG_PORT = APP_PORT + 9; // stand-in Telegram Bot API (trust pack 2026-11-14): never the real group
|
||||
const hubView = p => p ? { id: p.id, username: p.username, wallet: p.wallet, sponsor: (x => x ? { id: x.id, username: x.username } : null)(HUB.people.find(y => y.id === p.sponsorId)), blocked: false, locked: false } : null;
|
||||
@@ -45,6 +45,7 @@ function startStandIns() {
|
||||
if (HUB.down) { r.statusCode = 503; return r.end('{"error":"superseded"}'); }
|
||||
const want = crypto.createHmac('sha256', HUB_SECRET).update(q.headers['x-hub-ts'] + '\n' + b).digest('hex');
|
||||
if (q.headers['x-hub-sig'] !== want || q.headers['x-hub-site'] !== 'bannerline') { HUB.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); }
|
||||
if (q.url === '/v1/sso/signout') { HUB.got.push({ route: q.url, body: JSON.parse(b || '{}') }); return r.end('{"ok":true,"ended":1}'); } // Sign out everywhere (2026-11-16)
|
||||
if (q.url !== '/v1/resolve') { r.statusCode = 404; return r.end('{"error":"not_found"}'); }
|
||||
const j = JSON.parse(b || '{}'); const ref = String(j.ref || '').toLowerCase();
|
||||
const p = j.id ? HUB.people.find(x => x.id === j.id) : j.wallet ? HUB.people.find(x => x.wallet === String(j.wallet).toLowerCase()) : ref ? HUB.people.find(x => x.username === ref || x.wallet === ref) : null;
|
||||
@@ -357,6 +358,44 @@ async function main() {
|
||||
const ours = errors.filter(e => !/example\.(com|net|org)/.test(e)); // gate frames load example.* sites; their own 404s (favicon) are not ours
|
||||
ok(ours.length === 0, 'no console errors on our pages', ours);
|
||||
}
|
||||
console.log('9. network hub events (sign out everywhere, block, erase end sessions here)');
|
||||
{ const crypto = require('node:crypto'); const admin = (p, body) => client().json(p, body, { 'x-admin-token': ADMIN }); let hseq = 900000; let hn = 700;
|
||||
const signAs = async (w, name) => { const c = client('Mozilla/5.0 hook ' + (hn++)); const a = w.address.toLowerCase(); const xf = { 'X-Forwarded-For': '198.51.100.' + (hn % 250) };
|
||||
if (name) { c.hubId = hid(hn); HUB.people.push({ id: c.hubId, username: name, wallet: a, sponsorId: null }); }
|
||||
const ch = await c.json('/api/auth/challenge', { address: w.address }, xf);
|
||||
const v = await c.json('/api/auth/verify', { address: w.address, signature: await w.signMessage(ch.message) }, xf);
|
||||
c.address = a; c.wallet = w; c.ok = v.ok === true && !!c.jar['bl.sid']; return c; };
|
||||
const walletMember = o => signAs((o && o.wallet) || ethers.Wallet.createRandom(), o && o.hub && o.hub.username); const signedIn = async c => (await c.json('/api/me')).signedIn === true;
|
||||
const hook = async (events, o = {}) => { const raw = JSON.stringify({ events }); const ts = String(o.ts || Date.now());
|
||||
const sig = o.sig || crypto.createHmac('sha256', o.secret || HUB_SECRET).update(ts + '\n' + raw).digest('hex');
|
||||
const r = await fetch(BASE + '/api/hub/events', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Hub-Ts': ts, 'X-Hub-Sig': sig }, body: raw }); return r.status; };
|
||||
const ev = (type, personId, data, at) => ({ seq: ++hseq, at: at || Date.now(), type, personId, data: data || {} });
|
||||
const H1 = await walletMember({ hub: { username: 'hookone' } }); const H1b = await walletMember({ wallet: H1.wallet }); const H2 = await walletMember({ hub: { username: 'hooktwo' } });
|
||||
const H3 = await walletMember({ hub: { username: 'hookthree' } }); const H4 = await walletMember({ hub: { username: 'hookfour' } });
|
||||
ok(H1.ok && H1b.ok && H2.ok && H3.ok && H4.ok && await signedIn(H1) && await signedIn(H1b), 'setup: hub members signed in here (one of them in two browsers)');
|
||||
ok(await hook([ev('member.signedout', H1.hubId)], { secret: 'x'.repeat(40) }) === 401 && await hook([ev('member.signedout', H1.hubId)], { ts: Date.now() - 600000 }) === 401, 'a hook signed with another key, or 10 minutes old, is refused (401)');
|
||||
ok(await signedIn(H1), 'a refused hook ends nothing');
|
||||
const so = ev('member.signedout', H1.hubId);
|
||||
ok(await hook([so]) === 200 && !(await signedIn(H1)) && !(await signedIn(H1b)) && await signedIn(H2), 'member.signedout: every session of that wallet ends (both browsers), nobody else\'s');
|
||||
const H1c = await walletMember({ wallet: H1.wallet });
|
||||
ok(await hook([so]) === 200 && await signedIn(H1c), 'the same event sent twice: applied once, a fresh sign-in stays');
|
||||
ok(await hook([ev('member.signedout', H1.hubId, {}, Date.now() - 60000)]) === 200 && await signedIn(H1c), 'an event older than a session never ends it (only sessions made before the event)');
|
||||
ok(await hook([ev('member.blocked', H2.hubId)]) === 200 && !(await signedIn(H2)) && await signedIn(H3), 'member.blocked: that member is signed out here');
|
||||
const wh = crypto.createHash('sha256').update(H3.address).digest('hex'); HUB.people = HUB.people.filter(x => x.id !== H3.hubId);
|
||||
ok(await hook([ev('member.erased', H3.hubId, { emailHash: 'a'.repeat(64), walletHashes: [wh] })]) === 200 && !(await signedIn(H3)) && await signedIn(H4), 'member.erased: found by the wallet hash in the event (the hub no longer knows them), signed out');
|
||||
ok(await hook([ev('member.joined', H4.hubId), ev('member.signedout', 'h_' + 'f'.repeat(16))]) === 200 && await signedIn(H4), 'other events and unknown people are ignored');
|
||||
HUB.down = true; const late = ev('member.signedout', H4.hubId);
|
||||
ok(await hook([late]) === 503 && await signedIn(H4), 'the hub lookup failing answers 503 (the hub sends it again), nothing ended');
|
||||
HUB.down = false; ok(await hook([late]) === 200 && !(await signedIn(H4)), 'resent once the hub answers: signed out');
|
||||
const E1 = await walletMember({ hub: { username: 'hookfive' } }); const E2 = await walletMember({ wallet: E1.wallet }); const g0 = HUB.got.length;
|
||||
const eo = await E1.json('/api/auth/logout-everywhere', {});
|
||||
const call = HUB.got.slice(g0).find(x => x.route === '/v1/sso/signout');
|
||||
ok(eo.ok && eo.everywhere === true && !(await signedIn(E1)) && !(await signedIn(E2)) && call && call.body.wallet === E1.address, 'Sign out everywhere: the hub is told (signed, by wallet) and every session of that wallet here ends', { eo, call });
|
||||
ok(/id="outAllBtn"[^>]*>Sign out everywhere</.test(await (await client().req('/my')).text()), '/my has a Sign out everywhere button next to Sign out');
|
||||
const st2 = await admin('/api/admin/status');
|
||||
ok(st2.hubEvents && st2.hubEvents.on && st2.hubEvents.stats.ended >= 5 && st2.hubEvents.stats.refused >= 2 && !JSON.stringify(st2.hubEvents).includes(HUB_SECRET), 'admin status shows the hub events (counts only, no secret)', st2.hubEvents);
|
||||
}
|
||||
|
||||
console.log('\n' + pass + ' passed, ' + fail + ' failed. Output in ' + OUT);
|
||||
cleanup(); process.exit(fail ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ function limited(req, name, max, windowMs) {
|
||||
// verify membership"; hubpeople.js, cached 5 minutes); InstantAdPay's GET /api/network/member ?u= / ?a= only when the hub is
|
||||
// unreachable (cached an hour, misses too; a failed call is not cached). A person the hub does not know is unknown here too.
|
||||
const hubpeople = require('./hubpeople');
|
||||
const hubevents = require('./hubevents'); // network hub hook (2026-11-16): sign-out-everywhere, block and erase end sessions here
|
||||
const netCache = new Map();
|
||||
const fromHub = p => { const a = hubpeople.wallet(p); return a ? { address: a, username: p.username ? String(p.username) : null, hubId: p.id || null, via: 'hub' } : null; };
|
||||
async function netMember(q) {
|
||||
@@ -267,6 +268,8 @@ networksso.init({ self: 'bannerline', peer: 'iap', peerBase: () => C.iapBase, fr
|
||||
accept: async (email, req, v) => (v && v.wallet ? { ok: true } : { fallback: 'no wallet in the token' }),
|
||||
signIn: async (email, req, v) => { if (v.name) netCache.set('a:' + v.wallet, { at: Date.now(), m: { address: v.wallet, username: v.name } }); return cookie('bl.sid', store.mintSession(v.wallet), store.SESSION_TTL / 1000, true); },
|
||||
landing: to => to, signinPath: to => to });
|
||||
// the hub's member.signedout / member.blocked / member.erased: that person's sessions here end (by any of their wallets)
|
||||
hubevents.init({ dataDir: C.dataDir, site: 'bannerline', end: who => store.endSessions(x => who.match(x), who.before) });
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const u = new URL(req.url, 'http://x'); const p = u.pathname;
|
||||
@@ -452,6 +455,17 @@ const server = http.createServer(async (req, res) => {
|
||||
const s = session(req); if (s) store.dropSession(s.token);
|
||||
return json(res, 200, { ok: true }, { 'Set-Cookie': [cookie('bl.sid', '', 0, true), networksso.offCookie()] }); // signed out stays signed out here for 12 hours
|
||||
}
|
||||
// "Sign out everywhere" (2026-11-16): the hub ends every network sign-in of this member and tells every hooked site; every
|
||||
// session of this wallet here ends now. Same-origin POST only (SameSite=Lax session cookie).
|
||||
if (p === '/api/auth/logout-everywhere' && req.method === 'POST') {
|
||||
const s = session(req); let hub = { ok: false };
|
||||
if (s) { hub = await networksso.signOutEverywhere(s); store.endSessions(x => x.address === s.address, Date.now() + 1000); }
|
||||
return json(res, 200, { ok: true, everywhere: !!hub.ok }, { 'Set-Cookie': [cookie('bl.sid', '', 0, true), networksso.offCookie()] });
|
||||
}
|
||||
if (p === '/api/hub/events' && req.method === 'POST') {
|
||||
let raw = ''; try { raw = (await readRaw(req, 256 * 1024)).toString('utf8'); } catch (e) { return json(res, 413, { error: 'too big' }); }
|
||||
const r = await hubevents.receive(req.headers, raw); return json(res, r.status, r.body);
|
||||
}
|
||||
if (p === '/api/me' && req.method === 'GET') {
|
||||
// username / refName (Marty 2026-11-15): the footer's network links carry a referral username, the member's own network
|
||||
// username when signed in, else the sponsor's (usernames only, never the wallet)
|
||||
@@ -537,7 +551,7 @@ const server = http.createServer(async (req, res) => {
|
||||
// -- admin (ADMIN_TOKEN header): keeper preview + index status. No key material is ever returned.
|
||||
if (p === '/api/admin/status' && req.method === 'GET') {
|
||||
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
|
||||
return json(res, 200, { index: chain.status(), totals: chain.totals(), keeper: keeper.statusInfo(), hub: hubreport.view(), hubLookup: hubpeople.view(), refuelSpots: refuelspots.view(), nas: dlbnas.view() });
|
||||
return json(res, 200, { index: chain.status(), totals: chain.totals(), keeper: keeper.statusInfo(), hub: hubreport.view(), hubLookup: hubpeople.view(), hubEvents: hubevents.view(), refuelSpots: refuelspots.view(), nas: dlbnas.view() });
|
||||
}
|
||||
|
||||
// -- admin: the network hub's member lookup (Marty 2026-11-14, read-only). GET ?q=<wallet> | <spot id>. No email lives here.
|
||||
|
||||
@@ -59,6 +59,8 @@ const SESSION_TTL = 7 * 24 * HOUR;
|
||||
function mintSession(address) { const token = crypto.randomBytes(32).toString('hex'); S.sessions[token] = { address: address.toLowerCase(), expires: Date.now() + SESSION_TTL }; touch(address); save(); return token; }
|
||||
function session(token) { const s = token && S.sessions[token]; return s && s.expires > Date.now() ? Object.assign({ token }, s) : null; }
|
||||
function dropSession(token) { delete S.sessions[token]; save(); }
|
||||
// network hub events (hubevents.js, 2026-11-16): end every session `match` names that was made before `before` -> how many
|
||||
function endSessions(match, before) { let n = 0; for (const [k, x] of Object.entries(S.sessions)) if (x.expires - SESSION_TTL <= before && match(x)) { delete S.sessions[k]; n++; } if (n) save(); return n; }
|
||||
function touch(address) { S.seen[String(address).toLowerCase()] = Date.now(); save(); }
|
||||
function lastSeen(address) { return S.seen[String(address).toLowerCase()] || 0; }
|
||||
|
||||
@@ -67,4 +69,4 @@ function keeperLog(entry) { S.keeper.log.push(Object.assign({ at: Date.now() },
|
||||
function keeperEntries() { return S.keeper.log.slice(); }
|
||||
|
||||
module.exports = { load, flush, spotMeta, setSpotMeta, memberDefault, setMemberDefault, addView, views, addClick, clicks, daily,
|
||||
mintSession, session, dropSession, touch, lastSeen, keeperLog, keeperEntries, SESSION_TTL };
|
||||
mintSession, session, dropSession, endSessions, touch, lastSeen, keeperLog, keeperEntries, SESSION_TTL };
|
||||
|
||||
Reference in New Issue
Block a user