From b90f8cdac9371c219a72dda16f8deecc7c44fc28 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 3 Dec 2000 20:25:20 +0000 Subject: session monitor updates --- fs_sesmon/FS-SessionClient/MANIFEST | 4 +-- fs_sesmon/FS-SessionClient/Makefile.PL | 2 +- fs_sesmon/FS-SessionClient/SessionClient.pm | 22 ++++++++------ fs_sesmon/FS-SessionClient/bin/freeside-login | 2 +- fs_sesmon/FS-SessionClient/bin/freeside-logoff | 37 ----------------------- fs_sesmon/FS-SessionClient/bin/freeside-logout | 36 ++++++++++++++++++++++ fs_sesmon/FS-SessionClient/fs_sessiond | 10 +++--- fs_sesmon/FS-SessionClient/test.pl | 3 +- fs_sesmon/fs_session_server | 42 ++++++++++++++------------ 9 files changed, 82 insertions(+), 76 deletions(-) delete mode 100644 fs_sesmon/FS-SessionClient/bin/freeside-logoff create mode 100644 fs_sesmon/FS-SessionClient/bin/freeside-logout (limited to 'fs_sesmon') diff --git a/fs_sesmon/FS-SessionClient/MANIFEST b/fs_sesmon/FS-SessionClient/MANIFEST index 6da7b22e9..9da279a87 100644 --- a/fs_sesmon/FS-SessionClient/MANIFEST +++ b/fs_sesmon/FS-SessionClient/MANIFEST @@ -6,6 +6,6 @@ SessionClient.pm test.pl fs_sessiond cgi/logon.cgi -cgi/logoff.cgi +cgi/logout.cgi bin/freeside-login -bin/freeside-logoff +bin/freeside-logout diff --git a/fs_sesmon/FS-SessionClient/Makefile.PL b/fs_sesmon/FS-SessionClient/Makefile.PL index 1f598474a..137b6b8bd 100644 --- a/fs_sesmon/FS-SessionClient/Makefile.PL +++ b/fs_sesmon/FS-SessionClient/Makefile.PL @@ -4,7 +4,7 @@ use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'FS::SessionClient', 'VERSION_FROM' => 'SessionClient.pm', # finds $VERSION - 'EXE_FILES' => [ qw(fs_sessiond freeside-login freeside-logoff) ], + 'EXE_FILES' => [ qw(fs_sessiond bin/freeside-login bin/freeside-logout) ], 'INSTALLSCRIPT' => '/usr/local/sbin', 'PERM_RWX' => '750', ); diff --git a/fs_sesmon/FS-SessionClient/SessionClient.pm b/fs_sesmon/FS-SessionClient/SessionClient.pm index 97332cb26..8a0ff705f 100644 --- a/fs_sesmon/FS-SessionClient/SessionClient.pm +++ b/fs_sesmon/FS-SessionClient/SessionClient.pm @@ -10,7 +10,7 @@ use IO::Handle; $VERSION = '0.01'; @ISA = qw( Exporter ); -@EXPORT_OK = qw( login logoff portnum ); +@EXPORT_OK = qw( login logout portnum ); $fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket"; @@ -30,7 +30,7 @@ FS::SessionClient - Freeside session client API =head1 SYNOPSIS - use FS::SessionClient qw( login portnum logoff ); + use FS::SessionClient qw( login portnum logout ); $error = login ( { 'username' => $username, @@ -43,10 +43,10 @@ FS::SessionClient - Freeside session client API $portnum = portnum( { 'nasnum' => $nasnum, 'nasport' => $nasport } ) or die "unknown nasnum/nasport"; - $error = logoff ( { + $error = logout ( { 'username' => $username, 'password' => $password, - 'logoff' => $timestamp, + 'logout' => $timestamp, 'portnum' => $portnum, } ); @@ -73,13 +73,13 @@ Returns a scalar error message, or the empty string for success. =item portnum HASHREF should contain a single key: ip, or the two keys: nasnum and nasport. -Returns a portnum suitable for the login and logoff subroutines, or false +Returns a portnum suitable for the login and logout subroutines, or false on error. -=item logoff HASHREF +=item logout HASHREF -HASHREF should have the following keys: usrename, password, logoff and portnum. -logoff is a UNIX timestamp; if not specified, will default to the current time. +HASHREF should have the following keys: usrename, password, logout and portnum. +logout is a UNIX timestamp; if not specified, will default to the current time. Starts a new session for the specified user and portnum. The password is optional, but must be correct if specified. @@ -89,9 +89,11 @@ Returns a scalar error message, or the empty string for success. sub AUTOLOAD { my $hashref = shift; + my $method = $AUTOLOAD; + $method =~ s/^.*:://; socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!"; connect(SOCK, sockaddr_un($fs_sessiond_socket)) or die "connect: $!"; - print SOCK "$AUTOLOAD\n"; + print SOCK "$method\n"; print SOCK join("\n", %{$hashref}, 'END' ), "\n"; SOCK->flush; @@ -104,7 +106,7 @@ sub AUTOLOAD { =head1 VERSION -$Id: SessionClient.pm,v 1.2 2000-11-07 15:00:37 ivan Exp $ +$Id: SessionClient.pm,v 1.3 2000-12-03 20:25:20 ivan Exp $ =head1 BUGS diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-login b/fs_sesmon/FS-SessionClient/bin/freeside-login index 6ca4455f8..a6d475169 100644 --- a/fs_sesmon/FS-SessionClient/bin/freeside-login +++ b/fs_sesmon/FS-SessionClient/bin/freeside-login @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw -#false-laziness hack w freeside-logoff +#false-laziness hack w freeside-logout use strict; use FS::SessionClient qw( login portnum ); diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-logoff b/fs_sesmon/FS-SessionClient/bin/freeside-logoff deleted file mode 100644 index f7b876b33..000000000 --- a/fs_sesmon/FS-SessionClient/bin/freeside-logoff +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -Tw - -#false-laziness hack w freeside-login - -use strict; -use FS::SessionClient qw( logoff portnum ); - -my $username = shift; - -my $portnum; -if ( scalar(@ARGV) == 1 ) { - my $arg = shift; - if ( $arg =~ /^(\d+)$/ ) { - $portnum = $1; - } elsif ( $arg =~ /^([\d\.]+)$/ ) { - $portnum = portnum( { 'ip' => $1 } ) or die "unknown ip!" - } else { - &usage; - } -} elsif ( scalar(@ARGV) == 2 ) { - $portnum = portnum( { 'nasnum' => shift, 'nasport' => shift } ) - or die "unknown nasnum/nasport"; -} else { - &usage; -} - -my $error = login ( { - 'username' => $username, - 'portnum' => $portnum, -} ); - -warn $error if $error; - -sub usage { - die "Usage:\n\n freeside-logoff username ( portnum | ip | nasnum nasport )"; -} - diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-logout b/fs_sesmon/FS-SessionClient/bin/freeside-logout new file mode 100644 index 000000000..9b4ecfe23 --- /dev/null +++ b/fs_sesmon/FS-SessionClient/bin/freeside-logout @@ -0,0 +1,36 @@ +#!/usr/bin/perl -Tw + +#false-laziness hack w freeside-login + +use strict; +use FS::SessionClient qw( logout portnum ); + +my $username = shift; + +my $portnum; +if ( scalar(@ARGV) == 1 ) { + my $arg = shift; + if ( $arg =~ /^(\d+)$/ ) { + $portnum = $1; + } elsif ( $arg =~ /^([\d\.]+)$/ ) { + $portnum = portnum( { 'ip' => $1 } ) or die "unknown ip!" + } else { + &usage; + } +} elsif ( scalar(@ARGV) == 2 ) { + $portnum = portnum( { 'nasnum' => shift, 'nasport' => shift } ) + or die "unknown nasnum/nasport"; +} else { + &usage; +} + +my $error = logout ( { + 'username' => $username, + 'portnum' => $portnum, +} ); + +warn $error if $error; + +sub usage { + die "Usage:\n\n freeside-logout username ( portnum | ip | nasnum nasport )"; +} diff --git a/fs_sesmon/FS-SessionClient/fs_sessiond b/fs_sesmon/FS-SessionClient/fs_sessiond index 74d3aab31..d7284b252 100644 --- a/fs_sesmon/FS-SessionClient/fs_sessiond +++ b/fs_sesmon/FS-SessionClient/fs_sessiond @@ -12,7 +12,7 @@ use vars qw( $Debug ); $Debug = 1; -my $fs_session_socket = "/usr/local/freeside/fs_sessiond_socket"; +my $fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket"; $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin'; $ENV{'SHELL'} = '/bin/sh'; @@ -29,10 +29,10 @@ warn "$me starting\n" if $Debug; #nothing to read from server warn "$me creating $fs_sessiond_socket\n" if $Debug; -my $uaddr = sockaddr_un($fs_signupd_socket); +my $uaddr = sockaddr_un($fs_sessiond_socket); my $proto = getprotobyname('tcp'); socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!"; -unlink($fs_signup_socket); +unlink($fs_sessiond_socket); bind(Server, $uaddr) or die "bind: $!"; listen(Server,SOMAXCONN) or die "listen: $!"; @@ -44,8 +44,8 @@ for ( ; $paddr = accept(Client,Server); close Client) { if ( $command eq 'login' || $command eq 'logout' || $command eq 'portnum' ) { warn "$me reading data from local client\n" if $Debug; - my @data, $dos; - push @data, scalar() until $dos++ == 99 || $data[$#data] != "END\n"; + my( @data, $dos ); + push @data, scalar() until $dos++ == 99 || $data[$#data] eq "END\n"; if ( $dos == 99 ) { warn "$me WARNING: DoS attempt!" } else { diff --git a/fs_sesmon/FS-SessionClient/test.pl b/fs_sesmon/FS-SessionClient/test.pl index d05201b66..4b9ae17e0 100644 --- a/fs_sesmon/FS-SessionClient/test.pl +++ b/fs_sesmon/FS-SessionClient/test.pl @@ -8,7 +8,8 @@ BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} -use FS::SessionClient; +#use FS::SessionClient; +#sigh, "not running as the freeside user" $loaded = 1; print "ok 1\n"; diff --git a/fs_sesmon/fs_session_server b/fs_sesmon/fs_session_server index 46e53d118..0930a3c00 100644 --- a/fs_sesmon/fs_session_server +++ b/fs_sesmon/fs_session_server @@ -6,9 +6,9 @@ use strict; use vars qw( $opt $Debug ); use IO::Handle; -use Net::SSH qw(sshopen3) +use Net::SSH qw(sshopen2); use FS::UID qw(adminsuidsetup); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearchs ); #qsearch ); #use FS::cust_main_county; #use FS::cust_main; use FS::session; @@ -31,25 +31,28 @@ while (1) { my($reader, $writer) = (new IO::Handle, new IO::Handle); $writer->autoflush(1); warn "$me Connecting to $machine\n" if $Debug; - sshopen2($machine,$reader,$writer,$fs_signupd); + sshopen2($machine,$reader,$writer,$fs_sessiond); warn "$me Entering main loop\n" if $Debug; while (1) { warn "$me Reading (waiting for) data\n" if $Debug; - my $command = scalar(<$reader)); + my $command = scalar(<$reader>); + chomp $command; #DoS protection here too, to protect against a compromised client? *sigh* - while ( ( my $key = scalar(<$reader>) ) != "END\n" ) { + my %hash; + while ( ( my $key = scalar(<$reader>) ) ne "END\n" ) { chomp $key; chomp( $hash{$key} = scalar(<$reader>) ); } if ( $command eq 'login' ) { - $error = &login(\%hash); + my $error = &login(\%hash); print $writer "$error\n"; - } elsif ( $command eq 'logoff' ) { - $error = &logoff(\%hash); + } elsif ( $command eq 'logout' ) { + my $error = &logout(\%hash); print $writer "$error\n"; } elsif ( $command eq 'portnum' ) { + my $port; if ( exists $hash{'ip'} ) { $hash{'ip'} =~ /^([\d\.]+)$/ or $1='nomatch'; $port = qsearchs('port', { 'ip' => $1 } ); @@ -60,13 +63,13 @@ while (1) { } print $writer ( $port ? $port->portnum : '' ), "\n"; } else { - warn "$me WARNING: unrecognized command"; + warn "$me WARNING: unrecognized command: $command"; } } #won't ever reach without code above to throw out of loop, but... close $writer; close $reader; - warn "connection to $machine lost!\n" + warn "connection to $machine lost!\n"; sleep 5; warn "reconnecting...\n"; } @@ -75,10 +78,10 @@ sub login { my $href = shift; $href->{'username'} =~ /^([a-z0-9_\-\.]+)$/ or return "Illegal username"; my $username = $1; - $svc_acct = qsearchs('svc_acct', { 'username' => $username } ) + my $svc_acct = qsearchs('svc_acct', { 'username' => $username } ) or return "Unknown user"; return "Incorrect password" - if defined($href->{'password'}) + if exists($href->{'password'}) && $href->{'password'} ne $svc_acct->_password; my $session = new FS::session { 'portnum' => $href->{'portnum'}, @@ -92,18 +95,19 @@ sub logout { my $href = shift; $href->{'username'} =~ /^([a-z0-9_\-\.]+)$/ or return "Illegal username"; my $username = $1; - $svc_acct = qsearchs('svc_acct', { 'username' => $username } ) + my $svc_acct = qsearchs('svc_acct', { 'username' => $username } ) or return "Unknown user"; return "Incorrect password" - if defined($href->{'password'}) + if exists($href->{'password'}) && $href->{'password'} ne $svc_acct->_password; - my $session = qsearchs FS::session { + my $session = qsearchs( 'session', { 'portnum' => $href->{'portnum'}, 'svcnum' => $svc_acct->svcnum, - 'logoff' => '', - }; - return "No currently open sessios found for that user/port!" unless $session; - my $nsession = new FS::session ( { $old->hash } ); + 'logout' => '', + } ); + return "No currently open sessions found for that user/port!" unless $session; + my $nsession = new FS::session ( { $session->hash } ); + warn "$nsession replacing $session"; $nsession->replace($session); } -- cgit v1.2.1