home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / guestbk.zip / guestbook.cmd < prev    next >
OS/2 REXX Batch file  |  1996-01-22  |  4KB  |  120 lines

  1. /***************************************************************************
  2.  *
  3.  *  Guestbook.cmd - a REXX script to generate a guest book file
  4.  *
  5.  *  Adapted from TEST-CGI.CMD - a REXX script to test CGI interface
  6.  *
  7.  *  Originally by:  Frankie Fan <kfan@netcom.com>  7/11/94
  8.  *
  9.  *  Dennis Peterson (dpeterso@halcyon.com) 1-15-96
  10.  *
  11.  *  An unfinished work... There is no serialization yet.
  12.  *
  13.  **************************************************************************/
  14. /*
  15. unpackur: procedure
  16. parse arg text
  17. unsafe=xrange('00'x,'1F'x)'$-_@.&!*"''(),=;/#?: '
  18. out = ''
  19. do i = 1 to length(text)
  20.   c = substr(text,i,1)
  21.   if pos(c,unsafe)\=0 then
  22.     out = out'%'c2x(c)
  23.   else
  24.     out = out''c
  25. end
  26. return out
  27. */
  28.  
  29. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  30. Call SysLoadFuncs
  31.  
  32. Parse Arg Argv
  33.  
  34. env = "OS2ENVIRONMENT"
  35. Argc = Words(Argv)
  36.  
  37. header = '<BODY BACKGROUND="/webart/bk_saffron.gif"'
  38. header = header || ' BGCOLOR="#7F7F7F"'
  39. header = header || ' TEXT="#A00000"'
  40. header = header || ' LINK="#007F00"'
  41. header = header || ' VLINK="#00A000">'
  42. header = header || '<H2>Your comments will be added to our guest book!</H2><HR>'
  43.  
  44. trailer = '<A HREF="/"><IMG SRC="/webart/back.gif" alt="">Return to the OS/2 Northwest BBS</A><HR>'
  45.  
  46. Say "Content-type: text/html"
  47. Say
  48.  
  49. /*
  50.   len = value("CONTENT_LENGTH",,env)
  51.   post_string = charin(,,len) /* read only the number specified 
  52.                                  in CONTENT_LENGTH */
  53.   query_string = post_string
  54.   NF = ParseQueryString(query_string)
  55. */
  56.  
  57. NF = ParseQueryString(charin(,,value("CONTENT_LENGTH",,env)))
  58.  
  59. message = '<B>Name:</B> ' || Parms.XVal.1 '<BR>'
  60. message = message || '<B>Email:</B> ' || '<A HREF=mailto:'Parms.XVal.2 || '>'Parms.XVal.2'</A><BR>'
  61. message = message || '<B>Date:</B> ' || date('w') || ', ' || date('l') || ' -- ' || Time('c') || '<BR>'
  62. message = message || '<B>Homepage:</B>  <A HREF='translate(Parms.XVal.3,'/','\') || '>' || Parms.XVal.4 || '</A><BR>'
  63. message = message || '<B>Referred from:</B> ' || Parms.XVal.5 || '<BR>'
  64. message = message || '<B>Comments:</B> '
  65.  
  66. /* Preserve original line breaks from message by adding <BR> to each line */
  67. /* This is a hack until I find a cleaner way */
  68.  
  69. tempfile = SysTempFileName('d:\gopher\cgi-bin\guestbook.???')
  70. rc = lineout(tempfile, Parms.XVal.6)
  71. rc = lineout(tempfile)
  72.  
  73. Do while lines(tempfile) > 0
  74.    message = message || linein(tempfile) || '<BR>'
  75. end
  76. message = message || '<HR>'
  77.  
  78.  
  79. say  header || message  || '0d0a'x || trailer
  80.  
  81. rc = lineout(tempfile)
  82. rc = SysFileDelete(tempfile)
  83. rc = lineout("d:\gopher\cgi-bin\comments.txt", message)
  84. rc = lineout("d:\gopher\cgi-bin\comments.txt")
  85. call getcomments
  86. return
  87.  
  88.     /* Do not modify below this line --  Important parsing code... */
  89. ParseQueryString: procedure expose Parms. NFields
  90.   Parse arg P
  91.   i = 1
  92.   do while ((P \= '') & (i < 10))
  93.      Parse var P Parms.Text.i '&' rest
  94.      Parse var Parms.Text.i Parms.Tag.i '=' Parms.KeyVal.i
  95.      Parms.Tag.i = translate( Parms.Tag.i)
  96.      Parms.XVal.i=DecodeKeyVal( Parms.KeyVal.i)
  97.      P = rest
  98.      i = i + 1
  99.   end
  100.   NFields = i - 1
  101.   return NFields
  102.  
  103. DecodeKeyVal: procedure
  104.   parse arg Code
  105.   Text=''
  106.   Code=translate(Code, ' ', '+')
  107.   rest='%'
  108.   do while (rest\='')
  109.      Parse var Code T '%' rest
  110.      Text=Text || T
  111.      if (rest\='') then
  112.       do
  113.         ch = left( rest,2)
  114.         c=X2C(ch)
  115.         Text=Text || c
  116.         Code=substr( rest, 3)
  117.       end
  118.   end
  119.   return Text
  120.