Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I invoke a perl scipt on startup? Is it merely a matter of adding it to the rc.local (Slackware) startup file, or is there more to it? And once it's started, how would I check to see which port it is listening on?
I like using John LoVerso's no-ads.pac for filtering unwanted sites from the intenet, which routes such request to what he calls a black hole proxy. This proxy can be nothing more than a localhost port (default is localhost:3421) that is unused and works fine for most of the major browsers, except Opera seems to be unable to use the no-ads file as is. I think it needs an proxy that responds to such requests instead of merely timing out.
John has a noproxy script which has instructions for seting it up, and also mentions a perl script called black_hole_http_server.pl written by Sean Burke which I would like to try out.. However, this perl script doesn't have any instructions a n00b can use for implementing it.
Well, that perl script didn't work by just entering it in rc.local, or even just invoking it from a command line. I tried it without args and with args. It will accept port numbers as args, but all it does is.........nothing. Doesn't even return the command prompt, but just hangs forever.
So I tried using it from inetd.conf, like the instructions in the noproxy script and substituting the path, like so:
Then finding the PID for inetd with the 'ps -x' command so i can restart inetd with the kill command:
Code:
kill -HUP <PID of inetd>
This seemed to work, but Opera still doesn't like the no-ads.pac autoconfig proxy file (it stills tends to hang for quite a while). Oh well, guess I'll have to stick with using Privoxy with Opera for filtering ads.......
How do you separate a case when a program 'does nothing' from a case when a program 'waits for a connection to the port' or from a case when a program 'waits for input from the stdin'?
(Well, either by looking the source or checking with lsof -i, but you didn't mention using it in this particular case)
Actually, ToniT, you were a big help for me.....I learned about the lsof command, and after readng the man pages, got a better idea on its uses.......Usually, this is all it takes for me, a pointer in the right direction and then I can go from there.
I did read the source file for the perl script, but it didn't tell me much, as you can see (not commented), and I'm not familiar with the perl language:
Code:
#!/usr/bin/perl
# Time-stamp: "2002-02-22 14:01:52 MST"
#
# Black-hole proxy server. sburke@cpan.org
#
use strict;
use IO::Socket qw(: DEFAULT :crlf);
use constant MY_PORT => 9123;
use constant DEBUG => 0;
my $image_type = 'image/gif';
my $image = "$ENV{'HOME'}/public_html/null.gif";
{
if(PrivoxyWindowOpen(IN, "<$image")) {
binmode(IN);
local $/;
$image = join '',
"HTTP/1.0 200 OK", CRLF,
"Content-Type: ", $image_type, CRLF, CRLF,
<IN>;
close(IN);
} else {
# Default image:
$image = join '',
"HTTP/1.0 200 OK", CRLF,
"Content-Type: ", $image_type, CRLF, CRLF,
# 8x8 image: box with a border.
"\x47\x49\x46\x38\x37\x61\x08\x00\x08\x00\xb3",
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x40\x40\x40", # Inside box color
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x00\x00\x00", # Outside border color
# Actual gif data:
"\x2c\x00\x00\x00\x00\x08\x00\x08\x00\x00\x04\x0e\xf0\xc9\x49",
"\xeb\x3c\xf8\xd0\xac\x6f\xde\x9f\x25\x52\x11\x00\x3b",
;
}
}
#-----------------------------------------------------------------------------
my $quit = 0;
$SIG{'INT'} = sub {$quit = 1};
my $sock = IO::Socket::INET->new(
Listen => 20, LocalPort => shift(@ARGV)|| MY_PORT,
Timeout => 60 * 60, Reuse => 1,
) or die "Can't create listening socket: $!\n";
DEBUG and warn "Waiting for connections...\n";
my($session, $peer, $port);
while(!$quit) {
next unless my $session = $sock->accept;
if(DEBUG) {
$peer = gethostbyaddr($session->peeraddr, AF_INET)
|| $session->peerhost;
$port = $session->peerport;
warn "Connection from [$peer,$port] at ", scalar(localtime), "\n";
}
#select($session);
#++$|;
#select(STDOUT);
print $session $image;
close($session);
DEBUG and print " (Closed)\n";
}
DEBUG and print STDERR "Byebye\n";
close($sock);
exit 0;
I opened up the no-ads.pac file again (which is very well commented) and reread the section on black hole proxies and noticed that this perl program is a 'wait' style script, which I interpret to mean that when invoked it will wait for input. But how do I use it, I kept asking myself? Here's the relevant part I'm talking about:
Code:
// b. A simple, blackhole server
//
// When needed, I run a simple "server" at port 3421 that denies
// all requests. Some options you can use for this:
//
// - On Windows, you can try Larry Wang's black-hole proxy program:
//
// http://leisuresuit10.tripod.com/BlackHoleProxy/
//
// I can not vouch that his binaries are virus free, but he does
// offer the source code.
//
// - I use this shell script on UNIX; it is invoked via inetd.
// /usr/local/lib/noproxy:
//
// #!/bin/sh
// read a
// read b
// echo HTTP/1.0 501 No Ads Accepted
// echo ""
// exit
//
// Add this line to inetd.conf ('kill -HUP' inetd afterwards):
//
// 3421 stream tcp nowait nobody /usr/local/lib/noproxy noproxy
//
// This simple script doesn't work on Linux because of the
// (IMHO) broken way it's TCP stack works. See the bottom of
// http://www.schooner.com/~loverso/no-ads/ for a complete copy
// of the `noproxy' shell script.
//
// If always exec'ing a shell was expensive on your computer
// (it isn't on mine), then you could use a "wait"-style Perl
// script that would accept() incoming connections.
//
// - Sean Burke has a black-hole proxy written in Perl script:
//
// http://www.speech.cs.cmu.edu/~sburke...http_server.pl
// (This is a standalone server, not run from inetd).
So I'm guessing this to mean that it should be invoked in the variable defined by the no-ads.pac file, like so:
Code:
// ***
// *** Update the next line with the correct hostname: port
// *** of your blackhole proxy server, if needed.
// ***
// *** (If you use IE, this is already fine)
// ***
// var blackhole = "PROXY 127.0.0.1:3421"; // Original entry
var blackhole = "PROXY 127.0.0.1:3421/usr/local/bin/blackhole_proxy.pl";
But I'm only guessing here, and at this point I've determined that Opera just doesn't like no-ads.pac, period. However, it would be nice to know how to properly use that perl script, since the noproxy shell script written by John LoVerso doesn't work as well on Linux like it does on Unix.
So I'm still looking into the matter, and I've still got a long way to go in figuring out the Linux/Unix way of how things get done, but you did help me a lot, ToniT
PS: I had to edit the code sections in a couple of places, namely putting a space between any colon-letter combo, to get rid of any smiley faces
Last edited by thegeekster; 12-18-2003 at 05:22 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.