PERL   24

nph opt out

Guest on 10th July 2022 07:59:17 PM

  1. #!/usr/bin/perl
  2.  
  3. use Time::Local;
  4.  
  5. $domain = ".realmedia.com";
  6. $optoutname = "RMOPTOUT";
  7.  
  8.  
  9.  
  10. $future_time = "Friday, 31-Dec-2032 23:59:59";
  11. $expire_time = "Tuesday, 2-Apr-2022 00:00:00";
  12. %itsNodeHash = 0;
  13.  
  14. sub Decode
  15. {
  16.         my ($words) = @_;
  17.         while ($words =~ /(\%[0-9A-F][0-9A-F])/)
  18.         {
  19.                 my ($decode) = &DecodeToken ($1);
  20.                 $words =~ s/$1/$decode/g;
  21.         }
  22.         $words =~ s/\+/ /g;
  23.         return $words;
  24. }
  25.  
  26. sub GetDataField
  27. {
  28.         my ($name) = @_;
  29.         my ($values) = $itsNodeHash{$name};
  30.         return pop (@$values);
  31. }
  32.  
  33. #
  34. # Main
  35. #
  36.  
  37. #create the headers
  38.  
  39.  
  40. my ($input);
  41. my ($node);
  42. if (! ($input = $ENV{"QUERY_STRING"}))
  43. {
  44.         $input = <STDIN>;
  45. }
  46. chomp ($input);
  47. foreach $node (split ('&', $input))
  48. {
  49.         my ($name, $value) = split ('=', $node);
  50.         my ($decodedName) = &Decode ($name);
  51.         my ($decodedValue) = &Decode ($value);
  52.         my ($values) = $itsNodeHash{$decodedName};
  53.         push (@$values, $decodedValue);
  54.         $itsNodeHash{$decodedName} = $values;
  55. }
  56.  
  57. #get the Domain
  58. $domainKey = "Domain";
  59. chomp ($tmpDomain = &GetDataField ($domainKey));
  60. if (length($tmpDomain) > 0) { $domain = $tmpDomain; }
  61.  
  62. # Get the action
  63. $actionKey = "Action";
  64. chomp ($actionVal = &GetDataField ($actionKey));
  65.  
  66.  
  67. print "HTTP/1.1 302 Moved Temporarily\n";
  68.  
  69. if (length($actionVal) == 0){
  70. #this is the first request, so remove them all, set the opt-out, and redirect
  71.         foreach $cookie (split ('; ', $ENV{'HTTP_COOKIE'}))
  72.         {
  73.                 my ($cook) = (split ('=', $cookie))[0];
  74.                 print "Set-Cookie: $cook=0; path=/; domain= $domain; expires=$expire_time\n";
  75.         }
  76.         print "Set-Cookie: RMOPTOUT=3; path=/; domain= $domain; expires=$future_time\n";
  77.  
  78. #set the compact privacy policy
  79.         print "P3P: policyref=\"http://www.247realmedia.com/w3c/p3p.xml\",CP=\"NOI DSP COR NID CUR OUR NOR\"\n";    
  80.         $setflag = 1;
  81.         print "Location: nph-opt_out.cgi?Action=check&Domain=$domain\n\r";
  82.  
  83.  
  84. }
  85. else {
  86. #this is the second request. If there is no opt out cookie, or if there are other cookies in the domain, redirect to failure, otherwise redirect to success.
  87.  
  88.         $fail = 0;
  89.         foreach $cookie (split ('; ', $ENV{'HTTP_COOKIE'}))
  90.         {
  91.                 my ($cookieName) = (split ('=', $cookie))[0];
  92.                 my ($cookieVal) = (split ('=', $cookie))[1];
  93.                 if ($cookieName ne $optoutname) { $fail = 1;}
  94.         }
  95.  
  96.         if ($fail > 0) { print "Location: http://www.networkadvertising.org/optout/opt_failure.gif\n\r"; }
  97.         else {print "Location: http://www.networkadvertising.org/optout/opt_success.gif\n\r"; }
  98.  
  99. }

Raw Paste


Login or Register to edit or fork this paste. It's free.