Page 1 of 2 12>
Topic Options
#97389 - 2002-12-31 05:39 AM CGI in KiX?
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#97390 - 2002-12-31 06:13 AM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
thanks, will definitely check this out.
_________________________
!

download KiXnet

Top
#97391 - 2002-12-31 09:01 PM Re: CGI in KiX?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
You should be able to modify the executable type via the registry, but as the author mentioned... a very strong security risk. i.e. KiXtart would require either KiXtart or batch to execute, then possibly someone could use that to execute their own code against your system.
Top
#97392 - 2002-12-31 09:03 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, not sure of it on IIS, but on apache running on windows server, should not need any tweaks to work.
like I said, haven't tested.
only w2k-server running apache is our f-secure server.
_________________________
!

download KiXnet

Top
#97393 - 2002-12-31 10:35 PM Re: CGI in KiX?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
I think Apache needs to have the config.ini file modified in conjunction with the registry.... but I've not tried either. I'm still at home on vacation and do go back to work till Thursday. No Apache here at home.

ps You've got mail Lonk

[ 31. December 2002, 22:36: Message edited by: NTDOC ]

Top
#97394 - 2002-12-31 10:44 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
will work on this later. now time for "meditation"

anyway, apache has the main-config, but! it' does not need a trace of the stuff it's executing as CGI.
CGI is a stand-alone program which can fully define itself.
_________________________
!

download KiXnet

Top
#97395 - 2002-12-31 10:46 PM Re: CGI in KiX?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Please send me your files before going into too much meditation.. sleep [Wink]
Top
#97396 - 2002-12-31 10:50 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I've counted to reach the nirvana at 1 am (1h 5m from the posting) and before that, can't open e-mails nor any other form of personal messages...
you see, have a big pain in my heart.
have to clear it up before re-joining the kix-fanatics-leaders.

anyway, be patient, will report asap.
_________________________
!

download KiXnet

Top
#97397 - 2003-08-11 04:57 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
has anyone been playing with this?
I tried with apache as got bored to those cryptic unix scripting languages but no.

3.47 seems to give better results (seems to output to stdout, no?) than newer kix-versions...

but still, with apache I had no luck.
and couldn't find any specific documentation how to go with this.
_________________________
!

download KiXnet

Top
#97398 - 2003-08-11 05:04 PM Re: CGI in KiX?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I've got quite a bit of Apache experience (albeit with *nix), what exactly was your problem? Apache is usually pretty good at logging the cause of failures in the error log file.
Top
#97399 - 2003-08-11 05:18 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hehee.
the problem is that there is nothing much in the errorlog [Big Grin]

with kix 4.22 beta 1:
quote:
Premature end of script headers: index.cgi
and with 3.47:
quote:
malformed header from script. Bad header= : index.cgi
tested with:
code:
#!e:/kix32.exe
"Content-Type: text/html" ?
?
"<html><head><title>test</title></head><body>blaah!</body></html>" ?
?

if there is something simple wrong, I don't wonder.
as said, couldn't find anything related on the web.
_________________________
!

download KiXnet

Top
#97400 - 2003-08-12 11:18 AM Re: CGI in KiX?
Richard H. Administrator Offline
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
#97401 - 2003-08-12 04:43 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, chr(10) it's for sure.
that much I need to play with unix everyday [Wink]
but afaik, apache seems to have no problems with crlf on windows system.
on linux there indeed must be proper chars... at least in some meaningfull places.

I thought about the handler and read some from manual but got nowhere...
think I need search some more on the web.
it indeed sounds promising but it does not actually say how to do this.

what comes to ascii...
think that 3.47 has no setoption [Wink]
_________________________
!

download KiXnet

Top
#97402 - 2003-08-12 05:13 PM Re: CGI in KiX?
Richard H. Administrator Offline
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 Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
i have been wanting to do this with IIS for some time now... [Smile]

[ 12. August 2003, 17:42: Message edited by: Bryce ]

Top
#97404 - 2003-08-12 07:05 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Apache/2.0.47 (Win32)
_________________________
!

download KiXnet

Top
#97405 - 2003-08-13 02:33 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, tested with the 3.47 version that was said to work.
as got no luck with handlers nor magic, I just exec'ed kix from simple tcl-cgi:
code:
#!c:/tcl/bin/tclsh84.exe

exec e:/webroot/KIX32.exe {e:\webroot\test.kix}

result:
quote:
Premature end of script headers: KIX32.cgi
anyways, I got "better" errors when script was omitted:
quote:

Premature end of script headers: KIX32.cgi
Script error : failed to find/open script !.

child process exited abnormally
while executing
"exec e:/webroot/KIX32.exe"
(file "C:/Program Files/Apache Group/Apache2/cgi-bin/KIX32.cgi" line 3)

obviously, as kixtart does not pipe to stdout, it just won't work.

[ 13. August 2003, 14:35: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#97406 - 2003-08-13 03:53 PM Re: CGI in KiX?
Richard H. Administrator Offline
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 Offline
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 [Smile]
Top
#97408 - 2003-08-13 05:26 PM Re: CGI in KiX?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sorry, only thing with your way was different is that you used batch, I used tcl.

like said, couldn't make a go with 3.47 nor it can't be done with any other ver of kixtart.

indeed that temp file thing is a workaround but I'd never even think about using such stuff in real production env.

anyway, you proved that it can be done.
now I sit and wait for kixtart enchangement that enables us to write to stdout instead of playing with work-around files.
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 265 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org