Unsubscribe

This commit is contained in:
Surya Paolo
2023-02-15 21:40:19 +01:00
parent 81d7d32b85
commit a81300e13d
9 changed files with 11777 additions and 95 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"search.useIgnoreFiles": false
}

16
deploynodejs_on_risosrv_test.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
source ./.env.test.risosrv
echo "Sincronizzazione in corso..."
rsync -avz -e 'ssh -p 5522' css root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' docs root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' emails root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' images root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' plugins root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' sass root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' src root@risosrv:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 5522' .env.test.risosrv root@risosrv:/var/www/$SERVERDIR_WEBSITE/.env.test
rsync -avz -e 'ssh -p 5522' package.json root@risosrv:/var/www/$SERVERDIR_WEBSITE/package.json
echo "Sincronizzazione TERMINATA! - SERVER TEST!"

View File

@@ -9,6 +9,7 @@
"watch": "gulp watch", "watch": "gulp watch",
"test": "export NODE_ENV=development || SET NODE_ENV=development && mocha src/server/**/*.test.js", "test": "export NODE_ENV=development || SET NODE_ENV=development && mocha src/server/**/*.test.js",
"start:prod": "NODE_ENV=production node src/server/server.js", "start:prod": "NODE_ENV=production node src/server/server.js",
"starttest": "NODE_ENV=test node src/server/server.js",
"test-watch": "nodemon --exec 'npm test'" "test-watch": "nodemon --exec 'npm test'"
}, },
"engines": { "engines": {
@@ -47,6 +48,7 @@
"node-telegram-bot-api": "^0.59.0", "node-telegram-bot-api": "^0.59.0",
"nodemailer": "^6.7.8", "nodemailer": "^6.7.8",
"npm-check-updates": "^16.1.0", "npm-check-updates": "^16.1.0",
"pem": "^1.14.6",
"preview-email": "^3.0.7", "preview-email": "^3.0.7",
"pug": "^3.0.2", "pug": "^3.0.2",
"rate-limiter-flexible": "^2.3.9", "rate-limiter-flexible": "^2.3.9",

View File

@@ -8,7 +8,7 @@
} }
], ],
"settings": { "settings": {
"search.useIgnoreFiles": true, "search.useIgnoreFiles": false,
"search.useParentIgnoreFiles": true "search.useParentIgnoreFiles": false
} }
} }

View File

