home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / sambar70p.exe / CGITEST.DPR next >
Text File  |  1997-06-19  |  3KB  |  91 lines

  1. program Cgitest;
  2. { This tests the win-cgi capabilities of a web server. For Delphi (all
  3.   versions).
  4.  
  5.   The win-cgi programs receive three command line parameters.  These are
  6.   filenames for interacting with the server.
  7.  
  8.   The first parameter is the name of an INI file (doesn't have to be an .INI
  9.      file extension) containing information needed to process the request.
  10.  
  11.   The second parameter is the name of a file containing data that was
  12.      POSTed by a form.
  13.  
  14.   The third parameter is the file to where output needs to go to return
  15.      data to the web server.
  16.  
  17.  
  18.   This program simply reads the data from the file identified by the
  19.   first command line parameter and writes it to the file identified by
  20.   the third parameter.  Some HTML formatting is included in the output.
  21.   Include this program in HTML Forms to see the results of submitting
  22.   the form, etc.
  23.  
  24.                      by Dave Wedwick
  25.                         Phoenix Transit System
  26.                         June, 1997 }
  27.  
  28.  
  29. {$IFDEF WIN32}
  30.   { 32-bit Delphi }
  31.   {$APPTYPE CONSOLE}
  32.   uses SysUtils;
  33. {$ELSE}
  34.   { 16-bit Delphi }
  35.   uses WinCrt, SysUtils;
  36. {$ENDIF}
  37.  
  38. var
  39.   InStr: String;
  40.   InFile, OutFile: TextFile;
  41.  
  42. begin
  43.  
  44.   { If launched by the web server, there will be (at least) three
  45.     command line parameters.  If there aren't, assume that this is
  46.     being launched by the command line and show a usage message. }
  47.   if ParamCount < 3 then begin
  48.     { Write a message to the console }
  49.     WriteLn('CGI Test');
  50.     WriteLn('');
  51.     WriteLn('This tests the cgi-win capabilities of a web server.');
  52.     WriteLn('To test, copy this executable to the cgi-win area of the web');
  53.     WriteLn('server and reference it via the web browser.');
  54.  
  55.     Exit;
  56.   end;
  57.  
  58.   { Open the third parameter for writing (output) }
  59.   Assign(OutFile, ParamStr(3));
  60.   Rewrite(OutFile);
  61.  
  62.   { Open the first parameter for reading the source from the server (input) }
  63.   Assign(InFile, ParamStr(1));
  64.   Reset(InFile);
  65.  
  66.   { Required header used by the server for processing }
  67.   WriteLn(OutFile, 'HTTP/1.0 200 OK');
  68.   WriteLn(OutFile, 'Content-type: text/html');
  69.   WriteLn(OutFile, '');        { <== Blank line is required }
  70.  
  71.   { Show the current time/date }
  72.   WriteLn(OutFile, 'Current Date/Time is <I>' + FormatDateTime('c', Now) +
  73.                    '</I><BR>');
  74.  
  75.   { Simply read the input file, line by line, and write it to the
  76.     output file as pre-formatted HTML text (using the <PRE> tag) }
  77.   WriteLn(OutFile, '<PRE>');
  78.   while not EOF(InFile) do begin
  79.     ReadLn(InFile, InStr);
  80.     WriteLn(OutFile, InStr);
  81.   end;
  82.   WriteLn(OutFile, '</PRE>');
  83.  
  84.   { We're done.  Close the files.  When this .EXE finishes, the web server
  85.     then processes the output file for the client. }
  86.   CloseFile(InFile);
  87.   CloseFile(OutFile);
  88.  
  89. end.
  90.  
  91.