[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 31dccc90e9f6c993ed7a579b721d8986c246cf64

Ivan ivan at 420.am
Fri Oct 19 22:01:34 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  31dccc90e9f6c993ed7a579b721d8986c246cf64 (commit)
      from  80c01e2aff2fe380ab74ca04606e42e3a360b634 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 31dccc90e9f6c993ed7a579b721d8986c246cf64
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Oct 19 22:01:33 2012 -0700

    freeswitch export w/one file per user in addition to one file per domain, RT#18087

diff --git a/FS/FS/part_export/freeswitch.pm b/FS/FS/part_export/freeswitch.pm
index eb490fd..b7cb9e6 100644
--- a/FS/FS/part_export/freeswitch.pm
+++ b/FS/FS/part_export/freeswitch.pm
@@ -13,25 +13,45 @@ use FS::svc_phone;
 
 tie my %options, 'Tie::IxHash',
   'user'  => { label => 'SSH username', default=>'root', },
-  'directory' => { label   => 'Directory to store FreeSWITCH account XML files',
+  'directory' => { label   => 'Directory to store FreeSWITCH account XML files (one file per domain)',
                    default => '/usr/local/freeswitch/conf/directory/',
                  },
   #'domain'    => { label => 'Optional fixed SIP domain to use, overrides svc_phone domain', },
   'reload'    => { label   => 'Reload command',
                    default => '/usr/local/freeswitch/bin/fs_cli -x reloadxml',
                  },
-  'user_template' => { label   => 'User XML configuration template',
-                       type    => 'textarea',
-                       default => <<'END',
-<domain name="<% $domain %>">
-  <user id="<% $phonenum %>">
-    <params>
-      <param name="password" value="<% $sip_password %>"/>
-    </params>
-  </user>
-</domain>
+  'header_template' => { label   => 'Domain XML configuration header',
+                         type    => 'textarea',
+                         default => <<'END',
+<?xml version="1.0"?>
+<include>
+  <domain name="<% $domain %>">
+    <groups>
+      <group name="default">
+        <users>
 END
-                     },
+                       },
+  'user_template'   => { label   => 'User XML configuration template',
+                         type    => 'textarea',
+                         default => <<'END',
+          <user id="<% $phonenum %>">
+            <params>
+              <param name="password" value="<% $sip_password %>"/>
+            </params>
+          </user>
+
+END
+                       },
+  'footer_template' => { label   => 'Domain XML configuration footer',
+                         type    => 'textarea',
+                         default => <<'END',
+        </users>
+      </group>
+    </groups>
+  </domain>
+</include>
+END
+                       },
 ;
 
 %info = (
@@ -93,7 +113,8 @@ sub _export_rebuild_domain {
     #UNLINK   => 0,
   );
 
-  print $fh qq(<domain name="$domain">\n);
+  print $fh $self->freeswitch_template_fillin( $domain, 'header' )
+    or die "print to freeswitch template failed: $!";
 
   my @dom_svc_phone = qsearch( 'svc_phone', { 'domsvc'=>$svc_phone->domsvc } );
 
@@ -104,7 +125,9 @@ sub _export_rebuild_domain {
 
   }
 
-  print $fh qq(</domain>\n);
+  print $fh $self->freeswitch_template_fillin( $domain, 'footer' )
+    or die "print to freeswitch template failed: $!";
+
   $fh->flush;
 
   my $scp = new Net::SCP;
@@ -123,7 +146,7 @@ sub _export_rebuild_domain {
 }
 
 sub freeswitch_template_fillin {
-  my( $self, $svc_phone, $template ) = (shift, shift, shift);
+  my( $self, $svc_phone_or_dom, $template ) = (shift, shift, shift);
 
   $template ||= 'user'; #?
 
@@ -135,9 +158,9 @@ sub freeswitch_template_fillin {
   );
 
   #false lazinessish w/phone_shellcommands::_export_command
-  my %hash = (
-    map { $_ => $svc_phone->getfield($_) } $svc_phone->fields
-  );
+  my %hash = ref($svc_phone_or_dom)
+   ? ( map { $_ => $svc_phone_or_dom->getfield($_) } $svc_phone_or_dom->fields )
+   : ( 'domain' => $svc_phone_or_dom );
 
   #might as well do em all, they're all going in an XML file as attribs
   foreach ( keys %hash ) {
diff --git a/FS/FS/part_export/freeswitch.pm b/FS/FS/part_export/freeswitch_multifile.pm
similarity index 74%
copy from FS/FS/part_export/freeswitch.pm
copy to FS/FS/part_export/freeswitch_multifile.pm
index eb490fd..105ff02 100644
--- a/FS/FS/part_export/freeswitch.pm
+++ b/FS/FS/part_export/freeswitch_multifile.pm
@@ -1,12 +1,11 @@
-package FS::part_export::freeswitch;
+package FS::part_export::freeswitch_multifile;
 use base qw( FS::part_export );
 
 use vars qw( %info ); # $DEBUG );
 #use Data::Dumper;
 use Tie::IxHash;
 use Text::Template;
-use FS::Record qw( qsearch ); #qsearchs );
-use FS::svc_phone;
+#use FS::Record qw( qsearch qsearchs );
 #use FS::Schema qw( dbdef );
 
 #$DEBUG = 1;
@@ -16,7 +15,7 @@ tie my %options, 'Tie::IxHash',
   'directory' => { label   => 'Directory to store FreeSWITCH account XML files',
                    default => '/usr/local/freeswitch/conf/directory/',
                  },
-  #'domain'    => { label => 'Optional fixed SIP domain to use, overrides svc_phone domain', },
+  'domain'    => { label => 'Optional fixed SIP domain to use, overrides svc_phone domain', },
   'reload'    => { label   => 'Reload command',
                    default => '/usr/local/freeswitch/bin/fs_cli -x reloadxml',
                  },
@@ -36,12 +35,12 @@ END
 
 %info = (
   'svc'     => 'svc_phone',
-  'desc'    => 'Provision phone services to FreeSWITCH XML configuration files',
+  'desc'    => 'Provision phone services to FreeSWITCH XML configuration files (one file per user)',
   'options' => \%options,
   'notes'   => <<'END',
-Export XML account configuration files to FreeSWITCH, one per domain.
+Export XML account configuration files to FreeSWITCH, one per phone services.
 <br><br>
-You will need to enable the svc_phone-domain configuration setting and
+You will need to
 <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.9:Documentation:Administration:SSH_Keys">setup SSH for unattended operation</a>.
 END
 );
@@ -51,33 +50,6 @@ sub rebless { shift; }
 sub _export_insert {
   my( $self, $svc_phone ) = ( shift, shift );
 
-  $self->_export_rebuild_domain($svc_phone);
-
-}
-
-sub _export_replace {
-  my( $self, $new, $old ) = ( shift, shift, shift );
-
-  my $error = $self->_export_rebuild_domain($new);
-  return $error if $error;
-
-  if ( $new->domsvc ne $old->domsvc && $old->domsvc ) {
-    $error = $self->_export_rebuild_domain($old);
-    return $error if $error;
-  }
-
-  '';
-}
-
-sub _export_delete {
-  my( $self, $svc_phone ) = ( shift, shift );
-
-  $self->_export_rebuild_domain($svc_phone);
-}
-
-sub _export_rebuild_domain {
-  my($self, $svc_phone) = ( shift, shift );
-
   eval "use Net::SCP;";
   die $@ if $@;
 
@@ -85,34 +57,24 @@ sub _export_rebuild_domain {
 
   my $tempdir = '%%%FREESIDE_CONF%%%/cache.'. $FS::UID::datasrc;
 
-  my $domain = $svc_phone->domain or return "domain required";
+  my $svcnum = $svc_phone->svcnum;
 
   my $fh = new File::Temp(
-    TEMPLATE => "$tempdir/freeswitch.$domain.XXXXXXXX",
-    DIR      => $dir,
+    TEMPLATE => "$tempdir/freeswitch.$svcnum.XXXXXXXX",
+    DIR      => $tempdir,
     #UNLINK   => 0,
   );
 
-  print $fh qq(<domain name="$domain">\n);
-
-  my @dom_svc_phone = qsearch( 'svc_phone', { 'domsvc'=>$svc_phone->domsvc } );
-
-  foreach my $dom_svc_phone (@dom_svc_phone) {
-
-    print $fh $self->freeswitch_template_fillin( $dom_svc_phone, 'user' )
-      or die "print to freeswitch template failed: $!";
-
-  }
-
-  print $fh qq(</domain>\n);
-  $fh->flush;
+  print $fh $self->freeswitch_template_fillin( $svc_phone, 'user' )
+    or die "print to freeswitch template failed: $!";
+  close $fh;
 
   my $scp = new Net::SCP;
   my $user = $self->option('user')||'root';
   my $host = $self->machine;
   my $dir = $self->option('directory');
 
-  $scp->scp( $fh->filename, "$user\@$host:$dir/$domain.xml" )
+  $scp->scp( $fh->filename, "$user\@$host:$dir/$svcnum.xml" )
     or return $scp->{errstr};
 
   #signal freeswitch to reload config
@@ -122,6 +84,27 @@ sub _export_rebuild_domain {
 
 }
 
+sub _export_replace {
+  my( $self, $new, $old ) = ( shift, shift, shift );
+
+  $self->_export_insert($new, @_);
+}
+
+sub _export_delete {
+  my( $self, $svc_phone ) = ( shift, shift );
+
+  my $dir  = $self->option('directory');
+  my $svcnum = $svc_phone->svcnum;
+
+  #delete file
+  $self->freeswitch_ssh( command => "rm $dir/$svcnum.xml" );
+
+  #signal freeswitch to reload config
+  $self->freeswitch_ssh( command => $self->option('reload') );
+
+  '';
+}
+
 sub freeswitch_template_fillin {
   my( $self, $svc_phone, $template ) = (shift, shift, shift);
 
@@ -134,8 +117,13 @@ sub freeswitch_template_fillin {
     DELIMITERS => [ '<%', '%>' ],
   );
 
+  my $domain =  $self->option('domain')
+             || $svc_phone->domain
+             || '$${sip_profile}';
+
   #false lazinessish w/phone_shellcommands::_export_command
   my %hash = (
+    'domain' => $domain,
     map { $_ => $svc_phone->getfield($_) } $svc_phone->fields
   );
 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_export/freeswitch.pm                    |   59 +++++++++----
 .../{freeswitch.pm => freeswitch_multifile.pm}     |   90 +++++++++-----------
 2 files changed, 80 insertions(+), 69 deletions(-)
 copy FS/FS/part_export/{freeswitch.pm => freeswitch_multifile.pm} (74%)




More information about the freeside-commits mailing list