[LON-CAPA-cvs] cvs: modules /msu/sentinel LC_classlist_check.pl

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 08 Jan 2007 15:34:41 -0000


raeburn		Mon Jan  8 10:34:41 2007 EDT

  Added files:                 
    /modules/msu/sentinel	LC_classlist_check.pl 
  Log:
  cgi script to run on s10 so msulogin.loncapa.org can get a user's classes from the RO's LONCAPA_ClassList table.  Intended as a short term measure to avoid changing lond, lonsql and MSU's localenroll (the proper way to do this).
  
  

Index: modules/msu/sentinel/LC_classlist_check.pl
+++ modules/msu/sentinel/LC_classlist_check.pl
#!/usr/bin/perl
# Run a query against LONCAPA_ClassList
#
# Copyright Michigan State University Board of Trustees
#
# CGI script to be placed on an MSU LON-CAPA library server 
# whoch has access to the RO_ClassList database on esdb1.ais.msu.edu 
# This file is to be placed in /home/httpd/cgi-bin
#
# Allows a request to be made from a remote server included in the
# range of IP addresses for allowed servers to request a listing
# of official MSU courses using LON-CAPA for which a specified user 
# is registered.  
# 
# Expects the query_string to contain:  username=********
# where ******** is replaced by the MSU NetID of the specific user.
#
# Will return a text page with each line containing:
# the MSU course ID, =, and a : separated list of sections
# for any course in which username is a registered student 
#
# Intended as a short term measure only, to avoid changing lond, lonsql 
# and MSU's localenroll - the proper way to do this to use an internal 
# LON-CAPA query via lond/lonsql/localenroll.
#
# Do NOT use without appropriate access control via 
# loncapa_apache_local*.conf
# e.g.,
#
# <Location /cgi-bin/LC_classlist_check.pl>
# order deny,allow
# deny from all
# allow from 35.9.119.109
# AuthName "LON-CAPA Network Administration"
# AuthType Basic
# AuthUserFile /home/httpd/lonTabs/htpasswd
# require user lonadm
# </Location>
#

    use strict;
    use lib '/home/httpd/lib/perl/';
    use Apache::lonnet;
    use LONCAPA::Configuration;
    use DBI;
    use localenroll;

    my $result = '';
    my ($uname) = ($ENV{'QUERY_STRING'} =~ m/username=(\w+)$/);

    if ($uname =~ /^\w{2,8}$/) {
        my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
        my ($dbh,$dbflag) = &localenroll::connect_DB($$configvars{'lonDaemons'},'RO');

        my %courses;
        if ($dbflag) {
            eval {
                my $sth = $dbh->prepare("SELECT Term_Code,Subj_Code,Crse_Code,Sctn_Code FROM LONCAPA_ClassList WHERE Pilot_ID = '$uname'");
                $sth->execute();
                while ( my($semyr,$dept,$num,$sec)  = $sth->fetchrow_array ) {
                    push (@{$courses{$semyr.$dept.$num}},$sec);
                }
                $sth->finish;
            };
            &localenroll::disconnect_DB($dbh);
        }
  
        if (keys(%courses) > 0) {
            foreach my $course (sort(keys(%courses))) {
                $result .= $course.'='.join(':',@{$courses{$course}})."\n";
            }
        }
    }
    print 'Content-type: text/plain'."\n\n";
    print $result;