From: Jamie C. <jca...@we...> - 2013-07-23 08:07:17
|
On 22/Jul/2013 23:57 Krause Felix <Fel...@de...> wrote .. > Hi everyone, > > I am implementing a webmin module for monitoring an embedded system. The webmin > installation is primarily used to administrate the OS, but should also be able > to show the current status of the main application running on it. I need to use > AJAX to automatically update the visualization of some I/O channels. > > Now the application has a RESTful, JSON-based interface for accessing its status. > The problem is that it does not do any authentication, so it is reachable only > from localhost for security reasons. My Webmin module retrieves information from > there and renders it. For the AJAX requests, the Webmin module should act like > a proxy and just pipe through the content retrieved from the application. I tried > the following in a script io.cgi as part of my Webmin module: > > my $client = HTTP::Client->new(); > my $content = $client->get("http://127.0.0.1:8888/io"); > > print "HTTP/1.1 200 OK$CRLF"; > print "Content-Type: text/json$CRLF"; > print "Content-Length: " + length($content); > print "$CRLF$CRLF$content"; > > This does not work; when I try to retrieve /myModule/io.cgi, I get: > > HTTP/1.0 500 Bad Header > Server: MiniServ/1.620 > Date: Tue, 23 Jul 2013 06:07:06 GMT > Content-type: text/html; Charset=iso-8859-1 > Connection: close > > Is it possible to do this with Webmin? Hi Felix, Something like that should work - but you should remove the line that prints "HTTP/1.1 200 OK". This isn't necessary in any Webmin CGI script, as the webserver adds that line. The "500 Bad Header" error happens if your script's output doesn't start with valid HTTP headers. - Jamie |