++ Added root.pem and chain.pem to the SSL full certificates
PATH_SSL_ROOT_PEM PATH_SSL_CHAIN_PEM
This commit is contained in:
22
README.md
22
README.md
@@ -21,6 +21,28 @@ cp .env.development .env.test
|
|||||||
|
|
||||||
And modifying the file with your configuration
|
And modifying the file with your configuration
|
||||||
|
|
||||||
|
### Certificates
|
||||||
|
|
||||||
|
Once you have gone through the process of getting your Let’s Encrypt certificates you will have 4 certificates:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cert.pem
|
||||||
|
chain.pem
|
||||||
|
fullchain.pem
|
||||||
|
privkey.pem
|
||||||
|
```
|
||||||
|
|
||||||
|
You will need to download the root certificate (root.pem) and an intermediate certificate (chain.pem) from Let’s Encrypt – https://letsencrypt.org/certificates/
|
||||||
|
|
||||||
|
See this article:
|
||||||
|
https://www.psclistens.com/insight/blog/enabling-a-nodejs-ssl-webserver-using-let-s-encrypt-pem-certificates/
|
||||||
|
|
||||||
|
|
||||||
|
To see if all the certificates are OK, see this page check and enter the correct host and port:
|
||||||
|
https://decoder.link/sslchecker
|
||||||
|
|
||||||
|
For example:
|
||||||
|
https://decoder.link/sslchecker/test.freeplanet.app/3001
|
||||||
|
|
||||||
### Build the ambient test
|
### Build the ambient test
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const _ = require('lodash');
|
|||||||
// console.log(" cors");
|
// console.log(" cors");
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
|
|
||||||
|
|
||||||
// console.log(" 2) fs");
|
// console.log(" 2) fs");
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -25,22 +24,32 @@ const cron = require('node-cron');
|
|||||||
|
|
||||||
require('./db/mongoose');
|
require('./db/mongoose');
|
||||||
|
|
||||||
const { Settings } = require('./models/settings');
|
const {Settings} = require('./models/settings');
|
||||||
|
|
||||||
const i18n = require("i18n");
|
const i18n = require('i18n');
|
||||||
|
|
||||||
|
// OBTAIN
|
||||||
|
// 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')) {
|
if ((process.env.NODE_ENV === 'production') ||
|
||||||
|
(process.env.NODE_ENV === 'test')) {
|
||||||
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
|
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
|
||||||
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
|
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
|
||||||
var credentials = { key: privateKey, cert: certificate };
|
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 https = require('https');
|
var https = require('https');
|
||||||
} else {
|
} else {
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('DB: ' + process.env.DATABASE);
|
||||||
console.log("DB: " + process.env.DATABASE);
|
|
||||||
// console.log("PORT: " + port);
|
// console.log("PORT: " + port);
|
||||||
// console.log("MONGODB_URI: " + process.env.MONGODB_URI);
|
// console.log("MONGODB_URI: " + process.env.MONGODB_URI);
|
||||||
|
|
||||||
@@ -54,12 +63,12 @@ require('./models/cfgserver');
|
|||||||
|
|
||||||
const shared_consts = require('./tools/shared_nodejs');
|
const shared_consts = require('./tools/shared_nodejs');
|
||||||
|
|
||||||
var mongoose = require('mongoose').set('debug', false)
|
var mongoose = require('mongoose').set('debug', false);
|
||||||
|
|
||||||
mongoose.set('debug', process.env.DEBUG);
|
mongoose.set('debug', process.env.DEBUG);
|
||||||
|
|
||||||
const cfgserver = mongoose.model('cfgserver');
|
const cfgserver = mongoose.model('cfgserver');
|
||||||
const { ObjectID } = require('mongodb');
|
const {ObjectID} = require('mongodb');
|
||||||
|
|
||||||
const populate = require('./populate/populate');
|
const populate = require('./populate/populate');
|
||||||
|
|
||||||
@@ -67,7 +76,7 @@ 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');
|
||||||
@@ -81,7 +90,6 @@ myLoad().then(ris => {
|
|||||||
require('./models/calzoom');
|
require('./models/calzoom');
|
||||||
const mysql_func = require('./mysql/mysql_func');
|
const mysql_func = require('./mysql/mysql_func');
|
||||||
|
|
||||||
|
|
||||||
const index_router = require('./router/index_router');
|
const index_router = require('./router/index_router');
|
||||||
const push_router = require('./router/push_router');
|
const push_router = require('./router/push_router');
|
||||||
const newsletter_router = require('./router/newsletter_router');
|
const newsletter_router = require('./router/newsletter_router');
|
||||||
@@ -107,7 +115,7 @@ 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'));
|
||||||
|
|
||||||
@@ -120,11 +128,10 @@ myLoad().then(ris => {
|
|||||||
// 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'],
|
||||||
// cookie: 'cook',
|
// cookie: 'cook',
|
||||||
directory: __dirname + '/locales'
|
directory: __dirname + '/locales',
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
@@ -136,7 +143,6 @@ myLoad().then(ris => {
|
|||||||
// app.use(express.cookieParser());
|
// app.use(express.cookieParser());
|
||||||
app.use(i18n.init);
|
app.use(i18n.init);
|
||||||
|
|
||||||
|
|
||||||
// Use Routes
|
// Use Routes
|
||||||
app.use('/', index_router);
|
app.use('/', index_router);
|
||||||
app.use('/subscribe', subscribe_router);
|
app.use('/subscribe', subscribe_router);
|
||||||
@@ -177,10 +183,10 @@ myLoad().then(ris => {
|
|||||||
// 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('Error: ', err.message);
|
console.log('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
|
||||||
@@ -191,7 +197,6 @@ 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)
|
||||||
@@ -200,24 +205,23 @@ myLoad().then(ris => {
|
|||||||
// 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') || (process.env.NODE_ENV === 'test')) {
|
if ((process.env.NODE_ENV === 'production') ||
|
||||||
|
(process.env.NODE_ENV === 'test')) {
|
||||||
var httpsServer = https.createServer(credentials, app);
|
var httpsServer = https.createServer(credentials, app);
|
||||||
console.log("httpsServer: port ", port);
|
console.log('httpsServer: port ', port);
|
||||||
httpsServer.listen(port);
|
httpsServer.listen(port);
|
||||||
} else {
|
} else {
|
||||||
console.log("httpServer: port ", port);
|
console.log('httpServer: port ', port);
|
||||||
var httpServer = http.createServer(app);
|
var httpServer = http.createServer(app);
|
||||||
httpServer.listen(port);
|
httpServer.listen(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
mystart();
|
mystart();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// app.use(throttle(1024 * 128)); // throttling bandwidth
|
// app.use(throttle(1024 * 128)); // throttling bandwidth
|
||||||
@@ -239,10 +243,8 @@ async function mystart() {
|
|||||||
|
|
||||||
testmsgwebpush();
|
testmsgwebpush();
|
||||||
|
|
||||||
|
|
||||||
// tools.sendNotifToAdmin('Riparti', 'Riparti');
|
// tools.sendNotifToAdmin('Riparti', 'Riparti');
|
||||||
|
|
||||||
|
|
||||||
let miapass = '';
|
let miapass = '';
|
||||||
|
|
||||||
if (miapass !== '') {
|
if (miapass !== '') {
|
||||||
@@ -268,34 +270,31 @@ 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',
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
|
|
||||||
function populateDBadmin() {
|
function populateDBadmin() {
|
||||||
const cfgserv = [{
|
const cfgserv = [
|
||||||
|
{
|
||||||
_id: new ObjectID(),
|
_id: new ObjectID(),
|
||||||
idapp: '9',
|
idapp: '9',
|
||||||
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();
|
||||||
@@ -305,7 +304,6 @@ function mycron() {
|
|||||||
|
|
||||||
const sendemail = require('./sendemail');
|
const sendemail = require('./sendemail');
|
||||||
|
|
||||||
|
|
||||||
for (const app of tools.getApps()) {
|
for (const app of tools.getApps()) {
|
||||||
sendemail.checkifPendingNewsletter(app.idapp);
|
sendemail.checkifPendingNewsletter(app.idapp);
|
||||||
sendemail.checkifSentNewsletter(app.idapp);
|
sendemail.checkifSentNewsletter(app.idapp);
|
||||||
@@ -317,7 +315,8 @@ async function mycron_30min() {
|
|||||||
for (const app of tools.getApps()) {
|
for (const app of tools.getApps()) {
|
||||||
let enablecrontab = false;
|
let enablecrontab = false;
|
||||||
|
|
||||||
enablecrontab = await Settings.getValDbSettings(app.idapp, tools.ENABLE_CRONTAB, false);
|
enablecrontab = await Settings.getValDbSettings(app.idapp,
|
||||||
|
tools.ENABLE_CRONTAB, false);
|
||||||
|
|
||||||
if (enablecrontab) {
|
if (enablecrontab) {
|
||||||
// ...
|
// ...
|
||||||
@@ -326,29 +325,28 @@ 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((arrusers) => {
|
User.find({username: 'paoloar77', idapp: '1'}).then((arrusers) => {
|
||||||
if (arrusers !== null) {
|
if (arrusers !== null) {
|
||||||
for (const user of arrusers) {
|
for (const user of arrusers) {
|
||||||
tools.sendNotificationToUser(user._id, 'Server', 'Il Server è Ripartito', '/', '', 'server', [])
|
tools.sendNotificationToUser(user._id, '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
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Cron every X minutes
|
// Cron every X minutes
|
||||||
cron.schedule('*/2 * * * *', () => {
|
cron.schedule('*/2 * * * *', () => {
|
||||||
// console.log('Running Cron Job');
|
// console.log('Running Cron Job');
|
||||||
@@ -357,7 +355,6 @@ cron.schedule('*/2 * * * *', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Cron every X minutes
|
// Cron every X minutes
|
||||||
cron.schedule('*/60 * * * *', async () => {
|
cron.schedule('*/60 * * * *', async () => {
|
||||||
if (!process.env.DEBUG) {
|
if (!process.env.DEBUG) {
|
||||||
@@ -369,16 +366,16 @@ cron.schedule('*/60 * * * *', async () => {
|
|||||||
|
|
||||||
// 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 }).then((item) => {
|
await Newstosent.findOneAndUpdate({_id: rec.id}, {$set: rec}, {new: false}).
|
||||||
|
then((item) => {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -390,24 +387,29 @@ async function resetProcessingJob() {
|
|||||||
|
|
||||||
async function inizia() {
|
async function inizia() {
|
||||||
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
await telegrambot.sendMsgTelegram(tools.FREEPLANET, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
await telegrambot.sendMsgTelegram(tools.FREEPLANET,
|
||||||
|
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!`);
|
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
||||||
|
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
||||||
|
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
||||||
|
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// await telegrambot.sendMsgTelegram(tools.FREEPLANET, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
// await telegrambot.sendMsgTelegram(tools.FREEPLANET, 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!`);
|
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
||||||
|
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
||||||
|
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
||||||
|
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
// telegrambot.sendMsgTelegramToTheManagers('7', 'PROVAAA!');
|
// telegrambot.sendMsgTelegramToTheManagers('7', 'PROVAAA!');
|
||||||
|
|
||||||
// if (process.env.PROD !== 1) {
|
// if (process.env.PROD !== 1) {
|
||||||
@@ -446,14 +448,13 @@ async function faitest() {
|
|||||||
|
|
||||||
const langdest = 'it';
|
const langdest = 'it';
|
||||||
|
|
||||||
telegrambot.askConfirmationUserRegistration(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser, 'perseo77', langdest);
|
telegrambot.askConfirmationUserRegistration(myuser.idapp,
|
||||||
|
shared_consts.CallFunz.REGISTRATION, myuser, 'perseo77', langdest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
|
|
||||||
|
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
idapp: 12,
|
idapp: 12,
|
||||||
username: 'paolotest1',
|
username: 'paolotest1',
|
||||||
@@ -462,13 +463,11 @@ 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;
|
||||||
@@ -505,5 +504,5 @@ async function faitest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { app };
|
module.exports = {app};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user