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

Stanislav German-Evtushenko ginermail at gmail.com
Tue Sep 2 14:40:58 CEST 2014


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

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 72a1423..92deeea 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\@$hostname";
 
 		    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..4295003 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\@$hostname";
 
-    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/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