File: fexwall

package info (click to toggle)
fex 20160919-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,944 kB
  • sloc: perl: 17,699; sh: 346; makefile: 67
file content (124 lines) | stat: -rwxr-xr-x 2,422 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl -w

# send e-mail to all registered F*EX users
#
# Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
#

use Getopt::Std;
use File::Basename;
use Cwd 'abs_path';

# do not run as CGI!
exit if $ENV{SCRIPT_NAME};

unless ($ENV{FEXLIB}) {
  if ($ENV{FEXHOME}) {
    $ENV{FEXLIB} = $ENV{FEXHOME}.'/lib';
  } else {
    $ENV{FEXLIB} = dirname(dirname(abs_path($0))).'/lib';
  }
}
$FEXLIB = $ENV{FEXLIB};
die "$0: no FEXLIB\n" unless -f "$FEXLIB/fex.pp";

# program name
$0 =~ s:.*/::;

# become effective user fex
unless ($<) {
  if (my @pw = getpwnam('fex')) {
    $)         = $pw[3];
    $>         = $pw[2];
    $ENV{HOME} = $pw[7];
  } else {
    die "$0: no such user 'fex'\n";
  }
}

# import from fex.pp
our ($FEXHOME,$hostname,$sendmail,$spooldir,$admin,$bcc);

# load common code, local config : $HOME/lib/fex.ph
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";

die "$0: \$admin not configured in $FEXLIB/fex.ph\n"
  if not $admin or $admin =~ /example.org/;

$opt_h = 0;

getopts('h') or usage(2);
usage(0) if $opt_h;

$subject = "@ARGV";
die usage(1) unless $subject;

local $/;
$text = <STDIN>;
die usage(1) unless $text;

if (open my $sig,$ENV{HOME}.'/.signature') {
  $text .= "\n-- \n" . <$sig>;
  close $sig;
}

local $/ = "\n";

chdir $spooldir or die "$0: $spooldir - $!\n";

# @users = grep { chomp;s:/@:: } glob("*/@");
foreach $user (glob("*@*")) {
  if (-f "$user/@" and (readlink "$user/\@NOTIFICATION"||'') !~ /no/i) {
    push @users,$user;
  }
}

foreach $group (glob "*/\@GROUP/*") {
  if (open $group,$group) {
    while (<$group>) {
      s/#.*//;
      s/:.*\n//;
      push @users,$_ if /@/;
    }
    close $group;
  }
}

foreach $subuser (glob "*/\@SUBUSER") {
  if (open $subuser,$subuser) {
    while (<$subuser>) {
      s/#.*//;
      s/:.*\n//;
      push @users,$_ if /@/;
    }
    close $subuser;
  }
}

# @users = qw'framstag@fex';
die "$0: no users found\n" unless @users or grep /@/,@users;
push @users,$bcc;
@users = uniq(@users);

open $sendmail,'|-',$sendmail,@users or die "$0: $sendmail - $!\n";

print {$sendmail}
  "From: $admin\n",
  "To: fexusers\@$hostname\n",
  "Subject: $subject\n",
  "\n",
  $text;

close $sendmail or die "$0: $sendmail - $!\n";
print "mail sent to:\n",map { "$_\n" } @users;
exit;

sub uniq {
  my %x;
  grep !$x{$_}++,@_;
}

sub usage {
  print "usage: $0 \"SUBJECT\" < mail.text\n";
  exit shift||0;
}