version 1.5, 2002/11/06 22:38:42
|
version 1.13, 2007/04/11 21:37:24
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $Id$ |
# $Id$ |
|
|
$VERSION = "1.3.2 (Demonic/Linux/LON-CAPA Derivative)"; |
$VERSION = "1.3.2 (Demonic/Linux/LON-CAPA Derivative $Revison$)"; |
|
|
# HTTPi Hypertext Tiny Truncated Process Implementation |
# HTTPi Hypertext Tiny Truncated Process Implementation |
# Copyright 1999-2001 Cameron Kaiser # All rights reserved |
# Copyright 1999-2001 Cameron Kaiser # All rights reserved |
Line 10 $VERSION = "1.3.2 (Demonic/Linux/LON-CAP
|
Line 10 $VERSION = "1.3.2 (Demonic/Linux/LON-CAP
|
# LON-CAPA: find httpi license and readme at CVS loncom/license |
# LON-CAPA: find httpi license and readme at CVS loncom/license |
# |
# |
|
|
|
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)) { |
|
$port_to_use='8080'; |
|
} |
|
|
|
# The main server is running on 80, so exit in this case |
|
if ($port_to_use eq '80') { die('Apache is already on Port 80'); } |
|
|
%system_content_types = |
%system_content_types = |
("html" => "text/html", |
("html" => "text/html", |
"htm" => "text/html", |
"htm" => "text/html", |
Line 40 $VERSION = "1.3.2 (Demonic/Linux/LON-CAP
|
Line 52 $VERSION = "1.3.2 (Demonic/Linux/LON-CAP
|
"mpeg" => "video/mpeg", |
"mpeg" => "video/mpeg", |
"mpg" => "video/mpeg", |
"mpg" => "video/mpeg", |
"jpeg" => "image/jpeg", |
"jpeg" => "image/jpeg", |
"jpg" => "image/jpeg"); |
"jpg" => "image/jpeg", |
|
"png" => "image/png"); |
|
|
$logfile = "/home/httpd/perl/logs/lonhttpd.log"; |
$logfile = "/home/httpd/perl/logs/lonhttpd.log"; |
|
|
Line 50 $pidfile="/home/httpd/perl/logs/lonhttpd
|
Line 63 $pidfile="/home/httpd/perl/logs/lonhttpd
|
|
|
if (-e $pidfile) { |
if (-e $pidfile) { |
open(LFH,"$pidfile"); |
open(LFH,"$pidfile"); |
my $pide=<$LFH>; |
my $pide=<LFH>; |
chomp($pide); |
chomp($pide); |
close(LFH); |
close(LFH); |
if (kill 0 => $pide) { die "already running"; } |
if (kill 0 => $pide) { die "already running"; } |
Line 184 print PIDSAVE "$$\n";
|
Line 197 print PIDSAVE "$$\n";
|
close(PIDSAVE); |
close(PIDSAVE); |
|
|
$0 = "lonhttpd: (dhttpi) binding port ..."; |
$0 = "lonhttpd: (dhttpi) binding port ..."; |
$bindthis = pack($sockaddr, 2, 8080, pack('l', chr(0).chr(0).chr(0).chr(0))); |
$bindthis = pack($sockaddr, 2, $port_to_use, |
|
pack('l', chr(0).chr(0).chr(0).chr(0))); |
socket(S, 2, 1, 6); |
socket(S, 2, 1, 6); |
setsockopt(S, 1, 2, 1); |
setsockopt(S, 1, 2, 1); |
bind(S, $bindthis) || die("$0: while binding port 8080:\n\"$!\"\n"); |
bind(S, $bindthis) || die("$0: while binding port $port_to_use:\n\"$!\"\n"); |
listen(S, 128); |
listen(S, 128); |
$0 = "lonhttpd: (dhttpi) connected and waiting ANY:8080"; |
$0 = "lonhttpd: (dhttpi) connected and waiting ANY:$port_to_use"; |
|
|
$statiosuptime = time(); |
$statiosuptime = time(); |
|
|
Line 248 EOF
|
Line 262 EOF
|
} |
} |
|
|
|
|
sub bye { unlink($pidfile); exit; } |
sub bye { exit; } |
|
|
|
sub goodbye { unlink($pidfile); exit; } |
|
|
sub dead { |
sub dead { |
&htsponse(500, "Server Error"); |
&htsponse(500, "Server Error"); |
Line 264 EOF
|
Line 280 EOF
|
} |
} |
|
|
$SIG{'__DIE__'} = \&dead; |
$SIG{'__DIE__'} = \&dead; |
$SIG{'ALRM'} = $SIG{'TERM'} = $SIG{'INT'} = \&bye; |
$SIG{'ALRM'} = \&bye; |
|
$SIG{'TERM'} = $SIG{'INT'} = \&goodbye; |
|
|
sub master { |
sub master { |
$0 = "lonhttpd: (dhttpi) handling request"; |
$0 = "lonhttpd: (dhttpi) handling request"; |
Line 284 $date = "$dt/$mon/$yr:$tm +0000";
|
Line 301 $date = "$dt/$mon/$yr:$tm +0000";
|
select(STDOUT); $|=1; $address = 0; |
select(STDOUT); $|=1; $address = 0; |
alarm 1; |
alarm 1; |
while (<STDIN>) { |
while (<STDIN>) { |
if(/^([A-Z]+)\s+([^\s]+)\s+([^\s\r\l\n]*)/) { |
if(/^([A-Z]+)\s+(\S+)\s+(\S*)/) { |
$method = $1; |
$method = $1; |
$address = $2; |
$address = $2; |
$httpver = $3; |
$httpver = $3; |
Line 333 while (<STDIN>) {
|
Line 350 while (<STDIN>) {
|
1 while $address =~ s#/\.(/|$)#\1#; |
1 while $address =~ s#/\.(/|$)#\1#; |
1 while $address =~ s#/[^/]*/\.\.(/|$)#\1#; |
1 while $address =~ s#/[^/]*/\.\.(/|$)#\1#; |
1 while $address =~ s#^/\.\.(/|$)#\1#; |
1 while $address =~ s#^/\.\.(/|$)#\1#; |
$fail = 0; |
$fail = 1; |
# |
# |
# Heavily customized for LON-CAPA |
# Heavily customized for LON-CAPA |
# |
# |
$address=~s/\/+/\//g; |
$address=~s/\/+/\//g; |
unless ($address=~/^\/(status|adm\/|res\/adm\/)/) { $fail=1; } |
if ($address=~/^\/(status|adm\/|res\/adm\/)/) { |
|
$fail = 0; |
|
} elsif (&Apache::lonnet::is_domainimage($address)) { |
|
$fail = 0; |
|
} |
# |
# |
# because existing restriction matrix would not do precedence across rules |
# because existing restriction matrix would not do precedence across rules |
# |
# |
Line 362 while (<STDIN>) {
|
Line 383 while (<STDIN>) {
|
if ($fail) { |
if ($fail) { |
&htsponse(403, "Forbidden"); |
&htsponse(403, "Forbidden"); |
if ($fail == 1) { |
if ($fail == 1) { |
&hterror("Forbidden (Client Disallowed)", <<"EOF"); |
&hterror("Wrong URL", <<"EOF"); |
Your network address (<i>$ip</i>) is not allowed to access this resource. |
You might want to remove the "<tt>:$port_to_use</tt>" from the web page address (URL). |
EOF |
EOF |
&log; exit; |
&log; exit; |
} else { |
} else { |
Line 431 LonHTTPD (HTTPi) Status
|
Line 452 LonHTTPD (HTTPi) Status
|
</head> |
</head> |
<body bgcolor = "#ffffff" text = "#000000" vlink = "#0000ff" link = "#0000ff"> |
<body bgcolor = "#ffffff" text = "#000000" vlink = "#0000ff" link = "#0000ff"> |
<h1>LonHTTPD (HTTPi) Server Status (<code>$VERSION</code>)</h1> |
<h1>LonHTTPD (HTTPi) Server Status (<code>$VERSION</code>)</h1> |
<h3>lonhttpd on port 8080</h3> |
<h3>lonhttpd on port $port_to_use</h3> |
<b>Started at:</b> $suptime<br> |
<b>Started at:</b> $suptime<br> |
<b>Uptime:</b> $d days, $h:$m:$s<br> |
<b>Uptime:</b> $d days, $h:$m:$s<br> |
<b>Last request time:</b> $statiosltr<p> |
<b>Last request time:</b> $statiosltr<p> |
Line 478 EOF
|
Line 499 EOF
|
$ENV{'SERVER_NAME'} = "localhost"; |
$ENV{'SERVER_NAME'} = "localhost"; |
$ENV{'SERVER_PROTOCOL'} = "HTTP/$httpver"; |
$ENV{'SERVER_PROTOCOL'} = "HTTP/$httpver"; |
$ENV{'SERVER_SOFTWARE'} = "HTTPi/$VERSION"; |
$ENV{'SERVER_SOFTWARE'} = "HTTPi/$VERSION"; |
$ENV{'SERVER_PORT'} = "8080"; |
$ENV{'SERVER_PORT'} = "$port_to_use"; |
$ENV{'SERVER_URL'} = "http://localhost:8080/"; |
$ENV{'SERVER_URL'} = "http://localhost:$port_to_use/"; |
$ENV{'SCRIPT_FILENAME'} = $raddress; |
$ENV{'SCRIPT_FILENAME'} = $raddress; |
$ENV{'SCRIPT_NAME'} = $address; |
$ENV{'SCRIPT_NAME'} = $address; |
$ENV{'REMOTE_HOST'} = $hostname; |
$ENV{'REMOTE_HOST'} = $hostname; |
Line 573 for (;;) {
|
Line 594 for (;;) {
|
if ($pid = fork()) { |
if ($pid = fork()) { |
$0 = "lonhttpd: (dhttpi) waiting for child process"; |
$0 = "lonhttpd: (dhttpi) waiting for child process"; |
waitpid($pid, 0); |
waitpid($pid, 0); |
$0 = "lonhttpd: (dhttpi) on ANY:8080, last request " . |
$0 = "lonhttpd: (dhttpi) on ANY:$port_to_use, last request " . |
scalar localtime; |
scalar localtime; |
} else { |
} else { |
$0 = "lonhttpd: (dhttpi) child switching to socket"; |
$0 = "lonhttpd: (dhttpi) child switching to socket"; |