[LON-CAPA-cvs] cvs: loncom /auth blockedaccess.pm lonacc.pm lonroles.pm /interface lonaboutme.pm lonblockingstatus.pm lonchatfetch.pm loncommon.pm lonmenu.pm lonmsg.pm lonmsgdisplay.pm lonpreferences.pm lonprintout.pm lonquickgrades.pm lonrss.pm lonsearchcourse.pm lonsimplepage.pm portfolio.pm resetpw.pm /interface/spreadsheet lonspreadsheet.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Tue Nov 30 10:55:40 EST 2021


raeburn		Tue Nov 30 15:55:40 2021 EDT

  Modified files:              
    /loncom/interface	lonaboutme.pm lonblockingstatus.pm 
                     	lonchatfetch.pm loncommon.pm lonmenu.pm lonmsg.pm 
                     	lonmsgdisplay.pm lonpreferences.pm lonprintout.pm 
                     	lonquickgrades.pm lonrss.pm lonsearchcourse.pm 
                     	lonsimplepage.pm portfolio.pm resetpw.pm 
    /loncom/interface/spreadsheet	lonspreadsheet.pm 
    /loncom/auth	blockedaccess.pm lonacc.pm lonroles.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 6955 IP-based blocking. Pass user'sIP address as third arg to 
    loncommon::blockcheck() and second to loncommon::blocking_status().
  
  
-------------- next part --------------
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.160 loncom/interface/lonaboutme.pm:1.161
--- loncom/interface/lonaboutme.pm:1.160	Sat Jan  2 21:07:36 2021
+++ loncom/interface/lonaboutme.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Personal Information Page
 #
-# $Id: lonaboutme.pm,v 1.160 2021/01/02 21:07:36 raeburn Exp $
+# $Id: lonaboutme.pm,v 1.161 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -108,6 +108,7 @@
         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
     }
 
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
     my $candisplay = 1;
     if (!$is_course) {
         if ($action ne 'portfolio') {
@@ -153,7 +154,7 @@
                 '</ul>');
         } else {
             my ($blocked,$blocktext) =
-                &Apache::loncommon::blocking_status('port',$cnum,$cdom);
+                &Apache::loncommon::blocking_status('port',$clientip,$cnum,$cdom);
             if (!$blocked) {
                 &display_portfolio_files($r,$is_course);
             } else {
@@ -241,7 +242,7 @@
         $r->print($start_page);
    }
    my ($blocked,$blocktext) =
-       &Apache::loncommon::blocking_status('about',$cnum,$cdom);
+       &Apache::loncommon::blocking_status('about',$clientip,$cnum,$cdom);
    if ($blocked) {
        if ($target eq 'tex') {
            $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
Index: loncom/interface/lonblockingstatus.pm
diff -u loncom/interface/lonblockingstatus.pm:1.19 loncom/interface/lonblockingstatus.pm:1.20
--- loncom/interface/lonblockingstatus.pm:1.19	Sat Jan  2 21:07:36 2021
+++ loncom/interface/lonblockingstatus.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # displays the blocking status table
 #
-# $Id: lonblockingstatus.pm,v 1.19 2021/01/02 21:07:36 raeburn Exp $
+# $Id: lonblockingstatus.pm,v 1.20 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -69,7 +69,8 @@
     } elsif (($activity eq 'docs') && ($origurl eq '') && ($origsymb eq '')) {
         $r->print('<p class="LC_error">'.&mt('Error: could not determine what content was blocked from access').'</p>');
     } else {
-        $r->print(&blockpage($activity,$origurl,$origsymb));
+        my $clientip = &Apache::lonnet::get_requestor_ip($r);
+        $r->print(&blockpage($activity,$origurl,$origsymb,$clientip));
     }
 
     $r->print(&Apache::loncommon::end_page());
@@ -78,7 +79,7 @@
 }
 
 sub blockpage {
-    my ($activity,$origurl,$origsymb) = @_;
+    my ($activity,$origurl,$origsymb,$clientip) = @_;
 
     # in case of a portfolio block we need to determine the owner of the files
     # we're trying to look at. This information is passed via query string.
@@ -111,7 +112,7 @@
     }
 
     # retrieve start/end of possible active blocking
-    my (%setters,$startblock,$endblock,$triggerblock);
+    my (%setters,$startblock,$endblock,$triggerblock,$by_ip,$blockdom);
 
     if ($activity eq 'docs') {
         my ($cdom,$cnum);
@@ -132,17 +133,17 @@
         }
         if ($cancheck) {
             ($startblock,$endblock,$triggerblock) =
-                &Apache::loncommon::blockcheck(\%setters,$activity,$cnum,$cdom,$origurl,1,$origsymb,'blockingstatus');
+                &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$cnum,$cdom,$origurl,1,$origsymb,'blockingstatus');
         } else {
             return '<p class="LC_info">'.&mt('Could not determine why access is blocked.').'</p>';
         }
     } else {
-        ($startblock,$endblock,$triggerblock) =
-            &Apache::loncommon::blockcheck(\%setters,$activity,$uname,$udom,$origurl,undef,$origsymb,'blockingstatus');
+        ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+            &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$uname,$udom,$origurl,undef,$origsymb,'blockingstatus');
     }
 
     # nothing to do if there's no active blocking
