home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 November / APCD25112k.iso / feature / webserv / SAMBAR43.ZIP / _SETUP.1 / PBCgi.bas < prev    next >
Encoding:
BASIC Source File  |  1998-07-08  |  3.9 KB  |  106 lines

  1. ' This program is for PowerBasic Console Compiler and was converted from
  2.  
  3. ' the Delphi program named CGITEST which was by Dave Wedwick,
  4.  
  5. ' Phoenix Transit System, June, 1997
  6.  
  7.  
  8.  
  9. ' Converted on June 1998 by David Martin, Ivy League Software
  10.  
  11.  
  12.  
  13. ' This tests the win-cgi capabilities of a web server.
  14.  
  15.  
  16.  
  17. ' The win-cgi programs receive three command line parameters.  These are
  18.  
  19. ' filenames for interacting with the server.
  20.  
  21.  
  22.  
  23. ' The first parameter is the name of an INI file (doesn't have to be an 
  24.  
  25. ' .INI file extension) containing information needed to process the request.
  26.  
  27.  
  28.  
  29. ' The second parameter is the name of a file containing data that was POSTed
  30.  
  31. ' by a form.
  32.  
  33.  
  34.  
  35. ' The third parameter is the file to where output needs to go to return data
  36.  
  37. ' to the web server.
  38.  
  39.  
  40.  
  41. ' This program simply reads the data from the file identified by the first
  42.  
  43. ' command line parameter and writes it to the file identified by the third
  44.  
  45. ' parameter.  Some HTML formatting is included in the output. Include this
  46.  
  47. ' program in HTML Forms to see the results of submitting the form, etc.
  48.  
  49.  
  50.  
  51. FUNCTION PBMain ()
  52.  
  53.  
  54.  
  55.     ' If launched by the web server, there will be (at least) three
  56.  
  57.     ' command line parameters.  If there aren't, assume that this is
  58.  
  59.     ' being launched by the command line and show a usage message.
  60.  
  61.  
  62.  
  63.     CommandLine$ = COMMAND$
  64.  
  65.  
  66.  
  67.     IF PARSECOUNT ( CommandLine$ , ANY ", " ) < 3 THEN
  68.  
  69.         ' This is for when someone runs it from the command line
  70.  
  71.         CLS
  72.  
  73.         STDOUT "This is a Win-CGI Test Program..."
  74.  
  75.         STDOUT
  76.  
  77.         STDOUT "This program tests the cgi-win capabilities of a web server."
  78.  
  79.         STDOUT
  80.  
  81.         STDOUT "To test, copy this executable to the cgi-win area of the web"
  82.  
  83.         STDOUT "server and reference it via the web browser."
  84.  
  85.         STDOUT
  86.  
  87.         STDOUT "Example: HTTP:\\www.myserver.com\cgi-win\pbcgi.exe"
  88.  
  89.         IF NOT CommandLine$ = "" THEN
  90.  
  91.             STDOUT
  92.  
  93.             STDOUT "The COMMAND$ was: ";
  94.  
  95.             STDOUT CommandLine$
  96.  
  97.             STDOUT "Which has" ;
  98.  
  99.             STDOUT LTRIM$(STRING$(PARSECOUNT ( CommandLine$ , ANY ", " ),2)) ;
  100.  
  101.             STDOUT "parameters"
  102.  
  103.         END IF
  104.  
  105.     ELSE
  106.  
  107.         gIniFile$ = PARSE$( CommandLine$ , ANY ", " , 1 )
  108.  
  109.         gInputFile$ = PARSE$( CommandLine$ , ANY ", " , 2 )
  110.  
  111.         gOutputFile$ = PARSE$( CommandLine$ , ANY ", " , 3 )
  112.  
  113.  
  114.  
  115.         ' Open the third parameter for writing (output)
  116.  
  117.         gOutputNum% = FREEFILE    
  118.  
  119.       OPEN gOutputFile$ FOR BINARY AS #gOutputNum%
  120.  
  121.     
  122.  
  123.         ' Required header used by the server for processing
  124.  
  125.       PUT$ #gOutputNum% , "HTTP/1.0 200 OK" + CHR$(13,10)
  126.  
  127.       PUT$ #gOutputNum% , "Content-type: text/html" + CHR$(13,10) + CHR$(13,10)
  128.  
  129.     
  130.  
  131.         ' Useing builtin commands is easy
  132.  
  133.       PUT$ #gOutputNum% , "The date & time at the server is " + DATE$ + " at " + TIME$
  134.  
  135.     
  136.  
  137.         ' Show what the three filenames are
  138.  
  139.       PUT$ #gOutputNum% , "<H4>INI file is: " + gIniFile$ + _
  140.  
  141.                                                 "<br>Input file is: " + gInputFile$ + _
  142.  
  143.                                                 "<br>Output file is: " + gOutputFile$ + "</H4>"
  144.  
  145.         ' Read INI file and write it back out to the Output file
  146.  
  147.         gIniNum% = FREEFILE
  148.  
  149.       OPEN gIniFile$ FOR BINARY AS #gIniNum%
  150.  
  151.       PUT$ #gOutputNum% , "<HR><H1>Contents of INI file:</H1>"
  152.  
  153.       PUT$ #gOutputNum% , "<PRE>" + CHR$(13,10)
  154.  
  155.       WHILE NOT EOF(gIniNum%)
  156.  
  157.             GET$ #gIniNum% , 4000 , TheLineIn$
  158.  
  159.           PUT$ #gOutputNum% , TheLineIn$ + CHR$(13,10)
  160.  
  161.       WEND
  162.  
  163.       PUT$ #gOutputNum% , "</PRE>" + CHR$(13,10)
  164.  
  165.       CLOSE #gIniNum%
  166.  
  167.     
  168.  
  169.         ' Read Input file and write it back out to the Output file
  170.  
  171.         gInputNum% = FREEFILE
  172.  
  173.       OPEN gInputFile$ FOR BINARY AS #gInputNum%
  174.  
  175.       PUT$ #gOutputNum% , "<BR><HR><H1>Contents of INPUT file:</H1>"
  176.  
  177.       PUT$ #gOutputNum% , "<PRE>" + CHR$(13,10)
  178.  
  179.       WHILE NOT EOF(gInputNum%)
  180.  
  181.             GET$ #gInputNum% , 4000 , TheLineIn$
  182.  
  183.           PUT$ #gOutputNum% , TheLineIn$ + CHR$(13,10)
  184.  
  185.       WEND
  186.  
  187.       PUT$ #gOutputNum% , "</PRE>" + CHR$(13,10)
  188.  
  189.       CLOSE #gInputNum%
  190.  
  191.     
  192.  
  193.       PUT$ #gOutputNum% , "<HR>"
  194.  
  195.     
  196.  
  197.       CLOSE #gOutputNum%
  198.  
  199.     
  200.  
  201.         ' We're done.  When this .EXE finishes, the web server
  202.  
  203.         ' then processes the output file for the client.
  204.  
  205.     END IF
  206.  
  207.     
  208.  
  209. END FUNCTION
  210.  
  211.