Another From UGLY SOFT.

Mike Taylor (taylor@syrinx.jeffnet.org)
Tue, 29 Oct 1996 13:12:11 -0800 (PST)

The following garbage uses the lineparser set of scripts (renamed for
fun) to find all the users who have been on for 8 hrs or more "today" and
keep them from having any more usefull sessions. I run main every 30 mins,
and the reset script every 5 mins. It also requires the pmcommand from
livingston. This will only work if you use Livingston Portmasters.
If anyone would care to clean it up, and/or re-write it, have fun, but
make sure you post it here for all to use. As you will see, my perl skills
suck. Of course you will have to edit the files to match your system.

-----------------------MAIN----------------------------------------
#!/bin/bash
echo "PM0"
pmline /var/adm/radacct/pm0.jeffnet.org/detail > /sbin/daily.log
echo "PM1"
pmline /var/adm/radacct/pm1.jeffnet.org/detail >> /sbin/daily.log
echo "PM2"
pmline /var/adm/radacct/pm2.jeffnet.org/detail >> /sbin/daily.log
echo "PM3"
pmline /var/adm/radacct/pm3.jeffnet.org/detail >> /sbin/daily.log
#
/sbin/daily.use
echo "making summary...."
/sbin/summarize < /sbin/today.log > /sbin/today.totals
echo "finding offenders..."
/sbin/get.offend

----------------------daily.use-----------------------------------
#!/usr/bin/perl
#
# find todays date in DD/MM/YY format, grep lines matching date
#
#
$date = `date`;
#print "$date";
@dates = split (' ', $date);
$day = $dates[2];
print "today is day number: $day \n";
exec("grep \"/$day/\" /sbin/daily.log > /sbin/today.log");

------------------------get.offend---------------------------------------
#!/usr/bin/perl
#
# get todays user info from /sbin/today.totals write usernames with
# over 8hrs of use to /sbin/locked.today
#
open (TODAY, "cat /sbin/today.totals |");
open (LOCKED, "> /sbin/locked.today");
while ($linex = <TODAY>) {
@fields = split(' ', $linex);
@ttime = split(':', $fields[4]);
if ($ttime[0] >= "08"){
print LOCKED "$fields[0] \n";
print "$fields[0] $fields[4] \n";
}
}

---------------------------resetem-------------------------------
#!/usr/bin/perl
#
# use pmcommand to reset ports with users listed in /sbin/locked.today
# do not reset users listed in /etc/exempt.users
#
$date = `date`;
$any = "no";
$pmcom = "/sbin/pmcommand";
open (LOG, "> /sbin/reset.log");
print LOG "Subject: Punishing offenders \n \n";
print LOG "The following users have exceeded thier daily limit, but keep \n";
print LOG "logging back in. \n $date \n";
open (PORTS, "pm0 |");
while ($linex = <PORTS>) {
@fields = split (' ', $linex);
# print "$fields[0] $fields[1] \n";
open (USERS, "cat /sbin/locked.today |");
while ($liney = <USERS>) {
# print "$liney \n";
open (EXEMPT, "cat /etc/exempt.users |");
while ($linez = <EXEMPT>) {
if ($linez =~ /$liney/) { $liney = "xxx"; }
}
if ($liney =~ /$fields[1]/) {
open (PMCOM, "|$pmcom pm0 password") || next ;
print PMCOM "reset $fields[0] \n";
$any = "yes";
print LOG "Reset $fields[0] $liney \n";
print PMCOM "exit \n";
close (PMCOM);
}
}
}
open (PORTS, "pm1 |");
while ($linex = <PORTS>) {
@fields = split (' ', $linex);
# print "$fields[0] $fields[1] \n";
open (USERS, "cat /sbin/locked.today |");
while ($liney = <USERS>) {
# print "$liney \n";
open (EXEMPT, "cat /etc/exempt.users |");
while ($linez = <EXEMPT>) {
if ($linez =~ /$liney/) { $liney = "xxx"; }
}
if ($liney =~ /$fields[1]/) {
open (PMCOM, "| $pmcom pm1 password") || next;
print PMCOM "reset $fields[0] \n";
$any = "yes";
print LOG "Reset $fields[0] $liney \n";
print PMCOM "exit \n";
close (PMCOM);
}
}
}
open (PORTS, "pm2 |");
while ($linex = <PORTS>) {
@fields = split (' ', $linex);
# print "$fields[0] $fields[1] \n";
open (USERS, "cat /sbin/locked.today |");
while ($liney = <USERS>) {
# print "$liney \n";
open (EXEMPT, "cat /etc/exempt.users |");
while ($linez = <EXEMPT>) {
if ($linez =~ /$liney/) { $liney = "xxx"; }
}
if ($liney =~ /$fields[1]/) {
open (PMCOM, "| $pmcom pm2 password") || next;
print PMCOM "reset $fields[0] \n";
$any = "yes";
print LOG "Reset $fields[0] $liney \n";
print PMCOM "exit \n";
close (PMCOM);
}
}
}
open (PORTS, "pm3 |");
while ($linex = <PORTS>) {
@fields = split (' ', $linex);
# print "$fields[0] $fields[1] \n";
open (USERS, "cat /sbin/locked.today |");
while ($liney = <USERS>) {
# print "$liney \n";
open (EXEMPT, "cat /etc/exempt.users |");
while ($linez = <EXEMPT>) {
if ($linez =~ /$liney/) { $liney = "xxx"; }
}
if ($liney =~ /$fields[1]/) {
open (PMCOM, "| $pmcom pm3 password") || next;
print PMCOM "reset $fields[0] \n";
$any = "yes";
print LOG "Reset $fields[0] $liney \n";
print PMCOM "exit \n";
close (PMCOM);
}
}
}
close (LOG);
if ($any eq "yes") {
exec ('sendmail support-dist < /sbin/reset.log');
}
-----------------------EOF-----------------------------------------

\\|// ^^^^^ )))(( %%%%% ,,,,,
(- -) (o o) (- o) (0-0) (* *)
+--ooO-(_)-Ooo--oo0-(_)-0oo--ooO-(_)-Ooo--oo0-(_)-0oo--ooO-(_)-Ooo--+
| NETWORK OPERATIONS CENTER |
| mailto:support@friendly.jeffnet.org Voice # 800-876-8797 |
| http://jeffnet.org/linuxisp 541-776-3283 |
| Mike Taylor - Network Services Manager |
+-------------------------------------------------------------------+