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