From: Krause F. <Fel...@de...> - 2013-07-23 07:10:52
|
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? Regards, Felix |
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 |
From: Krause F. <Fel...@de...> - 2013-07-24 06:09:24
|
> 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. I changed it to: my $CRFL = "\x0d\x0a"; my $client = HTTP::Client->new(); my $content = $client->get("http://127.0.0.1:8888/io"); print "Date: " + time2str(localtime) + $CRLF; print "Content-Type: text/json; Charset=iso-8859-1$CRLF"; print "Content-Length: " + length($content); print "$CRLF$CRLF$content"; I get the same 500 error. Afaik these are the only required headers for a http response. Do I need to add others to make it work? Is there a log where Webmin tells me what it doesn't like about my headers? (The action log is empty.) I would look what a normal index.cgi outputs, but I cannot execute it directly from the command line (it says that WEBMIN_CONFIG is not set). Regards, Felix |
From: PEOPLES, M. P <mp...@at...> - 2013-07-23 13:33:06
|
I'm no expert here, but I would get a protocol analyzer (Wireshark) and/or tcpdump and look at the packet stream that is being sent by an application (browser) that does work with your embedded application. At least you'll know what a "well-formed" HTTP message looks like so that you can adjust your code accordingly. You can also look at what is actually being sent by Webmin. Maybe something is being altered before it is sent. Finally, you could try transmitting the message with curl or wget ( I can't really tell details, but I know they can do that) to see if it appropriately formatted. Michael Peoples (mp4783) iGEMS COE, Deployment, Engineering, Application Support and Security Global Service Assurance, M5 AT&T Business Solutions Office: +1 614-886-0923 Mobile: +1 614-886-0923 Senior Systems Manager mpe...@at... This e-mail and any files transmitted with it are AT&T property, are confidential, and are intended solely for the use of the individual or entity to whom this email is addressed. If you are not one of the named recipient(s) or otherwise have reason to believe that you have received this message in error, please notify the sender and delete this message immediately from your computer. Any other use, retention, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited." -----Original Message----- From: Krause Felix [mailto:Fel...@de...] Sent: Tuesday, July 23, 2013 2:58 AM To: web...@li... Subject: [webmin-devel] ajax with webmin 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? Regards, Felix ------------------------------------------------------------------------------ See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk - Forwarded by the Webmin development list at web...@we... To remove yourself from this list, go to http://lists.sourceforge.net/lists/listinfo/webadmin-devel |