point to wiki docs
[freeside.git] / FS / FS / part_export / textradius.pm
index 691753f..869c7c7 100644 (file)
@@ -1,13 +1,36 @@
 package FS::part_export::textradius;
 
-use vars qw(@ISA $prefix);
+use vars qw(@ISA %info $prefix);
 use Fcntl qw(:flock);
+use Tie::IxHash;
 use FS::UID qw(datasrc);
 use FS::part_export;
 
 @ISA = qw(FS::part_export);
 
-$prefix = "/usr/local/etc/freeside/export.";
+tie my %options, 'Tie::IxHash',
+  'user' => { label=>'Remote username', default=>'root' },
+  'users' => { label=>'users file location', default=>'/etc/raddb/users' },
+;
+
+%info = (
+  'svc'     => 'svc_acct',
+  'desc'    =>
+    'Real-time export to a text /etc/raddb/users file (Livingston, Cistron)',
+  'options' => \%options,
+  'notes'   => <<'END'
+This will edit a text RADIUS users file in place on a remote server.
+Requires installation of
+<a href="http://search.cpan.org/dist/RADIUS-UserFile">RADIUS::UserFile</a>
+from CPAN.  If using RADIUS::UserFile 1.01, make sure to apply
+<a href="http://rt.cpan.org/NoAuth/Bug.html?id=1210">this patch</a>.  Also
+make sure <a href="http://rsync.samba.org/">rsync</a> is installed on the
+remote machine, and <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.9:Documentation:Administration:SSH_Keys">SSH is setup for unattended
+operation</a>.
+END
+);
+
+$prefix = "%%%FREESIDE_CONF%%%/export.";
 
 sub rebless { shift; }
 
@@ -43,7 +66,7 @@ sub textradius_queue {
     'job'    => "FS::part_export::textradius::textradius_$method",
   };
   $queue->insert(
-    $self->option('user'),
+    $self->option('user')||'root',
     $self->machine,
     $self->option('users'),
     @_,
@@ -55,7 +78,7 @@ sub textradius_insert { #subroutine, not method
 
   #silly arg processing
   my($att, @check);
-  push @check, $att while ($att=shift @attributes) ne '-';
+  push @check, $att while @attributes && ($att=shift @attributes) ne '-';
   my %check = @check;
   my %reply = @attributes;
 
@@ -126,7 +149,13 @@ sub textradius_download {
   $rsync->exec( {
     src  => "$user\@$host:$users",
     dest => $dest,
-  } );
+  } ); # true/false return value from exec is not working, alas
+  if ( $rsync->err ) {
+    die "error downloading $user\@$host:$users : ".
+        'exit status: '. $rsync->status. ', '.
+        'STDERR: '. join(" / ", $rsync->err). ', '.
+        'STDOUT: '. join(" / ", $rsync->out);
+  }
 
   $dest;
 }
@@ -145,10 +174,18 @@ sub textradius_upload {
   $rsync->exec( {
     src  => "$dir/users",
     dest => "$user\@$host:$users",
-  } );
+  } ); # true/false return value from exec is not working, alas
+  if ( $rsync->err ) {
+    die "error uploading to $user\@$host:$users : ".
+        'exit status: '. $rsync->status. ', '.
+        'STDERR: '. join(" / ", $rsync->err). ', '.
+        'STDOUT: '. join(" / ", $rsync->out);
+  }
 
   flock(LOCK,LOCK_UN);
   close LOCK;
 
 }
 
+1;
+