Files
bpq_gui/bpq.mjs
T
alberto 2ef3c25eb3 Support multiple sysops and bulletin comments; complete UI translations
Allow native SYSOP accounts to sign in independently, with an optional sysopUsers allow-list and isolated browser sessions. Keep station services on the configured service account.

Add public bulletin comments that preserve category and distribution, alongside private replies to the author. Complete APRS and dynamic status translations and handle decorated button labels correctly.

Document configuration and reply behavior. Add authentication, installer, bulletin reply and translation regression coverage.
2026-10-19 13:04:39 +02:00

8 lines
3.5 KiB
JavaScript

export function decode(s){return s.replace(/&#(\d+);/g,(_,n)=>String.fromCodePoint(Number(n))).replace(/&#x([a-f\d]+);/gi,(_,n)=>String.fromCodePoint(parseInt(n,16))).replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"').replace(/&#39;|&apos;/g,"'").replace(/&nbsp;/g,' ').replace(/&amp;/g,'&');}
export function plain(html){return decode(html.replace(/<script[\s\S]*?<\/script>/gi,'').replace(/<style[\s\S]*?<\/style>/gi,'').replace(/<[^>]+>/g,' ')).replace(/\s+/g,' ').trim();}
export function parseMessages(html){const result=[];const regex=/<a\s+href=\/WebMail\/WM\?[^>&\s]+&(\d+)>[^<]+<\/a>([^\r\n<]+)/gi;for(const m of html.matchAll(regex)){const line=m[2];const a=line.match(/^\s*(\S+)\s+([BPT])([A-Z$])\s+(\d+)\s(.{7})\s(.{7})\s(.{7})(.*)$/);if(a){result.push({id:Number(m[1]),date:a[1],type:a[2],status:a[3],size:Number(a[4]),to:a[5].trim(),via:a[6].trim(),from:a[7].trim(),subject:decode(a[8].trim())});continue;}const header=line.match(/^\s*(\S+)\s+([BPT])([A-Z$])\s+(\d+) (.{8})(.*)$/);if(!header)continue;const tail=header[6].match(/^(.*?)([A-Z0-9]{1,6}) {2,}(.*)$/);if(tail)result.push({id:Number(m[1]),date:header[1],type:header[2],status:header[3],size:Number(header[4]),to:header[5].trim(),via:tail[1].trim(),from:tail[2],subject:decode(tail[3].trim()),needsMetadata:true});}return result;}
export function parseRoutes(html){return [...html.matchAll(/<tr>([\s\S]*?)<\/tr>/gi)].flatMap(m=>{const cells=[...m[1].matchAll(/<td[^>]*>([\s\S]*?)<\/td>/gi)].map(c=>plain(c[1]));if(cells.length<12)return [];return [{port:cells[0].replace('>',''),active:cells[0].startsWith('>'),call:cells[1],quality:Number(cells[2]),nodes:Number(cells[3]),frames:Number(cells[4]),retries:Number(cells[5]),heard:cells[9],queued:Number(cells[10])}];});}
export function parseMessage(html){const m=html.match(/<textarea[^>]*>([\s\S]*?)<\/textarea>/i);if(!m)return null;const text=decode(m[1]).replace(/\r\n|\r/g,'\n');const header={},first=text.indexOf('\n\n');for(const l of text.slice(0,first).split('\n')){const sep=l.indexOf(':');if(sep>0)header[l.slice(0,sep)]=l.slice(sep+1).trim();}return {from:header.From||'',to:header.To||'',via:header.Via||header.VIA||'',subject:header.Title||'',date:header['Date/Time']||'',bid:header.Bid||'',type:header['Type/Status']?.[0]||'',text:first>=0?text.slice(first+2):text};}
export function bpqTimestamp(value,reference=new Date()) {const m=String(value||'').match(/^(\d{1,2})-([A-Za-z]{3})\s+(\d{2}):(\d{2})Z$/);if(!m)return null;const month=['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'].indexOf(m[2].toLowerCase());if(month<0||Number(m[1])>31||Number(m[3])>23||Number(m[4])>59)return null;let year=reference.getUTCFullYear();let date=new Date(Date.UTC(year,month,Number(m[1]),Number(m[3]),Number(m[4])));if(date.getTime()>reference.getTime()+86400000)date=new Date(Date.UTC(--year,month,Number(m[1]),Number(m[3]),Number(m[4])));if(date.getUTCMonth()!==month||date.getUTCDate()!==Number(m[1]))return null;return date.toISOString();}
export function parseRadio(html){const t=plain(html);return {connected:/Connected to .*?(?:TNC|Modem)|Comms State Connected/i.test(t),state:t.match(/TNC State\s+(.*?)(?=Mode\b|Channel\b|Traffic\b|$)/)?.[1]?.trim()||'Free',busy:t.includes('Channel State Busy'),mode:t.match(/Mode (\S+)/)?.[1]||'',snr:t.match(/S\/N ([\d,.-]+)/)?.[1]||'—',sent:Number(t.match(/Traffic Sent (\d+)/)?.[1]||0),received:Number(t.match(/RXed (\d+)/)?.[1]||0),frequency:t.match(/\b(\d+\.\d+)\s+(?:USB|LSB|FM|DIG|DATA)\b/)?.[1]||'—',scanning:/\b\d+\.\d+\s+(?:USB|LSB|FM|DIG|DATA)\s+S\b/.test(t)};}