diff --git a/README.md b/README.md index 3b817ad..6413430 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,5 @@ Tests cover protocol parsing, mail/attachments, journal, gateway validation, pro - **Script/task policy blocks execution:** review the files and your Windows policy; organisation restrictions cannot be overridden by the installer. Third-party PDF.js, font and CMap licences are retained under `public/vendor/pdfjs`; map attribution is in `public/WORLD-MAP-LICENSE.txt`. + +Packet controller integrations must acknowledge a reserved slot with `pttReady: true`, after checking that their BPQ PTT backend responds. A modem TCP connection alone is insufficient. The slot status must also contain the matching request ID, frequency, VHF phase and a fresh timestamp. Manual alternate routes share the partner queue; their native HF row is reserved during use and is not counted as a second active session. diff --git a/manual-forwarding.mjs b/manual-forwarding.mjs index abfd5b2..26df378 100644 --- a/manual-forwarding.mjs +++ b/manual-forwarding.mjs @@ -2,7 +2,7 @@ import {readFile,writeFile,rename,mkdir,copyFile} from 'node:fs/promises'; import path from 'node:path'; import {reservePacketSlot,releasePacketSlot} from './radio-slot.mjs'; import {WinlinkRadio,rawProfile,activeMailStreams} from './winlink-radio.mjs'; -import {safeScript} from './forwarding.mjs'; +import {safeScript,parseForwarding} from './forwarding.mjs'; export function manualRoutes(config){ const ids=new Set();return (config.manualForwardingRoutes||[]).map(route=>{ if(!/^[A-Z0-9-]{1,32}$/.test(route.id)||route.id===route.peer||ids.has(route.id)||! /^[A-Z0-9]{1,6}$/.test(route.peer)||! /^[A-Z0-9]{3,7}(?:-\d{1,2})?$/.test(route.connectCall)||!Number.isFinite(route.frequencyMHz)||route.frequencyMHz<1||route.frequencyMHz>500||! /^(USB|LSB|FM|DATA-FM)$/.test(route.mode)||!config.ports.some(p=>p.id===route.port&&!/TELNET|AXIP/i.test(p.driver)))throw Error('Percorso manuale di forwarding non valido'); @@ -17,6 +17,7 @@ export class ManualForwarding extends WinlinkRadio{ profiles(native){return this.routes.flatMap(route=>{const p=native.find(p=>p.call===route.peer);if(!p)return [];const j=this.job?.channel?.id===route.id?this.job:null;const history=j?p.history.filter(s=>Date.parse(s.startedAt)>=Date.parse(j.startedAt)-1500&&(!j.endedAt||Date.parse(s.startedAt)<=Date.parse(j.endedAt))):[];return [{...p,call:route.id,label:route.label,peer:route.peer,manualOnly:true,enabled:false,interval:0,immediate:false,reverseInterval:0,times:[],configured:true,port:route.port,driver:this.config.ports.find(p=>p.id===route.port)?.driver||'',transport:'Radio',frequency:[String(route.frequencyMHz),route.mode],script:safeScript(route.script),history,last:history[0]||null,active:Boolean(j?.restoring),preparing:j?.state==='preparing',requestedAt:j?.startedAt||null,nextEstimated:null}];});} async prepare(route){await reservePacketSlot(this,route.controller,route.frequencyMHz,route.port);} async release(){await releasePacketSlot(this);} + displayProfiles(native){const j=this.job;const base=native.map(p=>{if(!j||j.peer!==p.call)return p;const history=p.history.filter(s=>!(Date.parse(s.startedAt)>=Date.parse(j.startedAt)-1500&&(!j.endedAt||Date.parse(s.startedAt)<=Date.parse(j.endedAt))));const original=parseForwarding('BBSForwarding : { '+p.call+' : { '+Object.entries(j.original||{}).map(([k,v])=>k+' = "'+String(v).replaceAll('"','')+'";').join(' ')+' } }',this.config.ports)[0];return {...p,...(j.restoring?original:{}),history,last:history[0]||null,active:j.restoring?false:p.active,reservedBy:j.restoring?j.channel.id:null};});return [...base,...this.profiles(native)];} async startRoute(id){await this.init;return this.fwd.exclusive(async()=>{ const route=this.routes.find(r=>r.id===id);if(!route)throw Error('Percorso manuale non configurato'); if(this.job?.restoring||this.fwd.lockedPeers.has(route.peer))throw Error('Un inoltro per questo partner è già in corso'); diff --git a/manual-forwarding.test.mjs b/manual-forwarding.test.mjs index cc1ede2..319569a 100644 --- a/manual-forwarding.test.mjs +++ b/manual-forwarding.test.mjs @@ -37,3 +37,9 @@ test('manual forwarding shares the queue, disables timers only during use and re assert.equal(client.job.restoring,false);assert.deepEqual(rawProfile(await readFile(file,'utf8'),'N0TEST'),original);assert.equal(fw.lockedPeers.has('N0TEST'),false); }finally{clearInterval(client.timer);await rm(dir,{recursive:true,force:true});} }); + +test('a manual VHF session occupies one route and reserves its HF partner',()=>{ + const client={job:{peer:'N0TEST',channel:{id:'N0TEST-VHF'},original,startedAt:'2026-10-16T22:00:00Z',restoring:true},config:{ports:[{id:1,driver:'VARA'}]},profiles:()=>[{call:'N0TEST-VHF',active:true}]}; + const rows=ManualForwarding.prototype.displayProfiles.call(client,[{call:'N0TEST',active:true,history:[{startedAt:'2026-10-16T22:00:01Z'}]}]); + assert.equal(rows.filter(p=>p.active).length,1);assert.equal(rows[0].port,1);assert.equal(rows[0].reservedBy,'N0TEST-VHF');assert.equal(rows[0].history.length,0); +}); diff --git a/public/forwarding.js b/public/forwarding.js index b5f518d..49bc1b2 100644 --- a/public/forwarding.js +++ b/public/forwarding.js @@ -10,9 +10,9 @@ const rules=(values,kind)=>!values.length?'Nessuna regola esplicita':values.incl const bands=p=>p.times.length?p.times.map(t=>t.replace(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/,'$1:$2–$3:$4')).join(' · '):'00:00–23:59'; function render(){if(!data)return;$('#forward-restore').hidden=!(data.manualSession?.restoring&&data.manualSession?.error);const focused=document.activeElement,focusPeer=focused.closest?.('[data-forward-row]')?.dataset.forwardRow,focusKind=focused.matches?.('[data-forward-start]')?'[data-forward-start]':focused.matches?.('.forward-toggle')?'.forward-toggle':null;const profiles=[...data.profiles].sort((a,b)=>Number(b.enabled&&b.configured)-Number(a.enabled&&a.configured)||Number(b.transport==='Radio')-Number(a.transport==='Radio')||a.call.localeCompare(b.call)),total=profiles.reduce((a,p)=>a+(p.manualOnly?0:p.queued||0),0);$('#forward-summary').innerHTML=[['Percorsi',profiles.length],['Automatici',profiles.filter(p=>p.enabled&&p.configured).length],['Messaggi in coda',total+(profiles.some(p=>p.queued===null)?' + ?':'')],['Sessioni attive',profiles.filter(p=>p.active).length]].map(([label,n])=>'
'+label+''+n+'
').join('');const errors=[...data.errors,...(data.manualSession?.error?[data.manualSession.error]:[])];$('#forward-error').hidden=!errors.length;$('#forward-error').textContent=errors.join(' · ');$('#forward-updated').textContent='Aggiornato '+time(data.updatedAt)+' · '+mailTimezone(); $('#forward-partners').innerHTML='
'+profiles.map(p=>{ - const requested=pending.get(p.call),requestWaiting=requested&&Date.now()-requested<30000,blocked=p.active||requestWaiting||(p.transport==='Radio'&&(data.radio?.active||data.radio?.connecting)),last=p.last; - const status=p.active?(p.preparing?'Preparazione radio':state(last?.status)):requestWaiting?'Richiesta inviata':!p.configured?'Non configurato':p.manualOnly?'Solo manuale':p.enabled?'Automatico':'Disattivato'; - const next=p.active?'Sessione in corso':p.manualOnly?'Solo su richiesta':!p.enabled?'Automatico disattivo':!p.configured?'Script assente':p.nextEstimated?time(p.nextEstimated):!p.reverse&&p.queued===0?'In attesa di messaggi':'Timer non disponibile'; + const requested=pending.get(p.call),requestWaiting=requested&&Date.now()-requested<30000,blocked=p.reservedBy||p.active||requestWaiting||(p.transport==='Radio'&&(data.radio?.active||data.radio?.connecting)),last=p.last; + const status=p.reservedBy?'Riservato al percorso VHF':p.active?(p.preparing?'Preparazione radio':state(last?.status)):requestWaiting?'Richiesta inviata':!p.configured?'Non configurato':p.manualOnly?'Solo manuale':p.enabled?'Automatico':'Disattivato'; + const next=p.reservedBy?'Attende fine percorso VHF':p.active?'Sessione in corso':p.manualOnly?'Solo su richiesta':!p.enabled?'Automatico disattivo':!p.configured?'Script assente':p.nextEstimated?time(p.nextEstimated):!p.reverse&&p.queued===0?'In attesa di messaggi':'Timer non disponibile'; const isOpen=expanded===p.call; return ``; }).join('')+'
Partner / percorsoStatoCodaUltimo scambioTX / RXProgrammazioneProssimo · stimaAzioni
${esc(status)}${p.queued??'—'}${esc(time(last?.startedAt).replace(/:\d{2}$/,''))}${esc(last?state(last.status):'Nessuna sessione recente')}${last?last.sent+' / '+last.received:'—'}${p.manualOnly?'Solo manuale':esc(interval(p.interval))}${p.manualOnly?esc(p.frequency.join(' MHz ')):esc(bands(p))+' · '+(p.timesLocal?'locale BPQ':'UTC')}${esc(next)}${p.nextEstimated?esc(mailTimezone()):''}${p.transport==='Radio'&&(data.radio?.active||data.radio?.connecting)&&!p.active?'Modem impegnato':''}
${isOpen?details(p):''}
'+(!profiles.length?'

Nessun partner di forwarding configurato in BPQ.

':'')+'
'; diff --git a/radio-slot.mjs b/radio-slot.mjs index f13fab3..cdbd987 100644 --- a/radio-slot.mjs +++ b/radio-slot.mjs @@ -5,7 +5,7 @@ export async function reservePacketSlot(client,controller,frequencyMHz,port){ const request={id:randomUUID(),frequencyMHz,expiresAt:Date.now()+90000};client.job.controller={...controller,id:request.id};await client.persist(); await writeFile(controller.requestFile+'.tmp',JSON.stringify(request));await rename(controller.requestFile+'.tmp',controller.requestFile); const deadline=Date.now()+65000; - while(Date.now()setTimeout(resolve,300));} + while(Date.now()setTimeout(resolve,300));} throw Error('Modem packet non pronto: nessuna chiamata avviata'); } export async function releasePacketSlot(client){ diff --git a/server.mjs b/server.mjs index 849a7a4..768ae7a 100644 --- a/server.mjs +++ b/server.mjs @@ -143,7 +143,7 @@ const server=http.createServer(async(req,res)=>{ if(url.pathname==='/api/logout'&&req.method==='POST'){const token=req.headers.cookie.match(/alnode=([a-f0-9]+)/)?.[1];user.terminal?.close();sessions.delete(token);res.setHeader('Set-Cookie','alnode=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0');json(res,200,{ok:true});return;} if(url.pathname==='/api/journal'&&req.method==='GET'){json(res,200,await journal.snapshot());return;} if(url.pathname==='/api/stations/location'&&req.method==='POST'){const data=await body(req);json(res,200,await journal.saveLocation(String(data.call||''),String(data.locator||'')));return;} - if(url.pathname==='/api/forwarding'&&req.method==='GET'){const data=await forwarding.snapshot();json(res,200,{...data,manualSession:manualForwarding.snapshot(),profiles:[...data.profiles,...manualForwarding.profiles(data.profiles)]});return;} + if(url.pathname==='/api/forwarding'&&req.method==='GET'){const data=await forwarding.snapshot();json(res,200,{...data,manualSession:manualForwarding.snapshot(),profiles:manualForwarding.displayProfiles(data.profiles)});return;} if(url.pathname==='/api/forwarding/manual/restore'&&req.method==='POST'){json(res,200,await manualForwarding.restore());return;} const fwdStart=url.pathname.match(/^\/api\/forwarding\/([A-Z0-9-]{1,32})\/sync$/);if(fwdStart&&req.method==='POST'){const peer=fwdStart[1];json(res,200,manualForwarding.routes.some(r=>r.id===peer)?await manualForwarding.startRoute(peer):await forwarding.start(peer));return;} if(url.pathname==='/api/dashboard'){json(res,200,await dashboard());return;} diff --git a/winlink-radio.test.mjs b/winlink-radio.test.mjs index 1433693..f56090b 100644 --- a/winlink-radio.test.mjs +++ b/winlink-radio.test.mjs @@ -25,7 +25,7 @@ test('directory merges independent HF and Packet downloads and marks incompatibl test('packet controller reservation verifies acknowledgement and releases its own request',async()=>{ const dir=await mkdtemp(path.join(os.tmpdir(),'wl-slot-'));const controller={requestFile:path.join(dir,'request.json'),statusFile:path.join(dir,'status.json')};const urls=[]; - const client={job:{},persist:async()=>writeFile(controller.statusFile,JSON.stringify({manualRequestId:client.job.controller.id,phase:'vhf',frequency:'433.750',at:new Date().toISOString()})),fwd:{bpq:async url=>{urls.push(url);return 'Connected to TNC AFSK AX.25 1200bd';}}}; + const client={job:{},persist:async()=>writeFile(controller.statusFile,JSON.stringify({manualRequestId:client.job.controller.id,phase:'vhf',pttReady:true,frequency:'433.750',at:new Date().toISOString()})),fwd:{bpq:async url=>{urls.push(url);return 'Connected to TNC AFSK AX.25 1200bd';}}}; try{await reservePacketSlot(client,controller,433.750,3);assert.deepEqual(urls,['/Node/Port?3']);const request=JSON.parse(await readFile(controller.requestFile));assert.equal(request.frequencyMHz,433.750);assert.ok(request.expiresAt>Date.now());await releasePacketSlot(client);assert.equal(JSON.parse(await readFile(controller.requestFile)).expiresAt,0);}finally{await rm(dir,{recursive:true,force:true});} }); test('temporary RMS profile preserves routing, disables timers and never overrides busy channel',()=>{const p=radioProfile(original,channel,3);assert.equal(p.Enabled,'0');assert.equal(p.ConnectScript,'ATTACH 3|RADIO 14.122000 USB|PAUSE 2|C N0TEST');assert.ok(!p.ConnectScript.includes('OVERRIDEBUSY'));assert.equal(p.UseB2Protocol,'1');assert.equal(p.HRoutes,original.HRoutes);assert.equal(p.TOCalls,original.TOCalls);assert.deepEqual(rawProfile(configText(original),'RMS'),original);assert.equal(profilePayload(original).split('|').length,21);assert.throws(()=>radioProfile(original,{...channel,call:'N0TEST|C EVIL'},3));assert.throws(()=>radioProfile(original,{...channel,dialHz:0},3));assert.deepEqual(activeMailStreams(''),[]);assert.equal(activeMailStreams('').length,1);assert.throws(()=>activeMailStreams('signin page'));});