X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fsvc_acct.cgi;h=14d6759dc87a6c897f209e1b20fa9ab3a564b8cd;hb=08dc9fe500cf44346e409fb8c75eda541300d64d;hp=681d8b5d9adb2eb67527d27be1b590d1ce6f8e36;hpb=1fd6d8cf5d7854860ef4fd10ed89828e0c04ec39;p=freeside.git diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 681d8b5d9..14d6759dc 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -1,20 +1,23 @@ - <% my $conf = new FS::Conf; my @shells = $conf->config('shells'); -my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct); +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') } ); $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 $svcnum=$1; @@ -27,42 +30,68 @@ 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; - } else { #adding + @groups = $svc_acct->radius_groups; - $svc_acct = new FS::svc_acct({}); + } else { #adding foreach $_ (split(/-/,$query)) { $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; + + $svc_acct = new FS::svc_acct({svcpart => $svcpart}); $svcnum=''; - #set gecos - my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); - if ($cust_pkg) { - my($cust_main)=qsearchs('cust_main',{'custnum'=> $cust_pkg->custnum } ); + } +} + +my( $cust_pkg, $cust_main ) = ( '', '' ); +if ( $pkgnum ) { + $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum } ); + $cust_main = $cust_pkg->cust_main; +} + +unless ( $svcnum || $cgi->param('error') ) { #adding + + #set gecos + if ($cust_main) { + 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, - ); + $svc_acct->set_default_and_fixed( { + #false laziness w/svc-acct::_fieldhandlers + 'usergroup' => sub { + my( $self, $groups ) = @_; + if ( ref($groups) eq 'ARRAY' ) { + @groups = @$groups; + $groups; + } elsif ( length($groups) ) { + @groups = split(/\s*,\s*/, $groups); + [ @groups ]; + } else { + @groups = (); + []; + } } + ); - } } + +#fixed radius groups always override & display +if ( $part_svc->part_svc_column('usergroup')->columnflag eq 'F' ) { + @groups = split(',', $part_svc->part_svc_column('usergroup')->columnvalue); +} + my $action = $svcnum ? 'Edit' : 'Add'; my $svc = $part_svc->getfield('svc'); @@ -72,7 +101,7 @@ my $otaker = getotaker; 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*"; @@ -81,43 +110,91 @@ if ( $svc_acct->_password ) { $password = ''; } -my $ulen = $svc_acct->dbdef_table->column('username')->length; +my $ulen = + $conf->exists('usernamemax') + ? $conf->config('usernamemax') + : dbdef->table('svc_acct')->column('username')->length; my $ulen2 = $ulen+2; my $pmax = $conf->config('passwordmax') || 8; my $pmax2 = $pmax+2; my $p1 = popurl(1); -print header("$action $svc account"); - -print qq!Error: !, $cgi->param('error'), - "

" - if $cgi->param('error'); - -print 'Service # '. ( $svcnum ? "$svcnum" : " (NEW)" ). '
'. - 'Service: '. $part_svc->svc. '

'. - < - - - -END - -print &itable("#cccccc",2), < -Username - -Password - -(blank to generate) + +%> + +<%= include("/elements/header.html","$action $svc account") %> + +<% if ( $cgi->param('error') ) { %> + Error: <%= $cgi->param('error') %> +

