21 lines
2.8 KiB
JavaScript
21 lines
2.8 KiB
JavaScript
process.on('uncaughtException',e=>{console.error('Installazione interrotta: '+e.message);process.exit(1)});
|
|
import {readFile,writeFile} from 'node:fs/promises';
|
|
import http from 'node:http';import path from 'node:path';import {fileURLToPath} from 'node:url';import {parseConfig} from './config.mjs';
|
|
const dir=path.dirname(fileURLToPath(import.meta.url)),args=process.argv.slice(2),arg=n=>{const i=args.indexOf('--'+n);return i>=0?args[i+1]:undefined};
|
|
const root=arg('bpq-root')||path.join(process.env.APPDATA||'','BPQ32');
|
|
const detected=parseConfig(await readFile(path.join(root,'BPQ32.cfg'),'utf8'));
|
|
if(!detected.users.length)throw new Error('Configurare un USER Telnet sysop in BPQ32.cfg');
|
|
const port=Number(arg('port')||8090),httpPort=Number(arg('http-port')||detected.httpPort);
|
|
if(!Number.isInteger(port)||port<1024||port>65535||!httpPort)throw new Error('Porte non valide o HTTPPORT BPQ assente');
|
|
await new Promise((resolve,reject)=>{const req=http.get({host:'127.0.0.1',port:httpPort,path:'/Node/Ports.html',headers:{Connection:'close'}},res=>{let text='';res.on('data',b=>text+=b);res.on('end',()=>res.statusCode===200&&/BPQ|Ports/i.test(text)?resolve():reject(new Error('Il server HTTP non conferma BPQ')))});req.setTimeout(8000,()=>req.destroy(new Error('BPQ non risponde: avviare BPQ e verificare HTTPPORT')));req.on('error',()=>reject(new Error('BPQ non raggiungibile: avviare BPQ e verificare HTTPPORT')))});
|
|
let previous={};try{previous=JSON.parse(await readFile(path.join(dir,'console.config.json'),'utf8'))}catch{}
|
|
const radioPort=Number(arg('radio-port')||previous.radioPort)||detected.radioPorts[0]?.id||null;
|
|
if(radioPort&&!detected.radioPorts.some(p=>p.id===radioPort))throw new Error('Porta radio selezionata non rilevata');
|
|
const sysopUser=arg('sysop-user')||previous.sysopUser||detected.users[0].user;
|
|
if(!detected.users.some(u=>u.user===sysopUser))throw new Error('Utente sysop non rilevato');
|
|
let peers=[];try{const mail=await readFile(path.join(root,'BPQMailChat','BPQMail.cfg'),'utf8');const forward=mail.split(/BBSForwarding\s*:/i)[1]?.split(/BBSUsers\s*:/i)[0]||'';peers=[...forward.matchAll(/^\s{2}([A-Z0-9-]+)\s*:/gm)].map(m=>m[1]);}catch{}
|
|
const config={nodeExe:process.execPath,bpqRoot:root,httpPort,port,radioPort,sysopUser,forwardPeer:arg('forward-peer')||previous.forwardPeer||'',cmsPeer:'RMS',varaSyslogPort:18514};
|
|
if(config.forwardPeer&&!peers.includes(config.forwardPeer))throw new Error('Profilo forwarding selezionato non rilevato');
|
|
console.log(JSON.stringify({bpq:'in esecuzione, HTTP verificato',nodeCall:detected.nodeCall,ports:detected.ports,services:detected.apps.map(a=>a.command),forwardProfiles:peers,selectedRadio:radioPort,sysopUser},null,2));
|
|
if(!args.includes('--check-only')){await writeFile(path.join(dir,'console.config.json'),JSON.stringify(config,null,2)+'\n');console.log('Configurazione salvata senza password.');}
|