--- loncom/lonhttpd	2003/07/01 19:57:45	1.8
+++ loncom/lonhttpd	2007/04/11 19:52:44	1.12
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: lonhttpd,v 1.8 2003/07/01 19:57:45 albertel Exp $
+# $Id: lonhttpd,v 1.12 2007/04/11 19:52:44 raeburn Exp $
 
 $VERSION = "1.3.2 (Demonic/Linux/LON-CAPA Derivative $Revison$)";
 
@@ -12,6 +12,7 @@ $VERSION = "1.3.2 (Demonic/Linux/LON-CAP
 
 use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration();
+use Apache::lonnet;
 %loncapavar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')};
 $port_to_use=$loncapavar{'lonhttpdPort'};
 if (!defined($port_to_use)) {
@@ -51,7 +52,8 @@ if ($port_to_use eq '80') { die('Apache
 	 "mpeg" => "video/mpeg",
 	 "mpg" => "video/mpeg",
 	 "jpeg" => "image/jpeg",
-	 "jpg" => "image/jpeg");
+	 "jpg" => "image/jpeg",
+         "png" => "image/png");
 
 $logfile = "/home/httpd/perl/logs/lonhttpd.log";
 
@@ -61,7 +63,7 @@ $pidfile="/home/httpd/perl/logs/lonhttpd
 
 if (-e $pidfile) {
    open(LFH,"$pidfile");
-   my $pide=<$LFH>;
+   my $pide=<LFH>;
    chomp($pide);
    close(LFH);
    if (kill 0 => $pide) { die "already running"; }
@@ -260,7 +262,9 @@ EOF
 	}
 
 
-sub bye { unlink($pidfile); exit; }
+sub bye { exit; }
+
+sub goodbye { unlink($pidfile); exit; }
 
 sub dead {
 	&htsponse(500, "Server Error");
@@ -276,7 +280,8 @@ EOF
 }
 
 $SIG{'__DIE__'} = \&dead;
-$SIG{'ALRM'} = $SIG{'TERM'} = $SIG{'INT'} = \&bye;
+$SIG{'ALRM'} = \&bye;
+$SIG{'TERM'} = $SIG{'INT'} = \&goodbye;
 
 sub master {
 	$0 = "lonhttpd: (dhttpi) handling request";
@@ -345,12 +350,19 @@ while (<STDIN>) {
 	1 while $address =~ s#/\.(/|$)#\1#;
         1 while $address =~ s#/[^/]*/\.\.(/|$)#\1#;
 	1 while $address =~ s#^/\.\.(/|$)#\1#;
-	$fail = 0;
+	$fail = 1;
 #
 # Heavily customized for LON-CAPA
 #
 	$address=~s/\/+/\//g;
-	unless ($address=~/^\/(status|adm\/|res\/adm\/)/) { $fail=1; }
+        if ($address=~/^\/(status|adm\/|res\/adm\/)/) {
+            $fail = 0;
+        } elsif ($address =~ /^\/res\/([^\/]+)\/\1\-domainconfig\/(logo|domlogo|img)\/[^\/]+$/) {
+            if (&Apache::lonnet::domain($1) ne '') {
+                $fail = 0;
+            }
+        }
+
 #
 # because existing restriction matrix would not do precedence across rules
 #