Diff for /loncom/lond between versions 1.305.2.4 and 1.313

version 1.305.2.4, 2006/02/10 09:48:17 version 1.313, 2006/01/31 16:12:12
Line 89  my $ConnectionType; Line 89  my $ConnectionType;
   
 my %hostid; # ID's for hosts in cluster by ip.  my %hostid; # ID's for hosts in cluster by ip.
 my %hostdom; # LonCAPA domain for hosts in cluster.  my %hostdom; # LonCAPA domain for hosts in cluster.
   my %hostname; # DNSname -> ID's mapping.
 my %hostip; # IPs for hosts in cluster.  my %hostip; # IPs for hosts in cluster.
 my %hostdns; # ID's of hosts looked up by DNS name.  my %hostdns; # ID's of hosts looked up by DNS name.
   
Line 1073  sub _do_hash_untie { Line 1074  sub _do_hash_untie {
     die();      die();
  }   }
           
    &logthis("$$ for $namespace");
  $sym=&Symbol::gensym();   $sym=&Symbol::gensym();
  open($sym,"$file_prefix.db");   open($sym,"$file_prefix.db");
    &logthis("$$ for $namespace attempt lock");
  my $failed=0;   my $failed=0;
  eval {   eval {
     local $SIG{__DIE__}='DEFAULT';      local $SIG{__DIE__}='DEFAULT';
Line 1087  sub _do_hash_untie { Line 1090  sub _do_hash_untie {
     alarm(0);      alarm(0);
  };   };
  if ($failed) {   if ($failed) {
       &logthis("$$ for $namespace got failed lock");
     $! = 100; # throwing error # 100      $! = 100; # throwing error # 100
     return undef;      return undef;
  }   }
    &logthis("$$ for $file_prefix.db got lock");
  return &_do_hash_tie($file_prefix,$namespace,$how,$loghead,$what);   return &_do_hash_tie($file_prefix,$namespace,$how,$loghead,$what);
     }      }
   
