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