function index()
local function authenticator(validator, accs)
local auth = luci.http.formvalue("auth", true)
- if auth then
- local user = luci.sauth.read(auth)
- if user and luci.util.contains(accs, user) then
- return user, auth
+ if auth then -- if authentication token was given
+ local sdat = luci.sauth.read(auth)
+ if sdat then -- if given token is valid
+ user = luci.sauth.decode(sdat).user
+ if user and luci.util.contains(accs, user) then
+ return user, auth
+ end
end
end
luci.http.status(403, "Forbidden")
rpc.notemplate = true
entry({"rpc", "uci"}, call("rpc_uci"))
- entry({"rpc", "uvl"}, call("rpc_uvl"))
entry({"rpc", "fs"}, call("rpc_fs"))
entry({"rpc", "sys"}, call("rpc_sys"))
entry({"rpc", "ipkg"}, call("rpc_ipkg"))
secret = sys.uniqueid(16)
http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
- sauth.write(sid, util.get_bytecode({
+ sauth.write(sid, sauth.encode({
user=user,
token=token,
secret=secret
ltn12.pump.all(jsonrpc.handle(uci, http.source()), http.write)
end
-function rpc_uvl()
- if not pcall(require, "luci.uvl") then
- luci.http.status(404, "Not Found")
- return nil
- end
- local uvl = require "luci.jsonrpcbind.uvl"
- local jsonrpc = require "luci.jsonrpc"
- local http = require "luci.http"
- local ltn12 = require "luci.ltn12"
-
- http.prepare_content("application/json")
- ltn12.pump.all(jsonrpc.handle(uvl, http.source()), http.write)
-end
-
function rpc_fs()
local util = require "luci.util"
local io = require "io"
- local fs2 = util.clone(require "luci.fs")
+ local fs2 = util.clone(require "nixio.fs")
local jsonrpc = require "luci.jsonrpc"
local http = require "luci.http"
local ltn12 = require "luci.ltn12"