| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use 5.010; |
| 4 |
use Getopt::Std; |
| 5 |
use File::Basename; |
| 6 |
use Socket; |
| 7 |
use IO::Socket::INET; |
| 8 |
use Digest::MD5 qw(md5_hex); |
| 9 |
use Cwd qw(abs_path getcwd); |
| 10 |
|
| 11 |
# use Digest::SHA qw(hmac_sha1_hex); # hmac_sha512_base64 |
| 12 |
# https://security.stackexchange.com/questions/211/how-to-securely-hash-passwords |
| 13 |
# https://www.sjoerdlangkemper.nl/2016/05/25/iterative-password-hashing/ |
| 14 |
# https://blog.codinghorror.com/speed-hashing/ |
| 15 |
|
| 16 |
our (@local_rdomains,@local_rhosts); |
| 17 |
|
| 18 |
$ENV{PATH} .= ':/sbin:/usr/sbin'; |
| 19 |
|
| 20 |
$usage = "usage: $0 [-p port] [IP-address]\n"; |
| 21 |
$xinetd = '/etc/xinetd.d/fex'; |
| 22 |
|
| 23 |
umask 022; |
| 24 |
|
| 25 |
if ($<) { |
| 26 |
die "you must be root to install F*EX\n"; |
| 27 |
} |
| 28 |
|
| 29 |
$fex = 'fex.belwue.de'; |
| 30 |
if (system("host $fex >/dev/null") != 0) { |
| 31 |
die "host $fex is not resolvable - check /etc/resolv.conf\n"; |
| 32 |
} |
| 33 |
|
| 34 |
if (`LC_ALL=en_US.UTF-8 locale 2>&1 >/dev/null` =~ /\w/) { |
| 35 |
die "no locale en_US.UTF-8 installed\n"; |
| 36 |
} |
| 37 |
|
| 38 |
# $fexupdate = '/root/bin/fexupdate'; |
| 39 |
# die "found $fexupdate\n" if -x $fexupdate; |
| 40 |
|
| 41 |
$opt_p = 80; |
| 42 |
|
| 43 |
if (open $xinetd,$xinetd) { |
| 44 |
while (<$xinetd>) { |
| 45 |
if (/^\s*port\s*=\s*(\d+)/) { |
| 46 |
$opt_p = $fexport = $1; |
| 47 |
} |
| 48 |
if (/^\s*bind\s*=\s*([\d.]+)$/) { |
| 49 |
$fexip = $ip = $1; |
| 50 |
} |
| 51 |
} |
| 52 |
close $xinetd; |
| 53 |
} |
| 54 |
|
| 55 |
goto INSTALL if $0 =~ /upgrade$/; |
| 56 |
|
| 57 |
if (`uname` =~ /^SunOS/) { |
| 58 |
die "Solaris is currently not supported. " |
| 59 |
."Please contact framstag\@rus.uni-stuttgart.de for details.\n"; |
| 60 |
} |
| 61 |
|
| 62 |
getopts('p:') or die $usage; |
| 63 |
|
| 64 |
$arg = shift; |
| 65 |
if ($arg and -f "locale/$arg/lib/fup.pl") { |
| 66 |
exec 'locale/translate',$arg; |
| 67 |
} else { |
| 68 |
$ip = $arg || $fexip || 0; |
| 69 |
} |
| 70 |
|
| 71 |
# if (not $ip and open P,"ifconfig 2>/dev/null |") { |
| 72 |
if (not $ip and open P,'host $(hostname)|') { |
| 73 |
$guessed_ip = 0; |
| 74 |
while (<P>) { |
| 75 |
if (/(\d+\.\d+\.\d+\.\d+)/) { |
| 76 |
$guessed_ip = $1; |
| 77 |
last; |
| 78 |
} |
| 79 |
} |
| 80 |
close P; |
| 81 |
unless (-f $xinetd) { |
| 82 |
print "Your IP [$guessed_ip] : "; |
| 83 |
chomp($ip = <STDIN>); |
| 84 |
} |
| 85 |
$ip ||= $guessed_ip; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET); |
| 90 |
die "cannot find hostname for IP $ip\n" unless $hostname; |
| 91 |
|
| 92 |
print "checking prerequisites\n"; |
| 93 |
|
| 94 |
if (`which xinetd` =~ m{^/}) { |
| 95 |
print "found xinetd\n"; |
| 96 |
} else { |
| 97 |
print "xinetd executable NOT found\n"; |
| 98 |
$premiss++; |
| 99 |
} |
| 100 |
|
| 101 |
foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') { |
| 102 |
if (-x) { |
| 103 |
$sendmail = $_; |
| 104 |
print "found $sendmail\n"; |
| 105 |
last; |
| 106 |
} |
| 107 |
} |
| 108 |
unless ($sendmail) { |
| 109 |
print "sendmail NOT found\n"; |
| 110 |
$premiss++; |
| 111 |
} |
| 112 |
|
| 113 |
if ($premiss) { |
| 114 |
print "installation aborted, nothing has been touched yet\n"; |
| 115 |
print "what now? ==> see doc/installation\n"; |
| 116 |
exit 1; |
| 117 |
} |
| 118 |
|
| 119 |
unless ($fexport) { |
| 120 |
|
| 121 |
$SH = IO::Socket::INET->new( |
| 122 |
PeerAddr => $ip, |
| 123 |
PeerPort => $opt_p, |
| 124 |
Proto => 'tcp', |
| 125 |
); |
| 126 |
|
| 127 |
if ($SH) { |
| 128 |
print "There is already a tcp-service running on $ip:$opt_p !\n"; |
| 129 |
print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n"; |
| 130 |
print "or an alternative IP-address by running $0 OTHERADDRESS\n"; |
| 131 |
exit 5; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
print "prerequisites checked, ok\n"; |
| 136 |
|
| 137 |
unless (getpwnam('fex')) { |
| 138 |
print "creating user fex\n"; |
| 139 |
system 'groupadd --system fex 2>/dev/null || groupadd fex'; |
| 140 |
my @g = getgrnam('fex') or die "$0: cannot groupadd fex\n"; |
| 141 |
my $gid = $g[2]; |
| 142 |
if (getpwuid($gid)) { |
| 143 |
system "useradd -s /bin/bash -c 'File EXchange' -g $gid -m fex" |
| 144 |
} else { |
| 145 |
system "useradd -s /bin/bash -c 'File EXchange' -u $gid -g $gid -m fex" |
| 146 |
} |
| 147 |
exit $? if $?; |
| 148 |
@pw = getpwnam('fex') or die "$0: no user fex\n"; |
| 149 |
$fexhome = $pw[7]; |
| 150 |
$profile = "$fexhome/.bash_profile"; |
| 151 |
$profile = "$fexhome/.bash_login" unless -f $profile; |
| 152 |
$profile = "$fexhome/.profile" unless -f $profile; |
| 153 |
open $profile,'>>',$profile or die "$0: cannot write $profile - $!\n"; |
| 154 |
print {$profile} qq'PATH="$fexhome/bin:\$PATH"\n'; |
| 155 |
close $profile; |
| 156 |
} |
| 157 |
|
| 158 |
if (open F,'/etc/passwd') { |
| 159 |
while (<F>) { |
| 160 |
$fexbash = $_ if /^fex:.*\/bash/; |
| 161 |
} |
| 162 |
close F; |
| 163 |
} |
| 164 |
unless ($fexbash) { |
| 165 |
die "no bash login shell for user fex\n"; |
| 166 |
} |
| 167 |
|
| 168 |
INSTALL: |
| 169 |
|
| 170 |
umask 077; |
| 171 |
|
| 172 |
@FEX = getpwnam('fex') or die "no user fex\n"; |
| 173 |
$FEXHOME = $FEX[7]; |
| 174 |
$ENV{HOME} = $FEXHOME; # needed for later eval fex.ph |
| 175 |
|
| 176 |
die "no HOME directory for user fex\n" unless -d $FEXHOME; |
| 177 |
if ($FEXHOME !~ /fex/) { |
| 178 |
print "HOME=$FEXHOME for user fex does not contain \"fex\"\n"; |
| 179 |
print "REALLY continue?! "; |
| 180 |
$_ = <STDIN>; |
| 181 |
exit unless /^y/i; |
| 182 |
} |
| 183 |
|
| 184 |
# old bug fix |
| 185 |
if (-d "$FEXHOME/htdocs/locale") { |
| 186 |
chmod 0755,"$FEXHOME/htdocs/locale"; |
| 187 |
chmod 0755,grep { -d $_ } glob("$FEXHOME/locale/*/htdocs"); |
| 188 |
} |
| 189 |
|
| 190 |
print "Installing:\n"; |
| 191 |
|
| 192 |
$pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm"; |
| 193 |
unless (-f $pecl) { |
| 194 |
mkdir "$FEXHOME/perl"; |
| 195 |
mkdir "$FEXHOME/perl/Encode"; |
| 196 |
open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n"; |
| 197 |
print {$pecl} |
| 198 |
"# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n", |
| 199 |
"1;\n"; |
| 200 |
close $pecl; |
| 201 |
print $pecl,"\n"; |
| 202 |
chownr('fex:0',"$FEXHOME/perl"); |
| 203 |
} |
| 204 |
|
| 205 |
@save = ( |
| 206 |
"lib/fex.ph", |
| 207 |
"lib/fup.pl", |
| 208 |
"lib/reactivation.txt", |
| 209 |
"etc/mime.types", |
| 210 |
"htdocs/index.html", |
| 211 |
"htdocs/robots.txt", |
| 212 |
"htdocs/FAQ/index.html", |
| 213 |
"htdocs/FAQ/local.faq", |
| 214 |
); |
| 215 |
|
| 216 |
foreach $s (@save) { |
| 217 |
$f = "$FEXHOME/$s"; |
| 218 |
if (-e $f) { |
| 219 |
$fs = $f.'_save'; |
| 220 |
rename $f,$fs and print "$f --> $fs\n"; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME); |
| 225 |
unlink "$FEXHOME/doc/License"; |
| 226 |
unlink "$FEXHOME/htdocs/License"; |
| 227 |
|
| 228 |
$hl = "$FEXHOME/htdocs/locale"; |
| 229 |
unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" } |
| 230 |
|
| 231 |
foreach $s (@save) { |
| 232 |
$f = "$FEXHOME/$s"; |
| 233 |
$fs = $f.'_save'; |
| 234 |
$fn = $f.'_new'; |
| 235 |
if (-e $fs) { |
| 236 |
unlink $fn; |
| 237 |
rename $f,$fn and print "$f --> $fn\n"; |
| 238 |
rename $fs,$f and print "$fs --> $f\n"; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
# foreach (glob("$FEXHOME/locale/*/lib")) { |
| 243 |
# next if m:/english/lib:; |
| 244 |
# system "locale/translate",basename(dirname($_)); |
| 245 |
# } |
| 246 |
|
| 247 |
if (-d "$FEXHOME/spool") { |
| 248 |
warn "checking $FEXHOME/spool ...\n"; |
| 249 |
$cid = getcwd(); |
| 250 |
&convert_spool; |
| 251 |
chdir $cid; |
| 252 |
} else { |
| 253 |
$newinstall = $FEXHOME; |
| 254 |
chmod 0700,$FEXHOME; |
| 255 |
mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n"; |
| 256 |
mkdir "$FEXHOME/spool/.error",0700; |
| 257 |
} |
| 258 |
foreach my $dir (qw'.dkeys .ukeys .akeys .skeys .gkeys .xkeys .locks') { |
| 259 |
mkdir "$FEXHOME/spool/$dir",0700; |
| 260 |
} |
| 261 |
|
| 262 |
chownr('fex',"$FEXHOME/spool/."); |
| 263 |
|
| 264 |
# fex-VM? |
| 265 |
if (open my $setup,'/root/bin/setup') { |
| 266 |
while (<$setup>) { |
| 267 |
exit if /#.*X-VM/; |
| 268 |
} |
| 269 |
close $setup; |
| 270 |
} |
| 271 |
|
| 272 |
system(qw'perl -p -i -e', |
| 273 |
's:href="/?FAQ.html":href="/FAQ/FAQ.html":', |
| 274 |
"$FEXHOME/lib/fup.pl" |
| 275 |
); |
| 276 |
|
| 277 |
$fph = "$FEXHOME/lib/fex.ph"; |
| 278 |
open $fph,$fph or die "cannot read $fph - $!\n"; |
| 279 |
while (<$fph>) { |
| 280 |
s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/; |
| 281 |
$conf .= $_; |
| 282 |
} |
| 283 |
close $fph; |
| 284 |
|
| 285 |
eval $conf; |
| 286 |
|
| 287 |
# die "no \$spooldir in $fph\n" unless $spooldir; |
| 288 |
$spooldir ||= '/home/fex/spool'; |
| 289 |
die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir; |
| 290 |
symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool"; |
| 291 |
@sds1 = stat "$spooldir/."; |
| 292 |
@sds2 = stat "$FEXHOME/spool/."; |
| 293 |
if ("@sds1" ne "@sds2") { |
| 294 |
die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n"; |
| 295 |
} |
| 296 |
|
| 297 |
$fid = "$FEXHOME/.fex/id"; |
| 298 |
$aa = "$spooldir/$admin/@"; |
| 299 |
|
| 300 |
if ($newinstall or not -s $aa) { |
| 301 |
print "\n"; |
| 302 |
for (;;) { |
| 303 |
print "Server hostname [$hostname] : "; |
| 304 |
$_ = <STDIN>; |
| 305 |
s/\s//g; |
| 306 |
$hostname = $_ if $_; |
| 307 |
last if gethostbyname($hostname); |
| 308 |
print "No DNS for $hostname\n"; |
| 309 |
} |
| 310 |
for (;;) { |
| 311 |
print "F*EX admin [$admin] : "; |
| 312 |
$_ = <STDIN>; |
| 313 |
s/\s//g; |
| 314 |
$admin = $_ if $_; |
| 315 |
last if $admin =~ /.\@./; |
| 316 |
print "admin must be a valid email address!\n"; |
| 317 |
} |
| 318 |
$aa = "$spooldir/$admin/@"; |
| 319 |
while (not $admin_pw) { |
| 320 |
print "F*EX admin password: "; |
| 321 |
$admin_pw = <STDIN>; |
| 322 |
$admin_pw =~ s/\s//g; |
| 323 |
} |
| 324 |
mkfid(); |
| 325 |
print "(admin password is in $aa)\n"; |
| 326 |
$conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m; |
| 327 |
$conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m; |
| 328 |
} else { |
| 329 |
if ($admin_pw) { |
| 330 |
print "\nFound old \$admin_pw in $fph !\n"; |
| 331 |
print "This is no longer supported for security reason.\n"; |
| 332 |
if (open $aa,$aa) { |
| 333 |
$_ = <$aa>||''; |
| 334 |
chomp; |
| 335 |
close $aa; |
| 336 |
if ($_ ne $admin_pw) { |
| 337 |
print "\nYou have to delete \$admin_pw in $fph and run\n"; |
| 338 |
print "$FEXHOME/bin/fac -u $admin $admin_pw\n"; |
| 339 |
print "\nThen rerun $0\n"; |
| 340 |
exit 2; |
| 341 |
} |
| 342 |
} |
| 343 |
mkfid(); |
| 344 |
print "\$admin_pw is transfered to auth-ID in $aa\n\n"; |
| 345 |
$conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n"; |
| 350 |
print {$fph} $conf; |
| 351 |
close $fph; |
| 352 |
system "chown fex $fph.new"; |
| 353 |
system qw'vv -s',$fph; |
| 354 |
rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n"; |
| 355 |
|
| 356 |
do $fph or die "$0: error in new $fph - $!\n"; |
| 357 |
|
| 358 |
if (@locales = glob "locale/*/lib/fup.pl") { |
| 359 |
foreach (@locales) { |
| 360 |
m{locale/(.+?)/} and $locale = $1; |
| 361 |
if (-f "$FEXHOME/$_") { |
| 362 |
# warn "locale/translate $locale"; |
| 363 |
system 'locale/translate',$locale; |
| 364 |
chownr('fex',"$FEXHOME/locale/$locale"); |
| 365 |
$hl = "$FEXHOME/htdocs/locale/$locale"; |
| 366 |
symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl; |
| 367 |
chownr('fex',"$FEXHOME/htdocs/locale/$locale"); |
| 368 |
} else { |
| 369 |
push @nlocales,"./install $1\n"; |
| 370 |
} |
| 371 |
} |
| 372 |
if (@nlocales) { |
| 373 |
if (glob "$FEXHOME/locale/*/lib/fup.pl") { |
| 374 |
print "\nTo install another localized version, type:\n"; |
| 375 |
} else { |
| 376 |
print "\nTo install a localized version, type:\n"; |
| 377 |
} |
| 378 |
print @nlocales; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
$fph = "$FEXHOME/lib/fex.ph"; |
| 383 |
do $fph; |
| 384 |
|
| 385 |
unless (-f $xinetd) { |
| 386 |
my $xc = '/etc/xinetd.conf'; |
| 387 |
if (open $xc,$xc) { |
| 388 |
while (<$xc>) { |
| 389 |
if (/^\s*only_from/) { |
| 390 |
print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n"; |
| 391 |
} |
| 392 |
} |
| 393 |
close $xc; |
| 394 |
} |
| 395 |
if (-d '/etc/xinetd.d') { |
| 396 |
unless (-f $xinetd) { |
| 397 |
open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n"; |
| 398 |
open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n"; |
| 399 |
while (<F>) { |
| 400 |
s/FEXHOME/$FEXHOME/; |
| 401 |
s/PORT/$opt_p/; |
| 402 |
s/ADDRESS/$ip/; |
| 403 |
print {$xinetd} $_; |
| 404 |
} |
| 405 |
close F; |
| 406 |
close $xinetd; |
| 407 |
if (-x '/etc/init.d/xinetd') { |
| 408 |
system qw'/etc/init.d/xinetd restart'; |
| 409 |
} else { |
| 410 |
system qw'service xinetd restart'; |
| 411 |
} |
| 412 |
print "WARNING: cannot restart xinetd\n" if $?; |
| 413 |
} |
| 414 |
} else { |
| 415 |
print "WARNING: No /etc/xinetd.d found.\n"; |
| 416 |
print "WARNING: You have to install etc/xinetd_fex manually.\n"; |
| 417 |
} |
| 418 |
|
| 419 |
$crontab = `crontab -u fex -l 2>/dev/null`; |
| 420 |
if ($crontab !~ /fex_cleanup/) { |
| 421 |
open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n"; |
| 422 |
print {$crontab} $crontab,"\n"; |
| 423 |
print {$crontab} " 3 2 * * * exec $FEXHOME/bin/fex_backup\n"; |
| 424 |
print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n"; |
| 425 |
close $crontab; |
| 426 |
system qw'crontab -u fex fex.cron'; |
| 427 |
} |
| 428 |
|
| 429 |
chownr('fex:0',$FEXHOME,"$FEXHOME/spool/.","$FEXHOME/htdocs/."); |
| 430 |
chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/."); |
| 431 |
|
| 432 |
print "\n"; |
| 433 |
print "Now check configuration file $FEXHOME/lib/fex.ph and run\n"; |
| 434 |
print "$FEXHOME/bin/fac for further configuration and user management.\n"; |
| 435 |
print "(You can do this as user \"fex\")\n"; |
| 436 |
} else { |
| 437 |
|
| 438 |
chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin"); |
| 439 |
|
| 440 |
print "\n"; |
| 441 |
print "F*EX update installed.\n"; |
| 442 |
print "You can inform your users about the new features with:\n"; |
| 443 |
print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ". |
| 444 |
"< $FEXHOME/doc/newfeatures\n"; |
| 445 |
} |
| 446 |
|
| 447 |
if (@local_rdomains and not @local_rhosts) { |
| 448 |
print "\nWARNING:\n"; |
| 449 |
print "In $fph you have \@local_rdomains but not \@local_rhosts!\n"; |
| 450 |
print "Selfregistrating of external users will not work!\n"; |
| 451 |
print "See ${fph}_new/\n"; |
| 452 |
} |
| 453 |
|
| 454 |
if (`$sendmail -h 2>&1 </dev/null` =~ /exim/ and |
| 455 |
`grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) { |
| 456 |
print "\nWARNING:\n"; |
| 457 |
print "$sendmail is exim\n"; |
| 458 |
print "You MUST set in your exim4.conf:\n"; |
| 459 |
print "trusted_users = mail : uucp : fex\n"; |
| 460 |
} |
| 461 |
|
| 462 |
exit; |
| 463 |
|
| 464 |
sub mkfid { |
| 465 |
my $ad = dirname($aa); |
| 466 |
mkdir $ad; |
| 467 |
open $aa,'>',$aa or die "$0: cannot create $aa - $!\n"; |
| 468 |
print {$aa} "$admin_pw\n"; |
| 469 |
close $aa; |
| 470 |
my $fd = dirname($fid); |
| 471 |
mkdir $fd; |
| 472 |
rename $fid,$fid.'_save'; |
| 473 |
open $fid,'>',$fid or die "$0: cannot create $fid - $!\n"; |
| 474 |
print {$fid} "$hostname:$opt_p\n"; |
| 475 |
print {$fid} "$admin\n"; |
| 476 |
print {$fid} "$admin_pw\n"; |
| 477 |
close $fid; |
| 478 |
chownr('fex',$ad,$fd); |
| 479 |
chmod 0700,$ad,$fd; |
| 480 |
} |
| 481 |
|
| 482 |
sub chownr { |
| 483 |
my $user = shift; |
| 484 |
local $_; |
| 485 |
foreach (@_) { |
| 486 |
if (m:^/*(lib|usr|home)?/*$:) { |
| 487 |
die "ERROR: short path in chownr $user @_\n"; |
| 488 |
} |
| 489 |
} |
| 490 |
system qw'chown -R',$user,@_; |
| 491 |
} |
| 492 |
|
| 493 |
sub chmodr { |
| 494 |
my $mod = shift; |
| 495 |
local $_; |
| 496 |
foreach (@_) { |
| 497 |
if (m:^/*(lib|usr|home)?/*$:) { |
| 498 |
die "ERROR: short path in chmodr $mod @_\n"; |
| 499 |
} |
| 500 |
} |
| 501 |
system qw'chmod -R',$mod,@_; |
| 502 |
} |
| 503 |
|
| 504 |
sub convert_spool { |
| 505 |
my ($f,$d,$to,$from,$link); |
| 506 |
|
| 507 |
()=q:(:; local $) = $FEX[3]; |
| 508 |
local $> = $FEX[2]; |
| 509 |
|
| 510 |
our ($spooldir,$skeydir,$gkeydir); |
| 511 |
$ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib"; |
| 512 |
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n"; |
| 513 |
die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir; |
| 514 |
die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:; |
| 515 |
|
| 516 |
# User --> user@maildomain |
| 517 |
if ($mdomain) { |
| 518 |
foreach $f (glob "$spooldir/.dkeys/*") { |
| 519 |
if ($link = readlink $f) { |
| 520 |
(undef,$to,$from,$file) = split('/',$link); |
| 521 |
if ($file) { |
| 522 |
$to .= '@'.$mdomain if $to !~ /@/; |
| 523 |
$from .= '@'.$mdomain if $from !~ /@/; |
| 524 |
if ($link ne "../$to/$from/$file") { |
| 525 |
symlink "../$to/$from/$file",$f; |
| 526 |
} |
| 527 |
} |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
# fix spool layout: FROM and TO must have domains and must be lower case |
| 533 |
foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) { |
| 534 |
if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) { |
| 535 |
$p = $1; |
| 536 |
$b = $2; |
| 537 |
if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) { |
| 538 |
if ($mdomain and $b !~ /@/) { |
| 539 |
rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain); |
| 540 |
} elsif ($b ne lc($b)) { |
| 541 |
rename $d,sprintf("%s/%s",$p,lc($b)); |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
# remove @ from special storage directories |
| 548 |
foreach my $u (glob "$spooldir/*@*") { |
| 549 |
foreach my $d (qw'CCC DOX SHARE STREAM') { |
| 550 |
my $dd = "$spooldir/$u/\@$d"; |
| 551 |
if (-d $dd) { |
| 552 |
rename $dd,"$spooldir/$u/$d" or warn "cannot rename $dd - $!\n"; |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
# save current disk usage for DOX folders |
| 558 |
foreach $d (glob "$spooldir/*@*/DOX") { |
| 559 |
foreach $f (glob "$d/*") { |
| 560 |
if (-l $f and -d $f) { |
| 561 |
my $s = 0; |
| 562 |
my @f = grep /_\d+_\d+$/,glob($f.'_*'); |
| 563 |
if (@f and open my $du,"du -ks @f 2>/dev/null|") { |
| 564 |
while (<$du>) { |
| 565 |
$s += $1 if /^(\d+)/; |
| 566 |
} |
| 567 |
close $du; |
| 568 |
my $duf = sprintf("%s/.%s.du",dirname($f),basename($f)); |
| 569 |
unlink $duf; |
| 570 |
symlink $s,$duf; |
| 571 |
} |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
# split auth-ID and subuser file: @ --> @ @SUBUSER |
| 577 |
foreach my $u (glob "$spooldir/*@*") { |
| 578 |
next if -f "$u/\@SUBUSER"; |
| 579 |
open my $idf,"$u/\@" or next; |
| 580 |
$id = <$idf>; |
| 581 |
if (defined ($su = <$idf>) and $su =~ /\w/ |
| 582 |
and open my $suf,">$u/\@SUBUSER") { |
| 583 |
print {$suf} $su; |
| 584 |
while (defined ($su = <$idf>)) { print {$suf} $su } |
| 585 |
close $suf; |
| 586 |
close $idf; |
| 587 |
if (open my $idf,">$u/\@") { |
| 588 |
print {$idf} $id; |
| 589 |
close $idf; |
| 590 |
} |
| 591 |
} else { |
| 592 |
close $idf; |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
# create new SKEYs |
| 597 |
foreach my $sf (glob "$spooldir/*/\@SUBUSER") { |
| 598 |
$user = (split '/',$sf)[-2]; |
| 599 |
if (open $sf,$sf) { |
| 600 |
while (<$sf>) { |
| 601 |
s/#.*//; |
| 602 |
if (/(.+\@.+):(.+)/) { |
| 603 |
($subuser,$id) = ($1,$2); |
| 604 |
next if $subuser =~ /\*/; |
| 605 |
$skey = md5_hex("$user:$subuser:$id"); |
| 606 |
if (open $skey,'>',"$skeydir/$skey") { |
| 607 |
print {$skey} "from=$subuser\n", |
| 608 |
"to=$user\n", |
| 609 |
"id=$id\n"; |
| 610 |
close $skey; |
| 611 |
} |
| 612 |
mkdirp("$spooldir/$subuser/\@MAINUSER"); |
| 613 |
symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user"; |
| 614 |
} |
| 615 |
} |
| 616 |
} |
| 617 |
close $sf; |
| 618 |
} |
| 619 |
|
| 620 |
# create new GKEYs |
| 621 |
foreach my $gf (glob "$spooldir/*/\@GROUP/*") { |
| 622 |
next unless -f $gf; |
| 623 |
# normalize group name |
| 624 |
if ($gf =~ m:(.+)/(.+):) { |
| 625 |
my $gd = $1; |
| 626 |
my $g1 = $2; |
| 627 |
my $g2 = $2; |
| 628 |
$g2 =~ s/[^\w\*%^+=:,.!-]/_/g; |
| 629 |
if ($g1 ne $g2) { |
| 630 |
rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2"; |
| 631 |
} |
| 632 |
} |
| 633 |
$group = (split '/',$gf)[-1]; |
| 634 |
$user = (split '/',$gf)[-3]; |
| 635 |
if (open $gf,$gf) { |
| 636 |
while (<$gf>) { |
| 637 |
s/#.*//; |
| 638 |
if (/(.+\@.+):(.+)/) { |
| 639 |
($gm,$id) = ($1,$2); |
| 640 |
$gkey = md5_hex("$user:$group:$gm:$id"); |
| 641 |
if (open $gkey,'>',"$gkeydir/$gkey") { |
| 642 |
print {$gkey} "from=$gm\n", |
| 643 |
"to=\@$group\n", |
| 644 |
"user=$user\n", |
| 645 |
"id=$id\n"; |
| 646 |
close $gkey; |
| 647 |
} |
| 648 |
mkdirp("$spooldir/$gm/\@GROUP"); |
| 649 |
symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group"; |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
close $gf; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
sub cpav { |
| 658 |
my $dd = pop @_; |
| 659 |
local *P; |
| 660 |
|
| 661 |
die "cpav: $dd is not a directory" unless -d $dd; |
| 662 |
open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |" |
| 663 |
or die "cpav: cannot tar - $!\n"; |
| 664 |
while (<P>) { |
| 665 |
chomp; |
| 666 |
print "$_ --> $dd/$_\n" unless /\/$/; |
| 667 |
} |
| 668 |
close P; |
| 669 |
} |