tolta la richiesta di accettazione dei RIS, che ora vengono accettati automaticamente.

This commit is contained in:
Surya Paolo
2024-07-03 13:22:32 +02:00
parent 1c7b89a55b
commit 76c34dbbe0
10 changed files with 226 additions and 78 deletions

View File

@@ -12,6 +12,8 @@ const cors = require('cors');
// console.log(" 2) fs");
const fs = require('fs');
var https = require('https');
const NUOVO_METODO_TEST = true;
const server_constants = require('./tools/server_constants');
@@ -30,6 +32,8 @@ const path = require('path');
const cron = require('node-cron');
console.log('Starting mongoose...');
const tls = require('tls');
require('./db/mongoose');
// console.log('Starting pem...');
@@ -250,64 +254,111 @@ myLoad().then(ris => {
const keyStream = path.resolve(`./${process.env.PATH_CERT_KEY}`);
const certificateStream = path.resolve(`./${process.env.PATH_SERVER_CRT}`);
const privateKey = fs.readFileSync(keyStream, "utf8");
const certificate = fs.readFileSync(certificateStream, "utf8");
let privateKey = fs.readFileSync(keyStream, "utf8");
let certificate = fs.readFileSync(certificateStream, "utf8");
let credentials = null;
let domain = 'piuchebuono.app';
const keyfile = '/etc/letsencrypt/live/' + domain + '/privkey.pem';
const certfile = '/etc/letsencrypt/live/' + domain + '/fullchain.pem';
arrSecureContext = ['piuchebuono.app', 'gruppomacro.app'];
for (let i = 0; i < arrSecureContext.length; i++) {
let secureContext = tls.createSecureContext({
key: fs.readFileSync('/etc/letsencrypt/live/' + arrSecureContext[i] + '/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/' + arrSecureContext[i] + '/fullchain.pem')
// ca: fs.readFileSync('../path_to_certificate_authority_bundle.ca-bundle1', 'utf8'), // this ca property is optional
});
credentials = {
SNICallback: function (domain, cb) {
if (secureContext) {
if (cb) {
cb(null, secureContext);
} else {
// compatibility for older versions of node
return secureContext;
}
} else {
}
}
}
}
let secureContext = {
'piuchebuono.app': tls.createSecureContext({
key: fs.readFileSync('/etc/letsencrypt/live/piuchebuono.app/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/piuchebuono.app/fullchain.pem')
// ca: fs.readFileSync('../path_to_certificate_authority_bundle.ca-bundle1', 'utf8'), // this ca property is optional
}),
'gruppomacro.app': tls.createSecureContext({
key: fs.readFileSync('/etc/letsencrypt/live/gruppomacro.app/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/gruppomacro.app/fullchain.pem')
// ca: fs.readFileSync('../path_to_certificate_authority_bundle.ca-bundle1', 'utf8'), // this ca property is optional
}),
}
if (NUOVO_METODO_TEST) {
credentials = {
SNICallback: function (domain, cb) {
if (secureContext[domain]) {
if (cb) {
cb(null, secureContext[domain]);
} else {
// compatibility for older versions of node
return secureContext[domain];
}
} else {
throw new Error('No keys/certificates for domain requested');
}
},
// must list a default key and cert because required by tls.createServer()
key: privateKey,
cert: certificate,
};
} else {
// NON USATO !
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');
/*} else {
// NON USATO !
credentials = {
key: privateKey,
cert: certificate,
ca: [
fs.readFileSync(process.env.PATH_SSL_ROOT_PEM, 'utf8'),
fs.readFileSync(process.env.PATH_SSL_CHAIN_PEM, 'utf8'),
],
};
}
/*} else {
*/
}
}
if (process.env.HTTPS_LOCALHOST === "true") {
privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
credentials = {
key: privateKey,
cert: certificate,
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384',
honorCipherOrder: true,
secureProtocol: 'TLSv1_2_method',
};
} else {
if (process.env.HTTPS_LOCALHOST === "true") {
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
credentials = {
key: privateKey,
cert: certificate,
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384',
honorCipherOrder: true,
secureProtocol: 'TLSv1_2_method',
};
var https = require('https');
} else {
var http = require('http');
}
var http = require('http');
}
if ((process.env.NODE_ENV === 'production') ||
(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);
const httpsServer = https.createServer(credentials, app);
console.log('httpsServer: port ', port);
httpsServer.listen(port);
}
console.log('httpsServer: port ', port);
httpsServer.listen(port);
} else {
console.log('httpServer: port ', port);
const httpServer = http.createServer(app);
@@ -316,8 +367,11 @@ myLoad().then(ris => {
mystart();
});
// app.use(throttle(1024 * 128)); // throttling bandwidth
// app.use((req, res, next) => {
@@ -447,6 +501,10 @@ async function mycron_everyday() {
}
}
// Crea un file con all'interno il nome del dominio per ogni app:
await tools.createFileWithDomainName();
} catch (e) {
console.error('mycron_everyday: ', e);
}
@@ -549,9 +607,9 @@ async function inizia() {
await Site.createFirstUserAdmin();
/*const {Circuit} = require('./models/circuit');
await Circuit.setDeperimentoOff();
*/