Ascend Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (ASCEND) Booting Users via SNMP



Attached is the perl script we use to log users off of MAXes.
This will NOT work on TNT's.

The script was written by:
    Deven Corzine <deven@fuse.net>
    Unix System Administrator, Fuse Internet Access

It's part of a larger user management system written by:
    Joshua Phillips <jphillip@ecn.purdue.edu>
    Fuse Internet Access Management Trainee

We can't support the script at this time, I'm posting it because I've 
already gotten several requests for it from the community.  We'll be
releasing the entire package in the near future.

The script will require some minor edits for file locations in your
environments, but it's well commented.  It also assumes that you have
BOTH a login password, and a Full Access password.  If that's not the case,
just remove the code for the second password prompt and response from
the Perl script.

Hope you like it.

-Rob

On Sun, 28 Sep 1997, Don Joy wrote:

> I wouldn't mind see that myself if you don't mind.  TIA.
> 
> Robert A. Pickering Jr. wrote:
> 
> > Or...you can do what we did.
> >
> > We just wrote some code that telnets into the Max, drops to the
> > terminal server mode, and boots the user.
> >
> > We can make it available if you'd like to see it.
> >
> > -Rob
> >
> > On Sat, 27 Sep 1997, Eric Reeves wrote:
> >
> > > On Sat, 27 Sep 1997, Mark Nordberg wrote:
> > >
> > > > I have written a whole web interface for showing users with speeds, ip,
> > > > duration, showing radius stats, showing modem dead/busy/suspect modems,
> > > > and a list of events on the max.
> > > >
> > > > I had the same problem with ssnStatusValidFlag and ssnActiveValidFlag.
> > > > I opened a ticket with ascend and they have reproduced this problem and
> > > > have told me that they have an engineering working on the problem currently.
> > > >
> > > > Hence, in some release in the future, this function wil be returned and
> > > > hanging up on users will be easy.  Exactly which version of 5.0A patch will
> > > > fix this is really up to Ascend.
> > >
> > > Well, I guess it's good to know it's not a problem with my scripts.
> > > I've got a similar package I've been working on for a while now.  Web
> > > interface as well as a textbased commandline interface.  Includes user
> > > searching, viewing a single max, and querying a list of maxes, and
> > > generating a report of all users logged in for more than a specified
> > > number of hours.  (very useful).  The big thing I want to add is the
> > > booting, but I guess I'll just have to wait. .   *shrug*
> > >
> > > Thanks for the nfo.
> > >
> > > +------------------------------------------+
> > > | Eric Reeves                tilex@ghg.net |
> > > | GHG Corporation          ereeves@ghg.net |
> > > +------------------------------------------+
> > >
> > > ++ Ascend Users Mailing List ++
> > > To unsubscribe:       send unsubscribe to ascend-users-request@bungi.com
> > > To get FAQ'd: <http://www.nealis.net/ascend/faq>
> > >
> >
> > --
> > Robert A. Pickering Jr.                Internet Services Manager
> > Cincinnati Bell Telephone              rob@fuse.net
> >
> >            A Rough Whimper of Insanity (Information Superhighway)
> >
> > PGP key ID: 75CAFF7D 1995/05/09
> > PGP Fingerprint: B1 63 0C 09 D8 2E 5D 69  BB 61 A2 92 22 37 63 C3
> >
> > ++ Ascend Users Mailing List ++
> > To unsubscribe: send unsubscribe to ascend-users-request@bungi.com
> > To get FAQ'd:   <http://www.nealis.net/ascend/faq>
> 
> 
> 
> --
> Don Joy
> System Administrator
> SooNet Corp
> 
> 

-- 
Robert A. Pickering Jr.                Internet Services Manager
Cincinnati Bell Telephone              rob@fuse.net

           A Rough Whimper of Insanity (Information Superhighway)

PGP key ID: 75CAFF7D 1995/05/09
PGP Fingerprint: B1 63 0C 09 D8 2E 5D 69  BB 61 A2 92 22 37 63 C3
#!/usr/bin/perl

# Hardcoded parameters.
# File is a list of Ascend login passwords.
# Format of file is:
# domain
# login password
# full access password
# Each line should be on a line by itself, against the left margin.
# domain is the domain that each ascend is within, ours is fuse.net
#
$passwd_file = "/usr/local/etc/ascend_pw";

