- Mail in a Box: comandi per aggiungere/modificare/rimuovere le caselle di posta

- aggiunto idMyGroup: ospiti siti di gruppi (AbitareGliIblei)
This commit is contained in:
Surya Paolo
2024-09-12 14:49:00 +02:00
parent 13322a7e0b
commit f25e1f3992
18 changed files with 625 additions and 57 deletions

View File

@@ -40,3 +40,6 @@ FTPSERVER_USER=ftpusrsrv_
FTPSERVER_PWD=ftpmypwd@1A_ FTPSERVER_PWD=ftpmypwd@1A_
AUTH_NEW_SITES=123123123 AUTH_NEW_SITES=123123123
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}] 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

View File

@@ -32,3 +32,6 @@ AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNV
DOMAINS=[{"hostname":"test.abitaregliiblei.it","port":"3021"}] DOMAINS=[{"hostname":"test.abitaregliiblei.it","port":"3021"}]
SCRIPTS_DIR=admin_scripts SCRIPTS_DIR=admin_scripts
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}] 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

View File

@@ -27,6 +27,7 @@ SYNC_ITEMS=(
"emails" "emails"
"plugins" "plugins"
"sass" "sass"
"admin_scripts"
"src" "src"
) )

View File

@@ -6,7 +6,7 @@ span hai dimenticato la Password? : 
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br> strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
span Email:&nbsp; span Email:&nbsp;
strong #{emailto}<br> strong #{emailto}<br>
p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}: p Per confermare la registrazione clicca sul bottone, oppure <a href=#{strlinkreg} target="_blank">CLICCA QUI</a>
div.divbtn <a href=#{strlinkreg} target="_blank"> div.divbtn <a href=#{strlinkreg} target="_blank">
button.btn.btn-lg Verifica Registrazione</a> button.btn.btn-lg Verifica Registrazione</a>

View File

@@ -6,7 +6,7 @@ span hai dimenticato la Password? :&nbsp;
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br> strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
span Email:&nbsp; span Email:&nbsp;
strong #{emailto}<br> strong #{emailto}<br>
p Per confermare la registrazione clicca sul bottone oppure clicca qui #{strlinkreg}: p Per confermare la registrazione clicca sul bottone, oppure <a href=#{strlinkreg} target="_blank">CLICCA QUI</a>
div.divbtn <a href=#{strlinkreg} target="_blank"> div.divbtn <a href=#{strlinkreg} target="_blank">
button.btn.btn-lg Verifica Registrazione</a> button.btn.btn-lg Verifica Registrazione</a>

View File

@@ -6,7 +6,7 @@ span hai dimenticato la Password? :&nbsp;
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br> strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
span Email:&nbsp; span Email:&nbsp;
strong #{emailto}<br> strong #{emailto}<br>
p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}: p Per confermare la registrazione clicca sul bottone, oppure <a href=#{strlinkreg} target="_blank">CLICCA QUI</a>
div.divbtn <a href=#{strlinkreg} target="_blank"> div.divbtn <a href=#{strlinkreg} target="_blank">
button.btn.btn-lg Verifica Registrazione</a> button.btn.btn-lg Verifica Registrazione</a>

View File

@@ -6,7 +6,7 @@ span hai dimenticato la Password? :&nbsp;
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br> strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
span Email:&nbsp; span Email:&nbsp;
strong #{emailto}<br> strong #{emailto}<br>
p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}: p Per confermare la registrazione clicca sul bottone, oppure <a href=#{strlinkreg} target="_blank">CLICCA QUI</a>
div.divbtn <a href=#{strlinkreg} target="_blank"> div.divbtn <a href=#{strlinkreg} target="_blank">
button.btn.btn-lg Verifica Registrazione</a> button.btn.btn-lg Verifica Registrazione</a>

View File

