0

A number of scripts on my system are relying on lynx which in turn can't pass through my proxy. More specifically, lynx successfully picks up the global proxy settings except the user id and password fields, suggesting to use -pauth on the command line instead:

lynx -pauth=proxyuserid:proxypass

Which I can't easily do because lynx is called indirectly. But then how should I do it, to apply these settings globally, for all lynx invocations? A configuration file -- couldn't find anything about proxy authorization. A bash shell wrapper under the same name lynx invoking the actual lynx with -pauth - somehow I can't make it work.

Update. I have environment variables fully describing proxy, e.g. http_proxy=http://userid:pass@proxyserver:port from which Lynx correctly reads off the proxy server and port correctly, but not the user/pass fields for some reason (unlike wget for example).

Therefore, I'm now using a lynx wrap script as follows:

envproxy=${http_proxy%@*}
/usr/bin/lynx -pauth=${envproxy:7} "$@"
  • Please add more details to your question. How are the scripts called and how is lynx called from the scripts? How is PATH set for the scripts that call lynx. Maybe wget or curl could be used instead of lynx. – Bodo Feb 20 at 11:57
  • The CHANGES files indicates "accept userinfo in a URL, subject to override by -auth option or -pauth options. According to RFC-3986, this is deprecated, but testing shows other clients support it -TD" -- have you tried the http :// user:pw@url syntax? – Jeff Schaller Feb 20 at 12:12
  • indeed, parse_authentication() appears to look for a colon to delimit a password. – Jeff Schaller Feb 20 at 12:14
1

Replacing lynx with a wrapper script will work if the scripts/programs call lynx without specifying the path, so the system will search it in the directories listed in variable PATH.

You have to find out where lynx is located, e.g. by typing type lynx.
I assume it might be /usr/bin/lynx.

The variable PATH for the scripts/programs that call lynx must have a different directory (e.g. /usr/local/bin) before the location of lynx (e.g. /usr/bin). If this is not the case you might have to extend PATH.

Example:

Assuming your PATH is set to

PATH=/usr/bin:/bin:/sbin:/usr/bin/X11

You could extend it with

PATH="/usr/local/bin:$PATH"

in one of the startup scripts that set PATH for the scripts/programs. How exactly you can do this depends on how these scripts/programs get called.

Then you could create a shell script /usr/local/bin/lynx like this:

#! /bin/sh

# Here you could do what is needed to get the user name and password for the
# proxy authentication and use these instead of hard coded values.

/usr/bin/lynx -pauth=proxyuserid:proxypass "$@"

When a script/program wants to execute lynx foo bar it will find your script /usr/local/bin/lynx before it would find the "real lynx" in /usr/bin/lynx.

The script will then call /usr/bin/lynx -pauth=proxyuserid:proxypass "foo" "bar".

Of course you can use a different location instead of /usr/local/bin.

This wrapper script solution will not work if the script/program executes lynx with specifying a path like /usr/bin/lynx foo bar. In such a case you could rename /usr/bin/lynx to e.g. /usr/bin/lynx.real and create a script /usr/bin/lynx that calls /usr/bin/lynx.real in the same way.

  • Thank you so much, your script works. Could you review one little modification that I've come up to? The script should ideally obtain the credentials from the environment variable (since lynx fails to do that by itself). This seems to work: envproxy=${http_proxy%@*} /usr/bin/lynx -pauth=${envproxy:7} "$@" – rych Feb 25 at 7:35
  • @rych Please add this to the question and show how variable http_proxy looks like. Instead of specifying an offset with ${envproxy:7} it might be better to specify a pattern with ${envproxy#pattern} – Bodo Feb 25 at 9:11
  • thank you @Bodo: I've updated the OP. I'm curious whether there is a one-liner extracting the credentials substring. And of course, why lynx can't read those fields off the environment variable by itself. – rych Feb 26 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.