Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: mulletman87 on May 18, 2016, 02:26:08 AM

Title: Lightweight Web Server on my RPI2
Post by: mulletman87 on May 18, 2016, 02:26:08 AM
Hi all,

I am looking for a very lightweight (used to use uHTTPd on openwrt) web server to serve a statistics page.

Any suggestions?

I was going to use Mongoose as there was a guide on using it on the forums already but it seems that the v7 repo doesn't have it (http://tinycorelinux.net/7.x/armv6/tcz/).

The web content (just html, js and css) is hosted in /opt/dest/www so I would just need to edit the config file of the package to point it to that location.

What would you use?

Thanks in advance :)

Title: Re: Lightweight Web Server on my RPI2
Post by: Greg Erskine on May 18, 2016, 04:16:31 AM
hi mulletman87,

We use busybox-httpd.tcz for piCorePlayer. It has meet our requirements to date.

So hundreds or maybe thousands of people are using it with no reported issues.

regards
Greg
Title: Re: Lightweight Web Server on my RPI2
Post by: xyz-worx on May 18, 2016, 04:17:59 AM
Hi mulletman87,

I would propose two web servers:

First, you could use busybox's internal simple web-server. As far as I know this is
an option on configuring/compiling busybox. Maybe one of the maintainers can give
you a hint, whether this option is present in busybox.

For my own purposes I use the monkey web-server: http://monkey-project.com/ (http://monkey-project.com/).
It's easy to configure and lightweight. It also can be extended with e. g. CGI if needed later.
The only drawback I see is, that there is no *.tcz upto now for direct download and install.
Therefore you  have to compile it from source which is not a big deal.

best regards

      xyz-worx
Title: Re: Lightweight Web Server on my RPI2
Post by: bmarkus on May 18, 2016, 04:59:48 AM

First, you could use busybox's internal simple web-server. As far as I know this is
an option on configuring/compiling busybox. Maybe one of the maintainers can give
you a hint, whether this option is present in busybox.


piCore version was not mentioned. However busybox-httpd.tcz is in the piCore-6.x and piCore-7.x repo. It is worth to use tcz tools to check what is in the repo before rebuilding which is free for everyone of course :)

Title: Re: Lightweight Web Server on my RPI2
Post by: gavinmc42 on May 18, 2016, 05:01:17 AM
busybox-httpd work for me fine.
Handles HTML5, CGI, Javascript.
Have used CGI to run shell, micropython, Lua, Luajit scripts to do GPIO stuff.
I use dygraphs.js to plot from csv files, mostly just data plots.
Title: Re: Lightweight Web Server on my RPI2
Post by: jgrulich on May 18, 2016, 08:36:30 AM
busybox-httpd is simple and seems to be stable. It even support basic authentication for some folders, but doesn't support https.
Hence the security seems to be the same important question as the basic function, has anybody practical experience how robust it is against the hacker attacks?
Title: Re: Lightweight Web Server on my RPI2
Post by: bmarkus on May 18, 2016, 08:40:25 AM
busybox-httpd is simple and seems to be stable. It even support basic authentication for some folders, but doesn't support https.
Hence the security seems to be the same important question as the basic function, has anybody practical experience how robust it is against the hacker attacks?

What kind of hacker attack? It is too generic. Usually not the web server itself hacked but via PHP code, SQL injection, etc. Working with simple static pages or CGI can be safe.
Title: Re: Lightweight Web Server on my RPI2
Post by: jgrulich on May 18, 2016, 09:08:14 AM
Guess the web pages modification / infection. Any possible way?
Which ports are open for infection? For sure :80, but no other?
Title: Re: Lightweight Web Server on my RPI2
Post by: patrikg on May 18, 2016, 09:33:48 AM
Lighttpd ??

http://tinycorelinux.net/7.x/armv6/tcz/lighttpd.tcz.info
Title: Re: Lightweight Web Server on my RPI2
Post by: mulletman87 on May 18, 2016, 10:06:18 AM
Thanks everyone, I think I will go with busybox-httpd.tcz, looks good.

