- Export Lista
- Ordinamento - PDF Risolto Salvataggio ed invio al server direttamente.
This commit is contained in:
@@ -72,6 +72,7 @@ const catalogo = new Schema(
|
||||
indebug: { type: Boolean },
|
||||
maxnumlibri: { type: Number },
|
||||
showListaArgomenti: { type: Boolean},
|
||||
showListaCollane: { type: Boolean},
|
||||
|
||||
first_page: IDimensioni,
|
||||
last_page: IDimensioni,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2,13 +2,12 @@ require('./config/config');
|
||||
|
||||
// console.log(" lodash");
|
||||
|
||||
console.log("VERSIONE NODE.JS :", process.versions.node);
|
||||
console.log('VERSIONE NODE.JS :', process.versions.node);
|
||||
if (process.env.AUTH_MONGODB === undefined) {
|
||||
console.error("AUTH_MONGODB non presente. VARIABILI D'AMBIENTE NON SETTATI!");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
const _ = require('lodash');
|
||||
// console.log(" cors");
|
||||
const cors = require('cors');
|
||||
@@ -42,7 +41,6 @@ const path = require('path');
|
||||
const cron = require('node-cron');
|
||||
console.log('Starting mongoose...');
|
||||
|
||||
|
||||
// console.log('Starting pem...');
|
||||
|
||||
// const pem = require('pem')
|
||||
@@ -88,8 +86,7 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
const printf = require('util').format;
|
||||
|
||||
myLoad().then(ris => {
|
||||
|
||||
myLoad().then((ris) => {
|
||||
const { User } = require('./models/user');
|
||||
|
||||
require('./models/todo');
|
||||
@@ -147,6 +144,9 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
app.use(express.static('views'));
|
||||
|
||||
app.use(express.json({ limit: '100mb' }));
|
||||
app.use(express.urlencoded({ extended: true, limit: '100mb' }));
|
||||
|
||||
// app.use(express.static(path.join(__dirname, 'client')));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
@@ -162,8 +162,8 @@ connectToDatabase(connectionUrl, options)
|
||||
// cookie: 'cook',
|
||||
directory: __dirname + '/locales',
|
||||
api: {
|
||||
'__': 'translate',
|
||||
'__n': 'translateN'
|
||||
__: 'translate',
|
||||
__n: 'translateN',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -173,14 +173,12 @@ connectToDatabase(connectionUrl, options)
|
||||
// res.sendFile(path.join(__dirname, 'service-worker.js')); // Modifica il percorso secondo la tua struttura
|
||||
});*/
|
||||
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// app.use(express.cookieParser());
|
||||
app.use(i18n.init);
|
||||
|
||||
console.log('Use Routes \...');
|
||||
|
||||
console.log('Use Routes ...');
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
// app.use(function (req, res, next) {
|
||||
@@ -195,7 +193,6 @@ connectToDatabase(connectionUrl, options)
|
||||
// development error handler
|
||||
// will print stacktrace
|
||||
if (app.get('env') === 'development') {
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
console.log('Server Error: ', err.message);
|
||||
// console.trace();
|
||||
@@ -205,16 +202,13 @@ connectToDatabase(connectionUrl, options)
|
||||
// error: err
|
||||
// });
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
console.log('*** PRODUCTION! ');
|
||||
}
|
||||
|
||||
if ((process.env.NODE_ENV === 'production') ||
|
||||
(process.env.NODE_ENV === 'test')) {
|
||||
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') {
|
||||
}
|
||||
startServer(app, process.env.PORT);
|
||||
|
||||
@@ -252,30 +246,23 @@ connectToDatabase(connectionUrl, options)
|
||||
app.use('/aitools', aitools_router);
|
||||
app.use('/apisqlsrv', article_router);
|
||||
|
||||
|
||||
mystart();
|
||||
|
||||
});
|
||||
|
||||
|
||||
// app.use(throttle(1024 * 128)); // throttling bandwidth
|
||||
|
||||
async function myLoad() {
|
||||
|
||||
return tools.loadApps();
|
||||
}
|
||||
|
||||
async function mystart() {
|
||||
|
||||
// await estraiTutteLeImmagini();
|
||||
|
||||
console.log('Versione Server: ' + await tools.getVersServer());
|
||||
|
||||
console.log('Versione Server: ' + (await tools.getVersServer()));
|
||||
|
||||
await tools.getApps();
|
||||
|
||||
if (process.env.PROD !== 1) {
|
||||
|
||||
testmsgwebpush();
|
||||
|
||||
// tools.sendNotifToAdmin('Riparti', 'Riparti');
|
||||
@@ -293,7 +280,6 @@ connectToDatabase(connectionUrl, options)
|
||||
mycron();
|
||||
}
|
||||
|
||||
|
||||
telegrambot = require('./telegram/telegrambot');
|
||||
|
||||
await inizia();
|
||||
@@ -309,14 +295,15 @@ connectToDatabase(connectionUrl, options)
|
||||
const mailchimpClientId = 'xxxxxxxxxxxxxxxx';
|
||||
|
||||
app.get('/mailchimp/auth/authorize', function (req, res) {
|
||||
res.redirect('https://login.mailchimp.com/oauth2/authorize?' +
|
||||
querystring.stringify({
|
||||
'response_type': 'code',
|
||||
'client_id': mailchimpClientId,
|
||||
'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback',
|
||||
}));
|
||||
res.redirect(
|
||||
'https://login.mailchimp.com/oauth2/authorize?' +
|
||||
querystring.stringify({
|
||||
response_type: 'code',
|
||||
client_id: mailchimpClientId,
|
||||
redirect_uri: 'http://127.0.0.1:3000/mailchimp/auth/callback',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// -----------------
|
||||
@@ -329,13 +316,13 @@ connectToDatabase(connectionUrl, options)
|
||||
chiave: 'vers',
|
||||
userId: 'ALL',
|
||||
valore: '0.1.2',
|
||||
}];
|
||||
},
|
||||
];
|
||||
|
||||
let cfg = new CfgServer(cfgserv[0]).save();
|
||||
}
|
||||
|
||||
async function mycron() {
|
||||
|
||||
try {
|
||||
const sendemail = require('./sendemail');
|
||||
|
||||
@@ -347,7 +334,6 @@ connectToDatabase(connectionUrl, options)
|
||||
await sendemail.checkifSentNewsletter(app.idapp);
|
||||
|
||||
await Cron.startJobCron(app.idapp);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err mycron', e);
|
||||
@@ -358,8 +344,7 @@ connectToDatabase(connectionUrl, options)
|
||||
for (const app of await tools.getApps()) {
|
||||
let enablecrontab = false;
|
||||
|
||||
enablecrontab = await Settings.getValDbSettings(app.idapp,
|
||||
tools.ENABLE_CRONTAB, false);
|
||||
enablecrontab = await Settings.getValDbSettings(app.idapp, tools.ENABLE_CRONTAB, false);
|
||||
|
||||
if (enablecrontab) {
|
||||
// ...
|
||||
@@ -369,12 +354,10 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
async function mycron_everyday() {
|
||||
try {
|
||||
|
||||
const { User } = require('./models/user');
|
||||
|
||||
const arrapps = await tools.getApps();
|
||||
for (const app of arrapps) {
|
||||
|
||||
// Azzera le richieste di password:
|
||||
const usersblocked = await User.find({ idapp: app.idapp, retry_pwd: { $exists: true, $gte: 29 } }).lean();
|
||||
for (const user of usersblocked) {
|
||||
@@ -382,14 +365,12 @@ connectToDatabase(connectionUrl, options)
|
||||
let text = `⚠️⚠️⚠️ L\'utente ${user.username} (${user.name} ${user.surname}) viene sbloccato dal numero massimo di tentativi di richiesta password!\nTelerlo d\'occhio !\n@${user.profile.username_telegram}`;
|
||||
await telegrambot.sendMsgTelegramToTheAdminAllSites(text, false);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('mycron_everyday: ', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function testmsgwebpush() {
|
||||
const { User } = require('./models/user');
|
||||
|
||||
@@ -399,10 +380,10 @@ connectToDatabase(connectionUrl, options)
|
||||
User.find({ username: 'paoloar77', idapp: '1' }).then(async (arrusers) => {
|
||||
if (arrusers !== null) {
|
||||
for (const user of arrusers) {
|
||||
await tools.sendNotificationToUser(user._id, 'Server',
|
||||
'Il Server è Ripartito', '/', '', 'server', []).then(ris => {
|
||||
await tools
|
||||
.sendNotificationToUser(user._id, 'Server', 'Il Server è Ripartito', '/', '', 'server', [])
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
@@ -410,10 +391,8 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Esecuzione ogni 1 minuto (*/1 * * * *)
|
||||
// La sintassi di cron è:
|
||||
// 0 12 * * * comando
|
||||
@@ -429,7 +408,6 @@ connectToDatabase(connectionUrl, options)
|
||||
// }
|
||||
});
|
||||
|
||||
|
||||
// Cron every 1 HOUR
|
||||
cron.schedule('*/60 * * * *', async () => {
|
||||
if (!process.env.VITE_DEBUG) {
|
||||
@@ -447,17 +425,13 @@ connectToDatabase(connectionUrl, options)
|
||||
// tools.writelogfile('test', 'prova.txt');
|
||||
|
||||
async function resetProcessingJob() {
|
||||
|
||||
const { Newstosent } = require('./models/newstosent');
|
||||
|
||||
arrrec = await Newstosent.find({});
|
||||
|
||||
for (const rec of arrrec) {
|
||||
rec.processing_job = false;
|
||||
await Newstosent.findOneAndUpdate({ _id: rec.id }, { $set: rec }, { new: false }).
|
||||
then((item) => {
|
||||
|
||||
});
|
||||
await Newstosent.findOneAndUpdate({ _id: rec.id }, { $set: rec }, { new: false }).then((item) => {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +440,6 @@ connectToDatabase(connectionUrl, options)
|
||||
//});
|
||||
|
||||
async function inizia() {
|
||||
|
||||
try {
|
||||
if (true) {
|
||||
const url = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
|
||||
@@ -477,19 +450,22 @@ connectToDatabase(connectionUrl, options)
|
||||
mycron_everyday();
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
await telegrambot.sendMsgTelegram(tools.FREEPLANET,
|
||||
await telegrambot.sendMsgTelegram(
|
||||
tools.FREEPLANET,
|
||||
shared_consts.ADMIN_USER_SERVER,
|
||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`
|
||||
);
|
||||
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(
|
||||
tools.FREEPLANET,
|
||||
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
||||
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
||||
|
||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` + `🔅 Il Server ${process.env.DATABASE} è appena ripartito!`
|
||||
);
|
||||
} else {
|
||||
|
||||
await telegrambot.sendMsgTelegramToTheAdminAllSites(`Ciao Admin\n` + `🔅🔅🔅 Il Server col BOT di {appname} è appena ripartito!`, false);
|
||||
|
||||
await telegrambot.sendMsgTelegramToTheAdminAllSites(
|
||||
`Ciao Admin\n` + `🔅🔅🔅 Il Server col BOT di {appname} è appena ripartito!`,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
await Site.createFirstUserAdmin();
|
||||
@@ -499,13 +475,7 @@ connectToDatabase(connectionUrl, options)
|
||||
await Circuit.setDeperimentoOff();
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -531,10 +501,8 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
const globalTables = require('./tools/globalTables');
|
||||
|
||||
|
||||
const mytable = globalTables.getTableByTableName(table);
|
||||
if (!mytable)
|
||||
return;
|
||||
if (!mytable) return;
|
||||
|
||||
console.log('INIZIO - estraiImmagini', table);
|
||||
|
||||
@@ -573,16 +541,12 @@ connectToDatabase(connectionUrl, options)
|
||||
console.log('creadir', folderprof);
|
||||
fs.mkdirSync(folderprof);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
for (const photo of myphotos) {
|
||||
|
||||
if (photo.imagefile) {
|
||||
file = dir + 'profile/' + myuser.username + '/' + table + '/' +
|
||||
photo.imagefile;
|
||||
file = dir + 'profile/' + myuser.username + '/' + table + '/' + photo.imagefile;
|
||||
filefrom = dir + 'profile/undefined/' + table + '/' + photo.imagefile;
|
||||
filefrom2 = dir + 'profile/' + myuser.username + '/' + photo.imagefile;
|
||||
|
||||
@@ -615,7 +579,6 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
|
||||
async function estraiTutteLeImmagini() {
|
||||
|
||||
await estraiImmagini('myskills');
|
||||
await estraiImmagini('mygoods');
|
||||
await estraiImmagini('mybachecas');
|
||||
@@ -660,30 +623,24 @@ connectToDatabase(connectionUrl, options)
|
||||
const langdest = 'it';
|
||||
|
||||
telegrambot.askConfirmationUser(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser);
|
||||
|
||||
}
|
||||
|
||||
if (false) {
|
||||
|
||||
const user = await User.findOne({
|
||||
idapp: 12,
|
||||
username: 'paolotest1',
|
||||
});
|
||||
|
||||
await sendemail.sendEmail_Registration('it', 'paolo@arcodiluce.it', user,
|
||||
'12', '');
|
||||
|
||||
await sendemail.sendEmail_Registration('it', 'paolo@arcodiluce.it', user, '12', '');
|
||||
}
|
||||
|
||||
if (false) {
|
||||
|
||||
const { User } = require('./models/user');
|
||||
|
||||
const idapp = tools.FREEPLANET;
|
||||
const idreg = 0;
|
||||
|
||||
try {
|
||||
|
||||
const user = await User.findOne({
|
||||
idapp,
|
||||
username: 'paoloar773',
|
||||
@@ -706,8 +663,7 @@ connectToDatabase(connectionUrl, options)
|
||||
user,
|
||||
};
|
||||
|
||||
await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION,
|
||||
mylocalsconf);
|
||||
await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION, mylocalsconf);
|
||||
} catch (e) {
|
||||
console.log('error ' + e);
|
||||
}
|
||||
@@ -715,7 +671,6 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
|
||||
function getCredentials(hostname) {
|
||||
|
||||
if (NUOVO_METODO_TEST) {
|
||||
if (METODO_MULTI_CORS) {
|
||||
const fileprivkey = `/etc/letsencrypt/live/${hostname}/` + process.env.PATH_CERT_KEY;
|
||||
@@ -746,20 +701,19 @@ connectToDatabase(connectionUrl, options)
|
||||
};*/
|
||||
|
||||
try {
|
||||
const key = fs.readFileSync(fileprivkey, "utf8");
|
||||
const cert = fs.readFileSync(filecert, "utf8");
|
||||
const key = fs.readFileSync(fileprivkey, 'utf8');
|
||||
const cert = fs.readFileSync(filecert, 'utf8');
|
||||
return { key, cert };
|
||||
} catch (error) {
|
||||
console.error(`Errore nel caricamento delle credenziali per ${hostname}:`, error);
|
||||
// Gestisci l'errore, per esempio ritorna null o lancia un'eccezione
|
||||
}
|
||||
|
||||
} else {
|
||||
const keyStream = path.resolve(`./${process.env.PATH_CERT_KEY}`);
|
||||
const certificateStream = path.resolve(`./${process.env.PATH_SERVER_CRT}`);
|
||||
|
||||
const privateKey = fs.readFileSync(keyStream, "utf8");
|
||||
const certificate = fs.readFileSync(certificateStream, "utf8");
|
||||
const privateKey = fs.readFileSync(keyStream, 'utf8');
|
||||
const certificate = fs.readFileSync(certificateStream, 'utf8');
|
||||
|
||||
return { key: privateKey, cert: certificate };
|
||||
}
|
||||
@@ -775,12 +729,10 @@ connectToDatabase(connectionUrl, options)
|
||||
let domains_allowed = [];
|
||||
|
||||
try {
|
||||
if (process.env.DOMAINS)
|
||||
domains = JSON.parse(process.env.DOMAINS);
|
||||
if (process.env.DOMAINS_ALLOWED)
|
||||
domains_allowed = JSON.parse(process.env.DOMAINS_ALLOWED);
|
||||
if (process.env.DOMAINS) domains = JSON.parse(process.env.DOMAINS);
|
||||
if (process.env.DOMAINS_ALLOWED) domains_allowed = JSON.parse(process.env.DOMAINS_ALLOWED);
|
||||
} catch (error) {
|
||||
console.error("Errore durante la conversione della stringa DOMAINS:", error);
|
||||
console.error('Errore durante la conversione della stringa DOMAINS:', error);
|
||||
}
|
||||
|
||||
console.log('domains', domains);
|
||||
@@ -797,22 +749,20 @@ connectToDatabase(connectionUrl, options)
|
||||
let corsOptions = {};
|
||||
|
||||
if (NOCORS) {
|
||||
console.log('NOCORS')
|
||||
console.log('NOCORS');
|
||||
corsOptions = {
|
||||
exposedHeaders: ['x-auth', 'x-refrtok'], // Intestazioni da esporre al client
|
||||
};
|
||||
|
||||
} else {
|
||||
console.log('WITH CORS')
|
||||
console.log('WITH CORS');
|
||||
let credentials = true;
|
||||
|
||||
let allowedOrigins = null;
|
||||
|
||||
if (!isProduction) {
|
||||
allowedOrigins = 'https://localhost:3000';
|
||||
|
||||
} else {
|
||||
allowedOrigins = domains.flatMap(domain => [
|
||||
allowedOrigins = domains.flatMap((domain) => [
|
||||
`https://${domain.hostname}`,
|
||||
`https://api.${domain.hostname}`,
|
||||
`https://test.${domain.hostname}`,
|
||||
@@ -820,20 +770,16 @@ connectToDatabase(connectionUrl, options)
|
||||
`http://${domain.hostname}`,
|
||||
`http://api.${domain.hostname}`,
|
||||
`http://test.${domain.hostname}`,
|
||||
`http://testapi.${domain.hostname}`
|
||||
`http://testapi.${domain.hostname}`,
|
||||
]);
|
||||
|
||||
// Aggiungi i domini da DOMAINS_ALLOWED
|
||||
allowedOrigins = allowedOrigins.concat(
|
||||
domains_allowed.map(domain => [
|
||||
`https://${domain}`,
|
||||
`http://${domain}`
|
||||
]).flat()
|
||||
domains_allowed.map((domain) => [`https://${domain}`, `http://${domain}`]).flat()
|
||||
);
|
||||
}
|
||||
|
||||
console.log('allowedOrigins', allowedOrigins)
|
||||
|
||||
console.log('allowedOrigins', allowedOrigins);
|
||||
|
||||
let myorigin = '*';
|
||||
|
||||
@@ -860,11 +806,10 @@ connectToDatabase(connectionUrl, options)
|
||||
console.warn('❌ Origine bloccata:', origin);
|
||||
return callback(new Error('CORS non permesso per questa origine'), false);
|
||||
} catch (error) {
|
||||
console.error('Errore durante la verifica dell\'origine:', error.message);
|
||||
console.error("Errore durante la verifica dell'origine:", error.message);
|
||||
return callback(error, false);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Configurazione CORS dettagliata
|
||||
@@ -879,12 +824,12 @@ connectToDatabase(connectionUrl, options)
|
||||
'Accept',
|
||||
'Authorization',
|
||||
'x-auth',
|
||||
'x-refrtok'
|
||||
'x-refrtok',
|
||||
],
|
||||
exposedHeaders: ['x-auth', 'x-refrtok'],
|
||||
maxAge: 86400, // Preflight cache 24 ore
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 204
|
||||
optionsSuccessStatus: 204,
|
||||
};
|
||||
|
||||
// Applica CORS come primo middleware
|
||||
@@ -933,11 +878,11 @@ connectToDatabase(connectionUrl, options)
|
||||
console.error('❌ Errore CORS:', {
|
||||
origin: req.headers.origin,
|
||||
method: req.method,
|
||||
path: req.path
|
||||
path: req.path,
|
||||
});
|
||||
res.status(403).json({
|
||||
error: '❌ CORS non permesso per questa origine (' + req.headers.origin + ')',
|
||||
origin: req.headers.origin
|
||||
origin: req.headers.origin,
|
||||
});
|
||||
} else {
|
||||
next(err);
|
||||
@@ -945,32 +890,34 @@ connectToDatabase(connectionUrl, options)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (isProduction) {
|
||||
for (let i = 0; i < domains.length; i++) {
|
||||
const mycredentials = getCredentials(domains[i].hostname);
|
||||
// console.log('credentials: ', credentials);
|
||||
httpsServer = https.createServer(mycredentials, app);
|
||||
console.log('⭐️⭐️⭐️⭐️⭐️ HTTPS server: ' + domains[i].hostname + ' Port:', domains[i].port + (domains[i].website ? 'WebSite = ' + domains[i].website : ''));
|
||||
console.log(
|
||||
'⭐️⭐️⭐️⭐️⭐️ HTTPS server: ' + domains[i].hostname + ' Port:',
|
||||
domains[i].port + (domains[i].website ? 'WebSite = ' + domains[i].website : '')
|
||||
);
|
||||
httpsServer.listen(domains[i].port);
|
||||
}
|
||||
} else {
|
||||
if (process.env.HTTPS_LOCALHOST === "true") {
|
||||
if (process.env.HTTPS_LOCALHOST === 'true') {
|
||||
let mycredentials = null;
|
||||
try {
|
||||
|
||||
const keyStream = path.resolve(`./${process.env.PATH_CERT_KEY}`);
|
||||
const certificateStream = path.resolve(`./${process.env.PATH_SERVER_CRT}`);
|
||||
|
||||
const privateKey = fs.readFileSync(keyStream, "utf8");
|
||||
const certificate = fs.readFileSync(certificateStream, "utf8");
|
||||
const privateKey = fs.readFileSync(keyStream, 'utf8');
|
||||
const certificate = fs.readFileSync(certificateStream, 'utf8');
|
||||
|
||||
mycredentials = {
|
||||
key: privateKey,
|
||||
cert: certificate,
|
||||
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384',
|
||||
ciphers:
|
||||
'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384',
|
||||
honorCipherOrder: true,
|
||||
secureProtocol: 'TLSv1_2_method'
|
||||
secureProtocol: 'TLSv1_2_method',
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Errore durante la lettura dei file di certificazione, error:', error.message);
|
||||
@@ -990,7 +937,6 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
|
||||
// console.log('credentials', credentials);
|
||||
|
||||
} else {
|
||||
httpServer = http.createServer(app);
|
||||
if (httpServer) {
|
||||
@@ -1012,7 +958,6 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
|
||||
if (wss) {
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
console.log('Client socket connected...');
|
||||
|
||||
@@ -1023,12 +968,10 @@ connectToDatabase(connectionUrl, options)
|
||||
const pty = require('node-pty');
|
||||
|
||||
ws.on('message', (message) => {
|
||||
|
||||
const parsedMessage = JSON.parse(message);
|
||||
|
||||
try {
|
||||
|
||||
if ((parsedMessage.type === 'start_script') && (User.isAdminById(parsedMessage.user_id))) {
|
||||
if (parsedMessage.type === 'start_script' && User.isAdminById(parsedMessage.user_id)) {
|
||||
if (scriptProcess) {
|
||||
scriptProcess.kill();
|
||||
}
|
||||
@@ -1042,7 +985,7 @@ connectToDatabase(connectionUrl, options)
|
||||
cols: 80,
|
||||
rows: 40,
|
||||
cwd: process.cwd(),
|
||||
env: process.env
|
||||
env: process.env,
|
||||
});
|
||||
|
||||
let buffer = '';
|
||||
@@ -1053,11 +996,14 @@ connectToDatabase(connectionUrl, options)
|
||||
ws.send(JSON.stringify({ type: 'output', data: data }));
|
||||
|
||||
// Controlla se c'è una richiesta di input
|
||||
if (buffer && (buffer.endsWith(': ') || buffer.includes('? ') ||
|
||||
buffer.toLowerCase().includes('password')
|
||||
|| buffer.includes('Inserisci')
|
||||
|| buffer.includes('Inserted')
|
||||
|| buffer.includes('(Y'))
|
||||
if (
|
||||
buffer &&
|
||||
(buffer.endsWith(': ') ||
|
||||
buffer.includes('? ') ||
|
||||
buffer.toLowerCase().includes('password') ||
|
||||
buffer.includes('Inserisci') ||
|
||||
buffer.includes('Inserted') ||
|
||||
buffer.includes('(Y'))
|
||||
) {
|
||||
ws.send(JSON.stringify({ type: 'input_required', prompt: data.trim() }));
|
||||
buffer = '';
|
||||
@@ -1084,11 +1030,9 @@ connectToDatabase(connectionUrl, options)
|
||||
scriptProcess.write(parsedMessage.data + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Errore durante l\'elaborazione del messaggio:', error.message);
|
||||
console.error("Errore durante l'elaborazione del messaggio:", error.message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
@@ -1098,24 +1042,17 @@ connectToDatabase(connectionUrl, options)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
console.error('Nessuna Socket Aperta con WebSocket !!');
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log('error startServer: ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Impossibile connettersi al database dopo diversi tentativi:", err);
|
||||
.catch((err) => {
|
||||
console.error('Impossibile connettersi al database dopo diversi tentativi:', err);
|
||||
process.exit(1); // Termina il processo se non riesce a connettersi
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = { app };
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.39
|
||||
1.2.40
|
||||
Reference in New Issue
Block a user