Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX add option to use master mail server for scripts system #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ allowed_hosts=127.0.0.1,ipofmasterserver
[email protected]
# email supervision
[email protected]
# Option to use mail server of master server (for scripts system)
# usemastermailserver=1

# Set location of the master database
databasehost=ipOfMasterServer or localhost if on master server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ allowed_hosts=127.0.0.1,ipofmasterserver
[email protected]
# email supervision
[email protected]
# Option to use mail server of master server (for scripts system)
# usemastermailserver=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we must just put a flag to say use master server. Because on master server, key (like smtp pass) is encrypted and only the master should be able to uncrypt so it is protected if database is stolen.
If you say to use the pass of the master, it also means you must store the decode key (so $dolibarr_main_instance_unique_id of the master) on the deployment server. This means the pass to encrypt master database fields become public.
I think we should instead store inside the .conf file, the data to use to send email (so the mode to send email, the smtp address and port, login/pass) so only smtp data are leaks on the deployment server instead of all encrypted data of the master.


# Set location of the master database
databasehost=ipOfMasterServer or localhost if on master server
Expand Down
25 changes: 19 additions & 6 deletions scripts/batch_customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
$ipserverdeployment='';
$emailfrom='';
$emailsupervision='';
$usemastermailserver='';
$fp = @fopen('/etc/sellyoursaas.conf', 'r');
// Add each line to an array
if ($fp) {
Expand Down Expand Up @@ -130,6 +131,9 @@
if ($tmpline[0] == 'emailsupervision') {
$emailsupervision = $tmpline[1];
}
if ($tmpline[0] == 'usemastermailserver') {
$usemastermailserver = $tmpline[1];
}
}
} else {
print "Failed to open /etc/sellyoursaas.conf file\n";
Expand Down Expand Up @@ -158,6 +162,11 @@
$from = $emailfrom;
$to = $emailsupervision;
// Supervision tools are generic for all domain. No way to target a specific supervision email.
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

$msg = 'Error in '.$script_file." ".(empty($argv[1]) ? '' : $argv[1])." ".(empty($argv[2]) ? '' : $argv[2])." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n".$dbmaster->error;

Expand Down Expand Up @@ -768,8 +777,10 @@
$from = $emailfrom;
$to = $emailsupervision;
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

$msg = 'Backup done without errors on '.gethostname().' by '.$script_file." ".(empty($argv[1]) ? '' : $argv[1])." ".(empty($argv[2]) ? '' : $argv[2])." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n".$out;

Expand All @@ -784,7 +795,7 @@
}*/

include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
print 'Send email MAIN_MAIL_SENDMODE='.$conf->global->MAIN_MAIL_SENDMODE.' MAIN_MAIL_SMTP_SERVER='.$conf->global->MAIN_MAIL_SMTP_SERVER.' from='.$from.' to='.$to.' title=[Backup instances - '.gethostname().'] Backup of user instances succeed'."\n";
print 'Send email MAIN_MAIL_SENDMODE='.getDolGlobalString('MAIN_MAIL_SENDMODE').' MAIN_MAIL_SMTP_SERVER='.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').' from='.$from.' to='.$to.' title=[Backup instances - '.gethostname().'] Backup of user instances succeed'."\n";
$cmail = new CMailFile('[Backup instances - '.gethostname().'] Backup of user instances succeed', $to, $from, $msg, array(), array(), array(), '', '', 0, 0, '', '', '', '', $sendcontext);
$result = $cmail->sendfile(); // Use the $conf->global->MAIN_MAIL_SMTPS_PW_$SENDCONTEXT for password
} else {
Expand All @@ -799,15 +810,17 @@
$from = $emailfrom;
$to = $emailsupervision;
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = '';
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

// Supervision tools are generic for all domains. No way to target a specific supervision email.

$msg = 'Error in '.$script_file." ".$argv[1]." ".$argv[2]." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n".$out;

include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
print 'Send email MAIN_MAIL_SENDMODE='.$conf->global->MAIN_MAIL_SENDMODE.' MAIN_MAIL_SMTP_SERVER='.$conf->global->MAIN_MAIL_SMTP_SERVER.' from='.$from.' to='.$to.' title=[Warning] Error(s) in backups - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
print 'Send email MAIN_MAIL_SENDMODE='.getDolGlobalString('MAIN_MAIL_SENDMODE').' MAIN_MAIL_SMTP_SERVER='.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').' from='.$from.' to='.$to.' title=[Warning] Error(s) in backups - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
$cmail = new CMailFile('[Warning] Error(s) in backups - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc'), $to, $from, $msg, array(), array(), array(), '', '', 0, 0, '', '', '', '', $sendcontext);
$result = $cmail->sendfile(); // Use the $conf->global->MAIN_MAIL_SMTPS_PW_$SENDCONTEXT for password