+<% } %> + +<% if ( $cust_main ) { %> + <%= include( '/elements/small_custview.html', $cust_main, '', 1 ) %> +
+<% } %> + +
+ + + + +Service # <%= $svcnum ? "$svcnum" : " (NEW)" %>
+ +<%= ntable("#cccccc",2) %> + + + Service + <%= $part_svc->svc %> + + + + Username + + MAXLENGTH=<%= $ulen %>> + + + + + Password + + MAXLENGTH=<%= $pmax %>> + (blank to generate) + -END + +<% +my $sec_phrase = $svc_acct->sec_phrase; +if ( $conf->exists('security_phrase') ) { +%> + + + Security phrase + + + (for forgotten passwords) + + + +<% } else { %> + + + +<% } %> + + +<% #domain my $domsvc = $svc_acct->domsvc || 0; if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) { - print qq!!; -} else { +%> + + + +<% } else { + my %svc_domain = (); if ( $domsvc ) { @@ -141,8 +218,7 @@ if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) { } } - my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum } ); - if ($cust_pkg) { + if ($cust_pkg && !$conf->exists('svc_acct-alldomains') ) { my @cust_svc = map { qsearch('cust_svc', { 'pkgnum' => $_->pkgnum } ) } qsearch('cust_pkg', { 'custnum' => $cust_pkg->custnum } ); @@ -154,88 +230,221 @@ if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) { } else { %svc_domain = map { $_->svcnum => $_ } qsearch('svc_domain', {} ); } - print qq!Domain!. - qq!"; -} +%> + + + Domain + + + + + +<% } %> + + +<% #pop my $popnum = $svc_acct->popnum || 0; -if ( $part_svc->part_svc_column('popnum')->columnflag eq "F" ) { - print qq!!; -} else { - print qq!Access number!. - qq!!. FS::svc_acct_pop::popselector($popnum). ''; -} +if ( $part_svc->part_svc_column('popnum')->columnflag eq 'F' ) { +%> + + + + +<% } else { %> + + + Access number + <%= FS::svc_acct_pop::popselector($popnum) %> + + +<% } %> + + +<% #uid/gid %> +<% foreach my $xid (qw( uid gid )) { %> + + <% + if ( $part_svc->part_svc_column($xid)->columnflag =~ /^[FA]$/ + || ! $conf->exists("svc_acct-edit_$xid") + ) { + %> + + <% if ( length($svc_acct->$xid()) ) { %> + + + <%= uc($xid) %> + <%= $svc_acct->$xid() %> + + + + + <% } %> + + + + <% } else { %> + + + <%= uc($xid) %> + + + + + + <% } %> + +<% } %> -my($uid,$gid,$finger,$dir)=( - $svc_acct->uid, - $svc_acct->gid, - $svc_acct->finger, - $svc_acct->dir, -); -print < - -GECOS - -END +<% +#finger +if ( $part_svc->part_svc_column('uid')->columnflag eq 'F' + && ! $svc_acct->finger ) { +%> + + + +<% } else { %> + + + GECOS + + + + + +<% } %> + + + + +<% +#shell my $shell = $svc_acct->shell; -if ( $part_svc->part_svc_column('shell')->columnflag eq "F" ) { - print qq!!; -} else { - print qq!Shell"; -} +if ( $part_svc->part_svc_column('shell')->columnflag eq 'F' + || ( !$shell && $part_svc->part_svc_column('uid')->columnflag eq 'F' ) + ) { +%> -my($quota,$slipip)=( - $svc_acct->quota, - $svc_acct->slipip, -); + -print qq!!; +<% } else { %> -if ( $part_svc->part_svc_column('slipip')->columnflag eq "F" ) { - print qq!!; -} else { - print qq!IP!; -} + + Shell + + + + + +<% } %> + + +<% if ( $part_svc->part_svc_column('quota')->columnflag eq 'F' ) { %> + + + +<% } else { %> + + + Quota: + + + +<% } %> + + +<% if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { %> + + +<% } else { %> + + + IP + + + +<% } %> + + +<% foreach my $r ( grep { /^r(adius|[cr])_/ } fields('svc_acct') ) { $r =~ /^^r(adius|[cr])_(.+)$/ or next; #? my $a = $2; - if ( $part_svc->part_svc_column($r)->columnflag eq 'F' ) { - print qq!'; - } else { - print qq!$FS::raddb::attrib{$a}'; - } -} +%> -#submit -print qq!
!; + <% if ( $part_svc->part_svc_column($r)->columnflag =~ /^[FA]$/ ) { %> -print < - - -END + -%> + <% } else { %> + + + <%= $FS::raddb::attrib{$a} %> + + + + <% } %> + +<% } %> + + + + RADIUS groups + + <% if ( $part_svc->part_svc_column('usergroup')->columnflag eq 'F' ) { %> + + <%= join('
', @groups) %> + + <% } else { %> + + <%= FS::svc_acct::radius_usergroup_selector( \@groups ) %> + + <% } %> + + + +<% foreach my $field ($svc_acct->virtual_fields) { %> + + <% # If the flag is X, it won't even show up in $svc_acct->virtual_fields. %> + <% if ( $part_svc->part_svc_column($field)->columnflag ne 'F' ) { %> + + <%= $svc_acct->pvf($field)->widget('HTML', 'edit', $svc_acct->getfield($field)) %> + + <% } %> + +<% } %> + + +
+ + + +