Diff for /loncom/homework/lonhomework.pm between versions 1.296 and 1.297

version 1.296, 2008/07/28 05:26:00 version 1.297, 2008/09/05 17:43:32
Line 209  sub proctor_checked_in { Line 209  sub proctor_checked_in {
     return 0;      return 0;
 }  }
   
 sub check_ip_acc {  
     my ($acc)=@_;  
     &Apache::lonxml::debug("acc is $acc");  
     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {   
  return 1;  
     }  
     my $allowed=0;  
     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};  
   
     my $name;  
     foreach my $pattern (split(',',$acc)) {  
  $pattern =~ s/^\s*//;  
  $pattern =~ s/\s*$//;  
  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;  
 }  
   
 sub check_slot_access {  sub check_slot_access {
     my ($id,$type)=@_;      my ($id,$type)=@_;
   
Line 307  sub check_slot_access { Line 255  sub check_slot_access {
  &Apache::lonhomework::showhash(%slot);   &Apache::lonhomework::showhash(%slot);
  if ($slot{'starttime'} < time &&   if ($slot{'starttime'} < time &&
     $slot{'endtime'} > time &&      $slot{'endtime'} > time &&
     &check_ip_acc($slot{'ip'})) {      &Apache::loncommon::check_ip_acc($slot{'ip'})) {
     &Apache::lonxml::debug("$slot is good");      &Apache::lonxml::debug("$slot is good");
     $slotstatus='NEEDS_CHECKIN';      $slotstatus='NEEDS_CHECKIN';
     $returned_slot=\%slot;      $returned_slot=\%slot;
Line 421  sub check_access { Line 369  sub check_access {
     #if ($env{'request.state'} ne "construct" && $symb ne '') {      #if ($env{'request.state'} ne "construct" && $symb ne '') {
     if ($env{'request.state'} ne "construct") {      if ($env{'request.state'} ne "construct") {
         my $idacc = &Apache::lonnet::EXT("resource.$id.acc");          my $idacc = &Apache::lonnet::EXT("resource.$id.acc");
  my $allowed=&check_ip_acc($idacc);   my $allowed=&Apache::loncommon::check_ip_acc($idacc);
  if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {   if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
     $status='INVALID_ACCESS';      $status='INVALID_ACCESS';
     $date=&mt("can not be accessed from your location.");      $date=&mt("can not be accessed from your location.");

Removed from v.1.296  
changed lines
  Added in v.1.297


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>