0: #!/usr/bin/perl -w
1: # pocketgopher - an RFC-1436 compliant gopher server in < 1024B
2: # Beth Skwarecki 2004
3: # This program is free software under the GNU GPL
4: use strict;
5: use IO::Socket;
6: local $/ = "\015\012";
7:
8: #### CONFIGURATION
9: my $port = '7070';
10: my $root = '/home/beth/gopher/gopher';
11: #### THAT IS ALL
12:
13: chroot $root or die "can't chroot: $!\n";
14:
15: # fork
16: local $SIG{HUP} = 'IGNORE';
17: exit if (my $pid = fork);
18:
19:
20: # listen
21: my $sock = new IO::Socket::INET
22: (LocalPort => $port,
23: Type => SOCK_STREAM,
24: Listen => 1,
25: Reuse => 1
26: ) or die "Couldn't create socket: $!\n";
27:
28:
29: # serve
30: my $s = $sock->accept();
31: while(my $req = <$s>){
32:
33: chomp (my $req = shift);
34: $req = '/'.$req;
35:
36: &error unless (-r $req);
37: $req .= '/.cache' if ( -d _ );
38: printfile($req);
39: close($sock);
40: }
41:
42:
43: sub printfile {
44: open (FILE, shift);
45: binmode FILE;
46: print $s <FILE>;
47: close FILE;
48: }
49:
50: sub error {
51: my $req = shift;
52: print $s "iBad Request: $! \tfake\t(NULL)\t0".$/;
53: }
54:
55:
56: ----------------------------
57: (code is over, notes follow)
58:
59: 2004-05-12:
60: - changed $/ to \015\012 (thanks revdiablo)
61: - did a binmode() on the filehandle (thanks Corion)
62:
63: These changes improve things to serve gopher clients on
64: different platforms; however, the code still assumes that
65: the server is running on a unix-oid OS.
66:
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|