+ Post New Thread
Results 1 to 4 of 4
Coding Thread, .pac files in Coding and Web Development; Hi all! our internet is filtered externally and we are given a list of proxies to use such as... proxy.server.com:6671 ...
  1. #1

    Join Date
    Nov 2008
    Location
    Fareham
    Posts
    18
    Thank Post
    11
    Thanked 3 Times in 3 Posts
    Rep Power
    12

    Question .pac files

    Hi all!

    our internet is filtered externally and we are given a list of proxies to use such as...

    proxy.server.com:6671 - for educational sites (basicaly blocks myspace, youtube)
    proxy.server.com:6672 - for most web sites (blocks google images and inappropriate content)
    proxy.server.com:6673 - very strict filtering for images but let you on to google images and yahoo images mainly
    proxy.server.com:6674 - library filter (lets you on wiki and thats about it)

    and i've been doing some experimenting with .pac files and trying to get different web sites to use different proxies but so far i've been unsuccessful.

    Just wondering if anyone has tried something like this before or has any advice?

    heres the .pac file i've been using


    Code:
    function FindProxyForURL(url, host)
     {
     if (isPlainHostName(url, host))
     return "DIRECT";
     else if (shExpMatch(url, "*.facebook.com/*")) return "PROXY proxy.server.com:6672";
     else if (shExpMatch(url, "*.myspace.com/*")) return "PROXY proxy.server.com:6672";
     else if (shExpMatch(url, "*.google.co.uk/*")) return "PROXY proxy.server.com:6673";
     else if (shExpMatch(url, "*.google.com/*")) return "PROXY proxy.server.com:6673";
     else
    
     return "PROXY proxy.server.com:6671";
     }
    With this pac code whatever the first site/proxy is it will use that one.

    Thanks in advance!
    Jamie

  2. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Ok, first test for the most specific thing, so test for your urls first, then your generic 'direct' test, then an else.

    Also do your shExpMatch on host, not url, so that you need less wildcards. I think that's why it is returning too soon, try shExpMatch(host, '*facebook.com').

    (if this doesn't make much sense, that's because it's tomorrow already...)

  3. #3


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,458
    Thank Post
    866
    Thanked 845 Times in 667 Posts
    Rep Power
    195
    OK... first you don't need any elseifs - i hate em anyway, messy construct. "return" is going to halt execution on match. We're going to explicitly brace our statements as well, for the sake of readablity. Finally, we'll check against host, not url where host is all we need.

    soo...

    var proxy1 = proxy.server.com:6672;
    var proxy2 = proxy.server.com:6673;

    var defaultproxy = proxy2;

    function FindProxyForURL(url, host)
    {
    if (isPlainHostName(url, host))
    {
    return "DIRECT";
    }
    if (shExpMatch(host,"*facebook.com"))
    {
    return proxy1;
    }
    if (shExpMatch(host,"*google*))
    {
    return proxy2;
    }
    return defaultproxy;
    }

    If that works (problem may lie with 2 ports on one proxy... should work tho) would move on to perhaps use regex matching rather than shexp, so you can match (facebook|fbcdn|..)

    This does seem a dangerous way to work, though, given that lots of sites have more than one domain.

  4. #4

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,665
    Thank Post
    1,614
    Thanked 1,866 Times in 1,384 Posts
    Blog Entries
    2
    Rep Power
    400
    whilst lots of sites have many domains, if you put the variables infront and behind the main bulk of the web address EG *facebook* then anything with facebook in the address will get blocked....

SHARE:
+ Post New Thread

Similar Threads

  1. Docx files opening at zip files
    By tomscaper in forum Office Software
    Replies: 20
    Last Post: 18th September 2008, 10:37 AM
  2. [Video] Pac Man the Movie
    By Dos_Box in forum Jokes/Interweb Things
    Replies: 0
    Last Post: 9th September 2008, 02:31 PM
  3. Replies: 2
    Last Post: 29th April 2008, 03:17 PM
  4. 2 pac and 50 cent!!
    By bishopsgarthstockton in forum General Chat
    Replies: 20
    Last Post: 16th July 2007, 11:32 PM
  5. Creating a PAC file
    By u8dmtm in forum Coding
    Replies: 4
    Last Post: 2nd March 2006, 03:49 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •