[LON-CAPA-cvs] cvs: loncom /interface loncommunicate.pm lonfeedback.pm lonmsg.pm lonmsgdisplay.pm

raeburn raeburn at source.lon-capa.org
Tue Jan 18 12:33:13 EST 2022


raeburn		Tue Jan 18 17:33:13 2022 EDT

  Modified files:              
    /loncom/interface	loncommunicate.pm lonmsg.pm lonmsgdisplay.pm 
                     	lonfeedback.pm 
  Log:
  Bug 6955
   -  If IP-based blocking set in domain config is in effect for user's
      current IP address, and 'Messaging 'is among blocked functions:
     (a) 'Send Feedback' (in course context), for resource(s) which allow it
         is only messaging mechanism available to users with out 'evb' priv.
     (b) Subject and Content for messages sent to instructor(s) via 'Send Feedback'
         are replaced in user's Sent Folder with: "Not shown due to IP block".
  
  
-------------- next part --------------
Index: loncom/interface/loncommunicate.pm
diff -u loncom/interface/loncommunicate.pm:1.47 loncom/interface/loncommunicate.pm:1.48
--- loncom/interface/loncommunicate.pm:1.47	Wed Apr 18 19:56:59 2012
+++ loncom/interface/loncommunicate.pm	Tue Jan 18 17:33:13 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Communicate
 #
-# $Id: loncommunicate.pm,v 1.47 2012/04/18 19:56:59 raeburn Exp $
+# $Id: loncommunicate.pm,v 1.48 2022/01/18 17:33:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,7 +46,23 @@
             $usertype = 'member';
         }   
     }
-	
+
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
+    my %setters;
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
+    if ($by_ip) {
+        my $showdom = &Apache::lonnet::domain($blockdom);
+        if ($showdom eq '') {
+            $showdom = $blockdom;
+        }
+        $r->print('<p class="LC_warning">'.
+                  &mt('Sending of LON-CAPA messages is blocked for your current IP address: [_1].',$clientip).'</p>'.
+                  '<ul><li>'.&mt('Note: communication is being blocked for certain IP address(es).').
+                  '</li><li>'.
+                  &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.',$showdom).
+                  '</li></ul><br />');
+    }
 
 # ------------------------------------------------------------------------ Menu
     my ($can_srm,$can_dcm,$can_dff);
@@ -66,11 +82,13 @@
                                            $env{'request.course.sec'}))) {
             $can_dff = 1;
         }
-    }   
+    }
 
-	my @reports = (
-	    {categorytitle => 'Send Messages',
-         items => [
+    my @reports;
+    unless ($by_ip) {
+        @reports = (
+            {categorytitle => 'Send Messages',
+             items => [
             {url => '/adm/email?compose=individual',
 			 permission => 'F',
 			 icon => 'mail-message-new.png',
@@ -89,12 +107,13 @@
              icon => 'fromfile.png',
              linktext => 'New Messages from File',
 			 linktitle => 'Create a message from file and send to users.'},
-         ]},
-		);
+             ]},
+        );
+    }
 		
-		if ($can_dff || $can_dcm ){
-		push(@reports,{categorytitle => 'Message Administration',
-         items => [
+    if ($can_dff || $can_dcm ){
+        push(@reports,{categorytitle => 'Message Administration',
+             items => [
             {url => '/adm/email?recordftf=query',
 			 permission => "$can_dff",
              icon => 'messalog.png',
@@ -107,10 +126,12 @@
              icon => 'comblock.png',
 			 linktext => 'Communication Blocking',
              linktitle => "Blocking of $usertype communication during exams."},
-         ]});
-        }
-$r->print(&Apache::lonhtmlcommon::generate_menu(@reports));
-
+             ]});
+    }
+    if (@reports) {
+        $r->print(&Apache::lonhtmlcommon::generate_menu(@reports));
+    }
+    return;
 }
 
 sub handler {
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.247 loncom/interface/lonmsg.pm:1.248
--- loncom/interface/lonmsg.pm:1.247	Tue Nov 30 15:55:37 2021
+++ loncom/interface/lonmsg.pm	Tue Jan 18 17:33:13 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.247 2021/11/30 15:55:37 raeburn Exp $
+# $Id: lonmsg.pm,v 1.248 2022/01/18 17:33:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -120,7 +120,7 @@
 
 New routine that respects "forward" and calls old routine
 
-=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore, $recipid, $attachmenturl, $permresults)>: 
+=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $toperm, $sentmessage, $nosentstore, $recipid, $attachmenturl, $permresults, $senthide)>: 
     Sends a critical message $message to the $user at $domain.  If $sendback
     is true,  a receipt will be sent to the current user when $user receives 
     the message.