Line 2450  sub put_user_profile_entry { Line 2455  sub put_user_profile_entry {
  $userinput);   $userinput);
     }      }
  } else {   } else {
     &Failure( $client, "error: ".($!+0)." tie(GDBM) Failed ".      &Failure( $client, "error: ".($!)." tie(GDBM) Failed ".
      "while attempting put\n", $userinput);       "while attempting put\n", $userinput);
  }   }
     } else {      } else {
Line 2486  sub newput_user_profile_entry { Line 2491  sub newput_user_profile_entry {
     my $hashref = &tie_user_hash($udom, $uname, $namespace,      my $hashref = &tie_user_hash($udom, $uname, $namespace,
  &GDBM_WRCREAT(),"N",$what);   &GDBM_WRCREAT(),"N",$what);
     if(!$hashref) {      if(!$hashref) {
  &Failure( $client, "error: ".($!+0)." tie(GDBM) Failed ".   &Failure( $client, "error: ".($!)." tie(GDBM) Failed ".
   "while attempting put\n", $userinput);    "while attempting put\n", $userinput);
  return 1;   return 1;
     }      }
Line 2676  sub roles_delete_handler { Line 2681  sub roles_delete_handler {
  foreach my $key (@rolekeys) {   foreach my $key (@rolekeys) {
     delete $hashref->{$key};      delete $hashref->{$key};
  }   }
  if (&untie_user_hash($hashref)) {   if (&untie_user_hash(%$hashref)) {
     &Reply($client, "ok\n", $userinput);      &Reply($client, "ok\n", $userinput);
  } else {   } else {
     &Failure( $client, "error: ".($!+0)." untie(GDBM) Failed ".      &Failure( $client, "error: ".($!+0)." untie(GDBM) Failed ".
Line 2817  sub delete_profile_entry { Line 2822  sub delete_profile_entry {
  foreach my $key (@keys) {   foreach my $key (@keys) {
     delete($hashref->{$key});      delete($hashref->{$key});
  }   }
  if (&untie_user_hash($hashref)) {   if (&untie_user_hash(%$hashref)) {
     &Reply($client, "ok\n", $userinput);      &Reply($client, "ok\n", $userinput);
  } else {   } else {
     &Failure($client, "error: ".($!+0)." untie(GDBM) Failed ".      &Failure($client, "error: ".($!+0)." untie(GDBM) Failed ".
Line 2859  sub get_profile_keys { Line 2864  sub get_profile_keys {
  foreach my $key (keys %$hashref) {   foreach my $key (keys %$hashref) {
     $qresult.="$key&";      $qresult.="$key&";
  }   }
  if (&untie_user_hash($hashref)) {   if (&untie_user_hash(%$hashref)) {
     $qresult=~s/\&$//;      $qresult=~s/\&$//;
     &Reply($client, "$qresult\n", $userinput);      &Reply($client, "$qresult\n", $userinput);
  } else {   } else {
Line 2975  sub dump_with_regexp { Line 2980  sub dump_with_regexp {
   
     my $userinput = "$cmd:$tail";      my $userinput = "$cmd:$tail";
   
     my ($udom,$uname,$namespace,$regexp)=split(/:/,$tail);      my ($udom,$uname,$namespace,$regexp,$range)=split(/:/,$tail);
     if (defined($regexp)) {      if (defined($regexp)) {
  $regexp=&unescape($regexp);   $regexp=&unescape($regexp);
     } else {      } else {
  $regexp='.';   $regexp='.';
     }      }
       my ($start,$end);
       if (defined($range)) {
    if ($range =~/^(\d+)\-(\d+)$/) {
       ($start,$end) = ($1,$2);
    } elsif ($range =~/^(\d+)$/) {
       ($start,$end) = (0,$1);
    } else {
       undef($range);
    }
       }
     my $hashref = &tie_user_hash($udom, $uname, $namespace,      my $hashref = &tie_user_hash($udom, $uname, $namespace,
  &GDBM_READER());   &GDBM_READER());
     if ($hashref) {      if ($hashref) {
         my $qresult='';          my $qresult='';
    my $count=0;
  while (my ($key,$value) = each(%$hashref)) {   while (my ($key,$value) = each(%$hashref)) {
     if ($regexp eq '.') {      if ($regexp eq '.') {
    $count++;
    if (defined($range) && $count >= $end)   { last; }
    if (defined($range) && $count <  $start) { next; }
  $qresult.=$key.'='.$value.'&';   $qresult.=$key.'='.$value.'&';
     } else {      } else {
  my $unescapeKey = &unescape($key);   my $unescapeKey = &unescape($key);
  if (eval('$unescapeKey=~/$regexp/')) {   if (eval('$unescapeKey=~/$regexp/')) {
       $count++;
       if (defined($range) && $count >= $end)   { last; }
       if (defined($range) && $count <  $start) { next; }
     $qresult.="$key=$value&";      $qresult.="$key=$value&";
  }   }
     }      }
Line 4318  sub get_institutional_code_format_handle Line 4340  sub get_institutional_code_format_handle
 &register_handler("autoinstcodeformat",  &register_handler("autoinstcodeformat",
   \&get_institutional_code_format_handler,0,1,0);    \&get_institutional_code_format_handler,0,1,0);
   
 # Get domain specific conditions for import of student photographs to a course  
 #  
 # Retrieves information from photo_permission subroutine in localenroll.  
 # Returns outcome (ok) if no processing errors, and whether course owner is   
 # required to accept conditions of use (yes/no).  
 #  
 #      
 sub photo_permission_handler {  
     my ($cmd, $tail, $client)   = @_;  
     my $userinput               = "$cmd:$tail";  
     my $cdom = $tail;  
     my ($perm_reqd,$conditions);  
     my $outcome;  
     eval {  
  local($SIG{__DIE__})='DEFAULT';  
  $outcome = &localenroll::photo_permission($cdom,\$perm_reqd,  
   \$conditions);  
     };  
     if (!$@) {  
  &Reply($client, &escape($outcome.':'.$perm_reqd.':'. $conditions)."\n",  
        $userinput);  
     } else {  
  &Failure($client,"unknown_cmd\n",$userinput);  
     }  
     return 1;  
 }  
 &register_handler("autophotopermission",\&photo_permission_handler,0,1,0);  
   
 #  
 # Checks if student photo is available for a user in the domain, in the user's  
 # directory (in /userfiles/internal/studentphoto.jpg).  
 # Uses localstudentphoto:fetch() to ensure there is an up to date copy of  
 # the student's photo.     
   
 sub photo_check_handler {  
     my ($cmd, $tail, $client)   = @_;  
     my $userinput               = "$cmd:$tail";  
     my ($udom,$uname,$pid) = split(/:/,$tail);  
     $udom = &unescape($udom);  
     $uname = &unescape($uname);  
     $pid = &unescape($pid);  
     my $path=&propath($udom,$uname).'/userfiles/internal/';  
     if (!-e $path) {  
         &mkpath($path);  
     }  
     my $response;  
     my $result = &localstudentphoto::fetch($udom,$uname,$pid,\$response);  
     $result .= ':'.$response;  
     &Reply($client, &escape($result)."\n",$userinput);  
     return 1;  
 }  
 &register_handler("autophotocheck",\&photo_check_handler,0,1,0);  
   
 #  
 # Retrieve information from localenroll about whether to provide a button       
 # for users who have enbled import of student photos to initiate an   
 # update of photo files for registered students. Also include   
 # comment to display alongside button.    
   
 sub photo_choice_handler {  
     my ($cmd, $tail, $client) = @_;  
     my $userinput             = "$cmd:$tail";  
     my $cdom                  = &unescape($tail);  
     my ($update,$comment);  
     eval {  
  local($SIG{__DIE__})='DEFAULT';  
  ($update,$comment)    = &localenroll::manager_photo_update($cdom);  
     };  
     if (!$@) {  
  &Reply($client,&escape($update).':'.&escape($comment)."\n",$userinput);  
     } else {  
  &Failure($client,"unknown_cmd\n",$userinput);  
     }  
     return 1;  
 }  
 &register_handler("autophotochoice",\&photo_choice_handler,0,1,0);  
   
 #  #
 # Gets a student's photo to exist (in the correct image type) in the user's   # Gets a student's photo to exist (in the correct image type) in the user's 
 # directory.  # directory.
Line 4407  sub photo_choice_handler { Line 4352  sub photo_choice_handler {
 #    $client  - The socket open on the client.  #    $client  - The socket open on the client.
 # Returns:  # Returns:
 #    1 - continue processing.  #    1 - continue processing.
   
 sub student_photo_handler {  sub student_photo_handler {
     my ($cmd, $tail, $client) = @_;      my ($cmd, $tail, $client) = @_;
     my ($domain,$uname,$ext,$type) = split(/:/, $tail);      my ($domain,$uname,$type) = split(/:/, $tail);
   
     my $path=&propath($domain,$uname). '/userfiles/internal/';      my $path=&propath($domain,$uname).
     my $filename = 'studentphoto.'.$ext;   '/userfiles/internal/studentphoto.'.$type;
     if ($type eq 'thumbnail') {      if (-e $path) {
         $filename = 'studentphoto_tn.'.$ext;  
     }  
     if (-e $path.$filename) {  
  &Reply($client,"ok\n","$cmd:$tail");   &Reply($client,"ok\n","$cmd:$tail");
  return 1;   return 1;
     }      }
     &mkpath($path);      &mkpath($path);
     my $file;      my $file=&localstudentphoto::fetch($domain,$uname);
     if ($type eq 'thumbnail') {  
  eval {  
     local($SIG{__DIE__})='DEFAULT';  
     $file=&localstudentphoto::fetch_thumbnail($domain,$uname);  
  };  
     } else {  
         $file=&localstudentphoto::fetch($domain,$uname);  
     }  
     if (!$file) {      if (!$file) {
  &Failure($client,"unavailable\n","$cmd:$tail");   &Failure($client,"unavailable\n","$cmd:$tail");
  return 1;   return 1;
     }      }
     if (!-e $path.$filename) { &convert_photo($file,$path.$filename); }      if (!-e $path) { &convert_photo($file,$path); }
     if (-e $path.$filename) {      if (-e $path) {
  &Reply($client,"ok\n","$cmd:$tail");   &Reply($client,"ok\n","$cmd:$tail");
  return 1;   return 1;
     }      }
Line 4851  sub ReadHostTable { Line 4784  sub ReadHostTable {
     }      }
     $hostid{$ip}=$id;         # LonCAPA name of host by IP.      $hostid{$ip}=$id;         # LonCAPA name of host by IP.
     $hostdom{$id}=$domain;    # LonCAPA domain name of host.       $hostdom{$id}=$domain;    # LonCAPA domain name of host. 
       $hostname{$id}=$name;     # LonCAPA name -> DNS name
     $hostip{$id}=$ip;         # IP address of host.      $hostip{$id}=$ip;         # IP address of host.
     $hostdns{$name} = $id;    # LonCAPA name of host by DNS.      $hostdns{$name} = $id;    # LonCAPA name of host by DNS.
   
Line 5101  sub reconlonc { Line 5035  sub reconlonc {
   
 sub subreply {  sub subreply {
     my ($cmd,$server)=@_;      my ($cmd,$server)=@_;
     my $peerfile="$perlvar{'lonSockDir'}/$server";      my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$server};
     my $sclient=IO::Socket::UNIX->new(Peer    =>"$peerfile",      my $sclient=IO::Socket::UNIX->new(Peer    =>"$peerfile",
                                       Type    => SOCK_STREAM,                                        Type    => SOCK_STREAM,
                                       Timeout => 10)                                        Timeout => 10)
        or return "con_lost";         or return "con_lost";
     print $sclient "$cmd\n";      print $sclient "sethost:$server:$cmd\n";
     my $answer=<$sclient>;      my $answer=<$sclient>;
     chomp($answer);      chomp($answer);
     if (!$answer) { $answer="con_lost"; }      if (!$answer) { $answer="con_lost"; }
Line 5122  sub reply { Line 5056  sub reply {
  $answer=subreply("ping",$server);   $answer=subreply("ping",$server);
         if ($answer ne $server) {          if ($answer ne $server) {
     &logthis("sub reply: answer != server answer is $answer, server is $server");      &logthis("sub reply: answer != server answer is $answer, server is $server");
            &reconlonc("$perlvar{'lonSockDir'}/$server");             &reconlonc("$perlvar{'lonSockDir'}/".$hostname{$server});
         }          }
         $answer=subreply($cmd,$server);          $answer=subreply($cmd,$server);
     }      }
Line 5428  sub make_new_child { Line 5362  sub make_new_child {
     # no need to try to do recon's to myself      # no need to try to do recon's to myself
     next;      next;
  }   }
  &reconlonc("$perlvar{'lonSockDir'}/$id");   &reconlonc("$perlvar{'lonSockDir'}/".$hostname{$id});
     }      }
     &logthis("<font color='green'>Established connection: $clientname</font>");      &logthis("<font color='green'>Established connection: $clientname</font>");
     &status('Will listen to '.$clientname);      &status('Will listen to '.$clientname);

Removed from v.1.305.2.4  
changed lines
  Added in v.1.313


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>