#!/usr/bin/perl -w # pocketgopher - an RFC-1436 compliant gopher server in < 1024B # Beth Skwarecki 2004 # This program is free software under the GNU GPL use strict; use IO::Socket; local $/ = "\015\012"; #### CONFIGURATION my $port = '7070'; my $root = '/home/beth/gopher/gopher'; #### THAT IS ALL chroot $root or die "can't chroot: $!\n"; # fork local $SIG{HUP} = 'IGNORE'; exit if (my $pid = fork); # listen my $sock = new IO::Socket::INET (LocalPort => $port, Type => SOCK_STREAM, Listen => 1, Reuse => 1 ) or die "Couldn't create socket: $!\n"; # serve my $s = $sock->accept(); while(my $req = <$s>){ chomp (my $req = shift); $req = '/'.$req; &error unless (-r $req); $req .= '/.cache' if ( -d _ ); printfile($req); close($sock); } sub printfile { open (FILE, shift); binmode FILE; print $s ; close FILE; } sub error { my $req = shift; print $s "iBad Request: $! \tfake\t(NULL)\t0".$/; } ---------------------------- (code is over, notes follow) 2004-05-12: - changed $/ to \015\012 (thanks revdiablo) - did a binmode() on the filehandle (thanks Corion) These changes improve things to serve gopher clients on different platforms; however, the code still assumes that the server is running on a unix-oid OS.