#!/usr/bin/perl

# redir
# given a single argument, either redirects to an alternative, if we have one,
# or redirect to that argument. Basically everything AFTER the ? on invocation
# is the argument (i.e. no  argument parsing ... if you want that, then you'll
# need to modify this or use a different script).
#
# The #!/usr/bin/perl is required to locate the perl interepreter on *nix
# systems. Similarly, this file can have ONLY newlines at the end of the line
# on many *nix systems. No DOS-like CR-LF, only LF. If not, then the script
# will fail to run.
#
# History:
# 03-Sep-2002   LeoN    Created
# 13-Aug-2003   LeoN    Cleaned up for publication
#
# Copyright (C) 2003, Puget Sound Software LLC
#

# table of redirections
# key is any token you'd like to use, and the value is the corresponding
# URL to invoke.
#
# Using the entry below as an example,
#
#   http://site/cgibin/redir.pl?pss
#
# would redirect to http://pugetsoundsoftware.com.
# Note that if the key is not found in the lookup table,
# then we'll attempt to redirect to the value of the key.
#
%mpOverrides = (
                "ms"      => "http://www.microsoft.com",
                "pss"     => "http://pugetsoundsoftware.com",
                );

# Check input - url required.
#
$urlTarget = "http://shop.adultshop.de/affiliateid/YCFMJNUGU0007/default.html";
if (!defined($urlTarget) || ("" eq $urlTarget))
    {
    _err ("Error in redirection: missing or malformed parameter");
    }
else
    {
    # if in our hit-list, then repace the destination
    #
    if (defined ($mpOverrides{$urlTarget}))
        {
        $urlTarget = $mpOverrides{$urlTarget};
        }

    # output immediate redirect to destination
    #
    print "Location: $urlTarget\n\n";
    }

sub _err
    {
    my $szErr = shift @_;

    print "Content-Type: text/html\n\n$szErr\n";
    }