solar has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl monks,

I need some help on how to get this KRPS system working?

#!/usr/bin/perl ## This Perl CGI is a sample KRPS external CGI ### Copyright © 2004 Kagi. All rights reserved. # 1442A Walnut Street PMB #392, Berkeley, CA 94709, USA. ### Permission is granted to use this specification and code for developme +nt and # deployment of a Kagi Remote Post CGI free of charge as long as Kagi +sells # your products. ## No warranty is made as to the suitability of code herein # or even this code is bug or error free. ## BECAUSE THE CODE IS LICENSED FREE OF CHARGE, THERE IS NO # WARRANTY FOR THE CODE, TO THE EXTENT PERMITTED BY # APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING # THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDING THE # CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER # EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE. YOU ASSUME THE ENTIRE RISK AS TO THE # QUALITY AND PERFORMANCE OF THE CODE. SHOULD THE CODE # PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL-NECESSARY # SERVICING, REPAIR OR CORRECTION. package KagiRemoteCGIPostReceiver; use strict; use Exporter; use English; use CGI; use Digest::MD5; # end of line and return for CGI and KRPS my ($cr,$lf) = ("\015", "\012"); my ($crlf) = ("$cr$lf"); &main; 1; exit; sub main(){ # # CGI programs must print their own HTTP # response headers # printf ("Content-type: text/text%s%s",$crlf,$crlf); my $cgi = new CGI; #read cgi input parameters # does it start correctly? if( !defined($cgi) ){ printf( "kagiRemotePostStatus=BAD, message=Could not get CGI started.%s%s",$crlf,$crlf ); return(0); } # get the message and the digest for comparison my $sharedSecret = "myTestPassword", my $digest = md5Password($sharedSecret,$cgi); if( !defined($digest) ){ # status set in call, just return return(0); } # Specifically get the password from the input parameters my $passwd = $cgi->param('ACG:Password'); #does the password match what I think it should be if( $digest ne $passwd ){ printf( "kagiRemotePostStatus=BAD, message=Password did not match calculated version. %s%s”, $crlf,$crlf ); return(0); } # OK we passed the password test, now do something useful my ($userName,$regNumber) = myalgo($cgi->param('ACG:PurchaserEmail); printf( "kagiRemotePostStatus=GOOD, message=Authenticated call from Kagi.%s%s",$crlf,$crlf ); printf( “username=%s,regNumber=%s%s%s”. $username,$regNumber,$crlf,$crlf); return(1); } sub md5Password($$){ # Calculate the KRPS encrypted password message and return lower case +version # # The result of this routine should match what is passed by Kagi if th +e MD5 # encryption hash was specified during setup. # Reference Appendix C for details on the implementation # my($sharedSecrete, $cgi) = @ARG; # build the password as MD5 Hash my $md5 = Digest::MD5->new(); if( !defined($md5) ){ printf("kagiRemotePostStatus=BAD, message=MD5 could not be initialized. %s%s", $crlf,$crlf) } # lowercase the data to be consistent, no spaces # this is step 1 and step 2 in Appendix C $md5->add( lc( $ sharedSecrete . $cgi->param("ACG:TransactionID") . $cgi->param("ACG:ProductName") . $cgi->param("ACG:UnitPayment") . $cgi->param("ACG:DateProcessed") . $cgi->param("ACG:QuantityOrdered") . $cgi->param("ACG:LicenseType") ) ); #we lowercase the password, this is step 3 and step 4 in Appendix C my $newHash = lc( $md5->hexdigest ); # Perl adds spaces to output only, other libraries might add more my ($cleanHash,@stringArray,$character) = ("",undef,undef); # this is more of step 4 of Appendix C, Perl only, yours will vary. @stringArray = split(//,$newHash); # this is more of step 4 of Appendix C, Perl only, yours will vary. foreach $character (@stringArray){ # only accept hex characters if( $character =~ /[a-f0-9]/ ){ $cleanHash.= $character; } } return( $cleanHash); } 1;

Here is the HTML:

