- 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:
Surya Paolo
2025-11-01 12:00:57 +01:00
parent 38c13eef28
commit 8d1dd45648
26 changed files with 660 additions and 556 deletions

View File

@@ -1,12 +1,12 @@
DATABASE=test_FreePlanet
DATABASE=test_PiuCheBuono
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0
SEND_EMAIL_ORDERS=1
PORT=3000
appTelegram_TEST=["1","13"]
appTelegram=["1","13"]
appTelegram_DEVELOP=["13"]
appTelegram_TEST=["1","17"]
appTelegram=["1","17"]
appTelegram_DEVELOP=["17"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=0
ENABLE_PUSHNOTIFICATION=1
@@ -29,7 +29,7 @@ GCM_API_KEY=""
PROD=0
PROJECT_DESCR_MAIN='__PROJECTS'
SECRK=Askb38v23jjDFaoskBOWj92axXCQ
TOKEN_LIFE=1m
TOKEN_LIFE=2h
REFRESH_TOKEN_LIFE=14d
FTPSERVER_HOST=139.162.166.31
FTPSERVER_PORT=21
@@ -38,4 +38,9 @@ FTPSERVER_PWD=ftpmypwd@1A_
AUTH_NEW_SITES=123123123
SCRIPTS_DIR=admin_scripts
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
MIAB_HOST=box.lamiaposta.org
MIAB_ADMIN_EMAIL=admin@lamiaposta.org
MIAB_ADMIN_PASSWORD=passpao1pabox@1A
DS_API_KEY="sk-222e3addb3d8455d8b0516d93906eec7"
SERVER_A_URL="http://51.77.156.69:3000"
API_KEY_MSSQL="m68yADSr123MIVIDA@154$DSAGVOK"

1
aggiornaserver.txt Executable file
View File

@@ -0,0 +1 @@
Aggiornamento Server...

View File

@@ -72,6 +72,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato
if [ $? -eq 0 ]; then
echo "Sincronizzazione completata con successo. SERVER PCB PRODUZIONE! "

View File

@@ -72,6 +72,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato
if [ $? -eq 0 ]; then
echo "Sincronizzazione completata con successo. SERVER PCB TEST! "

View File

@@ -67,6 +67,12 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \
"$CONFIG_JS" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato
if [ $? -eq 0 ]; then
echo "✅ Sincronizzazione completata con successo. SERVER $REMOTE_DIR! "

View File

@@ -75,6 +75,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato
if [ $? -eq 0 ]; then

View File

@@ -1,10 +1,10 @@
module.exports = {
apps: [
{
name: "PiuCheBuono (Prod)",
name: "PCB-PROD",
script: "/var/www/nodejs_piuchebuono_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
// interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
//autorestart: true,
instances: 1,
watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = {
apps: [
{
name: "PiuCheBuono (TEST)",
name: "PCB-TEST",
script: "/var/www/nodejs_test.piuchebuono_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
// interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
instances: 1,
watch: false,
env: {

View File

@@ -4,7 +4,7 @@ module.exports = {
name: "PRODUZIONE - FREEPLANET",
script: "/var/www/www.freeplanet_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node",
// interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node",
//autorestart: true,
instances: 1,
watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = {
apps: [
{
name: "RISO (Prod)",
name: "RISO-PROD",
script: "/var/www/nodejs_riso_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
// interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
//autorestart: true,
instances: 1,
watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = {
apps: [
{
name: "RISO (TEST)",
name: "RISO-TEST",
script: "./src/server/server.js",
ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
// interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
watch: false,
instances: 1,
env_test: {

View File

@@ -34,3 +34,5 @@ Sab 11/10 ORE 19:05: USER [surya1977]: ciao
Sab 11/10 ORE 19:36: USER [surya1977]: ciao
Sab 11/10 ORE 19:38: USER [surya1977]: ciao
Lun 27/10 ORE 13:35: USER [surya1977]: ciao

View File

@@ -16,6 +16,7 @@
"author": "Surya",
"license": "MIT",
"dependencies": {
"axios": "^1.13.0",
"basic-ftp": "^5.0.5",
"bcryptjs": "^3.0.2",
"bluebird": "^3.7.2",
@@ -30,9 +31,11 @@
"dotenv": "^16.4.7",
"ejs": "^3.1.10",
"email-templates": "^12.0.2",
"entities": "^7.0.0",
"express": "^4.21.2",
"fast-csv": "^5.0.5",
"formidable": "^3.5.2",
"fs-extra": "^11.3.2",
"ghostscript4js": "^3.2.3",
"helmet": "^8.1.0",
"i18n": "^0.15.1",
@@ -73,6 +76,7 @@
"validator": "^13.12.0",
"vhost": "^3.0.2",
"web-push": "^3.6.7",
"ws": "^8.18.3",
"xlsx": "^0.18.5",
"xml2js": "^0.6.2",
"xoauth2": "^1.2.0"

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 };

View File

@@ -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;
};

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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) => {

View File

@@ -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,

View File

@@ -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;

View File

@@ -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
}
}
},
};

View File

@@ -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,

View File

@@ -1 +1 @@
1.2.72
1.2.75

900
yarn.lock

File diff suppressed because it is too large Load Diff