]>
Commit | Line | Data |
---|---|---|
782bc232 DM |
1 | #!/usr/bin/perl -w -T |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Tools; | |
6 | use PVE::SafeSyslog; | |
7 | use PVE::AccessControl; | |
8 | ||
9 | # NOTE: we need to run this with setgid www-data | |
10 | # else we cant read /etc/pve/user.cfg | |
11 | ||
12 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
13 | ||
14 | initlog('pvemailforward'); | |
15 | ||
16 | eval { | |
17 | # note: that fails because we run with wrong uid (nobody) | |
18 | #my $usercfg = cfs_read_file("user.cfg"); | |
19 | my $filename = "/etc/pve/user.cfg"; | |
20 | my $raw = PVE::Tools::file_get_contents($filename); | |
21 | my $usercfg = PVE::AccessControl::parse_user_config($filename, $raw); | |
22 | ||
23 | my $rootcfg = $usercfg->{users}->{'root@pam'} || {}; | |
24 | my $mailto = $rootcfg->{email}; | |
25 | ||
26 | die "user 'root\@pam' does not have a email address\n" if !$mailto; | |
27 | ||
28 | syslog("info", "forward mail to <$mailto>"); | |
29 | ||
30 | # we never send DSN (avoid mail loops) | |
31 | open(CMD, "|sendmail -bm -N never $mailto") || | |
32 | die "can't exec sendmail - $!\n"; | |
33 | while (<>) { print CMD $_; } | |
34 | close(CMD); | |
35 | }; | |
36 | if (my $err = $@) { | |
37 | syslog('err', "mail forward failed: $err"); | |
38 | } | |
39 | ||
40 | exit(0); |