#!/tools/bin/perl # pHTTPD - a deny-all http server used in conjunction with ip-blocking # banner ad servers in /etc/host. Prevents "could not connect to host". # # Based on tHTTPd # ## Configuration section $port=80; # Port on which we listen # the following substitutes "require 'sys/socket.ph';" on ultrix # Check if the definitions are correct with /usr/include/sys/socket.h $AF_INET=2; $PF_INET=$AF_INET; $SOCK_STREAM=1; # Messages %errors= ( "403", "Forbidden", "404", "Not Found", "500", "Internal Error", "501", "Not Implemented", ); %verrors= ( "403", "Your client is not allowed to request this item", "404", "The requested item was not found on this server", "500", "An error occurred while trying to retrieve item", "501", "This server does not support the given request type", ); # set up a server socket, redirect stderr to logfile $IPPROTO_TCP=6; $sockaddr = 'S n a4 x8'; $this = pack($sockaddr, $AF_INET, $port, "\0\0\0\0"); socket(S, $PF_INET, $SOCK_STREAM, $IPPROTO_TCP) || die "socket: $!"; bind(S, $this) || die "bind: $!"; listen(S, 5) || die "listen: $!"; # accept incoming calls for (;;) { ($addr=accept(NS,S)) || die "accept: $!"; ($a,$p,$inetaddr) = unpack($sockaddr, $addr); @inetaddr = unpack('C4', $inetaddr); ($host,$aliases) = gethostbyaddr($inetaddr, $AF_INET); $inetaddr = join(".", @inetaddr); @host=split(' ', "$host $aliases"); $host || do { $host = $inetaddr; }; @t=localtime; print LOG "** @t[1..5]: $$ connect from $host ($inetaddr)\n"; open(STDIN, "+<&NS") || die "dup2 ns->stdin"; open(STDOUT, "+>&NS") || die "dup2 ns->stdout"; select(STDOUT); $|=1; &serve_request; close(STDIN); close(STDOUT); } # Read request from stdin and produce output sub serve_request { # Analyze HTTP input. $_=; ($method, $url, $proto) = split; &error(404,$url); } sub error { # generate error response local($errno) = @_[0]; local($errmsg) = "$errno $errors{$errno}"; print LOG "$$ $errmsg (@_[1,2])\n"; print <

Ad blocked

TheEnd }