CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Perl Webserver



Jan 2, 2005, 2:00 AM

Post #1 of 1 (1074 views)
Perl Webserver Can't Post


I'm making a web server in perl, mainly because with Apache it's not possible to execute commands in perl scripts which need root access (except running apache as root which is bad).

Here's what i've got so far:

print "Content-Type:text/html\n\n";
use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => '',
LocalPort => 7070,
Proto => 'tcp',
Listen => 100,
Reuse => 1
die "Socket could not be created. Reason: $!" unless $sock;

print "Socket Created.\n";

while ($new_sock = $sock->accept()) {
print "Incoming connection...\n";

$data = <$new_sock>;
if($data=~/GET/){ @split=split /GET /,$buf; }
if($data=~/POST/){ @split=split /POST /,$buf; }

@split2=split /HTTP/, $split[1];
print "Request was for $file\n";

if($file =~ /.cgi/) { @msg=`perl $file`; }

else {
open FILE, "$file";
close FILE;

foreach $msg (@msg)
$new_sock->send($msg) or print "Not sent";
print "Sent $msg\n";

OK, this is great for simple pages, and it can even display 'static' .cgi pages.

However, since the whole purpose of this mini web server is to serve CGI pages to manage the server, it needs to do a bit more.

I've discovered that the Perl pages, which work on Apache won't do the things i want them to do on my mini server:

1. Read Cookies

2. ENV Variables

3. Get inputs using CGI->Param();

Is there some module perhaps i can use to call my perl scripts (instead of just using backticks to run via the command line?).

I understand that i will need to write something equivilent to the apache 'mod_cgi' to get it to work.

Or maybe you could suggest another webserver that is simple, but it must have good support for CGI files.

I've tried PerlWebserver 0.4, but it only works on domains, and i want to really be able to go anywhere on my server, and just type :9090 to get to my scripts, like Apache does. It also seems to have a tendency to die after serving about 5 pages.

Thanks in advance,


(This post was edited by andy7t on Jan 2, 2005, 2:04 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives