torrus virtual ports, RT#10574
authorivan <ivan>
Sun, 27 Feb 2011 00:52:29 +0000 (00:52 +0000)
committerivan <ivan>
Sun, 27 Feb 2011 00:52:29 +0000 (00:52 +0000)
14 files changed:
FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
FS/FS/Schema.pm
FS/FS/torrus_srvderive.pm [new file with mode: 0644]
FS/FS/torrus_srvderive_component.pm [new file with mode: 0644]
FS/MANIFEST
FS/t/torrus_srvderive.t [new file with mode: 0644]
FS/t/torrus_srvderive_component.t [new file with mode: 0644]
httemplate/browse/torrus_srvderive.html [new file with mode: 0644]
httemplate/edit/process/torrus_srvderive.html [new file with mode: 0644]
httemplate/edit/torrus_srvderive.html [new file with mode: 0644]
httemplate/elements/checkboxes-table-name.html
httemplate/elements/checkboxes.html
httemplate/elements/menu.html
httemplate/elements/select-torrus_serviceid.html

index 985b1be..b55d0aa 100644 (file)
@@ -8,7 +8,7 @@ use File::Slurp qw(slurp);
 use Date::Format;
 use XML::Simple;
 use FS::svc_port;
-use FS::Record qw(qsearch);
+use FS::Record qw(qsearch dbh);
 use Torrus::ConfigTree;
 
 #$DEBUG = 0;
@@ -226,4 +226,23 @@ sub _torrus_reload {
 
 }
 
+sub torrus_serviceids {
+  my $self = shift;
+
+  #is this going to get too slow or will the index make it okay?
+  my $sth = dbh->prepare("SELECT DISTINCT(serviceid) FROM srvexport")
+    or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  my %serviceid = ();
+  while ( my $row = $sth->fetchrow_arrayref ) {
+    my $serviceid = $row->[0];
+    $serviceid =~ s/_(IN|OUT)$//;
+    $serviceid{$serviceid}=1;
+  }
+  my @serviceids = sort keys %serviceid;
+
+  @serviceids;
+
+}
+
 1;
index acac4a7..e8b3309 100644 (file)
@@ -3268,6 +3268,29 @@ sub tables_hashref {
 
     %{ tables_hashref_torrus() },
 
+    # tables of ours for doing torrus virtual port combining
+    'torrus_srvderive' => {
+      'columns' => [
+        'derivenum',  'serial', '', '', '', '',
+        'serviceid', 'varchar', '', 64, '', '', #srvexport / reportfields
+        #'func',      'varchar', '', $char_d, '', '',
+      ],
+      'primary_key' => 'derivenum',
+      'unique' => [ ['serviceid'] ],
+      'index'  => [],
+    },
+
+    'torrus_srvderive_component' => {
+      'columns' => [
+        'componentnum', 'serial', '', '', '', '',
+        'derivenum',       'int', '', '', '', '',
+        'serviceid',   'varchar', '', 64, '', '', #srvexport / reportfields
+      ],
+      'primary_key' => 'componentnum',
+      'unique'      => [ [ 'derivenum', 'serviceid' ], ],
+      'index'       => [ [ 'derivenum', ], ],
+    },
+
 
     # name type nullability length default local
 
diff --git a/FS/FS/torrus_srvderive.pm b/FS/FS/torrus_srvderive.pm
new file mode 100644 (file)
index 0000000..8736b0d
--- /dev/null
@@ -0,0 +1,138 @@
+package FS::torrus_srvderive;
+
+use strict;
+use base qw( FS::m2name_Common FS::Record );
+use FS::Record qw( qsearch qsearchs );
+use FS::torrus_srvderive_component;
+
+=head1 NAME
+
+FS::torrus_srvderive - Object methods for torrus_srvderive records
+
+=head1 SYNOPSIS
+
+  use FS::torrus_srvderive;
+
+  $record = new FS::torrus_srvderive \%hash;
+  $record = new FS::torrus_srvderive { 'column' => 'value' };
+
+  $error = $record->insert;
+
+  $error = $new_record->replace($old_record);
+
+  $error = $record->delete;
+
+  $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::torrus_srvderive object represents a Torrus virtual service ID.
+FS::torrus_srvderive inherits from FS::Record.  The following fields are
+currently supported:
+
+=over 4
+
+=item derivenum
+
+primary key
+
+=item serviceid
+
+serviceid
+
+=item func
+
+func
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new record.  To add the record 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<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'torrus_srvderive'; }
+
+=item insert
+
+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.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=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.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid record.  If there is
+an error, returns the error, otherwise returns false.  Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+  my $self = shift;
+
+  my $error = 
+    $self->ut_numbern('derivenum')
+    || $self->ut_text('serviceid')
+    #|| $self->ut_text('func')
+  ;
+  return $error if $error;
+
+  $self->SUPER::check;
+}
+
+sub torrus_srvderive_component {
+  my $self = shift;
+  qsearch('torrus_srvderive_component', { 'derivenum' => $self->derivenum } );
+}
+
+sub component_serviceids {
+  my $self = shift;
+  map $_->serviceid, $self->torrus_srvderive_component;
+}
+
+=back
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
diff --git a/FS/FS/torrus_srvderive_component.pm b/FS/FS/torrus_srvderive_component.pm
new file mode 100644 (file)
index 0000000..046b674
--- /dev/null
@@ -0,0 +1,127 @@
+package FS::torrus_srvderive_component;
+
+use strict;
+use base qw( FS::Record );
+use FS::Record qw( qsearch qsearchs );
+
+=head1 NAME
+
+FS::torrus_srvderive_component - Object methods for torrus_srvderive_component records
+
+=head1 SYNOPSIS
+
+  use FS::torrus_srvderive_component;
+
+  $record = new FS::torrus_srvderive_component \%hash;
+  $record = new FS::torrus_srvderive_component { 'column' => 'value' };
+
+  $error = $record->insert;
+
+  $error = $new_record->replace($old_record);
+
+  $error = $record->delete;
+
+  $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::torrus_srvderive_component object represents a component of a Torrus
+virtual service ID.  FS::torrus_srvderive_component inherits from FS::Record.
+The following fields are currently supported:
+
+=over 4
+
+=item componentnum
+
+primary key
+
+=item derivenum
+
+derivenum
+
+=item serviceid
+
+serviceid
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new record.  To add the record 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<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'torrus_srvderive_component'; }
+
+=item insert
+
+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.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=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.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid record.  If there is
+an error, returns the error, otherwise returns false.  Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+  my $self = shift;
+
+  my $error = 
+    $self->ut_numbern('componentnum')
+    || $self->ut_number('derivenum')
+    || $self->ut_text('serviceid')
+  ;
+  return $error if $error;
+
+  $self->SUPER::check;
+}
+
+=back
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
index 553c5ec..ae571a1 100644 (file)
@@ -565,3 +565,7 @@ FS/did_vendor.pm
 t/did_vendor.t
 FS/did_order.pm
 t/did_order.t
