added user interface for svc_forward and vpopmail support
[freeside.git] / httemplate / edit / svc_acct.cgi
1 <%
2 #
3 # $Id: svc_acct.cgi,v 1.2 2001-08-19 15:53:35 jeff Exp $
4 #
5 # Usage: svc_acct.cgi {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
6 #        http://server.name/path/svc_acct.cgi? {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
7 #
8 # ivan@voicenet.com 96-dec-18
9 #
10 # rewrite ivan@sisd.com 98-mar-8
11 #
12 # Changes to allow page to work at a relative position in server
13 # Changed 'password' to '_password' because Pg6.3 reserves the password word
14 #       bmccane@maxbaud.net     98-apr-3
15 #
16 # use conf/shells and dbdef username length ivan@sisd.com 98-jul-13
17 #
18 # $Log: svc_acct.cgi,v $
19 # Revision 1.2  2001-08-19 15:53:35  jeff
20 # added user interface for svc_forward and vpopmail support
21 #
22 # Revision 1.1  2001/07/30 07:36:04  ivan
23 # templates!!!
24 #
25 # Revision 1.10  1999/04/14 11:27:06  ivan
26 # showpasswords config option to show passwords
27 #
28 # Revision 1.9  1999/02/28 00:03:37  ivan
29 # removed misleading comments
30 #
31 # Revision 1.8  1999/02/23 08:09:22  ivan
32 # beginnings of one-screen new customer entry and some other miscellania
33 #
34 # Revision 1.7  1999/02/07 09:59:22  ivan
35 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
36 #
37 # Revision 1.6  1999/01/19 05:13:43  ivan
38 # for mod_perl: no more top-level my() variables; use vars instead
39 # also the last s/create/new/;
40 #
41 # Revision 1.5  1999/01/18 09:41:32  ivan
42 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
43 # (good idea anyway)
44 #
45 # Revision 1.4  1998/12/30 23:03:22  ivan
46 # bugfixes; fields isn't exported by derived classes
47 #
48 # Revision 1.3  1998/12/17 06:17:08  ivan
49 # fix double // in relative URLs, s/CGI::Base/CGI/;
50 #
51
52 use strict;
53 use vars qw( $conf $cgi @shells $action $svcnum $svc_acct $pkgnum $svcpart
54              $part_svc $svc $otaker $username $password $ulen $ulen2 $p1
55              $popnum $domsvc $uid $gid $finger $dir $shell $quota $slipip );
56 use CGI;
57 use CGI::Carp qw(fatalsToBrowser);
58 use FS::UID qw(cgisuidsetup getotaker);
59 use FS::CGI qw(header popurl);
60 use FS::Record qw(qsearch qsearchs fields);
61 use FS::svc_acct;
62 use FS::Conf;
63
64 $cgi = new CGI;
65 &cgisuidsetup($cgi);
66
67 $conf = new FS::Conf;
68 @shells = $conf->config('shells');
69
70 if ( $cgi->param('error') ) {
71   $svc_acct = new FS::svc_acct ( {
72     map { $_, scalar($cgi->param($_)) } fields('svc_acct')
73   } );
74   $svcnum = $svc_acct->svcnum;
75   $pkgnum = $cgi->param('pkgnum');
76   $svcpart = $cgi->param('svcpart');
77   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
78   die "No part_svc entry!" unless $part_svc;
79 } else {
80   my($query) = $cgi->keywords;
81   if ( $query =~ /^(\d+)$/ ) { #editing
82     $svcnum=$1;
83     $svc_acct=qsearchs('svc_acct',{'svcnum'=>$svcnum})
84       or die "Unknown (svc_acct) svcnum!";
85
86     my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
87       or die "Unknown (cust_svc) svcnum!";
88
89     $pkgnum=$cust_svc->pkgnum;
90     $svcpart=$cust_svc->svcpart;
91
92     $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
93     die "No part_svc entry!" unless $part_svc;
94
95   } else { #adding
96
97     $svc_acct = new FS::svc_acct({}); 
98
99     foreach $_ (split(/-/,$query)) {
100       $pkgnum=$1 if /^pkgnum(\d+)$/;
101       $svcpart=$1 if /^svcpart(\d+)$/;
102     }
103     $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
104     die "No part_svc entry!" unless $part_svc;
105
106     $svcnum='';
107
108     #set gecos
109     my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
110     if ($cust_pkg) {
111       my($cust_main)=qsearchs('cust_main',{'custnum'=> $cust_pkg->custnum } );
112       $svc_acct->setfield('finger',
113         $cust_main->getfield('first') . " " . $cust_main->getfield('last')
114       ) ;
115     }
116
117     #set fixed and default fields from part_svc
118     my($field);
119     foreach $field ( fields('svc_acct') ) {
120       if ( $part_svc->getfield('svc_acct__'. $field. '_flag') ne '' ) {
121         $svc_acct->setfield($field,$part_svc->getfield('svc_acct__'. $field) );
122       }
123     }
124
125   }
126 }
127 $action = $svcnum ? 'Edit' : 'Add';
128
129 $svc = $part_svc->getfield('svc');
130
131 $otaker = getotaker;
132
133 $username = $svc_acct->username;
134 if ( $svc_acct->_password ) {
135   if ( $conf->exists('showpasswords') ) {
136     $password = $svc_acct->_password;
137   } else {
138     $password = "*HIDDEN*";
139   }
140 } else {
141   $password = '';
142 }
143
144 $ulen = $svc_acct->dbdef_table->column('username')->length;
145 $ulen2 = $ulen+2;
146
147 $p1 = popurl(1);
148 print $cgi->header( '-expires' => 'now' ), header("$action $svc account");
149
150 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
151       "</FONT>"
152   if $cgi->param('error');
153
154 print <<END;
155     <FORM ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
156       <INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">
157       <INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">
158       <INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">
159 Username: 
160 <INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen>
161 <BR>Password: 
162 <INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=10 MAXLENGTH=8> 
163 (blank to generate)
164 END
165
166 #domain
167 $domsvc = $svc_acct->domsvc || 0;
168 if ( $part_svc->svc_acct__domsvc_flag eq "F" ) {
169   print qq!<INPUT TYPE="hidden" NAME="domsvc" VALUE="$domsvc">!;
170 } else { 
171   print qq!<BR>Domain: <SELECT NAME="domsvc" SIZE=1>\n!;
172   my($svc_domain);
173   foreach $svc_domain
174     ( sort {$a->domain cmp $b->domain} (qsearch ('svc_domain',{} ) ) ) 
175   {
176     print qq!<OPTION VALUE="!, $svc_domain->svcnum, qq!"!,
177           $svc_domain->svcnum == $domsvc ? ' SELECTED' : '',
178           ">", $svc_domain->domain, "\n"
179       ;
180   }
181   print "</SELECT>";
182 }
183
184 #pop
185 $popnum = $svc_acct->popnum || 0;
186 if ( $part_svc->svc_acct__popnum_flag eq "F" ) {
187   print qq!<INPUT TYPE="hidden" NAME="popnum" VALUE="$popnum">!;
188 } else { 
189   print qq!<BR>POP: <SELECT NAME="popnum" SIZE=1><OPTION>\n!;
190   my($svc_acct_pop);
191   foreach $svc_acct_pop ( qsearch ('svc_acct_pop',{} ) ) {
192   print "<OPTION", $svc_acct_pop->popnum == $popnum ? ' SELECTED' : '', ">", 
193         $svc_acct_pop->popnum, ": ", 
194         $svc_acct_pop->city, ", ",
195         $svc_acct_pop->state,
196         " (", $svc_acct_pop->ac, ")/",
197         $svc_acct_pop->exch, "\n"
198       ;
199   }
200   print "</SELECT>";
201 }
202
203 ($uid,$gid,$finger,$dir)=(
204   $svc_acct->uid,
205   $svc_acct->gid,
206   $svc_acct->finger,
207   $svc_acct->dir,
208 );
209
210 print <<END;
211 <INPUT TYPE="hidden" NAME="uid" VALUE="$uid">
212 <INPUT TYPE="hidden" NAME="gid" VALUE="$gid">
213 <BR>GECOS: <INPUT TYPE="text" NAME="finger" VALUE="$finger">
214 <INPUT TYPE="hidden" NAME="dir" VALUE="$dir">
215 END
216
217 $shell = $svc_acct->shell;
218 if ( $part_svc->svc_acct__shell_flag eq "F" ) {
219   print qq!<INPUT TYPE="hidden" NAME="shell" VALUE="$shell">!;
220 } else {
221   print qq!<BR>Shell: <SELECT NAME="shell" SIZE=1>!;
222   my($etc_shell);
223   foreach $etc_shell (@shells) {
224     print "<OPTION", $etc_shell eq $shell ? ' SELECTED' : '', ">",
225           $etc_shell, "\n";
226   }
227   print "</SELECT>";
228 }
229
230 ($quota,$slipip)=(
231   $svc_acct->quota,
232   $svc_acct->slipip,
233 );
234
235 print qq!<INPUT TYPE="hidden" NAME="quota" VALUE="$quota">!;
236
237 if ( $part_svc->svc_acct__slipip_flag eq "F" ) {
238   print qq!<INPUT TYPE="hidden" NAME="slipip" VALUE="$slipip">!;
239 } else {
240   print qq!<BR>IP: <INPUT TYPE="text" NAME="slipip" VALUE="$slipip">!;
241 }
242
243 #submit
244 print qq!<P><INPUT TYPE="submit" VALUE="Submit">!; 
245
246 print <<END;
247     </FORM>
248   </BODY>
249 </HTML>
250 END
251
252
253 %>