Skip to content

Instantly share code, notes, and snippets.

@ysc3839
Created October 29, 2019 05:50
Show Gist options
  • Select an option

  • Save ysc3839/e058bdd35df92b3f5ed9939615ece4a7 to your computer and use it in GitHub Desktop.

Select an option

Save ysc3839/e058bdd35df92b3f5ed9939615ece4a7 to your computer and use it in GitHub Desktop.

Revisions

  1. ysc3839 created this gist Oct 29, 2019.
    29 changes: 29 additions & 0 deletions conntest-handler.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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
    9 changes: 9 additions & 0 deletions uhttpd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@

    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'