1 package FS::part_export::thirdlane;
3 use base qw( FS::part_export );
5 use vars qw(%info $me);
9 $me = '['.__PACKAGE__.']';
11 tie my %options, 'Tie::IxHash',
12 #'server' => { label => 'Thirdlane server name or IP address', },
13 'username' => { label => 'Thirdlane username', },
14 'password' => { label => 'Thirdlane password', },
15 'prototype_tenant' => { label => 'Prototype tenant name', },
16 'debug' => { label => 'Checkbox label', type => 'checkbox' },
17 # 'select_option' => { label => 'Select option description',
18 # type => 'select', options=>[qw(chocolate vanilla)],
19 # default => 'vanilla',
21 # 'textarea_option' => { label => 'Textarea option description',
23 # default => 'Default text.',
28 'svc' => [qw( svc_pbx svc_phone )],
30 'Export tenants and DIDs to Thirdlane PBX manager',
31 'options' => \%options,
33 Exports tenants and DIDs to Thirdlane PBX manager using the XML-RPC API.
37 sub rebless { shift; }
40 my($self, $svc_x) = (shift, shift);
42 if ( $svc_x->isa('FS::svc_pbx') ) {
45 'tenant' => $svc_x->title,
46 'maxusers' => $svc_x->max_extensions,
47 #others? will they not clone?
50 @what_to_clone = qw(routes schedules menus queues voiceprompts moh);
52 my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_create',
54 $self->option('prototype_tenant'),
59 warn Dumper(\$result);
61 #$result == 0 means okay??
67 } elsif ( $svc_x->isa('FS::svc_phone') ) {
70 die "guru meditation #10: $svc_x is not FS::svc_pbx or FS::svc_phone";
76 my($self, $svc_x) = (shift, shift);
78 if ( $svc_x->isa('FS::svc_pbx') ) {
80 my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_delete',
85 warn Dumper(\$result);
87 #$result == 0 means okay??
93 } elsif ( $svc_x->isa('FS::svc_phone') ) {
96 die "guru meditation #11: $svc_x is not FS::svc_pbx or FS::svc_phone";
101 sub _export_replace {
102 my($self, $svc_x) = (shift, shift);
104 if ( $svc_x->isa('FS::svc_pbx') ) {
107 'tenant' => $svc_x->title,
108 'maxusers' => $svc_x->max_extensions,
109 #others? will they not clone?
112 my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_update',
117 warn Dumper(\$result);
119 #$result == 0 means okay??
125 } elsif ( $svc_x->isa('FS::svc_phone') ) {
128 die "guru meditation #11: $svc_x is not FS::svc_pbx or FS::svc_phone";
134 sub _thirdlane_command {
135 my($self, @param) = @_;
138 $self->option('username'). ':'. $self->option('password'). '@'.
139 $self->machine. '/xmlrpc.cgi';
141 warn "$me connecting to $url\n"
142 if $self->option('debug');
143 my $conn = Frontier::Client->new( 'url' => $url,
144 'debug' => $self->option('debug'),
147 warn "$me sending command: ". join(' ', @param). "\n"
148 if $self->option('debug');
153 sub _export_replace {
154 my( $self, $new, $old ) = (shift, shift, shift);
155 #return "can't change username with thirdlane"
156 # if $old->username ne $new->username;
157 #return '' unless $old->_password ne $new->_password;
158 $err_or_queue = $self->thirdlane_queue( $new->svcnum,
159 'replace', $new->username, $new->_password );
160 ref($err_or_queue) ? '' : $err_or_queue;
165 #my( $self, $svc_something ) = (shift, shift);
166 #$err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
167 # 'delete', $svc_something->username );
168 #ref($err_or_queue) ? '' : $err_or_queue;
171 #these three are optional
172 # fallback for svc_acct will change and restore password
173 sub _export_suspend {
174 my( $self, $svc_something ) = (shift, shift);
175 $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
176 'suspend', $svc_something->username );
177 ref($err_or_queue) ? '' : $err_or_queue;
180 sub _export_unsuspend {
181 my( $self, $svc_something ) = (shift, shift);
182 $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
183 'unsuspend', $svc_something->username );
184 ref($err_or_queue) ? '' : $err_or_queue;
188 my($self, $svc_something, $arrayref) = (shift, shift, shift);
189 #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_something->username.
190 # qq!">!. $svc_something->username. qq!</A>!;
196 ##a good idea to queue anything that could fail or take any time
197 #sub thirdlane_queue {
198 # my( $self, $svcnum, $method ) = (shift, shift, shift);
199 # my $queue = new FS::queue {
200 # 'svcnum' => $svcnum,
201 # 'job' => "FS::part_export::thirdlane::thirdlane_$method",
203 # $queue->insert( @_ ) or $queue;
206 #sub thirdlane_insert { #subroutine, not method
207 # my( $username, $password ) = @_;
208 # #do things with $username and $password
211 #sub thirdlane_replace { #subroutine, not method
214 #sub thirdlane_delete { #subroutine, not method
215 # my( $username ) = @_;
216 # #do things with $username
219 #sub thirdlane_suspend { #subroutine, not method
222 #sub thirdlane_unsuspend { #subroutine, not method