Expand Down
12 changes: 9 additions & 3 deletions scripts/batch_detect_evil_instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
$ipserverdeployment='';
$emailfrom='';
$emailsupervision='';
$usemastermailserver='';
$fp = @fopen('/etc/sellyoursaas.conf', 'r');
// Add each line to an array
if ($fp) {
Expand Down Expand Up @@ -119,6 +120,9 @@
if ($tmpline[0] == 'emailsupervision') {
$emailsupervision = $tmpline[1];
}
if ($tmpline[0] == 'usemastermailserver') {
$usemastermailserver = $tmpline[1];
}
}
} else {
print "Failed to open /etc/sellyoursaas.conf file\n";
Expand Down Expand Up @@ -829,15 +833,17 @@
$from = $emailfrom;
$to = $emailsupervision;
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = '';
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

// Supervision tools are generic for all domain. No way to target a specific supervision email.

$msg = 'Error in '.$script_file." ".$argv[1]." ".$argv[2]." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n".$out;

include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
print 'Send email MAIN_MAIL_SENDMODE='.$conf->global->MAIN_MAIL_SENDMODE.' MAIN_MAIL_SMTP_SERVER='.$conf->global->MAIN_MAIL_SMTP_SERVER.' from='.$from.' to='.$to.' title=[Warning] Alert(s) in batch_detect_evil_instances - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
print 'Send email MAIN_MAIL_SENDMODE='.getDolGlobalString('MAIN_MAIL_SENDMODE').' MAIN_MAIL_SMTP_SERVER='.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').' from='.$from.' to='.$to.' title=[Warning] Alert(s) in batch_detect_evil_instances - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
$cmail = new CMailFile('[Alert] Alert(s) in batch_detect_evil_instances - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc'), $to, $from, $msg, array(), array(), array(), '', '', 0, 0, '', '', '', '', $sendcontext);
$result = $cmail->sendfile();
}
Expand Down
20 changes: 14 additions & 6 deletions scripts/restore_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
$usecompressformatforarchive='gzip';
$emailfrom='';
$emailsupervision='';
$usemastermailserver='';
$fp = @fopen('/etc/sellyoursaas.conf', 'r');
// Add each line to an array
if ($fp) {
Expand Down Expand Up @@ -107,6 +108,9 @@
if ($tmpline[0] == 'emailsupervision') {
$emailsupervision = dol_sanitizeEmail($tmpline[1]);
}
if ($tmpline[0] == 'usemastermailserver') {
$usemastermailserver = $tmpline[1];
}
}
} else {
print "Failed to open /etc/sellyoursaas.conf file\n";
Expand Down Expand Up @@ -510,15 +514,17 @@
$from = $emailfrom;
$to = $emailsupervision;
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = '';
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

// Supervision tools are generic for all domain. No way to target a specific supervision email.

$msg = 'Restore done without errors by '.$script_file." ".(empty($argv[1]) ? '' : $argv[1])." ".(empty($argv[2]) ? '' : $argv[2])." ".(empty($argv[3]) ? '' : $argv[3])." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n";

include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
print 'Send email MAIN_MAIL_SENDMODE='.$conf->global->MAIN_MAIL_SENDMODE.' MAIN_MAIL_SMTP_SERVER='.$conf->global->MAIN_MAIL_SMTP_SERVER.' from='.$from.' to='.$to.' title=[Restore instance - '.gethostname().'] Restore of user instance succeed.'."\n";
print 'Send email MAIN_MAIL_SENDMODE='.getDolGlobalString('MAIN_MAIL_SENDMODE').' MAIN_MAIL_SMTP_SERVER='.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').' from='.$from.' to='.$to.' title=[Restore instance - '.gethostname().'] Restore of user instance succeed.'."\n";
$cmail = new CMailFile('[Restore instance - '.gethostname().'] Restore of user instance succeed - '.dol_print_date(dol_now(), 'dayrfc'), $to, $from, $msg, array(), array(), array(), '', '', 0, 0, '', '', '', '', $sendcontext);
$result = $cmail->sendfile(); // Use the $conf->global->MAIN_MAIL_SMTPS_PW_$SENDCONTEXT for password

Expand Down Expand Up @@ -549,15 +555,17 @@
$from = $emailfrom;
$to = $emailsupervision;
// Force to use local sending (MAIN_MAIL_SENDMODE is the one of the master server. It may be to an external SMTP server not allowed to the deployment server)
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = '';
if (empty($usemastermailserver)) {
$conf->global->MAIN_MAIL_SENDMODE = 'mail';
$conf->global->MAIN_MAIL_SMTP_SERVER = 'localhost';
}

// Supervision tools are generic for all domain. No way to target a specific supervision email.

$msg = 'Error in '.$script_file." ".(empty($argv[1]) ? '' : $argv[1])." ".(empty($argv[2]) ? '' : $argv[2])." ".(empty($argv[3]) ? '' : $argv[3])." (finished at ".dol_print_date(dol_now('gmt'), "%Y%m%d-%H%M%S", 'gmt').")\n\n".$return_var."\n".$return_varmysql;

include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
print 'Send email MAIN_MAIL_SENDMODE='.$conf->global->MAIN_MAIL_SENDMODE.' MAIN_MAIL_SMTP_SERVER='.$conf->global->MAIN_MAIL_SMTP_SERVER.' from='.$from.' to='.$to.' title=[Warning] Error(s) in restoring - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
print 'Send email MAIN_MAIL_SENDMODE='.getDolGlobalString('MAIN_MAIL_SENDMODE').' MAIN_MAIL_SMTP_SERVER='.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').' from='.$from.' to='.$to.' title=[Warning] Error(s) in restoring - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc')."\n";
$cmail = new CMailFile('[Warning] Error(s) in restore process - '.gethostname().' - '.dol_print_date(dol_now(), 'dayrfc'), $to, $from, $msg, array(), array(), array(), '', '', 0, 0, '', '', '', '', $sendcontext);
$result = $cmail->sendfile(); // Use the $conf->global->MAIN_MAIL_SMTPS_PW_$SENDCONTEXT for password

Expand Down