summaryrefslogtreecommitdiffhomepage
path: root/libs/sgi-webuci/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/sgi-webuci/luasrc
parent92d76ed83603e50321f171996fc78cef0a6d3580 (diff)
* Added native basic authentication support
* Cleanups
Diffstat (limited to 'libs/sgi-webuci/luasrc')
-rw-r--r--libs/sgi-webuci/luasrc/sgi/webuci.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/libs/sgi-webuci/luasrc/sgi/webuci.lua b/libs/sgi-webuci/luasrc/sgi/webuci.lua
index 2beff6907..1ad067c6b 100644
--- a/libs/sgi-webuci/luasrc/sgi/webuci.lua
+++ b/libs/sgi-webuci/luasrc/sgi/webuci.lua
@@ -33,6 +33,21 @@ function initenv(env, vars)
luci.http.vars = vars
end
+-- Enforces user authentification
+function luci.http.basic_auth(verify_callback, realm)
+ local user = luci.http.env.auth_user
+ local pass = luci.http.env.auth_password
+ realm = realm or ""
+
+ if not user or not verify_callback(user, pass) then
+ luci.http.status("401", "Unauthorized")
+ luci.http.header("WWW-Authenticate", string.format('Basic realm="%s"', realm))
+ return false
+ else
+ return true
+ end
+end
+
-- Returns the main dispatcher URL
function luci.http.dispatcher()
return luci.http.env.SCRIPT_NAME or ""