Link to home
Start Free TrialLog in
Avatar of pjoo
pjoo

asked on

ppp server inactivity timeout

I am running pppd-2-2 on Linux 2.0.34, Slackware. How can I
automatically log off and disconnect a user who has no activity for 10 minutes?
Avatar of pjoo
pjoo

ASKER

Adjusted points to 200
By killing their PID number through a script.

Here is the begining of the script that you need to create.

who -u | awk '{print $6 , $7}'  -- if the $6 is more than 10 minutes then kill -5 $7
Avatar of pjoo

ASKER

This will disconnect a user after being connected for x minutes even if the user is actively using the connection. who and
ps shows how long someone has been connected not their
period of inactivity when connected ia ppp. who shows a ppp user as being idle from the moment they connect and the idle time increments from the moment they connect
ASKER CERTIFIED SOLUTION
Avatar of rocca
rocca

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pjoo

ASKER

Does anyone know about anything in the ppp configuration that specifically
addresses such timeouts? Timeouts are implemented by almost all ISP's
and I really don't think they use the modem timeout.
Most of the terminal server's have timeout's built into their configuration settings. (such as the USR racks, Livingston, etc) However I have not found anything in the Linux stock PPP server.  There might be a hack out there for it, hmm, sounds like a good project. :-)
Oh, one other thought.  You could always do it using a setup with greping out the TX/RX packet stats on the output of ifconfig every ten minutes and comparing with the last results to determine idle modems.  Sounds like more work than it's worth though...
It appears the script got deleted from the history somehow, here is a repost:

#!/usr/bin/perl

# Copyrighted 1999, Peter Rocca <peter@rocca.org>
# Freely usable in commercial and non-commercial environments,
# provided the above copyright remains unaltered.
#
# Legal stuff:
#
# THE AUTHOR ASSUMES NO RESPONSIBILITY FOR ANY BEHAVIOUR
# EXHIBITED BY THIS PROGRAM NOR PROVIDES ANY CLAIMS, OTHER
# THAN TO SAY IT WORKED ON HIS SYSTEM. USERS OF THIS PROGRAM
# ASSUME ALL RISKS AND LIABILITIES.
#
# How to implement:
#
# Run "idlekill kill" in your root's cron however often you
# want to check for idles, for example, if you want to limit
# to 10 minutes idle, then run this program every 10 minutes.
# Please note that the actually idle time may vary upto 2x
# the run rate (if the person goes idle a minute after the
# first check, then the second check reported usage in the
# first period, and on the third check it would disconnect)
#
# How to configure:
#
# This was a quick script made available to the public and
# therefore the configuration is not nicely set at the top
# of the program. Things to check to ensure it works, is
# to make sure you set the $LogLevel to the syslog setting
# you want to log to, check the paths for 'ifconfig', 'ps',
# 'finger', 'kill', 'logger' as found below and also either
# create /usr/local/modems as a directory, or change the
# paths where referenced.

use strict;

my $LogLevel = "local6.info";
my ($x, $Line, $IP, $RX, $TX, $Interface, %Data, %New);

# Load last run statistics
if(open(DATA,"/usr/local/modems/idlekill.dat")) {
  while(<DATA>) {
    chomp;
    ($IP,$TX,$RX) = split(":",$_);
    $Data{$IP} = $TX . ":" . $RX;
  };
  close(DATA);
};

# Determine the PPP interfaces that are up and read their statistics
my @Lines = `/sbin/ifconfig`;
for($x=0; $x<scalar(@Lines); $x++) {
  $Line = $Lines[$x];
  chomp $Line;
  if($Line =~ m/P-t-P:([^ ]*)/) { $IP = $1; }
  elsif($Line =~ m/TX packets:(\d*)/) { $TX = $1; }
  elsif($Line =~ m/RX packets:(\d*)/) { $RX = $1; }
  elsif($Line =~ m/^(ppp\d*)/) { $Interface = $1; }
  elsif($IP) {
    $Line =~ s/ //g;
    if(length($Line)<1) {
      $New{$IP} = $TX . ":" . $RX;
      # If previous stats match our current stats...
      if($Data{$IP} eq $New{$IP}) {
        # Determine the PID of the process
        my ($PID) = split(" ",`ps -ax | grep $IP | grep -v grep`);
        if(!$PID) {
          if(open(FILE,"/var/run/$Interface.pid")) {
            $PID = <FILE>;
            close(FILE);
            chomp $PID;
          };
        };
        if($PID > 0) {
          # Only actually kill the process if 'kill' is a parameter
          if($ARGV[0] =~ m/kill/i) {
            my $Res = `finger | grep $IP`;
            chomp $Res;
            while( $Res =~ s/  / /g ) {};
            $Res .= " $PID";
            system("logger -p $LogLevel -t idlekill \"$Res\"");
            system("kill -9 $PID");
          } else {
            print "No activity on $IP, pid=$PID.\n";
          };
        } else {
          print "Unable to determine PID for $IP (Interface $Interface)\n";
        };
      };
      # Reset for next interface
      $IP = "";
    };
  };
};

# Write new statistics to the data file
if(open(DATA,">/usr/local/modems/idlekill.dat")) {
  foreach $IP (sort keys %New) {
    $Line = join(":",$IP,$New{$IP});
    print DATA "$Line\n";
  };
  close(DATA);
};