]> git.proxmox.com Git - pve-manager.git/blame - bin/pvemailforward
use new assemble_vnc_ticket
[pve-manager.git] / bin / pvemailforward
CommitLineData
782bc232
DM
1#!/usr/bin/perl -w -T
2
3use strict;
4use warnings;
5use PVE::Tools;
6use PVE::SafeSyslog;
7use 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
14initlog('pvemailforward');
15
16eval {
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};
36if (my $err = $@) {
37 syslog('err', "mail forward failed: $err");
38}
39
40exit(0);