# Read data (if any) into input buffer.
sub read_data {
   my($read,$write,$except,$bytes,$buffer);

   # Attempt to read some input from slave.
   unless (defined($bytes = sysread ASCEND,$buffer,10240)) {
      # An error occurred, abort unless it was EAGAIN.
      die "read: $!\n" unless $! eq "Resource temporarily unavailable";

      # Wait until either reading or writing is possible.
      $except = "";
      vec($except,fileno(ASCEND),1) = 1;
      $read = $write = $except;
      select $read,$write,$except,undef;

      # No input was ready, return undef.
      return undef;
   }

   # Add new data to end of input buffer.
#print STDOUT $buffer;
   $input_buffer .= $buffer;

   # Return the number of bytes read.
   return $bytes;
}

# Send data, buffering input as necessary.
sub send {
   my($buffer) = @_;

   # Read data into input buffer, if any.
   &read_data();

   # Loop until data is sent.
   while (length $buffer) {
      # Read data into input buffer, if any.
      &read_data();

      # Attempt to write the remaining buffer.
      if (defined($bytes = syswrite ASCEND,$buffer,length $buffer)) {
         # Remove sent data from buffer.
         substr($buffer,0,$bytes) = "";
      } else {
         # An error occurred, abort unless it was EAGAIN.
         die "write: $!\n" unless $! eq "Resource temporarily unavailable";
      }
   }
}

# Wait for expected output.
sub wait_for {
   my($pattern) = @_;

   # Loop reading data into input buffer.
   while (1) {
      # Read data into input buffer, return undef for EOF.
      return undef if &read_data() eq 0;

      # Search for pattern in buffer.
      if ($input_buffer =~ /$pattern/) {
         # Save remaining input.
         $input_buffer = $';

         # Return match.
         return $&;
      }
   }
}

# Initialize Fcntl and Socket modules.
use Fcntl;
use Socket;

# Don't buffer output.
$| = 1;

# Get program name.
($program = $0) =~ s/^.*\///;

# Get command-line arguments.
($ascend,@users) = @ARGV;

# Print usage if arguments are bad.
die "Usage: $program <ascend> <session> [...]\n" unless $ascend and @users;

# Read domain and passwords.
open IN,"<$passwd_file" or die "$passwd_file: $!\n";
chomp($domain = <IN>);
chomp($passwd1 = <IN>);
chomp($passwd2 = <IN>);
close IN;

# Add domain if missing.
$ascend .= ".$domain" unless $ascend =~ /\./;

# Open connection to ascend.
print "[$ascend]";
socket(ASCEND,PF_INET,SOCK_STREAM,getprotobyname('tcp')) or die;
connect(ASCEND,sockaddr_in(23,inet_aton($ascend))) or die "connect: $!\n";
print "\n";

# Select connection and set it for unbuffered non-blocking I/O.
select((select(ASCEND),$|=1)[0]);
fcntl ASCEND,F_SETFL,O_NONBLOCK or die "fcntl: $!\n";

# Login to ascend.
&wait_for("Enter password: ");
&send("$passwd1\r");
&wait_for("Main Edit Menu");
&send("\cd");
&wait_for("DO...");
&send("p");
&wait_for("Security profile");
&send("\cp\r");
&wait_for("Enter Password:");
&send("$passwd2\r");
&wait_for("Password accepted.");
&send("\r");
&wait_for("Main Edit Menu");
&send("\cd");
&wait_for("DO...");
&send("e");
&wait_for("\n" x 10);
&wait_for("%");

# If any user names were given instead of sessions, look up session numbers.
if (grep {/\D/} @users) {
   &send("show users\r");
   &wait_for("Address +Name\r\n");
   $/ = "\r\n";
   while (1) {
      $_ = &wait_for(".*[%\n]");
      chomp or last;
      ($session,$user) = (split ' ')[1,7];
      push @{$sessions{$user}},$session;
   }
   die if /\s/;
}

# Kill each specified user/session.
foreach $user (@users) {
   @sessions = $user =~ /\D/ ? @{$sessions{$user}} : $user;
   print "$user: No sessions found.\n" unless @sessions;
   foreach $session (@sessions) {
      &send("kill $session\r");
      &wait_for("\n");
      $_ = &wait_for(".*[%\n]");
      chomp or last;
      print "$_\n";
      &wait_for("%");
   }
}

# Close the connection.
close ASCEND;