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