Blog
The Blog

KB N°2604: TESTING THE FUNCTIONALITY OF A PROXY.PAC FILE

Olfeo On-Premise knowledge base
June 2, 2023

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 can to check whether a proxy.pac file is functioning correctly.

Pacparser is a library that is used for analysing 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 analysis of PAC files (C and python are currently supported).

Steps

Step 1

  1. The first step is to install the tool via 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

  2. To install the pacparser C library and pactester in a Windows environment:

    Download and unzip the pacparser -vvv - win32.zip archive. This will create a pacparser-v.v.v directory.

  3. Copy all .DLL files and the pactester.exe to a location where the system will be able to find them (e.g. to a directory accessible by executable search paths such as C:\Windows) or simply add the pacparser directory to the (PATH) system path.

  4. In pacparser, link libpacparser.a and pacparser.lib respectively 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 the pacparser - Python25 -vvv - win32.zip packet. Using the command prompt (cmd), go to the pacparser - Python25 -vvv -win32 directory and run setup.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 parparser 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 fulfilled, pacparser will return the required proxy and will return the value DIRECT (no proxy).

This tool allows you to perform simple tests on a .PAC file and thereby avoid errors during deployment.