Annotation of loncom/configuration/SSL.pm, revision 1.8
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Checksum installed LON-CAPA modules and some configuration files
3: #
1.8 ! raeburn 4: # $Id: SSL.pm,v 1.7 2018/08/18 22:07:53 raeburn Exp $
1.1 raeburn 5: #
6: # The LearningOnline Network with CAPA
7: #
8: # Copyright Michigan State University Board of Trustees
9: #
10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
11: #
12: # LON-CAPA is free software; you can redistribute it and/or modify
13: # it under the terms of the GNU General Public License as published by
14: # the Free Software Foundation; either version 2 of the License, or
15: # (at your option) any later version.
16: #
17: # LON-CAPA is distributed in the hope that it will be useful,
18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: # GNU General Public License for more details.
21: #
22: # You should have received a copy of the GNU General Public License
23: # along with LON-CAPA; if not, write to the Free Software
24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: #
26: # /home/httpd/html/adm/gpl.txt
27: #
28: # http://www.lon-capa.org/
29: #
30:
31: package LONCAPA::SSL;
32: use strict;
33: use lib '/home/httpd/lib/perl/';
1.7 raeburn 34: use Apache::lonlocal;
1.1 raeburn 35: use Apache::lonnet();
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
1.4 raeburn 38: use DateTime;
39: use DateTime::Format::x509;
1.1 raeburn 40: use LONCAPA;
41:
42: sub print_certstatus {
43: my ($servers,$target,$context) = @_;
44: return unless (ref($servers) eq 'HASH');
45: my $message;
46: my %lt = &Apache::lonlocal::texthash (
47: 'file' => 'File',
48: 'avai' => 'Available',
49: 'yes' => 'Yes',
50: 'no' => 'No',
1.7 raeburn 51: 'cn' => 'Common Name (CN)',
1.1 raeburn 52: 'start' => 'Valid From',
53: 'end' => 'Valid To',
54: 'alg' => 'Signature Algorithm',
55: 'size' => 'Public Key Size',
56: 'status' => 'Status',
57: 'email' => 'E-mail',
58: 'key' => 'Private Key',
59: 'host' => 'Connections Certificate',
60: 'hostname' => 'Replication Certificate',
61: 'ca' => 'LON-CAPA CA Certificate',
1.4 raeburn 62: 'expired' => 'Expired',
63: 'future' => 'Future validity',
1.5 raeburn 64: 'nokey' => 'No key',
1.7 raeburn 65: 'otherkey' => 'No matching key',
66: 'revoked' => 'Revoked by CA',
67: 'wrongcn' => 'Incorrect CN',
1.8 ! raeburn 68: 'mismatch' => 'Mismatched Issuer',
1.1 raeburn 69: );
70: my @files = qw(key host hostname ca);
71: my @fields = qw(status cn start end alg size email);
72: foreach my $server (sort(keys(%{$servers}))) {
1.7 raeburn 73: my $hostname = $servers->{$server};
74: my ($result,$hashref) = &Apache::lonnet::get_servercerts_info($server,
75: $hostname,
76: $context);
1.1 raeburn 77: if ($result eq 'ok' && ref($hashref) eq 'HASH') {
78: if ($target eq 'web') {
79: $message .= "<fieldset><legend>$hostname ($server)</legend>".
80: &Apache::loncommon::start_data_table().
81: &Apache::loncommon::start_data_table_header_row()."\n";
82: foreach my $item ('file','avai',@fields) {
83: $message .= '<th>'.$lt{$item}.'</th>';
84: }
85: $message .= &Apache::loncommon::end_data_table_header_row()."\n";
86: } else {
87: $message .= $server.':';
88: }
1.7 raeburn 89: my %csr;
1.1 raeburn 90: foreach my $file (@files) {
91: if ($target eq 'web') {
92: $message .= &Apache::loncommon::start_data_table_row()."\n".
93: '<td>'.$lt{$file}.'</td>';
94: } else {
95: $message .= $file.'=';
96: }
97: if (ref($hashref->{$file}) eq 'HASH') {
1.4 raeburn 98: my ($starttime,$endtime,$dateinvalid);
1.1 raeburn 99: if ($target eq 'web') {
100: $message .= '<td>'.$lt{'yes'}.'</td>';
101: } else {
1.5 raeburn 102: $message .= 'yes,';
1.1 raeburn 103: }
1.4 raeburn 104: unless ($file eq 'key') {
105: if ($hashref->{$file}->{'end'} ne '') {
106: my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'end'});
107: if (ref($dt)) {
108: $endtime = $dt->epoch;
109: if ($endtime < time) {
1.5 raeburn 110: if ($target eq 'web') {
111: $dateinvalid = $lt{'expired'};
112: } else {
113: $dateinvalid = 'expired';
114: }
1.4 raeburn 115: }
116: }
117: }
118: if ($hashref->{$file}->{'start'} ne '') {
119: my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'start'});
120: if (ref($dt)) {
121: $starttime = $dt->epoch;
122: if ($starttime > time) {
123: unless ($dateinvalid) {
1.5 raeburn 124: if ($target eq 'web') {
125: $dateinvalid = $lt{'future'};
126: } else {
127: $dateinvalid = 'future';
128: }
1.4 raeburn 129: }
130: }
131: }
132: }
133: }
1.1 raeburn 134: foreach my $item (@fields) {
135: my $display = $hashref->{$file}->{$item};
1.4 raeburn 136: if ($item eq 'status') {
137: if ($file eq 'key') {
138: if ($display =~ /ok$/) {
139: if ($target eq 'web') {
140: $display = &Apache::lonhtmlcommon::confirm_success($display);
141: }
142: }
143: } elsif ($file eq 'ca') {
144: if ($dateinvalid) {
145: $display = $dateinvalid;
146: } elsif ($target eq 'web') {
147: $display = &Apache::lonhtmlcommon::confirm_success($display);
148: }
149: } elsif ($display =~ /^ok/) {
150: if ($dateinvalid) {
151: $display = $dateinvalid;
152: } elsif ($target eq 'web') {
153: $display = &Apache::lonhtmlcommon::confirm_success($display);
154: }
1.7 raeburn 155: } elsif (($display eq 'nokey') || ($display eq 'otherkey') ||
156: ($display eq 'revoked') || ($display eq 'expired') ||
1.8 ! raeburn 157: ($display eq 'wrongcn') || ($display eq 'mismatch')) {
1.5 raeburn 158: if ($target eq 'web') {
1.7 raeburn 159: $display = $lt{$display};
160: }
161: if (ref($hashref->{$file.'-csr'}) eq 'HASH') {
162: if ($hashref->{$file.'-csr'}->{$item} eq 'ok') {
163: if ($target eq 'web') {
164: $display .= '<br />'.&mt('(New request awaiting signature)');
165: }
166: $csr{$file} = 1;
167: }
1.5 raeburn 168: }
1.4 raeburn 169: }
170: } elsif ($item eq 'start') {
171: if ($starttime) {
172: if ($target eq 'web') {
173: $display = &Apache::lonlocal::locallocaltime($starttime);
174: } else {
175: $display = $starttime;
176: }
177: }
178: } elsif ($item eq 'end') {
179: if ($endtime) {
180: if ($target eq 'web') {
181: $display = &Apache::lonlocal::locallocaltime($endtime);
182: } else {
183: $display = $endtime;
184: }
185: }
186: }
1.1 raeburn 187: if ($target eq 'web') {
188: $message .= "<td>$display</td>";
189: } else {
190: $message .= "$display,";
191: }
192: }
193: } else {
194: if ($target eq 'web') {
1.6 raeburn 195: $message .= '<td>'.$lt{'no'}.'</td>';
1.1 raeburn 196: } else {
1.5 raeburn 197: $message .= 'no,';
1.1 raeburn 198: }
1.7 raeburn 199: if ((($file eq 'host') || ($file eq 'hostname')) &&
200: (ref($hashref->{$file.'-csr'}) eq 'HASH')) {
201: if ($hashref->{$file.'-csr'}->{'status'} eq 'ok') {
202: if ($target eq 'web') {
203: my $colspan = scalar(@fields);
204: $message .= '<td colspan="'.$colspan.'">'.
205: &mt('Request for [_1] awaiting signature',
206: $lt{$file}).'</td>';
207: }
208: $csr{$file} = 1;
209: }
210: }
1.1 raeburn 211: foreach my $item (@fields) {
212: if ($target eq 'web') {
1.7 raeburn 213: unless ($csr{$file}) {
214: $message .= '<td> </td>';
215: }
1.1 raeburn 216: } else {
217: $message .= ',';
218: }
1.2 raeburn 219: }
220: }
221: if ($target eq 'web') {
222: $message .= &Apache::loncommon::end_data_table_row()."\n";
223: } else {
224: $message =~ s/,$//;
225: $message .= '&';
1.1 raeburn 226: }
227: }
228: if ($target eq 'web') {
229: $message .= &Apache::loncommon::end_data_table().'</fieldset>';
230: } else {
1.7 raeburn 231: if (keys(%csr)) {
232: foreach my $file (keys(%csr)) {
233: if (ref($hashref->{$file.'-csr'}) eq 'HASH') {
234: $message .= $file.'-csr=yes,';
235: foreach my $item (@fields) {
236: $message .= $hashref->{$file.'-csr'}->{$item}.',';
237: }
238: $message =~ s/,$//;
239: $message .= '&';
240: }
241: }
242: }
1.1 raeburn 243: $message =~ s/\&$//;
244: }
245: $message .= "\n";
246: } else {
247: if ($target eq 'web') {
1.3 raeburn 248: $message .= "$server:error\n";
1.1 raeburn 249: } else {
1.3 raeburn 250: $message .= "$server:error\n";
1.1 raeburn 251: }
252: }
253: }
254: return $message;
255: }
256:
257: 1;
258:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>