File:
[LON-CAPA] /
loncom /
configuration /
SSL.pm
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Thu May 18 22:13:57 2017 UTC (7 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Only translate SSL key and certificate status if target is web.
- Include additional status types for SSL certificates (host and hostname)
-- nokey and otherkey -- if key is missing, or certificate uses another
key.
# The LearningOnline Network with CAPA
# Checksum installed LON-CAPA modules and some configuration files
#
# $Id: SSL.pm,v 1.5 2017/05/18 22:13:57 raeburn Exp $
#
# The LearningOnline Network with CAPA
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package LONCAPA::SSL;
use strict;
use lib '/home/httpd/lib/perl/';
use Apache::lonlocal();
use Apache::lonnet();
use Apache::loncommon();
use Apache::lonhtmlcommon();
use DateTime;
use DateTime::Format::x509;
use LONCAPA;
sub print_certstatus {
my ($servers,$target,$context) = @_;
return unless (ref($servers) eq 'HASH');
my $message;
my %lt = &Apache::lonlocal::texthash (
'file' => 'File',
'avai' => 'Available',
'yes' => 'Yes',
'no' => 'No',
'cn' => 'Common Name',
'start' => 'Valid From',
'end' => 'Valid To',
'alg' => 'Signature Algorithm',
'size' => 'Public Key Size',
'status' => 'Status',
'email' => 'E-mail',
'key' => 'Private Key',
'host' => 'Connections Certificate',
'hostname' => 'Replication Certificate',
'ca' => 'LON-CAPA CA Certificate',
'expired' => 'Expired',
'future' => 'Future validity',
'nokey' => 'No key',
'otherkey' => 'No matching key',
);
my @files = qw(key host hostname ca);
my @fields = qw(status cn start end alg size email);
foreach my $server (sort(keys(%{$servers}))) {
my ($result,$hashref) = &Apache::lonnet::get_servercerts_info($server,$context);
if ($result eq 'ok' && ref($hashref) eq 'HASH') {
if ($target eq 'web') {
my $hostname = &Apache::lonnet::hostname($server);
$message .= "<fieldset><legend>$hostname ($server)</legend>".
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row()."\n";
foreach my $item ('file','avai',@fields) {
$message .= '<th>'.$lt{$item}.'</th>';
}
$message .= &Apache::loncommon::end_data_table_header_row()."\n";
} else {
$message .= $server.':';
}
foreach my $file (@files) {
if ($target eq 'web') {
$message .= &Apache::loncommon::start_data_table_row()."\n".
'<td>'.$lt{$file}.'</td>';
} else {
$message .= $file.'=';
}
if (ref($hashref->{$file}) eq 'HASH') {
my ($starttime,$endtime,$dateinvalid);
if ($target eq 'web') {
$message .= '<td>'.$lt{'yes'}.'</td>';
} else {
$message .= 'yes,';
}
unless ($file eq 'key') {
if ($hashref->{$file}->{'end'} ne '') {
my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'end'});
if (ref($dt)) {
$endtime = $dt->epoch;
if ($endtime < time) {
if ($target eq 'web') {
$dateinvalid = $lt{'expired'};
} else {
$dateinvalid = 'expired';
}
}
}
}
if ($hashref->{$file}->{'start'} ne '') {
my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'start'});
if (ref($dt)) {
$starttime = $dt->epoch;
if ($starttime > time) {
unless ($dateinvalid) {
if ($target eq 'web') {
$dateinvalid = $lt{'future'};
} else {
$dateinvalid = 'future';
}
}
}
}
}
}
foreach my $item (@fields) {
my $display = $hashref->{$file}->{$item};
if ($item eq 'status') {
if ($file eq 'key') {
if ($display =~ /ok$/) {
if ($target eq 'web') {
$display = &Apache::lonhtmlcommon::confirm_success($display);
}
}
} elsif ($file eq 'ca') {
if ($dateinvalid) {
$display = $dateinvalid;
} elsif ($target eq 'web') {
$display = &Apache::lonhtmlcommon::confirm_success($display);
}
} elsif ($display =~ /^ok/) {
if ($dateinvalid) {
$display = $dateinvalid;
} elsif ($target eq 'web') {
$display = &Apache::lonhtmlcommon::confirm_success($display);
}
} elsif (($display eq 'nokey') || ($display eq 'otherkey')) {
if ($target eq 'web') {
$display = $lt{$display};
}
}
} elsif ($item eq 'start') {
if ($starttime) {
if ($target eq 'web') {
$display = &Apache::lonlocal::locallocaltime($starttime);
} else {
$display = $starttime;
}
}
} elsif ($item eq 'end') {
if ($endtime) {
if ($target eq 'web') {
$display = &Apache::lonlocal::locallocaltime($endtime);
} else {
$display = $endtime;
}
}
}
if ($target eq 'web') {
$message .= "<td>$display</td>";
} else {
$message .= "$display,";
}
}
} else {
if ($target eq 'web') {
$message .= '<td>'.$lt{'no'}.'<td>';
} else {
$message .= 'no,';
}
foreach my $item (@fields) {
if ($target eq 'web') {
$message .= '<td> </td>';
} else {
$message .= ',';
}
}
}
if ($target eq 'web') {
$message .= &Apache::loncommon::end_data_table_row()."\n";
} else {
$message =~ s/,$//;
$message .= '&';
}
}
if ($target eq 'web') {
$message .= &Apache::loncommon::end_data_table().'</fieldset>';
} else {
$message =~ s/\&$//;
}
$message .= "\n";
} else {
if ($target eq 'web') {
$message .= "$server:error\n";
} else {
$message .= "$server:error\n";
}
}
}
return $message;
}
1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>