RADIUS groups on the way!
authorivan <ivan>
Fri, 22 Mar 2002 18:56:33 +0000 (18:56 +0000)
committerivan <ivan>
Fri, 22 Mar 2002 18:56:33 +0000 (18:56 +0000)
13 files changed:
FS/FS/cust_main_county.pm
FS/FS/svc_acct.pm
FS/MANIFEST
FS/t/radius_usergroup.t [new file with mode: 0644]
Makefile
README.1.4.0pre12
bin/create-history-tables
bin/fs-setup
httemplate/docs/schema.html
httemplate/docs/upgrade8.html
httemplate/edit/part_svc.cgi
httemplate/edit/svc_acct.cgi
httemplate/view/svc_acct.cgi

index 95ed53d..56d29da 100644 (file)
@@ -227,7 +227,7 @@ END
 
 =head1 BUGS
 
 
 =head1 BUGS
 
-regionseletor?  putting web ui components in here?  they should probably live
+regionselector?  putting web ui components in here?  they should probably live
 somewhere else...
 
 =head1 SEE ALSO
 somewhere else...
 
 =head1 SEE ALSO
index 2305aeb..9da5a66 100644 (file)
@@ -27,6 +27,7 @@ use FS::cust_main_invoice;
 use FS::svc_domain;
 use FS::raddb;
 use FS::queue;
 use FS::svc_domain;
 use FS::raddb;
 use FS::queue;
+use FS::radius_usergroup;
 
 @ISA = qw( FS::svc_Common );
 
 
 @ISA = qw( FS::svc_Common );
 
@@ -1282,8 +1283,64 @@ sub seconds_since {
   $self->cust_svc->seconds_since(@_);
 }
 
   $self->cust_svc->seconds_since(@_);
 }
 
+=item radius_groups
+
+Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
+
+=cut
+
+sub radius_groups {
+  my $self = shift;
+  map { $_->groupname }
+    qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
+}
+
 =back
 
 =back
 
+=head1 SUBROUTINES
+
+=item radius_usergroup_selector GROUPS_ARRAYREF
+
+=cut
+
+sub radius_usergroup_selector {
+  my $sel_groups = shift;
+  my %sel_groups = map { $_=>1 } @$sel_groups;
+
+  my $selectname = shift || 'radius_usergroup';
+
+  my $dbh = dbh;
+  my $sth = $dbh->prepare(
+    'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
+  ) or die $dbh->errstr;
+  $sth->execute() or die $sth->errstr;
+  my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
+
+  my $html = <<END;
+    <SCRIPT>
+    function ${selectname}_doadd(object) {
+      var myvalue = object.${selectname}_add.value;
+      var optionName = new Option(myvalue,myvalue,false,true);
+      var length = object.$selectname.length;
+      object.$selectname.options[length] = optionName;
+    }
+    </SCRIPT>
+    <SELECT MULTIPLE NAME="$selectname">
+END
+
+  foreach my $group ( @all_groups ) {
+    $html .= '<OPTION';
+    $html .= ' SELECTED' if $sel_groups{$group};
+    $html .= ">$group</OPTION>\n";
+  }
+  $html .= '</SELECT>';
+
+  $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
+           qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
+
+  $html;
+}
+
 =head1 BUGS
 
 The $recref stuff in sub check should be cleaned up.
 =head1 BUGS
 
 The $recref stuff in sub check should be cleaned up.
@@ -1292,6 +1349,9 @@ The suspend, unsuspend and cancel methods update the database, but not the
 current object.  This is probably a bug as it's unexpected and
 counterintuitive.
 
 current object.  This is probably a bug as it's unexpected and
 counterintuitive.
 
+radius_usergroup_selector?  putting web ui components in here?  they should
+probably live somewhere else...
+
 =head1 SEE ALSO
 
 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
 =head1 SEE ALSO
 
 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
index 19915cd..54aaaa1 100644 (file)
@@ -65,6 +65,7 @@ FS/prepay_credit.pm
 FS/svc_www.pm
 FS/svc_forward.pm
 FS/raddb.pm
 FS/svc_www.pm
 FS/svc_forward.pm
 FS/raddb.pm
+FS/radius_usergroup.pm
 FS/queue.pm
 FS/queue_arg.pm
 t/agent.t
 FS/queue.pm
 FS/queue_arg.pm
 t/agent.t
