HowTo: Test a Proxy PAC File Syntax With Syntax Checker

How can I test a Proxy PAC file syntax under Apple OS X / Linux / *BSD or Unix like operating systems using command line options?

You can use a tool called pactester written in Perl. This tool test Proxy Auto Configuration (PAC) files. From the project home page:
Tutorial details
Difficulty level Intermediate
Root privileges Yes/No
Requirements Perl
Est. reading time N/A

PAC files are used by browsers to determine the ‘right’ proxy for a URL. Since the PAC file evaluation mechanism is generated inside the browser and cannot be accessed from outside, the only way to tell which proxy your browser will use for a specific URL is manual inspection of the PAC file. But manual inspection doesn’t really scale very well. Pactester resolves this problem. It makes use of JavaScript interpreter and Netscape/Mozilla APIs to evaluate the PAC files and automates the whole process. Pactester reads a PAC file, evaluates it in a JavaScript context and uses this PAC file’s logic to determine the proxy for a specific URL.

Installation

Debian and Ubuntu Linux user type the following command to install this tool:
$ sudo apt-get install libpacparser1
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libpacparser1
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 395 kB of archives.
After this operation, 1,339 kB of additional disk space will be used.
Get:1 http://debian.osuosl.org/debian/ squeeze/main libpacparser1 amd64 1.2.6-2 [395 kB]
Fetched 395 kB in 2s (153 kB/s)                       
Selecting previously deselected package libpacparser1.
(Reading database ... 281091 files and directories currently installed.)
Unpacking libpacparser1 (from .../libpacparser1_1.2.6-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libpacparser1 (1.2.6-2) ...

A note about source code installation

Type the following wget command to download the source code:
$ cd /tmp/
$ wget http://pactester.googlecode.com/files/pactester-1.0.8.tar.gz

Sample outputs:

--2012-11-20 21:34:17--  http://pactester.googlecode.com/files/pactester-1.0.8.tar.gz
Resolving pactester.googlecode.com... 74.125.128.82, 2404:6800:4005:c00::52
Connecting to pactester.googlecode.com|74.125.128.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1214308 (1.2M) [application/x-gzip]
Saving to: `pactester-1.0.8.tar.gz'
 
100%[=============================>] 12,14,308    352K/s   in 3.4s    
 
2012-11-20 21:34:21 (352 KB/s) - `pactester-1.0.8.tar.gz' saved [1214308/1214308]

Untar the tarball with tar command:
$ tar xvf pactester-1.0.8.tar.gz
Sample outputs:

pactester-1.0.8/
pactester-1.0.8/README
pactester-1.0.8/build/
pactester-1.0.8/build/Log-Log4perl-1.08.tar.gz
pactester-1.0.8/build/install.sh
pactester-1.0.8/build/js-1.5.tar.gz
pactester-1.0.8/build/JavaScript-SpiderMonkey-0.17.tar.gz
pactester-1.0.8/pactester
pactester-1.0.8/INSTALL
pactester-1.0.8/COPYING
pactester-1.0.8/pac_utils.js

Install pactester in ~/pactester directory, enter:
$ mkdir $HOME/pactester
$ cd pactester-1.0.8/build/
$ ./install.sh $HOME/pactester

Sample outputs:

....
.
<snip>
...
Installing /home/vivek/pactester/lib/perl/5.10.1/auto/JavaScript/SpiderMonkey/SpiderMonkey.so
Installing /home/vivek/pactester/lib/perl/5.10.1/JavaScript/SpiderMonkey.pm
Installing /home/vivek/pactester/man/man3/JavaScript::SpiderMonkey.3pm
Appending installation info to /home/vivek/pactester/lib/perl/5.10.1/perllocal.pod
-e 
 
 
-e ###########################################
>>PERLLIB=-e /home/vivek/pactester/share/perl/5.10.1:/home/vivek/pactester/lib/perl/5.10.1
-e I have set up PERLLIB path in pactester script, so you won't have to
-e set it as an environment variable :)

How do I use pactester command to test proxy auto-config (pac) files?

The syntax is:

pactester -p /path/to/proxy.pac.file -u url
pactester -p /path/to/proxy.pac.file -u url -c client.ip.address.here

Sample proxy.pac file:

function FindProxyForURL(url, host) {
    // Your proxy server name and port
    var proxyserver = 'squidproxy1.cyberciti.biz.home.net.in:3128';
    //
    //  Here's a list of hosts to connect via the PROXY server
    //
    var proxylist = new Array(
        "reddit.com",
        "www.cyberciti.biz",
        "mail.google.com",
        "www.pandora.com",
        "www.google.com",
	"www.hulu.com",
	"mail.cyberciti.biz",
	"mail.nixcraft.com",
	"slashdot.org"
    );
    // Return our proxy name for matched domains/hosts
    for(var i=0; i<proxylist.length; i++) {
        var value = proxylist[i];
        if ( localHostOrDomainIs(host, value) ) {
            return "PROXY "+proxyserver;
        }
    }
    return "DIRECT";
}

To find out proxy string as returned by pac file proxy.pac for the URL http://www.cyberciti.biz:
$ pactester -p proxy.pac -u http://www.cyberciti.biz
Sample outputs:

PROXY squidproxy1.cyberciti.biz.home.net.in:3128

To find out proxy string as returned by pac file proxy.pac for the URL http://www.google.com:
$ pactester -p proxy.pac -u http://www.google.com
Sample outputs:

DIRECT

Test setting for a client with IP address 192.168.1.5:
$ pactester -p wpad.dat -c 192.168.1.5 -u http://www.google.com
Create a list of urls/hosts in /tmp/proxy.url.test file:

http://www.cyberciti.biz
http://nixcraft.com
https://mail.google.com
https://www.google.com
http://nas03
http://router1
http://www.pandora.com

Now, find out proxy settings for a list of urls specified in /tmp/proxy.url.test file
$ pactester -p /var/www/html/proxy.pac -f /tmp/proxy.url.test
Sample outputs:

http://www.cyberciti.biz : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
http://nixcraft.com : DIRECT
https://mail.google.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
https://www.google.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
http://nas03 : DIRECT
http://router1 : DIRECT
http://www.pandora.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • I Pay Attention Dec 22, 2014 @ 14:58

    From the project home page:

    Important: I have stopped maintaining this version of pactester. Please use the version that comes with ‘pacparser’. -Manu Garg

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum