Програмиране на PAC файл

Задавайте Вашите въпроси, относно софтуера който вече имате инсталиран на компютъра си и имате проблеми с него или как сте разрешили даден проблем.
Публикувай отговор
RauL's FaN
_KICKBOXER_
Мнения: 929
Регистриран на: Сря Яну 28, 2004 21:45 pm
Местоположение: Stara Zagora
Обратна връзка:

Програмиране на PAC файл

Мнение от RauL's FaN »

Това не знам какъв програмен език се води, но ситуацията е такава, че си сложих приложение към браузъра(Chrome), на което се задават различни проксита и лесно могат да се менажират кое да бъде активно. Лошото е, че интерфейса позволява за различен адрес да се използва различно прокси, но на мен ми трябва само за определен адрес да се използват всички налични зададени проксита, и ако някое се окаже неактивно автоматично да се премине на следващото в списъка да кажем след 5 секунди. По-долу са функциите от PAC файла, който приложението генерира, а аз само ще разменя адресите с примерни. Не знам как да се натъкми и дали е възможно обяснението ми за сайта примерен google, да се използват последователно зададените проксита. В сегашния формат, браузъра зарежда само първото и каквото стане.

Код за потвърждение: Избери целия код

function regExpMatch(url, pattern) {
	try { return new RegExp(pattern).test(url); } catch(ex) { return false; }
}

function FindProxyForURL(url, host) {
	if (shExpMatch(url, '*google.com/*')) return 'PROXY 11.222.333.444:443';
	if (shExpMatch(url, '*google.com/*')) return 'PROXY 111.33.111.222:8888';
	if (shExpMatch(url, '*google.com/*')) return 'PROXY 111.95.222.33:80';
	if (shExpMatch(url, '*google.com/*')) return 'PROXY 199.111.99.199:3128';
	return 'DIRECT';
}
Рових се из интернет, но не мога да разбера за какво иде реч. Все пак ще постна това, което мисля че може да се приложи, на някой ако му хрумне нещо.

IsInNet(host..) Failing

A number of users have contacted me about issues with the isInNet function failing when the host being parsed is a domain name and not an IP address. Good sources have indicated that this occurs in Internet Explorer 8.0 and also the Microsoft .NET Framework 2.0 and likely has something to do with an IPv6 implementation. I have not yet been able to replicate this behavior, but I do have a solution – Resolve the IP address of the host first with dnsResolve and then do a match with isInNet to look for a subnet match. As mentioned above, be careful of doing this as it can cause more DNS queries and some odd behavior, but it can be used effectively in certain circumstances. Here’s an example of how this would normally be written in a PAC file:

Код за потвърждение: Избери целия код

if (isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
    isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0") ||
    isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0")) {
        return "DIRECT";
}
 
That forces DNS resolution of the host variable and then compares that IP address against the subnet you specify using isInNet. 
 
The “Fixed” way to do it would be to place the resolved host IP address in a variable, then reference that variable multiple times with isInNet. 
 
hostip=dnsResolve(host);
 
if (isInNet(hostip, "10.0.0.0", "255.0.0.0") ||
    isInNet(hostip, "172.16.0.0", "255.240.0.0") ||
    isInNet(hostip, "192.168.0.0", "255.255.0.0")) {
        return "DIRECT";
}
link: www.proxypacfiles.com/...

Put it all Together

Now that we have all the building blocks, we can create our PAC file. If we wish, we can also set it up so that, instead of using the IP address of the proxy, it points to a DNS entry. This is useful if you have backup proxies. In that case, if the main one goes offline you can change the DNS entry to the backup and the clients will be re-directed, without you having to alter the PAC file. We use this in our final completed example.

Код за потвърждение: Избери целия код

function FindProxyForURL(url, host)

{

  //Set a default proxy if non are returned below

  var proxy = "PROXY 192.168.0.244:8080";

 

  // Test for Prestons subnets

  if (isInNet(myIpAddress(), "192.168.1.0", "255.255.255.0"))

    proxy = "PROXY proxy_preston:8080";

  if (isInNet(myIpAddress(), "192.168.2.0", "255.255.255.0"))

    proxy = "PROXY proxy_preston:8080";

 

  // Test for Londons subnets

  if (isInNet(myIpAddress(), "192.168.3.0", "255.255.255.0"))

    proxy = "PROXY proxy_blackpool:8080";

  if (isInNet(myIpAddress(), "192.168.4.0", "255.255.255.0"))

    proxy = "PROXY proxy_blackpool:8080";

 

  //Now direct the user out through the proxy if not internal site

  if (isInNet(host, "192.168.0.0", "255.255.0.0"))

  {

    return "DIRECT";

  }

  else if (url.substring(0, 24) == "http://www.microsoft.com")

  {

    return "PROXY 159.180.13.52:3128";

  }

  else if (url.substring(0, 5) == "http:")

  {

    return proxy;

  }

  else if (url.substring(0, 4) == "ftp:")

  {

    return proxy;

  }

}

{mospagebreak title=Directing Users to your PAC File}

Now that you have your PAC file, you need to get your users to start using it. There are a couple of ways you can accomplish this, apart from the obvious one of getting them to do it themselves.

Please note that all the options discussed below are for use with Internet Explorer; they won’t affect FireFox, Opera, Safari etc. If you have any way of setting up these browsers send them to me and I’ll attach them as a comment to this article.
link: www.aspfree.com/...
Браузърът ми е Chrome :Alvarin:
Публикувай отговор