[LON-CAPA-cvs] cvs: loncom / lond

foxr lon-capa-cvs@mail.lon-capa.org
Fri, 03 Sep 2004 10:13:59 -0000


This is a MIME encoded message

--foxr1094206439
Content-Type: text/plain

foxr		Fri Sep  3 06:13:59 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Incorporated the auto-enroll support into handlerized functions however:
  - Need to get Stuart to test this since I don't know how.
  - Left the old code in so that if there are huge problems, one
    can just remove the handler registrations and the code should
    work again.
  
  
--foxr1094206439
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20040903061359.txt"

Index: loncom/lond
diff -u loncom/lond:1.247 loncom/lond:1.248
--- loncom/lond:1.247	Thu Sep  2 14:37:44 2004
+++ loncom/lond	Fri Sep  3 06:13:59 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.247 2004/09/02 18:37:44 albertel Exp $
+# $Id: lond,v 1.248 2004/09/03 10:13:59 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,7 +57,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.247 $'; #' stupid emacs
+my $VERSION='$Revision: 1.248 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -3482,10 +3482,258 @@
 
     return 0;
 }
-&register_handler("exit", \&exit_handler, 0,,1);
-&register_handler("init", \&exit_handler, 0,,1);
-&register_handler("quit", \&exit_handler, 0,,1);
+&register_handler("exit", \&exit_handler, 0,1,1);
+&register_handler("init", \&exit_handler, 0,1,1);
+&register_handler("quit", \&exit_handler, 0,1,1);
+
+#  Determine if auto-enrollment is enabled.
+#  Note that the original had what I believe to be a defect.
+#  The original returned 0 if the requestor was not a registerd client.
+#  It should return "refused".
+# Formal Parameters:
+#   $cmd       - The command that invoked us.
+#   $tail      - The tail of the command (Extra command parameters.
+#   $client    - The socket open on the client that issued the request.
+# Returns:
+#    1         - Indicating processing should continue.
+#
+sub enrollment_enabled_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = $cmd.":".$tail; # For logging purposes.
+
+    
+    my $cdom = split(/:/, $tail);   # Domain we're asking about.
+    my $outcome  = &localenroll::run($cdom);
+    &Reply($client, "$outcome\n", $userinput);
+
+    return 1;
+}
+&register_handler("autorun", \&enrollment_enabled_handler, 0, 1, 0);
+
+#   Get the official sections for which auto-enrollment is possible.
+#   Since the admin people won't know about 'unofficial sections' 
+#   we cannot auto-enroll on them.
+# Formal Parameters:
+#    $cmd     - The command request that got us dispatched here.
+#    $tail    - The remainder of the request.  In our case this
+#               will be split into:
+#               $coursecode   - The course name from the admin point of view.
+#               $cdom         - The course's domain(?).
+#    $client  - Socket open on the client.
+# Returns:
+#    1    - Indiciting processing should continue.
+#
+sub get_sections_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+
+    my ($coursecode, $cdom) = split(/:/, $tail);
+    my @secs = &localenroll::get_sections($coursecode,$cdom);
+    my $seclist = &escape(join(':',@secs));
+
+    &Reply($client, "$seclist\n", $userinput);
+    
+
+    return 1;
+}
+&register_handler("autogetsections", \&get_sections_handler, 0, 1, 0);
+
+#   Validate the owner of a new course section.  
+#
+# Formal Parameters:
+#   $cmd      - Command that got us dispatched.
+#   $tail     - the remainder of the command.  For us this consists of a
+#               colon separated string containing:
+#                  $inst    - Course Id from the institutions point of view.
+#                  $owner   - Proposed owner of the course.
+#                  $cdom    - Domain of the course (from the institutions
+#                             point of view?)..
+#   $client   - Socket open on the client.
+#
+# Returns:
+#   1        - Processing should continue.
+#
+sub validate_course_owner_handler {
+    my ($cmd, $tail, $client)  = @_;
+    my $userinput = "$cmd:$tail";
+    my ($inst_course_id, $owner, $cdom) = split(/:/, $tail);
+
+    my $outcome = &localenroll::new_course($inst_course_id,$owner,$cdom);
+    &Reply($client, "$outcome\n", $userinput);
+
+
+
+    return 1;
+}
+&register_handler("autonewcourse", \&validate_course_owner_handler, 0, 1, 0);
+#
+#   Validate a course section in the official schedule of classes
+#   from the institutions point of view (part of autoenrollment).
+#
+# Formal Parameters:
+#   $cmd          - The command request that got us dispatched.
+#   $tail         - The tail of the command.  In this case,
+#                   this is a colon separated set of words that will be split
+#                   into:
+#                        $inst_course_id - The course/section id from the
+#                                          institutions point of view.
+#                        $cdom           - The domain from the institutions
+#                                          point of view.
+#   $client       - Socket open on the client.
+# Returns:
+#    1           - Indicating processing should continue.
+#
+sub validate_course_section_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($inst_course_id, $cdom) = split(/:/, $tail);
+
+    my $outcome=&localenroll::validate_courseID($inst_course_id,$cdom);
+    &Reply($client, "$outcome\n", $userinput);
+
+
+    return 1;
+}
+&register_handler("autovalidatecourse", \&validate_course_section_handler, 0, 1, 0);
+
+#
+#   Create a password for a new auto-enrollment user.
+#   I think/guess, this password allows access to the institutions 
+#   AIS class list server/services.  Stuart can correct this comment
+#   when he finds out how wrong I am.
+#
+# Formal Parameters:
+#    $cmd     - The command request that got us dispatched.
+#    $tail    - The tail of the command.   In this case this is a colon separated
+#               set of words that will be split into:
+#               $authparam - An authentication parameter (username??).
+#               $cdom      - The domain of the course from the institution's
+#                            point of view.
+#    $client  - The socket open on the client.
+# Returns:
+#    1 - continue processing.
+#
+sub create_auto_enroll_password_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+
+    my ($authparam, $cdom) = split(/:/, $userinput);
+
+    my ($create_passwd,$authchk);
+    ($authparam,
+     $create_passwd,
+     $authchk) = &localenroll::create_password($authparam,$cdom);
+
+    &Reply($client, &escape($authparam.':'.$create_passwd.':'.$authchk)."\n",
+	   $userinput);
+
+
+    return 1;
+}
+&register_handler("autocreatepassword", \&create_auto_enroll_password_handler, 
+		  0, 1, 0);
+
+#   Retrieve and remove temporary files created by/during autoenrollment.
+#
+# Formal Parameters:
+#    $cmd      - The command that got us dispatched.
+#    $tail     - The tail of the command.  In our case this is a colon 
+#                separated list that will be split into:
+#                $filename - The name of the file to remove.
+#                            The filename is given as a path relative to
+#                            the LonCAPA temp file directory.
+#    $client   - Socket open on the client.
+#
+# Returns:
+#   1     - Continue processing.
+
+sub retrieve_auto_file_handler {
+    my ($cmd, $tail, $client)    = @_;
+    my $userinput                = "cmd:$tail";
+
+    my ($filename)   = split(/:/, $tail);
+
+    my $source = $perlvar{'lonDaemons'}.'/tmp/'.$filename;
+    if ( (-e $source) && ($filename ne '') ) {
+	my $reply = '';
+	if (open(my $fh,$source)) {
+	    while (<$fh>) {
+		chomp($_);
+		$_ =~ s/^\s+//g;
+		$_ =~ s/\s+$//g;
+		$reply .= $_;
+	    }
+	    close($fh);
+	    &Reply($client, &escape($reply)."\n", $userinput);
+
+#   Does this have to be uncommented??!?  (RF).
+#
+#                                unlink($source);
+	} else {
+	    &Failure($client, "error\n", $userinput);
+	}
+    } else {
+	&Failure($client, "error\n", $userinput);
+    }
+    
+
+    return 1;
+}
+&register_handler("autoretrieve", \&retrieve_auto_file_handler, 0,1,0);
+
+#
+#   Read and retrieve institutional code format (for support form).
+# Formal Parameters:
+#    $cmd        - Command that dispatched us.
+#    $tail       - Tail of the command.  In this case it conatins 
+#                  the course domain and the coursename.
+#    $client     - Socket open on the client.
+# Returns:
+#    1     - Continue processing.
+#
+sub get_institutional_code_format_handler {
+    my ($cmd, $tail, $client)   = @_;
+    my $userinput               = "$cmd:$tail";
+
+    my $reply;
+    my($cdom,$course) = split(/:/,$tail);
+    my @pairs = split/\&/,$course;
+    my %instcodes = ();
+    my %codes = ();
+    my @codetitles = ();
+    my %cat_titles = ();
+    my %cat_order = ();
+    foreach (@pairs) {
+	my ($key,$value) = split/=/,$_;
+	$instcodes{&unescape($key)} = &unescape($value);
+    }
+    my $formatreply = &localenroll::instcode_format($cdom,
+						    \%instcodes,
+						    \%codes,
+						    \@codetitles,
+						    \%cat_titles,
+						    \%cat_order);
+    if ($formatreply eq 'ok') {
+	my $codes_str = &hash2str(%codes);
+	my $codetitles_str = &array2str(@codetitles);
+	my $cat_titles_str = &hash2str(%cat_titles);
+	my $cat_order_str = &hash2str(%cat_order);
+	&Reply($client,
+	       $codes_str.':'.$codetitles_str.':'.$cat_titles_str.':'
+	       .$cat_order_str."\n",
+	       $userinput);
+    } else {
+	# this else branch added by RF since if not ok, lonc will
+	# hang waiting on reply until timeout.
+	#
+	&Reply($client, "format_error\n", $userinput);
+    }
+    
+    return 1;
+}
 
+&register_handler("autoinstcodeformat", \&get_institutional_code_format_handler,
+		  0,1,0);
 
 #
 #
@@ -3678,7 +3926,8 @@
 	} else {
 	    print $client "refused\n";
 	}
-#---------------------  read and retrieve institutional code format (for support form).
+#---------------------  read and retrieve institutional code format 
+#                          (for support form).
     } elsif ($userinput =~/^autoinstcodeformat/) {
 	if (isClient) {
 	    my $reply;

--foxr1094206439--