-    unless ($startblock && $endblock) {
+    unless (($startblock && $endblock) || ($by_ip)) {
         if ($activity eq 'docs') {
             return '<p class="LC_info">'.&mt('Content no longer blocked from access').'</p>';
         }
@@ -176,16 +177,17 @@
 
     my $description = $descs{$activity};
     if ($activity eq 'port') {
-        $description = &get_portfolio_category($uname,$udom,\%setters);
+        $description = &get_portfolio_category($uname,$udom,$by_ip,\%setters);
     }
     if ($description eq '') {
         $description = 'Communication';
     }
 
-    my $showstart = Apache::lonlocal::locallocaltime($startblock);
-    my $showend   = Apache::lonlocal::locallocaltime($endblock);
-
-    my $output;
+    my ($showstart,$showend,$output);
+    unless ($by_ip) {
+        $showstart = Apache::lonlocal::locallocaltime($startblock);
+        $showend   = Apache::lonlocal::locallocaltime($endblock);
+    }
 
     if ( ref($description) ne 'ARRAY' ) {
         #default: $description is one of the above descriptions
@@ -197,24 +199,45 @@
         } elsif (($activity eq 'printout') || ($activity eq 'passwd') ||
                  ($activity eq 'grades') || ($activity eq 'search') ||
                  ($activity eq 'about')) {
-            $output = mt( $description
-                          . ' will be unavailable between [_1] and [_2] because'
-                          . ' this functionality is being blocked.'
-                          ,$showstart, $showend);
+            if ($by_ip) {
+                $output = mt( $description
+                              . ' unavailable from your current IP address: [_1] '
+                              . 'because this functionality is being blocked for certain IP address(es).'
+                              ,$clientip);
+            } else {
+                $output = mt( $description
+                              . ' will be unavailable between [_1] and [_2] because'
+                              . ' this functionality is being blocked.'
+                              ,$showstart, $showend);
+            }
         } else {
-            $output = mt( $description
-                          . ' will be inaccessible between [_1] and [_2] because'
-                          . ' communication is being blocked.'
-                          ,$showstart, $showend);
+            if ($by_ip) {
+                $output = mt( $description
+                              . ' unavailable from your current IP address: [_1] '
+                              . 'because communication is being blocked for certain IP address(es).'
+                              ,$clientip);
+            } else {
+                $output = mt( $description
+                              . ' will be inaccessible between [_1] and [_2] because'
+                              . ' communication is being blocked.'
+                              ,$showstart, $showend);
+            }
         }
     } else {
         # @$description is is the array returned from get_portfolio_category()
         # and contains the description (e.g. "Portfolio files belonging to [_1]"
         # and the value for [_1]
-        $output = mt( $$description[0]
-                      . ' will be inaccessible between [_2] and [_3] because'
-                      . ' communication is being blocked.'
-                     ,$$description[1], $showstart, $showend);
+        if ($by_ip) {
+            $output = mt( $$description[0]
+                          . ' are inaccessible from your current IP address: [_2] '
+                          . 'because communication is being blocked for certain IP address(es).'
+                          , $$description[1], $clientip);
+        } else {
+            $output = mt( $$description[0]
+                          . ' will be inaccessible between [_2] and [_3] because'
+                          . ' communication is being blocked.'
+                          ,$$description[1], $showstart, $showend);
+        }
     }
 
     $output = "<p class=\"LC_info\">$output</p>";
@@ -226,7 +249,17 @@
             && $udom  eq $env{'user.domain'} ) 
         || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
     {
-        $output .= &build_block_table(\%setters);
+        if ($by_ip) {
+            my $showdom = &Apache::lonnet::domain($blockdom);
+            if ($showdom eq '') {
+                $showdom = $blockdom
+            }
+            $output .= '<br />'.
+                       &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.'
+                          ,$showdom);
+        } else {
+            $output .= &build_block_table(\%setters);
+        }
     }
 
     return $output;
@@ -277,7 +310,7 @@
 }
 
 sub get_portfolio_category {
-    my ($uname, $udom, $setters) = @_;
+    my ($uname, $udom, $by_ip, $setters) = @_;
 
     if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
         # user's portolfio files
@@ -289,12 +322,17 @@
 
         my $coursedesc;
 
-        foreach my $course (keys(%{$setters})) {
-            my %courseinfo = Apache::lonnet::coursedescription($course);
+        if ($by_ip) {
+            my %courseinfo = Apache::lonnet::coursedescription($udom.'_'.$uname);
             $coursedesc    = $courseinfo{'description'};
+        } else {        
+            foreach my $course (keys(%{$setters})) {
+                my %courseinfo = Apache::lonnet::coursedescription($course);
+                $coursedesc    = $courseinfo{'description'};
+            }
         }
 
-        return ["Group portfolio in the course '[_1]'", $coursedesc];
+        return ["Group portfolio files in the course '[_1]'", $coursedesc];
         
     } else {
         # different user's portfolio files
Index: loncom/interface/lonchatfetch.pm
diff -u loncom/interface/lonchatfetch.pm:1.39 loncom/interface/lonchatfetch.pm:1.40
--- loncom/interface/lonchatfetch.pm:1.39	Mon Jul 22 18:06:51 2013
+++ loncom/interface/lonchatfetch.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Chat Fetching
 #
-# $Id: lonchatfetch.pm,v 1.39 2013/07/22 18:06:51 bisitz Exp $
+# $Id: lonchatfetch.pm,v 1.40 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -177,7 +177,8 @@
         $refresh_cmd .= "&group=$group";
     }
     my $headarg;
-    my ($blocked,$blocktext) = blockstatus();
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
+    my ($blocked,$blocktext) = &blockstatus($clientip);
     if ($blocked) {
         $newstuff = $blocktext;
         $headarg =  {'only_body' => 1,};
@@ -222,9 +223,11 @@
 }
 
 sub blockstatus {
+    my ($clientip) = @_;
     my ($blocked,$output);
     my %setters;
-    my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'chat');
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+        &Apache::loncommon::blockcheck(\%setters,'chat',$clientip);
     if ($startblock && $endblock) {
         $blocked = 1;
         my $endblocktime = &Apache::lonlocal::locallocaltime($endblock);
@@ -240,6 +243,18 @@
                 $output .= &mt('Block for [_1] starts: [_2], ends [_3], set by: [_4]',$courseinfo{'description'},$openblock,$closeblock,$fullname).'<br />';
             }
         }