<HTML> <!-- --> <!-- --> <!-- Copyright © 2004 Kagi. All rights reserved. 1442A Walnut Street PMB #392, Berkeley, CA 94709, USA. Permission is granted to use this specification and code for developme +nt and deployment of a Kagi Remote Post CGI free of charge as long as Kagi se +lls your products. No warranty is made as to the suitability of code herein or even that the code is bug or error free. BECAUSE THE CODE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE CODE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU ASSUME THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE CODE. SHOULD THE CODE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL-NECESSARY SERVICING, REPAIR OR CORRECTION. --> <HEAD> <TITLE>KRPS Test Page</TITLE> </HEAD> <BODY> <P><FONT SIZE="+2" FACE="Arial">ACG test page</FONT></P> <!-- --> <!-- MODIFY THE ACTION BELOW --> <!-- FOR YOUR SERVER ADDRESS AND CGI-BIN DIRECTORY --> <!-- --> <!-- --> <P><!-***************************************************--> <!--* Modify the line below to point to the correct ACG or External CG +I to test *--> <!--*****************************************************--></P> <P><FORM ACTION="http://127.0.0.1/cgi-bin/ KagiRemoteCGIPostReceiver.p +l" METHOD=POST> <P><!--***************************************************--> <!--***************************************************-> <!-*****************************************************--> </P> <P><TABLE> <TR> <TD> <P></P> </TD> <TD> <P>The seed parameters are comma separated. Internal commas come escaped with a comma. The maximum length of the value for a given seed is 256 bytes</P> </TD> </TR> <TR> <TD> <P>ACG:Flags</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:Flags" VALUE="Test=1" SIZE=55><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:UserName</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:UserName" VALUE="enter value if needed" SIZE=55><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:Password</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:Password" VALUE="myTestPassword" SIZE=55><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:CustomerSeed</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:CustomerSeed" VALUE="Keyword: mykey - value, hardwareFingerprint=E96D-6CEE, userPreferredName=Softedge,, Inc." SIZE=255><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:OEMSeed</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:OEMSeed" VALUE="Clear-Text=Password" SIZE=256><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:DebugFlag</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:DebugFlag" VALUE="1" SIZE=30> Value 0 or 1 </P> </TD> </TR> <TR> <TD> <P>ACG:InputVersion</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:InputVersion" VALUE="0200" SIZE=30> Value 0200<BR> </P> </TD> </TR> <TR> <TD> <P>ACG:Request</P> </TD> <TD> <P><SELECT NAME="ACG:Request"> <OPTION VALUE=Generate>Generate <OPTION VALUE=Information>Information <OPTION>NULL </SELECT>Value is 'Generate' and 'Information'. See specification for meanings</P> </TD> </TR> <TR> <TD> <P>ACG:CardName</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:CardName" VALUE="Card Name Here" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:CardName-8bit</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:CardName-8bit" VALUE="CARD NAME HERE" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:PurchaserName</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:PurchaserName" VALUE="Fred Fragola" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:PurchaserName-8bit</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:PurchaserName-8bit" VALUE="Fred Fragola" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:PurchaserEmail</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:PurchaserEmail" VALUE="email@domain.com" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:SQNM</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:SQNM" VALUE="9999" SIZE=30>Value 0000 to 9999<BR> </P> </TD> </TR> <TR> <TD> <P>ACG:QuantityOrdered</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:QuantityOrdered" VALUE="1" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:LicenseType</P> </TD> <TD> <P><SELECT NAME="ACG:LicenseType"> <OPTION VALUE=single>single <OPTION VALUE=site>site <OPTION VALUE=world>world <OPTION VALUE=upgrade>upgrade <OPTION VALUE=bonus>bonus <!-- --> <!-- Edit the value below for you special license type--> <!-- --> <OPTION VALUE="special=">special=(you must edit form and supply value) <OPTION>null </SELECT>See specification for meanings</P> </TD> </TR> <TR> <TD> <P>ACG:UnitPayment</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:UnitPayment" VALUE="149.000" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:TransactionID</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:TransactionID" VALUE="CH0123456789" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:Postal-8bit</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:Postal-8bit" VALUE="POSTAL-8BIT 12134 Center St. Boston CA 87654" SIZE=60><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:Postal</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:Postal" VALUE="Postal 12134 Center St. Boston CA 87654" SIZE=60><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:ProductName-8bit</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:ProductName-8bit" VALUE="PRODUCT_NAME" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:ProductName</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:ProductName" VALUE="Product_Name" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:UserPurchaseDate</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:UserPurchaseDate" VALUE="2000-12-31" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:DateProcessed</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:DateProcessed" VALUE="2000-12-31" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>ACG:TimeStamp</P> </TD> <TD> <P><INPUT TYPE=text NAME="ACG:TimeStamp" VALUE="49388234823" SIZE=30><BR> </P> </TD> </TR> <TR> <TD> <P>Submit</P> </TD> <TD> <P><INPUT TYPE=submit NAME=Submit VALUE="Do your ACG test"><BR> </P> </TD> </TR></FORM> </TABLE> </FORM></P> </BODY> </HTML>

