Virtual Hosting: PAC: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
(New page: <span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000"> {| | MPG UniCenter || Virtual Hosting: [[Virtual Hosting: Home | Ho...)
 
mNo edit summary
Line 64: Line 64:
|}
|}


*'''url''' <nowiki>----</nowiki>The full URL being accessed.
{|
*'''host''' <nowiki>----</nowiki>The hostname extracted from the URL. It is the string between '''://''' and the first ''':''' or '''/''' after that. ''Note'': The port number is not included. If required can be extracted from the URL.
|-
*'''ret''' <nowiki>----</nowiki>The return value a string describing the configuration.
|valign="top"|
*'''url'''
|
The full URL being accessed e.g.: '''<nowiki>http://wiki.uniformserver.com/index.php/Main_Page</nowiki>'''
|-
|valign="top"|
*'''host'''
|
The hostname extracted from the URL. It is the string between '''://''' and the first ''':''' or '''/''' after that e.g.<br><nowiki>http://</nowiki>'''wiki.uniformserver.com/index.php'''/Main_Page<br>
''Note 1'': The port number is not included. If required can be extracted from the URL.
|-
|valign="top"|
*'''ret'''
|The return value a string describing the configuration.
|}


'''Return Value:'''


'''Return Value:<br>'''The JavaScript function must return a single string if the string is null, no proxies shall be used. The string can contain any of the following blocks, separated by a semicolon:
The JavaScript function must return a single string if the string is null, no proxies shall be used. The string can contain any of the following blocks, separated by a semicolon:
{|cellpadding="6"
|-
|'''DIRECT'''||Connections should be made directly, without any proxies.
|-
|'''PROXY host;port'''||The specified proxy should be used. '''''It's this return value we are interested in'''''
|-
|'''SOCKS host;port'''||The specified SOCKS server should be used.
|}


'''DIRECT''' <nowiki>----</nowiki> Connections should be made directly, without any proxies.<br>
There are a number of predefined functions you can use we are interested in only two '''shExpMatch''' and '''dnsDomainIs'''.
'''PROXY host;port''' <nowiki>----</nowiki> The specified proxy should be used.<br>
'''SOCKS host;port''' <nowiki>----</nowiki> The specified SOCKS server should be used.


There are a number of predefined functions that can be used within the main function for example isInNet, dnsDomainIs and shExpMatch just to mention a few.
If these do not suit your needs you can easily find more information on the Internet this isworth a read [http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html Navigator Proxy Auto-Config File Format].
You can look these up on the Internet to find out what they do we are interest in only shExpMatch serves our requirement nicely.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Compare function ==
== Compare function ==
This function compares two strings I think the only special character it accepts is the wildcard character * (matches one or more characters) not a limitation probably makes it easier to use. The function has this format:
This function compares two strings I think the only special character it accepts is the wildcard character * (matches one or more characters) not a limitation probably makes it easier to use. The function has this format:
Line 84: Line 105:
'''shExpMatch(str, shexp)'''
'''shExpMatch(str, shexp)'''


{|
{| cellpadding="4" cellspacing="0"
|-
|-
|
|
'''str'''
:*'''str'''
|<nowiki>----</nowiki> any string to be compared for example the URL or the hostname.
|
any string to be compared for example the URL or the hostname.
|-
|-
|
|
'''shexp'''
:*'''shexp'''
|<nowiki>----</nowiki> the expression to compare against can use the wildcard character.
|
the expression to compare against can use the wildcard character.
|}
|}
The function returns true if the string matches the specified expression.
The function returns true if the string matches the specified expression.


Line 105: Line 129:
(shExpMatch('''url''', "*site1*");
(shExpMatch('''url''', "*site1*");


Any url passed to the above function containing the string site1 (anywhere) will produce true hence can be can be filtered out using an '''if''' statement.
Any url passed to the above function containing the string site1 ('''anywhere''') will produce true.


The result can be can be filtered using an '''if''' statement. If true do something else continue onto the next line of code.
{| cellpadding="4" cellspacing="1" style="background:#000000;"
{| cellpadding="4" cellspacing="1" style="background:#000000;"
|- style="background:#e8e8e8;"
|- style="background:#e8e8e8;"
Line 115: Line 140:
|}
|}


The url our browser is looking for can be found on the proxy server '''127.0.0.1''' (that's our local test server)
The comparison is true, the something to do is to return an IP address of a proxy server. The url our browser was looking for can be found on the proxy server '''127.0.0.1''' (that's our local test server) Its this return value that resolves the IP address hence the browser is happy and fetches the information.
Its this return value that resolves the IP address hence the browser is happy and fetches the information.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Complete PAC file ==
== Complete PAC file ==
Add this filter to the PAC function and we have our very own DNS resolver, with the ability to define any CNAME that we wish.
Add this filter to the PAC function and we have our very own DNS resolver, with the ability to define any CNAME that we wish.
Line 154: Line 179:
function FindProxyForURL(url, host)
function FindProxyForURL(url, host)
{
{
   if (shExpMatch(url,"*mine.nu*")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"*.mine.nu/*")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"*ric.com*")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"*.ric.com/*")) return "PROXY 127.0.0.1";
  return "";
}
</pre>
|}
 
=== Alternative function ===
If you do not like using wild cards you can use the function dnsDomainIs to directly target a domain name.
 
'''dnsDomainIs(host, domain)'''
 
{| cellpadding="4" cellspacing="0"
|-
|
:*host
|
is the hostname from the URL e.g http://'''wiki.uniformserver.com'''/index.php/Main_Page
|-
|
:*'''domain'''
|
is the domain name to test the hostname against e.g. '''.uniformserver.com'''
|}
 
Returns true if the domain of hostname matches.
 
{| cellpadding="4" cellspacing="1" style="background:#000000;"
|- style="background:#e8e8e8;"
!test1.pac File
|- style="background:#f5f5f5;"
|
<pre style="border:none">
function FindProxyForURL(url, host)
{
  if (dnsDomainIs(host,".mine.nu")) return "PROXY 127.0.0.1";
  if (dnsDomainIs(host,".ric.com")) return "PROXY 127.0.0.1";
   return "";
   return "";
}  
}  
Line 162: Line 222:


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Mimic Hosts file ==
== Mimic Hosts file ==
If you do not like using wild cards you can mimic the host file as follows:
You can mimic the host file as follows:


{| cellpadding="4" cellspacing="1" style="background:#000000;"
{| cellpadding="4" cellspacing="1" style="background:#000000;"
Line 173: Line 234:
function FindProxyForURL(url, host)
function FindProxyForURL(url, host)
{
{
   if (shExpMatch(url,"www.my_site1.fredtest.mine.nu")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"http://www.my_site1.fredtest.mine.nu/*")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"www.my_site2.fredtest.mine.nu")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"http://www.my_site2.fredtest.mine.nu/*")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"www.ric.com")) return "PROXY 127.0.0.1";
   if (shExpMatch(url,"http://www.ric.com/*")) return "PROXY 127.0.0.1";
   return "";
   return "";
}  
}  
Line 182: Line 243:


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Feedback from forum (27-6-07) ==
== Feedback from forum (27-6-07) ==
This was posted by '''figment88''' and provides another interesting way to use a PAC file; you can read the full post here [http://forum.uniformserver.com/index.php?showtopic=1216 Uniform Forum]. All I have done is a cut and past job.
This was posted by '''figment88''' and provides another interesting way to use a PAC file; you can read the full post here [http://forum.uniformserver.com/index.php?showtopic=1216 Uniform Forum]. All I have done is a cut and past job.

Navigation menu