diff --git a/backend/diagnose-hotspot.mjs b/backend/diagnose-hotspot.mjs index 690c8d5..0f3cde0 100644 --- a/backend/diagnose-hotspot.mjs +++ b/backend/diagnose-hotspot.mjs @@ -25,15 +25,14 @@ try { console.log('TEMP-RECORDS',JSON.stringify((db.tempAccess||[]).map(t=>({device:hash(t.mac),createdAt:t.createdAt,expiresAt:t.expiresAt,revoked:t.revoked})))); } catch(e){console.log('DB-ERROR',redact(e.message));} -const rows=(await rosCommand(['/ip/hotspot/walled-garden/ip/print','=.proplist=.id,dst-address,dst-port,protocol,action,comment,disabled'])).map(object); -const targets=rows.filter(r=>r.comment==='pix: portal pagamento'&&r.action==='accept'&&r.protocol==='tcp'&&r['dst-port']==='3000'); -if(targets.length>1)throw new Error('Ambiguous legacy portal walled garden rules'); -if(targets.length===1){ - const old=targets[0];const file=config.dataDir+'/walled-garden-before-port-fix-'+Date.now()+'.json'; - fs.writeFileSync(file,JSON.stringify(old,null,2),{mode:0o600});if(process.getuid?.()===0)fs.chownSync(file,1000,1000); - await rosCommand(['/ip/hotspot/walled-garden/ip/set','=numbers='+old['.id'],'=dst-address=192.168.3.100','=dst-port=8905']); - console.log('WALLED-GARDEN-FIX',JSON.stringify({id:old['.id'],previousAddress:old['dst-address'],previousPort:old['dst-port'],address:'192.168.3.100',port:'8905',backup:file})); +console.log('DEPLOYMENT-OBSERVATION',JSON.stringify({clientProbesInstalled:fs.readFileSync('/app/public/index.html','utf8').includes('verifyClientInternet'),startOnPixInstalled:fs.readFileSync('/app/public/index.html','utf8').includes("sessionStorage.setItem('pendingPix'")})); +const database=JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8')); +console.log('CLIENT-OBSERVATIONS',JSON.stringify((database.tempAccess||[]).map(t=>({device:hash(t.mac),expiresAt:t.expiresAt,probe:t.clientProbe||null})))); +const garden=(await rosCommand(['/ip/hotspot/walled-garden/ip/print','=.proplist=comment,dst-address,dst-port,protocol,disabled'])).map(object).filter(r=>r.comment==='pix: portal pagamento'); +console.log('LOCAL-PORTAL-EXCEPTION',JSON.stringify(garden)); +for(const hostname of ['www.gstatic.com','www.apple.com']){ + try { + const result=(await rosCommand(['/ping','=address='+hostname,'=count=1'])).map(object); + console.log('ROUTER-DNS-TEST',JSON.stringify({hostname,resolved:result.some(r=>/^[0-9a-f:.]+$/i.test(r.host||'')),received:result.at(-1)?.received||'0'})); + }catch(e){console.log('ROUTER-DNS-ERROR',hostname,redact(e.message));} } -const verify=(await rosCommand(['/ip/hotspot/walled-garden/ip/print','=.proplist=.id,dst-address,dst-port,protocol,action,comment,disabled'])).map(object).filter(r=>r.comment==='pix: portal pagamento'); -console.log('WALLED-GARDEN-VERIFIED',JSON.stringify(verify)); -if(!verify.some(r=>r['dst-address'].replace('/32','')==='192.168.3.100'&&r['dst-port']==='8905'))throw new Error('Local portal walled garden verification failed');