-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·408 lines (349 loc) · 9.79 KB
/
install
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/perl -w
use 5.006;
use Getopt::Std;
use Socket;
use IO::Socket::INET;
use Digest::MD5 qw(md5_hex);
$ENV{PATH} .= ':/sbin:/usr/sbin';
$usage = "usage: $0 [-p port] [IP-address]\n";
$xinetd = '/etc/xinetd.d/fex';
umask 022;
if ($<) {
die "you must be root to install F*EX\n";
}
goto INSTALL if $0 =~ /upgrade$/;
$fex = 'fex.rus.uni-stuttgart.de';
if (system("host $fex >/dev/null") != 0) {
die "host $fex is not resolvable - check /etc/resolv.conf\n";
}
if (`uname` =~ /^SunOS/) {
die "Solaris is currently not supported. "
."Please contact framstag\@rus.uni-stuttgart.de for details.\n";
}
$opt_p = 80;
if (open $xinetd,$xinetd) {
while (<$xinetd>) {
if (/^\s*port\s*=\s*(\d+)/) {
$opt_p = $fexport = $1;
}
if (/^\s*bind\s*=\s*([\d.]+)/) {
$fexip = $ip = $1;
}
}
close $xinetd;
}
getopts('p:') or die $usage;
$arg = shift;
if ($arg and -f "locale/$arg/lib/fup.pl") {
exec 'locale/translate',$arg;
} else {
$ip = $arg || $fexip || 0;
}
# if (not $ip and open P,"ifconfig 2>/dev/null |") {
if (not $ip and open P,'host $(hostname)|') {
$guessed_ip = 0;
while (<P>) {
if (/(\d+\.\d+\.\d+\.\d+)/) {
$guessed_ip = $1;
last;
}
}
close P;
print "Your IP [$guessed_ip] : ";
chomp($ip = <STDIN>);
$ip = $guessed_ip unless $ip;
}
$ip =~ /^\d+\.\d+\.\d+\.\d+$/ or die $usage;
($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
die "cannot find hostname for IP $ip\n" unless $hostname;
print "checking prerequisites\n";
if (`which xinetd` =~ m{^/}) {
print "found xinetd\n";
} else {
print "xinetd executable NOT found\n";
$premiss++;
}
if ( -x '/usr/lib/sendmail') {
print "found /usr/lib/sendmail\n";
} elsif ( -x '/usr/sbin/sendmail') {
print "found /usr/sbin/sendmail\n";
} else {
print "sendmail NOT found\n";
$premiss++;
}
if ($premiss) {
print "installation aborted, nothing has been touched yet\n";
print "what now? ==> see doc/installation\n";
exit 1;
}
unless ($fexport) {
$SH = IO::Socket::INET->new(
PeerAddr => $ip,
PeerPort => $opt_p,
Proto => 'tcp',
);
if ($SH) {
print "There is already a tcp-service running on $ip:$opt_p !\n";
print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
print "or an alternative IP-address by running $0 OTHERADDRESS\n";
exit 5;
}
}
print "prerequisites checked, ok\n";
unless (getpwnam('fex')) {
print "creating user fex\n";
system 'useradd -s /bin/bash -c "File EXchange" -m fex';
}
INSTALL:
@FEX = getpwnam('fex') or die "no cannot create user fex\n";
$FEXHOME = $FEX[7];
die "no HOME directory for user fex\n" unless -d $FEXHOME;
print "Installing:\n";
@save = (
"lib/fex.ph",
"lib/fup.pl",
"lib/reactivation.txt",
"etc/mime.types",
"htdocs/FAQ.html",
"htdocs/index.html",
"htdocs/robots.txt",
);
foreach $s (@save) {
$f = "$FEXHOME/$s";
if (-e $f) {
$fs = $f.'_save';
rename $f,$fs and print "$f --> $fs\n";
}
}
cpav(qw(bin cgi-bin lib etc htdocs doc),$FEXHOME);
unlink "$FEXHOME/doc/License";
unlink "$FEXHOME/htdocs/License";
$hl = "$FEXHOME/htdocs/locale";
unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
if (-d "$FEXHOME/spool") {
&convert_spool;
} else {
chmod 0700,$FEXHOME;
mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
mkdir "$FEXHOME/spool/.error",0700;
}
foreach $s (@save) {
$f = "$FEXHOME/$s";
$fs = $f.'_save';
$fn = $f.'_new';
if (-e $fs) {
system "rm -rf $fn";
rename $f,$fn and print "$f --> $fn\n";
rename $fs,$f and print "$fs --> $f\n";
}
}
system(qw(perl -p -i -e),
's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
"$FEXHOME/lib/fup.pl"
);
$fph = "$FEXHOME/lib/fex.ph";
open $fph,$fph or die "cannot read $fph - $!\n";
while (<$fph>) {
eval $_ if /^\s*\$admin_pw\s*=/;
s/'HOSTNAME'/'$hostname'/;
$conf .= $_;
}
close $fph;
if (-x "$FEXHOME/cgi-bin/fac" and not $admin_pw) {
while (not $admin_pw) {
print "\nF*EX admin password (for web interface): ";
$admin_pw = <STDIN>;
$admin_pw =~ s/\s//g;
}
$conf =~ s/\$admin_pw\s*=\s*''/\$admin_pw = '$admin_pw'/ or
$conf =~ s/^/\$admin_pw = '$admin_pw';\n/;
}
open $fph,">$fph" or die "cannot write $fph - $!\n";
print {$fph} $conf;
close $fph;
require $fph or die "$0: error in $fph\n";
rename "locale/deutsch","locale/german" if -d "locale/deutsch";
rename "locale/espanol","locale/spanish" if -d "locale/espanol";
if (@locales = glob "locale/*/lib/fup.pl") {
foreach (@locales) {
m{locale/(.+?)/} and $locale = $1;
if (-f "$FEXHOME/$_") {
system 'locale/translate',$locale;
$hl = "$FEXHOME/htdocs/locale/$locale";
symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
} else {
push @nlocales,"./install $1\n";
}
}
if (@nlocales) {
if (glob "$FEXHOME/locale/*/lib/fup.pl") {
print "\nTo install another localized version, type:\n";
} else {
print "\nTo install a localized version, type:\n";
}
print @nlocales;
}
}
unless (-f $xinetd) {
my $xc = '/etc/xinetd.conf';
if (open $xc,$xc) {
while (<$xc>) {
if (/^\s*only_from/) {
print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
}
}
close $xc;
}
if (-d '/etc/xinetd.d') {
unless (-f $xinetd) {
open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
while (<F>) {
s/FEXHOME/$FEXHOME/;
s/PORT/$opt_p/;
s/ADDRESS/$ip/;
print {$xinetd} $_;
}
close F;
close $xinetd;
system qw(/etc/init.d/xinetd restart);
}
} else {
print "WARNING: No /etc/xinetd.d found.\n";
print "WARNING: You have to install etc/xinetd_fex manually.\n";
}
$crontab = `crontab -u fex -l 2>/dev/null`;
if ($crontab !~ /fex_cleanup/) {
open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
print {$crontab} $crontab,"\n";
print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
close $crontab;
system qw(crontab -u fex fex.cron);
}
system "chown -R fex:root $FEXHOME $FEXHOME/spool/";
system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin $FEXHOME/spool/";
print "\nUse $FEXHOME/bin/fac to configure your F*EX server.\n";
} else {
system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin";
}
$fph = "$FEXHOME/lib/fex.ph";
require $fph;
if (@local_rdomains and not @local_rhosts) {
print "WARNING:\n";
print "In $fph you have @local_rdomains but not @local_rhosts!\n";
print "Selfregistrating of external users will not work!\n";
print "See ${fph}_new/\n";
}
exit;
sub convert_spool {
my ($f,$d,$to,$from,$link);
our ($spooldir,$skeydir,$gkeydir);
$ENV{FEXLIB} = "$FEXHOME/lib";
require "lib/fex.pp" or die "$0: cannot load lib/fex.pp - $!\n";
# User --> user@maildomain
if ($mdomain) {
foreach $f (glob "$spooldir/.dkeys/*") {
if ($link = readlink $f) {
(undef,$to,$from,$file) = split('/',$link);
if ($file) {
$to .= '@'.$mdomain if $to !~ /@/;
$from .= '@'.$mdomain if $from !~ /@/;
if ($link ne "../$to/$from/$file") {
symlink "../$to/$from/$file",$f;
}
}
}
}
}
# fix spool layout: FROM and TO must have domains and must be lower case
foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
$p = $1;
$b = $2;
if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
if ($mdomain and $b !~ /@/) {
rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
} elsif ($b ne lc($b)) {
rename $d,sprintf("%s/%s",$p,lc($b));
}
}
}
}
# split auth-ID and subuser file: @ --> @ @SUBUSER
foreach my $u (glob "$spooldir/*@*") {
next if -f "$u/\@SUBUSER";
open my $idf,"$u/\@" or next;
$id = <$idf>;
if (defined ($su = <$idf>) and $su =~ /\w/
and open my $suf,">$u/\@SUBUSER") {
print {$suf} $su;
while (defined ($su = <$idf>)) { print {$suf} $su }
close $suf;
close $idf;
if (open my $idf,">$u/\@") {
print {$idf} $id;
close $idf;
}
}
}
# create new SKEYs
foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
$user = (split '/',$sf)[-2];
if (open $sf,$sf) {
while (<$sf>) {
s/#.*//;
if (/(.+\@.+):(.+)/) {
($subuser,$id) = ($1,$2);
next if $subuser =~ /\*/;
$skey = md5_hex("$user:$subuser:$id");
if (open $skey,'>',"$skeydir/$skey") {
print {$skey} "from=$subuser\n",
"to=$user\n",
"id=$id\n";
close $skey;
}
mkdirp("$spooldir/$subuser/\@MAINUSER");
symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
}
}
}
close $sf;
}
# create new GKEYs
foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
next unless -f $gf;
$group = (split '/',$gf)[-1];
$user = (split '/',$gf)[-3];
if (open $gf,$gf) {
while (<$gf>) {
s/#.*//;
if (/(.+\@.+):(.+)/) {
($gm,$id) = ($1,$2);
$gkey = md5_hex("$user:$group:$gm:$id");
if (open $gkey,'>',"$gkeydir/$gkey") {
print {$gkey} "from=$gm\n",
"to=\@$group\n",
"user=$user\n",
"id=$id\n";
close $gkey;
}
mkdirp("$spooldir/$gm/\@GROUP");
symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
}
}
}
close $gf;
}
}
sub cpav {
my $dd = pop @_;
local *P;
die "cpav: $dd is not a directory" unless -d $dd;
open P,"tar cf - @_ | su -c 'cd $dd; tar xvf - 2>&1' fex |"
or die "cpav: cannot tar - $!\n";
while (<P>) {
chomp;
print "$_ --> $dd/$_\n" unless /\/$/;
}
close P;
}