summaryrefslogtreecommitdiff
path: root/httemplate/view/svc_cert.cgi
blob: 28a269bcce2baee057eac16dc0c1132c93b10715 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<% include('elements/svc_Common.html',
             'table'     => 'svc_cert',
             'labels'    => \%labels,
             #'html_foot' => $html_foot,
             'fields' => \@fields,
          )
%>
<%init>

my $fields = FS::svc_cert->table_info->{'fields'};
my %labels = map { $_ =>  ( ref($fields->{$_})
                             ? $fields->{$_}{'label'}
                             : $fields->{$_}
                         );
                 }
             keys %$fields;

my @fields = (
  { field=>'privatekey',
    value=> sub {
      my $svc_cert = shift;
      if ( $svc_cert->privatekey && $svc_cert->check_privatekey ) {
        '<FONT COLOR="#33ff33">Verification OK</FONT>';
      } elsif ( $svc_cert->privatekey ) {
        '<FONT COLOR="#ff0000">Verification error</FONT>';
      } else {
        '<I>(none)</I>';
      }
    },
  },
  qw( common_name organization organization_unit city state country cert_contact
    ),
  { 'field'=>'csr',
    'value'=> sub {
      my $svc_cert = shift;
      if ( $svc_cert->csr ) { #display the subject etc?
        '<PRE><FONT STYLE="font-family:monospace">'. "\n". $svc_cert->csr.
        '</FONT></PRE>';
      } elsif ( $svc_cert->common_name ) {
        my $svcnum = $svc_cert->svcnum;
        qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_csr;svcnum=$svcnum">Generate</A>);
      } else {
        '';
      }
    },
  },
  { 'field'=>'certificate',
    'value'=> sub {
      my $svc_cert = shift;
      if ( $svc_cert->certificate ) {

        my %hash = $svc_cert->check_certificate;

        tie my %w, 'Tie::IxHash',
          'subject' => 'Issued to',
          'issuer'  => 'Issued by',
        ;

        my $out = '<TABLE><TR><TD>';

        foreach my $w ( keys %w ) {

          $out .= include('/elements/table-grid.html'). #'<TABLE>'.
                  '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
                  $w{$w}. '</TH></TR>';

          my $col = $svc_cert->subj_col;

          my $subj = $hash{$w};
          foreach my $key (keys %$col) { #( keys %$subj ) {
            $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
                        "<TD>". $subj->{$key}. "</TD></TR>";
          }

          $out .= '</TABLE></TD><TD>';
        }
        $out .= '</TD></TR></TABLE>';

        $out .= '<TABLE>'.
                '<TR><TH ALIGN="right">Serial number</TH>'.
                    "<TD>$hash{serial}</TD></TR>".
                '<TR><TH ALIGN="right">Valid</TH>'.
                    "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
                '</TABLE>';

        if ( $hash{'selfsigned'} ) {
          my $svcnum = $svc_cert->svcnum;
          $out .= qq(<BR> <A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Re-generate self-signed</A>).
                  ' &nbsp; '.
                  include('/elements/popup_link.html', {
                    'action'      => $p."edit/svc_cert/import_certificate.html".
                                     "?svcnum=$svcnum",
                    'label'       => 'Import issued certificate', #link
                    'actionlabel' => 'Import issued certificate', #title
                    #opt
                    'width'       => '544',
                    'height'      => '368',
                    #'color'       => '#ff0000',
                  }).
                  '<BR>';
        }

        $out .= '<PRE><FONT STYLE="font-family:monospace">'.
                $svc_cert->certificate.
                '</FONT><PRE>';

        $out;
      } elsif ( $svc_cert->csr ) {
        my $svcnum = $svc_cert->svcnum;
        qq(<A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Generate self-signed</A>);
      } else {
        '';
      }
    },
  },
);

</%init>