%
#
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);
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');
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;
} else {
my($query) = $cgi->keywords;
if ( $query =~ /^(\d+)$/ ) { #editing
$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!";
$pkgnum=$cust_svc->pkgnum;
$svcpart=$cust_svc->svcpart;
$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
die "No part_svc entry!" unless $part_svc;
} else { #adding
$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;
$svcnum='';
#set gecos
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')
) ;
}
#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) );
}
}
}
}
$action = $svcnum ? 'Edit' : 'Add';
$svc = $part_svc->getfield('svc');
$otaker = getotaker;
$username = $svc_acct->username;
if ( $svc_acct->_password ) {
if ( $conf->exists('showpasswords') ) {
$password = $svc_acct->_password;
} else {
$password = "*HIDDEN*";
}
} else {
$password = '';
}
$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
#domain
$domsvc = $svc_acct->domsvc || 0;
if ( $part_svc->svc_acct__domsvc_flag eq "F" ) {
print qq!!;
} else {
my @svc_domain = ();
my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum } );
if ($cust_pkg) {
my @cust_svc =
map { qsearch('cust_svc', { 'pkgnum' => $_->pkgnum } ) }
qsearch('cust_pkg', { 'custnum' => $cust_pkg->custnum } );
foreach my $cust_svc ( @cust_svc ) {
my $svc_domain =
qsearchs('svc_domain', { 'svcnum' => $cust_svc->svcnum } );
push @svc_domain, $svc_domain if $svc_domain;
}
} else {
@svc_domain = qsearch('svc_domain', {} );
}
print qq!
Domain: ";
}
#pop
$popnum = $svc_acct->popnum || 0;
if ( $part_svc->svc_acct__popnum_flag eq "F" ) {
print qq!!;
} else {
print qq!
POP: ";
}
($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,
);
print qq!!;
if ( $part_svc->svc_acct__slipip_flag eq "F" ) {
print qq!!;
} else {
print qq!
IP: !;
}
#submit
print qq!!;
print <