summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/svc_cert.cgi
blob: 0e6037e3137ed74e549fdaf2566466fbbc996b34 (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
%if ( $popup ) {
%  if ( $error ) { #should redirect back to the posting page?
<% include("/elements/header-popup.html", "Error") %>
<P><FONT SIZE="+1" COLOR="#ff0000"><% $error |h %></FONT>
<BR><BR>
<P ALIGN="center">
<BUTTON TYPE="button" onClick="parent.cClick();">Close</BUTTON>
</BODY></HTML>
%  } else {
<% include('/elements/header-popup.html', $title ) %>
    <SCRIPT TYPE="text/javascript">
      window.top.location = '<% popurl(3). "$popup/svc_cert.cgi?$svcnum" %>';
    </SCRIPT>
    </BODY></HTML>
%  }
%} elsif ( $error ) {
%  $cgi->param('error', $error);
<% $cgi->redirect(popurl(2). "svc_cert.cgi?". $cgi->query_string ) %>
%} else {
<% $cgi->redirect(popurl(3). "view/svc_cert.cgi?$svcnum") %>
% }
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?

$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
my $svcnum = $1;

my $new = new FS::svc_cert ( {
  map {
    $_, scalar($cgi->param($_));
  } ( fields('svc_cert'), qw( pkgnum svcpart ) )
} );

my $old = '';
if ( $svcnum ) {
  $old = qsearchs('svc_cert', { 'svcnum' => $svcnum } ) #agent virt;
    or die 'unknown svcnum';
  $new->$_( $old->$_ ) for grep $old->$_, qw( privatekey csr certificate cacert );
}

my $popup = '';
my $title = '';
if ( $cgi->param('privatekey') eq '_generate' ) { #generate
  $popup = 'edit';
  $title = 'Key generated';

  $cgi->param('keysize') =~ /^(\d+)$/ or die 'illegal keysize';
  my $keysize = $1;
  $new->generate_privatekey($keysize);

} elsif ( $cgi->param('privatekey') =~ /\S/ ) { #import
  $popup = 'edit';
  $title = 'Key imported';

  $new->privatekey( $cgi->param('privatekey') );

#} #elsif ( $cgi->param('privatekey') eq '_clear' ) { #clear

} elsif ( $cgi->param('certificate') ) {

  $popup = 'view';
  $title = 'Certificate imported';

  $new->certificate( $cgi->param('certificate') );
  $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );

} elsif ( $cgi->param('cacert') ) {

  $popup = 'view';
  $title = 'Certificate authority chain imported';

  $new->cacert( $cgi->param('cacert') );
  $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );

}

my $error = '';
if ($cgi->param('svcnum')) {
  $error  = $new->replace();
} else {
  $error  = $new->insert;
  $svcnum = $new->svcnum;
}

</%init>