[LON-CAPA-cvs] cvs: loncom /cgi lonauthcgi.pm

raeburn raeburn at source.lon-capa.org
Fri Oct 14 16:50:54 EDT 2011


raeburn		Fri Oct 14 20:50:54 2011 EDT

  Modified files:              
    /loncom/cgi	lonauthcgi.pm 
  Log:
  - IP-based access to status information for manager in manager.tab
  
  
Index: loncom/cgi/lonauthcgi.pm
diff -u loncom/cgi/lonauthcgi.pm:1.6 loncom/cgi/lonauthcgi.pm:1.7
--- loncom/cgi/lonauthcgi.pm:1.6	Wed Apr 14 18:06:22 2010
+++ loncom/cgi/lonauthcgi.pm	Fri Oct 14 20:50:54 2011
@@ -1,7 +1,7 @@
 #
 # LON-CAPA authorization for cgi-bin scripts
 #
-# $Id: lonauthcgi.pm,v 1.6 2010/04/14 18:06:22 raeburn Exp $
+# $Id: lonauthcgi.pm,v 1.7 2011/10/14 20:50:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,9 +55,11 @@
 
 use strict;
 use lib '/home/httpd/lib/perl';
+use Socket;
 use Apache::lonnet;
 use Apache::lonlocal;
 use LONCAPA;
+use LONCAPA::Configuration();
 
 #############################################
 #############################################
@@ -94,6 +96,10 @@
             return $allowed;
         }
     }
+    if (&is_manager_ip($ip)) {
+        $allowed = 1;
+        return $allowed;
+    }
     if ($page ne 'ping') {
         my @poss_domains = &Apache::lonnet::current_machine_domains();
         foreach my $dom (@poss_domains) {
@@ -117,6 +123,45 @@
 #############################################
 #############################################
 
+sub is_manager_ip {
+    my ($remote_ip) = @_;
+    return if ($remote_ip eq '');
+    my ($directory,$is_manager);
+    my $config=LONCAPA::Configuration::read_conf();
+    if (ref($config) eq 'HASH') {
+        $directory = $config->{'lonTabDir'};
+    }
+    if (defined($directory)) {
+        if (open(MANAGERS, "$directory/managers.tab")) {
+            while(my $host = <MANAGERS>) {
+                chomp($host);
+                next if ($host =~ /^\#/);
+                my $ip = &Apache::lonnet::get_host_ip($host);
+                if (defined($ip)) {
+                    if ($remote_ip eq $ip) {
+                        $is_manager = 1;
+                        last;
+                    }
+                } else {
+                    my ($cluname,$dnsname) = split(/:/, $host);
+                    $ip = gethostbyname($dnsname);
+                    if (defined($ip)) {
+                        my $hostip = inet_ntoa($ip);
+                        if ($hostip = $remote_ip) {
+                            $is_manager = 1;
+                        }
+                    }
+                }
+            }
+            close(MANAGERS);
+        }
+    }
+    return $is_manager;
+}
+
+#############################################
+#############################################
+
 =pod
 
 =item can_view()




More information about the LON-CAPA-cvs mailing list