package FS::part_export::netsapiens;
-use vars qw(@ISA %info);
+use vars qw(@ISA $me %info);
use URI;
use MIME::Base64;
use Tie::IxHash;
use FS::part_export;
@ISA = qw(FS::part_export);
+$me = '[FS::part_export::netsapiens]';
tie my %options, 'Tie::IxHash',
'login' => { label=>'NetSapiens tac2 User API username' },
'device_password' => { label=>'NetSapiens tac2 Device API password' },
'device_url' => { label=>'NetSapiens tac2 Device URL' },
'domain' => { label=>'NetSapiens Domain' },
+ 'debug' => { label=>'Enable debugging', type=>'checkbox' },
;
%info = (
- 'svc' => 'svc_phone',
+ 'svc' => [ 'svc_phone', ], # 'part_device',
'desc' => 'Provision phone numbers to NetSapiens',
'options' => \%options,
'notes' => <<'END'
sub ns_device_command {
my $self = shift;
- $self->_ns_command('device', @_);
+ $self->_ns_command('device_', @_);
}
sub _ns_command {
$args[0] .= $ns->buildQuery( { @_ } );
}
+ warn "$me $method ". $self->option($prefix.'url'). join(', ', @args). "\n"
+ if $self->option('debug');
+
my $auth = encode_base64( $self->option($prefix.'login'). ':'.
$self->option($prefix.'password') );
push @args, { 'Authorization' => "Basic $auth" };
sub ns_registrar {
my($self, $svc_phone) = (shift, shift);
- my $domain = $self->option('domain');
- my $countrycode = $svc_phone->countrycode;
- my $phonenum = $svc_phone->phonenum;
-
$self->ns_subscriber($svc_phone).
'/registrar_config/'. $self->ns_devicename($svc_phone);
}
my( $self, $svc_phone ) = (shift, shift);
my $domain = $self->option('domain');
- my $countrycode = $svc_phone->countrycode;
+ #my $countrycode = $svc_phone->countrycode;
my $phonenum = $svc_phone->phonenum;
- "sip:$countrycode$phonenum@$domain";
+ #"sip:$countrycode$phonenum\@$domain";
+ "sip:$phonenum\@$domain";
}
sub ns_dialplan {
my($self, $svc_phone) = (shift, shift);
- my $countrycode = $svc_phone->countrycode;
+ #my $countrycode = $svc_phone->countrycode;
my $phonenum = $svc_phone->phonenum;
- "/dialplans/DID+Table/dialplan_config/sip:$countrycode$phonenum@*"
+ #"/dialplans/DID+Table/dialplan_config/sip:$countrycode$phonenum\@*"
+ "/dialplans/DID+Table/dialplan_config/sip:$phonenum\@*"
}
sub ns_device {
#my $countrycode = $svc_phone->countrycode;
#my $phonenum = $svc_phone->phonenum;
- "/phones_config/". $phone_device->mac_addr;
+ "/phones_config/". lc($phone_device->mac_addr);
}
sub ns_create_or_update {
my($self, $svc_phone, $dial_policy) = (shift, shift, shift);
my $domain = $self->option('domain');
- my $countrycode = $svc_phone->countrycode;
+ #my $countrycode = $svc_phone->countrycode;
my $phonenum = $svc_phone->phonenum;
my( $firstname, $lastname );
#Piece 2 - sip device creation
my $ns2 = $self->ns_command( 'PUT', $self->ns_registrar($svc_phone),
+ 'termination_match' => $self->ns_devicename($svc_phone)
);
if ( $ns2->responseCode !~ /^2/ ) {
#Piece 3 - DID mapping to user
my $ns3 = $self->ns_command( 'PUT', $self->ns_dialplan($svc_phone),
- 'to_user' => $countrycode.$phonenum,
+ 'to_user' => $phonenum,
'to_host' => $domain,
);
'PUT', $self->ns_device($svc_phone, $phone_device),
'line1_enable' => 'yes',
'device1' => $self->ns_devicename($svc_phone),
- 'line1_ext' => $countrycode.$phonenum,
+ 'line1_ext' => $phonenum,
,
#'line2_enable' => 'yes',
#'device2' =>