@@ -148,7 +148,7 @@
 
 =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
        $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
-       $error,$nosentstore,$recipid,$permresults)>:
+       $error,$nosentstore,$recipid,$permresults,$senthide)>:
  Sends a message to the  $user at $domain, with subject $subject and message $message.
 
     Additionally it will check if the user has a Forwarding address
@@ -218,8 +218,8 @@
 
 
 sub packagemsg {
-    my ($subject,$message,$citation,$baseurl,$attachmenturl,
-	$recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error,$recipid)=@_;
+    my ($subject,$message,$citation,$baseurl,$attachmenturl,$recuser,$recdomain,
+	$msgid,$type,$crsmsgid,$symb,$error,$recipid,$senthide,$origmsgid)=@_;
     $message =&HTML::Entities::encode($message,'<>&"');
     $citation=&HTML::Entities::encode($citation,'<>&"');
     $subject =&HTML::Entities::encode($subject,'<>&"');
@@ -229,6 +229,22 @@
     #remove machine specification
     $attachmenturl =~ s|^https?://[^/]+/|/|;
     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
+    if ($senthide) {
+        foreach my $item ($subject,$message) {
+            if ($item ne '') {
+                $item = 'Not shown due to IP block';
+            }
+        }
+        if ($attachmenturl ne '') {
+            $attachmenturl = '';
+        }
+        if ($citation ne '') {
+            $citation = '';
+        }
+        if ($msgid ne '') {
+            $msgid = '';
+        }
+    }
     my $course_context = &get_course_context();
     my $now=time;
     my $ip = &Apache::lonnet::get_requestor_ip();
@@ -319,6 +335,9 @@
             }
         }
     }
+    if ($senthide) {
+        $result .= '<senthide>$origmsgid</senthide>';
+    }
     return ($msgid,$result);
 }
 
@@ -714,7 +733,7 @@
 
 sub user_crit_msg_raw {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
+        $nosentstore,$recipid,$attachmenturl,$permresults,$senthide)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -732,11 +751,15 @@
             $$sentmessage = $packed_message;
         }
         if (!$nosentstore) {
-            (undef,my $packed_message_no_citation) =
+            my ($sentmsgid,$packed_message_no_citation) =
             &packagemsg($subject,$message,undef,undef,$attachmenturl,$user,
-                        $domain,$msgid);
+                        $domain,$msgid,undef,undef,undef,undef,undef,$senthide,$msgid);
             if ($status eq 'ok' || $status eq 'con_delayed') {
-                &store_sent_mail($msgid,$packed_message_no_citation);
+                if ($senthide && $sentmsgid) {
+                    &store_sent_mail($sentmsgid,$packed_message_no_citation);
+                } else {
+                    &store_sent_mail($msgid,$packed_message_no_citation);
+                }
             }
         }
     } else {
@@ -786,7 +809,7 @@
 
 sub user_crit_msg {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
+        $nosentstore,$recipid,$attachmenturl,$permresults,$senthide)=@_;
     my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -797,13 +820,13 @@
          push(@status,
 	      &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
 				 $sendback,$toperm,$sentmessage,$nosentstore,
-                                 $recipid,$attachmenturl,$permresults));
+                                 $recipid,$attachmenturl,$permresults,$senthide));
        }
     } else { 
 	push(@status,
 	     &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
 				$toperm,$sentmessage,$nosentstore,$recipid,
-                                $attachmenturl,$permresults));
+                                $attachmenturl,$permresults,$senthide));
     }
     if (wantarray) {
 	return @status;
@@ -852,7 +875,7 @@
 sub user_normal_msg_raw {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
         $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
-        $error,$nosentstore,$recipid,$permresults)=@_;
+        $error,$nosentstore,$recipid,$permresults,$senthide)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -874,11 +897,16 @@
                          ('email_status',{'recnewemail'=>time},$domain,$user);
 # Into sent-mail folder if sent mail storage required
        if (!$nosentstore) {
-           (undef,my $packed_message_no_citation) =
+           my ($sentmsgid,$packed_message_no_citation) =
                &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
-                           $user,$domain,$currid,undef,$crsmsgid,$symb,$error);
+                           $user,$domain,$currid,undef,$crsmsgid,$symb,$error,
+                           undef,$senthide,$msgid);
            if ($status eq 'ok' || $status eq 'con_delayed') {
-               &store_sent_mail($msgid,$packed_message_no_citation);
+               if ($senthide && $sentmsgid) {
+                   &store_sent_mail($sentmsgid,$packed_message_no_citation);
+               } else {
+                   &store_sent_mail($msgid,$packed_message_no_citation);
+               }
            }
        }
        if (ref($newid) eq 'SCALAR') {
@@ -929,7 +957,7 @@
 sub user_normal_msg {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
 	$toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid,
-        $permresults)=@_;
+        $permresults,$senthide)=@_;
     my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -941,13 +969,15 @@
 	        &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
 				     $citation,$baseurl,$attachmenturl,$toperm,
 				     undef,undef,$sentmessage,undef,$symb,