I will just set the www directory to /opt/dest/www within the config file which I presume should be easy enough.

Really appreciate the feedback.
Title: Re: Lightweight Web Server on my RPI2
Post by: gavinmc42 on May 18, 2016, 11:29:45 PM
I have two spots where I stick the HTML files.
/home/tc/www
or I make and use the third partition /mnt/mmcblk0p3/data/www
May need to make a symbolic link to /mnt/mmcblk0p3/.....

I save data to the third partition, trying to leave mmcblk0p1 and 2 untouched.
Mainly to make for long lifetime of the SD card.
Two units running for 18+ months saving data every 5 minutes, still working 24/7 :P
Title: Re: Lightweight Web Server on my RPI2
Post by: mulletman87 on May 19, 2016, 10:28:14 AM
Thanks @gavinmc42 - I definitely need to preserve the life the the SD card so that info is valuable for me, thanks!

I did install it today and fired it up by typing:

sudo /usr/local/sbin/busybox-httpd -p 80 -h /opt/dest/www/ -u tc:staff

I checked if the process was running using:

ps -e | grep busy

I am now getting a 404 error which I am 99% sure is now due to my web content giving issues so I will sort that out tomorrow (in this case, I am happy about the 404 because it means it is at least finding a webserver hehe).

Thanks for the help everyone.
Title: Re: Lightweight Web Server on my RPI2
Post by: gavinmc42 on May 19, 2016, 08:45:39 PM
Missing index.html?
That is the default for busybox-httpd

call below code a file ledon.cgi, stick it in www/cgi-bin/
button on the HTML5 page calls the ledon.cgi file, now you have web control of GPIO.

#!/bin/sh
#echo "Content-type: text/html"
#echo ""
#echo "LED 22 is on"
echo 1 > /sys/class/gpio/gpio22/value
echo "HTTP/1.1 303 Found"
echo "Location: /index.html"

.cgi files are just scripts, could be a shell file calling micropython, lua, luajit etc
Anything that can run by calling it.

The trick to CGI is the echo "HTTP1.1 xxx" codes, 204, 303 etc

Title: Re: Lightweight Web Server on my RPI2
Post by: mulletman87 on May 29, 2016, 10:44:21 AM
@gavinmc42, thank you, all sorted, really appreciate it.
Title: Re: Lightweight Web Server on my RPI2
Post by: gavinmc42 on May 31, 2016, 04:48:51 AM
I am putting this here in case I forget how to do it, which I just did;)

busybox-httpd likes to have cgi-bin and data files under it's directory.

So if your data gets stored on mmcblk0p3 you need to make a symbolic link to it

cd /home/tc/www
ln -s /mnt/mmcblk0p3/data/logs ./logs

Don't forget to mount mmcblk0p3 on boot, put this in the /opt/bootsync.sh file

mount -w /dev/mmcblk0p3

your cgi-bin code can now find the log files for plotting.
This is my file called select.cgi, just some shell script that goes in /home/tc/www/cgi-bin/
My html file uses Chrome's  input type="date" which does not work in Firefox as I found today.

   <form action="cgi-bin/select.cgi">
   Select file:
   <input type="date" name="date">
   
   <input type="submit">
   </form>


select.cgi

#!/bin/sh

echo $QUERY_STRING | awk -F'[=&]' '{print $2}' > /home/tc/day1

sed 's/-/_/g' /home/tc/day1 > /home/tc/day2
day=$( cat /home/tc/day2 )

selected="Data_"$day".csv"
echo $selected > /mnt/mmcblk0p3/www/file.ini


echo "HTTP/1.1 303 found"
echo "Location: /plot.html?"$selected
echo ""


Title: Re: Lightweight Web Server on my RPI2
Post by: bmarkus on June 01, 2016, 01:12:45 AM
busybox-httpd.tcz added to piCore 8.x repo.