Opening Webinterface only starts a download

Hello,
My Archer C7 v5 running openwrt a long time now wont open luci. I just installed Collectd and Statistics and configured it in the webinterface. After a reboot of the device i can´t open the Webinterface anymore. If i try to open the webinterface there only a Download starts. But no Webinterface opens up.
How can i fix this?

The Downloaded File named Download has the following Content:

#!/usr/bin/lua
require "luci.cacheloader"
require "luci.sgi.cgi"
luci.dispatcher.indexcache = "/tmp/luci-indexcache"
luci.sgi.cgi.run()

Did you try clearing the cache?

1 Like

I just figured out that i can reach the web Interface by using https. But why is this. I think Configuring statistics and collectd Config can not confuse the webserver so much. Everything else works fine....

Check your uci show uhttpd

Check to see if you have uhttpd.main.lua_prefix='/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua' in that list.

Here is mine:

uhttpd.main=uhttpd
uhttpd.main.redirect_https='1'
uhttpd.main.home='/www'
uhttpd.main.rfc1918_filter='1'
uhttpd.main.max_requests='3'
uhttpd.main.max_connections='100'
uhttpd.main.cert='/etc/uhttpd.crt'
uhttpd.main.key='/etc/uhttpd.key'
uhttpd.main.cgi_prefix='/cgi-bin'
uhttpd.main.script_timeout='60'
uhttpd.main.network_timeout='30'
uhttpd.main.http_keepalive='20'
uhttpd.main.tcp_keepalive='1'
uhttpd.main.ubus_prefix='/ubus'
uhttpd.main.listen_http='10.10.10.10:80'
uhttpd.main.listen_https='10.10.10.10:443'
uhttpd.main.lua_prefix='/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua'
uhttpd.defaults=cert
uhttpd.defaults.days='730'
uhttpd.defaults.bits='2048'
uhttpd.defaults.country='ZZ'
uhttpd.defaults.state='Somewhere'
uhttpd.defaults.location='Unknown'
uhttpd.defaults.commonname='OpenWrt'

If you've changed the uhttpd config, it is what the luCi interface uses..

mine looks similar to yours....

Check this one, as it tells uhttpd what the LUA directories are..

my uci show uhttpd

uhttpd.main=uhttpd
uhttpd.main.listen_http='0.0.0.0:80' '[::]:80'
uhttpd.main.listen_https='0.0.0.0:443' '[::]:443'
uhttpd.main.redirect_https='1'
uhttpd.main.home='/www'
uhttpd.main.rfc1918_filter='1'
uhttpd.main.max_requests='3'
uhttpd.main.max_connections='100'
uhttpd.main.cert='/etc/uhttpd.crt'
uhttpd.main.key='/etc/uhttpd.key'
uhttpd.main.cgi_prefix='/cgi-bin'
uhttpd.main.lua_prefix='/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua'
uhttpd.main.script_timeout='60'
uhttpd.main.network_timeout='30'
uhttpd.main.http_keepalive='20'
uhttpd.main.tcp_keepalive='1'
uhttpd.defaults=cert
uhttpd.defaults.days='730'
uhttpd.defaults.key_type='rsa'
uhttpd.defaults.bits='2048'
uhttpd.defaults.ec_curve='P-256'
uhttpd.defaults.country='ZZ'
uhttpd.defaults.state='Somewhere'
uhttpd.defaults.location='Unknown'
uhttpd.defaults.commonname='OpenWrt'

my uhttpd.lua:

-- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
-- Licensed to the public under the Apache License 2.0.

require "nixio.util"
require "luci.http"
require "luci.sys"
require "luci.dispatcher"
require "luci.ltn12"

function handle_request(env)
	exectime = os.clock()
	local renv = {
		CONTENT_LENGTH  = env.CONTENT_LENGTH,
		CONTENT_TYPE    = env.CONTENT_TYPE,
		REQUEST_METHOD  = env.REQUEST_METHOD,
		REQUEST_URI     = env.REQUEST_URI,
		PATH_INFO	= env.PATH_INFO,
		SCRIPT_NAME     = env.SCRIPT_NAME:gsub("/+$", ""),
		SCRIPT_FILENAME = env.SCRIPT_NAME,
		SERVER_PROTOCOL = env.SERVER_PROTOCOL,
		QUERY_STRING    = env.QUERY_STRING,
		DOCUMENT_ROOT   = env.DOCUMENT_ROOT,
		HTTPS           = env.HTTPS,
		REDIRECT_STATUS = env.REDIRECT_STATUS,
		REMOTE_ADDR     = env.REMOTE_ADDR,
		REMOTE_NAME     = env.REMOTE_NAME,
		REMOTE_PORT     = env.REMOTE_PORT,
		REMOTE_USER     = env.REMOTE_USER,
		SERVER_ADDR     = env.SERVER_ADDR,
		SERVER_NAME     = env.SERVER_NAME,
		SERVER_PORT     = env.SERVER_PORT
	}

	local k, v
	for k, v in pairs(env.headers) do
		k = k:upper():gsub("%-", "_")
		renv["HTTP_" .. k] = v
	end

	local len = tonumber(env.CONTENT_LENGTH) or 0
	local function recv()
		if len > 0 then
			local rlen, rbuf = uhttpd.recv(4096)
			if rlen >= 0 then
				len = len - rlen
				return rbuf
			end
		end
		return nil
	end

	local send = uhttpd.send

	local req = luci.http.Request(
		renv, recv, luci.ltn12.sink.file(io.stderr)
	)


	local x = coroutine.create(luci.dispatcher.httpdispatch)
	local hcache = { }
	local active = true

	while coroutine.status(x) ~= "dead" do
		local res, id, data1, data2 = coroutine.resume(x, req)

		if not res then
			send("Status: 500 Internal Server Error\r\n")
			send("Content-Type: text/plain\r\n\r\n")
			send(tostring(id))
			break
		end

		if active then
			if id == 1 then
				send("Status: ")
				send(tostring(data1))
				send(" ")
				send(tostring(data2))
				send("\r\n")
			elseif id == 2 then
				hcache[data1] = data2
			elseif id == 3 then
				for k, v in pairs(hcache) do
					send(tostring(k))
					send(": ")
					send(tostring(v))
					send("\r\n")
				end
				send("\r\n")
			elseif id == 4 then
				send(tostring(data1 or ""))
			elseif id == 5 then
				active = false
			elseif id == 6 then
				data1:copyz(nixio.stdout, data2)
			end
		end
	end
end

I just spent a long frustrating hour wrestling with this issue, and finally tracked it down: lighttpd was installed (probably as a dependency of some collectd-related package, but I can't figure out which), and it was listening to port 80 in place of uhttpd. Since lighttpd isn't configured by default for Luci's lua scripts, it ends up serving /www/cgi-bin/luci as a download rather than executing it.

The fix is simple: uninstall lighttpd. Then restart uhttpd (either via /etc/init.d/uhttpd restart or just rebooting). Then clear your browser cache - otherwise it'll remember the cached download.

Alternately, you could probably configure Luci to run on lighttpd, but I haven't tried that.

5 Likes

using uhttpd, instead of lighttpd also worked for me.
Thanks @SethML