fix: align legacy walled garden destination with verified ZimaOS portal

This commit is contained in:
jfeng committed 2026-10-22 16:12:16 +00:00
1 parent d12005d588
commit 228afc59ce
1 file changed
+12 -2
+12 -2
View File
@@ -25,5 +25,15 @@ 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));}
console.log('WALLED-GARDEN',redact(JSON.stringify((await rosCommand(['/ip/hotspot/walled-garden/ip/print','=.proplist=.id,server,dst-address,dst-port,protocol,action,comment,disabled'])).map(object))));
console.log('CLIENT-PROBES',JSON.stringify((JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8')).tempAccess||[]).map(t=>({device:hash(t.mac),expiresAt:t.expiresAt,clientProbe:t.clientProbe||null}))));
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}));
}
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');