add svc_broadband shellcommands export, RT11250
authorlevinse <levinse>
Sat, 22 Jan 2011 02:45:27 +0000 (02:45 +0000)
committerlevinse <levinse>
Sat, 22 Jan 2011 02:45:27 +0000 (02:45 +0000)
FS/FS/Schema.pm
FS/FS/part_export/broadband_shellcommands.pm [new file with mode: 0644]
FS/FS/svc_broadband.pm
httemplate/edit/svc_broadband.cgi
httemplate/view/svc_broadband.cgi

index 30fb006..fe5f96a 100644 (file)
@@ -2353,6 +2353,7 @@ sub tables_hashref {
         'altitude', 'decimal', 'NULL', '', '', '', 
         'vlan_profile', 'varchar', 'NULL', $char_d, '', '', 
         'performance_profile', 'varchar', 'NULL', $char_d, '', '',
+        'plan_id', 'varchar', 'NULL', $char_d, '', '',
       ],
       'primary_key' => 'svcnum',
       'unique'      => [ [ 'mac_addr' ] ],
diff --git a/FS/FS/part_export/broadband_shellcommands.pm b/FS/FS/part_export/broadband_shellcommands.pm
new file mode 100644 (file)
index 0000000..c7f0fbb
--- /dev/null
@@ -0,0 +1,109 @@
+package FS::part_export::broadband_shellcommands;
+
+use strict;
+use vars qw(@ISA %info);
+use Tie::IxHash;
+use FS::part_export;
+
+@ISA = qw(FS::part_export);
+
+tie my %options, 'Tie::IxHash',
+  'user' => { label=>'Remote username', default=>'freeside' },
+  'insert' => { label=>'Insert command',
+                 default=>'php provision.php --mac=$mac_addr --plan=$plan_id --account=active',
+               },
+  'delete'  => { label=>'Delete command',
+                  default=>'',
+                },
+  'suspend'  => { label=>'Suspension command',
+                  default=>'php provision.php --mac=$mac_addr --plan=$plan_id --account=suspend',
+                },
+  'unsuspend'=> { label=>'Unsuspension command',
+                  default=>'',
+                },
+  'uppercase_mac' => { label => 'Force MACs to uppercase', 
+                       type => 'checkbox', }
+;
+
+%info = (
+  'svc'     => 'svc_broadband',
+  'desc'    => 'Run remote commands via SSH, for svc_broadband services',
+  'options' => \%options,
+  'notes'   => <<'END'
+END
+);
+
+
+sub rebless { shift; }
+
+sub _export_insert {
+  my($self) = shift;
+  $self->_export_command('insert', @_);
+}
+
+sub _export_delete {
+  my($self) = shift;
+  $self->_export_command('delete', @_);
+}
+
+sub _export_suspend {
+  my($self) = shift;
+  $self->_export_command('suspend', @_);
+}
+
+sub _export_unsuspend {
+  my($self) = shift;
+  $self->_export_command('unsuspend', @_);
+}
+
+sub _export_command {
+  my ( $self, $action, $svc_broadband) = (shift, shift, shift);
+  my $command = $self->option($action);
+  return '' if $command =~ /^\s*$/;
+
+  #set variable for the command
+  no strict 'vars';
+  {
+    no strict 'refs';
+    ${$_} = $svc_broadband->getfield($_) foreach $svc_broadband->fields;
+  }
+
+  if ( $self->option('uppercase_mac') ) {
+       $mac_addr = uc $mac_addr;
+  }
+
+  #done setting variables for the command
+
+  $self->shellcommands_queue( $svc_broadband->svcnum,
+    user         => $self->option('user')||'root',
+    host         => $self->machine,
+    command      => eval(qq("$command")),
+  );
+}
+
+sub _export_replace {
+    '';
+}
+
+#a good idea to queue anything that could fail or take any time
+sub shellcommands_queue {
+  my( $self, $svcnum ) = (shift, shift);
+  my $queue = new FS::queue {
+    'svcnum' => $svcnum,
+    'job'    => "FS::part_export::broadband_shellcommands::ssh_cmd",
+  };
+  $queue->insert( @_ );
+}
+
+sub ssh_cmd { #subroutine, not method
+  use Net::OpenSSH;
+  my $opt = { @_ };
+  my $ssh = Net::OpenSSH->new($opt->{'user'}.'@'.$opt->{'host'});
+  die "Couldn't establish SSH connection: ". $ssh->error if $ssh->error;
+  my ($output, $errput) = $ssh->capture2($opt->{'command'});
+  die "Error running SSH command: ". $ssh->error if $ssh->error;
+  die $errput if $errput;
+  die $output if $output;
+  '';
+}
+
index 5ffe0e4..2b794aa 100755 (executable)
@@ -70,6 +70,8 @@ customer's router will have the same address for both its internal and external
 interfaces thus saving address space.  This has been found to work on most NAT
 routers available.
 
