X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Fluci-mod-rpc%2Fluasrc%2Fcontroller%2Frpc.lua;h=0051571701f0582f27f84c5e7bfbf6c04ef36053;hb=16047d03c54df4474cb675a9ce98d06aad5a656b;hp=359184c744c11e1e6eb992fcb6acd5cc3b135c36;hpb=1bb4822dca6113f73e3bc89e2acf15935e6f8e92;p=project%2Fluci.git diff --git a/modules/luci-mod-rpc/luasrc/controller/rpc.lua b/modules/luci-mod-rpc/luasrc/controller/rpc.lua index 359184c74..005157170 100644 --- a/modules/luci-mod-rpc/luasrc/controller/rpc.lua +++ b/modules/luci-mod-rpc/luasrc/controller/rpc.lua @@ -1,17 +1,6 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ -]]-- +-- Copyright 2008 Steven Barth +-- Copyright 2008 Jo-Philipp Wich +-- Licensed to the public under the Apache License 2.0. local require = require local pairs = pairs @@ -25,7 +14,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,12 +38,13 @@ 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" local util = require "luci.util" + require "luci.config" + local loginstat local server = {} @@ -62,17 +52,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}