summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-rpc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-01-15 10:55:53 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-15 11:09:05 +0100
commit199c8cbc4c32506ecfe89850615b88a3f0276dd3 (patch)
tree8f42aed92f92eba67898c0ce6bd5464a04986967 /modules/luci-mod-rpc
parenteb8560061ab2aed5c0f2ce2ca9fa0fe28fa89af4 (diff)
luci-base: switch to ubus sessions
Remove luci.sauth session storage implementation and offload the session management to the rpcd ubus backend. Also depend on rpcd due to this.
Diffstat (limited to 'modules/luci-mod-rpc')
-rw-r--r--modules/luci-mod-rpc/luasrc/controller/rpc.lua30
1 files changed, 17 insertions, 13 deletions
diff --git a/modules/luci-mod-rpc/luasrc/controller/rpc.lua b/modules/luci-mod-rpc/luasrc/controller/rpc.lua
index 359184c74..92947168e 100644
--- a/modules/luci-mod-rpc/luasrc/controller/rpc.lua
+++ b/modules/luci-mod-rpc/luasrc/controller/rpc.lua
@@ -25,7 +25,7 @@ function index()
local function authenticator(validator, accs)
local auth = luci.http.formvalue("auth", true)
if auth then -- if authentication token was given
- local sdat = luci.sauth.read(auth)
+ local sdat = (luci.util.ubus("session", "get", { ubus_rpc_session = auth }) or { }).values
if sdat then -- if given token is valid
if sdat.user and luci.util.contains(accs, sdat.user) then
return sdat.user, auth
@@ -49,7 +49,6 @@ end
function rpc_auth()
local jsonrpc = require "luci.jsonrpc"
- local sauth = require "luci.sauth"
local http = require "luci.http"
local sys = require "luci.sys"
local ltn12 = require "luci.ltn12"
@@ -62,17 +61,22 @@ function rpc_auth()
local sid, token, secret
if sys.user.checkpasswd(user, pass) then
- sid = sys.uniqueid(16)
- token = sys.uniqueid(16)
- secret = sys.uniqueid(16)
-
- http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
- sauth.reap()
- sauth.write(sid, {
- user=user,
- token=token,
- secret=secret
- })
+ local sdat = util.ubus("session", "create", { timeout = luci.config.sauth.sessiontime })
+ if sdat then
+ sid = sdat.ubus_rpc_session
+ token = sys.uniqueid(16)
+ secret = sys.uniqueid(16)
+
+ http.header("Set-Cookie", "sysauth="..sid.."; path=/")
+ util.ubus("session", "set", {
+ ubus_rpc_session = sid,
+ values = {
+ user = user,
+ token = token,
+ secret = secret
+ }
+ })
+ end
end
return sid and {sid=sid, token=token, secret=secret}