71513: Card tokenization [upgrade implemented]
[freeside.git] / bin / fs-radius-add-reply
index 997a8ea..c6c24e0 100755 (executable)
@@ -1,15 +1,18 @@
 #!/usr/bin/perl -Tw
 
 # quick'n'dirty hack of fs-setup to add radius attributes
 #!/usr/bin/perl -Tw
 
 # quick'n'dirty hack of fs-setup to add radius attributes
+# (i'm not sure this even works in the new world of schema changes - everyone
+#  uses attributes via groups now)
 
 use strict;
 use DBI;
 
 use strict;
 use DBI;
-use FS::UID qw(adminsuidsetup checkeuid getsecrets);
-die "Not running uid freeside!" unless checkeuid();
+use FS::UID qw(adminsuidsetup);
+use FS::raddb;
 
 
-my $user = shift or die &usage;
-getsecrets($user);
+my %attrib2db =
+  map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib;
 
 
+my $user = shift or die &usage;
 my $dbh = adminsuidsetup $user;
 
 ###
 my $dbh = adminsuidsetup $user;
 
 ###
@@ -18,7 +21,8 @@ print "\n\n", <<END, ":";
 Enter the additional RADIUS reply attributes you need to track for
 each user, separated by whitespace.
 END
 Enter the additional RADIUS reply attributes you need to track for
 each user, separated by whitespace.
 END
-my @attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
+my @attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
+                   split(" ",&getvalue);
 
 sub getvalue {
   my($x)=scalar(<STDIN>);
 
 sub getvalue {
   my($x)=scalar(<STDIN>);
@@ -33,20 +37,31 @@ my($char_d) = 80; #default maxlength for text fields
 ###
 
 foreach my $attribute ( @attributes ) {
 ###
 
 foreach my $attribute ( @attributes ) {
-  foreach my $statement ( 
-    "ALTER TABLE svc_acct ADD radius_$attribute varchar($char_d) NULL",
-#    "ALTER TABLE part_svc ADD svc_acct__radius_$attribute varchar($char_d) NULL;",
-#    "ALTER TABLE part_svc ADD svc_acct__radius_${attribute}_flag char(1) NULL;",
-  ) {
-    $dbh->do( $statement ) or warn "Error executing $statement: ". $dbh->errstr;  }
+
+  my $statement =
+    "ALTER TABLE svc_acct ADD COLUMN radius_$attribute varchar($char_d) NULL";
+  my $sth = $dbh->prepare( $statement )
+    or warn "Error preparing $statement: ". $dbh->errstr;
+  my $rc = $sth->execute
+    or warn "Error executing $statement: ". $sth->errstr;
+
+  $statement =
+    "ALTER TABLE h_svc_acct ADD COLUMN radius_$attribute varchar($char_d) NULL";
+  $sth = $dbh->prepare( $statement )
+    or warn "Error preparing $statement: ". $dbh->errstr;
+  $rc = $sth->execute
+    or warn "Error executing $statement: ". $sth->errstr;
+
 }
 
 }
 
+$dbh->commit or die $dbh->errstr;
+
 $dbh->disconnect or die $dbh->errstr;
 
 print "\n\n", "Now you must run dbdef-create.\n\n";
 
 sub usage {
 $dbh->disconnect or die $dbh->errstr;
 
 print "\n\n", "Now you must run dbdef-create.\n\n";
 
 sub usage {
-  die "Usage:\n  fs-radius-add user\n"; 
+  die "Usage:\n  fs-radius-add-reply user\n"; 
 }
 
 
 }