From 80fa5a2f42e60bede178ff1118e7c7532fced9a5 Mon Sep 17 00:00:00 2001 From: levinse Date: Sun, 16 Jan 2011 03:33:59 +0000 Subject: [PATCH] OpenSIPS provisioning, RT10993 --- FS/FS/Schema.pm | 1 + FS/FS/part_export/phone_sqlopensips.pm | 29 ++++++++++++++++++++++++++--- FS/FS/svc_phone.pm | 6 ++++++ httemplate/edit/svc_phone.cgi | 1 + httemplate/view/svc_phone.cgi | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 93c2c952a..33167ec30 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2976,6 +2976,7 @@ sub tables_hashref { 'domsvc', 'int', 'NULL', '', '', '', 'locationnum', 'int', 'NULL', '', '', '', 'route', 'varchar', 'NULL', $char_d, '', '', + 'gwlist', 'varchar', 'NULL', $char_d, '', '', 'forwarddst', 'varchar', 'NULL', 15, '', '', 'email', 'varchar', 'NULL', 255, '', '', 'lnp_status', 'varchar', 'NULL', $char_d, '', '', diff --git a/FS/FS/part_export/phone_sqlopensips.pm b/FS/FS/part_export/phone_sqlopensips.pm index 8a3d3a17b..cb644a0a1 100644 --- a/FS/FS/part_export/phone_sqlopensips.pm +++ b/FS/FS/part_export/phone_sqlopensips.pm @@ -7,6 +7,7 @@ use FS::Record qw( dbh qsearch qsearchs ); use FS::part_export; use FS::svc_phone; use FS::export_svc; +use LWP::UserAgent; @ISA = qw(FS::part_export); @@ -14,6 +15,7 @@ tie %options, 'Tie::IxHash', 'datasrc' => { label=>'DBI data source ' }, 'username' => { label=>'Database username' }, 'password' => { label=>'Database password' }, + 'xmlrpc_url' => { label=>'XMLRPC URL' }, ; %info = ( @@ -31,10 +33,10 @@ sub _export_insert { my $sth = $dbh->prepare("insert into dr_rules ". "( groupid, prefix, timerec, routeid, gwlist, description ) ". " values ( ?, ?, ?, ?, ?, ? )") or die $dbh->errstr; - $sth->execute('0',$svc_x->phonenum,'',$svc_x->route,'', + $sth->execute('0',$svc_x->phonenum,'',$svc_x->route,$svc_x->gwlist, $svc_x->phone_name) or die $sth->errstr; $dbh->disconnect; - ''; + $self->dr_reload; } sub opensips_connect { @@ -58,6 +60,11 @@ sub _export_replace { push @paramvalues, $new->phone_name; } + if($old->gwlist ne $new->gwlist) { + push @update, 'gwlist = ?'; + push @paramvalues, $new->gwlist; + } + if(scalar(@update)) { my $update_str = join(' and ',@update); my $dbh = $self->opensips_connect; @@ -66,6 +73,7 @@ sub _export_replace { push @paramvalues, $old->phonenum; $sth->execute(@paramvalues) or die $sth->errstr; $dbh->disconnect; + return $self->dr_reload; } ''; } @@ -87,6 +95,21 @@ sub _export_delete { or die $dbh->errstr; $sth->execute($svc_x->phonenum) or die $sth->errstr; $dbh->disconnect; - ''; + $self->dr_reload; +} + +sub dr_reload { + my $self = shift; + my $reqxml = " + + dr_reload +"; + my $ua = LWP::UserAgent->new; + my $resp = $ua->post( $self->option('xmlrpc_url'), + Content_Type => 'text/xml', + Content => $reqxml ); + return "invalid HTTP response from OpenSIPS: " . $resp->status_line + unless $resp->is_success; + ''; } diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index cffe1e3f6..deb12c29a 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -83,6 +83,10 @@ Optional svcnum from svc_pbx Route id/number +=item gwlist + +OpenSIPS dr_rules gwlist - OpenSIPS dynamic routing + =item forwarddst Forwarding destination @@ -178,6 +182,7 @@ sub table_info { 'route' => { label => 'Route', %dis2, }, + 'gwlist' => { label => 'OpenSIPS gwlist', %dis2 }, 'forwarddst' => { label => 'Forward Destination', %dis2, }, @@ -478,6 +483,7 @@ sub check { || $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' ) || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum') || $self->ut_textn('route') + || $self->ut_textn('gwlist') || $self->ut_numbern('forwarddst') || $self->ut_textn('email') || $self->ut_numbern('lrn') diff --git a/httemplate/edit/svc_phone.cgi b/httemplate/edit/svc_phone.cgi index 1623ed38a..f542ec216 100644 --- a/httemplate/edit/svc_phone.cgi +++ b/httemplate/edit/svc_phone.cgi @@ -38,6 +38,7 @@ push @fields, { field => 'pbxsvc', maxlength => $conf->config('svc_phone-phone_name-max_length'), }, 'route', + 'gwlist', 'forwarddst', 'email', diff --git a/httemplate/view/svc_phone.cgi b/httemplate/view/svc_phone.cgi index 7b0ea7071..433ea1761 100644 --- a/httemplate/view/svc_phone.cgi +++ b/httemplate/view/svc_phone.cgi @@ -19,7 +19,7 @@ my %labels = map { $_ => ( ref($fields->{$_}) my @fields = qw( countrycode phonenum ); push @fields, 'domain' if $conf->exists('svc_phone-domain'); -push @fields, qw( pbx_title sip_password pin phone_name route forwarddst email ); +push @fields, qw( pbx_title sip_password pin phone_name route gwlist forwarddst email ); if ( $conf->exists('svc_phone-lnp') ) { push @fields, 'lnp_status', -- 2.11.0