diagnostics: exercise temporary access for the single unauthenticated guest
This commit is contained in:
1 parent
8962de008e
commit
be92d48ca0
1 file changed
+28
@@ -24,3 +24,31 @@ try {
|
|||||||
const db=JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8'));
|
const db=JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8'));
|
||||||
console.log('TEMP-RECORDS',JSON.stringify((db.tempAccess||[]).map(t=>({device:hash(t.mac),createdAt:t.createdAt,expiresAt:t.expiresAt,revoked:t.revoked}))));
|
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));}
|
} 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));}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
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}))));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user