Saturday, November 14, 2015

Использование .pac файла для коммутации прокси-серверов

Полезная ссылка

chromium

You may enforce that all chromium browser instances on a machine use the autoconfig url. Place a file (e.g. proxyConfig) below /etc/chromium-browser/policies/managed/ with the following content

    "ProxyMode": "pac_script", 
    "ProxyPacUrl": "file:///myserver/myconfig.pac", 
}

Note: Placing this file below /etc/chromium-browser/policies/recommended will make this setting a default. The user is able to change this setting afterwards in his own chromium configuration.

firefox

Edit the file /etc/firefox/syspref.js and add the following lines 

lockPref("network.proxy.autoconfig_url", "http://myserver/myconfig.pac");
lockPref("network.proxy.type", 2);

Alternate way: Set this values as user preferences via about:config.

.pac file

function FindProxyForURL(url, host) {
if (shExpMatch(host, "*example*"))
{
return "PROXY 127.0.0.1:8889";
}

if (shExpMatch(host, "*example.com*"))
{
return "PROXY 10.10.10.10:3128";
}

if (isInNet(host, "10.10.0.0", "255.255.0.0"))
{
// return "DIRECT";
}

        if (isInNet(host, "127.0.0.0", "255.0.0.0"))
        {
                return "DIRECT";
        }

return "SOCKS5 127.0.0.1:8888";
}