summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlevinse <levinse>2011-01-22 02:45:32 +0000
committerlevinse <levinse>2011-01-22 02:45:32 +0000
commit8f12b9fe1d7370c7307f183b0dff1e061c047ac5 (patch)
treeeab745a91788c9d19ea30ce7a90dea526dfa49eb
parentfcb005c5f947ce881794a3958e0ef7617fbcbf7a (diff)
add svc_broadband shellcommands export, RT11250
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/part_export/broadband_shellcommands.pm109
-rwxr-xr-xFS/FS/svc_broadband.pm11
-rw-r--r--httemplate/edit/svc_broadband.cgi17
-rw-r--r--httemplate/view/svc_broadband.cgi6
5 files changed, 128 insertions, 16 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index fab562b2b..1e773a7e7 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2163,6 +2163,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
index 000000000..c7f0fbb33
--- /dev/null
+++ b/FS/FS/part_export/broadband_shellcommands.pm
@@ -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;
+ '';
+}
+
diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm
index 5ffe0e452..2b794aa4b 100755
--- a/FS/FS/svc_broadband.pm
+++ b/FS/FS/svc_broadband.pm
@@ -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;
diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi
index b11fec7a7..ae7f50fca 100644
--- a/httemplate/edit/svc_broadband.cgi
+++ b/httemplate/edit/svc_broadband.cgi
@@ -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 = '';
diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi
index f552e9bc7..12e5f0f5d 100644
--- a/httemplate/view/svc_broadband.cgi
+++ b/httemplate/view/svc_broadband.cgi
@@ -83,6 +83,10 @@
<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>