adding sqlradius_withdomain export including realms, closes: bug#514
authorivan <ivan>
Mon, 30 Jun 2003 12:22:24 +0000 (12:22 +0000)
committerivan <ivan>
Mon, 30 Jun 2003 12:22:24 +0000 (12:22 +0000)
FS/FS/part_export.pm
FS/FS/part_export/sqlradius.pm
FS/FS/part_export/sqlradius_withdomain.pm [new file with mode: 0644]
FS/bin/freeside-sqlradius-reset
FS/t/part_export-sqlradius_withdomain.t [new file with mode: 0644]

index f1a0b1a..0941da1 100644 (file)
@@ -691,6 +691,12 @@ tie my %sqlradius_options, 'Tie::IxHash',
   'password' => { label=>'Database password' },
 ;
 
+tie my %sqlradius_withdomain_options, 'Tie::IxHash',
+  'datasrc'  => { label=>'DBI data source ' },
+  'username' => { label=>'Database username' },
+  'password' => { label=>'Database password' },
+;
+
 tie my %cyrus_options, 'Tie::IxHash',
   'server' => { label=>'IMAP server' },
   'username' => { label=>'Admin username' },
@@ -896,7 +902,14 @@ tie my %forward_shellcommands_options, 'Tie::IxHash',
       'desc' => 'Real-time export to SQL-backed RADIUS (ICRADIUS, FreeRADIUS)',
       'options' => \%sqlradius_options,
       'nodomain' => 'Y',
-      'notes' => 'Real-time export of radcheck, radreply and usergroup tables to any SQL database for <a href="http://www.freeradius.org/">FreeRADIUS</a> or <a href="http://radius.innercite.com/">ICRADIUS</a>.  An existing RADIUS database will be updated in realtime, but you can use <a href="../docs/man/bin/freeside-sqlradius-reset">freeside-sqlradius-reset</a> to delete the entire RADIUS database and repopulate the tables from the Freeside database.  See the <a href="http://search.cpan.org/doc/TIMB/DBI-1.23/DBI.pm">DBI documentation</a> and the <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a> for the exact syntax of a DBI data source.',
+      'notes' => 'Real-time export of radcheck, radreply and usergroup tables to any SQL database for <a href="http://www.freeradius.org/">FreeRADIUS</a> or <a href="http://radius.innercite.com/">ICRADIUS</a>.  This export does not export RADIUS realms (see also sqlradius_withdomain).  AAn existing RADIUS database will be updated in realtime, but you can use <a href="../docs/man/bin/freeside-sqlradius-reset">freeside-sqlradius-reset</a> to delete the entire RADIUS database and repopulate the tables from the Freeside database.  See the <a href="http://search.cpan.org/doc/TIMB/DBI/DBI.pm">DBI documentation</a> and the <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a> for the exact syntax of a DBI data source.',
+    },
+
+    'sqlradius_withdomain' => {
+      'desc' => 'Real-time export to SQL-backed RADIUS (ICRADIUS, FreeRADIUS) with realms',
+      'options' => \%sqlradius_withdomain_options,
+      'nodomain' => '',
+      'notes' => 'Real-time export of radcheck, radreply and usergroup tables to any SQL database for <a href="http://www.freeradius.org/">FreeRADIUS</a> or <a href="http://radius.innercite.com/">ICRADIUS</a>.  This export exports domains to RADIUS realms (see also sqlradius).  An existing RADIUS database will be updated in realtime, but you can use <a href="../docs/man/bin/freeside-sqlradius-reset">freeside-sqlradius-reset</a> to delete the entire RADIUS database and repopulate the tables from the Freeside database.  See the <a href="http://search.cpan.org/doc/TIMB/DBI/DBI.pm">DBI documentation</a> and the <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a> for the exact syntax of a DBI data source.',
     },
 
     'sqlmail' => {
index 60450ee..8a8f9be 100644 (file)
@@ -8,6 +8,11 @@ use FS::part_export;
 
 sub rebless { shift; }
 
+sub export_username {
+  my($self, $svc_acct) = (shift, shift);
+  $svc_acct->username;
+}
+
 sub _export_insert {
   my($self, $svc_acct) = (shift, shift);
 
@@ -16,14 +21,14 @@ sub _export_insert {
     my %attrib = $svc_acct->$method();
     next unless keys %attrib;
     my $err_or_queue = $self->sqlradius_queue( $svc_acct->svcnum, 'insert',
-      $table, $svc_acct->username, %attrib );
+      $table, $self->export_username($svc_acct), %attrib );
     return $err_or_queue unless ref($err_or_queue);
   }
   my @groups = $svc_acct->radius_groups;
   if ( @groups ) {
     my $err_or_queue = $self->sqlradius_queue(
       $svc_acct->svcnum, 'usergroup_insert',
-      $svc_acct->username, @groups );
+      $self->export_username($svc_acct), @groups );
     return $err_or_queue unless ref($err_or_queue);
   }
   '';