-                                     $restitle,$error,$nosentstore,$recipid,$permresults));
+                                     $restitle,$error,$nosentstore,$recipid,
+                                     $permresults,$senthide));
         }
     } else {
 	push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
 				     $citation,$baseurl,$attachmenturl,$toperm,
 				     undef,undef,$sentmessage,undef,$symb,
-                                     $restitle,$error,$nosentstore,$recipid,$permresults));
+                                     $restitle,$error,$nosentstore,$recipid,
+                                     $permresults,$senthide));
     }
     if (wantarray) {
         return @status;
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.195 loncom/interface/lonmsgdisplay.pm:1.196
--- loncom/interface/lonmsgdisplay.pm:1.195	Tue Nov 30 16:16:14 2021
+++ loncom/interface/lonmsgdisplay.pm	Tue Jan 18 17:33:13 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.195 2021/11/30 16:16:14 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.196 2022/01/18 17:33:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1351,6 +1351,26 @@
 sub compout {
     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
         $multiforward)=@_;
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
+    my %setters;
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
+    if ($by_ip) {
+        my $showdom = &Apache::lonnet::domain($blockdom);
+        if ($showdom eq '') {
+            $showdom = $blockdom;
+        }
+        $r->print(&Apache::loncommon::start_page('Messages'));
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs('Send and display messages'));
+        $r->print('<p class="LC_warning">'.
+                 &mt('Sending of LON-CAPA messages is blocked for your current IP address: [_1].',$clientip).'</p>'.
+                 '<ul><li>'.
+                 &mt('Note: communication is being blocked for certain IP address(es).').
+                 '</li><li>'.
+                 &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.',$showdom).
+                 '</li></ul>');
+        return;
+    }
     my $suffix=&Apache::lonmsg::foldersuffix($folder);
     my ($cdom,$cnum,$group,$refarg);
     if (exists($env{'form.group'})) {
@@ -2800,7 +2820,14 @@
         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     }
