Commit 01c27679 authored by Stanislav German-Evtushenko's avatar Stanislav German-Evtushenko Committed by Dietmar Maurer

GUI: add new email_from option to datacenter.cfg

Signed-off-by: 's avatarStanislav German-Evtushenko <ginermail@gmail.com>
parent 1d095287
...@@ -341,10 +341,11 @@ __PACKAGE__->register_method({ ...@@ -341,10 +341,11 @@ __PACKAGE__->register_method({
if ($mailto) { if ($mailto) {
my $hostname = `hostname -f` || PVE::INotify::nodename(); my $hostname = `hostname -f` || PVE::INotify::nodename();
chomp $hostname; chomp $hostname;
my $mailfrom = $dcconf->{email_from} || "root";
my $data = "Content-Type: text/plain;charset=\"UTF8\"\n"; my $data = "Content-Type: text/plain;charset=\"UTF8\"\n";
$data .= "Content-Transfer-Encoding: 8bit\n"; $data .= "Content-Transfer-Encoding: 8bit\n";
$data .= "FROM: <root\@$hostname>\n"; $data .= "FROM: <$mailfrom>\n";
$data .= "TO: $mailto\n"; $data .= "TO: $mailto\n";
$data .= "SUBJECT: New software packages available ($hostname)\n"; $data .= "SUBJECT: New software packages available ($hostname)\n";
$data .= "\n"; $data .= "\n";
...@@ -364,7 +365,7 @@ __PACKAGE__->register_method({ ...@@ -364,7 +365,7 @@ __PACKAGE__->register_method({
return if !$count; return if !$count;
my $fh = IO::File->new("|sendmail -B 8BITMIME $mailto") || my $fh = IO::File->new("|sendmail -B 8BITMIME -f $mailfrom $mailto") ||
die "unable to open 'sendmail' - $!"; die "unable to open 'sendmail' - $!";
print $fh $data; print $fh $data;
......
...@@ -279,8 +279,10 @@ my $sendmail = sub { ...@@ -279,8 +279,10 @@ my $sendmail = sub {
foreach my $r (@$mailto) { foreach my $r (@$mailto) {
$rcvrarg .= " '$r'"; $rcvrarg .= " '$r'";
} }
my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg');
my $mailfrom = $dcconf->{email_from} || "root";
open (MAIL,"|sendmail -B 8BITMIME $rcvrarg") || open (MAIL,"|sendmail -B 8BITMIME -f $mailfrom $rcvrarg") ||
die "unable to open 'sendmail' - $!"; die "unable to open 'sendmail' - $!";
my $rcvrtxt = join (', ', @$mailto); my $rcvrtxt = join (', ', @$mailto);
...@@ -289,7 +291,7 @@ my $sendmail = sub { ...@@ -289,7 +291,7 @@ my $sendmail = sub {
print MAIL "\tboundary=\"$boundary\"\n"; print MAIL "\tboundary=\"$boundary\"\n";
print MAIL "MIME-Version: 1.0\n"; print MAIL "MIME-Version: 1.0\n";
print MAIL "FROM: vzdump backup tool <root>\n"; print MAIL "FROM: vzdump backup tool <$mailfrom>\n";
print MAIL "TO: $rcvrtxt\n"; print MAIL "TO: $rcvrtxt\n";
print MAIL "SUBJECT: vzdump backup status ($hostname) : $stat\n"; print MAIL "SUBJECT: vzdump backup status ($hostname) : $stat\n";
print MAIL "\n"; print MAIL "\n";
......
...@@ -24,12 +24,15 @@ eval { ...@@ -24,12 +24,15 @@ eval {
my $rootcfg = $usercfg->{users}->{'root@pam'} || {}; my $rootcfg = $usercfg->{users}->{'root@pam'} || {};
my $mailto = $rootcfg->{email}; my $mailto = $rootcfg->{email};
my $dcconf = cfs_read_file('datacenter.cfg');
my $mailfrom = $dcconf->{email_from} || "root";
die "user 'root\@pam' does not have a email address\n" if !$mailto; die "user 'root\@pam' does not have a email address\n" if !$mailto;
syslog("info", "forward mail to <$mailto>"); syslog("info", "forward mail to <$mailto>");
# we never send DSN (avoid mail loops) # we never send DSN (avoid mail loops)
open(CMD, "|sendmail -bm -N never $mailto") || open(CMD, "|sendmail -bm -N never -f $mailfrom $mailto") ||
die "can't exec sendmail - $!\n"; die "can't exec sendmail - $!\n";
while (<>) { print CMD $_; } while (<>) { print CMD $_; }
close(CMD); close(CMD);
......
...@@ -74,11 +74,37 @@ Ext.define('PVE.dc.ConsoleViewerEdit', { ...@@ -74,11 +74,37 @@ Ext.define('PVE.dc.ConsoleViewerEdit', {
} }
}); });
Ext.define('PVE.dc.EmailFromEdit', {
extend: 'PVE.window.Edit',
initComponent : function() {
var me = this;
Ext.applyIf(me, {
subject: gettext('Email from address'),
items: {
xtype: 'pvetextfield',
name: 'email_from',
vtype: 'email',
emptyText: gettext('Send emails from root@$hostname'),
deleteEmpty: true,
value: '',
fieldLabel: gettext('Email from address')
}
});
me.callParent();
me.load();
}
});
Ext.define('PVE.dc.OptionView', { Ext.define('PVE.dc.OptionView', {
extend: 'PVE.grid.ObjectGrid', extend: 'PVE.grid.ObjectGrid',
alias: ['widget.pveDcOptionView'], alias: ['widget.pveDcOptionView'],
noProxyText: gettext('Do not use any proxy'), noProxyText: gettext('Do not use any proxy'),
noEmailFromText: gettext('Send emails from root@$hostname'),
initComponent : function() { initComponent : function() {
var me = this; var me = this;
...@@ -110,6 +136,17 @@ Ext.define('PVE.dc.OptionView', { ...@@ -110,6 +136,17 @@ Ext.define('PVE.dc.OptionView', {
editor: 'PVE.dc.ConsoleViewerEdit', editor: 'PVE.dc.ConsoleViewerEdit',
required: true, required: true,
renderer: PVE.Utils.render_console_viewer renderer: PVE.Utils.render_console_viewer
},
email_from: {
header: gettext('Email from address'),
editor: 'PVE.dc.EmailFromEdit',
required: true,
renderer: function(value) {
if (!value) {
return me.noEmailFromText;
}
return value;
}
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment