summaryrefslogtreecommitdiff
path: root/htdocs/edit/svc_acct.cgi
blob: 61d0fdc28f167224933a5298694e6a06bff42a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/perl -Tw
#
# svc_acct.cgi: Add/edit account (output form)
#
# Usage: svc_acct.cgi {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
#        http://server.name/path/svc_acct.cgi? {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
#
# Note: Should be run setuid freeside as user nobody
#
# 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

use strict;
use CGI::Base qw(:DEFAULT :CGI);
use FS::UID qw(cgisuidsetup getotaker);
use FS::Record qw(qsearch qsearchs);
use FS::svc_acct qw(fields);

my($shells)="/var/spool/freeside/conf/shells";
open(SHELLS,$shells) or die "Can't open $shells: $!";
my(@shells)=map {
  /^([\/\w]*)$/ or die "Illegal shell in conf/shells!";
  $1;
} grep $_ !~ /^#/, <SHELLS>;

my($cgi) = new CGI::Base;
$cgi->get;
&cgisuidsetup($cgi);

my($action,$svcnum,$svc_acct,$pkgnum,$svcpart,$part_svc);

if ( $QUERY_STRING =~ /^(\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;

  $action="Edit";

} else { #adding

  $svc_acct=create FS::svc_acct({}); 

  foreach $_ (split(/-/,$QUERY_STRING)) {
    $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="Add";

}

my($svc)=$part_svc->getfield('svc');

my($otaker)=getotaker;

my($username,$password)=(
  $svc_acct->username,
  $svc_acct->_password ? "*HIDDEN*" : '',
);

my($ulen)=$svc_acct->dbdef_table->column('username')->length;
my($ulen2)=$ulen+2;

SendHeaders();
print <<END;
<HTML>
  <HEAD>
    <TITLE>$action $svc account</TITLE>
  </HEAD>
  <BODY>
    <CENTER>
    <H1>$action $svc account</H1>
    </CENTER><HR>
    <FORM ACTION="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">
Username: 
<INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen>
<BR>Password: 
<INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=10 MAXLENGTH=8> 
(blank to generate)
END

#pop
my($popnum)=$svc_acct->popnum || 0;
if ( $part_svc->svc_acct__popnum_flag eq "F" ) {
  print qq!<INPUT TYPE="hidden" NAME="popnum" VALUE="$popnum">!;
} else { 
  print qq!<BR>POP: <SELECT NAME="popnum" SIZE=1><OPTION>\n!;
  my($svc_acct_pop);
  foreach $svc_acct_pop ( qsearch ('svc_acct_pop',{} ) ) {
  print "<OPTION", $svc_acct_pop->popnum == $popnum ? ' SELECTED' : '', ">", 
        $svc_acct_pop->popnum, ": ", 
        $svc_acct_pop->city, ", ",
        $svc_acct_pop->state,
        "(", $svc_acct_pop->ac, ")/",
        $svc_acct_pop->exch, "\n"
      ;
  }
  print "</SELECT>";
}

my($uid,$gid,$finger,$dir)=(
  $svc_acct->uid,
  $svc_acct->gid,
  $svc_acct->finger,
  $svc_acct->dir,
);

print <<END;
<INPUT TYPE="hidden" NAME="uid" VALUE="$uid">
<INPUT TYPE="hidden" NAME="gid" VALUE="$gid">
<BR>GECOS: <INPUT TYPE="text" NAME="finger" VALUE="$finger">
<INPUT TYPE="hidden" NAME="dir" VALUE="$dir">
END

my($shell)=$svc_acct->shell;
if ( $part_svc->svc_acct__shell_flag eq "F" ) {
  print qq!<INPUT TYPE="hidden" NAME="shell" VALUE="$shell">!;
} else {
  print qq!<BR>Shell: <SELECT NAME="shell" SIZE=1>!;
  my($etc_shell);
  foreach $etc_shell (@shells) {
    print "<OPTION", $etc_shell eq $shell ? ' SELECTED' : '', ">",
          $etc_shell, "\n";
  }
  print "</SELECT>";
}

my($quota,$slipip)=(
  $svc_acct->quota,
  $svc_acct->slipip,
);

print qq!<INPUT TYPE="hidden" NAME="quota" VALUE="$quota">!;

if ( $part_svc->svc_acct__slipip_flag eq "F" ) {
  print qq!<INPUT TYPE="hidden" NAME="slipip" VALUE="$slipip">!;
} else {
  print qq!<BR>IP: <INPUT TYPE="text" NAME="slipip" VALUE="$slipip">!;
}

#submit
print qq!<P><CENTER><INPUT TYPE="submit" VALUE="Submit"></CENTER>!; 

print <<END;
    </FORM>
  </BODY>
</HTML>
END