Add connection journal with service traffic details and interactive offline station map

This commit is contained in:
alberto committed 2026-10-15 23:17:44 +02:00
1 parent 78839f5bb4
commit 106b04d631
14 files changed
+168 -7

No files matched your search

+11 -1
View File
@@ -55,7 +55,7 @@ test('generic PACTOR station runs without VARA, chat, monitor or BBS',async()=>{
try{
await new Promise((resolve,reject)=>{const timeout=setTimeout(()=>reject(new Error('Server fixture timeout')),8000);child.stdout.once('data',()=>{clearTimeout(timeout);resolve()});child.once('exit',code=>{clearTimeout(timeout);reject(new Error('Server fixture exited '+code))})});
const base='http://127.0.0.1:18991';const login=await fetch(base+'/api/login',{method:'POST',headers:{Origin:base,'Content-Type':'application/json'},body:JSON.stringify({user:'admin',password:'fixture'})});assert.equal(login.status,200);const user=await login.json();assert.equal(user.call,'N9DEMO');assert.equal(user.config.features.vara,false);assert.equal(user.config.features.bbs,false);assert.equal(user.config.radio.id,3);assert.equal(JSON.stringify(user.config).includes('fixture'),false);
const headers={Cookie:login.headers.get('set-cookie').split(';')[0]};assert.equal((await fetch(base+'/api/chat',{headers})).status,409);assert.equal((await fetch(base+'/api/monitor',{headers})).status,409);assert.equal((await fetch(base+'/api/winlink',{headers})).status,409);
const headers={Cookie:login.headers.get('set-cookie').split(';')[0]};const logbook=await fetch(base+'/api/journal',{headers});assert.equal(logbook.status,200);assert.deepEqual((await logbook.json()).sessions,[]);const denied=await fetch(base+'/api/stations/location',{method:'POST',headers:{...headers,Origin:base,'Content-Type':'application/json'},body:JSON.stringify({call:'N3TEST',locator:'JN45NN'})});assert.equal(denied.status,403);assert.equal((await fetch(base+'/api/chat',{headers})).status,409);assert.equal((await fetch(base+'/api/monitor',{headers})).status,409);assert.equal((await fetch(base+'/api/winlink',{headers})).status,409);
await new Promise(r=>setTimeout(r,1200));const telemetry=await (await fetch(base+'/api/telemetry',{headers})).json();assert.equal(telemetry.current.available,true);assert.equal(telemetry.current.nativeRate.listening,false);assert.equal(telemetry.current.varaCpu,null);assert.equal(telemetry.current.sent,12);
const dash=await (await fetch(base+'/api/dashboard',{headers})).json();assert.equal(dash.counts.messages,0);
}finally{child.kill();await new Promise(r=>child.once('exit',r));await new Promise(r=>upstream.close(r));await fs.rm(tmp,{recursive:true,force:true});}
@@ -65,3 +65,13 @@ test('generic own-call handling accepts SSIDs without station constants',()=>{as
test('configuration detects a Telnet-only node without inventing a modem',async()=>{const {parseConfig}=await import('./config.mjs');const c=parseConfig('NODECALL=N8TEST-7\nPORT\nDRIVER=Telnet.dll\nPORTNUM=2\nHTTPPORT=8088\nTCPPORT=9000\nENDPORT');assert.equal(c.httpPort,8088);assert.equal(c.telnetPort,9000);assert.deepEqual(c.radioPorts,[]);assert.equal(c.call,'N8TEST');});
test('empty modem state after restart remains idle',()=>{assert.equal(parseRadio('Comms State Connected to VARA TNC TNC State Mode Channel State Clear').state,'Free');});
test('journal locator conversion validates grid precision and distance',async()=>{const {locatorPosition,distanceKm}=await import('./journal.mjs');const a=locatorPosition('JN45NN');assert.ok(Math.abs(a.lat-45.56)<.03);assert.ok(Math.abs(a.lon-9.12)<.05);assert.equal(locatorPosition('ZZ99ZZ'),null);assert.equal(locatorPosition('JN45NN00').locator,'JN45NN00');assert.equal(distanceKm(a,a),0);assert.ok(distanceKm(a,locatorPosition('IM75IV'))>1500);});
test('journal merges VARA traffic and BBS messages without duplicating session',async()=>{const {parseVaraLog,parseBbsLog,mergeSessions}=await import('./journal.mjs');const radio=parseVaraLog('2026-10-15 12:00:00 ->CONNECT N0TEST-11 N1TEST-8\n2026-10-15 12:00:10 <-CONNECTED N0TEST-11 N1TEST-8 2300\n2026-10-15 12:01:00 N1TEST-8 Average S/N: 12,3 dB\n2026-10-15 12:01:00 Disconnected TX: 127 Bytes (Max: 270 bps) RX: 3180 Bytes (Max: 500 bps)');const bbs=parseBbsLog('261015 12:00:00 |N1TEST Connecting to BBS N1TEST\n261015 12:00:00 >N1TEST ATTACH 3\n261015 12:00:00 >N1TEST RADIO 14.100 USB\n261015 12:00:30 |N1TEST Uncompressing Message Comp Len 300 Msg Len 800 CRC abcd\n261015 12:00:31 ?N1TEST Msg 20 Routing Trace To WX Via WW\n261015 12:00:59 <N1TEST FQ\n261015 12:01:00 |N1TEST N1TEST Disconnected');const out=mergeSessions(bbs,radio,[]);assert.equal(out.length,1);assert.equal(out[0].service,'BBS');assert.equal(out[0].status,'complete');assert.equal(out[0].txBytes,127);assert.equal(out[0].rxBytes,3180);assert.equal(out[0].receivedMessages,1);assert.equal(out[0].messages[0].id,20);assert.equal(out[0].duration,50);assert.equal(out[0].frequency,14.1);assert.equal(out[0].port,3);assert.equal(out[0].snr,12.3);});
test('journal recognizes incoming Winlink and keeps CMS counters separate',async()=>{const {parseVaraLog,parseCmsLog,mergeSessions}=await import('./journal.mjs');const radio=parseVaraLog('2026-10-15 12:00:00 Incoming connection...\n2026-10-15 12:00:05 N2TEST connected VARA HF v4.9.0\n2026-10-15 12:01:00 Disconnected TX: 100 Bytes (Max: 270 bps) RX: 200 Bytes (Max: 270 bps)','VARA','N0TEST');const cms=parseCmsLog('12:00:10 15 N2TEST Connected to CMS\n12:00:59 15 Disconnected. Bytes Sent = 80 Bytes Received 50 Time 49 Seconds','2026-10-15','N0TEST');const list=mergeSessions([],radio,cms);assert.equal(list.length,1);assert.equal(list[0].service,'Winlink');assert.equal(list[0].direction,'incoming');assert.equal(list[0].txBytes,100);assert.equal(list[0].cmsTraffic.txBytes,80);});
test('journal never exposes credentials or mail/chat text from raw logs',async()=>{const {parseBbsLog,parseCmsLog}=await import('./journal.mjs');const log='261015 12:00:00 |RMS Connecting to BBS RMS\n261015 12:00:01 >RMS ;PR: secret-fixture\n261015 12:00:02 <RMS private-message-fixture\n261015 12:00:04 |RMS RMS Disconnected';const out=JSON.stringify(parseBbsLog(log));assert.equal(out.includes('secret-fixture'),false);assert.equal(out.includes('private-message-fixture'),false);const cms=parseCmsLog('23:59:00 15 N0TEST-11 Connected to CMS\n23:59:20 15 Disconnected. Bytes Sent = 12 Bytes Received 13 Time 20 Seconds','2026-10-15','N0TEST');assert.equal(cms[0].call,'CMS');assert.equal(cms[0].transport,'Internet');assert.equal(cms[0].endedAt,'2026-10-15T23:59:20Z');});
test('journal keeps simultaneous rejected inbound and successful outbound calls separate',async()=>{const {parseVaraLog,parseBbsLog,mergeSessions}=await import('./journal.mjs');const radio=parseVaraLog('2026-10-15 12:00:02 ->CONNECT N0TEST-11 N1TEST-8\n2026-10-15 12:00:20 <-CONNECTED N0TEST-11 N1TEST-8 2300\n2026-10-15 12:01:00 Disconnected TX: 10 Bytes (Max: 270 bps) RX: 20 Bytes (Max: 270 bps)');const bbs=parseBbsLog('261015 12:00:00 |N1TEST Connecting to BBS N1TEST\n261015 12:00:02 |N1TEST-8 Incoming Connect from N1TEST\n261015 12:00:03 >N1TEST-8 Already Connected\n261015 12:00:04 |N1TEST-8 N1TEST-8 Disconnected\n261015 12:00:20 <N1TEST *** Connected to N1TEST-8\n261015 12:00:59 <N1TEST FQ\n261015 12:01:00 |N1TEST N1TEST Disconnected');const list=mergeSessions(bbs,radio,[]);assert.equal(list.length,2);assert.equal(list.find(s=>s.direction==='incoming').status,'failed');assert.equal(list.find(s=>s.direction==='outgoing').txBytes,10);assert.equal(list.find(s=>s.direction==='outgoing').status,'complete');});
test('journal saves locators only for observed stations and validates input',async()=>{const {Journal}=await import('./journal.mjs');const fs=await import('node:fs/promises'),path=await import('node:path'),os=await import('node:os');const tmp=await fs.mkdtemp(path.join(os.tmpdir(),'bpq-journal-test-'));try{await fs.mkdir(path.join(tmp,'Logs'));const now=new Date(),date=now.toISOString().slice(0,10).replaceAll('-','');await fs.writeFile(path.join(tmp,'Logs','CMSAccess_'+date+'.log'),'12:00:00 15 N3TEST Connected to CMS\n12:01:00 15 Disconnected. Bytes Sent = 1 Bytes Received 2 Time 60 Seconds');const j=new Journal({root:tmp,sysop:{call:'N0TEST'},nodeCall:'N0TEST-7',locator:'JN45NN'},tmp);await assert.rejects(j.saveLocation('N3TEST','ZZ99ZZ'));await assert.rejects(j.saveLocation('N4OTHER','JN45NN'));const d=await j.saveLocation('N3TEST','JN46LB');assert.equal(d.stations[0].position.locator,'JN46LB');assert.ok(d.stations[0].distance>0);assert.equal(JSON.parse(await fs.readFile(path.join(tmp,'station-locations.json'),'utf8')).N3TEST.locator,'JN46LB');}finally{await fs.rm(tmp,{recursive:true,force:true})}});