opensips provisioning, RT10993
authorlevinse <levinse>
Fri, 7 Jan 2011 23:13:58 +0000 (23:13 +0000)
committerlevinse <levinse>
Fri, 7 Jan 2011 23:13:58 +0000 (23:13 +0000)
FS/FS/Schema.pm
FS/FS/part_export/phone_sqlopensips.pm [new file with mode: 0644]
FS/FS/svc_phone.pm
httemplate/edit/svc_phone.cgi
httemplate/view/svc_phone.cgi

index 52f4d8f..26252a7 100644 (file)
@@ -2973,6 +2973,7 @@ sub tables_hashref {
         'pbxsvc',           'int', 'NULL',      '', '', '',
         'domsvc',           'int', 'NULL',      '', '', '', 
         'locationnum',      'int', 'NULL', '', '', '',
         'pbxsvc',           'int', 'NULL',      '', '', '',
         'domsvc',           'int', 'NULL',      '', '', '', 
         'locationnum',      'int', 'NULL', '', '', '',
+        'route',   'varchar', 'NULL', $char_d, '', '',
         'lnp_status',   'varchar', 'NULL', $char_d, '', '',
         'portable',    'char', 'NULL',       1,  '', '', 
         'lrn',     'char',     'NULL',      10, '', '', 
         'lnp_status',   'varchar', 'NULL', $char_d, '', '',
         'portable',    'char', 'NULL',       1,  '', '', 
         'lrn',     'char',     'NULL',      10, '', '', 
diff --git a/FS/FS/part_export/phone_sqlopensips.pm b/FS/FS/part_export/phone_sqlopensips.pm
new file mode 100644 (file)
index 0000000..8a3d3a1
--- /dev/null
@@ -0,0 +1,92 @@
+package FS::part_export::phone_sqlopensips;
+
+use vars qw(@ISA @EXPORT_OK %info %options);
+use Exporter;
+use Tie::IxHash;
+use FS::Record qw( dbh qsearch qsearchs );
+use FS::part_export;
+use FS::svc_phone;
+use FS::export_svc;
+
+@ISA = qw(FS::part_export);
+
+tie %options, 'Tie::IxHash',
+  'datasrc'  => { label=>'DBI data source ' },
+  'username' => { label=>'Database username' },
+  'password' => { label=>'Database password' },
+;
+
+%info = (
+  'svc'      => 'svc_phone',
+  'desc'     => 'Export DIDs to OpenSIPs dr_rules table',
+  'options'  => \%options,
+  'notes'    => 'Export DIDs to OpenSIPs dr_rules table',
+);
+
+sub rebless { shift; }
+
+sub _export_insert {
+  my($self, $svc_x) = (shift, shift);
+  my $dbh = $self->opensips_connect;
+  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,'',
+               $svc_x->phone_name) or die $sth->errstr;
+  $dbh->disconnect;
+  '';
+}
+
+sub opensips_connect {
+    my $self = shift;
+    DBI->connect($self->option('datasrc'),$self->option('username'),
+                       $self->option('password')) or die $DBI::errstr;
+}
+
+sub _export_replace {
+  my( $self, $new, $old ) = (shift, shift, shift);
+    my @update = ();
+    my @paramvalues = ();
+
+    if($old->route ne $new->route){
+       push @update, 'routeid = ?';
+       push @paramvalues, $new->route;
+    }
+
+    if($old->phone_name ne $new->phone_name) {
+       push @update, 'description = ?';
+       push @paramvalues, $new->phone_name;
+    }
+
+    if(scalar(@update)) {
+      my $update_str = join(' and ',@update);
+      my $dbh = $self->opensips_connect;
+      my $sth = $dbh->prepare("update dr_rules set $update_str " . 
+           " where prefix = ? ") or die $dbh->errstr;
+      push @paramvalues, $old->phonenum;
+      $sth->execute(@paramvalues) or die $sth->errstr;
+      $dbh->disconnect;
+    }
+  '';
+}
+
+sub _export_suspend {
+  my( $self, $svc_phone ) = (shift, shift);
+  '';
+}
+
+sub _export_unsuspend {
+  my( $self, $svc_phone ) = (shift, shift);
+  '';
+}
+
+sub _export_delete {
+  my( $self, $svc_x ) = (shift, shift);
+  my $dbh = $self->opensips_connect;
+  my $sth = $dbh->prepare("delete from dr_rules where prefix = ?")
+    or die $dbh->errstr;
+  $sth->execute($svc_x->phonenum) or die $sth->errstr;
+  $dbh->disconnect;
+  '';
+}
+
index 56f3f3c..0b001d7 100644 (file)
@@ -79,6 +79,10 @@ Voicemail PIN
 
 Optional svcnum from svc_pbx
 
 
 Optional svcnum from svc_pbx
 
+=item route
+
+Route id/number
+
 =item lnp_status
 
 LNP Status (can be null, native, portedin, portingin, portin-reject,
 =item lnp_status
 
 LNP Status (can be null, native, portedin, portingin, portin-reject,
@@ -163,6 +167,9 @@ sub table_info {
                            disable_inventory => 1,
                            disable_select    => 1,
                          },
                            disable_inventory => 1,
                            disable_select    => 1,
                          },
+       'route' => {    label => 'Route',
+                       %dis2, 
+                   },
        'lnp_status' => {       label => 'LNP Status',
                                type => 'select-lnp_status.html',
                                %dis2,
        'lnp_status' => {       label => 'LNP Status',
                                type => 'select-lnp_status.html',
                                %dis2,
@@ -456,6 +463,7 @@ sub check {
     || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx',    'svcnum' )
     || $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' )
     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
     || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx',    'svcnum' )
     || $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' )
     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
+    || $self->ut_textn('route')
     || $self->ut_numbern('lrn')
     || $self->ut_numbern('lnp_desired_due_date')
     || $self->ut_numbern('lnp_due_date')
     || $self->ut_numbern('lrn')
     || $self->ut_numbern('lnp_desired_due_date')
     || $self->ut_numbern('lnp_due_date')
index 36b827b..8dd58d7 100644 (file)
@@ -37,6 +37,7 @@ push @fields, { field => 'pbxsvc',
                 type  => 'text',
                 maxlength => $conf->config('svc_phone-phone_name-max_length'),
               },
                 type  => 'text',
                 maxlength => $conf->config('svc_phone-phone_name-max_length'),
               },
+             'route',
 
               { value   => 'E911 Information',
                 type    => 'tablebreak-tr-title',
 
               { value   => 'E911 Information',
                 type    => 'tablebreak-tr-title',
index 96211d8..c2379a0 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');
 
 my @fields = qw( countrycode phonenum );
 push @fields, 'domain' if $conf->exists('svc_phone-domain');
-push @fields, qw( pbx_title sip_password pin phone_name );
+push @fields, qw( pbx_title sip_password pin phone_name route );
 
 if ( $conf->exists('svc_phone-lnp') ) {
 push @fields, 'lnp_status',
 
 if ( $conf->exists('svc_phone-lnp') ) {
 push @fields, 'lnp_status',