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.
This commit is contained in:
1 parent
33f1294405
commit
2ef3c25eb3
16 files changed
+298
-23
No files matched your search
+3
-3
@@ -19,7 +19,7 @@ import {ManualForwarding} from './manual-forwarding.mjs';
|
||||
import {forwardingHistory} from './forwarding.mjs';
|
||||
import {Forwarding} from './forwarding.mjs';
|
||||
import {SevenPlus} from './sevenplus.mjs';
|
||||
import {loadConfig,parseConfig,publicConfig,ownCall} from './config.mjs';
|
||||
import {loadConfig,parseConfig,publicConfig,ownCall,authenticateSysop} from './config.mjs';
|
||||
import {readFile, stat,open} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
@@ -68,7 +68,7 @@ function mailContext(){return mailReads.run('context',async()=>{if(mailKey&&Date
|
||||
function messages(includeTimes=true){return mailReads.run(includeTimes?'full':'quick',()=>readMessages(includeTimes));}
|
||||
async function readMessages(includeTimes=true){let {key}=await mailContext();let html=await bpq('/WebMail/WMALL?'+key);if(!html.includes('Message List')){mailKey=null;({key}=await mailContext());html=await bpq('/WebMail/WMALL?'+key);if(!html.includes('Message List'))throw new Error('Lista messaggi BPQ non disponibile');}const list=parseMessages(html).filter(m=>m.status!=='K');if(includeTimes)return messageMetadata.enrich(list);for(const m of list.filter(m=>m.type==='P'&&(m.to==='RMS'||m.needsMetadata))){const f=await messageFields(m.id);m.from=f.From||m.from;m.to=f.To||m.to;m.subject=f.Title||m.subject;m.via=f.VIA||m.via;}return list;}
|
||||
function equal(a,b){const aa=Buffer.from(a),bb=Buffer.from(b);return aa.length===bb.length&&timingSafeEqual(aa,bb);}
|
||||
async function authenticate(user,password){const users=parseConfig(await readFile(path.join(root,'BPQ32.cfg'),'utf8')).users;const found=users.find(u=>equal(u.user.toLowerCase(),user.toLowerCase())&&equal(u.password,password)&&u.user===config.sysop.user);return found?{call:found.call,name:found.user,config:publicConfig(config)}:null;}
|
||||
async function authenticate(user,password){const users=parseConfig(await readFile(path.join(root,'BPQ32.cfg'),'utf8')).users;const identity=authenticateSysop(users,user,password,config.sysopUsers);return identity?{...identity,config:publicConfig(config)}:null;}
|
||||
async function body(req){let chunks=[],size=0;for await(const chunk of req){size+=chunk.length;if(size>70000)throw new Error('Messaggio troppo grande');chunks.push(chunk)}return JSON.parse(Buffer.concat(chunks).toString()||'{}');}
|
||||
function json(res,status,data){res.writeHead(status,{'Content-Type':'application/json; charset=utf-8','Cache-Control':'no-store'});res.end(JSON.stringify(data));}
|
||||
function session(req){const token=req.headers.cookie?.match(/(?:^|;\s*)alnode=([a-f0-9]+)/)?.[1];const s=sessions.get(token);if(s&&s.expires>Date.now()){s.expires=Date.now()+8*3600000;return s;}if(token){s?.terminal?.close();sessions.delete(token);}return null;}
|
||||
@@ -203,7 +203,7 @@ const server=http.createServer(async(req,res)=>{
|
||||
if(url.pathname==='/api/winlink/sync'&&req.method==='POST'){if(Date.now()-lastCmsRequest<10000)throw new Error('Sincronizzazione già richiesta. Attendi qualche secondo.');await syncNow(config.cmsPeer||'RMS');lastCmsRequest=Date.now();json(res,200,{ok:true});return;}
|
||||
const readRoute=url.pathname.match(/^\/api\/messages\/(\d+)\/read$/);if(readRoute&&req.method==='POST'){const item=(await messages()).find(m=>m.id===Number(readRoute[1]));if(!item)throw new Error('Messaggio non disponibile');json(res,200,await messageReadState.mark(item));return;}
|
||||
if(/^\/api\/messages\/\d+\/delete$/.test(url.pathname)&&req.method==='POST'){json(res,200,await deleteMessage(Number(url.pathname.split('/')[3])));return;}
|
||||
if(/^\/api\/messages\/\d+$/.test(url.pathname)&&req.method==='GET'){const id=url.pathname.split('/').pop();const {key}=await mailContext();const msg=parseMessage(await bpq('/WebMail/WM?'+key+'&'+id));if(!msg)throw new Error('Messaggio non disponibile');try{const raw=await attachedMessage(Number(id));const text=b2Body(raw.bytes);if(text!==null)msg.text=text.replace(/\r\n|\r/g,'\n');}catch{}json(res,200,{id:Number(id),...msg,...await messageTimes(Number(id))});return;}
|
||||
if(/^\/api\/messages\/\d+$/.test(url.pathname)&&req.method==='GET'){const id=url.pathname.split('/').pop();const {key}=await mailContext();const msg=parseMessage(await bpq('/WebMail/WM?'+key+'&'+id));if(!msg)throw new Error('Messaggio non disponibile');try{const raw=await attachedMessage(Number(id));const text=b2Body(raw.bytes);if(text!==null)msg.text=text.replace(/\r\n|\r/g,'\n');}catch{}const fields=await messageFields(Number(id));json(res,200,{id:Number(id),...msg,to:fields.To||msg.to,via:fields.VIA||msg.via||'',...await messageTimes(Number(id))});return;}
|
||||
if(url.pathname==='/api/messages'&&req.method==='POST'){json(res,201,await sendMessage(await readSubmission(req)));return;}
|
||||
if(url.pathname==='/api/sync'&&req.method==='POST'){await syncNow();json(res,200,{ok:true});return;}
|
||||
json(res,404,{error:'Operazione non disponibile'});return;
|
||||
|
||||
Reference in new issue
Block a user