Skip to content

Instantly share code, notes, and snippets.

@ysc3839
Created October 29, 2019 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysc3839/e058bdd35df92b3f5ed9939615ece4a7 to your computer and use it in GitHub Desktop.
Save ysc3839/e058bdd35df92b3f5ed9939615ece4a7 to your computer and use it in GitHub Desktop.
require('luci.util')
local nx_redir = false
function http_date(time)
return os.date('!%a, %d %b %Y %H:%M:%S GMT', time)
end
function handle_request(env)
local send = uhttpd.send
if env.REQUEST_URI == '/' then -- NintendoWiFi
if nx_redir then
send('Status: 302 Found\r\n')
send('Location: https://www.bing.com/\r\n\r\n')
else
local date = http_date(os.time())
send('Status: 200 OK\r\n')
send('Content-Length: 2\r\n')
send('Expires: %s\r\n' % date)
send('Cache-Control: max-age=0, no-cache, no-store\r\n')
send('Pragma: no-cache\r\n')
send('Date: %s\r\n' % date)
send('X-Organization: Nintendo\r\n')
send('Content-Type: text/plain\r\n\r\nok')
end
elseif env.REQUEST_URI == '/generate_204' then -- Android generate_204
send('Status: 204 No Content\r\n')
send('Date: %s\r\n\r\n' % http_date(os.time()))
end
end
config uhttpd 'conntest'
option rfc1918_filter '1'
list listen_http '0.0.0.0:080'
option home '/var/tmp'
list lua_prefix '/=/root/conntest-handler.lua'
option http_keepalive '0'
option tcp_keepalive '0'
@ysc3839
Copy link
Author

ysc3839 commented Oct 29, 2019

You need to run opkg install uhttpd-mod-lua first to install uHTTPd lua handler support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment