#97389 - 2002-12-31 05:39 AM
CGI in KiX?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
This looks interesting for you CGI people out there..
Using Kix as a CGI script
Kent
|
Top
|
|
|
|
#97395 - 2002-12-31 10:46 PM
Re: CGI in KiX?
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Please send me your files before going into too much meditation.. sleep
|
Top
|
|
|
|
#97400 - 2003-08-12 11:18 AM
Re: CGI in KiX?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well, the malformed/premature end pretty much means that it doesn't like what you are outputting before the HTML.
There are three things I'd try:
- VERY IMPORTANT! Use SetOption("ASCII","ON"). The headers *must* be in ASCII (possibly even 7bit), and as we know KiXtart defaults to unicode.
- Write to a log file or something to ensure that the script is actually being called - there may simply be an error in the path / filename substitution semantics. Normally using the "#!" magic will cause the input to be piped to the command, and as we know KiXtart does not accept piped input. To avoid this, rather than using the "#!" magic you should use a "handler", defined in the Apache configuration. Define a "handler" for files with a ".kix" extension and away you go.
- Rather than using "?" for the line feeds with the headers, explicitly send the end of line character using Chr(). I can't remember if it is Chr(10), Chr(13) or both off the top of my head.
If all that fails, you could of course call the script from a DOS batch file. Not pretty, but it may get you started. It's been a while since I looked at this, so if you need more detail let me know. [ 12. August 2003, 11:22: Message edited by: Richard H. ]
|
Top
|
|
|
|
#97402 - 2003-08-12 05:13 PM
Re: CGI in KiX?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: what comes to ascii... think that 3.47 has no setoption
That may explain the difference in error messages between the two versions.
Which version of Apache are you running?
|
Top
|
|
|
|
#97403 - 2003-08-12 05:41 PM
Re: CGI in KiX?
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
i have been wanting to do this with IIS for some time now... [ 12. August 2003, 17:42: Message edited by: Bryce ]
|
Top
|
|
|
|
#97406 - 2003-08-13 03:53 PM
Re: CGI in KiX?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Ok, just downloaded Apache 2.0.47 and tried.
It works, but is a little kludgy.
First of all, you need to add a handler for KiXtart. Edit the httpd.conf file, search for the "AddHandler" lines and insert these:
code:
# KiXtart handler AddHandler KiXtart .kix Action KiXtart /cgi-bin/exec_kix.bat
What this does is say that whenever a file with the ".kix" extension is requested, run the handler instead. The requested file name is passed as an environment variable.
Now, in your cgi-bin directory, create a batch file called "exec_kix.bat". This is the handler script. WARNING You should probably create this script elsewhere, to avoid hackers running arbitrary code.
Here is a very simple example:
code:
@echo OFF echo Content-Type: text/html echo. if exist kixoutput.txt del kixoutput.txt kix32.exe "%PATH_TRANSLATED%" if exist kixoutput.txt type kixoutput.txt if exist kixoutput.txt del kixoutput.txt
This expects your KiXtart script to write it's output to "kixoutput.txt". In a real environment you need to do something a bit more clever to ensure that two requests don't overwrite the file. You could use the REMOTE_ADDR and REMOTE_PORT environment variables to create the temporary file name.
Here is a demonstration kixtart script, which you should put in your htdocs directory:
code:
Break ON $gNULL=SetOption("ASCII","ON") $gNULL=SetOption("WrapAtEOL","ON") $gNull=RedirectOutput("kixoutput.txt") "<HTML>" ? "<HEAD>" ? "<TITLE>KiXtart as CGI demonstration</TITLE>" "</HEAD>" ? "<BODY>" ? "Using KiXtart version "+@KIX+" as CGI!" ? "</BODY>" ? "</HTML>" ? Exit 0
Now, I call the page with URL http://127.0.0.1/kixdemo.kix the following string appears: quote: Using KiXtart version 4.20 as CGI!
It may be helpful to see all the environment variables, in which case write the following batch file to the cgi-bin directory:
code:
@echo OFF echo Content-Type: text/html echo. echo ^<HTML^> echo ^<HEAD^>^<TITLE^>DOS Batch as CGI^</TITLE^>^</HEAD^> echo ^<BODY^> echo ^<PRE^> set echo ^</PRE^> echo ^</BODY^> echo ^</HTML^>
When called with URL http://127.0.0.1/cgi-bin/env.bat you will get something similar to this: quote:
HTTP_ACCEPT=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* HTTP_ACCEPT_LANGUAGE=en-gb HTTP_ACCEPT_ENCODING=gzip, deflate HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322) HTTP_HOST=127.0.0.1 HTTP_CONNECTION=Keep-Alive PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;;C:\MinGW\bin;C:\Program Files\Compaq\Compaq Management Agents\Dmi\Win32\Bin;C:\Program Files\Symantec\pcAnywhere\ PROMPT=$P$G SystemRoot=C:\Windows COMSPEC=C:\Windows\system32\cmd.exe PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH WINDIR=C:\Windows SERVER_SIGNATURE=Apache/2.0.47 (Win32) Server at 127.0.0.1
SERVER_SOFTWARE=Apache/2.0.47 (Win32) SERVER_NAME=127.0.0.1 SERVER_ADDR=127.0.0.1 REMOTE_ADDR=127.0.0.1 DOCUMENT_ROOT=C:/Program Files/Apache Group/Apache2/htdocs SERVER_ADMIN=rhowarth@sgb.co.uk SCRIPT_FILENAME=C:/Program Files/Apache Group/Apache2/cgi-bin/env.bat REMOTE_PORT=2791 GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.1 REQUEST_METHOD=GET QUERY_STRING= REQUEST_URI=/cgi-bin/env.bat SCRIPT_NAME=/cgi-bin/env.bat
|
Top
|
|
|
|
#97407 - 2003-08-13 04:14 PM
Re: CGI in KiX?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Almost forgot, You may find with 3.47 that you don't need the RedirectOutput() kludge and temporary files to get it to work
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 265 anonymous users online.
|
|
|