summaryrefslogtreecommitdiff
path: root/FS
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 /FS
parentfcb005c5f947ce881794a3958e0ef7617fbcbf7a (diff)
add svc_broadband shellcommands export, RT11250
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/part_export/broadband_shellcommands.pm109
-rwxr-xr-xFS/FS/svc_broadband.pm11
3 files changed, 121 insertions, 0 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;