@@ -72,6 +73,7 @@ t/agent_type.t
 t/CGI.t
 t/Conf.t
 t/ConfItem.t
 t/CGI.t
 t/Conf.t
 t/ConfItem.t
+t/Record.t
 t/cust_bill.t
 t/cust_bill_event.t
 t/cust_bill_pay.t
 t/cust_bill.t
 t/cust_bill_event.t
 t/cust_bill_pay.t
@@ -100,7 +102,7 @@ t/part_svc_column.t
 t/pkg_svc.t
 t/port.t
 t/prepay_credit.t
 t/pkg_svc.t
 t/port.t
 t/prepay_credit.t
-t/Record.t
+t/radius_usergroup.t
 t/session.t
 t/svc_acct.t
 t/svc_acct_pop.t
 t/session.t
 t/svc_acct.t
 t/svc_acct_pop.t
diff --git a/FS/t/radius_usergroup.t b/FS/t/radius_usergroup.t
new file mode 100644 (file)
index 0000000..325742c
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::radius_usergroup;
+$loaded=1;
+print "ok 1\n";
index 8f577c5..21aeb45 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@ DATASOURCE = DBI:Pg:host=localhost;dbname=freeside
 DB_USER = freeside
 DB_PASSWORD=
 
 DB_USER = freeside
 DB_PASSWORD=
 
-TEMPLATE = asp
-#TEMPLATE = mason
+#TEMPLATE = asp
+TEMPLATE = mason
 
 ASP_GLOBAL = /usr/local/etc/freeside/asp-global
 
 
 ASP_GLOBAL = /usr/local/etc/freeside/asp-global
 
index d61656c..abbf6e5 100644 (file)
@@ -15,6 +15,14 @@ ALTER TABLE cust_bill_event ADD status varchar(80);
 ALTER TABLE cust_bill_event ADD statustext text NULL;
 UPDATE cust_bill_event SET status = 'done';
 
 ALTER TABLE cust_bill_event ADD statustext text NULL;
 UPDATE cust_bill_event SET status = 'done';
 
+CREATE TABLE radius_usergroup (
+  usergroupnum int primary key,
+  svcnum int not null,
+  groupname varchar(80) not null
+);
+CREATE INDEX radius_usergroup1 ON radius_usergroup ( svcnum );
+CREATE INDEX radius_usergroup2 ON radius_usergroup ( groupname );
+
 Run bin/dbdef-create
 
 Run bin/create-history-tables
 Run bin/dbdef-create
 
 Run bin/create-history-tables
index fb4c866..9ed641e 100755 (executable)
@@ -16,8 +16,13 @@ my $dbh = adminsuidsetup $user;
 my $schema = dbdef();
 
 #false laziness w/fs-setup
 my $schema = dbdef();
 
 #false laziness w/fs-setup
