home *** CD-ROM | disk | FTP | other *** search
- '----------------------------------------------------------------------
- ' ***************
- ' * CGITEST.BAS *
- ' ***************
- '
- ' Test CGI back-end for NCSA httpd for Windows. Generates HTML report
- ' detailing the stuff it got from the server via the interface.
- '
- ' Requires procedures in CGI.BAS. Set the VB project options to use
- ' Sub Main as the startup form.
- '
- ' Author: Robert B. Denny <rdenny@netcom.com>
- ' June 7, 1994
- '----------------------------------------------------------------------
- Option Explicit
-
- '
- ' Sample CGI script
- '
- ' Returns a report in HTML of the CGI data, depending on the "extra
- ' path info" on the URL (Logical Path), which is used here as an
- ' "opcode". Yeah, there are better ways to do this, but I designed
- ' this to be used from a command-driven linemode browser as well as
- ' interactively. So the tail end of the URL selects the type of
- ' report. See comments for more...
- '
- ' CGI.BAS contains the "Sub Main()" entry point. That code initializes
- ' the CGI environment, then calls CGI_Main(), here. At this point, the
- ' output file is open, the input file (if any) is NOT. Use the Send()
- ' function to isolate yourself from the output file number, and as
- ' a convenient shortcut.
- '
- ' NOTE: ALWAYS use FreeFile() to get file numbers if you need to open
- ' files in your code!
- '
- Sub CGI_Main ()
- Dim sel As String
- Dim buf As String
- Dim i As Integer
-
- sel = LCase$(Mid$(CGI_LogicalPath, 2)) ' Skip leading "/"
- Select Case sel
- '
- ' If no selector, return the usage document
- '
- Case ""
- Send ("Location: /winhttpd/htdocs/cgitest.htm")
- Send ("")
- Exit Sub ' Finished: BACK TO CGI DRIVER/MAIN!!!
- '
- ' Logical Path "Transparent" means generate the full HTTP/1.0
- ' header, testing the server's ability to detect this and pass
- ' it to the client without interpretation. Then it makes a
- ' 'normal' report.
- '
- Case "transparent"
- Send ("HTTP/1.0 200 OK")
- Send ("Server: " & CGI_ServerSoftware)
- Send ("MIME-Version: 1.0")
- StartDocument (sel)
- Send ("This was returned transparently.")
- '
- ' CGI means send back the CGI variables
- '
- Case "cgi"
- StartDocument (sel)
- Send ("<H2>CGI Variables (some may be blank):</H2>")
- Send ("<UL>")
- Send ("<LI><I>CGI Version: </I>" & CGI_Version)
- Send ("<LI><I>Request Protocol: </I>" & CGI_RequestProtocol)
- Send ("<LI><I>Request Method: </I>" & CGI_RequestMethod)
- Send ("<LI><I>Executable Path: </I>" & CGI_ExecutablePath)
- Send ("<LI><I>Logical Path: </I>" & CGI_LogicalPath)
- Send ("<LI><I>Physical Path: </I>" & CGI_PhysicalPath)
- Send ("<LI><I>Query String: </I>" & CGI_QueryString)
- Send ("<LI><I>Content Type: </I>" & CGI_ContentType)
- Send ("<LI><I>Content Length: </I>" & CGI_ContentLength)
- Send ("<LI><I>Server Software: </I>" & CGI_ServerSoftware)
- Send ("<LI><I>Server Name: </I>" & CGI_ServerName)
- Send ("<LI><I>Server Port: </I>" & CGI_ServerPort)
- Send ("<LI><I>Server Admin: </I>" & CGI_ServerAdmin)
- Send ("<LI><I>Remote Host: </I>" & CGI_RemoteHost)
- Send ("<LI><I>Remote Address: </I>" & CGI_RemoteAddr)
- Send ("<LI><I>Authentication Method: </I>" & CGI_AuthType)
- Send ("<LI><I>Authenticated Username: </I>" & CGI_AuthUser)
- Send ("<LI><I>RFC-931 Identity: </I>" & CGI_TAPUser)
- Send ("</UL>")
- Send ("<H2>System Variables</H2>")
- Send ("<UL>")
- Send ("<LI><I>Output File: </I>" & UCase$(CGI_OutputFile))
- Send ("<LI><I>Content File: </I>" & UCase$(CGI_ContentFile))
- If CGI_DebugMode Then buf = "Yes" Else buf = "no"
- Send ("<LI><I>Debug Mode: </I>" & buf)
- Send ("</UL>")
- '
- ' "Headers" means show the Accept: and Extra headers
- '
- Case "headers"
- StartDocument (sel)
- Send ("<H2>MIME Accept Types:</H2>")
- If CGI_NumAcceptTypes > 0 Then
- Send ("<UL>")
- For i = 0 To CGI_NumAcceptTypes - 1
- ' Don't display the "Yes"
- If CGI_AcceptTypes(i).value = "Yes" Then
- Send ("<LI>" & CGI_AcceptTypes(i).key)
- Else
- Send ("<LI>" & CGI_AcceptTypes(i).key & " (" & CGI_AcceptTypes(i).value & ")")
- End If
- Next i
- Send ("</UL>")
- Else
- Send ("(none)")
- End If
- Send ("<H2>Extra Headers:</H2>")
- If CGI_NumExtraHeaders > 0 Then
- Send ("<UL>")
- For i = 0 To CGI_NumExtraHeaders - 1
- Send ("<LI><I>" & CGI_ExtraHeaders(i).key & ": </I>" & CGI_ExtraHeaders(i).value)
- Next i
- Send ("</UL>")
- Else
- Send ("(none)")
- End If
- '
- ' "Form" means show the form stuff decoded
- '
- Case "form"
- StartDocument (sel)
- Send ("<H2>Form fields:</H2>")
- If CGI_NumFormTuples > 0 Then
- Send ("<UL>")
- For i = 0 To CGI_NumFormTuples - 1
- Send ("<LI><I>" & CGI_FormTuples(i).key & ": </I>" & CGI_FormTuples(i).value)
- Next i
- Send ("</UL>")
- Else
- Send ("(none)")
- End If
- If CGI_NumHugeTuples > 0 Then
- Send ("<H2>Form Fields > 64KB:</H2>")
- Send ("<UL>")
- For i = 0 To CGI_NumHugeTuples - 1
- Send ("<LI><I>" & CGI_HugeTuples(i).key & ": </I>Offset=" & CStr(CGI_HugeTuples(i).offset) & ", Length=" & CStr(CGI_HugeTuples(i).length))
- Next i
- Send ("</UL>")
- End If
-
- End Select
-
- '
- ' Finish up with server admin's address. Return to complete HTTP.
- '
- Send ("<HR>")
- Send ("<A HREF=""mailto:" & CGI_ServerAdmin & """>")
- Send ("<address><" & CGI_ServerAdmin & "></address>")
- Send ("</A></BODY></HTML>")
-
- '****** RETURN, DON'T STOP! ******
- End Sub
-
- Sub StartDocument (sel As String)
- Send ("Content-type: text/html")
- Send ("X-Script-name: Visual Basic CGI Test 1.1")
- Send ("")
- Send ("<HTML><HEAD><TITLE>CGI Test Results</TITLE></HEAD>")
- Send ("<BODY><H1>CGI Test Results</H1>")
- Send ("Program version: 1.1 (12-Nov-94)<BR>")
- Send ("Server: <B>" & CGI_ServerSoftware & "</B><BR>")
- Send ("Selector: <B>" & sel & "</B><P>")
- Send ("<A HREF=""/winhttpd/htdocs/cgitest.htm"">Return to usage document</A>")
- Send ("<HR>")
- End Sub
-
-