Simple cgi on the Chumby/Infocast with lighthttpd
There is a great blog posting, featured on Hack a Day, that describes how to run lighthttpd on the Chumby. The blog also provides a pre-built version of the web server that is configured to run in /mnt/storage instead of /mnt/usb. This is nice because it lets you run the httpd server from the writable partition of the internal microsd card instead of having to use a thumb drive. A lot of the Chumby derived devices have enough space in /mnt/storage to do all kinds of interesting things.
I recently purchased an BestBuy Insignia Infocast 8" device. It is essentially an 800Mhz big screen Chumby running linux 2.6 with some BestBuy customizations. The Insignia team did not include a web server and the simplest way to fix that is to use the lighthttp server from the blog mentioned above.
Installing and Configuring
The basic steps for installation are:
One of the nifty things about running a web server is that you can cause it to run programs on the device just by requesting the URL of a program tied to the web server. Everything written to standard-out is returned to the web browser.
The lighty/lighttpd.conf file contains mappings to support Bourne Shell and Perl scripts. It assumes that any file ending in .sh is a shell script and any file ending in .pl is a Perl script.
Final Thoughts
The referenced blog article describes how to build lighthttpd from scratch. You might want to do a custom build if you need additional modules.
I recently purchased an BestBuy Insignia Infocast 8" device. It is essentially an 800Mhz big screen Chumby running linux 2.6 with some BestBuy customizations. The Insignia team did not include a web server and the simplest way to fix that is to use the lighthttp server from the blog mentioned above.
Installing and Configuring
The basic steps for installation are:
- Turn on SSH in the Info cast. Touch the Insignia logo in the upper right corner. This should make the About Device panel appear. Then touch the Pi symbol in the upper right corner. Enable sshd by touching the SSHD button. The daemon starts immediately. The machine's IP address appears in the panel. You will need that to ssh into the box.
- SSH into the device from your PC. Windows users can use putty which is freely available on the internet. Linux users probably already have it installed. The root user id has no ssh password so linux users will login with ssh root@<chumby_ip_address>
- You can enable sshd across reboots by creating /psp/start_sshd with the command
touch /psp/start_sshd
but remember that you the default sshd has no password.
- cd into /mnt/storage.
- Download the pre-built version of light httpd. Find the URL in the blog mentioned above and enter wget <the_.tar.gz file path> in the ssh window. I normally create a software or downloads directory to keep stuff organized.
- Unzip the package with gunzip <the_.tar.gz file name> and then untar the .tar file while in the /mnt/storage directory.
- You can delete the .tar file because it is no longer needed.
- The directory /mnt/storage/psp/rfs1 does not exist in the default Infocast installation so create that directory using mkdir.
- Copy /mnt/storage/lighty/startup.sh to /mnt/storage/psp/rfs1/userhook1. Note that the userhook1 filename does not have any file extension.
- Edit /mnt/storage/lighty/lighthttpd.conf
- Change the server.errorlog and accesslog.filename to fit your needs. I changed mine to
# server.errorlog = "/mnt/storage/logs/lighthttpd.error.log"Start the web server and verify it's running
# accesslog.filename = "/mnt/storage/logs/lighttpd.access.log"
server.errorlog = "/tmp/lighthttpd.error.log"
accesslog.filename = "/dev/null"
- Type /mnt/storage/psp/rfs1/userhook1 to start the server.
- You should be able to verify the process is running with the ps -ef command.
- You can then hit the web server with your browser http://<chumby_ip_address> and see the welcome screen.
One of the nifty things about running a web server is that you can cause it to run programs on the device just by requesting the URL of a program tied to the web server. Everything written to standard-out is returned to the web browser.
The lighty/lighttpd.conf file contains mappings to support Bourne Shell and Perl scripts. It assumes that any file ending in .sh is a shell script and any file ending in .pl is a Perl script.
cgi.assign = ( ".sh" => "/bin/sh", ".pl" => "/mnt/storage/usr/bin/perl", ".cgi" => "/psp/usr/bin/perl" )The Infocast 8" comes with a couple shell scripts that were intended for the standard Chumby web server that are easily adapted to lighthttpd (with a simple rename). They have .sh on the end so we'll fix that when we copy them into the lighty cgi-bin directory.
alias.url = ( "/cgi-bin/" => "/mnt/storage/lighty/cgi-bin/", "/images/" => "/mnt/storage/images/" )
- cp /www/cgi-bin/memstats /mnt/storage/lighty/cgi-bin/memstats.sh
- cp /www/cgi-bin/wifi /mnt/storage/lighty/cgi-bin/wifi.sh
- http://<ip_address>/cgi-bin/memstats.sh
- http://<ib_address>/cgi-bin/wifi.sh
#!/bin/shI installed it in /mnt/storage/lighty/cgi-bin/top.sh and run it with http://<ip_address>/cgi-bin/top.sh
echo "Content-type: text/html"
echo ""
echo "<html><head>"
echo "<title>Chumby Top Processes</title>"
echo "<meta http-equiv=\"Refresh\" content=\"5\";>"
echo "</head></html>"
echo "<body>"
echo "<h4>Top Processes (refreshes every 5 seconds) </h4>"
echo "<pre>"
top -n1
echo "</pre>"
echo "</body></html>"
Final Thoughts
The referenced blog article describes how to build lighthttpd from scratch. You might want to do a custom build if you need additional modules.
I was have troubles with this, I'll try to do this later when I get home. Thanks.
ReplyDeletelong island document scanning
Could you run .sh script without extension?
ReplyDeleteThe original chumby(classic) runs apache/httpd,
http://wiki.chumby.com/index.php/Using_the_busybox_HTTP_server
it has no .conf and can run shell script w/o extension, e.g.
http://forum.chumby.com/viewtopic.php?id=1060
but how to set the lighttpd.conf for this?
thanks for sharing this post with us. it is interested post . i have great interest in new things which are belongs to IT field. i installed this device and i am sure to read this post that this device become very useful for everone those are using this.....
ReplyDeleteArchitectural CGI