Re: [squid-users] adding a parameter to a URL / Problem in the url_redirect program

From: Henrik Nordstrom <henrik_at_henriknordstrom.net>
Date: Mon, 07 Jul 2008 09:14:01 +0200

On sön, 2008-07-06 at 22:05 -0700, Shaine wrote:

> Following is my script.
>
> #!/usr/bin/perl
> # no buffered output, auto flush
> use strict;
> use warnings;
>
> my ($temp, $array, @array, $param_1, $param_2, $param_3, $new_uri);
>
> $|=1;
> $temp = "";
>
>
> while (<STDIN>){
> #@array = split(/ /);
> ($param_1, $param_2, $param_3) = split(/ /);
> #if (!($array[1] =~ m#VALUE-X#)) {
> if (!($param_2 =~ m#VALUE-X#)) {
> $temp = $param_2;
> if ($param_2 =~ m#\?#) {
> $temp .= "&VALUE-X=652224848";
> }else {
> $temp .= "?VALUE-X=652224848";
> }
> $new_uri = ($param_1 . " " . $temp . " " . $param_3);
> s#$param_2#$temp#;
> #print $new_uri;
> print;
> }else {
> print;
> }
> }

If I understand the above correct you modify the second parameter sent
to the script which is the requesting client ip...

The URL is the first, and the only one used by Squid in responses.

Here is a simplified version of that script which should work better I
think (completely untested)

### BEGIN ###
#!/usr/bin/perl
use strict;
use warnings;

# no buffered output, auto flush
$|=1;
while (<STDIN>) {
  chomp;
  my ($url) = split(/ /);
  if (!($url =~ m#VALUE-X#)) {
    if ($url =~ m#\?#) {
       $url .= "&VALUE-X=652224848";
    } else {
       $url .= "?VALUE-X=652224848";
    }
    print $url."\n";
  } else {
    print "\n";
  }
}
### END ###

The chomp isn't stricly needed, but makes testing from command line
easier as it's sufficient to then enter just the URL for proper results
and not a complete url rewriter request.

Regards
Henrik

Received on Mon Jul 07 2008 - 07:14:07 MDT

This archive was generated by hypermail 2.2.0 : Mon Jul 07 2008 - 12:00:04 MDT