--- loncom/homework/lonhomework.pm 2003/09/19 20:29:29 1.150 +++ loncom/homework/lonhomework.pm 2003/10/14 15:47:50 1.153 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.150 2003/09/19 20:29:29 albertel Exp $ +# $Id: lonhomework.pm,v 1.153 2003/10/14 15:47:50 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -147,6 +147,51 @@ sub send_footer { $Apache::lonxml::browse=''; +sub check_ip_acc { + my ($acc)=@_; + if (!defined($acc)) { return 1; } + my $allowed=0; + my $ip=$ENV{'REMOTE_ADDR'}; + my $name; + foreach my $pattern (split(',',$acc)) { + if ($pattern =~ /\*$/) { + #35.8.* + $pattern=~s/\*//; + if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } + } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { + #35.8.3.[34-56] + my $low=$2; + my $high=$3; + $pattern=$1; + if ($ip =~ /^\Q$pattern\E/) { + my $last=(split(/\./,$ip))[3]; + if ($last <=$high && $last >=$low) { $allowed=1; } + } + } elsif ($pattern =~ /^\*/) { + #*.msu.edu + $pattern=~s/\*//; + if (!defined($name)) { + use Socket; + my $netaddr=inet_aton($ip); + ($name)=gethostbyaddr($netaddr,AF_INET); + } + if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } + } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { + #127.0.0.1 + if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } + } else { + #some.name.com + if (!defined($name)) { + use Socket; + my $netaddr=inet_aton($ip); + ($name)=gethostbyaddr($netaddr,AF_INET); + } + if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } + } + if ($allowed) { last; } + } + return $allowed; +} # JB, 9/24/2002: Any changes in this function may require a change # in lonnavmaps::resource::getDateStatus. sub check_access { @@ -168,6 +213,14 @@ sub check_access { &Apache::lonxml::debug("checking for part :$id:"); &Apache::lonxml::debug("time:".time); + + my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc")); + if (!$allowed) { + $status='INVALID_ACCESS'; + $date=&mt("may be open from a different computer."); + return($status,$date); + } + foreach $temp ("opendate","duedate","answerdate") { $lastdate = $date; $date = &Apache::lonnet::EXT("resource.$id.$temp"); @@ -307,11 +360,10 @@ sub setuppermissions { sub setupheader { my $request=$_[0]; if ($ENV{'browser.mathml'}) { - $request->content_type('text/xml'); + &Apache::loncommon::content_type($request,'text/xml'); } else { - $request->content_type('text/html'); + &Apache::loncommon::content_type($request,'text/html'); } - $request->content_encoding('UTF-8'); if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { &Apache::loncommon::no_cache($request); }