Project

General

Profile

Creating a captive portal using http redirects?

Added by xj25vm over 10 years ago

I'm trying to create a captive portal (if that is the correct term) using iptables and lighttpd. The idea is to run a wifi AP using OpenWRT - and anybody connecting to this wifi AP will be redirected to one single website (which doesn't run on the router). I'm not entirely sure if I'm going about it the right way, but this is my plan so far:

1. Use iptables to forward all outgoing traffic on port 80 on the wifi AP to local port 8080 on the LAN facing interface.
2. Run lighttpd on the wifi AP on port 8080 on the internal facing interface.
3. Configure http redirect in lighttpd to send all traffic to the captive portal website (which is external).

These are the redirect statements I've been trying to use in lighttpd.conf:

$HTTP["host"] !~ "^www.mycaptiveportal.tld$" {
url.redirect = ( "" => "http://www.mycaptiveportal.tld" )
}

$HTTP["host"] == "^www.mycaptiveportal.tld$" {
url.redirect = ( ".*" => "http://%1" )
}

The idea being that the first redirect takes care of regular traffic - while the second redirect leaves alone requests aimed already at the captive portal website. At least that was the intention.

The redirect itself works OK if I don't use iptables to forward port 80 - if I go manually to my.routers.ip.address:8080. But if I enable the firewall and send all outgoing port 80 traffic to the router's 8080 port - things get stuck with "Page not found".

The problem is that I can't work out if the second redirect is working at all - or where do things get stuck.

Or am I doing it all wrong and iptables+lighttpd is the wrong tool for this job - and I should be looking instead at something like squid?

Any advice or suggestions much appreciated.