"same as billing address" box would uncheck itself on errors (only looked
[freeside.git] / httemplate / edit / svc_acct.cgi
index 3d0bb01..90b2632 100755 (executable)
@@ -1,27 +1,10 @@
+<!-- mason kludge -->
 <%
-#<!-- $Id: svc_acct.cgi,v 1.10 2001-10-20 12:18:00 ivan Exp $ -->
-
-use strict;
-use vars qw( $conf $cgi @shells $action $svcnum $svc_acct $pkgnum $svcpart
-             $part_svc $svc $otaker $username $password $ulen $ulen2 $p1
-             $popnum $domsvc $uid $gid $finger $dir $shell $quota $slipip
-             %svc_domain );
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(cgisuidsetup getotaker);
-use FS::CGI qw(header popurl itable);
-use FS::Record qw(qsearch qsearchs fields);
-use FS::svc_acct;
-use FS::svc_acct_pop qw(popselector);
-use FS::Conf;
-use FS::raddb;
-
-$cgi = new CGI;
-&cgisuidsetup($cgi);
-
-$conf = new FS::Conf;
-@shells = $conf->config('shells');
 
+my $conf = new FS::Conf;
+my @shells = $conf->config('shells');
+
+my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct, @groups);
 if ( $cgi->param('error') ) {
   $svc_acct = new FS::svc_acct ( {
     map { $_, scalar($cgi->param($_)) } fields('svc_acct')
@@ -29,8 +12,9 @@ if ( $cgi->param('error') ) {
   $svcnum = $svc_acct->svcnum;
   $pkgnum = $cgi->param('pkgnum');
   $svcpart = $cgi->param('svcpart');
-  $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
-  die "No part_svc entry!" unless $part_svc;
+  $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
+  die "No part_svc entry for svcpart $svcpart!" unless $part_svc;
+  @groups = $cgi->param('radius_usergroup');
 } else {
   my($query) = $cgi->keywords;
   if ( $query =~ /^(\d+)$/ ) { #editing
@@ -44,8 +28,10 @@ if ( $cgi->param('error') ) {
     $pkgnum=$cust_svc->pkgnum;
     $svcpart=$cust_svc->svcpart;
 
-    $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
-    die "No part_svc entry!" unless $part_svc;
+    $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
+    die "No part_svc entry for svcpart $svcpart!" unless $part_svc;
+
+    @groups = $svc_acct->radius_groups;
 
   } else { #adding
 
@@ -55,8 +41,8 @@ if ( $cgi->param('error') ) {
       $pkgnum=$1 if /^pkgnum(\d+)$/;
       $svcpart=$1 if /^svcpart(\d+)$/;
     }
-    $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
-    die "No part_svc entry!" unless $part_svc;
+    $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
+    die "No part_svc entry for svcpart $svcpart!" unless $part_svc;
 
     $svcnum='';
 
@@ -64,31 +50,38 @@ if ( $cgi->param('error') ) {
     my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
     if ($cust_pkg) {
       my($cust_main)=qsearchs('cust_main',{'custnum'=> $cust_pkg->custnum } );
-      $svc_acct->setfield('finger',
-        $cust_main->getfield('first') . " " . $cust_main->getfield('last')
-      ) ;
+      unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
+        $svc_acct->setfield('finger',
+          $cust_main->getfield('first') . " " . $cust_main->getfield('last')
+        );
+      }
     }
 
     #set fixed and default fields from part_svc
     foreach my $part_svc_column (
       grep { $_->columnflag } $part_svc->all_part_svc_column
     ) {
-      $svc_acct->setfield( $part_svc_column->columnname,
-                           $part_svc_column->columnvalue,
-                         );
+      if ( $part_svc_column->columnname eq 'usergroup' ) {
+        @groups = split(',', $part_svc_column->columnvalue);
+      } else {
+        $svc_acct->setfield( $part_svc_column->columnname,
+                             $part_svc_column->columnvalue,
+                           );
+      }
     }
 
   }
 }
-$action = $svcnum ? 'Edit' : 'Add';
+my $action = $svcnum ? 'Edit' : 'Add';
 
-$svc = $part_svc->getfield('svc');
+my $svc = $part_svc->getfield('svc');
 
-$otaker = getotaker;
+my $otaker = getotaker;
 
-$username = $svc_acct->username;
+my $username = $svc_acct->username;
+my $password;
 if ( $svc_acct->_password ) {
-  if ( $conf->exists('showpasswords') ) {
+  if ( $conf->exists('showpasswords') || ! $svcnum ) {
     $password = $svc_acct->_password;
   } else {
     $password = "*HIDDEN*";
@@ -97,11 +90,15 @@ if ( $svc_acct->_password ) {
   $password = '';
 }
 
-$ulen = $svc_acct->dbdef_table->column('username')->length;
-$ulen2 = $ulen+2;
+my $ulen = $conf->config('usernamemax')
+           || $svc_acct->dbdef_table->column('username')->length;
+my $ulen2 = $ulen+2;
 
-$p1 = popurl(1);
-print $cgi->header( '-expires' => 'now' ), header("$action $svc account");
+my $pmax = $conf->config('passwordmax') || 8;
+my $pmax2 = $pmax+2;
+
+my $p1 = popurl(1);
+print header("$action $svc account");
 
 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
       "</FONT><BR><BR>"
@@ -110,24 +107,35 @@ print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
 print 'Service # '. ( $svcnum ? "<B>$svcnum</B>" : " (NEW)" ). '<BR>'.
       'Service: <B>'. $part_svc->svc. '</B><BR><BR>'.
       <<END;
-    <FORM ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
+    <FORM NAME="OneTrueForm" ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
       <INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">
       <INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">
       <INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">
 END
 
-print &itable("#cccccc",2), <<END;
-<TR><TD>
+print &ntable("#cccccc",2), <<END;
 <TR><TD ALIGN="right">Username</TD>
 <TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
 <TR><TD ALIGN="right">Password</TD>
-<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=10 MAXLENGTH=8>
+<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$pmax>
 (blank to generate)</TD>
 </TR>
 END
 
+my $sec_phrase = $svc_acct->sec_phrase;
+if ( $conf->exists('security_phrase') ) {
+  print <<END;
+  <TR><TD ALIGN="right">Security phrase</TD>
+  <TD><INPUT TYPE="text" NAME="sec_phrase" VALUE="$sec_phrase" SIZE=32>
+    (for forgotten passwords)</TD>
+  </TD>
+END
+} else {
+  print qq!<INPUT TYPE="hidden" NAME="sec_phrase" VALUE="$sec_phrase">!;
+}
+
 #domain
-$domsvc = $svc_acct->domsvc || 0;
+my $domsvc = $svc_acct->domsvc || 0;
 if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) {
   print qq!<INPUT TYPE="hidden" NAME="domsvc" VALUE="$domsvc">!;
 } else { 
@@ -182,7 +190,7 @@ if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) {
 }
 
 #pop
-$popnum = $svc_acct->popnum || 0;
+my $popnum = $svc_acct->popnum || 0;
 if ( $part_svc->part_svc_column('popnum')->columnflag eq "F" ) {
   print qq!<INPUT TYPE="hidden" NAME="popnum" VALUE="$popnum">!;
 } else { 
@@ -190,7 +198,7 @@ if ( $part_svc->part_svc_column('popnum')->columnflag eq "F" ) {
         qq!<TD>!. FS::svc_acct_pop::popselector($popnum). '</TD></TR>';
 }
 
-($uid,$gid,$finger,$dir)=(
+my($uid,$gid,$finger,$dir)=(
   $svc_acct->uid,
   $svc_acct->gid,
   $svc_acct->finger,
@@ -200,12 +208,20 @@ if ( $part_svc->part_svc_column('popnum')->columnflag eq "F" ) {
 print <<END;
 <INPUT TYPE="hidden" NAME="uid" VALUE="$uid">
 <INPUT TYPE="hidden" NAME="gid" VALUE="$gid">
-<TR><TD ALIGN="right">GECOS</TD><TD><INPUT TYPE="text" NAME="finger" VALUE="$finger"></TD></TR>
-<INPUT TYPE="hidden" NAME="dir" VALUE="$dir">
 END
 
-$shell = $svc_acct->shell;
-if ( $part_svc->part_svc_column('shell')->columnflag eq "F" ) {
+if ( !$finger && $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
+  print '<INPUT TYPE="hidden" NAME="finger" VALUE="">';
+} else {
+  print '<TR><TD ALIGN="right">GECOS</TD>'.
+        qq!<TD><INPUT TYPE="text" NAME="finger" VALUE="$finger"></TD></TR>!;
+}
+print qq!<INPUT TYPE="hidden" NAME="dir" VALUE="$dir">!;
+
+my $shell = $svc_acct->shell;
+if ( $part_svc->part_svc_column('shell')->columnflag eq "F"
+     || ( !$shell && $part_svc->part_svc_column('uid')->columnflag eq 'F' )
+   ) {
   print qq!<INPUT TYPE="hidden" NAME="shell" VALUE="$shell">!;
 } else {
   print qq!<TR><TD ALIGN="right">Shell</TD><TD><SELECT NAME="shell" SIZE=1>!;
@@ -217,7 +233,7 @@ if ( $part_svc->part_svc_column('shell')->columnflag eq "F" ) {
   print "</SELECT></TD></TR>";
 }
 
-($quota,$slipip)=(
+my($quota,$slipip)=(
   $svc_acct->quota,
   $svc_acct->slipip,
 );
@@ -242,6 +258,14 @@ foreach my $r ( grep { /^r(adius|[cr])_/ } fields('svc_acct') ) {
   }
 }
 
+print '<TR><TD ALIGN="right">RADIUS groups</TD>';
+if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
+  print '<TD BGCOLOR="#ffffff">'. join('<BR>', @groups);
+} else {
+  print '<TD>'. &FS::svc_acct::radius_usergroup_selector( \@groups );
+}
+print '</TD></TR>';
+
 #submit
 print qq!</TABLE><BR><INPUT TYPE="submit" VALUE="Submit">!;