Skip to content

Instantly share code, notes, and snippets.

@larytet
Last active March 29, 2018 12:55
Show Gist options
  • Save larytet/d5b3420b9c9a894bfeca86a1ee67e9a6 to your computer and use it in GitHub Desktop.
Save larytet/d5b3420b9c9a894bfeca86a1ee67e9a6 to your computer and use it in GitHub Desktop.
/* Global Pac File */
'use strict';
function getPort(url)
{
var port;
var base_str = url.split("/")[2];
var str_after_userpass = base_str.split("@")[1];
if (str_after_userpass) {
port = parseInt(str_after_userpass.split(":")[1]);
}
else {
port = parseInt(base_str.split(":")[1]);
}
if(isNaN(port)) {
return 80;
}
return port;
}
function ip2num(ip)
{
var d = ip.split('.');
return ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]);
}
function isInRange(ip, range_ip1, range_ip2)
{
var ip_num = ip2num(ip);
return (ip_num >= ip2num(range_ip1) && ip_num <= ip2num(range_ip2));
}
function FindProxyForURL(url, host) {
/* Normalize the URL for pattern matching */
url = url.toLowerCase();
host = host.toLowerCase();
if (shExpMatch(host, "*.websaas.rnd.qa")) {
if (url.substring(0, 5) === 'http:' || url.substring(0, 6) === 'https:' )
{
return 'DIRECT';
}
}
var hostIP = false;
if (isResolvable(host))
{
hostIP = dnsResolve(host);
}
/* start DIRECT section */
/* Don't proxy specific hostname */
if (
(host === "apple.com") || dnsDomainIs(host, ".apple.com") ||
(host === "get.adobe.com") || dnsDomainIs(host, ".get.adobe.com") ||
(host === "icloud.com") || dnsDomainIs(host, ".icloud.com") ||
(host === "slack.com") || dnsDomainIs(host, ".slack.com") ||
(host === "slack-core.com") || dnsDomainIs(host, ".slack-core.com") ||
(host === "slack-edge.com") || dnsDomainIs(host, ".slack-edge.com") ||
(host === "slack-imgs.com") || dnsDomainIs(host, ".slack-imgs.com") ||
(host === "slack-redir.net") || dnsDomainIs(host, ".slack-redir.net") ||
(host === "slack-msgs.com") || dnsDomainIs(host, ".slack-msgs.com") ||
(host === "crl.comodo.net") || dnsDomainIs(host, ".crl.comodo.net") ||
(host === "crl.comodoca.com") || dnsDomainIs(host, ".crl.comodoca.com") ||
(host === "ocsp.comodoca.com") || dnsDomainIs(host, ".ocsp.comodoca.com") ||
(host === "live.com") || dnsDomainIs(host, ".live.com") ||
(host === "microsoft.com") || dnsDomainIs(host, ".microsoft.com") ||
(host === "swebkiss.is-teledata.com") || dnsDomainIs(host, ".swebkiss.is-teledata.com") ||
(host === "webfinanceopen.teledata.de") || dnsDomainIs(host, ".webfinanceopen.teledata.de") ||
(host === "webex.com") || dnsDomainIs(host, ".webex.com") ||
(host === "windowsupdate.com") || dnsDomainIs(host, ".windowsupdate.com") ||
(host === "wustat.windows.com") || dnsDomainIs(host, ".wustat.windows.com") ||
(host === "auth.gfx.ms") || dnsDomainIs(host, ".auth.gfx.ms") ||
(host === "notify\.dropbox\.com") || dnsDomainIs(host, ".notify\.dropbox\.com") ||
(host === "geo.kaspersky.com") || dnsDomainIs(host, ".geo.kaspersky.com") ||
(host === "kavdumps.kaspersky.com") || dnsDomainIs(host, ".kavdumps.kaspersky.com") ||
(host === "crl.verisign.net") || dnsDomainIs(host, ".crl.verisign.net") ||
(host === "pluto-webapp-stress-us-static.s3.amazonaws.com") || dnsDomainIs(host, ".pluto-webapp-stress-us-static.s3.amazonaws.com") ||
(host === "cyrendev.s3.amazonaws.com") || dnsDomainIs(host, ".cyrendev.s3.amazonaws.com") ||
false)
{
return 'DIRECT';
}
/* Don't proxy specific wildcard host */
if (
shExpMatch(host,"client\-*\.dropbox\.com") ||
shExpMatch(host,"client\d*\.dropbox\.com") ||
false)
{
return 'DIRECT';
}
/* Don't proxy specific url */
if (
false)
{
return 'DIRECT';
}
if (hostIP) {
/* Don't proxy specific ip */
if (
false)
{
return 'DIRECT';
}
/* Don't proxy specific wildcard ip */
if (
false)
{
return 'DIRECT';
}
/* Don't proxy specific ip range */
if (
false)
{
return 'DIRECT';
}
}
/* end DIRECT section */
/* start local proxy section */
/* Don't proxy specific hostname */
if (
false)
{
return ' DIRECT';
}
/* Don't proxy specific wildcard host */
if (
false)
{
return ' DIRECT';
}
/* Don't proxy specific url */
if (
false)
{
return ' DIRECT';
}
if (hostIP) {
/* Don't proxy specific ip */
if (
false)
{
return ' DIRECT';
}
/* Don't proxy specific wildcard ip */
if (
false)
{
return ' DIRECT';
}
/* Don't proxy specific ip range */
if (
false)
{
return ' DIRECT';
}
/* end local proxy section */
/* Don't proxy non-routable addresses (RFC 3330) */
if (isInNet(hostIP, '0.0.0.0', '255.0.0.0') ||
isInNet(hostIP, '10.0.0.0', '255.0.0.0') ||
isInNet(hostIP, '127.0.0.0', '255.0.0.0') ||
isInNet(hostIP, '169.254.0.0', '255.255.0.0') ||
isInNet(hostIP, '172.16.0.0', '255.240.0.0') ||
isInNet(hostIP, '192.0.2.0', '255.255.255.0') ||
isInNet(hostIP, '192.88.99.0', '255.255.255.0') ||
isInNet(hostIP, '192.168.0.0', '255.255.0.0') ||
isInNet(hostIP, '198.18.0.0', '255.254.0.0') ||
isInNet(hostIP, '224.0.0.0', '240.0.0.0') ||
isInNet(hostIP, '240.0.0.0', '240.0.0.0'))
{
return 'DIRECT';
}
}
/* Don't proxy local hostnames */
if ( isPlainHostName(host) ||
shExpMatch(host, "*.local") )
{
return 'DIRECT';
}
/* Do not proxy ports we do not want to handle */
var port = getPort(url);
if(port !== 80 && port !== 443)
{
return 'DIRECT';
}
if (url.substring(0, 5) === 'http:' || url.substring(0, 6) === 'https:' )
{
return 'DIRECT';
}
return 'DIRECT';
}
/* Generated for 172.20.20.180 - geo false, using (192.168.31.17) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment