RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / svc_cert.cgi
1 %if ( $popup ) {
2 %  if ( $error ) { #should redirect back to the posting page?
3 <% include("/elements/header-popup.html", "Error") %>
4 <P><FONT SIZE="+1" COLOR="#ff0000"><% $error |h %></FONT>
5 <BR><BR>
6 <P ALIGN="center">
7 <BUTTON TYPE="button" onClick="parent.cClick();">Close</BUTTON>
8 </BODY></HTML>
9 %  } else {
10 <% include('/elements/header-popup.html', $title ) %>
11     <SCRIPT TYPE="text/javascript">
12       window.top.location = '<% popurl(3). "$popup/svc_cert.cgi?$svcnum" %>';
13     </SCRIPT>
14     </BODY></HTML>
15 %  }
16 %} elsif ( $error ) {
17 %  $cgi->param('error', $error);
18 <% $cgi->redirect(popurl(2). "svc_cert.cgi?". $cgi->query_string ) %>
19 %} else {
20 <% $cgi->redirect(popurl(3). "view/svc_cert.cgi?$svcnum") %>
21 % }
22 <%init>
23
24 die "access denied"
25   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
26
27 $cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
28 my $svcnum = $1;
29
30 my $new = new FS::svc_cert ( {
31   map {
32     $_, scalar($cgi->param($_));
33   } ( fields('svc_cert'), qw( pkgnum svcpart ) )
34 } );
35
36 my $old = '';
37 if ( $svcnum ) {
38   $old = qsearchs('svc_cert', { 'svcnum' => $svcnum } ) #agent virt;
39     or die 'unknown svcnum';
40   $new->$_( $old->$_ ) for grep $old->$_, qw( privatekey csr certificate cacert );
41 }
42
43 my $popup = '';
44 my $title = '';
45 if ( $cgi->param('privatekey') eq '_generate' ) { #generate
46   $popup = 'edit';
47   $title = 'Key generated';
48
49   $cgi->param('keysize') =~ /^(\d+)$/ or die 'illegal keysize';
50   my $keysize = $1;
51   $new->generate_privatekey($keysize);
52
53 } elsif ( $cgi->param('privatekey') =~ /\S/ ) { #import
54   $popup = 'edit';
55   $title = 'Key imported';
56
57   $new->privatekey( $cgi->param('privatekey') );
58
59 #} #elsif ( $cgi->param('privatekey') eq '_clear' ) { #clear
60
61 } elsif ( $cgi->param('certificate') ) {
62
63   $popup = 'view';
64   $title = 'Certificate imported';
65
66   $new->certificate( $cgi->param('certificate') );
67   $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );
68
69 } elsif ( $cgi->param('cacert') ) {
70
71   $popup = 'view';
72   $title = 'Certificate authority chain imported';
73
74   $new->cacert( $cgi->param('cacert') );
75   $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );
76
77 }
78
79 my $error = '';
80 if ($cgi->param('svcnum')) {
81   $error  = $new->replace();
82 } else {
83   $error  = $new->insert;
84   $svcnum = $new->svcnum;
85 }
86
87 </%init>