@@ -159,14 +159,6 @@ module.exports = {
transport_preview.sendMail(mailOptions).then(console.log).catch(console.error); transport_preview.sendMail(mailOptions).then(console.log).catch(console.error);
} }
}, },
// getHostByIdApp: function (idapp) {
// if (idapp === 1) {
// let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : "";
// return process.env.URLBASE_APP1 + siteport;
// } else {
// return ""
// }
// },
getlinkReg: function(idapp, idreg) { getlinkReg: function(idapp, idreg) {
const strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `/?idapp=${idapp}&idlink=${idreg}`; const strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `/?idapp=${idapp}&idlink=${idreg}`;

View File

@@ -23,10 +23,15 @@ const bodyParser = require('body-parser');
const path = require('path'); const path = require('path');
const cron = require('node-cron'); const cron = require('node-cron');
console.log('Starting mongoose...');
require('./db/mongoose'); require('./db/mongoose');
const {Settings} = require('./models/settings'); // console.log('Starting pem...');
// const pem = require('pem')
const { Settings } = require('./models/settings');
// test // test
@@ -36,17 +41,28 @@ const i18n = require('i18n');
// https://www.psclistens.com/insight/blog/enabling-a-nodejs-ssl-webserver-using-let-s-encrypt-pem-certificates/ // https://www.psclistens.com/insight/blog/enabling-a-nodejs-ssl-webserver-using-let-s-encrypt-pem-certificates/
if ((process.env.NODE_ENV === 'production') || if ((process.env.NODE_ENV === 'production') ||
(process.env.NODE_ENV === 'test')) { (process.env.NODE_ENV === 'test')) {
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8'); if (false) {
var credentials = {
key: privateKey, } else {
cert: certificate,
ca: [ var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
fs.readFileSync(process.env.PATH_SSL_ROOT_PEM, 'utf8'), var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
fs.readFileSync(process.env.PATH_SSL_CHAIN_PEM, 'utf8'), /*var credentials = {
], key: privateKey,
}; cert: certificate,
ca: [
fs.readFileSync(process.env.PATH_SSL_ROOT_PEM, 'utf8'),
fs.readFileSync(process.env.PATH_SSL_CHAIN_PEM, 'utf8'),
],
};
*/
var credentials = {
key: privateKey,
cert: certificate,
};
}
var https = require('https'); var https = require('https');
} else { } else {
if (process.env.HTTPS_LOCALHOST === "true") { if (process.env.HTTPS_LOCALHOST === "true") {
@@ -82,17 +98,17 @@ var mongoose = require('mongoose').set('debug', false);
mongoose.set('debug', false); mongoose.set('debug', false);
const {CfgServer} = require('./models/cfgserver'); const { CfgServer } = require('./models/cfgserver');
const {ObjectID} = require('mongodb'); const { ObjectID } = require('mongodb');
const populate = require('./populate/populate'); const populate = require('./populate/populate');
const {Circuit} = require('./models/circuit'); const { Circuit } = require('./models/circuit');
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');
require('./models/project'); require('./models/project');
@@ -137,18 +153,18 @@ myLoad().then(ris => {
const mygoods_router = require('./router/mygoods_router'); const mygoods_router = require('./router/mygoods_router');
const mygen_router = require('./router/mygen_router'); const mygen_router = require('./router/mygen_router');
const {MyEvent} = require('./models/myevent'); const { MyEvent } = require('./models/myevent');
app.use(express.static('views')); app.use(express.static('views'));
// app.use(express.static(path.join(__dirname, 'client'))); // app.use(express.static(path.join(__dirname, 'client')));
app.use(bodyParser.json()); app.use(bodyParser.json());
// app.set('view engine', 'pug'); // app.set('view engine', 'pug');
// Set static folder // Set static folder
// app.use(express.static(path.join(__dirname, 'public'))); // app.use(express.static(path.join(__dirname, 'public')));
i18n.configure({ i18n.configure({
locales: ['it', 'enUs', 'es', 'fr', 'pt', 'si'], locales: ['it', 'enUs', 'es', 'fr', 'pt', 'si'],
@@ -167,10 +183,13 @@ myLoad().then(ris => {
app.use(bodyParser.json()); app.use(bodyParser.json());
// app.use(express.cookieParser()); // app.use(express.cookieParser());
app.use(i18n.init); app.use(i18n.init);
// Use Routes console.log('Use Routes \...');
// Use Routes
app.use('/', index_router); app.use('/', index_router);
app.use('/subscribe', subscribe_router); app.use('/subscribe', subscribe_router);
app.use('/sendmsg', sendmsg_router); app.use('/sendmsg', sendmsg_router);
@@ -200,24 +219,24 @@ myLoad().then(ris => {
app.use('/mygoods', mygoods_router); app.use('/mygoods', mygoods_router);
app.use('/mygen', mygen_router); app.use('/mygen', mygen_router);
// 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) {
// var err = new Error('Not Found'); // var err = new Error('Not Found');
// err.status = 404; // err.status = 404;
// next(err); // next(err);
// }); // });
// app.set('views', path.join(__dirname, 'views')); // app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'pug'); // app.set('view engine', 'pug');
// 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();
res.status(err.status || 500).send({error: err.message}); res.status(err.status || 500).send({ error: err.message });
// res.render('error', { // res.render('error', {
// message: err.message, // message: err.message,
// error: err // error: err
@@ -226,28 +245,40 @@ myLoad().then(ris => {
} }
// require('./telegram/telegrambot'); // require('./telegram/telegrambot');
// *** DB CONNECTIONS *** // *** DB CONNECTIONS ***
// mysql_func.mySqlConn_Shen.connect((err) => { // mysql_func.mySqlConn_Shen.connect((err) => {
// if (!err) // if (!err)
// console.log('DB connection to Shen Database succeded.'); // console.log('DB connection to Shen Database succeded.');
// else // else
// console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2)); // console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2));
// }); // });
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.HTTPS_LOCALHOST === "true") { (process.env.NODE_ENV === 'test') || process.env.HTTPS_LOCALHOST === "true") {
var httpsServer = https.createServer(credentials, app);
console.log('httpsServer: port ', port); if (false) {
httpsServer.listen(port); /*pem.createCertificate({ days: 1, selfSigned: true }, (err, keys) => {
if (err) {
throw err
}
const httpsServer = https.createServer({ key: keys.clientKey, cert: keys.certificate }, (req, res) => {
res.end('o hai!')
}).listen(port)
}) */
} else {
const httpsServer = https.createServer(credentials, app);
console.log('httpsServer: port ', port);
httpsServer.listen(port);
}
} else { } else {
console.log('httpServer: port ', port); console.log('httpServer: port ', port);
var httpServer = http.createServer(app); const httpServer = http.createServer(app);
httpServer.listen(port); httpServer.listen(port);
} }
@@ -306,17 +337,17 @@ async function mystart() {
faitest(); faitest();
// ----------------- MAILCHIMP ----- // ----------------- MAILCHIMP -----
const querystring = require('querystring'); const querystring = require('querystring');
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('https://login.mailchimp.com/oauth2/authorize?' +
querystring.stringify({ querystring.stringify({
'response_type': 'code', 'response_type': 'code',
'client_id': mailchimpClientId, 'client_id': mailchimpClientId,
'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback', 'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback',
})); }));
}); });
} }
@@ -352,7 +383,7 @@ async function mycron_30min() {
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) {
// ... // ...
@@ -361,22 +392,22 @@ async function mycron_30min() {
} }
function testmsgwebpush() { function testmsgwebpush() {
const {User} = require('./models/user'); const { User } = require('./models/user');
// console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1)); // console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1));
// console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2)); // console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2));
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.sendNotificationToUser(user._id, 'Server',
'Il Server è Ripartito', '/', '', 'server', []).then(ris => { '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
} }
}); });
} }
} }
}); });
@@ -404,16 +435,16 @@ cron.schedule('*/60 * * * *', async () => {
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) => {
}); });
} }
} }
@@ -427,13 +458,13 @@ async function inizia() {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
await telegrambot.sendMsgTelegram(tools.FREEPLANET, await telegrambot.sendMsgTelegram(tools.FREEPLANET,
telegrambot.ADMIN_USER_SERVER, telegrambot.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 {
@@ -470,7 +501,7 @@ async function inizia() {
// } // }
async function estraiImmagini(table) { async function estraiImmagini(table) {
const {User} = require('./models/user'); const { User } = require('./models/user');
let idapp = '13'; let idapp = '13';
@@ -485,7 +516,7 @@ async function estraiImmagini(table) {
console.log('INIZIO - estraiImmagini', table); console.log('INIZIO - estraiImmagini', table);
arrlist = await mytable.find({idapp}).lean(); arrlist = await mytable.find({ idapp }).lean();
let file = ''; let file = '';
let filetocheck = ''; let filetocheck = '';
@@ -500,7 +531,7 @@ async function estraiImmagini(table) {
} }
for (const rec of arrlist) { for (const rec of arrlist) {
const myuser = await User.findOne({idapp, _id: rec.userId}).lean(); const myuser = await User.findOne({ idapp, _id: rec.userId }).lean();
if (myuser) { if (myuser) {
const myphotos = rec.photos; const myphotos = rec.photos;
@@ -529,7 +560,7 @@ async function estraiImmagini(table) {
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;
@@ -589,7 +620,7 @@ async function faitest() {
} }
if (testfind) { if (testfind) {
const {City} = require('./models/city'); const { City } = require('./models/city');
let miacity = 'roma'; let miacity = 'roma';
const ris = await City.findByCity(miacity); const ris = await City.findByCity(miacity);
@@ -597,7 +628,7 @@ async function faitest() {
console.log('ris', ris); console.log('ris', ris);
} }
const {User} = require('./models/user'); const { User } = require('./models/user');
if (false) { if (false) {
let myuser = await User.findOne({ let myuser = await User.findOne({
@@ -619,13 +650,13 @@ async function faitest() {
}); });
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;
@@ -655,12 +686,12 @@ async function faitest() {
}; };
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);
} }
} }
} }
module.exports = {app}; module.exports = { app };

View File

@@ -2,11 +2,11 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.RISO]; const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.ARCADEI, tools.RISO]; const appTelegram_TEST = [tools.FREEPLANET, tools.RISO];
const appTelegram_DEVELOP = [tools.RISO]; const appTelegram_DEVELOP = [tools.RISO];
const appTelegramFinti = ['2', tools.CNM, tools.ARCADEI]; const appTelegramFinti = ['2', tools.CNM, tools.ARCADEI];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET, tools.FREEPLANET]; const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
const printf = require('util').format; const printf = require('util').format;

9
test.http Normal file
View File

@@ -0,0 +1,9 @@
### Init:
get http://localhost:3000/
### Create a new
get https://splendidus.it:3000/
### Create a new
get https://mail.freeplanet.app:3000/

11629
yarn.lock Normal file

File diff suppressed because it is too large Load Diff