OpenSIPS provisioning, RT10993
authorlevinse <levinse>
Sun, 16 Jan 2011 03:33:59 +0000 (03:33 +0000)
committerlevinse <levinse>
Sun, 16 Jan 2011 03:33:59 +0000 (03:33 +0000)
FS/FS/Schema.pm
FS/FS/part_export/phone_sqlopensips.pm
FS/FS/svc_phone.pm
httemplate/edit/svc_phone.cgi
httemplate/view/svc_phone.cgi

index 93c2c95..33167ec 100644 (file)
@@ -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, '', '',
index 8a3d3a1..cb644a0 100644 (file)
@@ -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 = "<?xml version=\"1.0\"?>
+<methodCall>
+  <methodName>dr_reload</methodName>
+</methodCall>";
+    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;
+    '';
 }
 
index cffe1e3..deb12c2 100644 (file)
@@ -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')
index 1623ed3..f542ec2 100644 (file)
@@ -38,6 +38,7 @@ push @fields, { field => 'pbxsvc',
                 maxlength => $conf->config('svc_phone-phone_name-max_length'),
               },
              'route',
+             'gwlist',
              'forwarddst',
              'email',
 
index 7b0ea70..433ea17 100644 (file)
@@ -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',