package FS::nas;
use strict;
-use vars qw( @ISA );
-use FS::Record qw(qsearchs); #qsearch);
-use FS::UID qw( dbh );
-
-@ISA = qw(FS::Record);
+use base qw( FS::m2m_Common FS::Record );
+use FS::Record qw( qsearch qsearchs dbh );
+use FS::export_nas;
+use FS::part_export;
=head1 NAME
use FS::nas;
$record = new FS::nas \%hash;
- $record = new FS::nas {
- 'nasnum' => 1,
- 'nasip' => '10.4.20.23',
- 'nasfqdn' => 'box1.brc.nv.us.example.net',
- };
+ $record = new FS::nas { 'column' => 'value' };
$error = $record->insert;
$error = $record->check;
- $error = $record->heartbeat($timestamp);
-
=head1 DESCRIPTION
-An FS::nas object represents an Network Access Server on your network, such as
-a terminal server or equivalent. FS::nas inherits from FS::Record. The
-following fields are currently supported:
+An FS::nas object represents a RADIUS client. FS::nas inherits from
+FS::Record. The following fields are currently supported:
=over 4
=item nasnum - primary key
-=item nas - NAS name
+=item nasname - "NAS name", i.e. IP address
+
+=item shortname - short descriptive name
+
+=item type - the equipment vendor
+
+=item ports
+
+=item secret - the authentication secret for this client
+
+=item server - virtual server name (optional)
-=item nasip - NAS ip address
+=item community
-=item nasfqdn - NAS fully-qualified domain name
+=item description - a longer descriptive name
-=item last - timestamp indicating the last instant the NAS was in a known
- state (used by the session monitoring).
+=item svcnum - the L<FS::svc_broadband> record that 'owns' this device
=back
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
-=cut
-
-# the insert method can be inherited from FS::Record
-
=item delete
-Delete this record from the database.
+Delete this record from the database and remove all linked exports.
=cut
-# the delete method can be inherited from FS::Record
+sub delete {
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $self = shift;
+ my $error = $self->process_m2m(
+ link_table => 'export_nas',
+ target_table => 'part_export',
+ params => []
+ ) || $self->SUPER::delete;
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit if $oldAutoCommit;
+ '';
+}
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
+To change the list of linked exports, see the C<export_nas> method.
+
=cut
-# the replace method can be inherited from FS::Record
+sub replace {
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my ($self, $old) = @_;
+ $old ||= qsearchs('nas', { 'nasnum' => $self->nasnum });
+
+ my $error;
+ foreach my $part_export ( $self->part_export ) {
+ $error ||= $part_export->export_nas_replace($self, $old);
+ }
+
+ $error ||= $self->SUPER::replace($old);
+
+ if ( $error ) {
+ $dbh->rollback;
+ return $error;
+ }
+
+ $dbh->commit if $oldAutoCommit;
+ '';
+}
=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 NAS. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
sub check {
my $self = shift;
- $self->ut_numbern('nasnum')
- || $self->ut_text('nas')
- || $self->ut_ip('nasip')
- || $self->ut_domain('nasfqdn')
- || $self->ut_numbern('last');
+ my $error =
+ $self->ut_numbern('nasnum')
+ || $self->ut_text('nasname')
+ || $self->ut_textn('shortname')
+ || $self->ut_text('type')
+ || $self->ut_numbern('ports')
+ || $self->ut_text('secret')
+ || $self->ut_textn('server')
+ || $self->ut_textn('community')
+ || $self->ut_text('description')
+ || $self->ut_foreign_keyn('svcnum', 'svc_broadband', 'svcnum')
+ ;
+ return $error if $error;
+
+ $self->SUPER::check;
}
-=item heartbeat TIMESTAMP
+=item part_export
-Updates the timestamp for this nas
+Return all L<FS::part_export> objects to which this NAS is being exported.
=cut
-sub heartbeat {
- my($self, $timestamp) = @_;
- my $dbh = dbh;
- my $sth =
- $dbh->prepare("UPDATE nas SET last = ? WHERE nasnum = ? AND last < ?");
- $sth->execute($timestamp, $self->nasnum, $timestamp) or die $sth->errstr;
- $self->last($timestamp);
+sub part_export {
+ my $self = shift;
+ map { qsearchs('part_export', { exportnum => $_->exportnum }) }
+ qsearch('export_nas', { nasnum => $self->nasnum})
}
=back
-=head1 VERSION
-
-$Id: nas.pm,v 1.5 2001-04-15 13:35:12 ivan Exp $
-
=head1 BUGS
=head1 SEE ALSO