+FS/torrus_srvderive.pm
+t/torrus_srvderive.t
+FS/torrus_srvderive_component.pm
+t/torrus_srvderive_component.t
diff --git a/FS/t/torrus_srvderive.t b/FS/t/torrus_srvderive.t
new file mode 100644 (file)
index 0000000..8a2e4e5
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::torrus_srvderive;
+$loaded=1;
+print "ok 1\n";
diff --git a/FS/t/torrus_srvderive_component.t b/FS/t/torrus_srvderive_component.t
new file mode 100644 (file)
index 0000000..3d3062a
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::torrus_srvderive_component;
+$loaded=1;
+print "ok 1\n";
diff --git a/httemplate/browse/torrus_srvderive.html b/httemplate/browse/torrus_srvderive.html
new file mode 100644 (file)
index 0000000..92cbb69
--- /dev/null
@@ -0,0 +1,26 @@
+<% include( 'elements/browse.html',
+              'title'          => 'Virtual network ports',
+              'name_singular'  => 'port',
+              'menubar'        => [ 'Add a new virtual port' =>
+                                      $p.'edit/torrus_srvderive.html',
+                                  ],
+              'query'          => { 'table' => 'torrus_srvderive' },
+              'count_query'    => 'SELECT COUNT(*) FROM torrus_srvderive',
+              'header'         => [ 'Virtual Port', 'Components', ],
+              'fields'         => [ 'serviceid', $components_sub, ],
+              'links'          => [ $link, '', ],
+          )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $link = [ $p.'edit/torrus_srvderive.html?', 'derivenum' ];
+
+my $components_sub = sub {
+  my $torrus_srvderive = shift;
+  join('<BR>', $torrus_srvderive->component_serviceids);
+};
+
+</%init>
diff --git a/httemplate/edit/process/torrus_srvderive.html b/httemplate/edit/process/torrus_srvderive.html
new file mode 100644 (file)
index 0000000..c3260bc
--- /dev/null
@@ -0,0 +1,21 @@
+<% include( 'elements/process.html',
+               'table'       => 'torrus_srvderive',
+               'viewall_dir' => 'browse',
+               'process_m2name' => {
+                     'link_table'   => 'torrus_srvderive_component',
+                     'num_col'      => 'derivenum',
+                     'name_col'     => 'serviceid',
+                     'names_list'   => \@serviceids,
+                     'param_style'  => 'link_table.value checkboxes',
+               },
+           )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $nms = new FS::NetworkMonitoringSystem;
+my @serviceids = $nms->torrus_serviceids;
+
+</%init>
diff --git a/httemplate/edit/torrus_srvderive.html b/httemplate/edit/torrus_srvderive.html
new file mode 100644 (file)
index 0000000..51e2337
--- /dev/null
@@ -0,0 +1,37 @@
+<% include( 'elements/edit.html',
+              'name_singular' => 'virtual port',
+              'table'         => 'torrus_srvderive',
+              'labels'        => { 'serviceid' => 'Virtual Port serviceid',
+                                 },
+              'fields'        => [ 'serviceid',
+                                 ],
+              'viewall_dir'   => 'browse',
+              'html_bottom'   => $html_bottom_sub,
+          )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $html_bottom_sub = sub {
+  my $torrus_srvderive = shift;
+
+  my $nms = new FS::NetworkMonitoringSystem;
+  my @serviceids = $nms->torrus_serviceids;
+
+  ntable('#cccccc',2).'<TR><TD>'.
+    include( '/elements/checkboxes-table-name.html',
+               'source_obj'    => $torrus_srvderive,
+               'link_table'    => 'torrus_srvderive_component',
+               'num_col'       => 'derivenum',
+               'name_col'      => 'serviceid',
+               'names_list'    => \@serviceids,
+               'disable_links' => 1,
+           ).
+  '</TD></TR></TABLE>';
+
+};
+
+
+</%init>
index 31652f3..8ee2f77 100644 (file)
@@ -45,6 +45,7 @@ Example:
              'names_list'             => $opt{'names_list'},
              'checked_callback'       => $checked_callback,
              'element_name_prefix'    => $opt{'link_table'}. '.',
+             'disable_links'          => $opt{'disable_links'},
           )
 %>
 
index b120ada..69ef18f 100644 (file)
@@ -29,6 +29,8 @@ Example:
 
 <TABLE CELLSPACING=0 CELLPADDING=0>
 
+% unless ( $opt{'disable_links'} ) {
+
 <TR>
   <TD COLSPAN=2 ALIGN="center"><FONT SIZE="-1">(
     <A HREF="javascript:setAll<%$prefix%>(true)">select all</A> |
@@ -37,6 +39,8 @@ Example:
   )</FONT></TD>
 </TR>
 
+% }
+
 % my $num=0;
 % foreach my $item ( @{ $opt{'names_list'} } ) {
 %
index 651b04d..d074159 100644 (file)
@@ -501,6 +501,10 @@ tie my %config_phone, 'Tie::IxHash',
   'View/Edit bulk DID vendors' => [ $fsurl.'browse/did_vendor.html', 'Bulk DID vendors' ],
 ;
 
+tie my %config_nms, 'Tie::IxHash',
+  'View/Edit virtual ports' => [ $fsurl.'browse/torrus_srvderive.html', '' ],
+;
+
 tie my %config_misc, 'Tie::IxHash';
 $config_misc{'Message templates'} = [ $fsurl.'browse/msg_template.html', 'Templates for customer notices' ]
   if $curuser->access_right('Edit templates')
@@ -545,11 +549,14 @@ $config_menu{'Ticketing'} = [ \%config_ticketing, '' ]
   if $conf->config('ticket_system')
   && FS::TicketSystem->access_right(\%session, 'ShowConfigTab');
 $config_menu{'Dialup'}  = [ \%config_dialup, ''    ]
-  if ( $curuser->access_right('Dialup configuration') );
+  if $curuser->access_right('Dialup configuration');
 $config_menu{'Broadband'} = [ \%config_broadband, ''    ]
-  if ( $curuser->access_right('Broadband configuration') );
+  if $curuser->access_right('Broadband configuration');
 $config_menu{'Phone'}  = [ \%config_phone, ''    ]
-  if ( $curuser->access_right('Configuration') );
+  if $curuser->access_right('Configuration');
+$config_menu{'Network Monitoring'} = [ \%config_nms, '' ]
+  if $curuser->access_right('Configuration')
+  && $conf->config('network_monitoring_system') eq 'Torrus_Internal';
 $config_menu{'Miscellaneous'} = [ \%config_misc, ''    ]
   if $curuser->access_right('Configuration' )
   || $curuser->access_right('Edit advertising sources')
index 34e8e93..e13a6e8 100644 (file)
@@ -4,7 +4,7 @@
   <OPTION VALUE="">Select serviceid</OPTION>
 % }
 
-% foreach my $serviceid ( keys %serviceid ) {
+% foreach my $serviceid ( @serviceids ) {
     <OPTION VALUE="<%$serviceid%>"
             <% $serviceid eq $value ? 'SELECTED' : '' %>
     ><% $serviceid %></OPTION>
@@ -18,15 +18,7 @@ my %opt = @_;
 
 my $value = $opt{'curr_value'} || $opt{'value'};
 
-#is this going to get too slow or will the index make it okay?
-my $sth = dbh->prepare("SELECT DISTINCT(serviceid) FROM srvexport")
-  or die dbh->errstr;
-$sth->execute or die $sth->errstr;
-my %serviceid = ();
-while ( my $row = $sth->fetchrow_arrayref ) {
-  my $serviceid = $row->[0];
-  $serviceid =~ s/_(IN|OUT)$//;
-  $serviceid{$serviceid}=1;
-}
+my $nms = new FS::NetworkMonitoringSystem;
+my @serviceids = $nms->torrus_serviceids;
 
 </%init>