I am a tcl user behind a corporate firewall. I'd like to develop an
app that communicates with a server outside of the firewall, and I'd
like to write this app in tcl. The only problem is that autoproxy
does not work because my company stores proxy info on a website. IE
knows the url and uses it just fine, but autoproxy seems unable to do
so. Is there anyway to grab the proxy info from that site and
configure the http package accordingly?
Sincerely,
Joshua Litt
If you are in the same case as I am, you're out of luck :-)
Indeed all the logic is written in Javascript to be executed by the
client (the browser)... In my case the workaround is to identify the
proxy to use for the "outside" which is (in my company) constant for a
given location of the client machine (my company is multi-site). Yes,
it's awfully inelegant, but taming a SpiderMonkey just for that was
contrary to my religion ;-)
-Alex
A general solution to this is to use IE or the XMLHttpRequest object
via its automation interface as these IE objects already know how to
read such proxy information. Using libcurl might be another solution.
In http://www.patthoyts.tk/programming/tclole05src.zip there is a
rough re-implementation of the http package using MSXML.XMLHTTP as the
transport to work with proxies on windows like this. It may be worth
examining (library/http.tcl and demo/*)
--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
I'm interested ! But how is libcurl supposed to handle the Javascript
encoding the logic ?
-Alex
Mine does too: http://proxy.company.com/proxy.pac
Have a look at the page. Mine has a FindProxyForURL function that
performs various tests to determine if the URL is internal. If yes, it
returns "DIRECT", otherwise it returns a string like
"PROXY proxy-abc1.company.com:8080"
Use that hostname and port for your proxy.
You might have to supply a username and password.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Glenn, my corporate firewall returns a similar .pac file with a
similar FindProxyForURL function. How can this function be called
from tcl?
Sincerely,
Joshua Litt
-Alex
I don't know -- is there a javascript interpreter written in Tcl?
However, fetching and parsing it is simple:
package require http
set get [http::geturl http://proxy.example.com/proxy.pac]
set contents [http::data $get]
http::cleanup $get
regexp {PROXY (\S+):(\d+)} $contents -> proxy_host proxy_port
Nope. That's why I mentioned taming Spidermonkey.
> However, fetching and parsing it is simple:
> regexp {PROXY (\S+):(\d+)} $contents -> proxy_host proxy_port
This doesn't work when non-trivial decisions are made by the
Javascript code. Which is my case.
-Alex
Sincerely,
Joshua Litt
I am not pat, but with that said, libcurl does not handle javascript.
But it may help you get through the proxies after you use tcl to
strip out the bits needed from the JS you downloaded with libcurl
is my guess.
Thanks,
marc
--
ms4...@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
Well, that would be orthogonal to the question. Tclcurl and the Tcl's
http package are equally capable in that respect. Only strong
performance requirements and/or specific bugs of the bundled package
may force you to depend on an extension.
-Alex
I've also wanted easy access to JavaScript from Tcl before (web-scraping
needs it more and more these days). Well, I didn't feel like hacking
around with SpiderMonkey (the install instructions seemed to start with
a dozen or so dependencies, like most Mozilla stuff...), so I instead
opted to quickly wrap the NJS JavaScript interpreter library
(http://www.njs-javascript.org/), which is lightweight and pretty
decent. I've put the result up at: http://www.cs.nott.ac.uk/~nem/tcl/ as
the "tcljs" package. Note: it's LGPL as that is the license NJS uses
(fine for me). Usage:
package require tcljs 1.0
tcljs js ;# create interpreter instance
js eval {
function foo(a, b) { return a * b; }
foo(12, 23)
}
Should make things pretty simple :-) Note though, that NJS does mention
that it is not an entirely standards-compliant interpreter, so possibly
might fail on some things. Should be fine for proxy .pac files, I'd
guess, though.
I was thinking about adding some more features to this, but then I
remembered that TkHTML also has a JavaScript library -- this time to the
SEE lib. See http://tkhtml.tcl.tk/hv3.html and the file hv3see.c for
details. So, it looks like we are now spoiled for choice of JS
interpreter bindings in Tcl... :-)
Cheers,
-- Neil
Turns out, as well as the JS interpreter, you also need to provide some
basic functions for a proxy.pac file (see
http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html).
I've updated the code (same URL as before) to allow registering Tcl
commands as global javascript methods, and then written a simple
proxypac.tcl script (in library/) that has the beginnings of making this
work (seems to work ok on the examples I have at hand).
Hope that is helpful.
Cheers,
Neil