'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' ] ],
--- /dev/null
+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;
+ '';
+}
+
interfaces thus saving address space. This has been found to work on most NAT
routers available.
+=item plan_id
+
=back
=head1 METHODS
'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',
},
};
}
|| $self->ut_coordn('longitude', -180, 180)
|| $self->ut_sfloatn('altitude')
|| $self->ut_textn('vlan_profile')
+ || $self->ut_textn('plan_id')
;
return $error if $error;
'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,
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 = '';
<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) {
$vlan_profile,
$auth_key,
$description,
+ $plan_id,
) = (
$svc_broadband->getfield('speed_down'),
$svc_broadband->getfield('speed_up'),
$svc_broadband->vlan_profile,
$svc_broadband->auth_key,
$svc_broadband->description,
+ $svc_broadband->plan_id,
);
</%init>