pve-manager/bin/pvemailforward

41 lines
1.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl -w -T
use strict;
use warnings;
use PVE::Tools;
use PVE::SafeSyslog;
use PVE::AccessControl;
# NOTE: we need to run this with setgid www-data
# else we cant read /etc/pve/user.cfg
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog('pvemailforward');
eval {
# note: that fails because we run with wrong uid (nobody)
#my $usercfg = cfs_read_file("user.cfg");
my $filename = "/etc/pve/user.cfg";
my $raw = PVE::Tools::file_get_contents($filename);
my $usercfg = PVE::AccessControl::parse_user_config($filename, $raw);
my $rootcfg = $usercfg->{users}->{'root@pam'} || {};
my $mailto = $rootcfg->{email};
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") ||
die "can't exec sendmail - $!\n";
while (<>) { print CMD $_; }
close(CMD);
};
if (my $err = $@) {
syslog('err', "mail forward failed: $err");
}
exit(0);