Diff for /loncom/lond between versions 1.16 and 1.45

version 1.16, 2000/07/17 16:37:14 version 1.45, 2001/03/27 13:37:43
Line 7 Line 7
 # 12/7,12/15,01/06,01/11,01/12,01/14,2/8,  # 12/7,12/15,01/06,01/11,01/12,01/14,2/8,
 # 03/07,05/31 Gerd Kortemeyer  # 03/07,05/31 Gerd Kortemeyer
 # 06/26 Scott Harrison  # 06/26 Scott Harrison
 # 06/29,06/30,07/14,07/15 Gerd Kortemeyer  # 06/29,06/30,07/14,07/15,07/17,07/20,07/25,09/18 Gerd Kortemeyer
   # 12/05 Scott Harrison
   # 12/05,12/13,12/29 Gerd Kortemeyer
   # Jan 01 Scott Harrison
   # 02/12 Gerd Kortemeyer
   # 03/15 Scott Harrison
   # 03/24 Gerd Kortemeyer
 #  #
 # based on "Perl Cookbook" ISBN 1-56592-243-3  # based on "Perl Cookbook" ISBN 1-56592-243-3
 # preforker - server who forks first  # preforker - server who forks first
Line 25  use LWP::UserAgent(); Line 31  use LWP::UserAgent();
 use GDBM_File;  use GDBM_File;
 use Authen::Krb4;  use Authen::Krb4;
   
   # grabs exception and records it to log before exiting
   sub catchexception {
       my ($error)=@_;
       $SIG{'QUIT'}='DEFAULT';
       $SIG{__DIE__}='DEFAULT';
       &logthis("<font color=red>CRITICAL: "
        ."ABNORMAL EXIT. Child $$ for server $wasserver died through "
        ."a crash with this error msg->[$error]</font>");
       if ($client) { print $client "error: $error\n"; }
       die($error);
   }
   
   # -------------------------------- Set signal handlers to record abnormal exits
   
   $SIG{'QUIT'}=\&catchexception;
   $SIG{__DIE__}=\&catchexception;
   
 # ------------------------------------ Read httpd access.conf and get variables  # ------------------------------------ Read httpd access.conf and get variables
   
 open (CONFIG,"/etc/httpd/conf/access.conf") || die "Can't read access.conf";  open (CONFIG,"/etc/httpd/conf/access.conf") || die "Can't read access.conf";
Line 38  while ($configline=<CONFIG>) { Line 61  while ($configline=<CONFIG>) {
 }  }
 close(CONFIG);  close(CONFIG);
   
   # ----------------------------- Make sure this process is running from user=www
   my $wwwid=getpwnam('www');
   if ($wwwid!=$<) {
      $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
      $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
      system("echo 'User ID mismatch.  lond must be run as user www.' |\
    mailto $emailto -s '$subj' > /dev/null");
      exit 1;
   }
   
   # --------------------------------------------- Check if other instance running
   
   my $pidfile="$perlvar{'lonDaemons'}/logs/lond.pid";
   
   if (-e $pidfile) {
      my $lfh=IO::File->new("$pidfile");
      my $pide=<$lfh>;
      chomp($pide);
      if (kill 0 => $pide) { die "already running"; }
   }
   
 $PREFORK=4; # number of children to maintain, at least four spare  $PREFORK=4; # number of children to maintain, at least four spare
   
 # ------------------------------------------------------------- Read hosts file  # ------------------------------------------------------------- Read hosts file
Line 92  sub HUPSMAN {                      # sig Line 136  sub HUPSMAN {                      # sig
     kill 'INT' => keys %children;      kill 'INT' => keys %children;
     close($server);                # free up socket      close($server);                # free up socket
     &logthis("<font color=red>CRITICAL: Restarting</font>");      &logthis("<font color=red>CRITICAL: Restarting</font>");
       unlink("$execdir/logs/lond.pid");
     my $execdir=$perlvar{'lonDaemons'};      my $execdir=$perlvar{'lonDaemons'};
     exec("$execdir/lond");         # here we go again      exec("$execdir/lond");         # here we go again
 }  }
