• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Proxy PAC File Javascript

keamas

New member
Hallo,
ich möchte gerade ein Proxy Pac File programmieren und habe dabei folgendes Problem:
Das Script sollte den richtigen Proxy wählen abhängig aus welchem Netz der Host kommt.
Allerdings gibt es in dem Script ein paar ausnahmen wie microsoft.com.
Allerdings scheint es als würde das Script diese Zeilen nicht auslesen. Laut meinem Testtol kommt er nie da an.
Kann mir bitte jemand helfen und sagen wo der Fehler hier ist oder habe ich einen Denkfehler drin oder funktioniert das was ich machen will ganz anders?

Code:
function FindProxyForURL(url, host)
{
    {
        /* The following is a load distribution and failover for the different locations. */
        /* EXAMPLE:
         if (isInNet(myIpAddress(), "10.1.0.0", "255.255.0.0"))
         {
         return "PROXY wcg1.example.com:8080; " + "PROXY wcg2.example.com:8080";
         } */

        //USA
        if (isInNet(myIpAddress(), "10.1.0.0", "255.255.255.0") ||		//Clients
            isInNet(myIpAddress(), "10.2.0.0", "255.255.255.0")) 	    //Servers

        {
            return "PROXY proxy-us.example.com:8080;"
        }

        //Europe
        if (isInNet(myIpAddress(), "10.20.0.0", "255.255.255.0") ||	//Clients
            isInNet(myIpAddress(), "10.21.0.0", "255.255.255.0") ||   //Servers
            isInNet(myIpAddress(), "10.22.0.0", "255.255.255.0") ||    //Developer
            isInNet(myIpAddress(), "10.23.0.0", "255.255.255.0")) 	//Client VPN
        {
            return "PROXY proxy_eu.example.com:8080;"
        }

        /* If no networks matches use the proxy servers. */
        else return "PROXY proxy.example.com:8080";





        /* Normalize the URL for pattern matching
         url = url.toLowerCase();
         host = host.toLowerCase();
         {
         /* Don't proxy local hostnames */


        /* If the requested website is hosted within the internal network, send direct.*/
        if (isPlainHostName(host)) {
            return 'DIRECT';
        }
        /* Don't proxy local domains */
        if (dnsDomainIs(host, ".example1.com") ||
            (host == "example1.com") ||
            dnsDomainIs(host, ".example2.com") ||
            (host == "example2.com") ||
            dnsDomainIs(host, ".example3.com") ||
            (host == "example3.com")) {
            return 'DIRECT';
        }
        /* Don't proxy Windows Update */
        if ((host == "download.microsoft.com") ||
            (host == "ntservicepack.microsoft.com") ||
            (host == "cdm.microsoft.com") ||
            (host == "wustat.windows.com") ||
            (host == "windowsupdate.microsoft.com") ||
            (dnsDomainIs(host, ".windowsupdate.microsoft.com")) ||
            (host == "update.microsoft.com") ||
            (dnsDomainIs(host, ".update.microsoft.com")) ||
            (dnsDomainIs(host, ".windowsupdate.com"))) {
            return 'DIRECT';
        }
        if (isResolvable(host)) {
            var hostIP = dnsResolve(host);
            /* 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 addresses.*/
            if (false) {
                return 'DIRECT';
            }
        }
        if (url.substring(0, 5) == 'http:' ||
            url.substring(0, 6) == 'https:' ||
            url.substring(0, 4) == 'ftp:') {
            return 'PROXY proxy.example.com:8080';
        }
        return 'DIRECT';


    }



}
 
Code:
function FindProxyForURL(url, host)
{
    { // <= warum
        ...
        //Europe
        if (isInNet(myIpAddress(), "10.20.0.0", "255.255.255.0") ||	//Clients
            isInNet(myIpAddress(), "10.21.0.0", "255.255.255.0") ||   //Servers
            isInNet(myIpAddress(), "10.22.0.0", "255.255.255.0") ||    //Developer
            isInNet(myIpAddress(), "10.23.0.0", "255.255.255.0")) 	//Client VPN
        {
            return "PROXY proxy_eu.example.com:8080;"
        }

        /* If no networks matches use the proxy servers. */
        else return "PROXY proxy.example.com:8080";
        
        // alles ab hier ist sinnlos
 
wird das in der fehlerkonsole angezeigt? mal davon ab, daß ich auch keine syntaxfehler sehe
Wenn es richtige Syntaxfehler sind, findet man diese auch in der Konsole (zumindest bei Firebug, wenn er korrekt eingestellt wurde).

Ich habe mal grob über den Code geschaut und einige fehlerhafte Klammerungen gefunden. Diese habe ich mal als Syntaxfehler abgestempelt...
 
In diesem Codeteil z.B.

Code:
...
/* Normalize the URL for pattern matching
         url = url.toLowerCase();
         host = host.toLowerCase();
         {  // -> Diese Klammer
....


Vielleicht bin ich aber auch nur blind und die Klammer ist dort richtig....
 
Vielleicht bin ich aber auch nur blind und die Klammer ist dort richtig....
Die Klammer ist unnötig, aber nicht falsch. Erzeugt einfach einen Block.

Da bei PAC ein paar Funktionen zur Verfügung stehen, die im normalen Browser-JS nicht definiert sind, kannst du die nicht so einfach im Browser aufrufen.
 
Zurück
Oben