--- loncom/lonhttpd 2002/11/06 22:38:42 1.5 +++ loncom/lonhttpd 2003/02/24 23:32:32 1.6 @@ -1,7 +1,7 @@ #!/usr/bin/perl -# $Id: lonhttpd,v 1.5 2002/11/06 22:38:42 albertel Exp $ +# $Id: lonhttpd,v 1.6 2003/02/24 23:32:32 albertel Exp $ -$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 # Copyright 1999-2001 Cameron Kaiser # All rights reserved @@ -10,6 +10,17 @@ $VERSION = "1.3.2 (Demonic/Linux/LON-CAP # LON-CAPA: find httpi license and readme at CVS loncom/license # +use lib '/home/httpd/lib/perl/'; +use LONCAPA::Configuration(); +%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 = ("html" => "text/html", "htm" => "text/html", @@ -184,12 +195,13 @@ print PIDSAVE "$$\n"; close(PIDSAVE); $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); 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); -$0 = "lonhttpd: (dhttpi) connected and waiting ANY:8080"; +$0 = "lonhttpd: (dhttpi) connected and waiting ANY:$port_to_use"; $statiosuptime = time(); @@ -431,7 +443,7 @@ LonHTTPD (HTTPi) Status

LonHTTPD (HTTPi) Server Status ($VERSION)

-

lonhttpd on port 8080

+

lonhttpd on port $port_to_use

Started at: $suptime
Uptime: $d days, $h:$m:$s
Last request time: $statiosltr

@@ -478,8 +490,8 @@ EOF $ENV{'SERVER_NAME'} = "localhost"; $ENV{'SERVER_PROTOCOL'} = "HTTP/$httpver"; $ENV{'SERVER_SOFTWARE'} = "HTTPi/$VERSION"; - $ENV{'SERVER_PORT'} = "8080"; - $ENV{'SERVER_URL'} = "http://localhost:8080/"; + $ENV{'SERVER_PORT'} = "$port_to_use"; + $ENV{'SERVER_URL'} = "http://localhost:$port_to_use/"; $ENV{'SCRIPT_FILENAME'} = $raddress; $ENV{'SCRIPT_NAME'} = $address; $ENV{'REMOTE_HOST'} = $hostname; @@ -573,7 +585,7 @@ for (;;) { if ($pid = fork()) { $0 = "lonhttpd: (dhttpi) waiting for child process"; waitpid($pid, 0); - $0 = "lonhttpd: (dhttpi) on ANY:8080, last request " . + $0 = "lonhttpd: (dhttpi) on ANY:$port_to_use, last request " . scalar localtime; } else { $0 = "lonhttpd: (dhttpi) child switching to socket";