[LON-CAPA-cvs] cvs: loncom /html/adm/helper newslot.helper

raeburn raeburn at source.lon-capa.org
Fri Jan 20 01:23:37 EST 2017


raeburn		Fri Jan 20 06:23:37 2017 EDT

  Modified files:              
    /loncom/html/adm/helper	newslot.helper 
  Log:
  - Support deny from specified IPs/Hosts as well as existing allow from.
  
  
Index: loncom/html/adm/helper/newslot.helper
diff -u loncom/html/adm/helper/newslot.helper:1.33 loncom/html/adm/helper/newslot.helper:1.34
--- loncom/html/adm/helper/newslot.helper:1.33	Mon Oct  5 02:35:51 2015
+++ loncom/html/adm/helper/newslot.helper	Fri Jan 20 06:23:37 2017
@@ -26,8 +26,32 @@
 	  my $name=$helper->{VARS}{'origname'};
 	  my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
 	  if (!ref($slot{$name})) { return $default; }
-	  if (!exists($slot{$name}{$which})) { return $default; }
-	  return $slot{$name}{$which};
+          if (($which eq 'ipdeny') || ($which eq 'ipallow')) {
+              if (!exists($slot{$name}{'ip'})) { return $default; }
+          } else {
+              if (!exists($slot{$name}{$which})) { return $default; }
+          }
+          if (($which eq 'ipdeny') || ($which eq 'ipallow')) {
+              my @allows;
+              my @denies;
+              foreach my $item (split(',',$slot{$name}{'ip'})) {
+                  $item =~ s/^\s*//;
+                  $item =~ s/\s*$//;
+                  if ($item =~ /^\!(.+)$/) {
+                      push(@denies,$1);
+                  } else {
+                      push(@allows,$item);
+                  }
+              }
+              if ($which eq 'ipdeny') {
+                  return join(',', at denies);
+              }
+              if ($which eq 'ipallow') {
+                  return join(',', at allows);
+              }
+          } else {
+	      return $slot{$name}{$which};
+          }
       }
     </exec>
     <message>
@@ -241,16 +265,30 @@
         }
       </defaultvalue>
     </choices>
+
+    <message>
+        </p><p>IP restrictions -- allow from all except: <br />   
+    </message>
+
+    <string variable="ipdeny" size="30">
+      <validator>
+          return undef;
+      </validator>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('ipdeny');
+      </defaultvalue>
+    </string>
     
     <message>
-	</p><p>IP restrictions:<br />         
+	</p><p>IP restrictions -- deny from all except: <br />         
     </message>
-    <string variable="ip" size="30">
+
+    <string variable="ipallow" size="30">
       <validator>
           return undef;
       </validator>
       <defaultvalue>
-        return &{$helper->{DATA}{origslot}}('ip');
+        return &{$helper->{DATA}{origslot}}('ipallow');
       </defaultvalue>
     </string>
 
@@ -378,12 +416,32 @@
 	    $slot{$which} = $helper->{'VARS'}{$which};
 	}
 
-	foreach my $which ('ip','description','maxspace','secret') {
+	foreach my $which ('description','maxspace','secret') {
 	    if ( $helper->{'VARS'}{$which} =~/\S/ ) {
 		$slot{$which} = $helper->{'VARS'}{$which};
 	    }
 	}
 
+        if ($helper->{'VARS'}{'ipdeny'} =~/\S/ ) {
+            foreach my $item (split(',',$helper->{'VARS'}{'ipdeny'})) {
+                $item =~ s/^\s*//;
+                $item =~ s/\s*$//;
+                $slot{'ip'} .= '!'.$item.',';
+            }
+        }
+
+        if ($helper->{'VARS'}{'ipallow'} =~/\S/ ) {
+            foreach my $item (split(',',$helper->{'VARS'}{'ipallow'})) {
+                $item =~ s/^\s*//;
+                $item =~ s/\s*$//;
+                $slot{'ip'} .= $item.',';
+            }
+        }
+ 
+        if ($slot{'ip'} ne '') {
+            $slot{'ip'} =~s /,$//;
+        }
+
         if ($helper->{'VARS'}{'type'} eq 'schedulable_student') {
             if (($helper->{'VARS'}{'reservationmsg'} eq 'only_student') ||
                ($helper->{'VARS'}{'reservationmsg'} eq 'student_and_user_notes_screen')) {




More information about the LON-CAPA-cvs mailing list