tyop
[freeside.git] / bin / svc_acct.import
index 8343ce8..795b853 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: svc_acct.import,v 1.3 1998-12-10 07:23:16 ivan Exp $
+# $Id: svc_acct.import,v 1.11 2000-06-29 12:27:01 ivan Exp $
 #
 # ivan@sisd.com 98-mar-9
 #
 # don't import /var/spool/freeside/conf/shells!  ivan@sisd.com 98-aug-13
 #
 # $Log: svc_acct.import,v $
-# Revision 1.3  1998-12-10 07:23:16  ivan
+# Revision 1.11  2000-06-29 12:27:01  ivan
+# s/password/_password/ for PostgreSQL wasn't done in the import.
+#
+# Revision 1.10  2000/06/28 12:32:30  ivan
+# allow RADIUS lines with "Auth-Type = Local" too
+#
+# Revision 1.8  2000/02/03 05:16:52  ivan
+# beginning of DNS and Apache support
+#
+# Revision 1.7  1999/07/08 02:32:26  ivan
+# import fix, noticed by Ben Leibig and Joel Griffiths
+#
+# Revision 1.6  1999/07/08 01:49:00  ivan
+# updates to avoid -w warnings from Joel Griffiths <griff@aver-computer.com>
+#
+# Revision 1.5  1999/03/25 08:42:19  ivan
+# import stuff uses Term::Query and spits out (some kinds of) nonsensical input
+#
+# Revision 1.4  1999/03/24 00:43:38  ivan
+# die if no relevant services
+#
+# Revision 1.3  1998/12/10 07:23:16  ivan
 # use FS::Conf, need user (for datasrc)
 #
 # Revision 1.2  1998/10/13 12:07:51  ivan
@@ -27,6 +48,7 @@
 use strict;
 use vars qw(%part_svc);
 use Date::Parse;
+use Term::Query qw(query);
 use FS::SSH qw(iscp);
 use FS::UID qw(adminsuidsetup datasrc);
 use FS::Record qw(qsearch);
@@ -44,6 +66,8 @@ $FS::svc_acct::nossh_hack = 1;
 
 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
 
+die "No services with svcdb svc_acct!\n" unless %part_svc;
+
 print "\n\n", &menu_svc, "\n", <<END;
 Most accounts probably have entries in passwd and users (with Port-Limit
 nonexistant or 1).
@@ -69,8 +93,7 @@ my($oisdn_svcpart)=&getpart;
 print "\n\n", &menu_svc, "\n", <<END;
 POP mail accounts have entries in passwd only, and have a particular shell.
 END
-print "Enter that shell: ";
-my($pop_shell)=&getvalue;
+my($pop_shell)=&getvalue("Enter that shell:");
 my($popmail_svcpart)=&getpart;
 
 print "\n\n", &menu_svc, "\n", <<END;
@@ -82,37 +105,38 @@ print "\n\n", <<END;
 Enter the location and name of your _user_ passwd file, for example
 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
 END
-print ":";
-my($loc_passwd)=&getvalue;
+my($loc_passwd)=&getvalue(":");
 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
 
 print "\n\n", <<END;
 Enter the location and name of your _user_ shadow file, for example
 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
 END
-print ":";
-my($loc_shadow)=&getvalue;
+my($loc_shadow)=&getvalue(":");
 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
 
 print "\n\n", <<END;
 Enter the location and name of your radius "users" file, for example
 "radius.isp.com:/etc/raddb/users"
 END
-print ":";
-my($loc_users)=&getvalue;
+my($loc_users)=&getvalue(":");
 iscp("root\@$loc_users", "$spooldir/users.import");
 
 sub menu_svc {
   ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
 }
 sub getpart {
-  print "Enter part number, or 0 for none: ";
-  &getvalue;
+  $^W=0; # Term::Query isn't -w-safe
+  my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
+  $^W=1;
+  $return;
 }
 sub getvalue {
-  my($x)=scalar(<STDIN>);
-  chop $x;
-  $x;
+  my $prompt = shift;
+  $^W=0; # Term::Query isn't -w-safe
+  my $return = query $prompt, '';
+  $^W=1;
+  $return;
 }
 
 print "\n\n";
@@ -127,12 +151,13 @@ my(%upassword,%ip,%allparam);
 my(%param,$username);
 while (<USERS>) {
   chop;
-  next if /^$/;
+  next if /^\s*$/;
+  next if /^\s*#/;
   if ( /^\S/ ) {
-    /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
+    /^(\w+)\s+(Auth-Type\s+=\s+Local,\s+)Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
       or die "1Unexpected line in users.import: $_";
     my($password,$expiration);
-    ($username,$password,$expiration)=(lc($1),$2,$4);
+    ($username,$password,$expiration)=(lc($1),$3,$5);
     $password = '' if $password eq 'UNIX';
     $upassword{$username}=$password;
     undef %param;
@@ -142,8 +167,12 @@ while (<USERS>) {
   while (<USERS>) {
     chop;
     if ( /^\s*$/ ) {
-      $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
-      delete $param{'radius_Framed_IP_Address'};
+      if ( defined $param{'radius_Framed_IP_Address'} ) {
+        $ip{$username} = $param{'radius_Framed_IP_Address'};
+        delete $param{'radius_Framed_IP_Address'};
+      } else {
+        $ip{$username} = '0e0';
+      }
       $allparam{$username}={ %param };
       last;
     } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
@@ -156,8 +185,12 @@ while (<USERS>) {
   }
 }
 #? incase there isn't a terminating blank line ?
-$ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
-delete $param{'radius_Framed_IP_Address'};
+if ( defined $param{'radius_Framed_IP_Address'} ) {
+  $ip{$username} = $param{'radius_Framed_IP_Address'};
+  delete $param{'radius_Framed_IP_Address'};
+} else {
+  $ip{$username} = '0e0';
+}
 $allparam{$username}={ %param };
 
 my(%password);
@@ -188,16 +221,16 @@ while (<PASSWD>) {
     $svcpart = $shell_svcpart;
   }
 
-  my($svc_acct) = create FS::svc_acct ({
-    'svcpart'  => $svcpart,
-    'username' => $username,
-    'password' => $password,
-    'uid'      => $uid,
-    'gid'      => $gid,
-    'finger'   => $finger,
-    'dir'      => $dir,
-    'shell'    => $shell,
-    'slipip'   => $ip{$username},
+  my($svc_acct) = new FS::svc_acct ({
+    'svcpart'   => $svcpart,
+    'username'  => $username,
+    '_password' => $password,
+    'uid'       => $uid,
+    'gid'       => $gid,
+    'finger'    => $finger,
+    'dir'       => $dir,
+    'shell'     => $shell,
+    'slipip'    => $ip{$username},
     %{$allparam{$username}},
   });
   my($error);
@@ -222,11 +255,11 @@ foreach $username ( keys %upassword ) {
     die "Illegal Port-Limit in users!\n";
   }
 
-  my($svc_acct) = create FS::svc_acct ({
-    'svcpart'  => $svcpart,
-    'username' => $username,
-    'password' => $password,
-    'slipip'   => $ip{$username},
+  my($svc_acct) = new FS::svc_acct ({
+    'svcpart'   => $svcpart,
+    'username'  => $username,
+    '_password' => $password,
+    'slipip'    => $ip{$username},
     %{$allparam{$username}},
   });
   my($error);
@@ -240,6 +273,6 @@ foreach $username ( keys %upassword ) {
 #
 
 sub usage {
-  die "Usage:\n\n  svc_acct.export user\n";
+  die "Usage:\n\n  svc_acct.import user\n";
 }