X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fsvc_acct.cgi;h=e6cd7d86c750c024d9bd2f04902e5420dd452bda;hb=dd65ba99bb9281571f19744154a3b03bcd3f01ab;hp=7badfe6966e0d0efdf94faf06e9daebd1c26a50c;hpb=51984ac3d3da3006809c6866fdecd4ad83610731;p=freeside.git diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 7badfe696..e6cd7d86c 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -1,232 +1,490 @@ -<% -# -# $Id: svc_acct.cgi,v 1.1 2001-07-30 07:36:04 ivan Exp $ -# -# Usage: svc_acct.cgi {svcnum} | pkgnum{pkgnum}-svcpart{svcpart} -# http://server.name/path/svc_acct.cgi? {svcnum} | pkgnum{pkgnum}-svcpart{svcpart} -# -# ivan@voicenet.com 96-dec-18 -# -# rewrite ivan@sisd.com 98-mar-8 -# -# Changes to allow page to work at a relative position in server -# Changed 'password' to '_password' because Pg6.3 reserves the password word -# bmccane@maxbaud.net 98-apr-3 -# -# use conf/shells and dbdef username length ivan@sisd.com 98-jul-13 -# -# $Log: svc_acct.cgi,v $ -# Revision 1.1 2001-07-30 07:36:04 ivan -# templates!!! -# -# Revision 1.10 1999/04/14 11:27:06 ivan -# showpasswords config option to show passwords -# -# Revision 1.9 1999/02/28 00:03:37 ivan -# removed misleading comments -# -# Revision 1.8 1999/02/23 08:09:22 ivan -# beginnings of one-screen new customer entry and some other miscellania -# -# Revision 1.7 1999/02/07 09:59:22 ivan -# more mod_perl fixes, and bugfixes Peter Wemm sent via email -# -# Revision 1.6 1999/01/19 05:13:43 ivan -# for mod_perl: no more top-level my() variables; use vars instead -# also the last s/create/new/; -# -# Revision 1.5 1999/01/18 09:41:32 ivan -# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl -# (good idea anyway) -# -# Revision 1.4 1998/12/30 23:03:22 ivan -# bugfixes; fields isn't exported by derived classes -# -# Revision 1.3 1998/12/17 06:17:08 ivan -# fix double // in relative URLs, s/CGI::Base/CGI/; -# - -use strict; -use vars qw( $conf $cgi @shells $action $svcnum $svc_acct $pkgnum $svcpart - $part_svc $svc $otaker $username $password $ulen $ulen2 $p1 - $popnum $uid $gid $finger $dir $shell $quota $slipip ); -use CGI; -use CGI::Carp qw(fatalsToBrowser); -use FS::UID qw(cgisuidsetup getotaker); -use FS::CGI qw(header popurl); -use FS::Record qw(qsearch qsearchs fields); -use FS::svc_acct; -use FS::Conf; - -$cgi = new CGI; -&cgisuidsetup($cgi); - -$conf = new FS::Conf; -@shells = $conf->config('shells'); +<& /elements/header.html, mt("$action [_1] account",$svc) &> +<& /elements/error.html &> + +% if ( $cust_main ) { + + <& /elements/small_custview.html, $cust_main, '', 1, + popurl(2) . "view/cust_main.cgi" &> +
+% } + + + +
+ + + + +% if ( $svcnum ) { +% my $svclabel = emt("Service #[_1]",$svcnum); +% $svclabel =~ s/$svcnum/$svcnum<\/B>/; +<% $svclabel %> +% } else { +<% mt("Service # (NEW)") |h %> +% } +
+ +<% ntable("#cccccc",2) %> + + + <% mt('Service') |h %> + <% $part_svc->svc %> + + + + <% mt('Username') |h %> + + MAXLENGTH=<% $ulen %>> + + + +%if ( $part_svc->part_svc_column('_password')->columnflag ne 'F' ) { + + <% mt('Password') |h %> + + MAXLENGTH=<% $pmax %>> + + + +%}else{ + +%} + +% +%my $sec_phrase = $svc_acct->sec_phrase; +%if ( $conf->exists('security_phrase') +% && $part_svc->part_svc_column('sec_phrase')->columnflag ne 'F' ) { + + + <% mt('Security phrase') |h %> + + + (<% mt('for forgotten passwords') |h %>) + + +% } else { + + +% } +% +%#domain +%my $domsvc = $svc_acct->domsvc || 0; +%if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) { +% + + +% } else { +% +% my %svc_domain = (); +% +% if ( $domsvc ) { +% my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $domsvc, } ); +% if ( $svc_domain ) { +% $svc_domain{$svc_domain->svcnum} = $svc_domain; +% } else { +% warn "unknown svc_domain.svcnum for svc_acct.domsvc: $domsvc"; +% } +% } +% +% %svc_domain = (%svc_domain, +% domain_select_hash FS::svc_acct('svcpart' => $svcpart, +% 'pkgnum' => $pkgnum, +% ) +% ); + + + <% mt('Domain') |h %> + + + + +% } + + +% if ( $communigate ) { + + + <% mt('Aliases') |h %> + + + +% } else { + +% } + + +<& /elements/tr-select-svc_pbx.html, + 'curr_value' => $svc_acct->pbxsvc, + 'part_svc' => $part_svc, + 'cust_pkg' => $cust_pkg, +&> + +%#pop +%my $popnum = $svc_acct->popnum || 0; +%if ( $part_svc->part_svc_column('popnum')->columnflag eq 'F' ) { +% + + +% } else { + + + <% mt('Access number') |h %> + <% 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) %> + + + + +% } +% } +% +%#finger +%if ( $part_svc->part_svc_column('uid')->columnflag eq 'F' +% && ! $svc_acct->finger ) { +% + + +% } else { + + + + <% mt('Real Name') |h %> + + + + +% } +% +%#dir +%if ( $part_svc->part_svc_column('dir')->columnflag eq 'F' +% || !$curuser->access_right('Edit home dir') +% ) { + + + +% } else { + + + + <% mt('Home directory') |h %> + + +% } +% +%#shell +%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' ) +% ) { +% + + +% } else { + + + + <% mt('Shell') |h %> + + + + +% } + +<& svc_acct/communigate.html, + 'svc_acct' => $svc_acct, + 'part_svc' => $part_svc, + 'communigate' => $communigate, +&> + +% if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { + +% } else { + + <% mt('IP') |h %> + + +% } + +% my %label = ( seconds => 'Time', +% upbytes => 'Upload bytes', +% downbytes => 'Download bytes', +% totalbytes => 'Total bytes', +% ); +% foreach my $uf (keys %label) { +% my $tf = $uf . "_threshold"; +% if ( $curuser->access_right('Edit usage') ) { + + <% mt("[_1] remaining",$label{$uf}) |h %> + (<% mt('blank disables') |h %>) + + + <% mt("[_1] threshold",$label{$uf}) |h %> + (<% mt('blank disables') |h %>) + +% }else{ + + +% } +% } +% +%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 =~ /^[FA]$/ ) { + + +% } else { + + + <% $FS::raddb::attrib{$a} %> + + +% } +% } + + + + <% mt('RADIUS groups') |h %> +% 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)) %> +% } +% } + + +
+ +% if ( $captcha_url ) { +
+<% mt('Enter the word shown above:') |h %>
+
+% } + + + + + +<& /elements/footer.html &> + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific? + +my $conf = new FS::Conf; +my @shells = $conf->config('shells'); + +my $curuser = $FS::CurrentUser::CurrentUser; + +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 for svcpart $svcpart!" unless $part_svc; + @groups = $cgi->param('radius_usergroup'); + +} elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding + + $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; + $pkgnum = $1; + $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; + $svcpart = $1; + $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); die "No part_svc entry!" unless $part_svc; -} else { + + $svc_acct = new FS::svc_acct({svcpart => $svcpart}); + + $svcnum=''; + + $svc_acct->password_recover('Y'); #default. hmm. + +} else { #editing + my($query) = $cgi->keywords; - if ( $query =~ /^(\d+)$/ ) { #editing - $svcnum=$1; - $svc_acct=qsearchs('svc_acct',{'svcnum'=>$svcnum}) - or die "Unknown (svc_acct) svcnum!"; + $query =~ /^(\d+)$/ or die "unparsable svcnum"; + $svcnum=$1; + $svc_acct=qsearchs('svc_acct',{'svcnum'=>$svcnum}) + or die "Unknown (svc_acct) svcnum!"; - my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum}) - or die "Unknown (cust_svc) svcnum!"; + my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum}) + or die "Unknown (cust_svc) svcnum!"; - $pkgnum=$cust_svc->pkgnum; - $svcpart=$cust_svc->svcpart; + $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({}); +} - 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; +my $communigate = scalar($part_svc->part_export('communigate_pro')); + # || scalar($part_svc->part_export('communigate_pro_singledomain')); + +my( $cust_pkg, $cust_main ) = ( '', '' ); +if ( $pkgnum ) { + $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum } ); + $cust_main = $cust_pkg->cust_main; +} - $svcnum=''; +unless ( $svcnum || $cgi->param('error') ) { #adding - #set gecos - my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); - if ($cust_pkg) { - my($cust_main)=qsearchs('cust_main',{'custnum'=> $cust_pkg->custnum } ); + #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 - my($field); - foreach $field ( fields('svc_acct') ) { - if ( $part_svc->getfield('svc_acct__'. $field. '_flag') ne '' ) { - $svc_acct->setfield($field,$part_svc->getfield('svc_acct__'. $field) ); - } - } + $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 = (); + []; + } + } + } ); - } } -$action = $svcnum ? 'Edit' : 'Add'; -$svc = $part_svc->getfield('svc'); +#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); +} -$otaker = getotaker; +my $action = $svcnum ? 'Edit' : 'Add'; -$username = $svc_acct->username; -if ( $svc_acct->_password ) { - if ( $conf->exists('showpasswords') ) { - $password = $svc_acct->_password; - } else { - $password = "*HIDDEN*"; - } -} else { - $password = ''; -} +my $svc = $part_svc->getfield('svc'); -$ulen = $svc_acct->dbdef_table->column('username')->length; -$ulen2 = $ulen+2; - -$p1 = popurl(1); -print $cgi->header( '-expires' => 'now' ), header("$action $svc account"); - -print qq!Error: !, $cgi->param('error'), - "" - if $cgi->param('error'); - -print < - - - -Username: - -
Password: - -(blank to generate) -END - -#pop -$popnum = $svc_acct->popnum || 0; -if ( $part_svc->svc_acct__popnum_flag eq "F" ) { - print qq!!; -} else { - print qq!
POP: "; -} +my $otaker = getotaker; -($uid,$gid,$finger,$dir)=( - $svc_acct->uid, - $svc_acct->gid, - $svc_acct->finger, - $svc_acct->dir, -); - -print < - -
GECOS: - -END - -$shell = $svc_acct->shell; -if ( $part_svc->svc_acct__shell_flag eq "F" ) { - print qq!!; -} else { - print qq!
Shell: "; } -($quota,$slipip)=( - $svc_acct->quota, - $svc_acct->slipip, -); +my $ulen = + $conf->exists('usernamemax') + ? $conf->config('usernamemax') + : dbdef->table('svc_acct')->column('username')->length; +my $ulen2 = $ulen+2; -print qq!!; - -if ( $part_svc->svc_acct__slipip_flag eq "F" ) { - print qq!!; -} else { - print qq!
IP: !; -} +my $pmax = max($conf->config('passwordmax') || 13); +my $pmax2 = $pmax+2; -#submit -print qq!

!; +my $p1 = popurl(1); -print < - - -END +sub max { + (sort(@_))[-1] +} +my $captcha_url; +my ($export_google) = $part_svc->part_export('acct_google'); +if ( $export_google ) { + my $error = $export_google->auth_error; + if ( $error ) { + if ( $error->{'captcha_url'} ) { + $captcha_url = $error->{'captcha_url'}; + } + else { + $cgi->param('error', $error->{'message'}); + } + } #if $error +} -%> +