[Klone-users] Downloading files with Klone

Alvaro Pereira alvaro.pereira at guidance.eu.com
Thu Nov 29 13:27:22 EST 2007


Hi Stefano,

Thanks for this! In the end I used the --enable_fs flag and it did work.
However I noted that the ls.kl1 example shown in your tutorial does not
work when this flag is enabled. I still do not know why but it could be
a mismatch with the run-time library functions used for file/directories
reading. Anyway this is not a big problem for me. I am happy with this.

I also explored the other solution that you recommended and that did not
work either. I set a session variable for keeping the name of the file I
want to download, which worked fine. But the following code produced a
run-time memory exception: "The instruction at "0x004119ea" referenced
memory at "0x5f636d62". The memory could not be "read" ". It sounds like
a memory leak or violation of some kind.

The code snippet follows:

<%! 
	#include <string.h>
	#include <stdio.h>
%>
<html>
	<head>
	</head>
	<body>
		<%
		int len;
		char *name, *logFileName;
		FILE *fp;
		char buf[1024];
						
		logFileName = session_get(session, "file");
	

		response_set_content_type(response, "text/plain");

		strcpy(name, "c:\\folder\\");
		strcat(name, logFileName);
		fp = fopen(name, "rt");
		while((len = fread(buf,sizeof(char), 3, fp )) > 0)
			io_write(out, buf, len);
		
		fclose(fp);
		%>

	</body>
</html>


Regards,
Alvaro




-----Original Message-----
From: klone-users-bounces at koanlogic.com
[mailto:klone-users-bounces at koanlogic.com] On Behalf Of Stefano Barbato
Sent: 28 November 2007 16:21
To: Klone users
Subject: Re: [Klone-users] Downloading files with Klone

Hi Alvaro,

KLone by default embeds all web application files into the "kloned"  
executable, so it doesn't need to rely on the target system file  
system to provide web contents (html files, images, flash, etc.).

If you want to return a file got from the file system you can enable  
this functionality using the --enable_fs parameter of the configure  
script or, if that makes sense for your application, create a .kl1  
page that returns back a file using the standard file system syscalls:

---[ getmyfile.kl1 ]---
FILE *fp;
char buf[1024];

response_set_content_type(response, "text/plain");

fp = fopen(...);
while((len = fread(buf,... )) > 0)
     io_write(out, buf, len);
fclose(fp);
------------------------

If you want to serve through HTTP a directory tree (just like any  
usual web server) you have to append --enable_fs to the  
KLONE_CONF_ARGS variable in the top-level Makefile. Then add an URL  
alias to access system files from the web.

For example if you want to serve files from /var/www/ your  
configuration could be:
	
	dir_alias	/target		/var/www/

and users will be able to access files into /var/www using
http://ip/target/file.ext 
  or http://ip/target/subdir/file.ext (again --enable_fs must be used  
during the configuration phase).

A more complete example (with virtual hosts, CGI and PHP can be found  
on wiki.koanlogic.com).

Answers:
- allow_root must be set to allow the execution of the daemon as the  
superuser "root" on unix systems; it is not used on Windows.
- to install a klone application copying the kloned.exe file is  
enough, everything is embedded into it.


bye,
stefano


On 28/nov/07, at 11:21, Alvaro Pereira wrote:

> Hi
>
> I have been trying now to download files (instead of uploading) from  
> the Klone web server. My targets are text files. So I have included  
> the following HTML code:
>
> <a href="file.txt">download file</a><br><br>
>
> The reason for this is that after upgrading our firmware it might be  
> necessary to have a look on installation logs which are usually txt  
> files. I have placed the above example file in several different  
> folders but Klone never finds it. Where is the web server's root?  
> Where is it actually looking for 'http://xx.xx.xx.xx:8080/file.txt'?  
> I understand this is defined in the configuration file kloned.conf.
>
> So I have the following attributes:
> server_list    app_http
> allow_root yes
> app_http
> {
>     type            http
>
>     addr.type       IPv4
>     addr.port       8080
>     dir_root        /www
> }
>
> What happens if 'allow_root' is deleted? It is also my understanding  
> that the directory './webapp/www' is my web server root. This is  
> where I placed all my html and Klone files, as well 'file.txt'. What  
> can I do in order to be able to download text files using hyperlinks?
>
>
> I have also another question on the same subject:
>
> When I copy and install KLone on my embedded system (after build) I  
> normally copy the .wc and kloned.exe files. I suppose the html and  
> kl1 pages are embedded into the Klone executable. Then I start the  
> service again.
>
> Is it really necessary to copy the contents of the /webapp folder as  
> well? My guess is that copying /etc and /www is not mandatory. Is  
> this right?
>
> But even so, how can I sort the downloading problem? I have tried  
> placing file.txt in the folder where kloned.exe is located but it  
> did not work either.
>
> Regards,
> Alvaro
> This e-mail (and any attachment) is intended only for the attention  
> of the addressee(s). Its unauthorised use, disclosure, storage or  
> copying is not permitted. If you are not the intended recipient,  
> please destroy all copies and inform the sender by return e-mail.  
> Internet e-mail is not a secure medium. Any reply to this message  
> could be intercepted and read by someone else. Please bear that in  
> mind when deciding whether to send material in response to this  
> message by e-mail. This e-mail (whether you are the sender or the  
> recipient) may be monitored, recorded and retained by Guidance  
> Navigation Limited, Guidance Monitoring Limited or any other member  
> of the Guidance group of companies. E-mail monitoring / blocking  
> software may be used, and e-mail content may be read at any time.  
> You have a responsibility to ensure laws are not broken when  
> composing or forwarding e-mails and their contents. Guidance  
> Monitoring Limited (Co No 2626613) and Guidance Navigation Limited  
> (Co No 5231840) are wholly owned trading subsidiaries of Guidance  
> Limited (Co No 5231837). All Guidance group companies are registered  
> in England and Wales with Registered Offices at 4 Dominus Way,  
> Leicester, LE19 1RP. Please note that nothing in this email may be  
> considered to be binding upon Guidance Limited unless the email is  
> from a Director of Guidance Limited and the text refers specifically  
> to commitments by Guidance Limited, rather than one of the above  
> trading companies. _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users


_______________________________________________
Klone-users mailing list
Klone-users at koanlogic.com
http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
This e-mail (and any attachment) is intended only for the attention of the addressee(s). Its unauthorised use, disclosure, storage or copying is not permitted. If you are not the intended recipient, please destroy all copies and inform the sender by return e-mail.   Internet e-mail is not a secure medium. Any reply to this message could be intercepted and read by someone else. Please bear that in mind when deciding whether to send material in response to this message by e-mail.

This e-mail (whether you are the sender or the recipient) may be monitored, recorded and retained by Guidance Navigation Limited, Guidance Monitoring Limited or any other member of the Guidance group of companies.  E-mail monitoring / blocking software may be used, and e-mail content may be read at any time. You have a responsibility to ensure laws are not broken when composing or forwarding e-mails and their contents.

Guidance Monitoring Limited (Co No 2626613) and Guidance Navigation Limited (Co No 5231840) are wholly owned trading subsidiaries of Guidance Limited (Co No 5231837).   All Guidance group companies are registered in England and Wales with Registered Offices at 4 Dominus Way, Leicester, LE19 1RP.  Please note that nothing in this email may be considered to be binding upon Guidance Limited unless the email is from a Director of Guidance Limited and the text refers specifically to commitments by Guidance Limited, rather than one of the above trading companies.





More information about the klone-users mailing list