' ' ' #################### ' ##### PROLOG ##### ' #################### ' PROGRAM "acgibin" VERSION "0.0003" ' ' This program shows how to create interactive web pages, using the ' Common Gateway Interface (CGI) and XBasic as the programming tool. ' ' This program reads the input data and saves it into to text variables ' commandline$ and formdata$, then builds a simple web page and sends it ' to the server. ' ' This CGI must be called from a web page with a code like this: ' '
' ' or ' ' ' ' Feel free to make to copy, modify or enhance this program. ' For further information call Alberto Alva E. email: talvae@esan.com.pe ' ' this program slightly beautified by "some jerk", but not altered functionally ' IMPORT "xst" IMPORT "kernel32" ' Windows API DECLARE FUNCTION Entry () DECLARE FUNCTION Send (a$) DECLARE FUNCTION CGIStart (pageTitle$) DECLARE FUNCTION CGIBody () DECLARE FUNCTION CGIEnd (footer$) ' $$STD_INPUT_HANDLE = -10 $$STD_OUTPUT_HANDLE = -11 ' ' Standard handles declaration ' XLONG #hStdIn XLONG #hStdOut ' ' ' ###################### ' ##### Entry () ##### ' ###################### ' FUNCTION Entry () ' pageTitle$="acgibin" footer$="end of test" ' CGIStart (pageTitle$) CGIBody () CGIEnd (footer$) END FUNCTION ' ' ' ##################### ' ##### Send () ##### ' ##################### ' FUNCTION Send (a$) a$ = a$ + "\r\n" length = LEN(a$) sent = 0 WriteFile (#hStdOut, &a$, length, &sent, 0) END FUNCTION ' ' ' ######################### ' ##### CGIStart () ##### ' ######################### ' FUNCTION CGIStart (pageTitle$) ' ' Get Standard Handles ' #hStdIn = GetStdHandle($$STD_INPUT_HANDLE) #hStdOut = GetStdHandle($$STD_OUTPUT_HANDLE) ' ' Get Enviroment variables ' Xst() name$ = "HTTP_ACCEPT" : XstGetEnvironmentVariable (@name$, @#accept$) name$ = "AUTH_TYPE" : XstGetEnvironmentVariable (@name$, @#authType$) name$ = "CONTENT_LENGTH" : XstGetEnvironmentVariable (@name$, @#contentLength$) name$ = "CONTENT_TYPE" : XstGetEnvironmentVariable (@name$, @#contentType$) name$ = "GATEWAY_INTERFACE" : XstGetEnvironmentVariable (@name$, @#gatewayInterface$) name$ = "PATH_INFO" : XstGetEnvironmentVariable (@name$, @#pathInfo$) name$ = "PATH_TRANSLATED" : XstGetEnvironmentVariable (@name$, @#pathTranslated$) name$ = "QUERY_STRING" : XstGetEnvironmentVariable (@name$, @#queryString$) name$ = "HTTP_REFERER" : XstGetEnvironmentVariable (@name$, @#referer$) name$ = "REMOTE_ADDR" : XstGetEnvironmentVariable (@name$, @#remoteAddr$) name$ = "REMOTE_HOST" : XstGetEnvironmentVariable (@name$, @#remoteHost$) name$ = "REMOTE_IDENT" : XstGetEnvironmentVariable (@name$, @#remoteIdent$) name$ = "REMOTE_USER" : XstGetEnvironmentVariable (@name$, @#remoteUser$) name$ = "REQUEST_METHOD" : XstGetEnvironmentVariable (@name$, @#requestMethod$) name$ = "SCRIPT_NAME" : XstGetEnvironmentVariable (@name$, @#scriptname$) name$ = "SERVER_SOFTWARE" : XstGetEnvironmentVariable (@name$, @#serverSoftware$) name$ = "SERVER_NAME" : XstGetEnvironmentVariable (@name$, @#servername$) name$ = "SERVER_PORT" : XstGetEnvironmentVariable (@name$, @#serverPort$) name$ = "SERVER_PROTOCOL" : XstGetEnvironmentVariable (@name$, @#serverProtocol$) name$ = "HTTP_USER_AGENT" : XstGetEnvironmentVariable (@name$, @#userAgent$) ' ' get Input Data (formData from STDIN (if method is POST) and commandLine from #queryString$) ' length = XLONG (#contentLength$) IF (#requestMethod$ == "POST") THEN read = 0 buffer$ = CHR$ (0, length) ReadFile (#hStdIn, &buffer$, length, &read, 0) #formData$ = LEFT$ (buffer$, read) END IF #commandLine$= #queryString$ ' ' send Header ' Send ("status: 200 OK") Send ("content-type: text/html\n\r") Send ("The Form Data posted is : "+ #formData$ + "
") END IF Send ("The Command Line is : " + #commandLine$ + "
") Send ("The Principal Enviroment Variables are:
VARIABLE NAME | ") Send ("VARIABLE VALUE |
REQUEST_METHOD | ") Send (""+#requestMethod$+" |
CONTENT_TYPE | ") Send (""+#contentType$+" |
CONTENT_LENGTH | ") Send (""+#contentLength$+" |
QUERY_STRING | ") Send (""+#queryString$+" |
REMOTE_ADDR | ") Send (""+#remoteAddr$+" |
Questions : Alberto Alva E. talvae@esan.com.pe
") Send (""+footer$+"
") Send ("") Send ("") END FUNCTION END PROGRAM