links to show alternate invoices also
[freeside.git] / bin / fs-radius-add-reply
1 #!/usr/bin/perl -Tw
2
3 # quick'n'dirty hack of fs-setup to add radius attributes
4
5 use strict;
6 use DBI;
7 use FS::UID qw(adminsuidsetup checkeuid getsecrets);
8 use FS::raddb;
9
10 die "Not running uid freeside!" unless checkeuid();
11
12 my %attrib2db =
13   map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib;
14
15 my $user = shift or die &usage;
16 getsecrets($user);
17
18 my $dbh = adminsuidsetup $user;
19
20 ###
21
22 print "\n\n", <<END, ":";
23 Enter the additional RADIUS reply attributes you need to track for
24 each user, separated by whitespace.
25 END
26 my @attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
27                    split(" ",&getvalue);
28
29 sub getvalue {
30   my($x)=scalar(<STDIN>);
31   chop $x;
32   $x;
33 }
34
35 ###
36
37 my($char_d) = 80; #default maxlength for text fields
38
39 ###
40
41 foreach my $attribute ( @attributes ) {
42
43   my $statement =
44     "ALTER TABLE svc_acct ADD COLUMN radius_$attribute varchar($char_d) NULL";
45   my $sth = $dbh->prepare( $statement )
46     or warn "Error preparing $statement: ". $dbh->errstr;
47   my $rc = $sth->execute
48     or warn "Error executing $statement: ". $sth->errstr;
49
50   $statement =
51     "ALTER TABLE h_svc_acct ADD COLUMN radius_$attribute varchar($char_d) NULL";
52   $sth = $dbh->prepare( $statement )
53     or warn "Error preparing $statement: ". $dbh->errstr;
54   $rc = $sth->execute
55     or warn "Error executing $statement: ". $sth->errstr;
56
57 }
58
59 $dbh->commit or die $dbh->errstr;
60
61 $dbh->disconnect or die $dbh->errstr;
62
63 print "\n\n", "Now you must run dbdef-create.\n\n";
64
65 sub usage {
66   die "Usage:\n  fs-radius-add-reply user\n"; 
67 }
68
69