views:

635

answers:

1

Is it possible to send custom HTML messages to users when they first start a session through a squid proxy server?

I want to be able to redirect a users first request to the "message of the Day".... then the rest of their browsing requests for the remainder of the session go without being redirected.....

Detailed Steps:

  1. User opens browser. (Browser is configured to use the Squid Proxy)
  2. User opens http://google.com (or other url of their choice)
  3. Instead of getting Google.com they are redirected to http://somewhere.else.com/MOD.html
  4. User reads the MOD
  5. User types http://google.com again (or other url of their choice) This time the browser goes to the correct destination with no redirection.

Would I have to develop or locate a Squid Proxy Server Plug-in to perform this kind of action or is this something the SQUID server can do with a little custom code?? (Perl etc)

+2  A: 

There's a line in the squid conf you can add like redirect_script. Write a perl program that takes input - one url per line. It outputs the url you are going to redirect the user to. The UpsideDownTernet script is an example.

Now change the script to output your MOTD the first time, and every other time just echo the URL back.

The problem is, how do you tell user requests apart? Well at this point you need to use a redirct_program line instead of redirect_script...

Squid will pass in serveral arguments to the program:

 URL ip-address/fqdn ident method

 URL    is the URL requested
 ip-address/fqdn    is the IP address or fully qualified domain name of the client   (web browser) which requested the page.
 ident  is the identity of the user running the web browser. Unless you configure   squid to do ident lookups, this will be "-".
 method is the request method: "GET", "POST", "HEAD"

Reference: http://taz.net.au/block/

At that point you can modify your script to determine the "timeout" each user gets between seeing the MOTD (e.g. if he doesn't visit a website for 12 hours, he gets the message) or whatever.

Tom Ritter
Can you craify what you mean by "you need to use a redirct_program line instead of redirect_script..."
Hortitude
Sure squid has two configuration options: redirect_script and redirect_program. Here's more info on redirect_program http://www.visolve.com/squid/squid24s1/externals.php I -thought- redirect_script was a "baby" version of redirect_program that took less arguments.Now that I've googled more it's possible that they are just aliases of each other; I'd have to check the source.
Tom Ritter