Line 446  sub make_new_child { Line 491  sub make_new_child {
                        my                          my 
                        ($cmd,$udom,$uname,$upass,$npass)=split(/:/,$userinput);                         ($cmd,$udom,$uname,$upass,$npass)=split(/:/,$userinput);
                        chomp($npass);                         chomp($npass);
                          $upass=&unescape($upass);
                          $npass=&unescape($npass);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $passfilename="$proname/passwd";                         my $passfilename="$proname/passwd";
                        if (-e $passfilename) {                         if (-e $passfilename) {
Line 460  sub make_new_child { Line 507  sub make_new_child {
                              $salt=substr($salt,6,2);                               $salt=substr($salt,6,2);
      my $ncpass=crypt($npass,$salt);       my $ncpass=crypt($npass,$salt);
                              { my $pf = IO::File->new(">$passfilename");                               { my $pf = IO::File->new(">$passfilename");
           print $pf "internal:$ncpass\n";; }                         print $pf "internal:$ncpass\n"; }             
                              print $client "ok\n";                               print $client "ok\n";
                            } else {                             } else {
                              print $client "non_authorized\n";                               print $client "non_authorized\n";
Line 474  sub make_new_child { Line 521  sub make_new_child {
      } else {       } else {
        print $client "refused\n";         print $client "refused\n";
      }       }
   # -------------------------------------------------------------------- makeuser
                      } elsif ($userinput =~ /^makeuser/) {
        if ($wasenc==1) {
                          my 
                          ($cmd,$udom,$uname,$umode,$npass)=split(/:/,$userinput);
                          chomp($npass);
                          $npass=&unescape($npass);
                          my $proname=propath($udom,$uname);
                          my $passfilename="$proname/passwd";
                          if (-e $passfilename) {
      print $client "already_exists\n";
                          } elsif ($udom ne $perlvar{'lonDefDomain'}) {
                              print $client "not_right_domain\n";
                          } else {
                              @fpparts=split(/\//,$proname);
                              $fpnow=$fpparts[0].'/'.$fpparts[1].'/'.$fpparts[2];
                              $fperror='';
                              for ($i=3;$i<=$#fpparts;$i++) {
                                  $fpnow.='/'.$fpparts[$i]; 
                                  unless (-e $fpnow) {
      unless (mkdir($fpnow,0777)) {
                                         $fperror="error:$!\n";
                                      }
                                  }
                              }
                              unless ($fperror) {
        if ($umode eq 'krb4') {
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "krb4:$npass\n"; 
                                  }             
                                  print $client "ok\n";
                                } elsif ($umode eq 'internal') {
          my $salt=time;
                                  $salt=substr($salt,6,2);
          my $ncpass=crypt($npass,$salt);
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "internal:$ncpass\n"; 
                                  }             
                                  print $client "ok\n";
                                } elsif ($umode eq 'none') {
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "none:\n"; 
                                  }             
                                  print $client "ok\n";
                                } else {
                                  print $client "auth_mode_error\n";
                                }  
                              } else {
                                  print $client "$fperror\n";
                              }
                          }
        } else {
          print $client "refused\n";
        }
 # ------------------------------------------------------------------------ home  # ------------------------------------------------------------------------ home
                    } elsif ($userinput =~ /^home/) {                     } elsif ($userinput =~ /^home/) {
                        my ($cmd,$udom,$uname)=split(/:/,$userinput);                         my ($cmd,$udom,$uname)=split(/:/,$userinput);
Line 511  sub make_new_child { Line 615  sub make_new_child {
                              $response=$ua->request($request,$transname);                               $response=$ua->request($request,$transname);
       }        }
                              if ($response->is_error()) {                               if ($response->is_error()) {
  unline($transname);   unlink($transname);
                                  my $message=$response->status_line;                                   my $message=$response->status_line;
                                  &logthis(                                   &logthis(
                                   "LWP GET: $message for $fname ($remoteurl)");                                    "LWP GET: $message for $fname ($remoteurl)");
                              } else {                               } else {
                          if ($remoteurl!~/\.meta$/) {                           if ($remoteurl!~/\.meta$/) {
                                     my $ua=new LWP::UserAgent;
                                   my $mrequest=                                    my $mrequest=
                                    new HTTP::Request('GET',$remoteurl.'.meta');                                     new HTTP::Request('GET',$remoteurl.'.meta');
                                   my $mresponse=                                    my $mresponse=
Line 553  sub make_new_child { Line 658  sub make_new_child {
                        my $ownership=ishome($fname);                         my $ownership=ishome($fname);
                        if ($ownership eq 'owner') {                         if ($ownership eq 'owner') {
                         if (-e $fname) {                          if (-e $fname) {
    if (-d $fname) {
      print $client "directory\n";
                            } else {
                            $now=time;                             $now=time;
                            {                              { 
                             my $sh=IO::File->new(">$fname.$hostid{$clientip}");      my $sh;
                             print $sh "$clientip:$now\n";                              if ($sh=
                                IO::File->new(">$fname.$hostid{$clientip}")) {
                                  print $sh "$clientip:$now\n";
       }
    }     }
                              unless ($fname=~/\.meta$/) {
          unlink("$fname.meta.$hostid{$clientip}");
                              }
                            $fname=~s/\/home\/httpd\/html\/res/raw/;                             $fname=~s/\/home\/httpd\/html\/res/raw/;
                            $fname="http://$thisserver/".$fname;                             $fname="http://$thisserver/".$fname;
                            print $client "$fname\n";                             print $client "$fname\n";
            }
                         } else {                          } else {
          print $client "not_found\n";           print $client "not_found\n";
                         }                          }
Line 659  sub make_new_child { Line 774  sub make_new_child {
                        my @queries=split(/\&/,$what);                         my @queries=split(/\&/,$what);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $qresult='';                         my $qresult='';
       if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_WRCREAT,0640)) {        if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_READER,0640)) {
                            for ($i=0;$i<=$#queries;$i++) {                             for ($i=0;$i<=$#queries;$i++) {
                                $qresult.="$hash{$queries[$i]}&";                                 $qresult.="$hash{$queries[$i]}&";
                            }                             }
Line 682  sub make_new_child { Line 797  sub make_new_child {
                        my @queries=split(/\&/,$what);                         my @queries=split(/\&/,$what);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $qresult='';                         my $qresult='';
       if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_WRCREAT,0640)) {        if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_READER,0640)) {
                            for ($i=0;$i<=$#queries;$i++) {                             for ($i=0;$i<=$#queries;$i++) {
                                $qresult.="$hash{$queries[$i]}&";                                 $qresult.="$hash{$queries[$i]}&";
                            }                             }
Line 744  sub make_new_child { Line 859  sub make_new_child {
                        $namespace=~s/\W//g;                         $namespace=~s/\W//g;
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $qresult='';                         my $qresult='';
       if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_WRCREAT,0640)) {        if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_READER,0640)) {
                            foreach $key (keys %hash) {                             foreach $key (keys %hash) {
                                $qresult.="$key&";                                 $qresult.="$key&";
                            }                             }
Line 765  sub make_new_child { Line 880  sub make_new_child {
                        $namespace=~s/\W//g;                         $namespace=~s/\W//g;
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $qresult='';                         my $qresult='';
       if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_WRCREAT,0640)) {        if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_READER,0640)) {
                            foreach $key (keys %hash) {                             foreach $key (keys %hash) {
                                $qresult.="$key=$hash{$key}&";                                 $qresult.="$key=$hash{$key}&";
                            }                             }
Line 807  sub make_new_child { Line 922  sub make_new_child {
                                $allkeys.=$key.':';                                 $allkeys.=$key.':';
                                $hash{"$version:$rid:$key"}=$value;                                 $hash{"$version:$rid:$key"}=$value;
                            }                             }
                            $allkeys=~s/:$//;                             $hash{"$version:$rid:timestamp"}=$now;
                              $allkeys.='timestamp';
                            $hash{"$version:keys:$rid"}=$allkeys;                             $hash{"$version:keys:$rid"}=$allkeys;
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
Line 829  sub make_new_child { Line 945  sub make_new_child {
                        chomp($rid);                         chomp($rid);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $qresult='';                         my $qresult='';
       if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_WRCREAT,0640)) {        if (tie(%hash,'GDBM_File',"$proname/$namespace.db",&GDBM_READER,0640)) {
                   my $version=$hash{"version:$rid"};                    my $version=$hash{"version:$rid"};
                            $qresult.="version=$version&";                             $qresult.="version=$version&";
                            my $scope;                             my $scope;
Line 839  sub make_new_child { Line 955  sub make_new_child {
                               my $key;                                my $key;
                               $qresult.="$scope:keys=$vkeys&";                                $qresult.="$scope:keys=$vkeys&";
                               foreach $key (@keys) {                                foreach $key (@keys) {
      $qresult.="$version:$key=".$hash{"$scope:$rid:$key"}."&";       $qresult.="$scope:$key=".$hash{"$scope:$rid:$key"}."&";
                               }                                                                  }                                  
                            }                             }
    if (untie(%hash)) {     if (untie(%hash)) {
Line 853  sub make_new_child { Line 969  sub make_new_child {
                        }                         }
 # ------------------------------------------------------------------- querysend  # ------------------------------------------------------------------- querysend
                    } elsif ($userinput =~ /^querysend/) {                     } elsif ($userinput =~ /^querysend/) {
                        my ($cmd,$query)=split(/:/,$userinput);                         my ($cmd,$query,
      $custom,$customshow)=split(/:/,$userinput);
        $query=~s/\n*$//g;         $query=~s/\n*$//g;
                      print $client sqlreply("$hostid{$clientip}\&$query")."\n";         unless ($custom or $customshow) {
      print $client "".
          sqlreply("$hostid{$clientip}\&$query")."\n";
          }
          else {
      print $client "".
          sqlreply("$hostid{$clientip}\&$query".
    "\&$custom"."\&$customshow")."\n";
          }
 # ------------------------------------------------------------------ queryreply  # ------------------------------------------------------------------ queryreply
                    } elsif ($userinput =~ /^queryreply/) {                     } elsif ($userinput =~ /^queryreply/) {
                        my ($cmd,$id,$reply)=split(/:/,$userinput);                          my ($cmd,$id,$reply)=split(/:/,$userinput); 
        my $store;         my $store;
                        my $execdir=$perlvar{'lonDaemons'};                         my $execdir=$perlvar{'lonDaemons'};
                        if ($store=IO::File->new(">$execdir/tmp/$id")) {                         if ($store=IO::File->new(">$execdir/tmp/$id")) {
      $reply=~s/\&/\n/g;
    print $store $reply;     print $store $reply;
    close $store;     close $store;
    print $client "ok\n";     print $client "ok\n";
Line 904  sub make_new_child { Line 1030  sub make_new_child {
                        my $proname="$perlvar{'lonUsersDir'}/$udom/ids";                         my $proname="$perlvar{'lonUsersDir'}/$udom/ids";
                        my @queries=split(/\&/,$what);                         my @queries=split(/\&/,$what);
                        my $qresult='';                         my $qresult='';
                  if (tie(%hash,'GDBM_File',"$proname.db",&GDBM_WRCREAT,0640)) {                   if (tie(%hash,'GDBM_File',"$proname.db",&GDBM_READER,0640)) {
                            for ($i=0;$i<=$#queries;$i++) {                             for ($i=0;$i<=$#queries;$i++) {
                                $qresult.="$hash{$queries[$i]}&";                                 $qresult.="$hash{$queries[$i]}&";
                            }                             }
Line 957  sub make_new_child { Line 1083  sub make_new_child {
                        my $ulsout='';                         my $ulsout='';
                        my $ulsfn;                         my $ulsfn;
                        if (-e $ulsdir) {                         if (-e $ulsdir) {
                           while ($ulsfn=<$ulsdir/*>) {   if (opendir(LSDIR,$ulsdir)) {
                             while ($ulsfn=readdir(LSDIR)) {
      my @ulsstats=stat($ulsfn);       my @ulsstats=stat($ulsfn);
                              $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';                               $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';
                           }                            }
                             closedir(LSDIR);
           }
        } else {         } else {
                           $ulsout='no_such_dir';                            $ulsout='no_such_dir';
                        }                         }
                          if ($ulsout eq '') { $ulsout='empty'; }
                        print $client "$ulsout\n";                         print $client "$ulsout\n";
 # ------------------------------------------------------------- unknown command  # ------------------------------------------------------------- unknown command
                    } else {                     } else {

Removed from v.1.16  
changed lines
  Added in v.1.45


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