version 1.1377, 2018/05/28 23:26:21
|
version 1.1384, 2018/09/20 14:17:11
|
Line 230 sub get_server_distarch {
|
Line 230 sub get_server_distarch {
|
} |
} |
|
|
sub get_servercerts_info { |
sub get_servercerts_info { |
my ($lonhost,$context) = @_; |
my ($lonhost,$hostname,$context) = @_; |
|
return if ($lonhost eq ''); |
|
if ($hostname eq '') { |
|
$hostname = &hostname($lonhost); |
|
} |
|
return if ($hostname eq ''); |
my ($rep,$uselocal); |
my ($rep,$uselocal); |
if (grep { $_ eq $lonhost } ¤t_machine_ids()) { |
if (grep { $_ eq $lonhost } ¤t_machine_ids()) { |
$uselocal = 1; |
$uselocal = 1; |
Line 250 sub get_servercerts_info {
|
Line 255 sub get_servercerts_info {
|
} |
} |
} |
} |
if ($uselocal) { |
if ($uselocal) { |
$rep = LONCAPA::Lond::server_certs(\%perlvar); |
$rep = LONCAPA::Lond::server_certs(\%perlvar,$lonhost,$hostname); |
} else { |
} else { |
$rep=&reply('servercerts',$lonhost); |
$rep=&reply('servercerts',$lonhost); |
} |
} |
my ($result,%returnhash); |
my ($result,%returnhash); |
if (defined($lonhost)) { |
|
if (!defined(&hostname($lonhost))) { |
|
return; |
|
} |
|
} |
|
if (($rep=~/^(refused|rejected|error)/) || ($rep eq 'con_lost') || |
if (($rep=~/^(refused|rejected|error)/) || ($rep eq 'con_lost') || |
($rep eq 'unknown_cmd')) { |
($rep eq 'unknown_cmd')) { |
$result = $rep; |
$result = $rep; |
Line 652 sub transfer_profile_to_env {
|
Line 652 sub transfer_profile_to_env {
|
sub check_for_valid_session { |
sub check_for_valid_session { |
my ($r,$name,$userhashref,$domref) = @_; |
my ($r,$name,$userhashref,$domref) = @_; |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
my ($linkname,$pubname); |
my ($lonidsdir,$linkname,$pubname,$secure,$lonid); |
if ($name eq '') { |
if ($name eq 'lonDAV') { |
$name = 'lonID'; |
$lonidsdir=$r->dir_config('lonDAVsessDir'); |
|
} else { |
|
$lonidsdir=$r->dir_config('lonIDsDir'); |
|
if ($name eq '') { |
|
$name = 'lonID'; |
|
} |
|
} |
|
if ($name eq 'lonID') { |
|
$secure = 'lonSID'; |
$linkname = 'lonLinkID'; |
$linkname = 'lonLinkID'; |
$pubname = 'lonPubID'; |
$pubname = 'lonPubID'; |
} |
if (exists($cookies{$secure})) { |
my $lonid=$cookies{$name}; |
$lonid=$cookies{$secure}; |
if (!$lonid) { |
} elsif (exists($cookies{$name})) { |
if (($name eq 'lonID') && ($ENV{'SERVER_PORT'} != 443) && ($linkname)) { |
$lonid=$cookies{$name}; |
|
} elsif (exists($cookies{$linkname})) { |
$lonid=$cookies{$linkname}; |
$lonid=$cookies{$linkname}; |
|
} elsif (exists($cookies{$pubname})) { |
|
$lonid=$cookies{$pubname}; |
} |
} |
if (!$lonid) { |
} else { |
if (($name eq 'lonID') && ($pubname)) { |
$lonid=$cookies{$name}; |
$lonid=$cookies{$pubname}; |
|
} |
|
} |
|
} |
} |
return undef if (!$lonid); |
return undef if (!$lonid); |
|
|
my $handle=&LONCAPA::clean_handle($lonid->value); |
my $handle=&LONCAPA::clean_handle($lonid->value); |
my $lonidsdir; |
if (-l "$lonidsdir/$handle.id") { |
if ($name eq 'lonDAV') { |
my $link = readlink("$lonidsdir/$handle.id"); |
$lonidsdir=$r->dir_config('lonDAVsessDir'); |
if ((-e $link) && ($link =~ m{^\Q$lonidsdir\E/(.+)\.id$})) { |
} else { |
$handle = $1; |
$lonidsdir=$r->dir_config('lonIDsDir'); |
} |
} |
} |
if (!-e "$lonidsdir/$handle.id") { |
if (!-e "$lonidsdir/$handle.id") { |
if ((ref($domref)) && ($name eq 'lonID') && |
if ((ref($domref)) && ($name eq 'lonID') && |
Line 3189 sub ssi {
|
Line 3197 sub ssi {
|
|
|
$request->header(Cookie => $ENV{'HTTP_COOKIE'}); |
$request->header(Cookie => $ENV{'HTTP_COOKIE'}); |
my $lonhost = $perlvar{'lonHostID'}; |
my $lonhost = $perlvar{'lonHostID'}; |
my $response= &LONCAPA::LWPReq::makerequest($lonhost,$request,'',\%perlvar); |
my $response= &LONCAPA::LWPReq::makerequest($lonhost,$request,'',\%perlvar, |
|
'','','',1); |
|
|
if (wantarray) { |
if (wantarray) { |
return ($response->content, $response); |
return ($response->content, $response); |
Line 10033 sub is_course {
|
Line 10042 sub is_course {
|
my ($cdom, $cnum) = scalar(@_) == 1 ? |
my ($cdom, $cnum) = scalar(@_) == 1 ? |
($_[0] =~ /^($match_domain)_($match_courseid)$/) : @_; |
($_[0] =~ /^($match_domain)_($match_courseid)$/) : @_; |
|
|
return unless $cdom and $cnum; |
return unless (($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)); |
|
my $uhome=&homeserver($cnum,$cdom); |
my %courses = &courseiddump($cdom, '.', 1, '.', '.', $cnum, undef, undef, |
my $iscourse; |
'.'); |
if (grep { $_ eq $uhome } current_machine_ids()) { |
|
$iscourse = &LONCAPA::Lond::is_course($cdom,$cnum); |
return unless(exists($courses{$cdom.'_'.$cnum})); |
} else { |
|
my $hashid = $cdom.':'.$cnum; |
|
($iscourse,my $cached) = &is_cached_new('iscourse',$hashid); |
|
unless (defined($cached)) { |
|
my %courses = &courseiddump($cdom, '.', 1, '.', '.', |
|
$cnum,undef,undef,'.'); |
|
$iscourse = 0; |
|
if (exists($courses{$cdom.'_'.$cnum})) { |
|
$iscourse = 1; |
|
} |
|
&do_cache_new('iscourse',$hashid,$iscourse,3600); |
|
} |
|
} |
|
return unless ($iscourse); |
return wantarray ? ($cdom, $cnum) : $cdom.'_'.$cnum; |
return wantarray ? ($cdom, $cnum) : $cdom.'_'.$cnum; |
} |
} |
|
|
Line 13511 sub get_dns {
|
Line 13533 sub get_dns {
|
} |
} |
|
|
my %alldns; |
my %alldns; |
open(my $config,"<","$perlvar{'lonTabDir'}/hosts.tab"); |
if (open(my $config,"<","$perlvar{'lonTabDir'}/hosts.tab")) { |
foreach my $dns (<$config>) { |
foreach my $dns (<$config>) { |
next if ($dns !~ /^\^(\S*)/x); |
next if ($dns !~ /^\^(\S*)/x); |
my $line = $1; |
my $line = $1; |
my ($host,$protocol) = split(/:/,$line); |
my ($host,$protocol) = split(/:/,$line); |
if ($protocol ne 'https') { |
if ($protocol ne 'https') { |
$protocol = 'http'; |
$protocol = 'http'; |
|
} |
|
$alldns{$host} = $protocol; |
} |
} |
$alldns{$host} = $protocol; |
close($config); |
} |
} |
while (%alldns) { |
while (%alldns) { |
my ($dns) = sort { $b cmp $a } keys(%alldns); |
my ($dns) = sort { $b cmp $a } keys(%alldns); |
Line 13527 sub get_dns {
|
Line 13551 sub get_dns {
|
my $response = &LONCAPA::LWPReq::makerequest('',$request,'',\%perlvar,30,0); |
my $response = &LONCAPA::LWPReq::makerequest('',$request,'',\%perlvar,30,0); |
delete($alldns{$dns}); |
delete($alldns{$dns}); |
next if ($response->is_error()); |
next if ($response->is_error()); |
my @content = split("\n",$response->content); |
if ($url eq '/adm/dns/loncapaCRL') { |
unless ($nocache) { |
return &$func($response); |
&do_cache_new('dns',$url,\@content,30*24*60*60); |
} else { |
} |
my @content = split("\n",$response->content); |
&$func(\@content,$hashref); |
unless ($nocache) { |
return; |
&do_cache_new('dns',$url,\@content,30*24*60*60); |
|
} |
|
&$func(\@content,$hashref); |
|
return; |
|
} |
|
} |
|
my $which = (split('/',$url,4))[3]; |
|
if ($which eq 'loncapaCRL') { |
|
my $diskfile = "$perlvar{'lonCertificateDirectory'}/$perlvar{'lonnetCertRevocationList'}"; |
|
if (-e $diskfile) { |
|
&logthis("unable to contact DNS, on disk file $diskfile not updated"); |
|
} else { |
|
&logthis("unable to contact DNS, no on disk file $diskfile available"); |
|
} |
|
} else { |
|
&logthis("unable to contact DNS defaulting to on disk file dns_$which.tab\n"); |
|
if (open(my $config,"<","$perlvar{'lonTabDir'}/dns_$which.tab")) { |
|
my @content = <$config>; |
|
close($config); |
|
&$func(\@content,$hashref); |
|
} |
} |
} |
close($config); |
|
my $which = (split('/',$url))[3]; |
|
&logthis("unable to contact DNS defaulting to on disk file dns_$which.tab\n"); |
|
open($config,"<","$perlvar{'lonTabDir'}/dns_$which.tab"); |
|
my @content = <$config>; |
|
&$func(\@content,$hashref); |
|
return; |
return; |
} |
} |
|
|
Line 13599 sub fetch_dns_checksums {
|
Line 13637 sub fetch_dns_checksums {
|
return \%checksums; |
return \%checksums; |
} |
} |
|
|
|
sub fetch_crl_pemfile { |
|
return &get_dns("/adm/dns/loncapaCRL",\&save_crl_pem,1,1); |
|
} |
|
|
|
sub save_crl_pem { |
|
my ($response) = @_; |
|
my ($msg,$hadchanges); |
|
if (ref($response)) { |
|
my $now = time; |
|
my $lonca = $perlvar{'lonCertificateDirectory'}.'/'.$perlvar{'lonnetCertificateAuthority'}; |
|
my $tmpcrl = $tmpdir.'/'.$perlvar{'lonnetCertRevocationList'}.'_'.$now.'.'.$$.'.tmp'; |
|
if (open(my $fh,'>',"$tmpcrl")) { |
|
print $fh $response->content; |
|
close($fh); |
|
if (-e $lonca) { |
|
if (open(PIPE,"openssl crl -in $tmpcrl -inform pem -CAfile $lonca -noout 2>&1 |")) { |
|
my $check = <PIPE>; |
|
close(PIPE); |
|
chomp($check); |
|
if ($check eq 'verify OK') { |
|
my $dest = "$perlvar{'lonCertificateDirectory'}/$perlvar{'lonnetCertRevocationList'}"; |
|
my $backup; |
|
if (-e $dest) { |
|
if (&File::Copy::move($dest,"$dest.bak")) { |
|
$backup = 'ok'; |
|
} |
|
} |
|
if (&File::Copy::move($tmpcrl,$dest)) { |
|
$msg = 'ok'; |
|
if ($backup) { |
|
my (%oldnums,%newnums); |
|
if (open(PIPE, "openssl crl -inform PEM -text -noout -in $dest.bak |grep 'Serial Number' |")) { |
|
while (<PIPE>) { |
|
$oldnums{(split(/:/))[1]} = 1; |
|
} |
|
close(PIPE); |
|
} |
|
if (open(PIPE, "openssl crl -inform PEM -text -noout -in $dest |grep 'Serial Number' |")) { |
|
while(<PIPE>) { |
|
$newnums{(split(/:/))[1]} = 1; |
|
} |
|
close(PIPE); |
|
} |
|
foreach my $key (sort {$b <=> $a } (keys(%newnums))) { |
|
unless (exists($oldnums{$key})) { |
|
$hadchanges = 1; |
|
last; |
|
} |
|
} |
|
unless ($hadchanges) { |
|
foreach my $key (sort {$b <=> $a } (keys(%oldnums))) { |
|
unless (exists($newnums{$key})) { |
|
$hadchanges = 1; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
unlink($tmpcrl); |
|
} |
|
} else { |
|
unlink($tmpcrl); |
|
} |
|
} else { |
|
unlink($tmpcrl); |
|
} |
|
} |
|
} |
|
return ($msg,$hadchanges); |
|
} |
|
|
# ------------------------------------------------------------ Read domain file |
# ------------------------------------------------------------ Read domain file |
{ |
{ |
my $loaded; |
my $loaded; |