OpenWrt Forum Archive

Topic: Captive portal configuration

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello!

I'm using this firmware:


Firmware Version    OpenWRTYun Attitude Adjustment 1 / LuCI 0.11 Branch (0.11+svn10537)
Kernel Version    3.3.8

I want to configure it as captive portal, with an html page with some php scripts. I can configure the captive portal, and i can install php, but separately. If i try to do both things the board stops working and it resets itself completely. I show you the commands i used:
Note: i wrote w w w, h t t p, u h t t p d because the forum doesn't allow me to post link. Sorry for the inconvenience!

1) Install PHP:

opkg update
opkg install php5 php5-cgi php5-cli

vi /etc/config/u h t t p d
# Edit to uncomment the list interpreter php

/etc/init.d/u h t t p d restart

# PHP test
cd /mnt/sda1/arduino/w w w
echo "<?=phpinfo(); ?>" >phpinfo.php

Using the browser i can see the php page correctly.

2) Captive portal configuration:

uci set wireless.@wifi-iface[0].ssid='ArduinoWiFi'

uci add_list dhcp.@dnsmasq[0].address='/#/1.1.1.1'

uci add firewall redirect  
uci set firewall.@redirect[-1].name=capture H T T P
uci set firewall.@redirect[-1].src=lan
uci set firewall.@redirect[-1].proto=tcp
uci set firewall.@redirect[-1].src_dip=!$(uci get network.lan.ipaddr)
uci set firewall.@redirect[-1].src_dport=80"
uci set firewall.@redirect[-1].dest_port=8080"
uci set firewall.@redirect[-1].dest_ip=$(uci get network.lan.ipaddr)
uci set firewall.@redirect[-1].target=DNAT

uci add firewall redirect  
uci set firewall.@redirect[-1].name=captureDNS
uci set firewall.@redirect[-1].src=lan
uci set firewall.@redirect[-1].src_dip=!$(uci get network.lan.ipaddr)
uci set firewall.@redirect[-1].src_dport=53
uci set firewall.@redirect[-1].dest_port=53
uci set firewall.@redirect[-1].dest_ip=$(uci get network.lan.ipaddr)
uci set firewall.@redirect[-1].target=DNAT

echo >/etc/h t t p d_redirect.conf 'A:/:/cgi-bin/redirect.cgi'

cat >/w w w/cgi-bin/redirect.cgi <<EOM
#!/bin/sh
echo Status: 302 found
echo Location: h t t p://$(uci get network.lan.ipaddr)
echo Cache-Control: no-cache
echo
echo You are headed for h t t p ://$(uci get network.lan.ipaddr)
EOM

chmod +x /w w w/cgi-bin/redirect.cgi

uci set u h t t p d.redirect='u h t t p d'
uci set u h t t p d.redirect.listen_h t t p='0.0.0.0:8080'
uci set u h t t p d.redirect.cgi_prefix='/cgi-bin'
uci set u h t t p d.redirect.config='/etc/h t t p d_redirect.conf'
uci set u h t t p d.redirect.home='/w w w'

cat >/w w w/cgi-bin/control.cgi <<'EOM' 
   #!/bin/sh
   echo $QUERY_STRING >/dev/ttyATH0
   echo Cache-Control: no-cache
   echo Content-type: text/plain
   echo 
   echo Command sent
   EOM

chmod +x /w w w/cgi-bin/control.cgi

uci commit

reboot -d 1 &

The page path is "/w w w/index.html". As i already said above, after reboot the board resets itself. Maybe there's some conflict between the two configurations. Can somebody help me?

Thanks.

Maybe you're running out of RAM?  PHP is pretty big.

mk24 wrote:

Maybe you're running out of RAM?  PHP is pretty big.

Thanks for you reply, how can i check that?

Run free or top from the command line.

What model is your router?  How much RAM does it have?

I'm using the Arduino Yùn board: h t t p s://w w w.arduino.cc/en/Guide/ArduinoYun

Processor: Atheros AR9331
Firmware Version: OpenWRTYun Attitude Adjustment 1 / LuCI 0.11 Branch (0.11+svn10537)
Kernel Version: 3.3.8

Here's the result of top and free after reset (before installing php and configuring captive portal):

root@Arduino:~# free
             total         used         free       shared      buffers
