certificates ala communigate, RT#7515
[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). "edit/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 %#change link when we make a non-generic view
21 %#<% $cgi->redirect(popurl(3). "view/svc_cert.cgi?$svcnum") %>
22 <% $cgi->redirect(popurl(3). "view/svc_Common.html?svcdb=svc_cert;svcnum=$svcnum") %>
23 % }
24 <%init>
25
26 die "access denied"
27   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
28
29 $cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
30 my $svcnum = $1;
31
32 my $new = new FS::svc_cert ( {
33   map {
34     $_, scalar($cgi->param($_));
35   } ( fields('svc_cert'), qw( pkgnum svcpart ) )
36 } );
37
38 my $old = '';
39 if ( $svcnum ) {
40   $old = qsearchs('svc_cert', { 'svcnum' => $svcnum } ) #agent virt;
41     or die 'unknown svcnum';
42   $new->$_( $old->$_ ) for grep $old->$_, qw( privatekey );
43 }
44
45 my $popup = 0;
46 my $title = '';
47 if ( $cgi->param('privatekey') eq '_generate' ) { #generate
48   $popup = 1;
49   $title = 'Key generated';
50
51   $cgi->param('keysize') =~ /^(\d+)$/ or die 'illegal keysize';
52   my $keysize = $1;
53   $new->generate_privatekey($keysize);
54
55 } elsif ( $cgi->param('privatekey') =~ /\S/ ) { #import
56   $popup = 1;
57   $title = 'Key imported';
58
59   $new->privatekey( $cgi->param('privatekey') );
60
61 } #elsif ( $cgi->param('privatekey') eq '_clear' ) { #import
62
63 my $error = '';
64 if ($cgi->param('svcnum')) {
65   $error  = $new->replace();
66 } else {
67   $error  = $new->insert;
68   $svcnum = $new->svcnum;
69 }
70
71 </%init>