#!/usr/local/bin/perl -Tw # -*- Mode: cperl -*- # small web proxy - Ronan Le Hy # usage: prox [port] # (default port is 8888) # works fine with Netscape 4.75, ok with Konqueror 1.9.8 (some problems though) use strict; use Socket; use IO::Handle; sub extract; sub filter; $SIG{KILL} = sub {close PROX; close NAV; close HOST; exit;}; # we don't want to exit if a connection is cut $SIG{PIPE} = sub {}; $SIG{CHLD} = sub {wait;}; my $port_proxy = $ARGV[0] || 8888; # if you surf perlmonks with those defaults on, that's gonna be fun :) my %translation_table = ( 'azatoth' => 'OeufMayo', 'merlyn' => 'Erudil', 'BooK' => 'azatoth', 'mirod' => 'merlyn', 'Dominus' => 'BooK', 'tilly' => 'vroom', 'tye' => 'Dominus', 'virtualsue' => 'tye', 'crazyinsomniac' => 'tilly', 'OeufMayo' => 'virtualsue', 'Erudil' => 'mirod', 'vroom' => 'crazyinsomniac', 'NodeReaper' => 'root', 'root' => 'NodeReaper' ); # untaint that harmless $port_proxy if ($port_proxy =~ /(\d*)/) { $port_proxy = $1; } else { die "I'd really like to see that happen!\n"; } # open server a server socket so we can wait for connections my $tcp = getprotobyname('tcp'); socket(PROX, PF_INET, SOCK_STREAM, $tcp) || die "socket: $!"; bind(PROX, sockaddr_in($port_proxy, INADDR_ANY)) || die "bind: $!"; listen(PROX,SOMAXCONN) || die "listen: $!"; while (accept(NAV, PROX)) { # we fork to manage that connection unless (fork()) { # the first line of the request (the one with GET) my $get = ''; $get =