@@ -64,6 +64,18 @@ const SiteSchema = new Schema({
cf_zoneId: { cf_zoneId: {
type: String, type: String,
}, },
servermail: {
type: String,
},
servermailip: {
type: String,
},
dkim: {
type: String,
},
enable_servermail: {
type: Boolean,
},
portapp: { portapp: {
type: String, type: String,
}, },
@@ -220,7 +232,10 @@ const SiteSchema = new Schema({
ecomm: { ecomm: {
enablePreOrders: { type: Boolean, default: false }, enablePreOrders: { type: Boolean, default: false },
NoteExtraOnCart: { type: String, default: '' }, NoteExtraOnCart: { type: String, default: '' },
} },
idMyGroup: {
type: String,
},
}); });
var Site = module.exports = mongoose.model('Site', SiteSchema); var Site = module.exports = mongoose.model('Site', SiteSchema);
@@ -291,6 +306,8 @@ module.exports.findAllIdApp = async function (idapp) {
rec.email_pwd = ''; rec.email_pwd = '';
rec.telegram_key = ''; rec.telegram_key = '';
rec.telegram_key_test = ''; rec.telegram_key_test = '';
rec.cf_token = '';
rec.cf_zoneId = '';
// rec.confsite = {}; // rec.confsite = {};
return rec; return rec;

View File

@@ -63,7 +63,9 @@ const UserSchema = new mongoose.Schema({
type: String, type: String,
required: true, required: true,
}, },
idMyGroup: {
type: String,
},
group: { group: {
type: Number, type: Number,
}, },
@@ -956,6 +958,7 @@ UserSchema.statics.getProjectUser = function () {
sospeso: 1, sospeso: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.username_telegram': 1, 'profile.username_telegram': 1,
'profile.firstname_telegram': 1, 'profile.firstname_telegram': 1,
@@ -1876,6 +1879,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1, username_who_report: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.mygroups': 1, 'profile.mygroups': 1,
'profile.mycircuits': 1, 'profile.mycircuits': 1,
@@ -1921,6 +1925,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1, username_who_report: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.mygroups': 1, 'profile.mygroups': 1,
'profile.mycircuits': 1, 'profile.mycircuits': 1,
@@ -1966,6 +1971,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
username_who_report: 1, username_who_report: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
notask_verif: 1, notask_verif: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.mygroups': 1, 'profile.mygroups': 1,
@@ -3338,6 +3344,7 @@ function getWhatToShow(idapp, username) {
username_who_report: 1, username_who_report: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
notask_verif: 1, notask_verif: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.mygroups': 1, 'profile.mygroups': 1,
@@ -3376,6 +3383,7 @@ function getWhatToShow_Unknown(idapp, username) {
// sospeso: 1, // sospeso: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.username_telegram': 1, 'profile.username_telegram': 1,
'profile.img': 1, 'profile.img': 1,
'profile.sex': 1, 'profile.sex': 1,
@@ -3404,6 +3412,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
verified_email: 1, verified_email: 1,
'profile.username_telegram': 1, 'profile.username_telegram': 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.img': 1, 'profile.img': 1,
'profile.sex': 1, 'profile.sex': 1,
'profile.born_province': 1, 'profile.born_province': 1,
@@ -4021,6 +4030,7 @@ UserSchema.statics.getUsersList = function (idapp) {
lasttimeonline: 1, lasttimeonline: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
made_gift: 1, made_gift: 1,
perm: 1, perm: 1,
email: 1, email: 1,
@@ -4449,6 +4459,7 @@ UserSchema.statics.getLastUsers = async function (idapp) {
surname: 1, surname: 1,
lasttimeonline: 1, lasttimeonline: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.img': 1, 'profile.img': 1,
date_reg: 1, date_reg: 1,
index: 1, index: 1,
@@ -4479,6 +4490,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
lasttimeonline: 1, lasttimeonline: 1,
date_reg: 1, date_reg: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.img': 1, 'profile.img': 1,
index: 1, index: 1,
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => { }).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
@@ -4506,6 +4518,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
surname: 1, surname: 1,
lasttimeonline: 1, lasttimeonline: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
date_reg: 1, date_reg: 1,
'profile.img': 1, 'profile.img': 1,
index: 1, index: 1,
@@ -4555,6 +4568,7 @@ UserSchema.statics.checkUser = async function (idapp, username) {
return await User.findOne({ idapp, username }, { return await User.findOne({ idapp, username }, {
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
notask_verif: 1, notask_verif: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.teleg_checkcode': 1, 'profile.teleg_checkcode': 1,

View File

@@ -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

View File

@@ -2,6 +2,8 @@ const axios = require('axios');
const apiUrl = 'https://api.cloudflare.com/client/v4'; // Endpoint const apiUrl = 'https://api.cloudflare.com/client/v4'; // Endpoint
const MailinaboxClass = require('./Mailinabox.js');
class CloudFlare { class CloudFlare {
constructor(config) { constructor(config) {
this.config = config ? config : {}; this.config = config ? config : {};
@@ -62,7 +64,7 @@ class CloudFlare {
let modif = (recsite.cf_token !== apiToken) || (recsite.cf_zoneId !== zone.id); let modif = (recsite.cf_token !== apiToken) || (recsite.cf_zoneId !== zone.id);
if (modif) { if (modif && apiToken) {
// update the Site // update the Site
await Site.findOneAndUpdate({ _id: recsite._id }, { await Site.findOneAndUpdate({ _id: recsite._id }, {
@@ -78,6 +80,24 @@ class CloudFlare {
console.error('Errore durante l\'aggiornamento del Site:', error); 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) { } 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) { 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++) { 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 // pause for 3 second
await new Promise(resolve => setTimeout(resolve, 3000)); 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=<dkim>
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) { async setSingleIpsOnDNS(domain, paramobj) {
try { try {
// get the parameters (Token and zoneId on Database) // get the parameters (Token and zoneId on Database)
@@ -154,15 +391,36 @@ class CloudFlare {
if (site.cf_token && site.cf_zoneId) { if (site.cf_token && site.cf_zoneId) {
const myarrrecdns = await this.fetchDNSRecords(site.cf_token, site.cf_zoneId); const myarrrecdns = await this.fetchDNSRecords(site.cf_token, site.cf_zoneId);
// find let nametofind = paramobj.urladd + domain;
let recTypeA = await myarrrecdns.find((rec) => rec.type === 'A' && (rec.name === (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); console.error('e', e);
} }
} }
} }
module.exports = CloudFlare module.exports = CloudFlare

View File

@@ -1202,7 +1202,7 @@ router.post('/cloudflare', authenticate, async (req, res) => {
tokcheck = req.body.tokcheck; tokcheck = req.body.tokcheck;
dnsRecordId = req.body.dnsRecordId; dnsRecordId = req.body.dnsRecordId;
record = req.body.record; 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'); const CloudFlareClass = require('../modules/Cloudflare.js');
@@ -1224,6 +1224,8 @@ router.post('/cloudflare', authenticate, async (req, res) => {
result = await cf.fetchDNSRecords(tok, zoneId); result = await cf.fetchDNSRecords(tok, zoneId);
} else if (cmd === "setRecordDNS") { } else if (cmd === "setRecordDNS") {
result = await cf.updateDNSRecord(tok, zoneId, dnsRecordId, record); result = await cf.updateDNSRecord(tok, zoneId, dnsRecordId, record);
} else if (cmd === "delRecordDNS") {
result = await cf.deleteDNSRecord(tok, zoneId, dnsRecordId);
} else if (cmd === "setCorrectIpsOnDNS") { } else if (cmd === "setCorrectIpsOnDNS") {
result = await cf.setCorrectIpsOnDNS(record); result = await cf.setCorrectIpsOnDNS(record);
} else if (cmd === "gettok") { } 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; module.exports = router;

View File

@@ -1283,9 +1283,11 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
telegrambot.sendMsgTelegramToTheManagers(idapp, text); 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: '' });
}
} }
} }

View File

@@ -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) { if (id_aportador) {
// Ottiene l'username "corretto" (senza maiuscole o minuscole) // Ottiene l'username "corretto" (senza maiuscole o minuscole)

View File

@@ -642,12 +642,14 @@ module.exports = {
mylocalsconf.dataemail.disclaimer) : ''; mylocalsconf.dataemail.disclaimer) : '';
mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.disc_bottom) : ''; 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_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.templ.testoheadermail) : ''; mylocalsconf.dataemail.templ.testoheadermail) : '';
mylocalsconf.dataemail.templ.content = !!mylocalsconf.dataemail.templ.content ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.content = !!mylocalsconf.dataemail.templ.content ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.templ.content) : ''; mylocalsconf.dataemail.templ.content) : '';
}
} catch (e) { } catch (e) {
console.error('Error replacefields: ' + e); console.error('Error replacefields: ' + e);

View File

@@ -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) { getAskToVerifyReg: function (idapp) {
return this.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg); return this.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg);
}, },
getidMyGroupBySite: function (idapp) { getidMyGroupBySite: function (idapp) {
return this.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg); return this.getparamSiteTableByIdApp(idapp, 'idMyGroup');
}, },
isManagAndAdminDifferent(idapp) { isManagAndAdminDifferent(idapp) {

View File

@@ -949,6 +949,7 @@ module.exports = {
mycities: 1, mycities: 1,
lang: 1, lang: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
idMyGroup: 1,
'profile.img': 1, 'profile.img': 1,
'profile.mygroups': 1, 'profile.mygroups': 1,
'profile.mycircuits': 1, 'profile.mycircuits': 1,
@@ -1032,29 +1033,29 @@ module.exports = {
}, },
CAMPI_PRODUCTINFO: [ CAMPI_PRODUCTINFO: [
{name: 'name', type: ''}, { name: 'name', type: '' },
{name: 'code', type: ''}, { name: 'code', type: '' },
{name: 'description', type: 1}, { name: 'description', type: 1 },
{name: 'link_scheda', type: ''}, { name: 'link_scheda', type: '' },
{name: 'idCatProds', type: ''}, { name: 'idCatProds', type: '' },
{name: 'idSubCatProds', type: ''}, { name: 'idSubCatProds', type: '' },
{name: 'weight', type: ''}, { name: 'weight', type: '' },
{name: 'weight_lordo', type: ''}, { name: 'weight_lordo', type: '' },
{name: 'unit', type: ''}, { name: 'unit', type: '' },
{name: 'unit_lordo', type: ''}, { name: 'unit_lordo', type: '' },
{name: 'size', type: ''}, { name: 'size', type: '' },
{name: 'vegan', type: ''}, { name: 'vegan', type: '' },
{name: 'sfuso', type: ''}, { name: 'sfuso', type: '' },
{name: 'img', type: ''}, { name: 'img', type: '' },
{name: 'image_link', type: ''}, { name: 'image_link', type: '' },
{name: 'link', type: ''}, { name: 'link', type: '' },
{name: 'ingredienti', type: ''}, { name: 'ingredienti', type: '' },
{name: 'valori_nutrizionali', type: ''}, { name: 'valori_nutrizionali', type: '' },
{name: 'author', type: ''}, { name: 'author', type: '' },
{name: 'collezione', type: ''}, { name: 'collezione', type: '' },
{name: 'publisher', type: ''}, { name: 'publisher', type: '' },
{name: 'numpages', type: ''}, { name: 'numpages', type: '' },
{name: 'note', type: ''}, { name: 'note', type: '' },
], ],
CAMPI_PRODUCT: [ CAMPI_PRODUCT: [

View File

@@ -1 +1 @@
1.0.57 1.0.58