mirror of https://git.openwrt.org/project/luci.git
modules/rpc: adapt rpc controller to sauth api changes
This commit is contained in:
parent
7bca24db1b
commit
c8ffc897e3
|
@ -27,20 +27,19 @@ function index()
|
||||||
if auth then -- if authentication token was given
|
if auth then -- if authentication token was given
|
||||||
local sdat = luci.sauth.read(auth)
|
local sdat = luci.sauth.read(auth)
|
||||||
if sdat then -- if given token is valid
|
if sdat then -- if given token is valid
|
||||||
user = luci.sauth.decode(sdat).user
|
if sdat.user and luci.util.contains(accs, sdat.user) then
|
||||||
if user and luci.util.contains(accs, user) then
|
return sdat.user, auth
|
||||||
return user, auth
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
luci.http.status(403, "Forbidden")
|
luci.http.status(403, "Forbidden")
|
||||||
end
|
end
|
||||||
|
|
||||||
local rpc = node("rpc")
|
local rpc = node("rpc")
|
||||||
rpc.sysauth = "root"
|
rpc.sysauth = "root"
|
||||||
rpc.sysauth_authenticator = authenticator
|
rpc.sysauth_authenticator = authenticator
|
||||||
rpc.notemplate = true
|
rpc.notemplate = true
|
||||||
|
|
||||||
entry({"rpc", "uci"}, call("rpc_uci"))
|
entry({"rpc", "uci"}, call("rpc_uci"))
|
||||||
entry({"rpc", "fs"}, call("rpc_fs"))
|
entry({"rpc", "fs"}, call("rpc_fs"))
|
||||||
entry({"rpc", "sys"}, call("rpc_sys"))
|
entry({"rpc", "sys"}, call("rpc_sys"))
|
||||||
|
@ -55,9 +54,9 @@ function rpc_auth()
|
||||||
local sys = require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
local ltn12 = require "luci.ltn12"
|
local ltn12 = require "luci.ltn12"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
|
|
||||||
local loginstat
|
local loginstat
|
||||||
|
|
||||||
local server = {}
|
local server = {}
|
||||||
server.challenge = function(user, pass)
|
server.challenge = function(user, pass)
|
||||||
local sid, token, secret
|
local sid, token, secret
|
||||||
|
@ -68,13 +67,14 @@ function rpc_auth()
|
||||||
secret = sys.uniqueid(16)
|
secret = sys.uniqueid(16)
|
||||||
|
|
||||||
http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
|
http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
|
||||||
sauth.write(sid, sauth.encode({
|
sauth.reap()
|
||||||
|
sauth.write(sid, {
|
||||||
user=user,
|
user=user,
|
||||||
token=token,
|
token=token,
|
||||||
secret=secret
|
secret=secret
|
||||||
}))
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return sid and {sid=sid, token=token, secret=secret}
|
return sid and {sid=sid, token=token, secret=secret}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ function rpc_auth()
|
||||||
local challenge = server.challenge(...)
|
local challenge = server.challenge(...)
|
||||||
return challenge and challenge.sid
|
return challenge and challenge.sid
|
||||||
end
|
end
|
||||||
|
|
||||||
http.prepare_content("application/json")
|
http.prepare_content("application/json")
|
||||||
ltn12.pump.all(jsonrpc.handle(server, http.source()), http.write)
|
ltn12.pump.all(jsonrpc.handle(server, http.source()), http.write)
|
||||||
end
|
end
|
||||||
|
@ -96,7 +96,7 @@ function rpc_uci()
|
||||||
local jsonrpc = require "luci.jsonrpc"
|
local jsonrpc = require "luci.jsonrpc"
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
local ltn12 = require "luci.ltn12"
|
local ltn12 = require "luci.ltn12"
|
||||||
|
|
||||||
http.prepare_content("application/json")
|
http.prepare_content("application/json")
|
||||||
ltn12.pump.all(jsonrpc.handle(uci, http.source()), http.write)
|
ltn12.pump.all(jsonrpc.handle(uci, http.source()), http.write)
|
||||||
end
|
end
|
||||||
|
@ -125,7 +125,7 @@ function rpc_fs()
|
||||||
local source = ltn12.source.chain(ltn12.source.file(fp), mime.encode("base64"))
|
local source = ltn12.source.chain(ltn12.source.file(fp), mime.encode("base64"))
|
||||||
return ltn12.pump.all(source, sink) and table.concat(output)
|
return ltn12.pump.all(source, sink) and table.concat(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs2.writefile(filename, data)
|
function fs2.writefile(filename, data)
|
||||||
local stat, mime = pcall(require, "mime")
|
local stat, mime = pcall(require, "mime")
|
||||||
if not stat then
|
if not stat then
|
||||||
|
@ -136,7 +136,7 @@ function rpc_fs()
|
||||||
local sink = file and ltn12.sink.chain(mime.decode("base64"), ltn12.sink.file(file))
|
local sink = file and ltn12.sink.chain(mime.decode("base64"), ltn12.sink.file(file))
|
||||||
return sink and ltn12.pump.all(ltn12.source.string(data), sink) or false
|
return sink and ltn12.pump.all(ltn12.source.string(data), sink) or false
|
||||||
end
|
end
|
||||||
|
|
||||||
http.prepare_content("application/json")
|
http.prepare_content("application/json")
|
||||||
ltn12.pump.all(jsonrpc.handle(fs2, http.source()), http.write)
|
ltn12.pump.all(jsonrpc.handle(fs2, http.source()), http.write)
|
||||||
end
|
end
|
||||||
|
@ -146,7 +146,7 @@ function rpc_sys()
|
||||||
local jsonrpc = require "luci.jsonrpc"
|
local jsonrpc = require "luci.jsonrpc"
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
local ltn12 = require "luci.ltn12"
|
local ltn12 = require "luci.ltn12"
|
||||||
|
|
||||||
http.prepare_content("application/json")
|
http.prepare_content("application/json")
|
||||||
ltn12.pump.all(jsonrpc.handle(sys, http.source()), http.write)
|
ltn12.pump.all(jsonrpc.handle(sys, http.source()), http.write)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue