Guys i'm new to javascript but have pulled together a PAC file based on requirements.
Problem is i'm not sure how javascript handles variables. I'm proficient with shell script, and a bit of perl.
I can't find any examples on the net of what i'm trying to do.
I want to return proxies which are set in variables depending on different conditions.
e.g
function FindProxyForURL(url,host)
{
// set chp1 and chp1 to the 2 xxxx proxies VIPS
// xxxx VIP
var chpv1="aa.bb.cc.dd:8080";
var chpv2="aa.bb.cc.dd:8080";
// Also set the real proxy P1 interfaces just in case
var chrp1="aa.bb.cc.dd:8080";
var chrp2="aa.bb.cc.dd:8080";
var shrp1="aa.bb.cc.dd:8080";
// Declare variables we use later
var proxyone;
var proxytwo;
var proxythree;
var proxyfour;
// Get client ip and store in var
var myip=myIpAddress();
// If client is unable to communicate with proxies, indicating out of office location,
// still allow connection to *.gov.uk sites by adding a fourth proxy as direct.
//
// This does have the effect that if all proxies are unavailable client will attempt
// direct connection. This will be denied by FW policy when in office and only
// allow connection to *.gov.uk sites if not.
// Not ideal due to PAC file timeouts, plus relies on office security to deny direct internet.
//
// Not done *.gov.uk* incase of *.gov.uk.scamdomain.com instances
if (shExpMatch(url, "*.gov.uk"))
{
var proxyfour="DIRECT";
}
// If ip is xxxxx range use proxy xxxxx first
// *** Correct IP range needed. Demo only ***
if ( (isInNet(myip, "10.10.10.0", "255.255.255.0")) || (isInNet(myip, "10.10.5.0", "255.255.255.0")) )
{
var proxyone=shrp1; // P1 Interface of xxxxx
var proxytwo=chpv1;
var proxythree=chpv2;
// Return proxy order to stop processing
// If 4th proxy defined (indicating *.gov.uk sites)
if ( proxyfour != null ) {
return "PROXY proxyone; PROXY proxytwo; PROXY proxythree; PROXY proxyfour";
} else {
// Not allowing direct attempt for any site
return "PROXY proxyone; PROXY proxytwo; PROXY proxythree";
}
}
// Now use main proxies based on odd/even
// find the 4th octet -
var ipbits=myip.split(".");
var myseg=parseInt(ipbits[3]);
// If even use proxy1 first
if(myseg==Math.floor(myseg/2)*2) {
var proxyone=chpv1;
var proxytwo=chpv2;
var proxythree=shrp1;
}
else {
// Must be odd use proxy2 first
var proxyone=chpv2;
var proxytwo=chpv1;
var proxythree=shrp1;
}
// Return proxy order
// If 4th proxy defined
if ( proxyfour == null ) {
return "PROXY proxyone; PROXY proxytwo; PROXY proxythree; PROXY proxyfour";
} else {
// Not allowing direct attempt for any site
return "PROXY proxyone; PROXY proxytwo; PROXY proxythree";
}
} // End of FindProxyURL function.
// End
Problem is when testing using pacparser i'm just getting back a string "PROXY proxyone; PROXY proxytwo; PROXY proxythree" instead of it resolving the variables and replacing with the correct order aa.bb.cc.dd:8080.
I basically want to set a proxy order based on conditions and then just return it at the end.
Anyone any ideas?
---------- Post updated at 03:13 PM ---------- Previous update was at 12:09 PM ----------
I've fixed this with :-
// Return proxy order
// If 4th proxy defined
if ( proxyfour != null ) {
//Need to expose vars outside quotes
return "PROXY "+proxyone+"\; PROXY "+proxytwo+"\; PROXY "+proxythree+"\; PROXY "+proxyfour;
} else {
// Not allowing direct attempt for any site
//return "PROXY proxyone; PROXY proxytwo; PROXY proxythree";
//Need to expose vars outside quotes
return "PROXY "+proxyone+"\; PROXY "+proxytwo+"\; PROXY "+proxythree;
}
But there may be a better way to do it?? I'm still not sure if need to return the string PROXY or not as i've seen it with and without in some pac examples.
Arr well.
as separators and the values are hex strings.