summaryrefslogtreecommitdiff
path: root/fs_sesmon
diff options
context:
space:
mode:
authorivan <ivan>2001-02-03 14:03:50 +0000
committerivan <ivan>2001-02-03 14:03:50 +0000
commitd220c8a4bfa1aee8f17ed71c2dba655160dd3595 (patch)
tree67e5270d4dbe6d98bf1d6f6213c057997d877e31 /fs_sesmon
parentd746dfce2e320169ec8217cb09b9dbb0d403675d (diff)
time-based prepaid cards, session monitor. woop!
Diffstat (limited to 'fs_sesmon')
-rw-r--r--fs_sesmon/fs_session_server39
1 files changed, 31 insertions, 8 deletions
diff --git a/fs_sesmon/fs_session_server b/fs_sesmon/fs_session_server
index 0930a3c00..00229f8dc 100644
--- a/fs_sesmon/fs_session_server
+++ b/fs_sesmon/fs_session_server
@@ -7,7 +7,7 @@ use strict;
use vars qw( $opt $Debug );
use IO::Handle;
use Net::SSH qw(sshopen2);
-use FS::UID qw(adminsuidsetup);
+use FS::UID qw(adminsuidsetup dbh);
use FS::Record qw( qsearchs ); #qsearch );
#use FS::cust_main_county;
#use FS::cust_main;
@@ -83,6 +83,7 @@ sub login {
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,
@@ -95,20 +96,42 @@ sub logout {
my $href = shift;
$href->{'username'} =~ /^([a-z0-9_\-\.]+)$/ or return "Illegal username";
my $username = $1;
- my $svc_acct = qsearchs('svc_acct', { 'username' => $username } )
+ 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' => '',
- } );
- return "No currently open sessions found for that user/port!" unless $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";
- $nsession->replace($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 {