1 package FS::part_export::phone_sqlopensips;
3 use vars qw(@ISA @EXPORT_OK %info %options);
6 use FS::Record qw( dbh qsearch qsearchs );
13 @ISA = qw(FS::part_export);
15 tie %options, 'Tie::IxHash',
16 'datasrc' => { label=>'DBI data source ' },
17 'username' => { label=>'Database username' },
18 'password' => { label=>'Database password' },
19 'xmlrpc_url' => { label=>'XMLRPC URL' },
20 # XXX: in future, add non-agent-virtualized config, i.e. per-export setting of gwlist, routeid, description, etc.
21 # and/or setting description from the phone_name column
26 'desc' => 'Export DIDs to OpenSIPs dr_rules table',
27 'options' => \%options,
29 'notes' => 'Export DIDs to OpenSIPs dr_rules table',
32 sub rebless { shift; }
35 my($self, $svc_x) = (shift, shift);
37 my $conf = new FS::Conf;
38 my $agentnum = $svc_x->cust_svc->cust_pkg->cust_main->agentnum || 0;
39 my $gwlist = $conf->config('opensips_gwlist',$agentnum) || '';
40 my $description = $conf->config('opensips_description',$agentnum) || '';
41 my $route = $conf->config('opensips_route',$agentnum) || '';
43 my $dbh = $self->opensips_connect;
44 my $sth = $dbh->prepare("insert into dr_rules ".
45 "( groupid, prefix, timerec, routeid, gwlist, description ) ".
46 " values ( ?, ?, ?, ?, ?, ? )") or die $dbh->errstr;
47 $sth->execute('0',$svc_x->phonenum,'',$route,$gwlist,$description)
50 $self->dr_reload; # XXX: if this fails, do we delete what we just inserted?
53 sub opensips_connect {
55 FS::DBI->connect($self->option('datasrc'),$self->option('username'),
56 $self->option('password')) or die $FS::DBI::errstr;
64 my( $self, $svc_phone ) = (shift, shift);
68 sub _export_unsuspend {
69 my( $self, $svc_phone ) = (shift, shift);
74 my( $self, $svc_x ) = (shift, shift);
75 my $dbh = $self->opensips_connect;
76 my $sth = $dbh->prepare("delete from dr_rules where prefix = ?")
78 $sth->execute($svc_x->phonenum) or die $sth->errstr;
80 $self->dr_reload; # XXX: if this fails, do we re-insert what we just deleted?
85 my $reqxml = "<?xml version=\"1.0\"?>
87 <methodName>dr_reload</methodName>
89 my $ua = LWP::UserAgent->new;
90 my $resp = $ua->post( $self->option('xmlrpc_url'),
91 Content_Type => 'text/xml',
93 return "invalid HTTP response from OpenSIPS: " . $resp->status_line
94 unless $resp->is_success;