WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Lighttpd or light web server alternative  (Read 10767 times)

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Lighttpd or light web server alternative
« on: November 13, 2013, 12:57:56 PM »
Hello,
I would like to run a light web server at start to just allow the user to config the SSID and password to a WIFI setup.
The idea is just serve one form page, and I'm searching for the smaller webserver capable of doing it.
It is the Lighttpd webserver ported to tce? I haven't found it on the tce package installer.

Thank you in advance
Gabriel

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lighttpd or light web server alternative
« Reply #1 on: November 13, 2013, 01:03:04 PM »
Try mongoose
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #2 on: November 13, 2013, 01:14:48 PM »
Thank you, I'll give a try!

Gabriel

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #3 on: November 13, 2013, 01:21:31 PM »
Sorry to disturb again,

Is there any php package available on tce?
I need to use the form info to write to a file (the wifi config data), and restart the raspi, and frankly I don't know how to achieve that in plain html...

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lighttpd or light web server alternative
« Reply #4 on: November 13, 2013, 01:40:51 PM »
PHP with APACHE is work in progress, will come in two weeks
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Zendrael

  • Sr. Member
  • ****
  • Posts: 363
    • Zendrael's home of projects
Re: Lighttpd or light web server alternative
« Reply #5 on: November 13, 2013, 01:43:30 PM »
Lighttpd (or even smaller, Busybox-Httpd) with some CGI can do the trick too!

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lighttpd or light web server alternative
« Reply #6 on: November 13, 2013, 01:49:54 PM »
Mongoose supports CGI too
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #7 on: November 13, 2013, 02:09:07 PM »
Seems that I have to learn cgi :)
If anyone can give me a hint, I want to just show a html form with two boxes: one for the SSID of the wifi and another for the password (I already have the form).

And when the user submits the form, just save both strings to a local text file and reboot the raspi (the cgi part I guess).
Any sugestion?

Thanks!
Gabriel
« Last Edit: November 13, 2013, 02:11:51 PM by gpulido »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lighttpd or light web server alternative
« Reply #8 on: November 13, 2013, 02:22:25 PM »
For CGI you can use nearly any language. You can find planty of docs with Google. For Python, see:

http://www.python.org/doc/essays/ppt/sd99east/sld040.htm

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #9 on: November 13, 2013, 05:18:49 PM »
Again, thank you.
As I wanted to maintain the tiny factor and try not to install unnecessary packages, and given than the python one is a little heavy, I finished using sh as language for the cgi.

If anyone is interested I could write here the content of the two files.
The idea is to serve a page that allows the user to config the wifi without the need of using ssh
Usefull for the picocore project for example and with the raspi connected also by eth. If the raspi is not connected also by the ehternet, I'm going to use the fallback to creation of an AP point on boot to serve the same page.

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #10 on: November 14, 2013, 05:40:38 PM »
As promised I'm going to write down the steps to configure an run a "wifi config server" on the raspi.
The idea is to allow the user to not ssh on the system to just config the wifi.

1) Install webserver:
I use the mongoose tcz package. It is a tiny server. So
Run the tce package manager. Search for mongoose and install it.

2) Create the pages
We need to create the server pages that mongose need to server. They need to be on the same folder structure. You can put it anywhere you want, mongoose is not strict. I just use /home/tc/www
2.1) The index.html. This is just a basic html form with the SSID, encryptyon and password fields so the user could just fill them.
The contents of my index.html (it is based on the pifi proyect)
 
Code: [Select]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />
  <meta charset="UTF-8" />

  <title>Wifi Config</title>
  <style type="text/css">
