diff --git a/.env.development b/.env.development
index 49a7e92..2f79ccc 100644
--- a/.env.development
+++ b/.env.development
@@ -40,3 +40,6 @@ FTPSERVER_USER=ftpusrsrv_
FTPSERVER_PWD=ftpmypwd@1A_
AUTH_NEW_SITES=123123123
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
\ No newline at end of file
diff --git a/.env.test.risosrv b/.env.test.risosrv
index 8452225..f7e1c9f 100644
--- a/.env.test.risosrv
+++ b/.env.test.risosrv
@@ -32,3 +32,6 @@ AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNV
DOMAINS=[{"hostname":"test.abitaregliiblei.it","port":"3021"}]
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
\ No newline at end of file
diff --git a/deploynodejs_on_risosrv_test.sh b/deploynodejs_on_risosrv_test.sh
index 50857c0..c63b79e 100755
--- a/deploynodejs_on_risosrv_test.sh
+++ b/deploynodejs_on_risosrv_test.sh
@@ -27,6 +27,7 @@ SYNC_ITEMS=(
"emails"
"plugins"
"sass"
+ "admin_scripts"
"src"
)
diff --git a/emails/registration/it/html.pug b/emails/registration/it/html.pug
index c170004..6304c9d 100755
--- a/emails/registration/it/html.pug
+++ b/emails/registration/it/html.pug
@@ -6,7 +6,7 @@ span hai dimenticato la Password? :
strong Trovala qui
span Email:
strong #{emailto}
-p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}:
+p Per confermare la registrazione clicca sul bottone, oppure CLICCA QUI
div.divbtn
button.btn.btn-lg Verifica Registrazione
diff --git a/emails/registration_ayni/it/html.pug b/emails/registration_ayni/it/html.pug
index b5923fa..4f92d86 100755
--- a/emails/registration_ayni/it/html.pug
+++ b/emails/registration_ayni/it/html.pug
@@ -6,7 +6,7 @@ span hai dimenticato la Password? :
strong Trovala qui
span Email:
strong #{emailto}
-p Per confermare la registrazione clicca sul bottone oppure clicca qui #{strlinkreg}:
+p Per confermare la registrazione clicca sul bottone, oppure CLICCA QUI
div.divbtn
button.btn.btn-lg Verifica Registrazione
diff --git a/emails/registration_cnm/it/html.pug b/emails/registration_cnm/it/html.pug
index c170004..6304c9d 100755
--- a/emails/registration_cnm/it/html.pug
+++ b/emails/registration_cnm/it/html.pug
@@ -6,7 +6,7 @@ span hai dimenticato la Password? :
strong Trovala qui
span Email:
strong #{emailto}
-p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}:
+p Per confermare la registrazione clicca sul bottone, oppure CLICCA QUI
div.divbtn
button.btn.btn-lg Verifica Registrazione
diff --git a/emails/registration_sip/it/html.pug b/emails/registration_sip/it/html.pug
index c170004..6304c9d 100755
--- a/emails/registration_sip/it/html.pug
+++ b/emails/registration_sip/it/html.pug
@@ -6,7 +6,7 @@ span hai dimenticato la Password? :
strong Trovala qui
span Email:
strong #{emailto}
-p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}:
+p Per confermare la registrazione clicca sul bottone, oppure CLICCA QUI
div.divbtn
button.btn.btn-lg Verifica Registrazione
diff --git a/src/server/models/site.js b/src/server/models/site.js
index 4429ddc..a866c52 100755
--- a/src/server/models/site.js
+++ b/src/server/models/site.js
@@ -64,6 +64,18 @@ const SiteSchema = new Schema({
cf_zoneId: {
type: String,
},
+ servermail: {
+ type: String,
+ },
+ servermailip: {
+ type: String,
+ },
+ dkim: {
+ type: String,
+ },
+ enable_servermail: {
+ type: Boolean,
+ },
portapp: {
type: String,
},
@@ -220,7 +232,10 @@ const SiteSchema = new Schema({
ecomm: {
enablePreOrders: { type: Boolean, default: false },
NoteExtraOnCart: { type: String, default: '' },
- }
+ },
+ idMyGroup: {
+ type: String,
+ },
});
var Site = module.exports = mongoose.model('Site', SiteSchema);
@@ -291,6 +306,8 @@ module.exports.findAllIdApp = async function (idapp) {
rec.email_pwd = '';
rec.telegram_key = '';
rec.telegram_key_test = '';
+ rec.cf_token = '';
+ rec.cf_zoneId = '';
// rec.confsite = {};
return rec;
diff --git a/src/server/models/user.js b/src/server/models/user.js
index 0ead141..82b208f 100755
--- a/src/server/models/user.js
+++ b/src/server/models/user.js
@@ -63,7 +63,9 @@ const UserSchema = new mongoose.Schema({
type: String,
required: true,
},
-
+ idMyGroup: {
+ type: String,
+ },
group: {
type: Number,
},
@@ -956,6 +958,7 @@ UserSchema.statics.getProjectUser = function () {
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.teleg_id': 1,
'profile.username_telegram': 1,
'profile.firstname_telegram': 1,
@@ -1876,6 +1879,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.nationality': 1,
'profile.mygroups': 1,
'profile.mycircuits': 1,
@@ -1921,6 +1925,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.nationality': 1,
'profile.mygroups': 1,
'profile.mycircuits': 1,
@@ -1966,6 +1971,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
notask_verif: 1,
'profile.nationality': 1,
'profile.mygroups': 1,
@@ -3338,6 +3344,7 @@ function getWhatToShow(idapp, username) {
username_who_report: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
notask_verif: 1,
'profile.nationality': 1,
'profile.mygroups': 1,
@@ -3376,6 +3383,7 @@ function getWhatToShow_Unknown(idapp, username) {
// sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.username_telegram': 1,
'profile.img': 1,
'profile.sex': 1,
@@ -3404,6 +3412,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
verified_email: 1,
'profile.username_telegram': 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.img': 1,
'profile.sex': 1,
'profile.born_province': 1,
@@ -4021,6 +4030,7 @@ UserSchema.statics.getUsersList = function (idapp) {
lasttimeonline: 1,
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
made_gift: 1,
perm: 1,
email: 1,
@@ -4449,6 +4459,7 @@ UserSchema.statics.getLastUsers = async function (idapp) {
surname: 1,
lasttimeonline: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.img': 1,
date_reg: 1,
index: 1,
@@ -4479,6 +4490,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
lasttimeonline: 1,
date_reg: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.img': 1,
index: 1,
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
@@ -4506,6 +4518,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
surname: 1,
lasttimeonline: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
date_reg: 1,
'profile.img': 1,
index: 1,
@@ -4555,6 +4568,7 @@ UserSchema.statics.checkUser = async function (idapp, username) {
return await User.findOne({ idapp, username }, {
verified_email: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
notask_verif: 1,
'profile.teleg_id': 1,
'profile.teleg_checkcode': 1,
diff --git a/src/server/modules/Mailinabox.js b/src/server/modules/Mailinabox.js
new file mode 100644
index 0000000..b05da6e
--- /dev/null
+++ b/src/server/modules/Mailinabox.js
@@ -0,0 +1,218 @@
+const axios = require('axios');
+
+const apiUrl = 'https://api.cloudflare.com/client/v4'; // Endpoint
+
+class Mailinabox {
+ constructor(config) {
+ this.config = config ? config : {};
+ if (!this.config.miabHost) {
+ this.config.miabHost = process.env.MIAB_HOST;
+ this.config.adminEmail = process.env.MIAB_ADMIN_EMAIL;
+ this.config.adminPassword = process.env.MIAB_ADMIN_PASSWORD;
+ }
+
+ }
+
+ init() {
+ if (this.config.arrTokens) {
+ this.zones = [];
+ }
+ }
+
+ checkIfParamOk() {
+ if (!this.config.miabHost || !this.config.adminEmail || !this.config.adminPassword) {
+ console.error('Configurazione mancante per il recupero del record DKIM.');
+ return false;
+ }
+
+ return true;
+ }
+
+
+ // Funzione per ottenere il record DKIM
+ async getDKIMRecord(domain) {
+
+ if (!this.checkIfParamOk()) {
+ return '';
+ }
+
+ const url = `https://${this.config.miabHost}/admin/dns/zonefile/${domain}`;
+ const auth = Buffer.from(`${this.config.adminEmail}:${this.config.adminPassword}`).toString('base64');
+
+ try {
+ const response = await axios.get(url, {
+ headers: {
+ 'Authorization': `Basic ${auth}`
+ }
+ });
+
+ // console.log(`Record DNS esterni per ${config.domain}:`);
+
+ // Analizza la risposta per estrarre i record DNS
+ const records = response.data.split('\n')
+ .filter(line => line.trim() !== '' && !line.startsWith(';'))
+ .map(line => line.trim());
+
+ // Trova e stampa il record DKIM
+ const dkimRecord = records.find(record => record.includes('mail._domainkey'));
+ if (dkimRecord) {
+ const pMatch = dkimRecord.match(/p=([A-Za-z0-9+/]+)/);
+ if (pMatch && pMatch[1]) {
+ // console.log('Valore di p nel record DKIM:');
+ // console.log(pMatch[1]);
+ return pMatch[1];
+ } else {
+ console.log('Record DKIM non trovato.');
+ }
+ }
+
+ return '';
+
+ } catch (error) {
+ console.error('Errore nel recupero del record DKIM:', error.message);
+ if (error.response) {
+ console.error('Dettagli errore:', error.response.data);
+ }
+ }
+
+ return '';
+ }
+
+ async MIAB_getEmails(myrec) {
+
+ if (!this.checkIfParamOk() || !myrec.domain) {
+ return;
+ }
+
+ const url = `https://${this.config.miabHost}/admin/mail/users?format=text`;
+ const auth = Buffer.from(`${this.config.adminEmail}:${this.config.adminPassword}`).toString('base64');
+
+ try {
+ const response = await axios.get(url, {
+ headers: {
+ 'Authorization': `Basic ${auth}`
+ }
+ });
+
+ const records = response.data.split('\n')
+ .filter(line => line.trim() !== '' && line.indexOf(myrec.domain) > -1)
+ .map(line => line.trim());
+
+ return records;
+
+ } catch (error) {
+ console.error('Errore nel recupero delle Email ', error.message);
+ if (error.response) {
+ console.error('Dettagli errore:', error.response.data);
+ }
+ }
+
+ return '';
+ }
+ async removeEmail(myrec) {
+
+ if (!this.checkIfParamOk() || !myrec.email) {
+ return;
+ }
+
+ const url = `https://${this.config.miabHost}/admin/mail/users/remove`;
+ const auth = Buffer.from(`${this.config.adminEmail}:${this.config.adminPassword}`).toString('base64');
+
+ try {
+ const myrecout = `email=${myrec.email}`;
+
+ const response = await axios.post(url, myrecout, {
+ headers: {
+ 'Authorization': `Basic ${auth}`
+ }
+ });
+
+ const ris = response.data;
+
+ return ris;
+
+ } catch (error) {
+ console.error('Errore nella cancellazione della Email ' + record.email, error.message);
+ if (error.response) {
+ console.error('Dettagli errore:', error.response.data);
+ }
+ }
+
+ return '';
+ }
+ async addEmail(myrec) {
+
+ if (!this.checkIfParamOk() || !myrec.email) {
+ return;
+ }
+
+ const url = `https://${this.config.miabHost}/admin/mail/users/add`;
+ const auth = Buffer.from(`${this.config.adminEmail}:${this.config.adminPassword}`).toString('base64');
+
+ try {
+ let privileges = myrec.privileges ? 'admin' : ''
+ const myrecout = `email=${myrec.email}&password=${myrec.pwd}&privileges="${privileges}"`;
+
+ const response = await axios.post(url, myrecout, {
+ headers: {
+ 'Authorization': `Basic ${auth}`
+ }
+ });
+
+ const ris = response.data;
+
+ return ris;
+
+ } catch (error) {
+ console.error('Errore nella creazione della Email ' + record.email, error.message);
+ if (error.response) {
+ console.error('Dettagli errore:', error.response.data);
+ }
+ }
+
+ return '';
+ }
+ async setMailUserPassword(myrec) {
+
+ if (!this.checkIfParamOk() || !myrec.email) {
+ return;
+ }
+
+ const url = `https://${this.config.miabHost}/admin/mail/users/password`;
+ const auth = Buffer.from(`${this.config.adminEmail}:${this.config.adminPassword}`).toString('base64');
+
+ try {
+
+ let data = `email=${myrec.email}&password=${myrec.pwd}`;
+
+ const response = await axios.post(url,
+ data,
+ {
+ headers: {
+ 'Authorization': `Basic ${auth}`,
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ }
+ });
+
+ let ris = '';
+
+ if (response.status === 200) {
+ ris = `Password cambiata con successo per ${myrec.email}`;
+ } else {
+ ris = `Errore nel cambio password per ${myrec.email}`;
+ }
+
+ return ris;
+
+ } catch (error) {
+ console.error('Errore nella creazione della Email ' + record.email, error.message);
+ if (error.response) {
+ console.error('Dettagli errore:', error.response.data);
+ }
+ }
+
+ return '';
+ }
+}
+
+module.exports = Mailinabox
\ No newline at end of file
diff --git a/src/server/modules/cloudflare.js b/src/server/modules/cloudflare.js
index 5691604..7df32f0 100644
--- a/src/server/modules/cloudflare.js
+++ b/src/server/modules/cloudflare.js
@@ -2,6 +2,8 @@ const axios = require('axios');
const apiUrl = 'https://api.cloudflare.com/client/v4'; // Endpoint
+const MailinaboxClass = require('./Mailinabox.js');
+
class CloudFlare {
constructor(config) {
this.config = config ? config : {};
@@ -62,7 +64,7 @@ class CloudFlare {
let modif = (recsite.cf_token !== apiToken) || (recsite.cf_zoneId !== zone.id);
- if (modif) {
+ if (modif && apiToken) {
// update the Site
await Site.findOneAndUpdate({ _id: recsite._id }, {
@@ -78,6 +80,24 @@ class CloudFlare {
console.error('Errore durante l\'aggiornamento del Site:', error);
});
}
+
+ // Controlla se ho il DKIM !
+
+ if (recsite.enable_servermail && !recsite.dkim) {
+ let miab = new MailinaboxClass(null);
+ miab.init();
+
+ const dkim = await miab.getDKIMRecord(recsite.host);
+
+ if (dkim) {
+ await Site.findOneAndUpdate({ _id: recsite._id }, {
+ $set: {
+ dkim,
+ }
+ })
+
+ }
+ }
}
} catch (error) {
@@ -130,18 +150,235 @@ class CloudFlare {
}
}
+ // Funzione per creare un record DNS di CloudFlare
+ async createDNSRecord(apiToken, zoneId, dnsRecordData) {
+ const apiUrlDNS = apiUrl + `/zones/${zoneId}/dns_records`;
+ try {
+ const response = await axios.post(apiUrlDNS, dnsRecordData, {
+ headers: {
+ 'Authorization': `Bearer ${apiToken}`, // Autenticazione con token
+ 'Content-Type': 'application/json' // Tipo di contenuto
+ }
+ });
+ const createdRecord = response.data.result;
+ console.log('Record DNS creato:', createdRecord);
+
+ return createdRecord;
+ // Stampa il record DNS creato
+ } catch (error) {
+ console.error('Errore durante la creazione del record DNS:', error.message);
+ }
+ }
+
+ // Funzione per cancellare un record DNS di CloudFlare
+ async deleteDNSRecord(apiToken, zoneId, dnsRecordId) {
+ const apiUrlDNS = apiUrl + `/zones/${zoneId}/dns_records/${dnsRecordId}`;
+ try {
+ const response = await axios.delete(apiUrlDNS, {
+ headers: {
+ 'Authorization': `Bearer ${apiToken}`, // Autenticazione con token
+ 'Content-Type': 'application/json' // Tipo di contenuto
+ }
+ });
+ const deletedRecord = response.data.result;
+ console.log('Record DNS cancellato:', deletedRecord);
+
+ return deletedRecord;
+ } catch (error) {
+ console.error('Errore durante la cancellazione del record DNS:', error.message);
+ }
+ }
+
+
async setCorrectIpsOnDNS(domainrec) {
- const arrparams = [{ urladd: '', paramsite: 'host_ip' }, { urladd: 'test.', paramsite: 'host_test_ip' }, { urladd: 'api.', paramsite: 'host_api_ip' }, { urladd: 'testapi.', paramsite: 'host_testapi_ip' }]
+ const arrparams = [{ urladd: '', paramsite: 'host_ip', type: 'A' },
+ { urladd: 'test.', paramsite: 'host_test_ip', type: 'A' },
+ { urladd: 'api.', paramsite: 'host_api_ip', type: 'A' },
+ { urladd: 'testapi.', paramsite: 'host_testapi_ip', type: 'A' },
+ { urladd: 'www.', paramsite: 'host', type: 'CNAME' },
+ ]
for (let i = 0; i < arrparams.length; i++) {
- this.setSingleIpsOnDNS(domainrec.name, arrparams[i])
+ await this.setSingleIpsOnDNS(domainrec.name, arrparams[i])
}
+ // Set Server Mail
+ await this.setServerMail(domainrec);
+
// pause for 3 second
await new Promise(resolve => setTimeout(resolve, 3000));
}
+ async setServerMail(domainrec) {
+
+ try {
+ // get the parameters (Token and zoneId on Database)
+ const Site = require('../models/site');
+
+ await Site.findOne({ host: domainrec.name }).lean()
+ .then(async (site) => {
+ if (site) {
+
+ if (site.cf_token && site.cf_zoneId) {
+ const myarrrecdns = await this.fetchDNSRecords(site.cf_token, site.cf_zoneId);
+
+ // MX:
+ let recTypeMX = await myarrrecdns.find((rec) => rec.type === 'MX' && (rec.name === (domainrec.name)));
+
+ if (recTypeMX) {
+ if (recTypeMX.content !== site.servermail) {
+ recTypeMX.content = site.servermail;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recTypeMX.id, recTypeMX);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: 'MX',
+ name: domainrec.name,
+ content: site.servermail,
+ ttl: 1,
+ proxied: false,
+ priority: 10,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+
+ // TXT record spf1 : TXT nomedominio v=spf1 a mx:box.lamiaposta.org ip4:65.21.63.147 ~all
+
+ let recTypeTXTspf1 = await myarrrecdns.find((rec) => rec.type === 'TXT' && (rec.name === (domainrec.name) && (rec.content.indexOf('v=spf1') > -1)));
+
+ if (site.servermailip) {
+ let contentTXTspf1 = `v=spf1 a mx:${site.servermail} ip4:${site.servermailip} ~all`;
+
+ if (recTypeTXTspf1) {
+ if (recTypeTXTspf1.content !== contentTXTspf1) {
+ recTypeTXTspf1.content = contentTXTspf1;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recTypeTXTspf1.id, recTypeTXTspf1);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: 'TXT',
+ name: domainrec.name,
+ content: contentTXTspf1,
+ ttl: 3600,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+ }
+
+ // mail._domainkey.nomedominio v=DKIM1; h=sha256; k=rsa; s=email; p=
+
+ let nameDkimtoFind = `mail._domainkey.${domainrec.name}`;
+
+ let recTypeTXTDKIM = await myarrrecdns.find((rec) => rec.type === 'TXT' && (rec.name === nameDkimtoFind));
+
+ if (site.dkim) {
+ let contentTXTDKIM = `v=DKIM1; h=sha256; k=rsa; s=email; p=${site.dkim}`;
+
+ if (recTypeTXTDKIM) {
+ if (recTypeTXTDKIM.content !== contentTXTDKIM) {
+ recTypeTXTDKIM.content = contentTXTDKIM;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recTypeTXTDKIM.id, recTypeTXTDKIM);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: 'TXT',
+ name: nameDkimtoFind,
+ content: contentTXTDKIM,
+ ttl: 1,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+ }
+
+ // DMARC:
+
+ let nameDmarctoFind = `_dmarc.${domainrec.name}`;
+
+ let recTypeTXTdmarc = await myarrrecdns.find((rec) => rec.type === 'TXT' && (rec.name === (nameDmarctoFind) && (rec.content.indexOf('v=DMARC1') > -1)));
+
+ if (site.servermailip) {
+ let contentTXTdmarc = `v=DMARC1; p=quarantine; ruf=mailto:dmarc@${domainrec.name};`;
+
+ if (recTypeTXTdmarc) {
+ if (recTypeTXTdmarc.content !== contentTXTdmarc) {
+ recTypeTXTdmarc.content = contentTXTdmarc;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recTypeTXTspf1.id, recTypeTXTspf1);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: 'TXT',
+ name: nameDmarctoFind,
+ content: contentTXTdmarc,
+ ttl: 1,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+ }
+
+ // AutoConfig:
+ let myType = 'CNAME';
+ let strfind = `autoconfig.${domainrec.name}`;
+ let contentExpected = site.servermail;
+ let rectofind = await myarrrecdns.find((rec) => rec.type === 'CNAME' && (rec.name === strfind));
+
+ if (rectofind) {
+ if (rectofind.content !== contentExpected) {
+ rectofind.content = contentExpected;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, rectofind.id, rectofind);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: myType,
+ name: strfind,
+ content: contentExpected,
+ ttl: 1,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+
+ // AutoDiscover:
+ myType = 'CNAME';
+ strfind = `autodiscover.${domainrec.name}`;
+ contentExpected = site.servermail;
+ rectofind = await myarrrecdns.find((rec) => rec.type === 'CNAME' && (rec.name === strfind));
+
+ if (rectofind) {
+ if (rectofind.content !== contentExpected) {
+ rectofind.content = contentExpected;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, rectofind.id, rectofind);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: myType,
+ name: strfind,
+ content: contentExpected,
+ ttl: 1,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+
+ }
+ }
+ });
+
+ } catch (e) {
+ console.error('e', e);
+ }
+ }
+
async setSingleIpsOnDNS(domain, paramobj) {
try {
// get the parameters (Token and zoneId on Database)
@@ -154,15 +391,36 @@ class CloudFlare {
if (site.cf_token && site.cf_zoneId) {
const myarrrecdns = await this.fetchDNSRecords(site.cf_token, site.cf_zoneId);
- // find
- let recTypeA = await myarrrecdns.find((rec) => rec.type === 'A' && (rec.name === (paramobj.urladd + domain)));
+ let nametofind = paramobj.urladd + domain;
+
+ // find
+ let recType = await myarrrecdns.find((rec) => rec.type === paramobj.type && (rec.name === nametofind));
+
+ let paramexpected = '';
+ try {
+ paramexpected = site[paramobj.paramsite];
+ } catch (e) {
- if (recTypeA && site[paramobj.paramsite]) {
- if (recTypeA.content !== site[paramobj.paramsite]) {
- recTypeA.content = site[paramobj.paramsite];
- return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recTypeA.id, recTypeA);
- }
}
+
+ if (recType && paramexpected) {
+ if (recType.content !== paramexpected) {
+ recType.content = paramexpected;
+ return this.updateDNSRecord(site.cf_token, site.cf_zoneId, recType.id, recType);
+ }
+ } else {
+ // create a new record
+ const newRecord = {
+ type: paramobj.type,
+ name: nametofind,
+ content: paramexpected,
+ ttl: 1,
+ proxied: true,
+ };
+
+ await this.createDNSRecord(site.cf_token, site.cf_zoneId, newRecord);
+ }
+
}
}
});
@@ -171,6 +429,7 @@ class CloudFlare {
console.error('e', e);
}
}
+
}
module.exports = CloudFlare
\ No newline at end of file
diff --git a/src/server/router/admin_router.js b/src/server/router/admin_router.js
index 7848dbb..97c4e20 100755
--- a/src/server/router/admin_router.js
+++ b/src/server/router/admin_router.js
@@ -1202,7 +1202,7 @@ router.post('/cloudflare', authenticate, async (req, res) => {
tokcheck = req.body.tokcheck;
dnsRecordId = req.body.dnsRecordId;
record = req.body.record;
- console.log('/cloudflare idapp=', idapp, req.body.script);
+ // console.log('/cloudflare idapp=', idapp, req.body.script);
const CloudFlareClass = require('../modules/Cloudflare.js');
@@ -1224,6 +1224,8 @@ router.post('/cloudflare', authenticate, async (req, res) => {
result = await cf.fetchDNSRecords(tok, zoneId);
} else if (cmd === "setRecordDNS") {
result = await cf.updateDNSRecord(tok, zoneId, dnsRecordId, record);
+ } else if (cmd === "delRecordDNS") {
+ result = await cf.deleteDNSRecord(tok, zoneId, dnsRecordId);
} else if (cmd === "setCorrectIpsOnDNS") {
result = await cf.setCorrectIpsOnDNS(record);
} else if (cmd === "gettok") {
@@ -1238,4 +1240,43 @@ router.post('/cloudflare', authenticate, async (req, res) => {
});
+router.post('/miab', authenticate, async (req, res) => {
+ try {
+ idapp = req.body.idapp;
+ cmd = req.body.cmd;
+ record = req.body.record;
+ tokcheck = req.body.tokcheck;
+
+ const MailinaboxClass = require('../modules/Mailinabox.js');
+
+ const TOKCHECK = 'php8.1_version_762321HSD121nJDokq@?!aFS.tar.gz'
+
+ if (!User.isAdmin(req.user.perm) || (tokcheck !== TOKCHECK)) {
+ // If without permissions, exit
+ return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
+ }
+
+ let result = '';
+
+ let miab = new MailinaboxClass(null);
+ miab.init();
+
+ if (cmd === "getEmails") {
+ result = await miab.MIAB_getEmails(record);
+ } else if (cmd === "removeEmails") {
+ result = await miab.removeEmail(record);
+ } else if (cmd === "addEmail") {
+ result = await miab.addEmail(record);
+ } else if (cmd === "setMailUserPassword") {
+ result = await miab.setMailUserPassword(record);
+ }
+
+ return res.send(result);
+ } catch (e) {
+ console.error('e', e);
+ return res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: '' });
+ }
+
+});
+
module.exports = router;
diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js
index afe0036..256946b 100755
--- a/src/server/router/index_router.js
+++ b/src/server/router/index_router.js
@@ -1283,9 +1283,11 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
telegrambot.sendMsgTelegramToTheManagers(idapp, text);
}
- cancellato = true;
- return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
+ if (!User.isAdmin(req.user.perm)) {
+ cancellato = true;
+ return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
+ }
}
}
diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js
index f8e5a51..39e3e32 100755
--- a/src/server/router/users_router.js
+++ b/src/server/router/users_router.js
@@ -276,8 +276,9 @@ router.post('/', async (req, res) => {
}
}
- if (idMyGroup)
- tools.getidMyGroupBySite(body.idapp)
+
+ let idMyGroupSite = tools.getidMyGroupBySite(body.idapp);
+ user.idMyGroup = idMyGroupSite ? idMyGroupSite : '';
if (id_aportador) {
// Ottiene l'username "corretto" (senza maiuscole o minuscole)
diff --git a/src/server/sendemail.js b/src/server/sendemail.js
index c7aa58f..29791ef 100755
--- a/src/server/sendemail.js
+++ b/src/server/sendemail.js
@@ -642,12 +642,14 @@ module.exports = {
mylocalsconf.dataemail.disclaimer) : '';
mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.disc_bottom) : '';
- if (mylocalsconf.dataemail.templ)
+
+ if (mylocalsconf.dataemail.templ) {
mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.templ.testoheadermail) : '';
- mylocalsconf.dataemail.templ.content = !!mylocalsconf.dataemail.templ.content ? this.fieldsloop(mylocalsconf,
- mylocalsconf.dataemail.templ.content) : '';
+ mylocalsconf.dataemail.templ.content = !!mylocalsconf.dataemail.templ.content ? this.fieldsloop(mylocalsconf,
+ mylocalsconf.dataemail.templ.content) : '';
+ }
} catch (e) {
console.error('Error replacefields: ' + e);
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index eb3ebf8..9ddf00e 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -1902,12 +1902,18 @@ module.exports = {
}
},
+ getparamSiteTableByIdApp: function (idapp, param) {
+ const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
+ return myapp && param ? myapp[param] : '';
+ },
+
+
getAskToVerifyReg: function (idapp) {
return this.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg);
},
getidMyGroupBySite: function (idapp) {
- return this.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg);
+ return this.getparamSiteTableByIdApp(idapp, 'idMyGroup');
},
isManagAndAdminDifferent(idapp) {
diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js
index 62a6c5a..d2354e4 100755
--- a/src/server/tools/shared_nodejs.js
+++ b/src/server/tools/shared_nodejs.js
@@ -50,7 +50,7 @@ module.exports = {
OPTIONS_SEARCH_USER_ONLY_FULL_WORDS: 2,
OPTIONS_SEARCH_USER_ALL_WORDS: 4,
OPTIONS_ADD_COUNT_FAVORITE: 8,
-
+
PROD: {
GAS: 1,
@@ -188,12 +188,12 @@ module.exports = {
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'],
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'attivitas'],
-
+
//++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps'],
-
+
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
-
+
TABLES_VISU_STAT_IN_HOME: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'mygroups', 'circuits'],
TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'],
@@ -202,7 +202,7 @@ module.exports = {
TABLES_EVENTS_NOTIFICATION: ['mybachecas'],
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
-
+
TABLES_NUM_AS_ID_NUMBER: [],
@@ -876,7 +876,7 @@ module.exports = {
idSkill: 1,
idCity: 1,
logo: 1,
- photos: 1,
+ photos: 1,
note: 1,
descr: 1,
website: 1,
@@ -892,7 +892,7 @@ module.exports = {
createdBy: 1,
//**ADDFIELD_ATTIVITA
};
-
+
} else if (table === this.TABLES_MYBACHECAS) {
proj = {
recSkill: 1,
@@ -949,6 +949,7 @@ module.exports = {
mycities: 1,
lang: 1,
verified_by_aportador: 1,
+ idMyGroup: 1,
'profile.img': 1,
'profile.mygroups': 1,
'profile.mycircuits': 1,
@@ -1032,29 +1033,29 @@ module.exports = {
},
CAMPI_PRODUCTINFO: [
- {name: 'name', type: ''},
- {name: 'code', type: ''},
- {name: 'description', type: 1},
- {name: 'link_scheda', type: ''},
- {name: 'idCatProds', type: ''},
- {name: 'idSubCatProds', type: ''},
- {name: 'weight', type: ''},
- {name: 'weight_lordo', type: ''},
- {name: 'unit', type: ''},
- {name: 'unit_lordo', type: ''},
- {name: 'size', type: ''},
- {name: 'vegan', type: ''},
- {name: 'sfuso', type: ''},
- {name: 'img', type: ''},
- {name: 'image_link', type: ''},
- {name: 'link', type: ''},
- {name: 'ingredienti', type: ''},
- {name: 'valori_nutrizionali', type: ''},
- {name: 'author', type: ''},
- {name: 'collezione', type: ''},
- {name: 'publisher', type: ''},
- {name: 'numpages', type: ''},
- {name: 'note', type: ''},
+ { name: 'name', type: '' },
+ { name: 'code', type: '' },
+ { name: 'description', type: 1 },
+ { name: 'link_scheda', type: '' },
+ { name: 'idCatProds', type: '' },
+ { name: 'idSubCatProds', type: '' },
+ { name: 'weight', type: '' },
+ { name: 'weight_lordo', type: '' },
+ { name: 'unit', type: '' },
+ { name: 'unit_lordo', type: '' },
+ { name: 'size', type: '' },
+ { name: 'vegan', type: '' },
+ { name: 'sfuso', type: '' },
+ { name: 'img', type: '' },
+ { name: 'image_link', type: '' },
+ { name: 'link', type: '' },
+ { name: 'ingredienti', type: '' },
+ { name: 'valori_nutrizionali', type: '' },
+ { name: 'author', type: '' },
+ { name: 'collezione', type: '' },
+ { name: 'publisher', type: '' },
+ { name: 'numpages', type: '' },
+ { name: 'note', type: '' },
],
CAMPI_PRODUCT: [
@@ -1108,7 +1109,7 @@ module.exports = {
EPUB: 105,
MOBI: 106,
PDF: 107,
- STREAMING: 108,
+ STREAMING: 108,
},
diff --git a/src/server/version.txt b/src/server/version.txt
index 91cc3fe..4ded4f9 100644
--- a/src/server/version.txt
+++ b/src/server/version.txt
@@ -1 +1 @@
-1.0.57
\ No newline at end of file
+1.0.58
\ No newline at end of file