- check updates
- risolto problema della generazione dei PDF, avevo modificato in CMyPageElem , se si cambia qualcosa occorre stare attenti a mettere !hideHeader
This commit is contained in:
@@ -1409,7 +1409,7 @@ module.exports.removeProductInfoWithoutDateUpdatedFromGM = async function (idapp
|
||||
|
||||
return mylog;
|
||||
};
|
||||
module.exports.HideProductInfoWithoutDateUpdatedFromGM = async function (idapp) {
|
||||
module.exports.unSetDate_Updated_fromGM_OnProduct = async function (idapp) {
|
||||
const Product = this;
|
||||
|
||||
let mylog;
|
||||
|
||||
@@ -874,6 +874,8 @@ sendNotifSchema.statics.compileOtherFields = async function (arrnotif) {
|
||||
).lean();
|
||||
if (myimgprofile && myimgprofile.profile.img)
|
||||
notif.myimgsender = 'upload/profile/' + notif.sender + '/' + myimgprofile.profile.img;
|
||||
else
|
||||
notif.myimgsender = '/images/noimg-user.svg'
|
||||
}
|
||||
|
||||
return arrnotif;
|
||||
|
||||
@@ -8,6 +8,8 @@ mongoose.set('debug', false);
|
||||
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
@@ -408,6 +410,7 @@ module.exports.createFirstUserAdmin = async function () {
|
||||
const numusers = await User.countDocuments({ idapp: mysite.idapp });
|
||||
if (numusers === 0) {
|
||||
// Non esistono utenti, quindi creo quello di Admin
|
||||
console.error('❌❌❌❌ ***** Non esistono utenti, quindi creo quello di Admin ! app=', mysite.idapp);
|
||||
|
||||
const utenteadmin = { idapp: '13', username: shared_consts.ADMIN_USER_SERVER };
|
||||
|
||||
|
||||
@@ -796,7 +796,7 @@ async function findUserByTokenAndAccess(User, decoded, token, typeaccess, withus
|
||||
|
||||
return await User.findOne(query, project).lean();
|
||||
} catch (err) {
|
||||
console.warn('Errore con decoded._id, provo con decoded.smart:', err.message);
|
||||
// console.warn('Errore con decoded._id, provo con decoded.smart:', err.message);
|
||||
|
||||
// Fallback: usa decoded.smart
|
||||
const query = {
|
||||
@@ -917,6 +917,8 @@ UserSchema.statics.findByRefreshTokenAnyAccess = async function (refreshToken) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -472,6 +472,9 @@ class GenPdf {
|
||||
filenamerelative = options.path + `${myfilenameout}${addstr}_generato.pdf`;
|
||||
|
||||
fullnamepath = tools.getdirByIdApp(this.idapp) + '/' + filenamerelative;
|
||||
|
||||
await tools.ensureDir(fullnamepath);
|
||||
|
||||
await this.generatePdfFromUrl(url, fullnamepath, options);
|
||||
|
||||
if (options.comprimi) {
|
||||
|
||||
@@ -465,7 +465,7 @@ class Macro {
|
||||
// disattiva dalla tabella product tutti i campi date_updated_fromGM
|
||||
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
||||
|
||||
let quanti_rimossi = result.modifiedCount;
|
||||
let quanti_rimossi = result. modifiedCount;
|
||||
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||
rimuoviTabellePerIniziare = true;
|
||||
}
|
||||
@@ -513,7 +513,7 @@ class Macro {
|
||||
}
|
||||
|
||||
if (rimuoviTabellePerIniziare && options.rimuovieventualiCancellati) {
|
||||
await Product.HideProductInfoWithoutDateUpdatedFromGM(options.idapp);
|
||||
await Product.unSetDate_Updated_fromGM_OnProduct(options.idapp);
|
||||
}
|
||||
if (myjob) await myjob.terminateJob();
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ router.post('/gettable', authenticate_noerror, (req, res) => {
|
||||
params.table = sanitizeHtml(params.table);
|
||||
|
||||
if (!shared_consts.TABLES_ENABLE_GETTABLE_FOR_NOT_LOGGED.includes(params.table) && !req.user) {
|
||||
return res.status(req.code).send({});
|
||||
return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_PERMESSI).send({msgerr: 'Non hai i permessi per vedere questa pagina.'});
|
||||
}
|
||||
|
||||
let idapp = req.user ? req.user.idapp : sanitizeHtml(params.idapp);
|
||||
@@ -2078,7 +2078,7 @@ async function load(req, res, version = '0') {
|
||||
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
||||
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
||||
myuserextra: req.user ? User.addExtraInfo(idapp, req.user, version) : Promise.resolve(null),
|
||||
statuscode2: version >= 91 ? req.statuscode2 : Promise.resolve([]),
|
||||
statuscode2: version >= 91 ? req.statuscode2 : Promise.resolve([]),
|
||||
};
|
||||
|
||||
// Esecuzione parallela di tutte le promesse
|
||||
@@ -2206,85 +2206,95 @@ async function load(req, res, version = '0') {
|
||||
}
|
||||
|
||||
router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res) => {
|
||||
const idapp = req.query.idapp;
|
||||
try {
|
||||
const idapp = req.query.idapp;
|
||||
|
||||
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
||||
if (!req.user) {
|
||||
return res.status(req.code).send();
|
||||
}
|
||||
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
||||
if (!req.user) {
|
||||
if (req.code === 1) return res.status(200).send();
|
||||
else return res.status(req.code).send();
|
||||
}
|
||||
|
||||
await CfgServer.find({ idapp })
|
||||
.then(async (arrcfgrec) => {
|
||||
if (arrcfgrec.length === 0) {
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
// crea un nuovo record
|
||||
const mycfgServer = new CfgServer();
|
||||
mycfgServer.idapp = idapp;
|
||||
mycfgServer.chiave = 'vers';
|
||||
mycfgServer.userId = 'ALL';
|
||||
mycfgServer.valore = await tools.getVersServer();
|
||||
await CfgServer.find({ idapp })
|
||||
.then(async (arrcfgrec) => {
|
||||
if (arrcfgrec.length === 0) {
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
// crea un nuovo record
|
||||
const mycfgServer = new CfgServer();
|
||||
mycfgServer.idapp = idapp;
|
||||
mycfgServer.chiave = 'vers';
|
||||
mycfgServer.userId = 'ALL';
|
||||
mycfgServer.valore = await tools.getVersServer();
|
||||
|
||||
mycfgServer.save();
|
||||
mycfgServer.save();
|
||||
|
||||
arrcfgrec = await CfgServer.find({ idapp });
|
||||
} else {
|
||||
return res.status(404).send();
|
||||
}
|
||||
}
|
||||
|
||||
// ++Add to Log Stat ....
|
||||
|
||||
let last_msgs = null;
|
||||
let last_notifs = null;
|
||||
let last_notifcoins = null;
|
||||
let usersList = null;
|
||||
let last_notifcoins_inattesa = null;
|
||||
// const sall = '0';
|
||||
|
||||
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
if (req.user) {
|
||||
const userId = req.user._id;
|
||||
if (!ObjectId.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
|
||||
// Se sono il Gestore, le ricevo tutte quante:
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
last_notifcoins_inattesa = SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
||||
} else {
|
||||
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true);
|
||||
}
|
||||
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
|
||||
|
||||
if (req.user) {
|
||||
// If User is Admin, then send user Lists
|
||||
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) || User.isManager(req.user.perm)) {
|
||||
// Send UsersList
|
||||
usersList = User.getUsersList(idapp);
|
||||
// usersList = null;
|
||||
arrcfgrec = await CfgServer.find({ idapp });
|
||||
} else {
|
||||
return res.status(404).send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all([usersList, last_msgs, last_notifs, last_notifcoins, last_notifcoins_inattesa]).then(
|
||||
(arrdata) => {
|
||||
// console.table(arrdata);
|
||||
return res.send({
|
||||
CfgServer: arrcfgrec,
|
||||
usersList: arrdata[0],
|
||||
last_msgs: arrdata[1],
|
||||
last_notifs: arrdata[2],
|
||||
last_notifcoins: [...arrdata[4], ...arrdata[3]],
|
||||
});
|
||||
// ++Add to Log Stat ....
|
||||
|
||||
let last_msgs = null;
|
||||
let last_notifs = null;
|
||||
let last_notifcoins = null;
|
||||
let usersList = null;
|
||||
let last_notifcoins_inattesa = null;
|
||||
// const sall = '0';
|
||||
|
||||
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
if (req.user) {
|
||||
const userId = req.user._id;
|
||||
if (!ObjectId.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
|
||||
// Se sono il Gestore, le ricevo tutte quante:
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
last_notifcoins_inattesa = SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
||||
} else {
|
||||
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(
|
||||
req.user.username,
|
||||
idapp,
|
||||
200,
|
||||
true
|
||||
);
|
||||
}
|
||||
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
|
||||
|
||||
if (req.user) {
|
||||
// If User is Admin, then send user Lists
|
||||
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) || User.isManager(req.user.perm)) {
|
||||
// Send UsersList
|
||||
usersList = User.getUsersList(idapp);
|
||||
// usersList = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
||||
});
|
||||
|
||||
return Promise.all([usersList, last_msgs, last_notifs, last_notifcoins, last_notifcoins_inattesa]).then(
|
||||
(arrdata) => {
|
||||
// console.table(arrdata);
|
||||
return res.send({
|
||||
CfgServer: arrcfgrec,
|
||||
usersList: arrdata[0],
|
||||
last_msgs: arrdata[1],
|
||||
last_notifs: arrdata[2],
|
||||
last_notifcoins: [...arrdata[4], ...arrdata[3]],
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('error:', e);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
||||
|
||||
@@ -402,7 +402,7 @@ connectToDatabase(connectionUrl, options)
|
||||
// console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1));
|
||||
// console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2));
|
||||
|
||||
User.find({ username: 'paoloar77', idapp: '1' }).then(async (arrusers) => {
|
||||
User.find({ username: 'surya1977', idapp: '1' }).then(async (arrusers) => {
|
||||
if (arrusers !== null) {
|
||||
for (const user of arrusers) {
|
||||
await tools
|
||||
@@ -466,7 +466,7 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
async function inizia() {
|
||||
try {
|
||||
if (true) {
|
||||
if (false) {
|
||||
const url = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
|
||||
const outputPath = './comuni_italia_geojson.json';
|
||||
downloadGeoJSON(url, outputPath);
|
||||
@@ -672,7 +672,7 @@ connectToDatabase(connectionUrl, options)
|
||||
username: 'paoloar773',
|
||||
});
|
||||
|
||||
user.aportador_solidario = 'paoloar77';
|
||||
user.aportador_solidario = 'surya1977';
|
||||
|
||||
let mylocalsconf = {
|
||||
idapp,
|
||||
|
||||
@@ -2494,16 +2494,17 @@ class Telegram {
|
||||
}
|
||||
|
||||
async menuRestartSrv(rec, msg, cmd2) {
|
||||
console.log('menuRestartSrv')
|
||||
if (cmd2 === '6711') {
|
||||
const freeSpace = await tools.getFreeDiskSpace();
|
||||
const strfree = `Spazio libero su disco: ${freeSpace}`;
|
||||
|
||||
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(
|
||||
this.chisono(rec) + ' ha rilanciato il Server NODE.JS... \n' + strfree
|
||||
this.chisono(rec) + ' sta rilanciando il Server NODE.JS... \n' + strfree
|
||||
);
|
||||
let file = '~/batch/production_restart_server.sh';
|
||||
let file = '/opt/scripts/production_restart_server.sh';
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
file = '~/batch/test_restart_server.sh';
|
||||
file = '/opt/scripts/test_restart_server.sh';
|
||||
}
|
||||
|
||||
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + file + ' ' + process.version;
|
||||
|
||||
@@ -4760,29 +4760,47 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
execScriptByTelegram: function (idapp, msg, script, testo) {
|
||||
// general.js
|
||||
|
||||
execScriptByTelegram: function (idapp, msg, scriptPath, testo) {
|
||||
const { exec } = require('child_process');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const idchat = msg.chat.id;
|
||||
|
||||
console.log(testo + ' (' + script + ')');
|
||||
console.log(`👉 execScriptByTelegram: ${testo} (${scriptPath})`);
|
||||
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, testo);
|
||||
|
||||
exec(script, (error, stdout, stderr) => {
|
||||
// Opzioni per simulare una shell più completa
|
||||
const options = {
|
||||
shell: '/bin/bash',
|
||||
env: {
|
||||
...process.env, // eredita le variabili d'ambiente correnti
|
||||
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
},
|
||||
timeout: 60000, // 60 secondi max
|
||||
};
|
||||
|
||||
exec(scriptPath, options, (error, stdout, stderr) => {
|
||||
let logMsg = '';
|
||||
let telegramMsg = '';
|
||||
|
||||
if (error) {
|
||||
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + error.message);
|
||||
console.log(`error: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + stderr);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
return;
|
||||
logMsg = `❌ Script fallito: ${error.message}`;
|
||||
telegramMsg = `❌ ERRORE: ${error.message}`;
|
||||
console.error(logMsg);
|
||||
} else if (stderr && !error) {
|
||||
// Nota: alcuni script scrivono info su stderr anche se OK → non sempre è errore!
|
||||
logMsg = `⚠️ Stderr (non fatale): ${stderr}`;
|
||||
telegramMsg = `⚠️ Avviso: ${stderr.substring(0, 300)}`; // tronca per Telegram
|
||||
console.warn(logMsg);
|
||||
} else {
|
||||
logMsg = '✅ Script completato con successo';
|
||||
telegramMsg = stdout ? stdout.substring(0, 300) : '✅ Completato';
|
||||
console.log(logMsg);
|
||||
}
|
||||
|
||||
// console.log(` ... stdout: ${stdout}`);
|
||||
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, stdout);
|
||||
// Invia sempre un feedback a Telegram
|
||||
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, telegramMsg);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -6271,4 +6289,21 @@ module.exports = {
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
async ensureDir(fullnamepath) {
|
||||
const dir = path.dirname(fullnamepath);
|
||||
|
||||
try {
|
||||
await fs.stat(dir);
|
||||
// La directory esiste → tutto ok
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
console.log('Directory non esistente, creazione:', dir);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
} else {
|
||||
console.error('Errore imprevisto durante il controllo della directory:', err);
|
||||
throw err; // Rilancia l'errore se non è ENOENT
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,7 +28,8 @@ module.exports = Object.freeze({
|
||||
RIS_CODE_LOGIN_OK: 1,
|
||||
RIS_ISCRIZIONE_OK: 5,
|
||||
|
||||
RIS_CODE_HTTP_INVALID_TOKEN: 403,
|
||||
RIS_CODE_HTTP_INVALID_TOKEN: 401,
|
||||
RIS_CODE_HTTP_FORBIDDEN_PERMESSI: 403,
|
||||
RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED: 408,
|
||||
|
||||
RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND: -23,
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.72
|
||||
1.2.75
|
||||
Reference in New Issue
Block a user