2

To deal with the Android captive portal detection for my specific setup, I need to return an HTTP status code 204 whenever I get a GET request for /generate_204. I currently use uhttpd as my webserver, so I'm wondering whether this is possible to do with this server.

My current understanding: I need to write myself a CGI (or PHP or Lua) script that returns something like
Status: 204 No Result

The question I have is how I can configure uhttpd to forward requests to /generate_204 to CGI or PHP or Lua, since that neither has a prefix nor a file-extension that I can match for this purpose.

2
  • Use something along the lines option lua_prefix /generate_204 and have your script as the index document in that subdirectory?
    – HBruijn
    Aug 21 '16 at 8:45
  • @HBruijn That seems like a good idea. I tried it and if I open the /generate_204 url, it does give me the desired result, but it changes the url in the browser window to /generate_204/ (notice the xtra slash at the end). The Android captive portal detection still fails. Looking at the source code, it uses a request with FollowRedirects set to false. Is uhttp generating a redirect to /generate_204/ when I make the request? Is there a way to prevent this?
    – Markus A.
    Aug 21 '16 at 19:31
4

Unfortunately @HBruijn's quite clever idea of simply making /generate_204 a directory rather than a file and then using that as the cgi_prefix with an index.cgi-file inside it as the index_page, only works partly. When I open /generate_204 from the browser myself, it does exactly what I wanted, but only after first returning a redirect to /generate_204/, which the Android captive portal detection explicitly ignores. So, unfortunately this solution doesn't solve my problem.

Here's the hack-job I've come up with that does seem to work:

Simply don't have a /generate_204 file at all and instead create a CGI-script in cgi-bin that handles all erroneous requests that looks like this:

#!/bin/sh
if [ "$REQUEST_URI" == "/generate_204" ]; then
    echo "Status: 204 No Content"
    echo ""
    exit
fi

echo "Status: 404 Not Found"
echo "Content-Type: text/html"
echo ""
cat /path/to/my/error404.html

Then simply add the following to /etc/config/uhttpd:

option error_page  /cgi-bin/error.cgi
option cgi_prefix  /cgi-bin
list   interpreter ".cgi=/bin/ash"

(adjusting file and folder names as needed)

This is definitely not the cleanest solution, and in case there's a way to prevent the redirect and make @HBruijn's idea work, I'll leave the question open for now, since I'd much prefer that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.