-foreach my $table ( grep { ! /^h_/ } $schema->tables ) {
-  my $tableobj = $schema->table($table);
+my @tables = scalar(@ARGV)
+               ? @ARGV
+               : grep { ! /^h_/ } $schema->tables;
+foreach my $table ( @tables ) {
+  warn "creating history table for $table\n";
+  my $tableobj = $schema->table($table)
+    or die "unknown talble $table (did you run dbdef-create?)\n";
   my $h_tableobj = DBIx::DBSchema::Table->new( {
     name        => "h_$table",
     primary_key => 'historynum',
   my $h_tableobj = DBIx::DBSchema::Table->new( {
     name        => "h_$table",
     primary_key => 'historynum',
@@ -73,6 +78,6 @@ $dbh->commit or die $dbh->errstr;
 $dbh->disconnect or die $dbh->errstr;
 
 sub usage {
 $dbh->disconnect or die $dbh->errstr;
 
 sub usage {
-  die "Usage:\n  create-history-tables user\n";
+  die "Usage:\n  create-history-tables user [ table table ... ] \n";
 }
 
 }
 
index 7ee04a5..01e08f7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
 #!/usr/bin/perl -Tw
 #
-# $Id: fs-setup,v 1.83 2002-03-04 12:48:49 ivan Exp $
+# $Id: fs-setup,v 1.84 2002-03-22 18:56:32 ivan Exp $
 
 #to delay loading dbdef until we're ready
 BEGIN { $FS::Record::setup_hack = 1; }
 
 #to delay loading dbdef until we're ready
 BEGIN { $FS::Record::setup_hack = 1; }
@@ -951,6 +951,17 @@ sub tables_hash_hack {
       'index'       => [ [ 'exportnum' ], [ 'optionname' ] ],
     },
 
       'index'       => [ [ 'exportnum' ], [ 'optionname' ] ],
     },
 
+    'radius_usergroup' => {
+      'columns' => [
+        'usergroupnum', 'int', '', '',
+        'svcnum',       'int', '', '',
+        'groupname',    'varchar', '', $char_d,
+      ],
+      'primary_key' => 'usergroupnum',
+      'unique'      => [],
+      'index'       => [ [ 'svcnum' ], [ 'groupname' ] ],
+    },
+
   );
 
   %tables;
   );
 
   %tables;
index b828213..192f56b 100644 (file)
         <li>jobnum - <a href="#queue">job</a>
         <li>arg - argument
       </ul>
         <li>jobnum - <a href="#queue">job</a>
         <li>arg - argument
       </ul>
+    <li><a name="radius_usergroup" href="man/FS/radius_usergroup.html">radius_usergroup</a> - Link users to RADIUS groups.
+      <ul>
+        <li>usergroupnum - primary key
+        <li>svcnum - <a href="#svc_acct">account</a>
+        <li>groupname
+      </ul>
   </ul>
 </body>
   </ul>
 </body>
index e52b69a..440024d 100644 (file)
@@ -171,6 +171,14 @@ CREATE TABLE part_export_option (
 CREATE INDEX part_export_option1 ON part_export_option ( exportnum );
 CREATE INDEX part_export_option2 ON part_export_option ( optionname );
 
 CREATE INDEX part_export_option1 ON part_export_option ( exportnum );
 CREATE INDEX part_export_option2 ON part_export_option ( optionname );
 
+CREATE TABLE radius_usergroup (
+  usergroupnum int primary key,
+  svcnum int not null,
+  groupname varchar(80) not null
+);
+CREATE INDEX radius_usergroup1 ON radius_usergroup ( svcnum );
+CREATE INDEX radius_usergroup2 ON radius_usergroup ( groupname );
+
 ALTER TABLE svc_acct ADD domsvc integer NOT NULL;
 ALTER TABLE svc_domain ADD catchall integer NULL;
 ALTER TABLE cust_main ADD referral_custnum integer NULL;
 ALTER TABLE svc_acct ADD domsvc integer NOT NULL;
 ALTER TABLE svc_domain ADD catchall integer NULL;
 ALTER TABLE cust_main ADD referral_custnum integer NULL;
index 3292a9b..b1bb7f3 100755 (executable)
@@ -86,6 +86,10 @@ my %defs = (
                      select_key   => 'svcnum',
                      select_label => 'domain',
                    },
                      select_key   => 'svcnum',
                      select_label => 'domain',
                    },
+    'radius_groups' => {
+                         desc =>'ICRADIUS/FreeRADIUS groups',
+                         type =>'radius_usergroup_selector',
+                       },
   },
   'svc_domain' => {
     'domain'    => 'Domain',
   },
   'svc_domain' => {
     'domain'    => 'Domain',
index d147a16..6846b5c 100755 (executable)
@@ -239,6 +239,10 @@ foreach my $r ( grep { /^r(adius|[cr])_/ } fields('svc_acct') ) {
   }
 }
 
   }
 }
 
+print '<TR><TD ALIGN="right">RADIUS groups</TD><TD>'.
+      &FS::svc_acct::radius_usergroup_selector( [ $svc_acct->radius_groups ] ).
+      '</TD></TR>';
+
 #submit
 print qq!</TABLE><BR><INPUT TYPE="submit" VALUE="Submit">!; 
 
 #submit
 print qq!</TABLE><BR><INPUT TYPE="submit" VALUE="Submit">!; 
 
index d1c6157..b779e87 100755 (executable)
@@ -129,6 +129,9 @@ if ($svc_acct->slipip) {
   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
 }
 
   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
 }
 
+print '<TR><TD ALIGN="right">RADIUS groups</TD><TD BGCOLOR="#ffffff">'.
+      join('<BR>', $svc_acct->radius_groups). '</TD></TR>';
+
 print "</TABLE></TD></TR></TABLE>".
       '<BR>'. joblisting({'svcnum'=>$svcnum}, 1).
       "</BODY></HTML>";
 print "</TABLE></TD></TR></TABLE>".
       '<BR>'. joblisting({'svcnum'=>$svcnum}, 1).
       "</BODY></HTML>";