#!/usr/bin/perl # # IPN Perl Script # # This sample script will read iKobo IPN message, parse it and save it into /tmp/ipn.txt # /tmp/ directory is available and allows writing on most Unix systems # printf "Content-type: text/plain\n\n"; #read(STDIN,$buffer,$ENV{CONTENT_LENGTH}); $buffer = $ENV{'QUERY_STRING'}; @in = split(/&/,$buffer); open F, ">/tmp/ipn.txt"; printf( F "buffer=%s\n", buffer ); foreach $i (0 .. $#in) { # Convert plus's to spaces $in[$i] =~ s/\+/ /g; # Split into key and value. ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. # Convert %XX from hex numbers to alphanumeric $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; # Associate key and value $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; printf( F "%s=%s\n", $key, $val ); if ( lc($key) eq "option_list" ) # parse option list { @options = split(/,/,$val); foreach $j (0 .. $#options) { # printf( F "parsing option_list for item $j: %s\n", $options[$j] ); @item_options = split( /:/, $options[$j] ); foreach $k (0 .. $#item_options) { # Split into key and value. ($opt_group, $opt_name, $opt_price) = split( /[=+]/, $item_options[$k] ); print( F "item $j, option group=$opt_group, name=$opt_name, price=$opt_price\n" ); } } } } close F; print( "RESP=OK\r\n" );