2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 module("luci.controller.rpc", package.seeall)
18 local function authenticator(validator, accs)
19 local args = luci.dispatcher.context.args
20 if args and #args > 0 then
21 local user = luci.sauth.read(args[1])
22 if user and luci.util.contains(accs, user) then
26 luci.http.status(403, "Forbidden")
29 uci = entry({"rpc", "uci"}, call("rpc_uci"))
31 uci.sysauth_authenticator = authenticator
34 uci = entry({"rpc", "auth"}, call("rpc_auth"))
38 require "luci.jsonrpc"
41 luci.http.setfilehandler()
46 server.login = function(user, pass)
49 if luci.sys.user.checkpasswd(user, pass) then
50 sid = luci.sys.uniqueid(16)
51 luci.http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
52 luci.sauth.write(sid, user)
58 luci.http.prepare_content("application/json")
59 luci.http.write(luci.jsonrpc.handle(server, luci.http.content()))