Solved

ppp server inactivity timeout

Posted on 1998-08-18
8
334 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
ID: 1586483
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:bryanjones
ID: 1586484
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
ID: 1586485
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Accepted Solution

by:
rocca earned 200 total points
ID: 1586486
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
 

Author Comment

by:pjoo
ID: 1586487
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
ID: 1586488
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
ID: 1586489
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
ID: 2247417
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux : how to point the OS to use the new DNS server 11 102
Measure data download 2 110
how to run my script during boot in rhel 7 14 172
SSH connect to Amazon Centos Instance 7 64
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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