adding export to read mailbox status information, RT#15987
[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 ) {
37
38         my $out = '';
39
40         my %hash = $svc_cert->check_csr;
41
42         $out .= include('/elements/table-grid.html'). #'<TABLE>'.
43                 '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
44                 'Requested by</TH></TR>';
45
46         my $col = $svc_cert->subj_col;
47
48         foreach my $key (keys %hash) {
49           $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
50                       "<TD>". $hash{$key}. "</TD></TR>";
51         }
52
53         $out .= '</TABLE>';
54
55         $out .= 
56           '<PRE><FONT STYLE="font-family:monospace">'. $svc_cert->csr.
57           '</FONT></PRE>';
58
59         $out;
60
61       } elsif ( $svc_cert->common_name ) {
62         my $svcnum = $svc_cert->svcnum;
63         qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_csr;svcnum=$svcnum">Generate</A>);
64       } else {
65         '';
66       }
67     },
68   },
69   { 'field'=>'certificate',
70     'value'=> sub {
71       my $svc_cert = shift;
72       if ( $svc_cert->certificate ) {
73
74         my %hash = $svc_cert->check_certificate;
75
76         tie my %w, 'Tie::IxHash',
77           'subject' => 'Issued to',
78           'issuer'  => 'Issued by',
79         ;
80
81         my $out = '<TABLE><TR><TD>';
82
83         foreach my $w ( keys %w ) {
84
85           $out .= include('/elements/table-grid.html'). #'<TABLE>'.
86                   '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
87                   $w{$w}. '</TH></TR>';
88
89           my $col = $svc_cert->subj_col;
90
91           my $subj = $hash{$w};
92           foreach my $key (keys %$col) { #( keys %$subj ) {
93             $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
94                         "<TD>". $subj->{$key}. "</TD></TR>";
95           }
96
97           $out .= '</TABLE></TD><TD>';
98         }
99         $out .= '</TD></TR></TABLE>';
100
101         $out .= '<TABLE>'.
102                 '<TR><TH ALIGN="right">Serial number</TH>'.
103                     "<TD>$hash{serial}</TD></TR>".
104                 '<TR><TH ALIGN="right">Valid</TH>'.
105                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
106                 '</TABLE>';
107
108         my $svcnum = $svc_cert->svcnum;
109
110         if ( $hash{'selfsigned'} ) {
111           $out .= qq(<BR> <A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Re-generate self-signed</A>).
112                   ' &nbsp; '.
113                   include('/elements/popup_link.html', {
114                     'action'      => $p."edit/svc_cert/import_certificate.html".
115                                      "?svcnum=$svcnum",
116                     'label'       => 'Import issued certificate', #link
117                     'actionlabel' => 'Import issued certificate', #title
118                     #opt
119                     'width'       => '544',
120                     'height'      => '368',
121                     #'color'       => '#ff0000',
122                   }).
123                   '<BR>';
124         }
125
126         $out .= '<PRE><FONT STYLE="font-family:monospace">'.
127                 $svc_cert->certificate.
128                 '</FONT><PRE>';
129
130         $out;
131       } elsif ( $svc_cert->csr ) {
132         my $svcnum = $svc_cert->svcnum;
133         qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Generate self-signed</A>);
134       } else {
135         '';
136       }
137     },
138   },
139   { 'field'=>'cacert',
140     'value'=> sub {
141       my $svc_cert = shift;
142       if ( $svc_cert->cacert ) {
143
144         my %hash = $svc_cert->check_cacert;
145
146         tie my %w, 'Tie::IxHash',
147           'subject' => 'Issued to',
148           'issuer'  => 'Issued by',
149         ;
150
151         my $out = '<TABLE><TR><TD>';
152
153         foreach my $w ( keys %w ) {
154
155           $out .= include('/elements/table-grid.html'). #'<TABLE>'.
156                   '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
157                   $w{$w}. '</TH></TR>';
158
159           my $col = $svc_cert->subj_col;
160
161           my $subj = $hash{$w};
162           foreach my $key (keys %$col) { #( keys %$subj ) {
163             $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
164                         "<TD>". $subj->{$key}. "</TD></TR>";
165           }
166
167           $out .= '</TABLE></TD><TD>';
168         }
169         $out .= '</TD></TR></TABLE>';
170
171         $out .= '<TABLE>'.
172                 '<TR><TH ALIGN="right">Serial number</TH>'.
173                     "<TD>$hash{serial}</TD></TR>".
174                 '<TR><TH ALIGN="right">Valid</TH>'.
175                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
176                 '</TABLE>';
177
178         $out .= '<PRE><FONT STYLE="font-family:monospace">'.
179                 $svc_cert->certificate.
180                 '</FONT><PRE>';
181
182         $out;
183
184       } else {
185
186         my $svcnum = $svc_cert->svcnum;
187
188         include('/elements/popup_link.html', {
189           'action'      => $p."edit/svc_cert/import_cacert.html".
190                            "?svcnum=$svcnum",
191           'label'       => 'Import certificate authority chain',#link
192           'actionlabel' => 'Import certificate authority chain',#title
193           #opt
194           'width'       => '544',
195           'height'      => '368',
196           #'color'       => '#ff0000',
197         }). '&nbsp;(optional)'.
198         '<BR>';
199
200       }
201     },
202   },
203 );
204
205 </%init>