/*<![CDATA[*/
  a:link {color:black; text-decoration:none;}    /* unvisited link */
  a:visited {color:black; text-decoration:none;} /* visited link */
  a:hover {color:#900000; text-decoration:underline;}   /* mouse over link */
  a:active {color:#900000; text-decoration:underline;}  /* selected link */
  @font-face
  {
  font-family: "asenine";
  src: url('/fonts/asenine.ttf');
  }
  h1 {
    text-shadow:2px 2px 5px rgba(10,10,10,0.6);
    font-family: 'asenine', Fallback, sans-serif;
    font-size:300%;
   }
  h2 {
    text-shadow:2px 2px 5px rgba(10,10,10,0.6);
    font-family: 'asenine', Fallback, sans-serif;
    font-size:200%;
    margin-top: 0.5em;
    margin-bottom: 0.1em;
   }
  p {
    font-size: 150%;
  text-shadow:2px 2px 5px rgba(10,10,10,0.6);
  font-family: 'asenine', Fallback, sans-serif;
  margin-top: 0.5em;
  margin-bottom: 0.1em;
  }
  /* html *
  {
  text-shadow:2px 2px 5px rgba(10,10,10,0.6);
  font-family: 'asenine', Fallback, sans-serif;
  font-size: 120%;
  }*/
  html, body { min-height: 100%; }
  body
  {
  background-image: url('/images/bg_top.png'), url('/images/bg_bottom.png'), url('/images/pifi_mini_logo.png');
  background-position: top left, bottom left, top center;
  background-repeat: repeat-x, repeat-x, no-repeat;
  background-size: 3%, 2%, 45%;
  }
  /*]]>*/
  </style>
</head>

<body>
  <center>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />

    <h1><a href="index.php">Main Menu</a></h1>

    <form name="user_wpa_info" method="get" action="wpa_helper.cgi" onsubmit=
    "return confirm('Are you sure? This will reboot the unit!')">
      <h2>SSID:</h2><input name="ui_ssid" type="text" size="22" /><br />

      <h2>Encryption Type:</h2><select name="ui_encryption">
        <option value="open">
          Open (No Encyrption)
        </option>

        <option value="wep">
          WEP
        </option>

        <option value="wpa">
          WPA or WPA2
        </option>
      </select><br />

      <h2>Password:</h2><input name="ui_pass" type="password" size="22" /><br />
      <br />
      <input type="submit" style=
      "-mox-box-shadow: 0 1px 3px #111; -webkit-box-shadow: 0 1px 3px #111; box-shadow: 0 1px 3px #111 ;border-radius:8px; -moz-border-radius:8px; -webkit-border-radius: 8px;font-face:'asenine'; font-size:110%;"
      value=" Submit and Reboot " />
    </form><br />
  </center>
</body>
</html>
You can of course make it more pretty or better. This just works.

2.2) CGI script.
The idea is use a sh script to retrieve the parameters from the form and just create a WIFI.db that substitutes the created by the wifi.sh script. This way the same init code for the wifi that is used on the wifi script could be used here.
Also it needs to persist the changes, and reboot the raspi.
Any programming language could be used here. However I wanted to maintain an small footprint, so I didn't want to install python / perl  whatever for just this.
My wpa_helper.cgi:
Code: [Select]
#!/bin/sh

#first we retrieve the parameters from the query_string
IFS='&'
set -- $QUERY_STRING
ui_ssid=${1#*=}
ui_encr=${2#*=}
ui_pass=${3#*=}
#save the parameters to the wifi.db
echo ${ui_ssid}$'\t'${ui_pass}$'\t'${ui_encr}> /home/tc/wifi.db
# The HTML output starts here
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Storing WIFI Data connection. Please wait</title>"
echo "</head><body><h1>Storing WIFI Data Connection... Please wait</h1><pre>"
#Persist the info
filetool.sh -b
#reboot the raspi
reboot
Edited 11-17-2013
As point out by mcdudeabides. It is need to give execution permits to the cgi script:
Code: [Select]
sudo chmod 755 /home/tc/www/wpa_helper.cgi
Thats all. Easy enough :)
3) Run the server at boottime.
We need to run mongoose, so add the following to the /opt/bootlocal.sh
Code: [Select]
mongoose -document_root /home/tc/www &
4) Persist all before rebooting:
Ensure that you have the home folder on your filelist, and just
Code: [Select]
filetool.sh -b
That's all folks the next time you reboot your raspi and point your webbrowser to the port 8080 on the raspi the wifi config will appear.

Some notes:
If you combine this approach with the data of the post: http://forum.tinycorelinux.net/index.php/topic,16181.msg95878.html#msg95878
You can create a boot process like this:

Code: [Select]
The raspi tries to connect to the wifi network that is defined on the wifi.db.

If it connects then
    resume normal boot

if not (maybe the wifi.db doesn't exist or the network is unreachable)
    the raspi creates an AP with DHCP
    The wifi config server (the one of this post) is started
    Then after that, the user could just connect to the wifi that the raspi is generating, go to the wifi server page, config the wifi data, and reboot, next time the raspi will be connected to the wifi.

This mechanism allows to use the raspi without ethernet connection as a wifi-connected device. The user only needs a wifi capable device (as an smartphone) to config the device without the need of ssh to it.

Some drawbacks or improvements that could be done:
- At this moment the SSID introduced by the user is not checked. A mechanism to retrieve all reachable wifi's and fill a combobox of ssid could be great.
To do it, the index.html must be trasnformed on an index.cgi and us sh to call iwilist and parse the info.
- The password of the wifi is stored as plain text on the wifi.db, however this is the same way as the wifi.sh script does, I'm not very comfy with that, but I don't have the time / knowledge to use another mechanism.
- The password is passed on the url when the user clicks on the form button. Again I don't think this would be a major concern as this is use just one moment after the reboot. Also if it is configured using the PA mechanism the network on which the server is running is almost "one-time" use and created ad-hoc for the configuration.

I hope this could help anyone. If anyone have any doubts I will try to explain.
Gabriel
« Last Edit: November 16, 2013, 08:04:51 PM by gpulido »

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: Lighttpd or light web server alternative
« Reply #11 on: November 15, 2013, 06:15:49 PM »
Please forgive the NOOB question.  Is the wpa_helper.cgi file stored in the same www directory with the index.html file?  There is not a special cgi-bin directory required? 

I am able to go to //mybox:8080 and see the input page displayed.  I can enter fields and then submit.  It will attempt http://mybox:8080/wpa_helper.cgi?ui_ssid=tester&ui_encryption=open&ui_pass=tester but it throws a HTTP 500 error.  There is probably a simple answer.  Thanks for your help.

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: Lighttpd or light web server alternative
« Reply #12 on: November 16, 2013, 12:18:49 AM »
Doh.  A mind is a terrible thing.  Didn't give execute to www directory.

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: Lighttpd or light web server alternative
« Reply #13 on: November 16, 2013, 08:01:33 PM »
Please forgive the NOOB question.  Is the wpa_helper.cgi file stored in the same www directory with the index.html file?  There is not a special cgi-bin directory required? 

I am able to go to //mybox:8080 and see the input page displayed.  I can enter fields and then submit.  It will attempt http://mybox:8080/wpa_helper.cgi?ui_ssid=tester&ui_encryption=open&ui_pass=tester but it throws a HTTP 500 error.  There is probably a simple answer.  Thanks for your help.

Hello, as you already figured out, there is not need on mongoose server to specify the cgi directory, he just figures out using the extension.
And you are right, I forget to add to the tutorial the given permisions to the cgi script. Thank for point me it out, I'm going to modify the post.

Gabriel