Hi Kartik,

Here is what I have.  My employer has a proxy but no WPAD facility.
So the proxy does not return an IP address.  I think that's as much
as I can test, since it's unlikely that any proxy is going to serve
its wpad.dat file outward, only inward.

If you get any further info, positive or negative, please tell me.

This is based on http://en.wikipedia.org/wiki/ Web_Proxy_Autodiscovery_Protocol

Best Regards,
Craig

use Sys::Hostname;
use LWP::UserAgent;

my @pacs = ();

# do the WPAD discovery protocol
my $ua = LWP::UserAgent->new('timeout' => 30);
my ($netHostName, @netHostAddrs, $resp, @netWpadAddrs);
my $ofn = "wdat.pac";
my $hostname = hostname();  # in Sys::Hostname

# ask the proxy for the net name of our machine
($netHostName, undef, undef, undef, @netHostAddrs) = gethostbyname ($hostname);

# count the dots
my $dotCount = 0;
while ($netHostName =~ /\./g) {$dotCount++}

# successively replace the highest node name with 'wpad'
while ($dotCount-- >= 2
    && $netHostName =~ s/^[^.]+\./wpad./) {

  # do a DNS on the modified host name
(undef, undef, undef, undef, @netWpadAddrs) = gethostbyname ($netHostName);
  while (@netWpadAddrs) {

# the proxy answered with (an) IP address(es) -- try to read the wpad.dat file
    my $wpadIP = sprintf("%d.%d.%d.%d", unpack ('C4', $_));
$resp = $ua->get("http://$wpadIP/wpad.dat";, ':content_file' => $ofn);
    if ($resp->is_success) {
      push @pacs, $ofn;
      last;
  } }
  $netHostName = substr ($netHostName, 5);
}
# @pacs contains $ofn if we got a wdat.dat file


On Mar 2, 2010, at 1:43 PM, Kartik Thakore wrote:

Hi Craig,

How do I use the WPAD query to get the .pac file? It would be awsome to add this for Alien::SDL build.

Kartik Thakore

On 2010-03-02, at 3:13 PM, cr...@animalhead.com wrote:

Thank you, JE and your patch are the answer to my problem!

Someone ought to do something about the fact that JE doesn't come
up on a search.cpan.org search for "javascript" until page 12!

Might it be possible you could please put a version of
HTTP::ProxyPac that uses JE on CPAN?

Thanks much,
cmac


On Mar 2, 2010, at 10:31 AM, Kartik Thakore wrote:



Kartik Thakore

On 2010-03-01, at 10:47 PM, cr...@animalhead.com wrote:

Hi module authors,

I'm working on a module that has an accompanying script that can
be scheduled (cron'ed on Unix/Linux) to update its database from
the internet. The biggest problem with this, that is not covered by LWP,
is that of proxies.

I know how to access environment variables plus the CPAN config to
automatically take care of many systems that include a proxy.
Nevertheless if none of these contain anything, I feel that I have to include a query during Build.PL execution, to ask if there's a proxy. (Of course there will be a default "n" to take care of smoke- testing.)

If the query (which is only asked if the environment/CPAN variables
don't identify a proxy) comes back "y", I know how to run a WPAD
protocol, and if that doesn't yield anything, how to search on Windows
for *.pac.

Q1: where should one search for *.pac on non-Windows systems?

In internet settings for IE
But my main problem is when a wpad or pac search succeeds.  Now I
have a Javascript file that can tell my script what proxy should be
used for a URL that it wants to access. The only viable module that I've been able to find on CPAN to help with this is called HTTP::ProxyPAC.

I have fixed this with using JE and this patch for Http::ProxyPAC

http://paste.scsys.co.uk/40102


HTTP::ProxyPAC has JavaScript as a prerequisite.  The JavaScript
bindings expect that the user must have 'libjs' from Mozilla installed (by hand) before it will install. And if jslib is present, the JavaScript installer asks 3 scary questions about how it was installed, to which
only a true wizard would know the answers.

With JE no compile needed.
I would like to use ProxyPAC and JavaScript but don't want to subject my installers to such pain. I can put the .tar.gz of libjs from Mozilla inside my module, and drive the installation from Build.PL if it is needed. (Running a proxy.pac or wpad.dat file hardly needs the latest version!)

Q2: can libjs can be installed by Build.PL before the CPAN code
prepends HTTP::ProxyPAC and then JavaScript and tries to
install them (based on META.yml) before it ever runs my Build.PL?

Answers to these Qs, and any other comments or advice on the best
way to handle this matter, will be much appreciated.

Thanks,
cmac
www.animalhead.com



Reply via email to