wiki:Proxies

Version 9 (modified by speck, 11 years ago) (diff)

--

Proxies

GlimmerBlocker is itself an http proxy and it supports forwarding the requests to other proxies in addition to contacting the web-servers directly. For advanced users, it supports dynamic/URL-specific DNS server specifications.

Case 1: No proxy

This is by far the most comment case. GlimmerBlocker always contacts the web servers directly.

Case 2: Using a single proxy

This is the case when you e.g. have a work computer which you never bring home and the company requires use of a proxy. GlimmerBlocker will always use this proxy.

Case 3: Location-dependent proxy setup

Suppose you have a MacBook which you bring to work. At work it must use a company-wide proxy, but at home it must contact the servers directly. You can write a small Javascript (see examples below) which determines which proxy (if any) that should be used by examining the Network Location, AirPort network name and/or ip-adresses.

Case 4: URL-dependent proxy setup

This is the most advanced case. In addition to case 3, you can create rules for specific hosts, so accessing some hosts will use one proxy, other hosts will use another proxy, and the remaining some other proxy. Just like you can block ads using host/path/query criterias, you can specify a request-specific proxy.

How to configure

Select the "Network" tab in the GlimmerBlocker Preferences Pane. To never use a proxy (case 1), select "None". To always use the same proxy (case 2), select "Always use this proxy" and enter the name and port-number of the proxy. To use location-dependent proxy (case 3), select "Dynamic configuration".

URL-dependent proxies (case 4) are created as rules, and matching rules overrides any proxy which is setup in the "Network" tab.

The proxy Javascript

The dynamic configurations are created by writing a small Javascript which sets the proxy variable. Select "Dynamic configuration" and click the "edit" button.

The script specifies the proxy by assigning it to the gb.proxy variable. An empty string or null value means "use no proxy". The variable will be empty when the script is executed, so if the script doesn't assign any value to the variable, no proxy is used. It does not 'remember' the last assignment.

The Javascript runs globally and does therefore not have access to any request specific information. The only utility is the gb.log(...) method which logs to the GlimmerBlocker log. See the Transform page for documentation on its printf-style argument list.

The network settings variable

The second tab in the editing sheet shows the current configuration globals as a JSON dump. A shortened example:

gb.network = {
   location: {
      name: 'At work'
   },
   interfaces: {
      en0: {},
      en1: {
         link: true,
         AirPort: {
            power: 1,
            ssid: 'The Great Company',
         },
         IPv4: {
            addr: ['10.0.1.123'],
            mask: ['255.255.255.0'],
            broadcast: ['10.0.0.255']
         }
      }
   }
}

The "en0" interface is Ethernet and contains an empty {} object as it isn't connected. The "en1" interface is the AirPort card. The "link" attribute is present and true when the interface is connected, e.g. the Ethernet cable is plugged in or the AirPort? is connected to a network.

Simple "use proxy at work" script

Suppose you must use a proxy when having selected the "At work" location, but not when using "Automatic" or "At home". The simple script is:

if (gb.network.location.name == 'At work')
  gb.proxy = 'proxy.company.com:8008';

Beware: The above comparison is case-sensitive. Make sure you have the exact name and doesn't have extra spaces in the location name.

AirPort network dependent

When AirPort is online, the JSON can look like:

gb.network = {
   interfaces: {
      en1: {
         AirPort: {
            power: 1,
            ssid: 'The Great Company',
         },
         IPv4: { /* ... */ }
      }
   }
}

When it's offline, the JSON can look like:

gb.network = {
   interfaces: {
      en1: {
         AirPort: {
            power: 0
         },
         IPv4: { /* ... */ }
      }
   }
}

The script would be:

if (gb.network.interfaces.en1.AirPort.ssid == 'The Great Company')
  gb.proxy = 'proxy.company.com:8008';

If you have several AirPort cards installed, you might be advanced:

for (var k in gb.network.interfaces) {
   var x = gb.network.interfaces[k];
   if (!x.AirPort)
      continue;
   if (x.AirPort.ssid == 'The Great Company')
      gb.proxy = 'proxy.company.com:8008';
}

As most interfaces don't have an AirPort member, the code must check for its presence to avoid dereferencing a null.

Detecting IP adresses

Suppose you use Ethernet both at work and home, and doesn't use AirPort, but your IP-address differs.

for (var k in gb.network.interfaces) {
   var x = gb.network.interfaces[k];
   if (!x.IPv4)
      continue;
   if (x.IPv4.addr.length && x.IPv4.addr[0] == '10.0.1.123')
      gb.proxy = 'proxy.company.com:8008';
}

An interface can have multiple IP adresses, but the above code assumes it has just a single address.

URL-specific proxies

URL-specific proxies are specified by creating rules just like the transformation rules. The difference is that the 'modify request' scripts are executed before the request is sent to the server, while the transform scripts are executed after the request is sent to the server and the response is received.

Suppose you want to use a proxy to access your university, but not for all other sites. Assuming the domain name of the university is "ruc.dk", create a rule like:

The default value for the gb.proxy variable is the output from the global proxy script/settings (if any). So if you don't assign anything to gb.proxy, the global default is used. If you assign an empty string, the request will not use a proxy, even if a global proxy is configured.

So the rules have the ability to change which proxy is used for the request, but rules doesn't have to specify a proxy. You can e.g. have if (...) gb.proxy = '...'; conditionals inside the rule's script.

Attachments (7)

Download all attachments as: .zip