Mem:         61116        26784        34332            0         3464
-/+ buffers:              23320        37796
Swap:            0            0            0
root@Arduino:~# top
Mem: 26832K used, 34284K free, 0K shrd, 3464K buff, 9976K cached
CPU:   0% usr   1% sys   0% nic  97% idle   0% io   0% irq   0% sirq
Load average: 0.31 0.27 0.12 1/53 1858
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 1848  1761 root     R     1492   2%   0% top
 1526     1 root     S     1492   2%   0% /usr/sbin/ntpd -n -p 0.openwrt.pool.n
 1745  1618 root     S     1220   2%   0% /usr/sbin/dropbear -P /var/run/dropbe
 1500     1 nobody   S     2168   4%   0% avahi-daemon: running [Arduino.local]
 1463     1 root     S     1696   3%   0% /usr/sbin/dbus-daemon --system
 1187     1 root     S     1624   3%   0% hostapd -P /var/run/wifi-phy0.pid -B
 1451     1 root     S     1564   3%   0% /usr/sbin/u h t t p d -f -h /w w w -r Arduin
  572     1 root     S     1524   2%   0% {rcS} /bin/sh /etc/init.d/rcS S boot
  766     1 root     S     1500   2%   0% /sbin/syslogd -C16
    1     0 root     S     1496   2%   0% init
 1533     1 root     S N   1496   2%   0% {uSDaemon} /bin/sh /sbin/uSDaemon
 1761  1745 root     S     1496   2%   0% -ash
  701     1 root     S     1496   2%   0% init
  876   809 root     S     1492   2%   0% udhcpc -p /var/run/udhcpc-eth1.pid -s
 1328     1 root     S     1492   2%   0% /sbin/watchdog -t 5 /dev/watchdog
  574   572 root     S     1488   2%   0% logger -s -p 6 -t sysinit
  768     1 root     S     1480   2%   0% /sbin/klogd
 1858  1533 root     S N   1480   2%   0% sleep 2
  809     1 root     S     1476   2%   0% /sbin/netifd
 1618     1 root     S     1152   2%   0% /usr/sbin/dropbear -P /var/run/dropbe

After php installation:

root@Arduino:~# free
             total         used         free       shared      buffers
Mem:         61116        39324        21792            0         5172
-/+ buffers:              34152        26964
Swap:            0            0            0
root@Arduino:~# top
Mem: 39360K used, 21756K free, 0K shrd, 5172K buff, 20088K cached
CPU:   0% usr   1% sys   1% nic  96% idle   0% io   0% irq   0% sirq
Load average: 0.18 0.34 0.21 1/55 2909
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 1486     1 root     S N   1496   2%   0% {uSDaemon} /bin/sh /sbin/uSDaemon
 2789  1780 root     R     1492   2%   0% top
 1744  1383 root     S     1216   2%   0% /usr/sbin/dropbear -P /var/run/dropbe
    3     2 root     SW       0   0%   0% [ksoftirqd/0]
 1452     1 nobody   S     2168   4%   0% avahi-daemon: running [Arduino.local]
 1425     1 root     S     1696   3%   0% /usr/sbin/dbus-daemon --system
 1229     1 root     S     1624   3%   0% wpa_supplicant -B -P /var/run/wifi-wl
 2277     1 root     S     1584   3%   0% /usr/sbin/u h t t p d -f -h /w w w -r Arduin
  573     1 root     S     1524   2%   0% {rcS} /bin/sh /etc/init.d/rcS S boot
  699     1 root     S     1500   2%   0% /sbin/syslogd -C16
 1312   733 root     S     1500   2%   0% udhcpc -p /var/run/udhcpc-wlan0.pid -
    1     0 root     S     1496   2%   0% init
 1479     1 root     S     1496   2%   0% /usr/sbin/ntpd -n -p 0.openwrt.pool.n
 1780  1744 root     S     1496   2%   0% -ash
  574     1 root     S     1496   2%   0% init
  799   733 root     S     1492   2%   0% udhcpc -p /var/run/udhcpc-eth1.pid -s
 1264     1 root     S     1492   2%   0% /sbin/watchdog -t 5 /dev/watchdog
  576   573 root     S     1488   2%   0% logger -s -p 6 -t sysinit
  733     1 root     S     1480   2%   0% /sbin/netifd
  701     1 root     S     1480   2%   0% /sbin/klogd

The discussion might have continued from here.