summaryrefslogtreecommitdiff
path: root/fs_sesmon
diff options
context:
space:
mode:
authorivan <ivan>2000-11-07 15:00:37 +0000
committerivan <ivan>2000-11-07 15:00:37 +0000
commit7f07089722bfcabe3bf42619bb2bdb81fd8d44e1 (patch)
tree8bbfe5b33182d68cd89e63176a11dcc468091ed0 /fs_sesmon
parentb31966d5d1f9d8629bd28ff1c2ff37a5c84965c1 (diff)
session monitor
Diffstat (limited to 'fs_sesmon')
-rw-r--r--fs_sesmon/FS-SessionClient/MANIFEST2
-rw-r--r--fs_sesmon/FS-SessionClient/Makefile.PL2
-rw-r--r--fs_sesmon/FS-SessionClient/SessionClient.pm6
-rw-r--r--fs_sesmon/FS-SessionClient/bin/freeside-login36
-rw-r--r--fs_sesmon/FS-SessionClient/bin/freeside-logoff37
-rw-r--r--fs_sesmon/fs_session_server66
6 files changed, 142 insertions, 7 deletions
diff --git a/fs_sesmon/FS-SessionClient/MANIFEST b/fs_sesmon/FS-SessionClient/MANIFEST
index 3ced1df17..6da7b22e9 100644
--- a/fs_sesmon/FS-SessionClient/MANIFEST
+++ b/fs_sesmon/FS-SessionClient/MANIFEST
@@ -7,3 +7,5 @@ test.pl
fs_sessiond
cgi/logon.cgi
cgi/logoff.cgi
+bin/freeside-login
+bin/freeside-logoff
diff --git a/fs_sesmon/FS-SessionClient/Makefile.PL b/fs_sesmon/FS-SessionClient/Makefile.PL
index 8dff176a7..1f598474a 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' => [ 'fs_sessiond' ],
+ 'EXE_FILES' => [ qw(fs_sessiond freeside-login freeside-logoff) ],
'INSTALLSCRIPT' => '/usr/local/sbin',
'PERM_RWX' => '750',
);
diff --git a/fs_sesmon/FS-SessionClient/SessionClient.pm b/fs_sesmon/FS-SessionClient/SessionClient.pm
index fd50e8908..97332cb26 100644
--- a/fs_sesmon/FS-SessionClient/SessionClient.pm
+++ b/fs_sesmon/FS-SessionClient/SessionClient.pm
@@ -1,7 +1,7 @@
package FS::SessionClient;
use strict;
-use vars qw($VERSION @ISA @EXPORT_OK $fs_sessiond_socket);
+use vars qw($AUTOLOAD $VERSION @ISA @EXPORT_OK $fs_sessiond_socket);
use Exporter;
use Socket;
use FileHandle;
@@ -10,7 +10,7 @@ use IO::Handle;
$VERSION = '0.01';
@ISA = qw( Exporter );
-@EXPORT_OK = qw( login logoff );
+@EXPORT_OK = qw( login logoff portnum );
$fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket";
@@ -104,7 +104,7 @@ sub AUTOLOAD {
=head1 VERSION
-$Id: SessionClient.pm,v 1.1 2000-10-27 20:15:50 ivan Exp $
+$Id: SessionClient.pm,v 1.2 2000-11-07 15:00:37 ivan Exp $
=head1 BUGS
diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-login b/fs_sesmon/FS-SessionClient/bin/freeside-login
new file mode 100644
index 000000000..6ca4455f8
--- /dev/null
+++ b/fs_sesmon/FS-SessionClient/bin/freeside-login
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -Tw
+
+#false-laziness hack w freeside-logoff
+
+use strict;
+use FS::SessionClient qw( login 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-login username ( portnum | ip | nasnum nasport )";
+}
diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-logoff b/fs_sesmon/FS-SessionClient/bin/freeside-logoff
new file mode 100644
index 000000000..f7b876b33
--- /dev/null
+++ b/fs_sesmon/FS-SessionClient/bin/freeside-logoff
@@ -0,0 +1,37 @@
+#!/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_session_server b/fs_sesmon/fs_session_server
index be0a01710..46e53d118 100644
--- a/fs_sesmon/fs_session_server
+++ b/fs_sesmon/fs_session_server
@@ -12,6 +12,8 @@ use FS::Record qw( qsearch qsearchs );
#use FS::cust_main_county;
#use FS::cust_main;
use FS::session;
+use FS::port;
+use FS::svc_acct;
#require "configfile";
$Debug = 1;
@@ -42,12 +44,70 @@ while (1) {
}
if ( $command eq 'login' ) {
-
+ $error = &login(\%hash);
+ print $writer "$error\n";
} elsif ( $command eq 'logoff' ) {
-
+ $error = &logoff(\%hash);
+ print $writer "$error\n";
} elsif ( $command eq 'portnum' ) {
-
+ if ( exists $hash{'ip'} ) {
+ $hash{'ip'} =~ /^([\d\.]+)$/ or $1='nomatch';
+ $port = qsearchs('port', { 'ip' => $1 } );
+ } else {
+ $hash{'nasnum'} =~ /^(\d+)$/ and my $nasnum = $1;
+ $hash{'nasport'} =~ /^(\d+)$/ and my $nasport = $1;
+ $port = qsearchs('port', { 'nasnum'=>$nasnum, 'nasport'=>$nasport } );
+ }
+ print $writer ( $port ? $port->portnum : '' ), "\n";
} else {
warn "$me WARNING: unrecognized command";
}
+ }
+ #won't ever reach without code above to throw out of loop, but...
+ close $writer;
+ close $reader;
+ warn "connection to $machine lost!\n"
+ sleep 5;
+ warn "reconnecting...\n";
+}
+
+sub login {
+ my $href = shift;
+ $href->{'username'} =~ /^([a-z0-9_\-\.]+)$/ or return "Illegal username";
+ my $username = $1;
+ $svc_acct = qsearchs('svc_acct', { 'username' => $username } )
+ or return "Unknown user";
+ return "Incorrect password"
+ if defined($href->{'password'})
+ && $href->{'password'} ne $svc_acct->_password;
+ my $session = new FS::session {
+ 'portnum' => $href->{'portnum'},
+ 'svcnum' => $svc_acct->svcnum,
+ 'login' => $href->{'login'},
+ };
+ $session->insert;
+}
+
+sub logout {
+ my $href = shift;
+ $href->{'username'} =~ /^([a-z0-9_\-\.]+)$/ or return "Illegal username";
+ my $username = $1;
+ $svc_acct = qsearchs('svc_acct', { 'username' => $username } )
+ or return "Unknown user";
+ return "Incorrect password"
+ if defined($href->{'password'})
+ && $href->{'password'} ne $svc_acct->_password;
+ my $session = qsearchs FS::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 } );
+ $nsession->replace($session);
+}
+
+sub usage {
+ die "Usage:\n\n fs_session_server user machine\n";
+}