Jump to content

Recommended Posts

Posted
Saying that though I'm testing the pac file on IE/FF and it never doesn't return true to me :s

 

I can put the time to 1-2am and it still returns that proxy hmm, maybe that timerange one was removed? :s

 

Steve

 

Thanks for trying!

 

Looks like it should still be working in Firefox at least: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Necko/Proxy_Auto-Configuration_(PAC)_file (also found a similarly-dated bug report about timeRange(23, 1) nit working as expected (11pm to 1am) but it looks as if it shouldn't anyway!

Posted

OK - just in case anyone ever finds this on a search, I could not get the timeRange function to work at all. So, after reasoning that the pac file is basically Javascript and with the help of JavaScript Comparison and Logical Operators + JavaScript If...Else Statements and much trial and error (didn't know where to find sufficiently detailed error logs plus typo spotting) I've got a semi-working solution. Semi-working because the time accuracy seems +/- a minute or two and because if someone is already playing (say) a Flash game online it seems to be cached, so they can keep on playing until the browser is closed. (In fact, one site seemed to have cached a lot of content). Got to schedule a "stop IE + Chrome" task (or train the staff to get them all to log off at the end of the lesson - ha!), I guess...

 

Anyway, the following pac file will block access for a time period (and by url) with the above caveats and otherwise use a proxy, and seems to do the trick:

 

function FindProxyForURL(url, host)
{
//Declare Date variable
   var dTime = new Date();
//Declare and resolve Time variables
   var hours = dTime.getHours();
   var minutes = dTime.getMinutes();
//Set proxy to Direct over lunch
   if (hours == 12 && minutes > 10)
   return "DIRECT";
   if (hours == 13 && minutes < 08)
   return "DIRECT";
//Block access to all those nasty *.io Flash game sites that the firewall doesn't seem to spot
   if (shExpMatch(url, "*.io*"))
   return "DIRECT";
// Otherwise use proxy
   else 
   {return "PROXY ProxyAddress:Port";    }
}

 

Don't forget that the pac must be hosted at an available "without proxy" http address (so probably an internal web server).

 

Thanks again who contributed, particularly @simpsonj, @ih_aswc and @Steve21.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...