diff options
| -rw-r--r-- | FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm | 21 | ||||
| -rw-r--r-- | FS/FS/Schema.pm | 23 | ||||
| -rw-r--r-- | FS/FS/torrus_srvderive.pm | 138 | ||||
| -rw-r--r-- | FS/FS/torrus_srvderive_component.pm | 127 | ||||
| -rw-r--r-- | FS/MANIFEST | 4 | ||||
| -rw-r--r-- | FS/t/torrus_srvderive.t | 5 | ||||
| -rw-r--r-- | FS/t/torrus_srvderive_component.t | 5 | ||||
| -rw-r--r-- | httemplate/browse/torrus_srvderive.html | 26 | ||||
| -rw-r--r-- | httemplate/edit/process/torrus_srvderive.html | 21 | ||||
| -rw-r--r-- | httemplate/edit/torrus_srvderive.html | 37 | ||||
| -rw-r--r-- | httemplate/elements/checkboxes-table-name.html | 1 | ||||
| -rw-r--r-- | httemplate/elements/checkboxes.html | 4 | ||||
| -rw-r--r-- | httemplate/elements/menu.html | 13 | ||||
| -rw-r--r-- | httemplate/elements/select-torrus_serviceid.html | 14 | 
14 files changed, 424 insertions, 15 deletions
| diff --git a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm index 985b1be05..b55d0aaf7 100644 --- a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm +++ b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm @@ -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; diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index acac4a7af..e8b3309e2 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -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 index 000000000..8736b0d2e --- /dev/null +++ b/FS/FS/torrus_srvderive.pm @@ -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 index 000000000..046b6748b --- /dev/null +++ b/FS/FS/torrus_srvderive_component.pm @@ -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; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 553c5ec81..ae571a10f 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -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 index 000000000..8a2e4e5c6 --- /dev/null +++ b/FS/t/torrus_srvderive.t @@ -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 index 000000000..3d3062a09 --- /dev/null +++ b/FS/t/torrus_srvderive_component.t @@ -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 index 000000000..92cbb6928 --- /dev/null +++ b/httemplate/browse/torrus_srvderive.html @@ -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 index 000000000..c3260bc8a --- /dev/null +++ b/httemplate/edit/process/torrus_srvderive.html @@ -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 index 000000000..51e23377c --- /dev/null +++ b/httemplate/edit/torrus_srvderive.html @@ -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> diff --git a/httemplate/elements/checkboxes-table-name.html b/httemplate/elements/checkboxes-table-name.html index 31652f330..8ee2f7736 100644 --- a/httemplate/elements/checkboxes-table-name.html +++ b/httemplate/elements/checkboxes-table-name.html @@ -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'},            )  %> diff --git a/httemplate/elements/checkboxes.html b/httemplate/elements/checkboxes.html index b120adab7..69ef18fb9 100644 --- a/httemplate/elements/checkboxes.html +++ b/httemplate/elements/checkboxes.html @@ -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'} } ) {  % diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 651b04d28..d0741596b 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -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') diff --git a/httemplate/elements/select-torrus_serviceid.html b/httemplate/elements/select-torrus_serviceid.html index 34e8e930f..e13a6e80d 100644 --- a/httemplate/elements/select-torrus_serviceid.html +++ b/httemplate/elements/select-torrus_serviceid.html @@ -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> | 
