X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fthirdlane.pm;h=60c099748d67a1bf35b7c2b21a08d53c425481a6;hb=20f03d52cc6c930f610c0b4466eeeeda54fdbb40;hp=196177ea3c1b2a434ac9d948b398bc664e501690;hpb=046395d0a66db2f057c80768e01ae0f5b06bc555;p=freeside.git diff --git a/FS/FS/part_export/thirdlane.pm b/FS/FS/part_export/thirdlane.pm index 196177ea3..60c099748 100644 --- a/FS/FS/part_export/thirdlane.pm +++ b/FS/FS/part_export/thirdlane.pm @@ -4,6 +4,7 @@ use base qw( FS::part_export ); use vars qw(%info $me); use Tie::IxHash; +use URI::Escape; use Frontier::Client; $me = '['.__PACKAGE__.']'; @@ -12,7 +13,12 @@ tie my %options, 'Tie::IxHash', #'server' => { label => 'Thirdlane server name or IP address', }, 'username' => { label => 'Thirdlane username', }, 'password' => { label => 'Thirdlane password', }, + 'ssl' => { label => 'Enable HTTPS (SSL) connection', + type => 'checkbox', + }, + 'port' => { label => 'Port number if not 80 or 443', }, 'prototype_tenant' => { label => 'Prototype tenant name', }, + 'omit_countrycode' => { label => 'Omit country code', type => 'checkbox' }, 'debug' => { label => 'Checkbox label', type => 'checkbox' }, # 'select_option' => { label => 'Select option description', # type => 'select', options=>[qw(chocolate vanilla)], @@ -25,12 +31,12 @@ tie my %options, 'Tie::IxHash', ; %info = ( - 'svc' => [qw( svc_pbx svc_phone )], + 'svc' => [qw( svc_pbx svc_phone svc_acct )], 'desc' => - 'Export tenants and DIDs to Thirdlane PBX manager', + 'Export tenants, DIDs and admins to Thirdlane PBX manager', 'options' => \%options, 'notes' => <<'END' -Exports tenants and DIDs to Thirdlane PBX manager using the XML-RPC API. +Exports tenants, DIDs and admins to Thirdlane PBX manager using the XML-RPC API. END ); @@ -63,13 +69,13 @@ sub _export_insert { #use Data::Dumper; #warn Dumper(\$result); - $result eq '0' ? '' : 'Thirdlane API failure'; + $result eq '0' ? '' : 'Thirdlane API failure (rpc_tenant_create)'; } elsif ( $svc_x->isa('FS::svc_phone') ) { my $result = $self->_thirdlane_command( 'asterisk::rpc_did_create', - $svc_x->countrycode. $svc_x->phonenum, + $self->_thirdlane_did($svc_x) ); #use Data::Dumper; @@ -80,7 +86,7 @@ sub _export_insert { $result = $self->_thirdlane_command( 'asterisk::rpc_did_assign', - $svc_x->countrycode. $svc_x->phonenum, + $self->_thirdlane_did($svc_x), $svc_x->pbx_title, ); @@ -88,8 +94,23 @@ sub _export_insert { #warn Dumper(\$result); $result eq '0' ? '' : 'Thirdlane API failure (rpc_did_assign)'; + } elsif ( $svc_x->isa('FS::svc_acct') ) { + + return 'Must select a PBX' unless $svc_x->pbxsvc; + + my $result = $self->_thirdlane_command( + 'asterisk::rpc_admin_create', + $svc_x->username, + $svc_x->_password, + $svc_x->pbx_title, + ); + + #use Data::Dumper; + #warn Dumper(\$result); + $result eq '0' ? '' : 'Thirdlane API failure (rpc_admin_create)'; + } else { - die "guru meditation #10: $svc_x is not FS::svc_pbx or FS::svc_phone"; + die "guru meditation #10: $svc_x is not FS::svc_pbx, FS::svc_phone or FS::svc_acct"; } } @@ -122,7 +143,7 @@ sub _export_replace { #use Data::Dumper; #warn Dumper(\$result); - $result eq '0' ? '' : 'Thirdlane API failure'; + $result eq '0' ? '' : 'Thirdlane API failure (rpc_tenant_update)'; } elsif ( $new->isa('FS::svc_phone') ) { @@ -136,7 +157,7 @@ sub _export_replace { if ( $old->pbxsvc ) { my $result = $self->_thirdlane_command( 'asterisk::rpc_did_unassign', - $new->countrycode. $new->phonenum, + $self->_thirdlane_did($old), ); $result eq '0' or return 'Thirdlane API failure (rpc_did_unassign)'; } @@ -144,7 +165,7 @@ sub _export_replace { if ( $new->pbxsvc ) { my $result = $self->_thirdlane_command( 'asterisk::rpc_did_assign', - $new->countrycode. $new->phonenum, + $self->_thirdlane_did($new), $new->pbx_title, ); $result eq '0' or return 'Thirdlane API failure (rpc_did_assign)'; @@ -155,8 +176,21 @@ sub _export_replace { ''; + } elsif ( $new->isa('FS::svc_acct') ) { + + return "can't change uesrname with thirdlane" + if $old->username ne $new->username; + + return "can't change password with thirdlane" + if $old->_password ne $new->_password; + + return "can't change PBX for user with thirdlane" + if $old->pbxsvc != $new->pbxsvc; + + ''; #we don't care then + } else { - die "guru meditation #11: $new is not FS::svc_pbx or FS::svc_phone"; + die "guru meditation #11: $new is not FS::svc_pbx, FS::svc_phone or FS::svc_acct"; } } @@ -176,26 +210,46 @@ sub _export_delete { #use Data::Dumper; #warn Dumper(\$result); - $result eq '0' ? '' : 'Thirdlane API failure'; + #$result eq '0' ? '' : 'Thirdlane API failure (rpc_tenant_delete)'; + warn "Thirdlane API failure (rpc_tenant_delete); deleting anyway\n" + if $result ne '0'; + ''; } elsif ( $svc_x->isa('FS::svc_phone') ) { if ( $svc_x->pbxsvc ) { my $result = $self->_thirdlane_command( 'asterisk::rpc_did_unassign', - $svc_x->countrycode. $svc_x->phonenum, + $self->_thirdlane_did($svc_x), ); $result eq '0' or return 'Thirdlane API failure (rpc_did_unassign)'; } my $result = $self->_thirdlane_command( 'asterisk::rpc_did_delete', - $svc_x->countrycode. $svc_x->phonenum, + $self->_thirdlane_did($svc_x), ); $result eq '0' ? '' : 'Thirdlane API failure (rpc_did_delete)'; + } elsif ( $svc_x->isa('FS::svc_acct') ) { + + return '' unless $svc_x->pbxsvc; #error out? nah + + my $result = $self->_thirdlane_command( + 'asterisk::rpc_admin_delete', + $svc_x->username, + $svc_x->pbx_title, + ); + + #use Data::Dumper; + #warn Dumper(\$result); + #$result eq '0' ? '' : 'Thirdlane API failure (rpc_admin_delete)'; + warn "Thirdlane API failure (rpc_admin_delete); deleting anyway\n" + if $result ne '0'; + ''; + } else { - die "guru meditation #11: $svc_x is not FS::svc_pbx or FS::svc_phone"; + die "guru meditation #12: $svc_x is not FS::svc_pbx, FS::svc_phone or FS::svc_acct"; } } @@ -203,14 +257,18 @@ sub _export_delete { sub _thirdlane_command { my($self, @param) = @_; - my $url = 'http://'. - $self->option('username'). ':'. $self->option('password'). '@'. - $self->machine. '/xmlrpc.cgi'; + my $url = $self->option('ssl') ? 'https://' : 'http://'; + $url .= uri_escape($self->option('username')). ':'. + uri_escape($self->option('password')). '@'. + $self->machine; + $url .= ':'. $self->option('port') if $self->option('port'); + $url .= '/xmlrpc.cgi'; warn "$me connecting to $url\n" if $self->option('debug'); my $conn = Frontier::Client->new( 'url' => $url, - 'debug' => $self->option('debug'), + #no, spews output to browser + #'debug' => $self->option('debug'), ); warn "$me sending command: ". join(' ', @param). "\n" @@ -219,6 +277,15 @@ sub _thirdlane_command { } +sub _thirdlane_did { + my($self, $svc_phone) = @_; + if ( $self->option('omit_countrycode') ) { + $svc_phone->phonenum; + } else { + $svc_phone->countrycode. $svc_phone->phonenum; + } +} + #my( $self, $svc_something ) = (shift, shift); #$err_or_queue = $self->thirdlane_queue( $svc_something->svcnum, # 'delete', $svc_something->username );