Feb 062013
 

After some experimentation with the RaspAP, I decided to write up a simple web interface for it so that when hostapd started broadcasting, I could use a simple web page rather than ssh to control the wifi and hostapd on the Raspberry Pi. The distribution I used was Raspbian Server Edition once again.

I started off by installing lighttpd and php5

apt-get install lighttpd php5-cgi

After that, I enabled php for lighttpd and restarted it for the settings to take effect.

sudo lighty-enable-mod fastcgi-php
/etc/init.d/lighttpd restart

Now, comes the fun part.
For security reasons, the www-data user which lighttpd runs under is not allowed to start or stop daemons, or run commands like ifdown and ifup, all of which I wanted my page to do.
So what I have done, is added the www-data user to the sudoers file, but with restrictions on what commands the user can run.
The line appears in /etc/sudoers like this –

www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results,/sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf,/etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start,/etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf

Notice I’ve restricted the www-data user to only be able to run the exact commands in the sudoers file
This means that the www-data can only take down, bring up, and show the configuration of wlan0 for example.

After the sudoers file has been modified, the script can now do what it needs to do.
I have a very very rough version written up so far, but it’s not available to download yet.

Here are some screenshots of what it’ll be able to do though ! 🙂

WiFi Information screen
infowifi

WiFI Client connection screen
configwifi

WiFi Hotspot setup screen
confighostapd

I’m in the process of prettying up the GUI but in the meantime, this is functional enough 🙂
I’ll get the demo up and running soon enough too ! 🙂

**Update**
I have released the PHP files for this – Please check this post for details.

Share

  17 Responses to “Script : Web Configuration Page for Raspberry Pi”

  1. Hi.
    Just been reading through this and would quite like to give it a go. Is the GUI available to download at all?

    • I’ll be making it available shortly. I’m rather ashamed of the code at the moment haha, so I’ll clean it up before posting it online to download 🙂

  2. […] Here’s a simple web configuration interface for controlling wifi and hosted on the Raspberry Pi from Sirlagz.net: […]

  3. […] a continuation this post, I have completed the first version of the RaspAP WebGUI. I have yet to decide on a good name for […]

  4. […] : Starting hostapd when WiFi goes down How To : Turn the Raspberry Pi Into a Shaping WiFi Router Script : Web Configuration Page for Raspberry Pi RaspAP WebGUI How To : Use A RT5370 USB WiFi NIC In A […]

  5. Great Tool – I like it! Pretty cool !

    Short question: If I want to open/close an openVPN Connection with a Button or A HREF link – how do I do it?

    The command: sudo /etc/init.d/openvpn start
    and
    sudo /etc/init.d/openvpn stop

    Thanks and best,
    Tobi

    • You would need to modify the sudo file to allow the page to run those commands, and then create buttons to actually run the commands.

  6. Hola!
    Comentarte que es una aplicación web funcional. Gracias por compartirla. 😀
    Solo una pregunta. Esta versión Beta aun no permite realizar los cambios de parámetros como: Cambiar SSID, contraseña, tipo de seguridad?
    En general, esta muy bien!

    • This page is a very very early version, and I haven’t put any work into it since I built it due to a lack of time.
      I don’t remember if you can change those settings. I thought you could but I could be wrong.
      I’ll put this onto github sometime, and then everyone can modify it and improve it !

      • Thanks for replying! Yeah, I’ve been looking for to change those settings, since I need it to work as soon as possible, I’m running late about it and I’m a begginer in this stuff. If you could share the modified version I would appreciate it so much.

        Thanks in advance!

  7. You’re like a coding genius!
    I know enough HTML to hack out a webpage, barely. But I need to learn this PHP stuff since It’s what I need for my project. Thank you for posting this It gives me a lot to break, fix and learn.

  8. Hi!

    This is great, but I get an error in this line:
    system(‘sudo cp /tmp/WLANdata /etc/wpa_supplicant/wpa_supplicant.conf’,$returnval);

    He cant copy the WLANdata file to /etc/wpa_supplicant/wpa_supplicant.conf.
    I can do this on the command line.

    Maybe someone has an idea, where the problem is?

    Thank you!

  9. I was looking for this, but only for lan not wifi

    Whats the possibility of changing it for lan, im reading all the code but not sure were to start (very new to php)

    Im looking at a info page, and a configuration page to set ip, netmask and dns

    Just point me in the direction of how to modify the code and ill be a very happy chappy

    Thanks
    Robert

  10. Hi where can I download the codes for this Raspberry web app?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.