summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-02 17:49:27 +0000
committerSteven Barth <steven@midlink.org>2008-06-02 17:49:27 +0000
commitf56890a5733b3c57d088b52bf91a77c44976ca99 (patch)
treee835d0e242cf957bc8b0d0cce1eb5551c3d4a321 /libs/web/luasrc
parent92d76ed83603e50321f171996fc78cef0a6d3580 (diff)
* Added native basic authentication support
* Cleanups
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r--libs/web/luasrc/dispatcher.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index feda28d51..cd481622b 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -58,6 +58,18 @@ function build_url(...)
return luci.http.dispatcher() .. "/" .. table.concat(arg, "/")
end
+-- Prints an error message or renders the "error401" template if available
+function error401(message)
+ message = message or "Unauthorized"
+
+ require("luci.template")
+ if not pcall(luci.template.render, "error401") then
+ luci.http.prepare_content("text/plain")
+ print(message)
+ end
+ return false
+end
+
-- Sends a 404 error code and renders the "error404" template if available
function error404(message)
luci.http.status(404, "Not Found")
@@ -115,6 +127,20 @@ function dispatch()
end
end
+ if track.sysauth then
+ local accs = track.sysauth
+ accs = (type(accs) == "string") and {accs} or accs
+
+ local function sysauth(user, password)
+ return (luci.util.contains(accs, user)
+ and luci.sys.user.checkpasswd(user, password))
+ end
+
+ if not luci.http.basic_auth(sysauth) then
+ error401()
+ return
+ end
+ end
if track.i18n then
require("luci.i18n").loadc(track.i18n)