Subject: dumpxfer.pl [1087]

From: [email-masked] (Dave Williss)
Date: Wed, 11 Jan 1995 08:53:47 -0600 (CST)

#!/usr/local/bin/perl
#
#
#	dumpxfer [-g] [-b] [-a] [-f filename]
#
#		-g  Write normal transfer report
#		-b  Write report of just bad transfers
#		-a  Same as -gb (default)
#		-f filename  
#		    File to get xferlog from (default = /usr/adm/xferlog)
#		-S  Provide a default Subject: line
#		-s subject
#		    Subject to use. (Be sure to put it in double quotes)
#
require "getopts.pl";

&Getopts('gbaf:Ss:');
$opt_a = 1 if (!$opt_g && !$opt_b);
if ($opt_a) {
	$opt_g = 1;
	$opt_b = 1;
	}

$good_subject = "FTP Transfer Log";
$bad_subject = "Strange FTP Transfer Warning";
if ($opt_S == 1) {
	$opt_s = ($opt_g) ? $good_subject : $bad_subject;
	}

$xferlog = $opt_f ? $opt_f : "/usr/adm/xferlog";

open (XFERLOG, "<$xferlog") || exit(0);

$need_space = 0;

if ($opt_g) {
	$num_found = 0;
	while (<XFERLOG>) {
		($day, $month, $date, $time, $year, $pid, $host, $size, $file,
			$mode, $nothing, $direction, $class, $password, $user, $crud) = split;

		# if user didn't give host name in password, tack it on
		$password .= "@" . $host if (! ($password =~ /@./));
		($subuser, $subhost) = split(/@/, $password);
		if (!($host =~ /$subhost/i) && !($subhost =~ /$host/i)) {
			$password .= " ($host)";
			}

		if ("$direction" eq "i") {
			if (!$num_found) {
				print "Subject: $opt_s\n\n" if ($opt_s);
				print "Incoming FTP Transfers\n";
				print "======================\n\n";
				$need_space = 1;
				}
			
			printf("%s %-40.40s %s\n", $mode, $file, $password);
			++ $num_found;
			}
		}
	}

if ($opt_b) {
	seek(XFERLOG, 0, 0);
	$num_found = 0;

	while (<XFERLOG>) {
		($day, $month, $date, $time, $year, $pid, $host, $size, $file,
			$mode, $nothing, $direction, $class, $password, $user, $crud) = split;
		# if user didn't give host name in password, tack it on
		$password .= "@" . $host if (! ($password =~ /@./));
		($subuser, $subhost) = split(/@/, $password);
		if (!($host =~ /$subhost/i) && !($subhost =~ /$host/i)) {
			$password .= " ($host)";
			}

		if ("$direction" eq "i" && ! ($file =~ m#/pub/incoming#)) {
			if (!$num_found) {
				print "Subject: $opt_s\n\n" if ($opt_s && !$need_space);
				print "\n\n" if $need_space;
				print "Incoming FTP Transfers not in the /pub/incoming directory\n";
				print "=========================================================\n";
				print "\n";
				$need_space = 1;
				}
			printf("%s %-40.40s %s\n", $mode, $file, $password);
			++ $num_found;
			}
		}
	}

if ($opt_g) {
	$num_found = 0;
	seek(XFERLOG, 0, 0);
	while (<XFERLOG>) {
		($day, $month, $date, $time, $year, $pid, $host, $size, $file,
			$mode, $nothing, $direction, $class, $password, $user, $crud) = split;
		# if user didn't give host name in password, tack it on
		$password .= "@" . $host if (! ($password =~ /@./));
		($subuser, $subhost) = split(/@/, $password);
		if (!($host =~ /$subhost/i) && !($subhost =~ /$host/i)) {
			$password .= " ($host)";
			}

		if ("$direction" eq "o") {

			# Files we don't care if people look at
			next if $file =~ /.message/;
			next if $file =~ /README/;
			next if $file =~ /welcome.msg/;
			next if $file =~ /.html/;

			if (!$num_found) {
				print "Subject: $opt_s\n\n" if ($opt_s && !$need_space);
				print "\n\n" if $need_space;
				print "Outgoing FTP Transfers\n";
				print "======================\n\n";
				$need_space = 1;
				}
			
			printf("%s %-40.40s %s\n", $mode, $file, $password);
			++ $num_found;
			}
		}
	}

if ($opt_b) {
	$num_found = 0;
	seek(XFERLOG, 0, 0);
	while (<XFERLOG>) {
		($day, $month, $date, $time, $year, $pid, $host, $size, $file,
			$mode, $nothing, $direction, $class, $password, $user, $crud) = split;
		# if user didn't give host name in password, tack it on
		$password .= "@" . $host if (! ($password =~ /@./));
		($subuser, $subhost) = split(/@/, $password);
		if (!($host =~ /$subhost/i) && !($subhost =~ /$host/i)) {
			$password .= " ($host)";
			}

		if ("$direction" eq "o") {
			next if $file =~ /.message/;
			next if $file =~ /README/;
			if ($file =~ m#/pub/incoming#) {
				if (! $num_found) {
					print "Subject: $opt_s\n\n" if ($opt_s && !$need_space);
					print "\n\n" if $need_space;
					print "Outgoing FTP Transfers from /pub/incoming directory\n";
					print "===================================================\n\n";
					
					}	
				printf("%s %-40.40s %s\n", $mode, $file, $password);
				++ $num_found;
				}
			}
		}
	}

close(XFERLOG);