From a41ada3bc3283c3e875c2c4ab82799a2c5073205 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 1 Apr 2008 23:26:51 +0000 Subject: [PATCH] remove fs_sesmon --- fs_sesmon/FS-SessionClient/Changes | 5 - fs_sesmon/FS-SessionClient/MANIFEST | 11 -- fs_sesmon/FS-SessionClient/MANIFEST.SKIP | 1 - fs_sesmon/FS-SessionClient/Makefile.PL | 10 -- fs_sesmon/FS-SessionClient/SessionClient.pm | 118 --------------------- fs_sesmon/FS-SessionClient/bin/freeside-login | 36 ------- fs_sesmon/FS-SessionClient/bin/freeside-logout | 36 ------- fs_sesmon/FS-SessionClient/cgi/login.cgi | 108 ------------------- fs_sesmon/FS-SessionClient/cgi/logout.cgi | 83 --------------- fs_sesmon/FS-SessionClient/fs_sessiond | 65 ------------ fs_sesmon/FS-SessionClient/test.pl | 21 ---- fs_sesmon/fs_session_server | 140 ------------------------- 12 files changed, 634 deletions(-) delete mode 100644 fs_sesmon/FS-SessionClient/Changes delete mode 100644 fs_sesmon/FS-SessionClient/MANIFEST delete mode 100644 fs_sesmon/FS-SessionClient/MANIFEST.SKIP delete mode 100644 fs_sesmon/FS-SessionClient/Makefile.PL delete mode 100644 fs_sesmon/FS-SessionClient/SessionClient.pm delete mode 100644 fs_sesmon/FS-SessionClient/bin/freeside-login delete mode 100644 fs_sesmon/FS-SessionClient/bin/freeside-logout delete mode 100644 fs_sesmon/FS-SessionClient/cgi/login.cgi delete mode 100644 fs_sesmon/FS-SessionClient/cgi/logout.cgi delete mode 100644 fs_sesmon/FS-SessionClient/fs_sessiond delete mode 100644 fs_sesmon/FS-SessionClient/test.pl delete mode 100644 fs_sesmon/fs_session_server diff --git a/fs_sesmon/FS-SessionClient/Changes b/fs_sesmon/FS-SessionClient/Changes deleted file mode 100644 index 390a7b946..000000000 --- a/fs_sesmon/FS-SessionClient/Changes +++ /dev/null @@ -1,5 +0,0 @@ -Revision history for Perl extension FS::SessionClient - -0.01 Wed Oct 18 16:34:36 1999 - - original version; created by ivan 1.0 - diff --git a/fs_sesmon/FS-SessionClient/MANIFEST b/fs_sesmon/FS-SessionClient/MANIFEST deleted file mode 100644 index 162d4e453..000000000 --- a/fs_sesmon/FS-SessionClient/MANIFEST +++ /dev/null @@ -1,11 +0,0 @@ -Changes -MANIFEST -MANIFEST.SKIP -Makefile.PL -SessionClient.pm -test.pl -fs_sessiond -cgi/login.cgi -cgi/logout.cgi -bin/freeside-login -bin/freeside-logout diff --git a/fs_sesmon/FS-SessionClient/MANIFEST.SKIP b/fs_sesmon/FS-SessionClient/MANIFEST.SKIP deleted file mode 100644 index ae335e78a..000000000 --- a/fs_sesmon/FS-SessionClient/MANIFEST.SKIP +++ /dev/null @@ -1 +0,0 @@ -CVS/ diff --git a/fs_sesmon/FS-SessionClient/Makefile.PL b/fs_sesmon/FS-SessionClient/Makefile.PL deleted file mode 100644 index 137b6b8bd..000000000 --- a/fs_sesmon/FS-SessionClient/Makefile.PL +++ /dev/null @@ -1,10 +0,0 @@ -use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. -WriteMakefile( - 'NAME' => 'FS::SessionClient', - 'VERSION_FROM' => 'SessionClient.pm', # finds $VERSION - '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 deleted file mode 100644 index 0d3f86b4d..000000000 --- a/fs_sesmon/FS-SessionClient/SessionClient.pm +++ /dev/null @@ -1,118 +0,0 @@ -package FS::SessionClient; - -use strict; -use vars qw($AUTOLOAD $VERSION @ISA @EXPORT_OK $fs_sessiond_socket); -use Exporter; -use Socket; -use FileHandle; -use IO::Handle; - -$VERSION = '0.01'; - -@ISA = qw( Exporter ); -@EXPORT_OK = qw( login logout portnum ); - -$fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket"; - -$ENV{'PATH'} ='/usr/bin:/bin'; -$ENV{'SHELL'} = '/bin/sh'; -$ENV{'IFS'} = " \t\n"; -$ENV{'CDPATH'} = ''; -$ENV{'ENV'} = ''; -$ENV{'BASH_ENV'} = ''; - -my $freeside_uid = scalar(getpwnam('freeside')); -die "not running as the freeside user\n" if $> != $freeside_uid; - -=head1 NAME - -FS::SessionClient - Freeside session client API - -=head1 SYNOPSIS - - use FS::SessionClient qw( login portnum logout ); - - $error = login ( { - 'username' => $username, - 'password' => $password, - 'login' => $timestamp, - 'portnum' => $portnum, - } ); - - $portnum = portnum( { 'ip' => $ip } ) or die "unknown ip!" - $portnum = portnum( { 'nasnum' => $nasnum, 'nasport' => $nasport } ) - or die "unknown nasnum/nasport"; - - $error = logout ( { - 'username' => $username, - 'password' => $password, - 'logout' => $timestamp, - 'portnum' => $portnum, - } ); - -=head1 DESCRIPTION - -This modules provides an API for a remote session application. - -It needs to be run as the freeside user. Because of this, the program which -calls these subroutines should be written very carefully. - -=head1 SUBROUTINES - -=over 4 - -=item login HASHREF - -HASHREF should have the following keys: username, password, login and portnum. -login 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. - -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 logout subroutines, or false -on error. - -=item logout HASHREF - -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. - -Returns a scalar error message, or the empty string for success. - -=cut - -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 "$method\n"; - - print SOCK join("\n", %{$hashref}, 'END' ), "\n"; - SOCK->flush; - - chomp( my $r = ); - $r; -} - -=back - -=head1 BUGS - -=head1 SEE ALSO - -L - -=cut - -1; - - - diff --git a/fs_sesmon/FS-SessionClient/bin/freeside-login b/fs_sesmon/FS-SessionClient/bin/freeside-login deleted file mode 100644 index a6d475169..000000000 --- a/fs_sesmon/FS-SessionClient/bin/freeside-login +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/perl -Tw - -#false-laziness hack w freeside-logout - -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-logout b/fs_sesmon/FS-SessionClient/bin/freeside-logout deleted file mode 100644 index 9b4ecfe23..000000000 --- a/fs_sesmon/FS-SessionClient/bin/freeside-logout +++ /dev/null @@ -1,36 +0,0 @@ -#!/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/cgi/login.cgi b/fs_sesmon/FS-SessionClient/cgi/login.cgi deleted file mode 100644 index 0307c5a3d..000000000 --- a/fs_sesmon/FS-SessionClient/cgi/login.cgi +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/perl -Tw - -#false-laziness hack w logout.cgi - -use strict; -use vars qw( $cgi $username $password $error $ip $portnum ); -use CGI; -use CGI::Carp qw(fatalsToBrowser); -use FS::SessionClient qw( login portnum ); - -$cgi = new CGI; - -if ( defined $cgi->param('magic') ) { - $cgi->param('username') =~ /^\s*(\w{1,255})\s*$/ or do { - $error = "Illegal username"; - &print_form; - exit; - }; - $username = $1; - $cgi->param('password') =~ /^([^\n]{0,255})$/ or die "guru meditation #420"; - $password = $1; - #$ip = $cgi->remote_host; - $ip = $ENV{REMOTE_ADDR}; - $ip =~ /^([\d\.]+)$/ or die "illegal ip: $ip"; - $ip = $1; - $portnum = portnum( { 'ip' => $1 } ) or do { - $error = "You appear to be coming from an unknown IP address. Verify ". - "that your computer is set to obtain an IP address automatically ". - "via DHCP."; - &print_form; - exit; - }; - - ( $error = login ( { - 'username' => $username, - 'portnum' => $portnum, - 'password' => $password, - } ) ) - ? &print_form() - : &print_okay(); - -} else { - $username = ''; - $password = ''; - $error = ''; - &print_form; -} - -sub print_form { - my $self_url = $cgi->self_url; - - print $cgi->header( '-expires' => 'now' ), <login - -END - -print qq!Error: $error! if $error; - -print < - - - - - - - - - - - - - - - - -
- Welcome -
- Username - - -
- Password - - -
- -
- - - -END - -} - -sub print_okay { - print $cgi->header( '-expires' => 'now' ), <login sucessful -login successful, etc. - - -END -} - -sub usage { - die "Usage:\n\n freeside-login username ( portnum | ip | nasnum nasport )"; -} diff --git a/fs_sesmon/FS-SessionClient/cgi/logout.cgi b/fs_sesmon/FS-SessionClient/cgi/logout.cgi deleted file mode 100644 index 95cef98d1..000000000 --- a/fs_sesmon/FS-SessionClient/cgi/logout.cgi +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/perl -Tw - -#false-laziness hack w login.cgi - -use strict; -use vars qw( $cgi $username $password $error $ip $portnum ); -use CGI; -use CGI::Carp qw(fatalsToBrowser); -use FS::SessionClient qw( logout portnum ); - -$cgi = new CGI; - -if ( defined $cgi->param('magic') ) { - $cgi->param('username') =~ /^\s*(\w{1,255})\s*$/ or do { - $error = "Illegal username"; - &print_form; - exit; - }; - $username = $1; - $cgi->param('password') =~ /^([^\n]{0,255})$/ or die "guru meditation #420"; - $password = $1; - #$ip = $cgi->remote_host; - $ip = $ENV{REMOTE_ADDR}; - $ip =~ /^([\d\.]+)$/ or die "illegal ip: $ip"; - $ip = $1; - $portnum = portnum( { 'ip' => $1 } ) or do { - $error = "You appear to be coming from an unknown IP address. Verify ". - "that your computer is set to obtain an IP address automatically ". - "via DHCP."; - &print_form; - exit; - }; - - ( $error = logout ( { - 'username' => $username, - 'portnum' => $portnum, - 'password' => $password, - } ) ) - ? &print_form() - : &print_okay(); - -} else { - $username = ''; - $password = ''; - $error = ''; - &print_form; -} - -sub print_form { - my $self_url = $cgi->self_url; - - print $cgi->header( '-expires' => 'now' ), <logout - -END - -print qq!Error: $error! if $error; - -print < - -Username
-Password
- - - - -END - -} - -sub print_okay { - print $cgi->header( '-expires' => 'now' ), <logout sucessful -logout successful, etc. - - -END -} - -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 deleted file mode 100644 index bfdb20a1d..000000000 --- a/fs_sesmon/FS-SessionClient/fs_sessiond +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/perl -Tw -# -# fs_sessiond -# -# This is run REMOTELY over ssh by fs_session_server -# - -use strict; -use Socket; - -use vars qw( $Debug ); - -$Debug = 1; - -my $fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket"; - -$ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin'; -$ENV{'SHELL'} = '/bin/sh'; -$ENV{'IFS'} = " \t\n"; -$ENV{'CDPATH'} = ''; -$ENV{'ENV'} = ''; -$ENV{'BASH_ENV'} = ''; - -$|=1; - -my $me = "[fs_sessiond]"; - -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_sessiond_socket); -my $proto = getprotobyname('tcp'); -socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!"; -unlink($fs_sessiond_socket); -bind(Server, $uaddr) or die "bind: $!"; -listen(Server,SOMAXCONN) or die "listen: $!"; - -warn "$me entering main loop\n" if $Debug; -my $paddr; -for ( ; $paddr = accept(Client,Server); close Client) { - - chomp( my $command = ); - - if ( $command eq 'login' || $command eq 'logout' || $command eq 'portnum' ) { - warn "$me reading data from local client\n" if $Debug; - my @data; - my $dos = 0; - push @data, scalar() until $dos++ == 99 || $data[$#data] eq "END\n"; - if ( $dos == 99 ) { - warn "$me WARNING: DoS attempt!" - } else { - warn "$me sending data to remote server\n" if $Debug; - print "$command\n", @data; - warn "$me reading result from remote server\n" if $Debug; - my $error = ; - warn "$me sending error to local client\n" if $Debug; - print Client $error; - } - } else { - warn "$me WARNING: unexpected command from client: $command"; - } - -} - diff --git a/fs_sesmon/FS-SessionClient/test.pl b/fs_sesmon/FS-SessionClient/test.pl deleted file mode 100644 index 4b9ae17e0..000000000 --- a/fs_sesmon/FS-SessionClient/test.pl +++ /dev/null @@ -1,21 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### We start with some black magic to print on failure. - -# Change 1..1 below to 1..last_test_to_print . -# (It may become useful if the test is moved to ./t subdirectory.) - -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -#use FS::SessionClient; -#sigh, "not running as the freeside user" -$loaded = 1; -print "ok 1\n"; - -######################### End of black magic. - -# Insert your test code below (better if it prints "ok 13" -# (correspondingly "not ok 13") depending on the success of chunk 13 -# of the test code): - diff --git a/fs_sesmon/fs_session_server b/fs_sesmon/fs_session_server deleted file mode 100644 index 00229f8dc..000000000 --- a/fs_sesmon/fs_session_server +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/perl -Tw -# -# fs_session_server -# - -use strict; -use vars qw( $opt $Debug ); -use IO::Handle; -use Net::SSH qw(sshopen2); -use FS::UID qw(adminsuidsetup dbh); -use FS::Record qw( qsearchs ); #qsearch ); -#use FS::cust_main_county; -#use FS::cust_main; -use FS::session; -use FS::port; -use FS::svc_acct; - -#require "configfile"; -$Debug = 1; - -my $user = shift or die &usage; -&adminsuidsetup( $user ); - -my $machine = shift or die &usage; - -my $fs_sessiond = "/usr/local/sbin/fs_sessiond"; - -my $me = "[fs_session_server]"; - -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_sessiond); - - warn "$me Entering main loop\n" if $Debug; - while (1) { - warn "$me Reading (waiting for) data\n" if $Debug; - my $command = scalar(<$reader>); - chomp $command; - #DoS protection here too, to protect against a compromised client? *sigh* - my %hash; - while ( ( my $key = scalar(<$reader>) ) ne "END\n" ) { - chomp $key; - chomp( $hash{$key} = scalar(<$reader>) ); - } - - if ( $command eq 'login' ) { - my $error = &login(\%hash); - print $writer "$error\n"; - } 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 } ); - } 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: $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; - my $svc_acct = qsearchs('svc_acct', { 'username' => $username } ) - or return "Unknown user"; - return "Incorrect password" - if exists($href->{'password'}) - && $href->{'password'} ne $svc_acct->_password; - return "Time limit exceeded" unless $svc_acct->seconds; - 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; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; - my $svc_acct = - qsearchs('svc_acct', { 'username' => $username }, '', 'FOR UPDATE' ) - or return "Unknown user"; - return "Incorrect password" - if exists($href->{'password'}) - && $href->{'password'} ne $svc_acct->_password; - my $session = qsearchs( 'session', { - 'portnum' => $href->{'portnum'}, - 'svcnum' => $svc_acct->svcnum, - 'logout' => '', - }, - '', 'FOR UPDATE' - ); - unless ( $session ) { - $dbh->rollback; - return "No currently open sessions found for that user/port!"; - } - my $nsession = new FS::session ( { $session->hash } ); - warn "$nsession replacing $session"; - my $error = $nsession->replace($session); - if ( $error ) { - $dbh->rollback; - return "can't logout: $error"; - } - my $time = $nsession->logout - $nsession->login; - my $new_svc_acct = new FS::svc_acct ( { $svc_acct->hash } ); - my $seconds = $new_svc_acct->seconds; - $seconds -= $time; - $seconds = 0 if $seconds < 0; - $new_svc_acct->seconds( $seconds ); - $error = $new_svc_acct->replace( $svc_acct ); - warn "can't debit time: $error\n"; #don't want to rollback, though - $dbh->commit or die $dbh->errstr; - '' -} - -sub usage { - die "Usage:\n\n fs_session_server user machine\n"; -} - -- 2.11.0