Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.394 and 1.406

version 1.394, 2003/07/25 01:18:04 version 1.406, 2003/08/26 04:56:30
Line 76  qw(%perlvar %hostname %homecache %badSer Line 76  qw(%perlvar %hostname %homecache %badSer
    %libserv %pr %prp %metacache %packagetab %titlecache      %libserv %pr %prp %metacache %packagetab %titlecache 
    %courselogs %accesshash %userrolehash $processmarker $dumpcount      %courselogs %accesshash %userrolehash $processmarker $dumpcount 
    %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseresdatacache      %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseresdatacache 
    %domaindescription %domain_auth_def %domain_auth_arg_def $tmpdir);     %domaindescription %domain_auth_def %domain_auth_arg_def 
      %domain_lang_def %domain_city %domain_longi %domain_lati $tmpdir);
   
 use IO::Socket;  use IO::Socket;
 use GDBM_File;  use GDBM_File;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
Line 243  sub critical { Line 245  sub critical {
     }      }
     return $answer;      return $answer;
 }  }
   
   # -------------- Remove all key from the env that start witha lowercase letter
   #                (Which is alweways a lon-capa value)
   sub cleanenv {
       foreach my $key (keys(%ENV)) {
    if ($key =~ /^[a-z]/) {
       delete($ENV{$key});
    }
       }
   }
     
 # ------------------------------------------- Transfer profile into environment  # ------------------------------------------- Transfer profile into environment
   
Line 377  sub userload { Line 389  sub userload {
  my $curtime=time;   my $curtime=time;
  while ($filename=readdir(LONIDS)) {   while ($filename=readdir(LONIDS)) {
     if ($filename eq '.' || $filename eq '..') {next;}      if ($filename eq '.' || $filename eq '..') {next;}
     my ($atime)=(stat($perlvar{'lonIDsDir'}.'/'.$filename))[8];      my ($mtime)=(stat($perlvar{'lonIDsDir'}.'/'.$filename))[9];
     if ($curtime-$atime < 3600) { $numusers++; }      if ($curtime-$mtime < 3600) { $numusers++; }
  }   }
  closedir(LONIDS);   closedir(LONIDS);
     }      }
Line 1284  sub get_course_adv_roles { Line 1296  sub get_course_adv_roles {
     return %returnhash;      return %returnhash;
 }  }
   
   sub get_my_roles {
       my ($uname,$udom)=@_;
       unless (defined($uname)) { $uname=$ENV{'user.name'}; }
       unless (defined($udom)) { $udom=$ENV{'user.domain'}; }
       my %dumphash=
               &dump('nohist_userroles',$udom,$uname);
       my %returnhash=();
       my $now=time;
       foreach (keys %dumphash) {
    my ($tend,$tstart)=split(/\:/,$dumphash{$_});
           if (($tstart) && ($tstart<0)) { next; }
           if (($tend) && ($tend<$now)) { next; }
           if (($tstart) && ($now<$tstart)) { next; }
           my ($role,$username,$domain,$section)=split(/\:/,$_);
    $returnhash{$username.':'.$domain.':'.$role}=$tstart.':'.$tend;
        }
       return %returnhash;
   }
   
   # ----------------------------------------------------- Frontpage Announcements
   #
   #
   
   sub postannounce {
       my ($server,$text)=@_;
       unless (&allowed('psa',$hostdom{$server})) { return 'refused'; }
       unless ($text=~/\w/) { $text=''; }
       return &reply('setannounce:'.&escape($text),$server);
   }
   
   sub getannounce {
       if (my $fh=Apache::File->new($perlvar{'lonDocRoot'}.'/announcement.txt')) {
    my $announcement='';
    while (<$fh>) { $announcement .=$_; }
    $fh->close();
    if ($announcement=~/\w/) { 
       return 
      '<table bgcolor="#FF5555" cellpadding="5" cellspacing="3">'.
      '<tr><td bgcolor="#FFFFFF"><pre>'.$announcement.'</pre></td></tr></table>'; 
    } else {
       return '';
    }
       } else {
    return '';
       }
   }
   
 # ---------------------------------------------------------- Course ID routines  # ---------------------------------------------------------- Course ID routines
 # Deal with domain's nohist_courseid.db files  # Deal with domain's nohist_courseid.db files
 #  #
Line 2209  sub customaccess { Line 2268  sub customaccess {
             $access=($effect eq 'allow');              $access=($effect eq 'allow');
             last;              last;
         }          }
    if ($realm eq '' && $role eq '') {
               $access=($effect eq 'allow');
    }
     }      }
     return $access;      return $access;
 }  }
Line 2221  sub allowed { Line 2283  sub allowed {
     my $orguri=$uri;      my $orguri=$uri;
     $uri=&declutter($uri);      $uri=&declutter($uri);
   
       if (defined($ENV{'allowed.'.$priv})) { return $ENV{'allowed.'.$priv}; }
 # Free bre access to adm and meta resources  # Free bre access to adm and meta resources
   
     if ((($uri=~/^adm\//) || ($uri=~/\.meta$/)) && ($priv eq 'bre')) {      if ((($uri=~/^adm\//) || ($uri=~/\.meta$/)) && ($priv eq 'bre')) {
Line 2746  sub modifyuser { Line 2809  sub modifyuser {
              ' in domain '.$ENV{'request.role.domain'});               ' in domain '.$ENV{'request.role.domain'});
     my $uhome=&homeserver($uname,$udom,'true');      my $uhome=&homeserver($uname,$udom,'true');
 # ----------------------------------------------------------------- Create User  # ----------------------------------------------------------------- Create User
     if (($uhome eq 'no_host') && ($umode) && ($upass)) {      if (($uhome eq 'no_host') && 
    (($umode && $upass) || ($umode eq 'localauth'))) {
         my $unhome='';          my $unhome='';
         if (defined($desiredhome) && $hostdom{$desiredhome} eq $udom) {           if (defined($desiredhome) && $hostdom{$desiredhome} eq $udom) { 
             $unhome = $desiredhome;              $unhome = $desiredhome;
Line 3070  sub dirlist { Line 3134  sub dirlist {
         }          }
         my $alldomstr='';          my $alldomstr='';
         foreach (sort keys %alldom) {          foreach (sort keys %alldom) {
             $alldomstr.=$perlvar{'lonDocRoot'}.'/res/'.$_.'&domain:';              $alldomstr.=$perlvar{'lonDocRoot'}.'/res/'.$_.'/&domain:';
         }          }
         $alldomstr=~s/:$//;          $alldomstr=~s/:$//;
         return split(/:/,$alldomstr);                 return split(/:/,$alldomstr);       
Line 3222  sub EXT_cache_set { Line 3286  sub EXT_cache_set {
   
 # --------------------------------------------------------- Value of a Variable  # --------------------------------------------------------- Value of a Variable
 sub EXT {  sub EXT {
     my ($varname,$symbparm,$udom,$uname,$usection)=@_;      my ($varname,$symbparm,$udom,$uname,$usection,$recurse)=@_;
   
     unless ($varname) { return ''; }      unless ($varname) { return ''; }
     #get real user name/domain, courseid and symb      #get real user name/domain, courseid and symb
Line 3323  sub EXT { Line 3387  sub EXT {
         return $ENV{'course.'.$courseid.'.'.$spacequalifierrest};          return $ENV{'course.'.$courseid.'.'.$spacequalifierrest};
     } elsif ($realm eq 'resource') {      } elsif ($realm eq 'resource') {
   
    my $section;
  if (defined($courseid) && $courseid eq $ENV{'request.course.id'}) {   if (defined($courseid) && $courseid eq $ENV{'request.course.id'}) {
   
     #print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest;      #print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest;
Line 3335  sub EXT { Line 3400  sub EXT {
     my $symbparm=$symbp.'.'.$spacequalifierrest;      my $symbparm=$symbp.'.'.$spacequalifierrest;
     my $mapparm=$mapp.'___(all).'.$spacequalifierrest;      my $mapparm=$mapp.'___(all).'.$spacequalifierrest;
   
     my $section;  
     if (($ENV{'user.name'} eq $uname) &&      if (($ENV{'user.name'} eq $uname) &&
  ($ENV{'user.domain'} eq $udom)) {   ($ENV{'user.domain'} eq $udom)) {
  $section=$ENV{'request.course.sec'};   $section=$ENV{'request.course.sec'};
Line 3426  sub EXT { Line 3490  sub EXT {
     my $part=join('_',@parts);      my $part=join('_',@parts);
     if ($part eq '') { $part='0'; }      if ($part eq '') { $part='0'; }
     my $partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,      my $partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,
  $symbparm,$udom,$uname);   $symbparm,$udom,$uname,$section,1);
     if (defined($partgeneral)) { return $partgeneral; }      if (defined($partgeneral)) { return $partgeneral; }
  }   }
    if ($recurse) { return undef; }
    my $pack_def=&packages_tab_default($filename,$varname);
    if (defined($pack_def)) { return $pack_def; }
   
 # ---------------------------------------------------- Any other user namespace  # ---------------------------------------------------- Any other user namespace
     } elsif ($realm eq 'environment') {      } elsif ($realm eq 'environment') {
Line 3449  sub EXT { Line 3516  sub EXT {
     return '';      return '';
 }  }
   
   sub packages_tab_default {
       my ($uri,$varname)=@_;
       my (undef,$part,$name)=split(/\./,$varname);
       my $packages=&metadata($uri,'packages');
       foreach my $package (split(/,/,$packages)) {
    my ($pack_type,$pack_part)=split(/_/,$package,2);
    if ($pack_part eq $part) {
       return $packagetab{"$pack_type&$name&default"};
    }
       }
       return undef;
   }
   
 sub add_prefix_and_part {  sub add_prefix_and_part {
     my ($prefix,$part)=@_;      my ($prefix,$part)=@_;
     my $keyroot;      my $keyroot;
Line 3490  sub metadata { Line 3570  sub metadata {
         if ($liburi) {          if ($liburi) {
     $liburi=&declutter($liburi);      $liburi=&declutter($liburi);
             $filename=$liburi;              $filename=$liburi;
         }          } else {
       delete($metacache{$uri.':packages'});
    }
         my %metathesekeys=();          my %metathesekeys=();
         unless ($filename=~/\.meta$/) { $filename.='.meta'; }          unless ($filename=~/\.meta$/) { $filename.='.meta'; }
  my $metastring=&getfile(&filelocation('',&clutter($filename)));   my $metastring=&getfile(&filelocation('',&clutter($filename)));
         my $parser=HTML::LCParser->new(\$metastring);          my $parser=HTML::LCParser->new(\$metastring);
         my $token;          my $token;
         undef %metathesekeys;          undef %metathesekeys;
  delete($metacache{$uri.':packages'});  
         while ($token=$parser->get_token) {          while ($token=$parser->get_token) {
     if ($token->[0] eq 'S') {      if ($token->[0] eq 'S') {
  if (defined($token->[2]->{'package'})) {   if (defined($token->[2]->{'package'})) {
Line 3517  sub metadata { Line 3598  sub metadata {
     foreach (keys %packagetab) {      foreach (keys %packagetab) {
  if ($_=~/^$package\&/) {   if ($_=~/^$package\&/) {
     my ($pack,$name,$subp)=split(/\&/,$_);      my ($pack,$name,$subp)=split(/\&/,$_);
       # ignore package.tab specified default values
                               # here &package_tab_default() will fetch those
       if ($subp eq 'default') { next; }
     my $value=$packagetab{$_};      my $value=$packagetab{$_};
     my $part=$keyroot;      my $part=$keyroot;
     $part=~s/^\_//;      $part=~s/^\_//;
Line 3524  sub metadata { Line 3608  sub metadata {
  $value.=' [Part: '.$part.']';   $value.=' [Part: '.$part.']';
     }      }
     my $unikey='parameter'.$keyroot.'_'.$name;      my $unikey='parameter'.$keyroot.'_'.$name;
     if ($subp eq 'default') {      $metacache{$uri.':'.$unikey.'.part'}=$part;
  $unikey='parameter_0_'.$name;      $metathesekeys{$unikey}=1;
  $metacache{$uri.':'.$unikey.'.part'}='0';  
     } else {  
  $metacache{$uri.':'.$unikey.'.part'}=$part;  
  $metathesekeys{$unikey}=1;  
     }  
     unless (defined($metacache{$uri.':'.$unikey.'.'.$subp})) {      unless (defined($metacache{$uri.':'.$unikey.'.'.$subp})) {
  $metacache{$uri.':'.$unikey.'.'.$subp}=$value;   $metacache{$uri.':'.$unikey.'.'.$subp}=$value;
     }      }
Line 4105  BEGIN { Line 4184  BEGIN {
            next if (/^(\#|\s*$)/);             next if (/^(\#|\s*$)/);
 #           next if /^\#/;  #           next if /^\#/;
            chomp;             chomp;
            my ($domain, $domain_description, $def_auth, $def_auth_arg)             my ($domain, $domain_description, $def_auth, $def_auth_arg,
                = split(/:/,$_,4);         $def_lang, $city, $longi, $lati) = split(/:/,$_);
            $domain_auth_def{$domain}=$def_auth;     $domain_auth_def{$domain}=$def_auth;
            $domain_auth_arg_def{$domain}=$def_auth_arg;             $domain_auth_arg_def{$domain}=$def_auth_arg;
            $domaindescription{$domain}=$domain_description;     $domaindescription{$domain}=$domain_description;
      $domain_lang_def{$domain}=$def_lang;
      $domain_city{$domain}=$city;
      $domain_longi{$domain}=$longi;
      $domain_lati{$domain}=$lati;
   
 #          &logthis("Domain.tab: $domain, $domain_auth_def{$domain}, $domain_auth_arg_def{$domain},$domaindescription{$domain}");  #          &logthis("Domain.tab: $domain, $domain_auth_def{$domain}, $domain_auth_arg_def{$domain},$domaindescription{$domain}");
 #          &logthis("Domain.tab: $domain ".$domaindescription{$domain} );  #          &logthis("Domain.tab: $domain ".$domaindescription{$domain} );
        }         }

Removed from v.1.394  
changed lines
  Added in v.1.406


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