File: fexwall

package info (click to toggle)
fex 20200429-1
  • links: PTS, VCS
  • area: non-free
  • in suites: sid
  • size: 3,532 kB
  • sloc: perl: 32,103; sh: 410; javascript: 53; makefile: 42
file content (139 lines) | stat: -rwxr-xr-x 2,822 bytes parent folder | download
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/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 = $opt_f = $opt_n = 0;

getopts('hfn') 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
      and not ($opt_f and -f "$user/\@ALLOWED_RECIPIENTS")) {
    push @users,$user;
  }
}

unless ($opt_f) {

  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);

if ($opt_n) {
  print "<|$sendmail\n\t",join("\n\t",@users),"\n\n";
  $sendmail = *STDOUT;
} else {
  open $sendmail,'|-',$sendmail,@users or die "$0: $sendmail - $!\n";
}

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

unless ($opt_n) {
  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 [-f] [-n] \"SUBJECT\" < mail.text\n";
  print "options: -f  full users only\n";
  print "         -n  do not send mail, just show it with recipients\n";
  exit shift||0;
}