8 use Digest::MD5 'md5_hex';
10 $ENV{PATH} .= ':/sbin:/usr/sbin';
12 $usage = "usage: $0 [-p port] [IP-address]\n";
13 $xinetd = '/etc/xinetd.d/fex';
18 die "you must be root to install F*EX\n";
21 goto INSTALL if $0 =~ /upgrade$/;
23 $fex = 'fex.rus.uni-stuttgart.de';
24 if (system("host $fex >/dev/null") != 0) {
25 die "host $fex is not resolvable - check /etc/resolv.conf\n";
28 if (`uname` =~ /^SunOS/) {
29 die "Solaris is currently not supported. "
30 ."Please contact framstag\@rus.uni-stuttgart.de for details.\n";
35 if (open $xinetd,$xinetd) {
37 if (/^\s*port\s*=\s*(\d+)/) {
38 $opt_p = $fexport = $1;
40 if (/^\s*bind\s*=\s*([\d.]+)/) {
47 getopts('p:') or die $usage;
50 if ($arg and -f "locale/$arg/lib/fup.pl") {
51 exec 'locale/translate',$arg;
53 $ip = $arg || $fexip || 0;
57 # if (not $ip and open P,"ifconfig 2>/dev/null |") {
58 if (not $ip and open P,'host $(hostname)|') {
61 if (/(\d+\.\d+\.\d+\.\d+)/) {
67 print "Your IP [$guessed_ip] : ";
72 $ip =~ /^\d+\.\d+\.\d+\.\d+$/ or die $usage;
74 ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
75 die "cannot find hostname for IP $ip\n" unless $hostname;
77 print "checking prerequisites\n";
79 if (`which xinetd` =~ m{^/}) {
80 print "found xinetd\n";
82 print "xinetd executable NOT found\n";
86 foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') {
89 print "found $sendmail\n";
94 print "sendmail NOT found\n";
99 print "installation aborted, nothing has been touched yet\n";
100 print "what now? ==> see doc/installation\n";
106 $SH = IO::Socket::INET->new(
113 print "There is already a tcp-service running on $ip:$opt_p !\n";
114 print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
115 print "or an alternative IP-address by running $0 OTHERADDRESS\n";
120 print "prerequisites checked, ok\n";
122 unless (getpwnam('fex')) {
123 print "creating user fex\n";
124 system 'useradd -s /bin/bash -c "File EXchange" -m fex';
128 if (open F,'/etc/passwd') {
130 $fexbash = $_ if /^fex:.*\/bash/;
135 die "no bash login shell for user fex\n";
142 @FEX = getpwnam('fex') or die "no user fex\n";
145 die "no HOME directory for user fex\n" unless -d $FEXHOME;
147 print "Installing:\n";
152 "lib/reactivation.txt",
156 "htdocs/FAQ/local.faq",
163 rename $f,$fs and print "$f --> $fs\n";
167 cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME);
168 unlink "$FEXHOME/doc/License";
169 unlink "$FEXHOME/htdocs/License";
171 $hl = "$FEXHOME/htdocs/locale";
172 unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
174 if (-d "$FEXHOME/spool") {
175 warn "checking spool ...\n";
177 system "chown -R fex $spooldir/";
179 $newinstall = $FEXHOME;
181 mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
182 mkdir "$FEXHOME/spool/.error",0700;
183 system "chown -R fex $FEXHOME/spool";
192 rename $f,$fn and print "$f --> $fn\n";
193 rename $fs,$f and print "$fs --> $f\n";
197 system(qw'perl -p -i -e',
198 's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
199 "$FEXHOME/lib/fup.pl"
202 $fph = "$FEXHOME/lib/fex.ph";
203 open $fph,$fph or die "cannot read $fph - $!\n";
205 s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/;
211 $spooldir ||= "$FEXHOME/spool";
213 $fid = "$FEXHOME/.fex/id";
214 $aa = "$spooldir/$admin/@";
219 print "Server hostname [$hostname] : ";
222 $hostname = $_ if $_;
223 last if gethostbyname($hostname);
224 print "No DNS for $hostname\n";
227 print "F*EX admin [$admin] : ";
231 last if $admin =~ /.\@./;
232 print "admin must be a valid email address!\n";
234 while (not $admin_pw) {
235 print "F*EX admin password: ";
237 $admin_pw =~ s/\s//g;
240 print "(admin password is in $aa)\n";
241 $conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m;
242 $conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m;
245 print "\nFound old \$admin_pw in $fph !\n";
246 print "This is no longer supported for security reason.\n";
251 if ($_ ne $admin_pw) {
252 print "\nYou have to delete \$admin_pw in $fph and run\n";
253 print "$FEXHOME/bin/fac -u $admin $admin_pw\n";
254 print "\nThen rerun $0\n";
259 print "\$admin_pw is transfered to auth-ID in $aa\n\n";
260 $conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m;
265 my $ad = dirname($aa);
267 open $aa,'>',$aa or die "$0: cannot create $aa - $!\n";
268 print {$aa} "$admin_pw\n";
270 my $fd = dirname($fid);
272 rename $fid,$fid.'_save';
273 open $fid,'>',$fid or die "$0: cannot create $fid - $!\n";
274 print {$fid} "$hostname:$opt_p\n";
275 print {$fid} "$admin\n";
276 print {$fid} "$admin_pw\n";
279 system "chown -R fex $fd $ad";
282 open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n";
285 system "chown fex $fph.new";
286 rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n";
288 do $fph or die "$0: error in new $fph - $!\n";
290 rename "locale/deutsch","locale/german" if -d "locale/deutsch";
291 rename "locale/espanol","locale/spanish" if -d "locale/espanol";
293 if (@locales = glob "locale/*/lib/fup.pl") {
295 m{locale/(.+?)/} and $locale = $1;
296 if (-f "$FEXHOME/$_") {
297 system 'locale/translate',$locale;
298 system "chown -R fex $FEXHOME/locale/$locale";
299 $hl = "$FEXHOME/htdocs/locale/$locale";
300 symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
302 push @nlocales,"./install $1\n";
306 if (glob "$FEXHOME/locale/*/lib/fup.pl") {
307 print "\nTo install another localized version, type:\n";
309 print "\nTo install a localized version, type:\n";
315 $fph = "$FEXHOME/lib/fex.ph";
318 unless (-f $xinetd) {
319 my $xc = '/etc/xinetd.conf';
322 if (/^\s*only_from/) {
323 print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
328 if (-d '/etc/xinetd.d') {
329 unless (-f $xinetd) {
330 open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
331 open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
340 system qw'/etc/init.d/xinetd restart';
341 print "WARNING: cannot restart xinetd\n" if $?;
344 print "WARNING: No /etc/xinetd.d found.\n";
345 print "WARNING: You have to install etc/xinetd_fex manually.\n";
348 $crontab = `crontab -u fex -l 2>/dev/null`;
349 if ($crontab !~ /fex_cleanup/) {
350 open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
351 print {$crontab} $crontab,"\n";
352 print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
354 system qw(crontab -u fex fex.cron);
357 system "chown -R fex:root $FEXHOME $FEXHOME/spool/";
358 system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin $FEXHOME/spool/";
361 print "Now check configuration file $FEXHOME/lib/fex.ph and run\n";
362 print "$FEXHOME/bin/fac for further configuration and user management.\n";
363 print "(You can do this as user \"fex\")\n";
366 system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin";
369 print "F*EX update installed.\n";
370 print "You can inform your users about the new features with:\n";
371 print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ".
372 "< $FEXHOME/doc/newfeatures\n";
375 if (@local_rdomains and not @local_rhosts) {
376 print "\nWARNING:\n";
377 print "In $fph you have @local_rdomains but not @local_rhosts!\n";
378 print "Selfregistrating of external users will not work!\n";
379 print "See ${fph}_new/\n";
382 if (`$sendmail -h 2>&1` =~ /exim/ and
383 `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
384 print "\nWARNING:\n";
385 print "$sendmail is exim\n";
386 print "You MUST set in your exim4.conf:\n";
387 print "trusted_users = mail : uucp : fex\n";
393 my ($f,$d,$to,$from,$link);
398 our ($spooldir,$skeydir,$gkeydir);
399 $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib";
400 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
402 # User --> user@maildomain
404 foreach $f (glob "$spooldir/.dkeys/*") {
405 if ($link = readlink $f) {
406 (undef,$to,$from,$file) = split('/',$link);
408 $to .= '@'.$mdomain if $to !~ /@/;
409 $from .= '@'.$mdomain if $from !~ /@/;
410 if ($link ne "../$to/$from/$file") {
411 symlink "../$to/$from/$file",$f;
418 # fix spool layout: FROM and TO must have domains and must be lower case
419 foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
420 if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
423 if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
424 if ($mdomain and $b !~ /@/) {
425 rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
426 } elsif ($b ne lc($b)) {
427 rename $d,sprintf("%s/%s",$p,lc($b));
433 # split auth-ID and subuser file: @ --> @ @SUBUSER
434 foreach my $u (glob "$spooldir/*@*") {
435 next if -f "$u/\@SUBUSER";
436 open my $idf,"$u/\@" or next;
438 if (defined ($su = <$idf>) and $su =~ /\w/
439 and open my $suf,">$u/\@SUBUSER") {
441 while (defined ($su = <$idf>)) { print {$suf} $su }
444 if (open my $idf,">$u/\@") {
452 foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
453 $user = (split '/',$sf)[-2];
457 if (/(.+\@.+):(.+)/) {
458 ($subuser,$id) = ($1,$2);
459 next if $subuser =~ /\*/;
460 $skey = md5_hex("$user:$subuser:$id");
461 if (open $skey,'>',"$skeydir/$skey") {
462 print {$skey} "from=$subuser\n",
467 mkdirp("$spooldir/$subuser/\@MAINUSER");
468 symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
476 foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
478 $group = (split '/',$gf)[-1];
479 $user = (split '/',$gf)[-3];
483 if (/(.+\@.+):(.+)/) {
485 $gkey = md5_hex("$user:$group:$gm:$id");
486 if (open $gkey,'>',"$gkeydir/$gkey") {
487 print {$gkey} "from=$gm\n",
493 mkdirp("$spooldir/$gm/\@GROUP");
494 symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
506 die "cpav: $dd is not a directory" unless -d $dd;
507 open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |"
508 or die "cpav: cannot tar - $!\n";
511 print "$_ --> $dd/$_\n" unless /\/$/;