Launch prep: /health + Dockerfile HEALTHCHECK; old site links (/?<old username>, /splashpg.php?pid=N&r=, /lcp.php?pid=N&r= -> /?ref=<network username> from the oldrefs.json MySQL document, loaded by POST /api/admin/oldrefs; any other *.php -> /), checked before any page; hubreport.js (DLB pattern): each VBBShop purchase reported to the network hub by wallet, first as contract-bind with the sponsor, later as contract-spend, signed as vbb, off unless HUB_ENABLED; compose passes HUB_* + RPC_URLS + CHAIN_ID. Smoke 134/134

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 08:03:26 -06:00
parent 07cc1944e6
commit be9de262db
6 changed files with 159 additions and 3 deletions
+33 -1
View File
@@ -19,6 +19,7 @@ const loop = require('./loop');
const safety = require('./safety');
const networksso = require('./networksso');
const shop = require('./shop');
const hubreport = require('./hubreport'); // network hub report by wallet (off unless HUB_ENABLED)
const PUB = path.join(__dirname, 'public');
const UPL = path.join(C.dataDir, 'uploads');
@@ -163,6 +164,26 @@ networksso.init({ self: 'vbb', peer: 'iap', peerBase: () => C.iapBase, from: { i
},
landing: to => to, signinPath: to => to });
// old site links (2026-11-14, the Downline Banners pattern): the old YFW site's referral links were /?<old username>,
// /splashpg.php?pid=N&r=<old username> and /lcp.php?pid=N&r=<old username>. An old username maps to the same person's network
// username (oldrefs.json, a MySQL document loaded by POST /api/admin/oldrefs, matched by email); any other *.php page goes home.
let oldRefs = { at: 0, map: {} };
function oldRefMap() {
if (Date.now() - oldRefs.at < 60000) return oldRefs.map;
let m = {}; try { m = JSON.parse(fs.readFileSync(path.join(C.dataDir, 'oldrefs.json'), 'utf8')) || {}; } catch (e) {}
oldRefs = { at: Date.now(), map: m }; return m;
}
function oldLink(u) {
const p = u.pathname;
const bare = u.search.slice(1).split('&')[0];
if (p === '/' || p === '/index.php') { if (!/^[A-Za-z0-9_.-]{2,40}$/.test(bare)) return p === '/' ? null : '/'; } // "&fbclid=..." may follow
else if (!/\.php$/i.test(p)) return null;
const lp = p.toLowerCase();
const old = (lp === '/splashpg.php' || lp === '/lcp.php') ? String(u.searchParams.get('r') || '') : (lp === '/' || lp === '/index.php') ? bare : '';
const net = /^[A-Za-z0-9_.-]{2,40}$/.test(old) ? oldRefMap()[old.toLowerCase()] : null;
return net ? '/?ref=' + encodeURIComponent(net) : '/';
}
const PAGES = { '/': 'index.html', '/my': 'my.html', '/leaders': 'leaders.html', '/how': 'how.html', '/packages': 'packages.html', '/admin': 'admin.html' };
const challenges = new Map();
const clickSeen = new Map();
@@ -175,6 +196,8 @@ const server = http.createServer(async (req, res) => {
if (req.method === 'GET' && (p.startsWith('/sso/') || p === '/api/sso/status') && await networksso.handle(req, res, u)) return;
if (req.method === 'GET' || req.method === 'HEAD') {
if (p === '/health') return json(res, 200, { ok: true, store: docstore.isOn() ? 'mysql' : 'files' });
{ const to = oldLink(u); if (to) { res.writeHead(301, { Location: to, 'Cache-Control': 'no-store' }); return res.end(); } } // before any page
if (PAGES[p]) {
const ex = {};
const ref = u.searchParams.get('ref');
@@ -343,7 +366,15 @@ const server = http.createServer(async (req, res) => {
queue: { length: S.queue.length, next: S.queue.slice(0, 20) }, progress: S.progress, held: S.progress >= C.perShift && !S.queue.length,
today: { visits: t.visits || 0, shifts: t.shifts || 0, cycles: t.cycles || 0, posts: t.posts || 0, clicks: t.clicks || 0 },
totals: S.totals, ledger: { entries: L.length, views: L.reduce((x, e) => x + e.views, 0), viewsByStatus: byStatus, credited: 0 },
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), docstore: docstore.view() });
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), hub: hubreport.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
}
// old username -> network username map for the old-link redirects: { oldrefs: { old: network } } replaces the whole map
if (p === '/api/admin/oldrefs' && req.method === 'POST') {
let b; try { b = JSON.parse((await readRaw(req, 4 * 1024 * 1024)).toString('utf8')); } catch (e) { return json(res, 400, { error: 'bad json' }); }
if (!b || !b.oldrefs || typeof b.oldrefs !== 'object') return json(res, 400, { error: 'oldrefs object required' });
const o = {}; for (const [k, v] of Object.entries(b.oldrefs)) if (/^[a-z0-9_.-]{2,40}$/.test(k) && NAME_RE.test(String(v))) o[k] = String(v);
fs.writeFileSync(path.join(C.dataDir, 'oldrefs.json'), JSON.stringify(o)); oldRefs = { at: 0, map: {} };
return json(res, 200, { ok: true, total: Object.keys(o).length, skipped: Object.keys(b.oldrefs).length - Object.keys(o).length });
}
if (p === '/api/admin/ledger' && req.method === 'GET') {
const n = Math.min(2000, Math.max(1, Number(u.searchParams.get('n')) || 200)); const L = store.ledger();
@@ -373,6 +404,7 @@ function saveUpload(owner, buf, ext) {
store.load();
loop.init({ onCycle: (b, e) => console.log('cycle', 'banner #' + b.id, e.views + ' network views recorded') });
store.pruneVisits(); loop.rebuildIndex();
hubreport.init({ dataDir: C.dataDir, purchases: () => Object.entries((store.state() || {}).purchases || {}).map(([key, x]) => Object.assign({ key }, x)) });
shop.init(C); // inert without CONTRACT_ADDRESS + CHAIN_RPC (watcher) / KEEPER_KEY (vouchers)
setInterval(() => { if (store.pruneVisits()) loop.rebuildIndex(); }, 3600000).unref();
server.listen(C.port, () => console.log('Viral Banner Blitz on :' + C.port + ' loop ' + C.loopSize + ', ' + C.perShift + ' visitors per shift, store: ' + (docstore.isOn() ? 'MySQL documents' : 'files (prototype mode)')));