The Documentation on this program can be found here:

KRPS_Supplier_Spec.pdf

For some reason is not working on any of my servers, and i only know the basics of perl modules. So i cant even poke around.

Thanx

Edited by planetscape - added readmore tags and rudimentary formatting

( keep:0 edit:17 reap:1 )

Replies are listed 'Best First'.
Re: KRPS System
by grep (Monsignor) on Sep 23, 2006 at 21:43 UTC
    After fixing some (what I assume are copy and paste errors) I get some useful information from perl -c.

    Bareword found where operator expected at download.cgi line 69, near " +printf( "kagiRemotePostStatus" (Might be a runaway multi-line "" string starting on line 62) Global symbol "$sharedSecret" requires explicit package name at downlo +ad.cgi line 53. Global symbol "$userName" requires explicit package name at download.c +gi line 62. Global symbol "$regNumber" requires explicit package name at download. +cgi line 62. syntax error at download.cgi line 69, near "printf( "kagiRemotePostSta +tus" Global symbol "%s" requires explicit package name at download.cgi line + 70. Global symbol "$username" requires explicit package name at download.c +gi line 70. Global symbol "$regNumber" requires explicit package name at download. +cgi line 70. Global symbol "$sharedSecrete" requires explicit package name at downl +oad.cgi line 70. Global symbol "$md5" requires explicit package name at download.cgi li +ne 70. Global symbol "$md5" requires explicit package name at download.cgi li +ne 70. Global symbol "$md5" requires explicit package name at download.cgi li +ne 92. Global symbol "$sharedSecrete" requires explicit package name at downl +oad.cgi line 93. Global symbol "$md5" requires explicit package name at download.cgi li +ne 101. download.cgi had compilation errors.
    This code won't even compile, so there is no use in poking around modules - you need to fix the basic perl stuff.

    Once you do that:

    • Make sure the code passes perl -c script.cgi
    • Look to see what works and what doesn't
    • Check for error messages in the log file
    • If you can't find error messages in the log file. Run from the command line (there is plenty of info on that if you go to Search)
    • Then if you're still stuck - Try and narrow the problem down to a resonable number of lines
    • Then you can post relavant information here (errors, the lines of code, what it's supposed to do, and what it doesn't do)


    grep
    Mynd you, mønk bites Kan be pretti nasti...
Re: KRPS System
by Fletch (Bishop) on Sep 23, 2006 at 21:25 UTC

    Considering no one here has access to any of your servers, nor access to any error messages you're getting, nor any sort of idea about what exactly "not working" means in this case, I'd say you're up the proverbial creek without the poodle.

    See How (Not) To Ask A Question

Re: KRPS System
by Popcorn Dave (Abbot) on Sep 24, 2006 at 00:02 UTC
    Some things that you might look at:
    • Have you checked the permissions for the script on your server? Is it set to be executable?
    • Are you calling it using suid or some other method?
    • Can you check your error logs to see what's happening?
    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.
Re: KRPS System
by graff (Chancellor) on Sep 24, 2006 at 04:07 UTC
    You seem to have a bunch of comment lines near the top that do not start with "#". Make sure that these lines really do have "#" as the first non-space character:
    This Perl CGI is a sample KRPS external CGI Copyright © 2004 Kagi. All rights reserved. Permission is granted to use this specification and code for developme +nt and No warranty is made as to the suitability of code herein BECAUSE THE CODE IS LICENSED FREE OF CHARGE, THERE IS NO
    You also have something that looks like a double quote character but really is not the ASCII double-quote that perl is looking for to terminate a quoted string (at or near line 63, "Password did not match calculated version"). Then a missing single-quote and close paren at/near line 68, and more bogus double-quotes at line 71.

    These things are what brother grep was referring to as probable "copy and paste errors". I was able to spot them easily because I use a text editor that understands most of perl syntax, automatically indents lines according to block nesting or line continuation, and colorizes text according to whether it's comment, quoted-string, reserved word, etc. (I use emacs, but there are other editors that have these features, and it's worthwhile learning to use any one of them.)

    After you check those things and fix them where necessary, follow the other advice offered above, about checking whether the script compiles (with "perl -c"), whether the web server has permission to read and execute the perl script file, looking at the server error log if you can, etc.

    There's also a way to run the perl script at the command line, by supplying a cgi parameter string to @ARGV. The CGI manual page is rather long, but worth taking the time to read it -- or at least skim it for the parts that interest you at the moment. This might not be relevant unless you are able to run a command line shell on the web server.