#!/bin/perl

##
# Timeout - a perl script to periodically check who is logged on to
#           a portmaster and "flush off" those users who have been
#           online too long
# 
#  Copyright (c) 1995 Dave Andersen  <angio@aros.net>
##

##
#  Todo - support for multiple portmasters as command-line options
##

##
# Configuration section
##

$TIMELIMIT = 60*8;   # Let them have 8 hours online
$portmaster = "PUT YOUR PORTMASTER ADDRESS HERE";

$pmcom = "/usr/local/sys/bin/pmcom";  # Customize

open(PMWHO, "/usr/local/sys/bin/pmwho|") ||
	die "Could not finger da portmaster.\n";

while (<PMWHO>) {
	chop;
	if (!/^S/) { next; }
	($port, $user, $host, $type, $dir, $status, $start, $idle) = split;

	if ($user eq "angio" || $user eq "kslewin") { next; }
           # We use this to exclude the admins from the timeout

	if ($start =~ /:/) { 
		($hours, $minutes) = split(/:/, $start);
		$start = ($hours*60) + $minutes;
	}
	if ($start > $TIMELIMIT) {
		printf("$_\n");
		system("/usr/local/sys/bin/pmcom $portmaster \"reset $port\"");
	}
}
