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

View File

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

View File

@@ -159,14 +159,6 @@ module.exports = {
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) {
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 cron = require('node-cron');
console.log('Starting mongoose...');
require('./db/mongoose');
const {Settings} = require('./models/settings');
// console.log('Starting pem...');
// const pem = require('pem')
const { Settings } = require('./models/settings');
// 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/
if ((process.env.NODE_ENV === 'production') ||
(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');
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'),
],
};
(process.env.NODE_ENV === 'test')) {
if (false) {
} else {
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, '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');
} else {
if (process.env.HTTPS_LOCALHOST === "true") {
@@ -82,17 +98,17 @@ var mongoose = require('mongoose').set('debug', false);
mongoose.set('debug', false);
const {CfgServer} = require('./models/cfgserver');
const {ObjectID} = require('mongodb');
const { CfgServer } = require('./models/cfgserver');
const { ObjectID } = require('mongodb');
const populate = require('./populate/populate');
const {Circuit} = require('./models/circuit');
const { Circuit } = require('./models/circuit');
const printf = require('util').format;
myLoad().then(ris => {
const {User} = require('./models/user');
const { User } = require('./models/user');
require('./models/todo');
require('./models/project');
@@ -137,18 +153,18 @@ myLoad().then(ris => {
const mygoods_router = require('./router/mygoods_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(path.join(__dirname, 'client')));
// app.use(express.static(path.join(__dirname, 'client')));
app.use(bodyParser.json());
// app.set('view engine', 'pug');
// app.set('view engine', 'pug');
// Set static folder
// app.use(express.static(path.join(__dirname, 'public')));
// Set static folder
// app.use(express.static(path.join(__dirname, 'public')));
i18n.configure({
locales: ['it', 'enUs', 'es', 'fr', 'pt', 'si'],
@@ -167,10 +183,13 @@ myLoad().then(ris => {
app.use(bodyParser.json());
// app.use(express.cookieParser());
// app.use(express.cookieParser());
app.use(i18n.init);
// Use Routes
console.log('Use Routes \...');
// Use Routes
app.use('/', index_router);
app.use('/subscribe', subscribe_router);
app.use('/sendmsg', sendmsg_router);
@@ -200,24 +219,24 @@ myLoad().then(ris => {
app.use('/mygoods', mygoods_router);
app.use('/mygen', mygen_router);
// catch 404 and forward to error handler
// app.use(function (req, res, next) {
// var err = new Error('Not Found');
// err.status = 404;
// next(err);
// });
// catch 404 and forward to error handler
// app.use(function (req, res, next) {
// var err = new Error('Not Found');
// err.status = 404;
// next(err);
// });
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'pug');
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'pug');
// development error handler
// will print stacktrace
// development error handler
// will print stacktrace
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.trace();
res.status(err.status || 500).send({error: err.message});
res.status(err.status || 500).send({ error: err.message });
// res.render('error', {
// message: err.message,
// error: err
@@ -226,28 +245,40 @@ myLoad().then(ris => {
}
// require('./telegram/telegrambot');
// require('./telegram/telegrambot');
// *** DB CONNECTIONS ***
// mysql_func.mySqlConn_Shen.connect((err) => {
// if (!err)
// console.log('DB connection to Shen Database succeded.');
// else
// console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2));
// });
// *** DB CONNECTIONS ***
// mysql_func.mySqlConn_Shen.connect((err) => {
// if (!err)
// console.log('DB connection to Shen Database succeded.');
// else
// console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2));
// });
if (process.env.NODE_ENV === 'production') {
console.log('*** PRODUCTION! ');
}
if ((process.env.NODE_ENV === 'production') ||
(process.env.NODE_ENV === 'test') || process.env.HTTPS_LOCALHOST === "true") {
var httpsServer = https.createServer(credentials, app);
console.log('httpsServer: port ', port);
httpsServer.listen(port);
(process.env.NODE_ENV === 'test') || process.env.HTTPS_LOCALHOST === "true") {
if (false) {
/*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 {
console.log('httpServer: port ', port);
var httpServer = http.createServer(app);
const httpServer = http.createServer(app);
httpServer.listen(port);
}
@@ -306,17 +337,17 @@ async function mystart() {
faitest();
// ----------------- MAILCHIMP -----
// ----------------- MAILCHIMP -----
const querystring = require('querystring');
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?' +
querystring.stringify({
'response_type': 'code',
'client_id': mailchimpClientId,
'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback',
}));
querystring.stringify({
'response_type': 'code',
'client_id': mailchimpClientId,
'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback',
}));
});
}
@@ -352,7 +383,7 @@ async function mycron_30min() {
let enablecrontab = false;
enablecrontab = await Settings.getValDbSettings(app.idapp,
tools.ENABLE_CRONTAB, false);
tools.ENABLE_CRONTAB, false);
if (enablecrontab) {
// ...
@@ -361,22 +392,22 @@ async function mycron_30min() {
}
function testmsgwebpush() {
const {User} = require('./models/user');
const { User } = require('./models/user');
// 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: '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 => {
if (ris) {
'Il Server è Ripartito', '/', '', 'server', []).then(ris => {
if (ris) {
} else {
// already sent the error on calling sendNotificationToUser
}
});
} else {
// already sent the error on calling sendNotificationToUser
}
});
}
}
});
@@ -404,16 +435,16 @@ cron.schedule('*/60 * * * *', async () => {
async function resetProcessingJob() {
const {Newstosent} = require('./models/newstosent');
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) => {
});
});
}
}
@@ -427,13 +458,13 @@ async function inizia() {
if (process.env.NODE_ENV === 'development') {
await telegrambot.sendMsgTelegram(tools.FREEPLANET,
telegrambot.ADMIN_USER_SERVER,
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
telegrambot.ADMIN_USER_SERVER,
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
telegrambot.ADMIN_IDTELEGRAM_SERVER,
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
telegrambot.ADMIN_IDTELEGRAM_SERVER,
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
} else {
@@ -470,7 +501,7 @@ async function inizia() {
// }
async function estraiImmagini(table) {
const {User} = require('./models/user');
const { User } = require('./models/user');
let idapp = '13';
@@ -485,7 +516,7 @@ async function estraiImmagini(table) {
console.log('INIZIO - estraiImmagini', table);
arrlist = await mytable.find({idapp}).lean();
arrlist = await mytable.find({ idapp }).lean();
let file = '';
let filetocheck = '';
@@ -500,7 +531,7 @@ async function estraiImmagini(table) {
}
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) {
const myphotos = rec.photos;
@@ -529,7 +560,7 @@ async function estraiImmagini(table) {
if (photo.imagefile) {
file = dir + 'profile/' + myuser.username + '/' + table + '/' +
photo.imagefile;
photo.imagefile;
filefrom = dir + 'profile/undefined/' + table + '/' + photo.imagefile;
filefrom2 = dir + 'profile/' + myuser.username + '/' + photo.imagefile;
@@ -589,7 +620,7 @@ async function faitest() {
}
if (testfind) {
const {City} = require('./models/city');
const { City } = require('./models/city');
let miacity = 'roma';
const ris = await City.findByCity(miacity);
@@ -597,7 +628,7 @@ async function faitest() {
console.log('ris', ris);
}
const {User} = require('./models/user');
const { User } = require('./models/user');
if (false) {
let myuser = await User.findOne({
@@ -619,13 +650,13 @@ async function faitest() {
});
await sendemail.sendEmail_Registration('it', 'paolo@arcodiluce.it', user,
'12', '');
'12', '');
}
if (false) {
const {User} = require('./models/user');
const { User } = require('./models/user');
const idapp = tools.FREEPLANET;
const idreg = 0;
@@ -655,12 +686,12 @@ async function faitest() {
};
await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION,
mylocalsconf);
mylocalsconf);
} catch (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_TEST = [tools.FREEPLANET, tools.ARCADEI, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.RISO];
const appTelegram_DEVELOP = [tools.RISO];
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;