tyop
[freeside.git] / bin / svc_acct.export
index 47df3d1..636921a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# $Id: svc_acct.export,v 1.11 2000-03-06 16:00:39 ivan Exp $
+# $Id: svc_acct.export,v 1.16 2000-07-06 13:23:29 ivan Exp $
 #
 # Create and export password files: passwd, passwd.adjunct, shadow,
 # acp_passwd, acp_userinfo, acp_dialup, users
 # ivan@sisd.com 98-sep-18
 # 
 # $Log: svc_acct.export,v $
-# Revision 1.11  2000-03-06 16:00:39  ivan
+# Revision 1.16  2000-07-06 13:23:29  ivan
+# tyop
+#
+# Revision 1.15  2000/07/06 08:57:28  ivan
+# support for radius check attributes (except importing).  poorly documented.
+#
+# Revision 1.14  2000/06/29 15:01:25  ivan
+# another silly typo in svc_acct.export
+#
+# Revision 1.13  2000/06/28 12:37:28  ivan
+# add support for config option textradiusprepend
+#
+# Revision 1.12  2000/06/15 14:07:02  ivan
+# added ICRADIUS radreply table support, courtesy of Kenny Elliott
+#
+# Revision 1.11  2000/03/06 16:00:39  ivan
 # sync up with working versoin
 #
 # Revision 1.2  1998/12/10 07:23:15  ivan
@@ -86,6 +101,8 @@ my $icradius_mysqlsource =
 my $icradius_dbh = dbh; #could eventually get it from a config file if you're
                         #not running MySQL for your Freeside database
 
+my $textradiusprepend = $conf->config('textradiusprepend');
+
 my(@saltset)= ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
 require 5.004; #srand(time|$$);
 
@@ -137,6 +154,8 @@ chmod 0600, "$spooldir/master.passwd",
 if ( $icradiusmachines ) {
   my $sth = $icradius_dbh->prepare("DELETE FROM radcheck");
   $sth->execute or die "Can't reset radcheck table: ". $sth->errstr;
+  my $sth2 = $icradius_dbh->prepare("DELETE FROM radreply");
+  $sth2->execute or die "Can't reset radreply table: ". $sth2->errstr;
 }
 
 setpriority(0,0,10);
@@ -227,21 +246,24 @@ foreach $svc_acct (@svc_acct) {
       print ACP_DIALUP $svc_acct->username, "\t*\t", $svc_acct->slipip, "\n";
     }
 
+    my %radreply = $svc_acct->radius_reply;
+    my %radcheck = $svc_acct->radius_check;
+
+    my $radcheck = join ", ", map { qq($_ = "$radcheck{$_}") } keys %radcheck;
+    $radcheck .= ", " if $radcheck;
+
     ###
     # FORMAT OF THE USERS FILE HERE
     print USERS
-      $svc_acct->username, qq(\tPassword = "$rpassword"\n\t),
-
-      join ",\n\t",
-        map  {
-          /^(radius_(.*))$/;
-          my($field,$attrib)=($1,$2);
-          $attrib =~ s/_/\-/g;
-          "$attrib = \"". $svc_acct->getfield($field). "\"";
-        } grep /^radius_/ && $svc_acct->getfield($_), fields('svc_acct') 
-    ;
+      $svc_acct->username,
+      qq(\t${textradiusprepend}),
+      $radcheck,
+      qq(Password = "$rpassword"\n\t),
+      join ",\n\t", map { qq($_ = "$radreply{$_}") } keys %radreply;
+    
     if ( $ip && $ip ne '0e0' ) {
-      print USERS qq(,\n\tFramed-Address = "$ip"\n\n);
+      #print USERS qq(,\n\tFramed-Address = "$ip"\n\n);
+      print USERS qq(,\n\tFramed-IP-Address = "$ip"\n\n);
     } else {
       print USERS qq(\n\n);
     }
@@ -249,17 +271,45 @@ foreach $svc_acct (@svc_acct) {
     ###
     # ICRADIUS export
     if ( $icradiusmachines ) {
+
       my $sth = $icradius_dbh->prepare(
         "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
         join(", ", map { $icradius_dbh->quote( $_ ) } (
-          $svc_acct->svcnum,
+          '',
           $svc_acct->username,
           "Password",
           $svc_acct->_password,
         ) ). " )"
       );
       $sth->execute or die "Can't insert into radcheck table: ". $sth->errstr;
-   }
+
+      foreach my $attribute ( keys %radcheck ) {
+        my $sth = $icradius_dbh->prepare(
+          "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
+          join(", ", map { $icradius_dbh->quote( $_ ) } (
+            '',
+            $svc_acct->username,
+            $attribute,
+            $radcheck{$attribute},
+          ) ). " )"
+        );
+        $sth->execute or die "Can't insert into radcheck table: ". $sth->errstr;
+      }
+
+      foreach my $attribute ( keys %radreply ) {
+        my $sth = $icradius_dbh->prepare(
+          "INSERT INTO radreply (id, UserName, Attribute, Value) VALUES ( ".
+          join(", ", map { $icradius_dbh->quote( $_ ) } (
+            '',
+            $svc_acct->username,
+            $attribute,
+            $radreply{$attribute},
+          ) ). " )"
+        );
+        $sth->execute or die "Can't insert into radreply table: ". $sth->errstr;
+      }
+
+    }
 
   }
 
@@ -345,7 +395,7 @@ my($radiusmachine);
 foreach $radiusmachine (@radiusmachines) {
   scp("$spooldir/users","root\@$radiusmachine:/etc/raddb/users")
     == 0 or die "scp error: $!";
-  ssh("root\@$erpcdmachine",
+  ssh("root\@$radiusmachine",
     "( ".
       "builddbm".
     " )"
@@ -358,10 +408,15 @@ foreach my $icradiusmachine ( @icradiusmachines ) {
   chdir $icradius_mysqlsource or die "Can't cd $icradius_mysqlsource: $!";
   open(WRITER,"|ssh root\@$machine mysql -v --user=$user -p $db");
   my $oldfh = select WRITER; $|=1; select $oldfh;
-  print WRITER "$pass\n"; sleep 2; print WRITER "LOCK TABLES radcheck WRITE;\n";
+  print WRITER "$pass\n";
+  sleep 2;
+  print WRITER "LOCK TABLES radcheck WRITE, radreply WRITE;\n";
   foreach my $file ( glob("radcheck.*") ) {
     scp($file,"root\@$machine:$icradius_mysqldest/$db/$file");
   }
+  foreach my $file ( glob("radreply.*") ) {
+    scp($file,"root\@$machine:$icradius_mysqldest/$db/$file");
+  }
   close WRITER;
 }