
KB No. 2604: Testing the functionality of a proxy.pac file
How to check if a proxy.pac file is functioning correctly using a pactester.
Objective
Check if a proxy.pac file is functioning correctly using a pactester.
Context
proxy.pac files are used to specify the proxy address and port for client workstation browsers. To check whether a specified proxy.pac is functioning correctly, complete the following steps:
You can use the pacparser tool to check whether a proxy.pac file is functioning correctly.
Pacparser is a library that is used for analyzing the automatic configuration of a PAC file proxy. Proxy auto-configuration files are now widely used for the configuration of proxies. Web browsers can use a PAC file to determine the proxy server that is to be used, or whether direct access should be given to a given URL. PAC files are written in JavaScript and can be programmed to return different proxy methods (e.g., "PROXY proxy1: port; DIRECT") depending on the URL, source IP address, protocol, etc.
The use of PAC files introduces a number of possibilities. PAC files are now a commonly accepted method of managing proxies, with many companies using them in an enterprise environment. PAC files are supported by all of the major web browsers.
Because the proxy.pac mechanism is triggered from the browser and cannot be accessed externally, the only way to determine which proxy the browser will use for a specific URL is to manually check the proxy.pac file. However, manual checking can prove tedious and can result in errors proportional to the size of the file.
The idea behind the pacparser tool is to simplify the analysis of PAC files (C and Python are currently supported).
Steps
Step 1
-
The first step is to install the tool using the following command in the case of Linux operating systems:
$ sudo apt-get install libpacparser1 python-pacparser libpacparser-dev
For Windows and Mac OS X systems, go to the following address:https://code.google.com/p/pacparser/downloads/list
-
To install the pacparser C library and pactester in a Windows environment:
Download and unzip thepacparser-vvv-win32.ziparchive. This will create apacparser-v.v.vdirectory.
-
Copy all.DLLfiles andpactester.exeto a location where the system will be able to find them (e.g., to a directory accessible by executable search paths such asC:\Windows) or simply add the pacparser directory to the (PATH) system path.
-
In pacparser, linklibpacparser.aandpacparser.librespectively with the MinGW and Visual Studio compilation tools. To link pacparser to Visual Studio, complete the following steps:http://code.google.com/p/pacparser/wiki/LinkingOnVisualStudio
* Python Module
To install the pacparser Python module: download and unzip thepacparser – Python25 -vvv – win32.zippacket. Using the command prompt (cmd), go to thepacparser – Python25 -vvv -win32directory and runsetup.py install:
C:\temp > cd pacparser – Python25 – 1.0.5 -win32
C:\temp\pacparser – Python25 – 1.0.5 -win32 > setup.py install
If, for some reason, this command fails, simply copy the pacparser directory to the Python folder: C:\Python25\Lib\site-packages\pacparser.
Step 2
Once the pacparser tool is installed, you can test the proxy.pac configuration file using Python:
Note: If the proxy.pac file is hosted on Olfeo, you will need to copy it to the client machine on which pacparser is already installed.
>>> import pacparser
>>> pacparser.init()
>>> pacparser.parse_pac_file('examples/wpad.dat')
>>> pacparser.find_proxy('http://www.google.com', 'www.google.com')
‘PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT’
>>> pacparser.find_proxy(‘http://www2.manugarg.com’, ‘www2.manugarg.com’)
‘DIRECT’
>>> pacparser.cleanup()
>>>
It is also possible to test the .PAC file using C:
manugarg@hobbiton:~$ cat pactest.c
#include <stdio.h>
#include <pacparser.h>
int main(int argc, char* argv[])
{
char *proxy;
pacparser_init();
pacparser_parse_pac_file(argv[1]);
proxy = pacparser_find_proxy(argv[2], argv[3]);
printf(« %s\n », proxy);
pacparser_cleanup();
}
manugarg@hobbiton:~$ gcc -o pactest pactest.c -lpacparser
manugarg@hobbiton:~$ ./pactest wpad.dat http://www.google.com www.google.com
PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT
Validation
If these conditions are met, pacparser will return the required proxy and will return the valueDIRECT(no proxy).
This tool allows you to perform simple tests on a .PAC file and thereby avoid errors during deployment.