Annotation of loncom/configuration/SSL.pm, revision 1.6
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Checksum installed LON-CAPA modules and some configuration files
3: #
1.6 ! raeburn 4: # $Id: SSL.pm,v 1.5 2017/05/18 22:13:57 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/';
34: use Apache::lonlocal();
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',
51: 'cn' => 'Common Name',
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',
65: 'otherkey' => 'No matching key',
1.1 raeburn 66: );
67: my @files = qw(key host hostname ca);
68: my @fields = qw(status cn start end alg size email);
69: foreach my $server (sort(keys(%{$servers}))) {
70: my ($result,$hashref) = &Apache::lonnet::get_servercerts_info($server,$context);
71: if ($result eq 'ok' && ref($hashref) eq 'HASH') {
72: if ($target eq 'web') {
1.2 raeburn 73: my $hostname = &Apache::lonnet::hostname($server);
1.1 raeburn 74: $message .= "<fieldset><legend>$hostname ($server)</legend>".
75: &Apache::loncommon::start_data_table().
76: &Apache::loncommon::start_data_table_header_row()."\n";
77: foreach my $item ('file','avai',@fields) {
78: $message .= '<th>'.$lt{$item}.'</th>';
79: }
80: $message .= &Apache::loncommon::end_data_table_header_row()."\n";
81: } else {
82: $message .= $server.':';
83: }
84: foreach my $file (@files) {
85: if ($target eq 'web') {
86: $message .= &Apache::loncommon::start_data_table_row()."\n".
87: '<td>'.$lt{$file}.'</td>';
88: } else {
89: $message .= $file.'=';
90: }
91: if (ref($hashref->{$file}) eq 'HASH') {
1.4 raeburn 92: my ($starttime,$endtime,$dateinvalid);
1.1 raeburn 93: if ($target eq 'web') {
94: $message .= '<td>'.$lt{'yes'}.'</td>';
95: } else {
1.5 raeburn 96: $message .= 'yes,';
1.1 raeburn 97: }
1.4 raeburn 98: unless ($file eq 'key') {
99: if ($hashref->{$file}->{'end'} ne '') {
100: my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'end'});
101: if (ref($dt)) {
102: $endtime = $dt->epoch;
103: if ($endtime < time) {
1.5 raeburn 104: if ($target eq 'web') {
105: $dateinvalid = $lt{'expired'};
106: } else {
107: $dateinvalid = 'expired';
108: }
1.4 raeburn 109: }
110: }
111: }
112: if ($hashref->{$file}->{'start'} ne '') {
113: my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'start'});
114: if (ref($dt)) {
115: $starttime = $dt->epoch;
116: if ($starttime > time) {
117: unless ($dateinvalid) {
1.5 raeburn 118: if ($target eq 'web') {
119: $dateinvalid = $lt{'future'};
120: } else {
121: $dateinvalid = 'future';
122: }
1.4 raeburn 123: }
124: }
125: }
126: }
127: }
1.1 raeburn 128: foreach my $item (@fields) {
129: my $display = $hashref->{$file}->{$item};
1.4 raeburn 130: if ($item eq 'status') {
131: if ($file eq 'key') {
132: if ($display =~ /ok$/) {
133: if ($target eq 'web') {
134: $display = &Apache::lonhtmlcommon::confirm_success($display);
135: }
136: }
137: } elsif ($file eq 'ca') {
138: if ($dateinvalid) {
139: $display = $dateinvalid;
140: } elsif ($target eq 'web') {
141: $display = &Apache::lonhtmlcommon::confirm_success($display);
142: }
143: } elsif ($display =~ /^ok/) {
144: if ($dateinvalid) {
145: $display = $dateinvalid;
146: } elsif ($target eq 'web') {
147: $display = &Apache::lonhtmlcommon::confirm_success($display);
148: }
1.5 raeburn 149: } elsif (($display eq 'nokey') || ($display eq 'otherkey')) {
150: if ($target eq 'web') {
151: $display = $lt{$display};
152: }
1.4 raeburn 153: }
154: } elsif ($item eq 'start') {
155: if ($starttime) {
156: if ($target eq 'web') {
157: $display = &Apache::lonlocal::locallocaltime($starttime);
158: } else {
159: $display = $starttime;
160: }
161: }
162: } elsif ($item eq 'end') {
163: if ($endtime) {
164: if ($target eq 'web') {
165: $display = &Apache::lonlocal::locallocaltime($endtime);
166: } else {
167: $display = $endtime;
168: }
169: }
170: }
1.1 raeburn 171: if ($target eq 'web') {
172: $message .= "<td>$display</td>";
173: } else {
174: $message .= "$display,";
175: }
176: }
177: } else {
178: if ($target eq 'web') {
1.6 ! raeburn 179: $message .= '<td>'.$lt{'no'}.'</td>';
1.1 raeburn 180: } else {
1.5 raeburn 181: $message .= 'no,';
1.1 raeburn 182: }
183: foreach my $item (@fields) {
184: if ($target eq 'web') {
185: $message .= '<td> </td>';
186: } else {
187: $message .= ',';
188: }
1.2 raeburn 189: }
190: }
191: if ($target eq 'web') {
192: $message .= &Apache::loncommon::end_data_table_row()."\n";
193: } else {
194: $message =~ s/,$//;
195: $message .= '&';
1.1 raeburn 196: }
197: }
198: if ($target eq 'web') {
199: $message .= &Apache::loncommon::end_data_table().'</fieldset>';
200: } else {
201: $message =~ s/\&$//;
202: }
203: $message .= "\n";
204: } else {
205: if ($target eq 'web') {
1.3 raeburn 206: $message .= "$server:error\n";
1.1 raeburn 207: } else {
1.3 raeburn 208: $message .= "$server:error\n";
1.1 raeburn 209: }
210: }
211: }
212: return $message;
213: }
214:
215: 1;
216:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>