+    } elsif ($by_ip) {
+        $blocked = 1;
+        my $showdom = &Apache::lonnet::domain($blockdom);
+        if ($showdom eq '') {
+            $showdom = $blockdom;
+        }
+        $output = &mt('Chat Room is unavailable from your current IP address: [_1], '
+                     .'because communication is blocked for certain IP address(es).'
+                     ,$clientip).
+                  '<br />'.
+                  &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.'
+                     ,$showdom);
     }
     return ($blocked,$output);
 }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1371 loncom/interface/loncommon.pm:1.1372
--- loncom/interface/loncommon.pm:1.1371	Wed Nov 24 04:25:01 2021
+++ loncom/interface/loncommon.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1371 2021/11/24 04:25:01 raeburn Exp $
+# $Id: loncommon.pm,v 1.1372 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5201,8 +5201,76 @@
 ###############################################
 
 sub blockcheck {
-    my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
-
+    my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
+    unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
+        my ($has_evb,$check_ipaccess);
+        my $dom = $env{'user.domain'};
+        if ($env{'request.course.id'}) {
+            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            my $checkrole = "cm./$cdom/$cnum";
+            my $sec = $env{'request.course.sec'};
+            if ($sec ne '') {
+                $checkrole .= "/$sec";
+            }
+            if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+                ($env{'request.role'} !~ /^st/)) {
+                $has_evb = 1;
+            }
+            unless ($has_evb) {
+                if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
+                    ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
+                    if ($udom eq $cdom) {
+                        $check_ipaccess = 1;
+                    }
+                }
+            }
+        }
+        unless ($has_evb || $check_ipaccess) {
+            my @machinedoms = &Apache::lonnet::current_machine_domains();
+            if (($dom eq 'public') && ($activity eq 'port')) {
+                $dom = $udom;
+            }
+            if (($dom ne '') && (grep(/^\Q$dom\E$/, at machinedoms))) {
+                $check_ipaccess = 1;
+            } else {
+                my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+                my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
+                my $prim = &Apache::lonnet::domain($dom,'primary');
+                my $intdom = &Apache::lonnet::internet_dom($prim);
+                if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
+                    if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
+                        $check_ipaccess = 1;
+                    }
+                }
+            }
+        }
+        if ($check_ipaccess) {
+            my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
+            unless (defined($cached)) {
+                my %domconfig =
+                    &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
+                $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
+            }
+            if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
+                foreach my $id (keys(%{$ipaccessref})) {
+                    if (ref($ipaccessref->{$id}) eq 'HASH') {
+                        my $range = $ipaccessref->{$id}->{'ip'};
+                        if ($range) {
+                            if (&Apache::lonnet::ip_match($clientip,$range)) {
+                                if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
+                                    if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
+                                        return ('','','',$id,$dom);
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
     if (defined($udom) && defined($uname)) {
         # If uname and udom are for a course, check for blocks in the course.
         if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
@@ -5503,14 +5571,17 @@
 }
 
 sub blocking_status {
-    my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
+    my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
     my %setters;
 
 # check for active blocking
-    my ($startblock,$endblock,$triggerblock) = 
-        &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
+    if ($clientip eq '') {
+        $clientip = &Apache::lonnet::get_requestor_ip();
+    }
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = 
+        &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
     my $blocked = 0;
-    if ($startblock && $endblock) {
+    if (($startblock && $endblock) || ($by_ip)) {
         $blocked = 1;
     }
 
@@ -8858,7 +8929,8 @@
         }
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-        my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
+        my $clientip = &Apache::lonnet::get_requestor_ip();
+        my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
         if ($blocked) {
             my $checkrole = "cm./$cdom/$cnum";
             if ($env{'request.course.sec'} ne '') {
@@ -17954,7 +18026,7 @@
     }
     if (($now-$env{'request.course.timechecked'})>$interval) {
         &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
-        my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
+        my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
         if ($blocked) {
             return ();
         }
@@ -18481,7 +18553,7 @@
         if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-            my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
+            my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
             if ($blocked) {
                 my $checkrole = "cm./$cdom/$cnum";
                 if ($env{'request.course.sec'} ne '') {
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.513 loncom/interface/lonmenu.pm:1.514
--- loncom/interface/lonmenu.pm:1.513	Fri Nov 19 18:57:34 2021
+++ loncom/interface/lonmenu.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.513 2021/11/19 18:57:34 raeburn Exp $
+# $Id: lonmenu.pm,v 1.514 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1348,11 +1348,12 @@
 
     my $editbutton = '';
     my $viewsrcbutton = '';
+    my $clientip = &Apache::lonnet::get_requestor_ip();
 #
 # Determine whether or not to display 'Edit' or 'View Source' icon/button
 #
     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
-        my $blocked = &Apache::loncommon::blocking_status('about',$2,$1);
+        my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
         my $file=&Apache::lonnet::declutter($env{'request.filename'});
         ($cfile,$home,$switchserver,$forceedit,$forceview) =
             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
@@ -1470,7 +1471,7 @@
         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
             my ($sdom,$sname) = ($1,$2);
             unless (&Apache::lonnet::is_course($sdom,$sname)) {
-                my $blocked = &Apache::loncommon::blocking_status('about',$sname,$sdom);
+                my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
                 unless ($blocked) {
                     &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                             '',
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.246 loncom/interface/lonmsg.pm:1.247
--- loncom/interface/lonmsg.pm:1.246	Fri Dec 18 15:23:02 2020
+++ loncom/interface/lonmsg.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.246 2020/12/18 15:23:02 raeburn Exp $
+# $Id: lonmsg.pm,v 1.247 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -495,6 +495,7 @@
     my $hostname = &Apache::lonnet::hostname($homeserver);
     my $protocol = $Apache::lonnet::protocol{$homeserver};
     $protocol = 'http' if ($protocol ne 'https');
+#FIXME
     my $url = $protocol.'://'.$hostname.
               '/adm/email?username='.$touname.'&domain='.$toudom.
               '&display='.&escape($msgid);
@@ -539,16 +540,20 @@
         $subject = $subj;
     }
  
-    my ($blocked,$blocktext);
+    my ($blocked,$blocktext,$clientip);
+    $clientip = &Apache::lonnet::get_requestor_ip();
     if (!$crit) {
         my %setters;
-        my ($startblock,$endblock) = 
-            &Apache::loncommon::blockcheck(\%setters,'com',$touname,$toudom);
+        my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = 
+            &Apache::loncommon::blockcheck(\%setters,'com',$clientip,$touname,$toudom);
         if ($startblock && $endblock) {
             $blocked = 1;
             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
             my $showend = &Apache::lonlocal::locallocaltime($endblock);
             $blocktext = &mt_user($user_lh,'LON-CAPA messages sent to you between [_1] and [_2] will be inaccessible until the end of this time period, because you are a student in a course with an active communications block.',$showstart,$showend);
+        } elsif ($by_ip) {
+            $blocked = 1;
+            $blocktext = &mt_user($user_lh,'LON-CAPA messages sent to you will be inaccessible from your IP address [_1], because communication is being blocked for certain IP address(es).',$clientip);
         }
     }
     if ($userenv{'notifywithhtml'} ne '') {
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.193 loncom/interface/lonmsgdisplay.pm:1.194
--- loncom/interface/lonmsgdisplay.pm:1.193	Wed Nov 11 01:27:04 2020
+++ loncom/interface/lonmsgdisplay.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.193 2020/11/11 01:27:04 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.194 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -912,7 +912,7 @@
 }
 
 sub sortedmessages {
-    my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
+    my ($blocked,$startblock,$endblock,$by_ip,$numblocked,$folder,$msgstatus) = @_;
     my $suffix=&Apache::lonmsg::foldersuffix($folder);
     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
     #unpack the varibles and repack into temp for sorting
@@ -944,7 +944,8 @@
 	    push(@temp1,$content{'recuser'},$content{'recdomain'});
 	}
         # Check whether message was sent during blocking period.
-        if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
+        if (($by_ip) ||
+            (($sendtime >= $startblock) && ($sendtime <= $endblock && $endblock > 0))) {
             $$blocked{$msgid} = 'ON';
             $$numblocked ++;
         } else { 
@@ -1071,7 +1072,9 @@
     my %blocked = ();
     my %setters = ();
     my $numblocked = 0;
-    my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = 
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
     my %js_lt = &Apache::lonlocal::texthash(
                       sede => 'Select a destination folder to which the messages will be moved.',
                       nome => 'No messages have been selected to apply this action to.',
@@ -1115,7 +1118,7 @@
 ENDDISHEADER
 
     my $fsqs='&folder='.$folder;
-    my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
+    my @temp=&sortedmessages(\%blocked,$startblock,$endblock,$by_ip,\$numblocked,$folder,$msgstatus);
     my $totalnumber=$#temp+1;
     if ($totalnumber < 1) {
         $r->print('<p class="LC_info">');
@@ -1128,7 +1131,7 @@
         }
         $r->print('</p>');
         if ($numblocked > 0) {
-            $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
+            $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,$by_ip,$clientip,$blockdom,
                                          \%setters));
         }
         return;
@@ -1323,15 +1326,22 @@
 }
 
 sub blocked_in_folder {
-    my ($numblocked,$startblock,$endblock,$setters) = @_;
-    my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
-    my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
-    my $output = '<br /><br />'.
+    my ($numblocked,$startblock,$endblock,$by_ip,$clientip,$blockdom,$setters) = @_;
+    my $output;
+    if ($by_ip) {
+        $output = '<br /><br />'.
+                  &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages is blocked for your current IP address: [_2].',$numblocked,$clientip).'<br />'.
+                  &mt('Note: communication is being blocked for certain IP address(es).');
+    } else {
+        my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
+        my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
+        $output = '<br /><br />'.
                   &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock);
+    }
     #$output .= &Apache::loncommon::build_block_table($startblock,$endblock,
     #                                                 $setters);
     
-    my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
+    my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com",$clientip);
     $output .="<br /><br />".$blocktext;
 
     return $output;
@@ -2106,14 +2116,16 @@
     my %setters = ();
     my $numblocked = 0;
     my $crstype = &Apache::loncommon::course_type();
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
 
 # info to generate "next" and "previous" buttons and check if message is blocked
-    my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
-    my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = 
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
+    my @messages=&sortedmessages(\%blocked,$startblock,$endblock,$by_ip,\$numblocked,$folder,$msgstatus);
     if ( $blocked{$msgid} eq 'ON' ) {
         &printheader($r,'/adm/email',&mt('Display a Message'));
         #$r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.'));
-        my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
+        my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com",$clientip);
         $r->print("<br />".$blocktext);
         return;
     }
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.238 loncom/interface/lonpreferences.pm:1.239
--- loncom/interface/lonpreferences.pm:1.238	Sat Mar  6 19:44:12 2021
+++ loncom/interface/lonpreferences.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.238 2021/03/06 19:44:12 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.239 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1265,7 +1265,8 @@
     # This function is a bit of a mess....
     # Passwords are encrypted using londes.js (DES encryption)
     $errormessage = ($errormessage || '');
-    my ($user,$domain,$currentpass);
+    my ($user,$domain,$currentpass,$clientip);
+    $clientip = &Apache::lonnet::get_requestor_ip($r);
     &Apache::lonhtmlcommon::add_breadcrumb(
 		{ href => '/adm/preferences?action=changepass',
                   text => 'Change Password'});
@@ -1280,7 +1281,7 @@
             $caller = 'preferences';
         }
         my ($blocked,$blocktext) =
-            &Apache::loncommon::blocking_status('passwd');
+            &Apache::loncommon::blocking_status('passwd',$clientip);
         if ($blocked) {
             $r->print('<p class="LC_warning">'.$blocktext.'</p>');
             return;
@@ -1302,7 +1303,7 @@
                 $domain = $data{'domain'};
                 $currentpass = $data{'temppasswd'};
                 my ($blocked,$blocktext) =
-                    &Apache::loncommon::blocking_status('passwd',$user,$domain);
+                    &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
                 if ($blocked) {
                     $r->print('<p class="LC_warning">'.$blocktext.'</p>');
                     return;
@@ -1623,7 +1624,7 @@
 
 sub verify_and_change_password {
     my ($r,$caller,$mailtoken,$timelimit,$extrafields,$ended) = @_;
-    my ($user,$domain,$homeserver);
+    my ($user,$domain,$homeserver,$clientip);
     if ($caller eq 'reset_by_email') {
         $user       = $env{'form.uname'};
         $domain     = $env{'form.udom'};
@@ -1646,8 +1647,9 @@
         $domain     = $env{'user.domain'};
         $homeserver = $env{'user.home'};
     }
+    $clientip = &Apache::lonnet::get_requestor_ip($r);
     my ($blocked,$blocktext) =
-        &Apache::loncommon::blocking_status('passwd',$user,$domain);
+        &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
     if ($blocked) {
         $r->print('<p class="LC_warning">'.$blocktext.'</p>');
         if ($caller eq 'reset_by_email') {
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.673 loncom/interface/lonprintout.pm:1.674
--- loncom/interface/lonprintout.pm:1.673	Thu Apr 29 17:45:22 2021
+++ loncom/interface/lonprintout.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.673 2021/04/29 17:45:22 raeburn Exp $
+# $Id: lonprintout.pm,v 1.674 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3890,8 +3890,9 @@
     if ($env{'request.course.id'}) {
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $clientip = &Apache::lonnet::get_requestor_ip($r);
         my ($blocked,$blocktext) = 
-            &Apache::loncommon::blocking_status('printout',$cnum,$cdom);
+            &Apache::loncommon::blocking_status('printout',$clientip,$cnum,$cdom);
         if ($blocked) {
             my $checkrole = "cm./$cdom/$cnum";
             if ($env{'request.course.sec'} ne '') {
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.121 loncom/interface/lonquickgrades.pm:1.122
--- loncom/interface/lonquickgrades.pm:1.121	Mon Jul 19 15:48:26 2021
+++ loncom/interface/lonquickgrades.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.121 2021/07/19 15:48:26 raeburn Exp $
+# $Id: lonquickgrades.pm,v 1.122 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,8 +86,9 @@
     if ($env{'request.course.id'}) {
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $clientip = &Apache::lonnet::get_requestor_ip($r);
         my ($blocked,$blocktext) =
-            &Apache::loncommon::blocking_status('grades',$cnum,$cdom);
+            &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom);
         if ($blocked) {
             my $checkrole = "cm./$cdom/$cnum";
             if ($env{'request.course.sec'} ne '') {
Index: loncom/interface/lonrss.pm
diff -u loncom/interface/lonrss.pm:1.58 loncom/interface/lonrss.pm:1.59
--- loncom/interface/lonrss.pm:1.58	Wed Aug 14 16:06:13 2019
+++ loncom/interface/lonrss.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # RSS Feeder
 #
-# $Id: lonrss.pm,v 1.58 2019/08/14 16:06:13 raeburn Exp $
+# $Id: lonrss.pm,v 1.59 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -244,7 +244,7 @@
 }
 
 sub blocking_blogdisplay {
-    my ($uname,$udom,$html,$filterfeedname) = @_;
+    my ($uname,$udom,$html,$filterfeedname,$clientip) = @_;
     my $user = &Apache::loncommon::plainname($uname,$udom);
     if ($html) {
         $user = &Apache::loncommon::aboutmewrapper($user,$uname,$udom);
@@ -253,23 +253,29 @@
     }
     my %setters;
     my ($blocked,$output,$blockcause);
-    my ($startblock,$endblock) =
-             &Apache::loncommon::blockcheck(\%setters,'blogs');
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+             &Apache::loncommon::blockcheck(\%setters,'blogs',$clientip);
     if ($startblock && $endblock) {
         $blockcause = 'user';
+    } elsif ($by_ip) {
+        $blockcause = 'ip'; 
     } else { 
         if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
             ($startblock,$endblock) =
-                 &Apache::loncommon::blockcheck(\%setters,'blogs',
+                 &Apache::loncommon::blockcheck(\%setters,'blogs',$clientip,
                                                 $uname,$udom);
             $blockcause = 'blogowner';
         }
     }
-    if ($startblock && $endblock) {
+    if (($startblock && $endblock) || ($by_ip)) {
         $blocked = 1;
-        my $showstart = &Apache::lonlocal::locallocaltime($startblock);
-        my $showend = &Apache::lonlocal::locallocaltime($endblock);
-        $output = &mt('Blogs belonging to [_1] are unavailable from [_2] to [_3].',$user,$showstart,$showend);
+        if ($startblock && $endblock) {
+            my $showstart = &Apache::lonlocal::locallocaltime($startblock);
+            my $showend = &Apache::lonlocal::locallocaltime($endblock);
+            $output = &mt('Blogs belonging to [_1] are unavailable from [_2] to [_3].',$user,$showstart,$showend);
+        } else {
+            $output = &mt('Blogs are unavailable from your current IP address: [_1].',$clientip);
+        }
         if ($html) {$output.='<br />';}
         if ($blockcause eq 'user') {
             $output .= &mt('This is because you are a student in one or more courses in which communication is being blocked.');
@@ -277,9 +283,15 @@
                 #$output .= '<br />'.
                        #&Apache::loncommon::build_block_table($startblock,
                        #                                 $endblock,\%setters);
-                 my ($blocked, $blocktext) = Apache::loncommon::blocking_status('blogs');
+                 my ($blocked, $blocktext) = Apache::loncommon::blocking_status('blogs',$clientip);
                  $output .= '<br /><br />'.$blocktext;
             }
+        } elsif ($blockcause eq 'ip') {
+            my $showdom = &Apache::lonnet::domain($blockdom);
+            if ($showdom eq '') {
+                $showdom = $blockdom
+            }
+            $output .= &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain',$showdom);
         } else {
             $output .= &mt('This is because the blog owner is a student in one or more courses in which communication is being blocked.');
         }
@@ -325,7 +337,8 @@
     my ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
     my ($blocked,$blocktext,$disabled,$disabletext);
     if (!&Apache::lonnet::is_course($udom,$uname)) {
-        ($blocked,$blocktext) = &blocking_blogdisplay($uname,$udom,$html,$filterfeedname);
+        my $clientip = &Apache::lonnet::get_requestor_ip($r); 
+        ($blocked,$blocktext) = &blocking_blogdisplay($uname,$udom,$html,$filterfeedname,$clientip);
         if (&Apache::lonnet::usertools_access($uname,$udom,'blog')) {
             $disabled = 0;
         } else {
Index: loncom/interface/lonsearchcourse.pm
diff -u loncom/interface/lonsearchcourse.pm:1.6 loncom/interface/lonsearchcourse.pm:1.7
--- loncom/interface/lonsearchcourse.pm:1.6	Tue Sep 22 12:19:15 2020
+++ loncom/interface/lonsearchcourse.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Course
 #
-# $Id: lonsearchcourse.pm,v 1.6 2020/09/22 12:19:15 raeburn Exp $
+# $Id: lonsearchcourse.pm,v 1.7 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -331,8 +331,9 @@
     &Apache::lonnavdisplay::startContentScreen($r,'coursesearch');
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
     my ($blocked,$blocktext) =
-        &Apache::loncommon::blocking_status('search',$cnum,$cdom);
+        &Apache::loncommon::blocking_status('search',$clientip,$cnum,$cdom);
     if ($blocked) {
         my $checkrole = "cm./$cdom/$cnum";
         if ($env{'request.course.sec'} ne '') {
Index: loncom/interface/lonsimplepage.pm
diff -u loncom/interface/lonsimplepage.pm:1.106 loncom/interface/lonsimplepage.pm:1.107
--- loncom/interface/lonsimplepage.pm:1.106	Wed Sep  9 18:37:00 2020
+++ loncom/interface/lonsimplepage.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Simple Page Editor
 #
-# $Id: lonsimplepage.pm,v 1.106 2020/09/09 18:37:00 raeburn Exp $
+# $Id: lonsimplepage.pm,v 1.107 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -207,8 +207,9 @@
             }
             return OK;
         }
+        my $clientip = &Apache::lonnet::get_requestor_ip($r);
         my ($blocked,$blocktext) =
-             &Apache::loncommon::blocking_status('groups');
+             &Apache::loncommon::blocking_status('groups',$clientip);
         if ($blocked) {
             $r->print($blocktext);
             $r->print(&Apache::loncommon::end_page());
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.264 loncom/interface/portfolio.pm:1.265
--- loncom/interface/portfolio.pm:1.264	Thu Apr 29 16:18:58 2021
+++ loncom/interface/portfolio.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.264 2021/04/29 16:18:58 raeburn Exp $
+# $Id: portfolio.pm,v 1.265 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2769,8 +2769,9 @@
     }
     $r->rflush();
     # Check if access to portfolio is blocked by one or more blocking events in courses.
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
     my ($blocked,$blocktext) = 
-        &Apache::loncommon::blocking_status('port',$uname,$udom);
+        &Apache::loncommon::blocking_status('port',$clientip,$uname,$udom);
     if ($blocked) {
         my $evade_block;
         # If portfolio display is in a window popped up from a "Select Portfolio Files"
Index: loncom/interface/resetpw.pm
diff -u loncom/interface/resetpw.pm:1.49 loncom/interface/resetpw.pm:1.50
--- loncom/interface/resetpw.pm:1.49	Tue May  4 18:47:36 2021
+++ loncom/interface/resetpw.pm	Tue Nov 30 15:55:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow access to password changing via a token sent to user's e-mail. 
 #
-# $Id: resetpw.pm,v 1.49 2021/05/04 18:47:36 raeburn Exp $
+# $Id: resetpw.pm,v 1.50 2021/11/30 15:55:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,6 +115,7 @@
         }
     }
     my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
     my $token = $env{'form.token'};
     my $useremail = $env{'form.useremail'};
     if (($udom ne '') && (!$otherinst) && (!$token)) {
@@ -292,7 +293,7 @@
     my $output;
     if ($token) {
         $r->print($header);
-        &reset_passwd($r,$token,$contact_name,$contact_email,\%passwdconf);
+        &reset_passwd($r,$token,$contact_name,$contact_email,$clientip,\%passwdconf);
         $r->print(&Apache::loncommon::end_page());
         return OK;
     } elsif ($udom) {
@@ -327,7 +328,7 @@
                 my $authtype = &Apache::lonnet::queryauthenticate($uname,$udom);
                 if ($authtype =~ /^internal/) {
                     my ($blocked,$blocktext) =
-                        &Apache::loncommon::blocking_status('passwd',$uname,$udom);
+                        &Apache::loncommon::blocking_status('passwd',$clentip,$uname,$udom);
                     if ($blocked) {
                         $output = '<p class="LC_warning">'.$blocktext.'</p>'
                                   .&display_actions($contact_email,$domdesc);
@@ -604,7 +605,7 @@
 }
 
 sub reset_passwd {
-    my ($r,$token,$contact_name,$contact_email,$passwdconf) = @_;
+    my ($r,$token,$contact_name,$contact_email,$clientip,$passwdconf) = @_;
     return unless (ref($passwdconf) eq 'HASH');
     my %data = &Apache::lonnet::tmpget($token);
     my $now = time;
@@ -625,7 +626,7 @@
         }
         my $reqtime = &Apache::lonlocal::locallocaltime($data{'time'});
         my ($blocked,$blocktext) =
-            &Apache::loncommon::blocking_status('passwd',$data{'username'},$data{'domain'});
+            &Apache::loncommon::blocking_status('passwd',$clientip,$data{'username'},$data{'domain'});
         if ($blocked) {
             $r->print('<p class="LC_warning">'.$blocktext.'</p>');
             return;
@@ -792,6 +793,7 @@
                     delete($env{'form.udom'});
                 }
             } else {
+#FIXME
                 $r->print(&mt('The token included in an e-mail sent to you [_1] has been verified, so you may now proceed to reset the password for your LON-CAPA account.',$reqtime).'<br /><br />');
                 if (keys(%formfields)) {
                     if (($formfields{'username'}) && ($formfields{'email'})) {
Index: loncom/interface/spreadsheet/lonspreadsheet.pm
diff -u loncom/interface/spreadsheet/lonspreadsheet.pm:1.66 loncom/interface/spreadsheet/lonspreadsheet.pm:1.67
--- loncom/interface/spreadsheet/lonspreadsheet.pm:1.66	Mon Aug 10 19:28:21 2020
+++ loncom/interface/spreadsheet/lonspreadsheet.pm	Tue Nov 30 15:55:39 2021
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.66 2020/08/10 19:28:21 raeburn Exp $
+# $Id: lonspreadsheet.pm,v 1.67 2021/11/30 15:55:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -247,8 +247,9 @@
     if ($env{'request.course.id'}) {
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $clientip = &Apache::lonnet::get_requestor_ip($r);
         my ($blocked,$blocktext) =
-            &Apache::loncommon::blocking_status('grades',$cnum,$cdom);
+            &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom);
         if ($blocked) {
             my $checkrole = "cm./$cdom/$cnum";
             if ($env{'request.course.sec'} ne '') {
Index: loncom/auth/blockedaccess.pm
diff -u loncom/auth/blockedaccess.pm:1.6 loncom/auth/blockedaccess.pm:1.7
--- loncom/auth/blockedaccess.pm:1.6	Thu Oct  1 10:16:33 2020
+++ loncom/auth/blockedaccess.pm	Tue Nov 30 15:55:40 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Information about blocking status for Portfolio files
 #
-# $Id: blockedaccess.pm,v 1.6 2020/10/01 10:16:33 raeburn Exp $
+# $Id: blockedaccess.pm,v 1.7 2021/11/30 15:55:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -44,13 +44,14 @@
     &Apache::lonlocal::get_language_handle($r);
     my $ver_origurl = $r->uri;
     my $origurl = &Apache::lonnet::deversion($r->uri);
-    my ($blocked,$blocktext);
+    my ($blocked,$blocktext,$clientip);
+    $clientip = &Apache::lonnet::get_requestor_ip($r);
 
     if (&Apache::lonnet::is_portfolio_url($origurl)) {
         my ($type,$udom,$uname,$file_name,$group) = 
 	    &Apache::lonnet::parse_portfolio_url($origurl);
         ($blocked,$blocktext) = 
-            &Apache::loncommon::blocking_status('port',$uname,$udom);
+            &Apache::loncommon::blocking_status('port',$clientip,$uname,$udom);
     } else {
         if ($env{'request.course.id'}) {
             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -65,7 +66,7 @@
                 }
             }
             ($blocked,$blocktext) =
-                &Apache::loncommon::blocking_status('docs',$cnum,$cdom,$url,1,$symb,'blockedaccess');
+                &Apache::loncommon::blocking_status('docs',$clientip,$cnum,$cdom,$url,1,$symb,'blockedaccess');
         }
     }
     if ($blocked) {
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.200 loncom/auth/lonacc.pm:1.201
--- loncom/auth/lonacc.pm:1.200	Wed Nov  3 01:04:02 2021
+++ loncom/auth/lonacc.pm	Tue Nov 30 15:55:40 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.200 2021/11/03 01:04:02 raeburn Exp $
+# $Id: lonacc.pm,v 1.201 2021/11/30 15:55:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -820,7 +820,8 @@
                         }
                     }
                 }
-                $access=&Apache::lonnet::allowed('bre',$requrl,'','','','','',$nodeeplinkcheck);
+                my $clientip = &Apache::lonnet::get_requestor_ip($r);
+                $access=&Apache::lonnet::allowed('bre',$requrl,'','',$clientip,'','',$nodeeplinkcheck);
             }
         }
         if ($check_block) {
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.358 loncom/auth/lonroles.pm:1.359
--- loncom/auth/lonroles.pm:1.358	Tue Nov 30 14:16:13 2021
+++ loncom/auth/lonroles.pm	Tue Nov 30 15:55:40 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.358 2021/11/30 14:16:13 raeburn Exp $
+# $Id: lonroles.pm,v 1.359 2021/11/30 15:55:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -277,7 +277,8 @@
         $update = $then;
     }
 
-    my ($norolelist,$blocked_by_ip,$blocked_type,$blocked_ipaddr);
+    my ($norolelist,$blocked_by_ip,$blocked_type,$clientip);
+    $clientip = &Apache::lonnet::get_requestor_ip($r);
     if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -358,13 +359,12 @@
                         $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$cdom,$domconfig{'ipaccess'},1800);
                     }
                     if (ref($ipaccessref) eq 'HASH') {
-                        my $remote_ip = &Apache::lonnet::get_requestor_ip();
                         foreach my $id (keys(%{$ipaccessref})) {
                             if (ref($ipaccessref->{$id}) eq 'HASH') {
                                 my $range = $ipaccessref->{$id}->{'ip'};
                                 if ($range) {
                                     my $type = 'exclude';
-                                    if (&Apache::lonnet::ip_match($remote_ip,$range)) {
+                                    if (&Apache::lonnet::ip_match($clientip,$range)) {
                                         $type = 'include';
                                     }
                                     if (ref($ipaccessref->{$id}->{'courses'}) eq 'HASH') {
@@ -386,9 +386,6 @@
                                 }
                             }
                         }
-                        unless ($showrole) {
-                            $blocked_ipaddr = $remote_ip;
-                        }
                     }
                 }
             }
@@ -783,7 +780,7 @@
                         $r->rflush();
                         my ($msg,$blockcrit,$critmsg_check);
                         $critmsg_check = 1;
-                        $blockcrit = &Apache::loncommon::blocking_status('alert',$cnum,$cdom,undef,1);
+                        $blockcrit = &Apache::loncommon::blocking_status('alert',$clientip,$cnum,$cdom,undef,1);
                         if ($blockcrit) {
                             my $checkrole = "cm./$cdom/$cnum";
                             if ($csec ne '') {
@@ -1354,7 +1351,7 @@
             }
             $r->print('<h3><span class="LC_error">'.
                       &mt('The [_1] you selected is not available for access with a [_2] role from your current IP address: [_3].',
-                          lc($blocked_type),$blocked_role,$blocked_ipaddr).
+                          lc($blocked_type),$blocked_role,$clientip).
                       '</span></h3>');
         }
     }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1472 loncom/lonnet/perl/lonnet.pm:1.1473
--- loncom/lonnet/perl/lonnet.pm:1.1472	Tue Nov 30 07:01:30 2021
+++ loncom/lonnet/perl/lonnet.pm	Tue Nov 30 15:55:40 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1472 2021/11/30 07:01:30 raeburn Exp $
+# $Id: lonnet.pm,v 1.1473 2021/11/30 15:55:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7583,15 +7583,15 @@
     if ($result) {
         my %setters;
         if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
-            my ($startblock,$endblock) =
-                &Apache::loncommon::blockcheck(\%setters,'port',$unum,$udom);
-            if ($startblock && $endblock) {
+            my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+                &Apache::loncommon::blockcheck(\%setters,'port',$clientip,$unum,$udom);
+            if (($startblock && $endblock) || ($by_ip)) {
                 return 'B';
             }
         } else {
-            my ($startblock,$endblock) =
-                &Apache::loncommon::blockcheck(\%setters,'port');
-            if ($startblock && $endblock) {
+            my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+                &Apache::loncommon::blockcheck(\%setters,'port',$clientip);
+            if (($startblock && $endblock) || ($by_ip)) {
                 return 'B';
             }
         }
@@ -8174,9 +8174,9 @@
     if (($space=~/^(uploaded|editupload)$/) && ($env{'user.name'} eq $name) && 
 	($env{'user.domain'} eq $domain) && ('portfolio' eq $dir[0])) {
         my %setters;
-        my ($startblock,$endblock) = 
-            &Apache::loncommon::blockcheck(\%setters,'port');
-        if ($startblock && $endblock) {
+        my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = 
+            &Apache::loncommon::blockcheck(\%setters,'port',$clientip);
+        if (($startblock && $endblock) || ($by_ip)) {
             return 'B';
         } else {
             return 'F';


More information about the LON-CAPA-cvs mailing list