summaryrefslogtreecommitdiff
path: root/httemplate/edit/svc_acct.cgi
blob: 6846b5c93653857905460a8b1b1257df025a8c7c (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!-- mason kludge -->
<%

my $conf = new FS::Conf;
my @shells = $conf->config('shells');

my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct);
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 } );
      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,
                         );
    }

  }
}
my $action = $svcnum ? 'Edit' : 'Add';

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

my $otaker = getotaker;

my $username = $svc_acct->username;
my $password;
if ( $svc_acct->_password ) {
  if ( $conf->exists('showpasswords') || ! $svcnum ) {
    $password = $svc_acct->_password;
  } else {
    $password = "*HIDDEN*";
  }
} else {
  $password = '';
}

my $ulen = $conf->config('usernamemax')
           || $svc_acct->dbdef_table->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!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
      "</FONT><BR><BR>"
  if $cgi->param('error');

print 'Service # '. ( $svcnum ? "<B>$svcnum</B>" : " (NEW)" ). '<BR>'.
      'Service: <B>'. $part_svc->svc. '</B><BR><BR>'.
      <<END;
    <FORM ACTION="${p1}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">
END

print &ntable("#cccccc",2), <<END;
<TR><TD ALIGN="right">Username</TD>
<TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
<TR><TD ALIGN="right">Password</TD>
<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$pmax>
(blank to generate)</TD>
</TR>
END

#domain
my $domsvc = $svc_acct->domsvc || 0;
if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) {
  print qq!<INPUT TYPE="hidden" NAME="domsvc" VALUE="$domsvc">!;
} 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";
    }
  }

  if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'D' ) {
    my $svc_domain = qsearchs('svc_domain', {
      'svcnum' => $part_svc->part_svc_column('domsvc')->columnvalue,
    } );
    if ( $svc_domain ) {
      $svc_domain{$svc_domain->svcnum} = $svc_domain;
    } else {
      warn "unknown svc_domain.svcnum for part_svc_column domsvc: ".
           $part_svc->part_svc_column('domsvc')->columnvalue;
    }
  }

  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 } );
     $svc_domain{$svc_domain->svcnum} = $svc_domain if $svc_domain;
    }
  } else {
    %svc_domain = map { $_->svcnum => $_ } qsearch('svc_domain', {} );
  }
  print qq!<TR><TD ALIGN="right">Domain</TD>!.
        qq!<TD><SELECT NAME="domsvc" SIZE=1>\n!;
  foreach my $svcnum (
    sort { $svc_domain{$a}->domain cmp $svc_domain{$b}->domain }
      keys %svc_domain
  ) {
    my $svc_domain = $svc_domain{$svcnum};
    print qq!<OPTION VALUE="!. $svc_domain->svcnum. qq!"!.
          ( $svc_domain->svcnum == $domsvc ? ' SELECTED' : '' ).
          '>'. $svc_domain->domain. "\n" ;
  }
  print "</SELECT></TD></TR>";
}

#pop
my $popnum = $svc_acct->popnum || 0;
if ( $part_svc->part_svc_column('popnum')->columnflag eq "F" ) {
  print qq!<INPUT TYPE="hidden" NAME="popnum" VALUE="$popnum">!;
} else { 
  print qq!<TR><TD ALIGN="right">Access number</TD>!.
        qq!<TD>!. FS::svc_acct_pop::popselector($popnum). '</TD></TR>';
}

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">
END

if ( !$finger && $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
  print '<INPUT TYPE="hidden" NAME="finger" VALUE="">';
} else {
  print '<TR><TD ALIGN="right">GECOS</TD>'.
        qq!<TD><INPUT TYPE="text" NAME="finger" VALUE="$finger"></TD></TR>!;
}
print qq!<INPUT TYPE="hidden" NAME="dir" VALUE="$dir">!;

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' )
   ) {
  print qq!<INPUT TYPE="hidden" NAME="shell" VALUE="$shell">!;
} else {
  print qq!<TR><TD ALIGN="right">Shell</TD><TD><SELECT NAME="shell" SIZE=1>!;
  my($etc_shell);
  foreach $etc_shell (@shells) {
    print "<OPTION", $etc_shell eq $shell ? ' SELECTED' : '', ">",
          $etc_shell, "\n";
  }
  print "</SELECT></TD></TR>";
}

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

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

if ( $part_svc->part_svc_column('slipip')->columnflag eq "F" ) {
  print qq!<INPUT TYPE="hidden" NAME="slipip" VALUE="$slipip">!;
} else {
  print qq!<TR><TD ALIGN="right">IP</TD><TD><INPUT TYPE="text" NAME="slipip" VALUE="$slipip"></TD></TR>!;
}

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!<INPUT TYPE="hidden" NAME="$r" VALUE="!.
          $svc_acct->getfield($r). '">';
  } else {
    print qq!<TR><TD ALIGN="right">$FS::raddb::attrib{$a}</TD><TD><INPUT TYPE="text" NAME="$r" VALUE="!.
          $svc_acct->getfield($r). '"></TD></TR>';
  }
}

print '<TR><TD ALIGN="right">RADIUS groups</TD><TD>'.
      &FS::svc_acct::radius_usergroup_selector( [ $svc_acct->radius_groups ] ).
      '</TD></TR>';

#submit
print qq!</TABLE><BR><INPUT TYPE="submit" VALUE="Submit">!; 

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

%>