#
#  execute a pile of commands to suck in network information
#

require "conf/coroner.cf";

sub suck_netinfo {

print "Running all sorts of network commands on host (in &suck_netinfo())\n" if $verbose;

if (-x $NETSTAT) {
	&date_stamp("$COMM_OUT/netstat-in");
	&redirect_command($NETSTAT, "-in", ">>$COMM_OUT/netstat-in");
	&sign_it("$COMM_OUT/netstat-in");
	}

if (-x $NETSTAT) {
	&date_stamp("$COMM_OUT/netstat-rn");
	&redirect_command($NETSTAT, "-rn", ">>$COMM_OUT/netstat-rn");
	&sign_it("$COMM_OUT/netstat-rn");
	}

if (-x $SHOWMOUNT) {
	&date_stamp("$COMM_OUT/showmount-e");
	&redirect_command($SHOWMOUNT, "-e", ">>$COMM_OUT/showmount-e");
	&sign_it("$COMM_OUT/showmount-e");
	}

if (-x $SHOWMOUNT) {
	&date_stamp("$COMM_OUT/showmount-a");
	&redirect_command($SHOWMOUNT, "-a", ">>$COMM_OUT/showmount-a");
	&sign_it("$COMM_OUT/showmount-a");
	}

if (-x $ARP) {
	&date_stamp("$COMM_OUT/arp");
	&redirect_command($ARP, "-a", ">>$COMM_OUT/arp");
	&sign_it("$COMM_OUT/arp");
	}

if (-x $RPCINFO) {
	&date_stamp("$COMM_OUT/rpcinfo");
	&redirect_command($RPCINFO, "-p", ">>$COMM_OUT/rpcinfo");
	&sign_it("$COMM_OUT/rpcinfo");
	}


if (-x $NETSTAT) {
	if ($OS ne "LINUX2") {
		&date_stamp("$COMM_OUT/netstat-a");
		&redirect_command($NETSTAT, "-a", "-f", "inet", ">>$COMM_OUT/netstat-a");
		&sign_it("$COMM_OUT/netstat-a");

		&date_stamp("$COMM_OUT/netstat-na");
		&redirect_command($NETSTAT, "-na", "-f", "inet", ">>$COMM_OUT/netstat-na");
		&sign_it("$COMM_OUT/netstat-na");
		}
	else {
		&date_stamp("$COMM_OUT/netstat-A");
		&redirect_command($NETSTAT, "-a", "-A", "inet", ">>$COMM_OUT/netstat-A");
		&sign_it("$COMM_OUT/netstat-A");

		&date_stamp("$COMM_OUT/netstat-nA");

		&redirect_command($NETSTAT, "-a", "-nA", "inet", ">>$COMM_OUT/netstat-nA");
		&sign_it("$COMM_OUT/netstat-nA");
		}
	}

if (($OS eq "SUNOS4") || ($OS eq "SUNOS5")) {
	if (-x $IFCONFIG) {
		&date_stamp("$COMM_OUT/ifconfig");
		&redirect_command($IFCONFIG, "-a", ">>$COMM_OUT/ifconfig");
		&sign_it("$COMM_OUT/ifconfig");
		}
	}

elsif (-x $IFCONFIG && -x $NETSTAT) {
	# need to figure out interfaces here
	#warn "Can't execute $NETSTAT\n" unless open(NS, "$NETSTAT -in|");
	&pipe_command(NS, $NETSTAT, "-in", "-|");

	<NS>;	# kill off the first line

	# just grab the first field, maybe duplicates
	while (<NS>) {
		($int, $x) = split(/\s/, $_);
		$net_interfaces{$int} = $int;
		}
	close(NS);

	# finally!  ;-)
	&date_stamp("$COMM_OUT/ifconfig");
	for (keys %net_interfaces) {
		&redirect_command($IFCONFIG, "$_", ">>$COMM_OUT/ifconfig");
		}
	&sign_it("$COMM_OUT/ifconfig");
	}

#
# I think -l is pretty universal...
#
if (-x $RPCINFO) {
	&date_stamp("$COMM_OUT/rpcinfo");
	&redirect_command($RPCINFO, "-p", ">>$COMM_OUT/rpcinfo");
	&sign_it("$COMM_OUT/rpcinfo");
	}

if (-x $FINGER) {
	&date_stamp("$COMM_OUT/finger");
	&redirect_command($FINGER, "-l", ">>$COMM_OUT/finger");
	&sign_it("$COMM_OUT/finger");
	}

if (-x $WHO) {
	&date_stamp("$COMM_OUT/who");
	&redirect_command($WHO, ">>$COMM_OUT/who");
	&sign_it("$COMM_OUT/who");
	}

if (-x $W) {
	&date_stamp("$COMM_OUT/w");
	&redirect_command($W, ">>$COMM_OUT/w");
	&sign_it("$COMM_OUT/w");
	}

if (-x $UPTIME) {
	&date_stamp("$COMM_OUT/uptime");
	&redirect_command($UPTIME, ">>$COMM_OUT/uptime");
	&sign_it("$COMM_OUT/uptime");
	}

print "Running last - this could take awhile (in &suck_hostinfo())\n" if $verbose;

if (-x $LAST) {
	&date_stamp("$COMM_OUT/last");
	&redirect_command($LAST, ">>$COMM_OUT/last");
	&sign_it("$COMM_OUT/last");
	}

#
# need to put in a portable way of dumping bind's database... basically
# need a way to find bind's pid, send a kill -SIGINT, find the database
# that comes out, and save that.
#

}

if (!$running_under_grave_robber) {
	$debug = $verbose = 1;
	require "lib/command.pl";
	require "lib/ostype.pl";
	require "lib/dig-sig.pl";
	&determine_os();

	&suck_netinfo();
	}

1;