-    if ($env{'form.send'}) {
+    my $clientip = &Apache::lonnet::get_requestor_ip($r);
+    my %setters;
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
+    if ($by_ip) {
+        &printheader($r,'','Sending messages blocked from your location.');
+        return 'blocked';
+    } elsif ($env{'form.send'}) {
         if (!$env{'form.multiforward'}) {
             if ($group eq '') {
 	        &printheader($r,'','Messages being sent.');
@@ -3494,8 +3521,12 @@
                 my $count = keys(%forwardfail);
                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
                 foreach my $key (keys(%forwardfail)) {
-                    $message .= '<br />'.&mt('Could not deliver forwarded message.').'</span> '.
-                                &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
+                    $message .= '<br />'.&mt('Could not deliver forwarded message.').'</span> ';
+                    if ($forwardfail{$key} eq 'blocked') {
+                        $message .= &mt('Sending messages is blocked from your IP address');
+                    } else {
+                        $message .= &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
+                    }
                 }
                 $message = &Apache::loncommon::confirmwrapper($message);
                 $r->print($message);
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.388 loncom/interface/lonfeedback.pm:1.389
--- loncom/interface/lonfeedback.pm:1.388	Tue Jan 18 16:55:30 2022
+++ loncom/interface/lonfeedback.pm	Tue Jan 18 17:33:13 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.388 2022/01/18 16:55:30 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.389 2022/01/18 17:33:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2793,7 +2793,7 @@
 
 sub redirect_back {
   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,
-      $rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
+      $rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge,$delay) = @_;
   my $sorttag = '';
   my $roletag = '';
   my $statustag = '';
@@ -2892,11 +2892,20 @@
   &Apache::lonenc::check_encrypt(\$feedurl);
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   my %parms=('only_body'   => 1);
+  if ($delay !~ /^\d+(|\.\d+)$/) {
+      $delay = 0;
+  }
   if ($env{'form.modal'}) {
       my $onload = 'document.forms.reldt.submit()';
+      if ($delay) {
+          my $js_delay = int(1000 * $delay);
+          $onload = "setTimeout(function(){
+                        document.forms.reldt.submit();
+                     },$js_delay);";
+      }
       $parms{'add_entries'}={'onload' => $onload};
   } else {
-      $parms{'redirect'}=[0,$feedurl];
+      $parms{'redirect'}=[$delay,$feedurl];
   }
   my $start_page=
       &Apache::loncommon::start_page('Feedback sent',undef,\%parms);
@@ -3161,9 +3170,17 @@
 }
 
 sub send_msg {
-    my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
+    my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,$clientip,%to)=@_;
     my $status='';
     my $sendsomething=0;
+    my $delay; 
+    my $senthide;
+    my %setters;
+    my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
+        &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
+    if ($by_ip) {
+        $senthide = 1;
+    }
     my $restitle = &get_resource_title($symb,$feedurl);
     if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
     unless ($title=~/\w/) { $title=&mt('Feedback'); }
@@ -3177,7 +3194,8 @@
 	    } else {
 		unless (&Apache::lonmsg::user_normal_msg($user,$domain,
 							 $title.' ['.$restitle.']',$email,$citations,$feedurl,
-							 $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) {
+							 $attachmenturl,undef,undef,$symb,$restitle,undef,
+                                                         undef,undef,undef,$senthide)=~/ok/) {
 		    $status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';
 		} else {
 		    $sendsomething++;
@@ -3185,6 +3203,24 @@
 	    }
 	}
     }
+    if ($sendsomething && $senthide) {
+        if ($by_ip) {
+            my $showdom = &Apache::lonnet::domain($blockdom);
+            if ($showdom eq '') {
+                $showdom = $blockdom;
+            }
+            $delay = 4;
+            $status.='<br />'.&mt("Message content of feedback you send to instructor(s) from your current IP address: [_1] will be unavailable in your 'Sent' folder.",$clientip).
+                     '<ul><li>'.
+                     &mt('This does not affect delivery of feedback to your instructor(s).').
+                     '</li><li>'.
+                     &mt('Note: some types of communication functionality are blocked for certain IP address(es).').
+                     '</li><li>'.
+                     &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.',
+                         $showdom).
+                     '</li></ul><br />';
+        }
+    }
 
 # Records of number of feedback messages are kept under the "symb" called "_feedback"
 # There are two entries within the framework of a course:
@@ -3202,7 +3238,7 @@
 	    }
         }
     }
-    return ($status,$sendsomething);
+    return ($status,$sendsomething,$delay);
 }
 
 # Routine to get the complete feedback records
@@ -4766,9 +4802,10 @@
       my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
 
 # Actually send mail
-      my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),
-				      $feedurl,$email,$citations,
-				      $attachmenturl,$usersymb,%to);
+      my $clientip = &Apache::lonnet::get_requestor_ip($r);
+      my ($status,$numsent,$delay)=&send_msg(&clear_out_html($env{'form.subject'}),
+				             $feedurl,$email,$citations,
+				             $attachmenturl,$usersymb,$clientip,%to);
 
 # Discussion? Store that.
       my $numpost=0;
@@ -4804,7 +4841,7 @@
 	  
 # Receipt screen and redirect back to where came from
       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},
-                     undef,undef,undef,undef,undef,undef,$group,$toolarge);
+                     undef,undef,undef,undef,undef,undef,$group,$toolarge,$delay);
   }
   return OK;
 }


More information about the LON-CAPA-cvs mailing list