certificates ala communigate, RT#7515
[freeside.git] / httemplate / view / svc_cert.cgi
1 <% include('elements/svc_Common.html',
2              'table'     => 'svc_cert',
3              'labels'    => \%labels,
4              #'html_foot' => $html_foot,
5              'fields' => \@fields,
6           )
7 %>
8 <%init>
9
10 my $fields = FS::svc_cert->table_info->{'fields'};
11 my %labels = map { $_ =>  ( ref($fields->{$_})
12                              ? $fields->{$_}{'label'}
13                              : $fields->{$_}
14                          );
15                  }
16              keys %$fields;
17
18 my @fields = (
19   { field=>'privatekey',
20     value=> sub {
21       my $svc_cert = shift;
22       if ( $svc_cert->privatekey && $svc_cert->check_privatekey ) {
23         '<FONT COLOR="#33ff33">Verification OK</FONT>';
24       } elsif ( $svc_cert->privatekey ) {
25         '<FONT COLOR="#ff0000">Verification error</FONT>';
26       } else {
27         '<I>(none)</I>';
28       }
29     },
30   },
31   qw( common_name organization organization_unit city state country cert_contact
32     ),
33   { 'field'=>'csr',
34     'value'=> sub {
35       my $svc_cert = shift;
36       if ( $svc_cert->csr ) { #display the subject etc?
37         '<PRE><FONT STYLE="font-family:monospace">'. "\n". $svc_cert->csr.
38         '</FONT></PRE>';
39       } elsif ( $svc_cert->common_name ) {
40         my $svcnum = $svc_cert->svcnum;
41         qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_csr;svcnum=$svcnum">Generate</A>);
42       } else {
43         '';
44       }
45     },
46   },
47   { 'field'=>'certificate',
48     'value'=> sub {
49       my $svc_cert = shift;
50       if ( $svc_cert->certificate ) {
51
52         my %hash = $svc_cert->check_certificate;
53
54         tie my %w, 'Tie::IxHash',
55           'subject' => 'Issued to',
56           'issuer'  => 'Issued by',
57         ;
58
59         my $out = '<TABLE><TR><TD>';
60
61         foreach my $w ( keys %w ) {
62
63           $out .= include('/elements/table-grid.html'). #'<TABLE>'.
64                   '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
65                   $w{$w}. '</TH></TR>';
66
67           my $col = $svc_cert->subj_col;
68
69           my $subj = $hash{$w};
70           foreach my $key (keys %$col) { #( keys %$subj ) {
71             $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
72                         "<TD>". $subj->{$key}. "</TD></TR>";
73           }
74
75           $out .= '</TABLE></TD><TD>';
76         }
77         $out .= '</TD></TR></TABLE>';
78
79         $out .= '<TABLE>'.
80                 '<TR><TH ALIGN="right">Serial number</TH>'.
81                     "<TD>$hash{serial}</TD></TR>".
82                 '<TR><TH ALIGN="right">Valid</TH>'.
83                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
84                 '</TABLE>';
85
86         my $svcnum = $svc_cert->svcnum;
87
88         if ( $hash{'selfsigned'} ) {
89           $out .= qq(<BR> <A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Re-generate self-signed</A>).
90                   ' &nbsp; '.
91                   include('/elements/popup_link.html', {
92                     'action'      => $p."edit/svc_cert/import_certificate.html".
93                                      "?svcnum=$svcnum",
94                     'label'       => 'Import issued certificate', #link
95                     'actionlabel' => 'Import issued certificate', #title
96                     #opt
97                     'width'       => '544',
98                     'height'      => '368',
99                     #'color'       => '#ff0000',
100                   }).
101                   '<BR>';
102         }
103
104         $out .= '<PRE><FONT STYLE="font-family:monospace">'.
105                 $svc_cert->certificate.
106                 '</FONT><PRE>';
107
108         $out;
109       } elsif ( $svc_cert->csr ) {
110         my $svcnum = $svc_cert->svcnum;
111         qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Generate self-signed</A>);
112       } else {
113         '';
114       }
115     },
116   },
117   { 'field'=>'cacert',
118     'value'=> sub {
119       my $svc_cert = shift;
120       if ( $svc_cert->cacert ) {
121
122         my %hash = $svc_cert->check_cacert;
123
124         tie my %w, 'Tie::IxHash',
125           'subject' => 'Issued to',
126           'issuer'  => 'Issued by',
127         ;
128
129         my $out = '<TABLE><TR><TD>';
130
131         foreach my $w ( keys %w ) {
132
133           $out .= include('/elements/table-grid.html'). #'<TABLE>'.
134                   '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
135                   $w{$w}. '</TH></TR>';
136
137           my $col = $svc_cert->subj_col;
138
139           my $subj = $hash{$w};
140           foreach my $key (keys %$col) { #( keys %$subj ) {
141             $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
142                         "<TD>". $subj->{$key}. "</TD></TR>";
143           }
144
145           $out .= '</TABLE></TD><TD>';
146         }
147         $out .= '</TD></TR></TABLE>';
148
149         $out .= '<TABLE>'.
150                 '<TR><TH ALIGN="right">Serial number</TH>'.
151                     "<TD>$hash{serial}</TD></TR>".
152                 '<TR><TH ALIGN="right">Valid</TH>'.
153                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
154                 '</TABLE>';
155
156         $out .= '<PRE><FONT STYLE="font-family:monospace">'.
157                 $svc_cert->certificate.
158                 '</FONT><PRE>';
159
160         $out;
161
162       } else {
163
164         my $svcnum = $svc_cert->svcnum;
165
166         include('/elements/popup_link.html', {
167           'action'      => $p."edit/svc_cert/import_cacert.html".
168                            "?svcnum=$svcnum",
169           'label'       => 'Import certificate authority chain',#link
170           'actionlabel' => 'Import certificate authority chain',#title
171           #opt
172           'width'       => '544',
173           'height'      => '368',
174           #'color'       => '#ff0000',
175         }). '&nbsp;(optional)'.
176         '<BR>';
177
178       }
179     },
180   },
181 );
182
183 </%init>