Solved

ppp server inactivity timeout

Posted on 1998-08-18
8
331 Views
Last Modified: 2013-12-05
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?
0
Comment
Question by:pjoo
  • 4
  • 3
8 Comments
 

Author Comment

by:pjoo
Comment Utility
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:bryanjones
Comment Utility
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
0
 

Author Comment

by:pjoo
Comment Utility
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
0
 
LVL 1

Accepted Solution

by:
rocca earned 200 total points
Comment Utility
We has this same problem and a friend suggested a simple solution which works great.  Just set the inactivity registers in your modem (no changes at all to your PPP setup).  Not all modems support inactivity, but 99% of them do.  For us it was:

AT\T15&W0

.to set a 15 minute timeout.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:pjoo
Comment Utility
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.
0
 
LVL 1

Expert Comment

by:rocca
Comment Utility
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. :-)
0
 
LVL 1

Expert Comment

by:rocca
Comment Utility
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...
0
 
LVL 1

Expert Comment

by:rocca
Comment Utility
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);
};
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now