+=item plan_id
+
 =back
 
 =head1 METHODS
@@ -105,6 +107,14 @@ sub table_info {
                          'select_label' => 'cidr',
                          'disable_inventory' => 1,
                        },
+     'plan_id' => 'Service Plan Id',
+     'performance_profile' => 'Peformance Profile',
+     'authkey'      => 'Authentication key',
+     'mac_addr'     => 'MAC address',
+     'latitude'     => 'Latitude',
+     'longitude'    => 'Longitude',
+     'altitude'     => 'Altitude',
+     'vlan_profile' => 'VLAN profile',
     },
   };
 }
@@ -337,6 +347,7 @@ sub check {
     || $self->ut_coordn('longitude', -180, 180)
     || $self->ut_sfloatn('altitude')
     || $self->ut_textn('vlan_profile')
+    || $self->ut_textn('plan_id')
   ;
   return $error if $error;
 
index b11fec7..ae7f50f 100644 (file)
@@ -2,21 +2,6 @@
      'post_url'             => popurl(1). 'process/svc_broadband.cgi',
      'name'                 => 'broadband service',
      'table'                => 'svc_broadband',
-     'labels'               => { 'svcnum'       => 'Service',
-                                 'description'  => 'Description',
-                                 'ip_addr'      => 'IP address',
-                                 'speed_down'   => 'Download speed',
-                                 'speed_up'     => 'Upload speed',
-                                 'blocknum'     => 'Router/Block',
-                                 'block_label'  => 'Router/Block',
-                                 'mac_addr'     => 'MAC address',
-                                 'latitude'     => 'Latitude',
-                                 'longitude'    => 'Longitude',
-                                 'altitude'     => 'Altitude',
-                                 'vlan_profile' => 'VLAN profile',
-                                 'performance_profile' => 'Performance profile',
-                                 'authkey'      => 'Authentication key',
-                               },
      'fields'               => \@fields, 
      'field_callback'       => $callback,
      'dummy'                => $cgi->query_string,
@@ -35,7 +20,7 @@ my $conf = new FS::Conf;
 my @fields = (
   qw( description ip_addr speed_down speed_up blocknum ),
   { field=>'block_label', type=>'fixed' },
-  qw( mac_addr latitude longitude altitude vlan_profile performance_profile authkey )
+  qw( mac_addr latitude longitude altitude vlan_profile performance_profile authkey plan_id )
 );
 
 my $fixedblock = '';
index f552e9b..12e5f0f 100644 (file)
           <TD ALIGN="right">Authentication Key</TD>
           <TD BGCOLOR="#ffffff"><%$auth_key%></TD>
         </TR>
+       <TR>
+          <TD ALIGN="right">Service Plan Id</TD>
+          <TD BGCOLOR="#ffffff"><%$plan_id%></TD>
+        </TR>
         <TR COLSPAN="2"><TD></TD></TR>
 %
 %foreach (sort { $a cmp $b } $svc_broadband->virtual_fields) {
@@ -203,6 +207,7 @@ my (
      $vlan_profile,
      $auth_key,
      $description,
+     $plan_id,
    ) = (
      $svc_broadband->getfield('speed_down'),
      $svc_broadband->getfield('speed_up'),
@@ -214,6 +219,7 @@ my (
      $svc_broadband->vlan_profile,
      $svc_broadband->auth_key,
      $svc_broadband->description,
+     $svc_broadband->plan_id,
    );
 
 </%init>