@@ -44,9 +49,9 @@ sub _export_replace {
   my $dbh = dbh;
 
   my $jobnum = '';
-  if ( $old->username ne $new->username ) {
+  if ( $self->export_username($old) ne $self->export_username($new) ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'rename',
-      $new->username, $old->username );
+      $self->export_username($new), $self->export_username($old) );
     unless ( ref($err_or_queue) ) {
       $dbh->rollback if $oldAutoCommit;
       return $err_or_queue;
@@ -63,7 +68,7 @@ sub _export_replace {
               } keys %new
     ) {
       my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'insert',
-        $table, $new->username, %new );
+        $table, $self->export_username($new), %new );
       unless ( ref($err_or_queue) ) {
         $dbh->rollback if $oldAutoCommit;
         return $err_or_queue;
@@ -80,7 +85,7 @@ sub _export_replace {
     my @del = grep { !exists $new{$_} } keys %old;
     if ( @del ) {
       my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'attrib_delete',
-        $table, $new->username, @del );
+        $table, $self->export_username($new), @del );
       unless ( ref($err_or_queue) ) {
         $dbh->rollback if $oldAutoCommit;
         return $err_or_queue;
@@ -109,7 +114,7 @@ sub _export_replace {
 
   if ( @delgroups ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_delete',
-      $new->username, @delgroups );
+      $self->export_username($new), @delgroups );
     unless ( ref($err_or_queue) ) {
       $dbh->rollback if $oldAutoCommit;
       return $err_or_queue;
@@ -125,7 +130,7 @@ sub _export_replace {
 
   if ( @newgroups ) {
     my $err_or_queue = $self->sqlradius_queue( $new->svcnum, 'usergroup_insert',
-      $new->username, @newgroups );
+      $self->export_username($new), @newgroups );
     unless ( ref($err_or_queue) ) {
       $dbh->rollback if $oldAutoCommit;
       return $err_or_queue;
@@ -147,7 +152,7 @@ sub _export_replace {
 sub _export_delete {
   my( $self, $svc_acct ) = (shift, shift);
   my $err_or_queue = $self->sqlradius_queue( $svc_acct->svcnum, 'delete',
-    $svc_acct->username );
+    $self->export_username($svc_acct) );
   ref($err_or_queue) ? '' : $err_or_queue;
 }
 
diff --git a/FS/FS/part_export/sqlradius_withdomain.pm b/FS/FS/part_export/sqlradius_withdomain.pm
new file mode 100644 (file)
index 0000000..1c8f38c
--- /dev/null
@@ -0,0 +1,12 @@
+package FS::part_export::sqlradius_withdomain;
+
+use vars qw(@ISA);
+use FS::part_export::sqlradius;
+
+@ISA = qw(FS::part_export::sqlradius);
+
+sub export_username {
+  my($self, $svc_acct) = (shift, shift);
+  $svc_acct->email;
+}
+
index 9d3a6a7..74f90a5 100755 (executable)
@@ -12,7 +12,9 @@ adminsuidsetup $user;
 
 #my $machine = shift or die &usage;
 
-my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } );
+my @exports =  qsearch('part_export', { exporttype=>'sqlradius' } );
+push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } );
+
 
 foreach my $export ( @exports ) {
   my $icradius_dbh = DBI->connect(
diff --git a/FS/t/part_export-sqlradius_withdomain.t b/FS/t/part_export-sqlradius_withdomain.t
new file mode 100644 (file)
index 0000000..504bf67
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::part_export::sqlradius_withdomain;
+$loaded=1;
+print "ok 1\n";