X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/7fa382617fbaccc0ce522b2b3adbbee9db5ad227..c65ee6f7429eff9a7f58aad7c0aec858ad473092:/bin/fac?ds=inline diff --git a/bin/fac b/bin/fac index 0946704..c2d59f4 100755 --- a/bin/fac +++ b/bin/fac @@ -43,7 +43,7 @@ unless ($<) { umask 077; # import from fex.pp -our ($FEXHOME,$FHS,$hostname,$spooldir,$logdir,$akeydir,$docdir); +our ($FEXHOME,$FHS,$hostname,$spooldir,@logdir,$logdir,$akeydir,$docdir); our ($durl,@durl,$mdomain,$admin,$mailmode); our ($autodelete,$keep_default,$keep_max,$recipient_quota,$sender_quota); our (@local_rdomains); @@ -57,10 +57,10 @@ die "$0: \$admin not configured in $FEXLIB/fex.ph\n" unless $admin; $EDITOR = $ENV{EDITOR} || $ENV{VISUAL} || (-x '/usr/bin/editor' ? '/usr/bin/editor' : 'vi'); -$opt_c = $opt_v = $opt_l = $opt_L = $opt_h = $opt_w = $opt_u = $opt_R = 0; +$opt_c = $opt_v = $opt_l = $opt_L = $opt_h = $opt_w = $opt_u = 0; $opt_M = $opt_E = 0; $opt_r = $opt_d = $opt_q = $opt_a = $opt_n = $opt_k = $opt_m = ''; -$opt_y = $opt_S = $opt_C = $opt_D = $opt_A = $opt_V = $opt_P = ''; +$opt_y = $opt_S = $opt_C = $opt_D = $opt_A = $opt_V = $opt_P = $opt_R = ''; ${'opt_/'} = ''; @__ = @ARGV; @@ -79,8 +79,8 @@ warn "WARNING: $spooldir with owner=root !?\n" unless $stat[4]; if (abs_path($spooldir) ne abs_path("$FEXHOME/spool")) { warn "WARNING: \$spooldir differs from $FEXHOME/spool !\n"; } - -getopts('hcvlLwuMRE/q:r:d:a:n:k:m:y:S:C:A:V:D:P:') or usage(2); + +getopts('hcvlLwuME/q:r:d:a:n:k:m:y:S:C:A:V:D:P:R:') or usage(2); usage(0) if $opt_h; examples() if $opt_E; @@ -97,7 +97,7 @@ if (${'opt_/'}) { close $aa or die "$0: cannot write $aa - $!\n"; my $fph = "$FEXLIB/fex.ph"; $_ = slurp($fph) or die "$0: cannot read $fph\n"; - s/^\s*\$admin\s*=.*/\$admin = '$admin';/m or + s/^\s*\$admin\s*=.*/\$admin = '$admin';/m or $_ = "\$admin = '$admin';\n".$_; open $fph,">$fph.new" or die "$0: cannot write $fph.new\n"; print {$fph} $_; @@ -159,14 +159,14 @@ if ($opt_m) { if ($opt_M) { my ($mtime,$comment,$file,$keep); local $_; - + if (@ARGV) { foreach $file (glob("@ARGV")) { $mtime = mtime("$file/data") or next; $comment = slurp("$file/comment")||''; next if $comment =~ /NOMAIL/; - $keep = readlink "$file/keep" - || readlink "$file/../../\@KEEP" + $keep = readlink "$file/keep" + || readlink "$file/../../\@KEEP" || $keep_default; $keep = $keep - int((time-mtime("$file/data"))/60/60/24); @@ -209,8 +209,8 @@ if ($opt_l) { my ($file,$dkey,@L); chdir $spooldir or die "$0: $spooldir - $!\n"; foreach $file (glob "*/*/*") { - if (-s "$file/data" and - $dkey = readlink("$file/dkey") and + if (-s "$file/data" and + $dkey = readlink("$file/dkey") and -l ".dkeys/$dkey" ) { push @L,sprintf "%2\$s --> %1\$s : $durl/$dkey/%3\$s\n",split "/",$file; @@ -225,7 +225,7 @@ if ($opt_L) { my $filter = shift; my ($comment,$file,$keep,$old,$size,$download); local $_; - + foreach $file (glob "*/*/*/data") { next if $file =~ m:(.+?)/: and -l $1; $size = -s $file or next; @@ -238,7 +238,7 @@ if ($opt_L) { $download = join(' & ',split("\n",(slurp("$file/download")||''))); print "\n$file\n"; printf " comment: %s\n",decode_utf8($comment); - printf " size: %s\n",d3($size); + printf " size: %s\n",d3($size); printf " sender ip: %s\n",readlink("$file/ip")||''; printf " expire in: %s days\n",$keep-$old; printf " upload speed: %s kB/s\n",readlink("$file/speed")||0; @@ -248,7 +248,7 @@ if ($opt_L) { exit; } -# delete user +# delete user if ($opt_d) { $idf = "$spooldir/$opt_d/\@"; die "$0: no such user $opt_d\n" unless -f $idf; @@ -260,17 +260,32 @@ if ($opt_d) { # set user restriction file if ($opt_R) { - $user = shift or die "usage: $0 -R user\n"; - $user .= '@'.$mdomain if $mdomain and $user !~ /@/; - die "$0: no user $user\n" unless -d "$spooldir/$user"; - unless (@local_rdomains) { - die "$0: no \@local_rdomains in server config\n"; - } - my $rf = "$spooldir/$user/\@ALLOWED_RECIPIENTS"; - open $rf,'>',$rf or die "$0: cannot open $rf - $!"; - print {$rf} "\@LOCAL_RDOMAINS\n"; - close $rf; - print "$user restricted\n"; + if ($opt_R eq 'i') { + $user = shift or die "usage: $0 -Ri user\n"; + $user .= '@'.$mdomain if $mdomain and $user !~ /@/; + die "$0: no user $user\n" unless -d "$spooldir/$user"; + unless (@local_rdomains) { + die "$0: no \@local_rdomains in server config\n"; + } + my $rf = "$spooldir/$user/\@ALLOWED_RECIPIENTS"; + open $rf,'>',$rf or die "$0: cannot open $rf - $!"; + print {$rf} "\@LOCAL_RDOMAINS\n"; + close $rf; + print "$user restricted to internal recipients\n"; + exit; + } elsif ($opt_R eq 'l') { + $user = shift or die "usage: $0 -Rl user\n"; + $user .= '@'.$mdomain if $mdomain and $user !~ /@/; + die "$0: no user $user\n" unless -d "$spooldir/$user"; + my $rf = "$spooldir/$user/\@ALLOWED_RECIPIENTS"; + open $rf,'>',$rf or die "$0: cannot open $rf - $!"; + print {$rf} "\@LOCAL_USERS\n"; + close $rf; + print "$user restricted to local recipients\n"; + exit; + } else { + usage(2); + } exit; } @@ -297,7 +312,7 @@ if ($opt_r) { EOD } elsif ($opt_r eq 'UPLOAD_HOSTS') { print {$rf}<$fph" or die "$0: cannot write to $fph - $!\n"; print {$fph} $_; close $fph; - system "cp $FEXLIB/fup.pl $vhd/lib/fup.pl"; + cpa("$FEXLIB/fup.pl","$vhd/lib"); foreach $i (qw'dop fex.pp fup.pl lf.pl reactivation.txt') { # symlink "$FEXLIB/$i","$vhd/lib/$i"; symlink "../../lib/$i","$vhd/lib/$i"; @@ -401,10 +416,10 @@ if ($opt_A) { } # show config -if ($opt_v) { +if ($opt_v and not @ARGV) { print "config from $FEXLIB/fex.ph :\n"; print " spooldir = $spooldir\n"; - print " logdir = $logdir\n"; + print " logdir = @logdir\n"; print " docdir = $docdir\n"; print " durl = @durl\n"; print " admin = $admin\n"; @@ -433,26 +448,27 @@ if ($opt_v) { # add user or show user config if ($opt_u) { + chdir $spooldir or die "$0: cannot chdir $spooldir = $!\n"; if ($opt_u = shift @ARGV) { $user = lc $opt_u; $user .= '@'.$mdomain if $mdomain and $user !~ /@/; $id = shift @ARGV; - $idf = "$spooldir/$user/@"; + $idf = "$user/@"; if (open $idf,$idf) { chomp($ido = <$idf>||''); close $idf; } unless ($id) { - die "$0: $user is not a FEX user\n" unless -f "$spooldir/$user/@"; + die "$0: $user is not a regular FEX user\n" unless -f "$user/@"; showuser($user,$ido); exit; } unless ($user =~ /\w@[\w.-]+\.[a-z]+$/) { die "$0: $user is not a valid email-address!\n"; } - unless (-d "$spooldir/$user") { - mkdir "$spooldir/$user",0755 - or die "$0: cannot mkdir $spooldir/$user - $!\n"; + unless (-d $user) { + mkdir $user,0755 + or die "$0: cannot mkdir $user - $!\n"; } open F,">$idf" or die "$0: cannot write $idf - $!\n"; print F $id,"\n"; @@ -460,7 +476,7 @@ if ($opt_u) { showuser($user,$id); } else { print "Users in $spooldir:\n"; - foreach $user (glob "$spooldir/*/@") { + foreach $user (glob "*/@") { $user =~ s:.*/(.+)/@:$1:; print "$user\n"; } @@ -476,7 +492,7 @@ if ($opt_a) { if (/^n/i) { $autodelete = 'no' } elsif (/^y/i) { $autodelete = 'yes' } elsif (/^d/i) { $autodelete = 'delay' } - else { + else { die "usage: $0 -a user yes\n". "usage: $0 -a user no\n". "usage: $0 -a user delay\n". @@ -497,7 +513,7 @@ if ($opt_n) { if (/^n/i) { $notification = 'no' } elsif (/^[sb]/i) { $notification = 'short' } elsif (/^[fd]/i) { $notification = '' } - else { + else { die "usage: $0 -n user no\n". "usage: $0 -n user brief\n". "usage: $0 -n user detailed\n". @@ -533,7 +549,7 @@ if ($opt_q) { $user = lc $opt_q; $user .= '@'.$mdomain if $mdomain and $user !~ /@/; unless (-d "$spooldir/$user") { - die "$0: $user is not a regular FEX user\n"; + die "$0: $user is not a FEX user\n"; } quota($user,@ARGV); exit; @@ -587,18 +603,15 @@ if ($opt_y) { if ($opt_D) { $user = lc $opt_D; $user .= '@'.$mdomain if $mdomain and $user !~ /@/; - $_ = shift @ARGV || ''; - if (/^y/i) { - open $user,">>$spooldir/$user/\@DISABLED"; - close $user; - print "$user is now disabled\n"; - } elsif (/^n/i) { + $_ = $ARGV[0] || ''; + if (/^no?$/i) { unlink "$spooldir/$user/\@DISABLED"; print "$user is now enabled\n"; } else { - die "usage: $0 -D user yes\n". - "usage: $0 -D user no\n". - "example: $0 -D framstag\@rus.uni-stuttgart.de no\n"; + open $user,">>$spooldir/$user/\@DISABLED"; + print {$user} "@ARGV\n"; + close $user; + print "$user is now disabled\n"; } exit; } @@ -637,7 +650,7 @@ usage(3); sub showuser { my $user = shift; my $id = shift; - my ($keep,$autodelete,$notification); + my ($keep,$autodelete,$notification,$login); $user .= '@'.$mdomain if $mdomain and $user !~ /@/; @@ -646,14 +659,27 @@ sub showuser { printf "%s/%s\n",$fup,b64("from=$user&id=$id"); # printf "%s/%s\n",$fup,b64("from=$user&to=$user&id=$id&submit=."); print "spool: $spooldir/$user/\n"; + if ($login_check and $login = readlink "$user/.login") { + my $lc = &$login_check($login); + if ($lc) { + print "login: $login\n"; + } else { + print "login: DELETED\n"; + } + } + my $disabled = 'no'; + if (-e "$spooldir/$user/\@DISABLED") { + $disabled = slurp("$spooldir/$user/\@DISABLED"); + chomp $disabled; + $disabled ||= 'yes'; + } printf "fex yourself web default: %s\n", -e "$spooldir/$user/\@FEXYOURSELF" ? 'yes' : 'no'; printf "persistent: %s\n", -e "$spooldir/$user/\@PERSISTENT" ? 'yes' : 'no'; printf "captive: %s\n", -e "$spooldir/$user/\@CAPTIVE" ? 'yes' : 'no'; - printf "disabled: %s\n", - -e "$spooldir/$user/\@DISABLED" ? 'yes' : 'no'; + printf "disabled: %s\n",$disabled; printf "recipients restrictions: %s\n", -e "$spooldir/$user/\@ALLOWED_RECIPIENTS" ? 'yes' : 'no'; printf "upload restrictions: %s\n", @@ -693,17 +719,13 @@ sub quota { $squota = $1 if /^s.*:(\d*)/i; } open $qf,'>',$qf or die "$0: cannot write $qf - $!\n"; - print {$qf} "recipient:$rquota\n" if $rquota =~ /\d/; - print {$qf} "sender:$squota\n" if $squota =~ /\d/; + print {$qf} "recipient:$rquota\n" if $rquota; + print {$qf} "sender:$squota\n" if $squota; close $qf; } - $rquota = $recipient_quota if $rquota !~ /\d/; - $squota = $sender_quota if $squota !~ /\d/; - printf "recpient quota (used): %d (%d) MB\n", - check_recipient_quota($user) if $rquota; - printf "sender quota (used): %d (%d) MB\n", - check_sender_quota($user) if $squota; + printf "recpient quota (used): %d (%d) MB\n",check_recipient_quota($user); + printf "sender quota (used): %d (%d) MB\n",check_sender_quota($user); } @@ -789,13 +811,8 @@ sub cpa { } -sub mtime { - my @s = lstat shift; - return @s ? $s[9] : undef; -} - sub check_admin { - + my $admin_id = slurp("$spooldir/$admin/@") or die "$0: no admin account - you have to create it with:\n". "$0 -/ $admin ".randstring(8)."\n"; @@ -820,7 +837,7 @@ sub check_admin { warn "$0: moving $fid to ${fid}_save\n"; rename $fid,$fid.'_save'; } - } + } unless (-f $fid) { mkdir dirname($fid); open $fid,'>',$fid or die "$0: cannot create $fid - $!\n"; @@ -860,12 +877,14 @@ $0 -u user auth-ID # create new user or set new auth-ID $0 -/ admin auth-ID # set new admin and auth-ID $0 -q user s:quota # set new disk quota (MB) for sender user $0 -q user r:quota # set new disk quota (MB) for recipient user -$0 -R user # restrict user: only internal recipients allowed +$0 -Ri user # restrict user: only internal domain recipients allowed +$0 -Rl user # restrict user: only local users as recipients allowed $0 -rr user # edit user recipients restriction $0 -ru user # edit user upload restriction $0 -rd user # edit user download restriction $0 -d user # delete user -$0 -D user [yn] # disable user (yes,no) +$0 -D user "reason" # disable user +$0 -D user "no" # re-enable user $0 -P user [yn] # make user persistent = no account expiration (yes,no) $0 -a user [ynd] # set user autodelete default (yes,no,delay) $0 -n user [dbn] # set user notification default (detailed,brief,no) @@ -882,10 +901,10 @@ $0 -L [filter] # list pending files in detail $0 -M # list pending files with TO/FROM/FILE $0 -M TO/FROM/FILE # resend notification email $0 -m "reason" # enter maintenance mode (reason "exit" to leave) -$0 -A alias:hostname # add new virtual server -$0 -V virtualhost ... # operations on virtualhost (alias or hostname) $0 -E # show usage examples EOD +# $0 -A alias:hostname # add new virtual server +# $0 -V virtualhost ... # operations on virtualhost (alias or hostname) if (-x "$FEXHOME/cgi-bin/fac") { print "See also web admin interface $proto://$hostname$port/fac\n"; }