From: ivan Date: Sun, 7 Nov 2010 23:47:04 +0000 (+0000) Subject: certificates ala communigate, RT#7515 X-Git-Tag: TORRUS_1_0_9~123 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=874ad675da1321638b374d0b574231d7fa577196;hp=5ac9e46a92f4eefd795f97643f3e8f62ec1a2b26 certificates ala communigate, RT#7515 --- diff --git a/FS/FS/svc_cert.pm b/FS/FS/svc_cert.pm index e3ef3256f..36e7582a6 100644 --- a/FS/FS/svc_cert.pm +++ b/FS/FS/svc_cert.pm @@ -2,6 +2,7 @@ package FS::svc_cert; use strict; use base qw( FS::svc_Common ); +use Tie::IxHash; #use FS::Record qw( qsearch qsearchs ); use FS::cust_svc; @@ -251,14 +252,18 @@ sub check_privatekey { return ($ok =~ /key ok/); } -my %subj = ( +tie my %subj, 'Tie::IxHash', 'CN' => 'common_name', 'O' => 'organization', 'OU' => 'organization_unit', 'L' => 'city', 'ST' => 'state', 'C' => 'country', -); +; + +sub subj_col { + \%subj; +} sub subj { my $self = shift; @@ -343,11 +348,25 @@ sub check_certificate { my %hash = (); while () { - warn $_; /^\s*(\w+)=\s*(.*)\s*$/ or next; $hash{$1} = $2; } + for my $f (qw( subject issuer )) { + + $hash{$f} = { map { if ( /^\s*(\w+)=\s*(.*)\s*$/ ) { + ($1=>$2); + } else { + (''=>''); + } + } + split('/', $hash{$f}) + }; + + } + + $hash{'selfsigned'} = 1 if $hash{'subject'}->{'O'} eq $hash{'issuer'}->{'O'}; + %hash; } diff --git a/httemplate/edit/process/svc_cert.cgi b/httemplate/edit/process/svc_cert.cgi index 58b95a6e9..a8dc0ca8a 100644 --- a/httemplate/edit/process/svc_cert.cgi +++ b/httemplate/edit/process/svc_cert.cgi @@ -9,7 +9,7 @@ % } else { <% include('/elements/header-popup.html', $title ) %> % } @@ -40,10 +40,10 @@ if ( $svcnum ) { $new->$_( $old->$_ ) for grep $old->$_, qw( privatekey csr certificate cacert ); } -my $popup = 0; +my $popup = ''; my $title = ''; if ( $cgi->param('privatekey') eq '_generate' ) { #generate - $popup = 1; + $popup = 'edit'; $title = 'Key generated'; $cgi->param('keysize') =~ /^(\d+)$/ or die 'illegal keysize'; @@ -51,12 +51,22 @@ if ( $cgi->param('privatekey') eq '_generate' ) { #generate $new->generate_privatekey($keysize); } elsif ( $cgi->param('privatekey') =~ /\S/ ) { #import - $popup = 1; + $popup = 'edit'; $title = 'Key imported'; $new->privatekey( $cgi->param('privatekey') ); -} #elsif ( $cgi->param('privatekey') eq '_clear' ) { #clear +#} #elsif ( $cgi->param('privatekey') eq '_clear' ) { #clear + +} elsif ( $cgi->param('certificate') ) { + + $popup = 'view'; + $title = 'Certificate imported'; + + $new->certificate( $cgi->param('certificate') ); + $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact ); + +} my $error = ''; if ($cgi->param('svcnum')) { diff --git a/httemplate/edit/svc_cert/import_certificate.html b/httemplate/edit/svc_cert/import_certificate.html new file mode 100644 index 000000000..337a7419e --- /dev/null +++ b/httemplate/edit/svc_cert/import_certificate.html @@ -0,0 +1,22 @@ +<% include('/elements/header-popup.html', 'Import issued certificate' ) %> + +<% include('/elements/error.html') %> + +
+ + + + + +

+ + +
+ + +<%init> + +$cgi->param('svcnum') =~ /^(\d*)$/ or die 'illegal svcnum'; +my $svcnum = $1; + + diff --git a/httemplate/view/svc_cert.cgi b/httemplate/view/svc_cert.cgi index 36f598b9a..28a269bcc 100644 --- a/httemplate/view/svc_cert.cgi +++ b/httemplate/view/svc_cert.cgi @@ -34,8 +34,8 @@ my @fields = ( 'value'=> sub { my $svc_cert = shift; if ( $svc_cert->csr ) { #display the subject etc? - '
'. $svc_cert->csr.
-        '
'; + '
'. "\n". $svc_cert->csr.
+        '
'; } elsif ( $svc_cert->common_name ) { my $svcnum = $svc_cert->svcnum; qq(Generate); @@ -50,15 +50,60 @@ my @fields = ( if ( $svc_cert->certificate ) { my %hash = $svc_cert->check_certificate; - my $out = ''; #XXX better formatting - foreach my $key ( keys %hash ) { - $out .= ""; + + tie my %w, 'Tie::IxHash', + 'subject' => 'Issued to', + 'issuer' => 'Issued by', + ; + + my $out = '
$key$hash{$key}
'; + + foreach my $w ( keys %w ) { + + $out .= include('/elements/table-grid.html'). #''. + ''; + + my $col = $svc_cert->subj_col; + + my $subj = $hash{$w}; + foreach my $key (keys %$col) { #( keys %$subj ) { + $out .= "". + ""; + } + + $out .= '
'. + $w{$w}. '
". $labels{$col->{$key}}. "". $subj->{$key}. "
'; } - $out .= '
'; + $out .= ''; + + $out .= ''. + ''. + "". + ''. + "". + '
Serial number$hash{serial}
Valid$hash{notBefore} - $hash{notAfter}
'; - $out .= '
'.
+        if ( $hash{'selfsigned'} ) {
+          my $svcnum = $svc_cert->svcnum;
+          $out .= qq(
Re-generate self-signed). + '   '. + 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', + }). + '
'; + } + + $out .= '
'.
                 $svc_cert->certificate.
-                '
'; + '
';
+
         $out;
       } elsif ( $svc_cert->csr ) {
         my $svcnum = $svc_cert->svcnum;