[pve-devel] [PATCH] GUI: add new email_from option to datacenter.cfg

Stanislav German-Evtushenko ginermail at gmail.com
Thu Sep 4 14:39:17 CEST 2014


Signed-off-by: Stanislav German-Evtushenko <ginermail at gmail.com>
---
 PVE/API2/APT.pm              |  5 +++--
 PVE/VZDump.pm                |  6 ++++--
 bin/pvemailforward.pl        |  5 ++++-
 www/manager/dc/OptionView.js | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 72a1423..3327445 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -341,10 +341,11 @@ __PACKAGE__->register_method({
 		if ($mailto) {
 		    my $hostname = `hostname -f` || PVE::INotify::nodename();
 		    chomp $hostname;
+		    my $mailfrom = $dcconf->{email_from} || "root";
 
 		    my $data = "Content-Type: text/plain;charset=\"UTF8\"\n";
 		    $data .= "Content-Transfer-Encoding: 8bit\n";
-		    $data .= "FROM: <root\@$hostname>\n";
+		    $data .= "FROM: <$mailfrom>\n";
 		    $data .= "TO: $mailto\n";
 		    $data .= "SUBJECT: New software packages available ($hostname)\n";
 		    $data .= "\n";
@@ -364,7 +365,7 @@ __PACKAGE__->register_method({
 
 		    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' - $!";
 
 		    print $fh $data;
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 36bbf32..4a4d25c 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -279,8 +279,10 @@ my $sendmail = sub {
     foreach my $r (@$mailto) {
 	$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' - $!";
 
     my $rcvrtxt = join (', ', @$mailto);
@@ -289,7 +291,7 @@ my $sendmail = sub {
     print MAIL "\tboundary=\"$boundary\"\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 "SUBJECT: vzdump backup status ($hostname) : $stat\n";
     print MAIL "\n";
diff --git a/bin/pvemailforward.pl b/bin/pvemailforward.pl
index 53b58a0..2f807e4 100755
--- a/bin/pvemailforward.pl
+++ b/bin/pvemailforward.pl
@@ -24,12 +24,15 @@ eval {
     my $rootcfg = $usercfg->{users}->{'root at pam'} || {};
     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;
 
     syslog("info", "forward mail to <$mailto>");
 
     # 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";
     while (<>) { print CMD $_; }
     close(CMD);
diff --git a/www/manager/dc/OptionView.js b/www/manager/dc/OptionView.js
index f58c9db..81eab6f 100644
--- a/www/manager/dc/OptionView.js
+++ b/www/manager/dc/OptionView.js
@@ -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', {
     extend: 'PVE.grid.ObjectGrid',
     alias: ['widget.pveDcOptionView'],
 
     noProxyText: gettext('Do not use any proxy'),
+    noEmailFromText: gettext('Send emails from root@$hostname'),
 
     initComponent : function() {
 	var me = this;
@@ -110,6 +136,17 @@ Ext.define('PVE.dc.OptionView', {
 		editor: 'PVE.dc.ConsoleViewerEdit',
 		required: true,
 		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;
+		}
 	    }
 	};
 
-- 
1.9.1




More information about the pve-devel mailing list