diagnostics: verify live DNS NAT and guest return traffic
This commit is contained in:
1 parent
be92d48ca0
commit
b854c40232
1 file changed
+16
-23
@@ -25,30 +25,23 @@ 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('DEPLOYED',JSON.stringify({directLogin:fs.readFileSync('/app/src/index.js','utf8').includes('loginPaymentAccess'),countdown:fs.readFileSync('/app/public/index.html','utf8').includes('freeAccessMessage')}));
|
||||
{
|
||||
const source=fs.readFileSync('/app/src/ros.js','utf8').replace("from './config.js'","from 'file:///app/src/config.js'").replace("else if (attr === '!done') this.done = true;","else if (attr === '!done') { this.done = true; if (words.length > 1) this.replies.push(words.slice(1)); }");
|
||||
const {rosCommand:rawRos}=await import('data:text/javascript;base64,'+Buffer.from(source).toString('base64'));
|
||||
const files=(await rawRos(['/file/print','=.proplist=.id,name,type,size'])).map(object);
|
||||
for(const suffix of ['login.html','alogin.html']){
|
||||
const f=files.find(f=>f.name==='hotspot/'+suffix||f.name==='flash/hotspot/'+suffix);
|
||||
if(!f){console.log('HOTSPOT-FILE',suffix,'missing');continue;}
|
||||
try {
|
||||
const rows=await rawRos(['/file/get','=number='+f['.id'],'=value-name=contents']);
|
||||
const content=rows.flat().find(v=>v.startsWith('=ret='))?.slice(5)||'';
|
||||
console.log('HOTSPOT-FILE',JSON.stringify({file:f.name,length:content.length,hasMacVariable:content.includes('$(mac)'),hasDstVariable:/link-redirect|link-orig|dst=/.test(content),redirectionUrls:[...new Set(content.match(/https?:[^"'<>\s]+/g)||[])]}));
|
||||
}catch(e){console.log('HOTSPOT-FILE-ERROR',suffix,redact(e.message));}
|
||||
for(const [label,words] of [
|
||||
['DNS',['/ip/dns/print','=.proplist=servers,dynamic-servers,allow-remote-requests']],
|
||||
['DHCP-NETWORK',['/ip/dhcp-server/network/print','=.proplist=address,gateway,dns-server']],
|
||||
['NAT',['/ip/firewall/nat/print','=.proplist=chain,action,disabled,comment,src-address,dst-address,out-interface,dst-port,to-addresses,to-ports,protocol']],
|
||||
['DEFAULT-ROUTE',['/ip/route/print','?dst-address=0.0.0.0/0','=.proplist=gateway,active,distance']],
|
||||
['INTERNET-PING',['/ping','=address=1.1.1.1','=count=3']],
|
||||
['TRAFFIC',['/ip/hotspot/active/print','=.proplist=mac-address,user,uptime,session-time-left,bytes-in,bytes-out,packets-in,packets-out']],
|
||||
]){
|
||||
try{console.log(label,redact(JSON.stringify((await rosCommand(words)).map(object))));}
|
||||
catch(e){console.log(label+'-ERROR',redact(e.message));}
|
||||
}
|
||||
}
|
||||
{
|
||||
const hosts=(await rosCommand(['/ip/hotspot/host/print','=.proplist=address,mac-address,server,authorized,bypassed'])).map(object).filter(h=>h.server===config.mikrotik.server && h.authorized!=='true' && h.bypassed!=='true');
|
||||
if(hosts.length!==1){console.log('LIVE-TEST-SKIPPED','Expected exactly one unauthenticated device, found '+hosts.length);}
|
||||
else {
|
||||
const h=hosts[0];const mac=h['mac-address'];
|
||||
const response=await fetch('http://127.0.0.1:'+config.port+'/api/access/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({mac})});
|
||||
const d=await response.json();
|
||||
console.log('LIVE-ACCESS-RESPONSE',redact(JSON.stringify({device:hash(mac),status:response.status,ok:d.ok,authenticated:d.authenticated,seconds:d.seconds,expiresAt:d.expiresAt,fallbackAvailable:!!d.loginUrl,error:d.error,retryAfterSeconds:d.retryAfterSeconds})));
|
||||
const active=(await rosCommand(['/ip/hotspot/active/print','?mac-address='+mac,'=.proplist=user,server,uptime,session-time-left'])).map(object);
|
||||
console.log('LIVE-DEVICE-ACTIVE',JSON.stringify(active.map(a=>({...a,user:a.user?'account-'+hash(a.user):undefined}))));
|
||||
const hosts=(await rosCommand(['/ip/hotspot/host/print','=.proplist=address,mac-address,server,authorized,bypassed'])).map(object).filter(h=>h.server===config.mikrotik.server);
|
||||
const connections=(await rosCommand(['/ip/firewall/connection/print','=.proplist=src-address,dst-address,seen-reply,protocol,tcp-state'])).map(object);
|
||||
for(const h of hosts){
|
||||
const c=connections.filter(c=>(c['src-address']||'').split(':')[0]===h.address);
|
||||
const internet=c.filter(c=>!/^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(c['dst-address']||''));
|
||||
console.log('DEVICE-TRAFFIC-SUMMARY',JSON.stringify({device:hash(h['mac-address']),authorized:h.authorized,connections:c.length,internetConnections:internet.length,internetWithReplies:internet.filter(c=>c['seen-reply']==='true').length,dnsWithReplies:internet.filter(c=>(c['dst-address']||'').endsWith(':53')&&c['seen-reply']==='true').length}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user