[Klone-users] help with klone cgi

Stefano Barbato barbato at koanlogic.com
Mon Sep 14 11:18:35 EDT 2009


Hi Mark!

below are a few notes about your issues:

### issue 1 ###

The cgi{} configuration block must be inside the "app_http" block;  
the /axis-cgi directory may be anywhere in the filesystem, KLone  
expects an absolute directory for the script_alias directive (it's  
better to move it out of /www otherwise a misconfiguration may show  
the source code of the cgi script that may be dangerous).

Is the "flash.cgi" file a shell script? in such case it should print  
out the content-type header field followed by a blank line (this will  
avoid the browser save dialog step). For ex. this is a valid cgi script:

---[ test.cgi ]---
#!/bin/sh

# header
echo "Content-type: text/html"
echo

# content
echo "<body>hi!</body>"
------------------

This is how the config file shoud look like:
---[ kloned.conf ]---
[...]
app_http
{
     type            http
     addr.port       8080
     dir_root        /www
     cgi
     {
         script_alias    /cgi   /full/path/to/axis-cgi
         cgi.handler     exec
     }
}
[...]
---------------------

### issue 2 ###

That's because the cgi{} config block is misplaced so klone thinks  
that it's a simple static web content to return as-is.

You'll see the Save dialog because klone uses "application/octet- 
strem" when it doesn't know the proper content-type (it's based on  
file extension); browsers also don't know how to display binary data  
inline so they let you save that on disk hoping that somebody known  
how to handle that later :)

Note also that HTML you added ("<!DOCTYPE html PUBLIC "-//W3C//DT...."  
etc.) is read and used just by browsers, KLone never looks inside HTML  
content. What I wrote in my last email is that the CGI must set the  
HTTP (not HTML) header fields before writing any HTML content (but if  
you're using stock Axis CGIs they are doing that already I suppose).

### issue 3 ###

You can move the kloned.conf out of webapp/ directory (i.e. out of the  
embedded filesystem) and use the -f switch when lanuching the kloned  
daemon:

	./kloned -f kloned.conf

Klone always tried to find the page requested in the embedded fs and  
falls back to external file system otherwise. Given that your cgi must  
be out of the embedded fs you will be able to tweak the CGI script and  
re-try it without recompiling and restarting klone.

NOTE: you must configure KLone with --enable_fs to enable external  
filesystem support and --enable_cgi to use CGIs (add those switch to  
KLONE_CONF_ARGS variable in the top level makefile)

### issue 4 ###

That would be great; probably a simple mime{} block in the .conf file  
should be enough:

mime
{
	# file extension	mimetype
	abc			application/ABC
}

I'm not sure how we could import an external patch into klone if it's  
not copyright'd by KoanLogic but we will sort that out in some way :)

Let me know,
stefano



On 13/set/09, at 16:57, Mark Richards wrote:

> Stefano.
>
> Thanks for your answers so far.  And great to hear from you!
>
> Here's the headers and a little more :) below...
>
>
>
> There seem to be two problems, but I am trying to stay with one at a  
> time :)
>
> *** Issue 1: my script_alias seems to be ignored.
>
> http://192.168.1.29:8087/
> (index.kl1):
>
> GET / HTTP/1.1
> Host: 192.168.1.29:8087å,ž
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 
> 1.9.1.3) Gecko/20090824 Firefox/3.5.3å,ž
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/ 
> *;q=0.8å,ž
> Accept-Language: en-us,en;q=0.5å,ž
> Accept-Encoding: gzip,deflateå,ž
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7å,ž
> Keep-Alive: 300å,ž
> Connection: keep-aliveå,ž
> Cookie: klone_sid=5c85e0b8605a2f4469dd27b3712faf2bå,ž
>
> HTTP/1.0 200 OK
> Server: klone/2.1.0å,ž
> Date: Sat, 12 Sep 2009 19:11:35 GMTå,ž
> Content-Type: text/htmlå,ž
> Cache-Control: no-cache, must-revalidateå,ž
> Expires: Mon, 1 Jan 1990 05:00:00 GMTå,ž
> Pragma: no-cacheå,ž
>
>
> and the cgi:
>
> Test 1**  Test fails when web address points to cgi:
>         http://192.168.1.29:8087/cgi/admin/flash.cgi
>  * note below: as script_alias is set to /cgi  /axis-cgi  I assume  
> the target directory is referenced as /www/...
>    but just to be certain I also put axis_cgi in www/../ (one  
> directory below www).  Get same result:
>
> Not Found
> URL: /cgi/admin/flash.cgi
>
> with:
>
> app_http
> {
>     type            http
>     dir_root        /www
>     #dir_alias       /cgi/ /axis-cgi/
>     #dir_alias       /admin-bin/ /www/admin-bin/
>     #dir_alias       /axis-release/ /www/axis-release/
>         addr.type       IPv4
>         addr.port       8087
>
> }
>
> cgi
> {
>     script_alias    /cgi  /axis-cgi
>         # .pl and .cgi files will be executed as is
>         pl.handler          exec
>         cgi.handler         exec
> }
>
> and:
> [root at dev1 klone]# ls webapp/www/axis-cgi/admin/ -ltr
> total 280
> -rwxrwxrwx 1 root root 278782 Sep  7 15:43 flash.cgi
>
>
> *** Issue 2:
> When directly pointing to the CGI (It's included in the webapp/www  
> directory), the cgi responds but instead of launching at the  
> server's commandline it sends the cgi back and therefore presents a  
> save/open dialog.
>
>
> REQUEST:
>
> GET /axis-cgi/admin/flash.cgi HTTP/1.1
> 192.168.1.29:8087日本語
> Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/ 
> 20090824 Firefox/3.5.3日本語
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8日本 
>> en-us,en;q=0.5日本語
> gzip,deflate日本語
> ISO-8859-1,utf-8;q=0.7,*;q=0.7日本語
> 300日本語
> keep-alive日本語
> klone_sid=5c85e0b8605a2f4469dd27b3712faf2b日本語
>
>
> RESPONSE:
>
> HTTP/1.0 200 OK
> klone/2.1.0日本語
> Sat, 12 Sep 2009 19:33:05 GMT日本語
> application/octet-stream日本語
> Mon, 07 Sep 2009 19:43:31 GMT日本語
> 278782日本語
>
>
> 日本語 is because firefox handles japanese character encoding.
>
> This got me to considering... I did not set the http headers.
>     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 
> ">
>     <html xmlns="http://www.w3.org/1999/xhtml">
>     <head>
>     <meta http-equiv="Content-Type" content="text/html;  
> charset=utf-8" />
>
> After doing so I get the same response from the CGI.
>
>
> --
>
> And why not heap on two more (therefore can legitimately say "he has  
> issues"):
>
> ***Issue 3: Although I have been around klone for some time (yet not  
> active for at least a year until now) I can't seem to figure out if  
> it's possible to have an external kloned.conf and still use an  
> internal (kloned-compiled) web page and other stuff (webapps/ 
> www...).  If possible, how does one reference "encapsulated" versus  
> "external" files?  I was looking at this as a possible easy way to  
> test the stuff above.
>
>
> *** issue 4:I looked at how klone does mime.  Apparently mime_types  
> is built into mime_map.c.
>
> Might be nice to have ability to override with an external file -  
> perhaps also referenced via kloned.conf?
>
> I can write this change if you thinks it's worthwhile.
>
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users





More information about the klone-users mailing list