Diff for /loncom/interface/loncommon.pm between versions 1.1075.2.127 and 1.1075.2.127.2.1

version 1.1075.2.127, 2017/04/02 03:09:27 version 1.1075.2.127.2.1, 2017/06/21 16:26:43
Line 4992  sub check_ip_acc { Line 4992  sub check_ip_acc {
     return $allowed;      return $allowed;
 }  }
   
   sub check_slotip_acc {
       my ($acc,$clientip)=@_;
       &Apache::lonxml::debug("acc is $acc");
       if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
           return 1;
       }
       my $allowed;
       my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
   
       my $name;
       my %access = (
                        allowfrom => 1,
                        denyfrom  => 0,
                    );
       my @allows;
       my @denies;
       foreach my $item (split(',',$acc)) {
           $item =~ s/^\s*//;
           $item =~ s/\s*$//;
           my $pattern;
           if ($item =~ /^\!(.+)$/) {
               push(@denies,$1);
           } else {
               push(@allows,$item);
           }
      }
      my $numdenies = scalar(@denies);
      my $numallows = scalar(@allows);
      my $count = 0;
      foreach my $pattern (@denies,@allows) {
           $count ++;
           my $acctype = 'allowfrom';
           if ($count <= $numdenies) {
               $acctype = 'denyfrom';
           }
           if ($pattern =~ /\*$/) {
               #35.8.*
               $pattern=~s/\*//;
               if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
           } 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=$access{$acctype}; }
               }
           } 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=$access{$acctype}; }
           } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
               #127.0.0.1
               if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
           } 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=$access{$acctype}; }
           }
           if ($allowed =~ /^(0|1)$/) { last; }
       }
       if ($allowed eq '') {
           if ($numdenies && !$numallows) {
               $allowed = 1;
           } else {
               $allowed = 0;
           }
       }
       return $allowed;
   }
   
 ###############################################  ###############################################
   
 =pod  =pod

Removed from v.1.1075.2.127  
changed lines
  Added in v.1.1075.2.127.2.1


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