X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsession.pm;h=027708d989a90eb72380b6ce141e3f70ab46121d;hp=0d766bd221c904fe28055cb8c39e56230717f14f;hb=b90f8cdac9371c219a72dda16f8deecc7c44fc28;hpb=eea322178c024e57730831556d28a78524df7450 diff --git a/FS/FS/session.pm b/FS/FS/session.pm index 0d766bd22..027708d98 100644 --- a/FS/FS/session.pm +++ b/FS/FS/session.pm @@ -4,6 +4,8 @@ use strict; use vars qw( @ISA ); use FS::Record qw( qsearchs ); use FS::svc_acct; +use FS::port; +use FS::nas; @ISA = qw(FS::Record); @@ -31,6 +33,8 @@ FS::session - Object methods for session records $error = $record->check; + $error = $record->nas_heartbeat($timestamp); + =head1 DESCRIPTION An FS::session object represents an user login session. FS::session inherits @@ -57,7 +61,7 @@ from FS::Record. The following fields are currently supported: =item new HASHREF -Creates a new example. To add the example to the database, see L<"insert">. +Creates a new session. To add the session to the database, see L<"insert">. Note that this stores the hash reference, not a distinct copy of the hash it points to. You can ask the object for a copy with the I method. @@ -90,11 +94,16 @@ sub insert { $error = $self->check; return $error if $error; + return "a session on that port is already open!" + if qsearchs('session', { 'portnum' => $self->portnum, 'logout' => '' } ); + $self->setfield('login', time()) unless $self->getfield('login'); $error = $self->SUPER::insert; return $error if $error; + $self->nas_heartbeat($self->getfield('login')); + #session-starting callback! ''; @@ -118,7 +127,7 @@ it is replaced with the current time. =cut sub replace { - my $self = shift; + my($self, $old) = @_; my $error; local $SIG{HUP} = 'IGNORE'; @@ -133,9 +142,11 @@ sub replace { $self->setfield('logout', time()) unless $self->getfield('logout'); - $error = $self->SUPER::replace; + $error = $self->SUPER::replace($old); return $error if $error; + $self->nas_heartbeat($self->getfield('logout')); + #session-ending callback! ''; @@ -143,7 +154,7 @@ sub replace { =item check -Checks all fields to make sure this is a valid example. If there is +Checks all fields to make sure this is a valid session. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods. @@ -167,15 +178,45 @@ sub check { ''; } +=item nas_heartbeat + +Heartbeats the nas associated with this session (see L). + +=cut + +sub nas_heartbeat { + my $self = shift; + my $port = qsearchs('port',{'portnum'=>$self->portnum}); + my $nas = qsearchs('nas',{'nasnum'=>$port->nasnum}); + $nas->heartbeat(shift); +} + +=item svc_acct + +Returns the svc_acct record associated with this session (see L). + +=cut + +sub svc_acct { + my $self = shift; + qsearchs('svc_acct', { 'svcnum' => $self->svcnum } ); +} + =back =head1 VERSION -$Id: session.pm,v 1.1 2000-10-27 20:18:32 ivan Exp $ +$Id: session.pm,v 1.3 2000-12-03 20:25:20 ivan Exp $ =head1 BUGS -The author forgot to customize this manpage. +Maybe you shouldn't be able to insert a session if there's currently an open +session on that port. Or maybe the open session on that port should be flagged +as problematic? autoclosed? *sigh* + +Hmm, sessions refer to current svc_acct records... probably need to constrain +deletions to svc_acct records such that no svc_acct records are deleted which +have a session (even if long-closed). =head1 SEE ALSO