2 LuCI - Lua Development Framework
4 Copyright 2009 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 local type, ipairs = type, ipairs
16 local srv = require "luci.lucid.rpc.server"
17 local nixio = require "nixio"
18 local lucid = require "luci.lucid"
20 module "luci.lucid.rpc.system"
23 local mod = srv.Module("System functions"):register({
26 multicall = srv.Method.extended(multicall),
27 authenticate = srv.Method.extended(authenticate)
29 mod.checkrestricted = function(self, session, request, ...)
30 if request ~= "authenticate" then
31 return srv.Module.checkrestricted(self, session, request, ...)
46 function multicall(session, ...)
47 local server, responses, response = session.server, {}, nil
48 for k, req in ipairs({...}) do
50 if type(req) == "table" and type(req.method) == "string"
51 and (not req.params or type(req.params) == "table") then
52 req.params = req.params or {}
53 result = server.root:process(session, req.method, req.params)
54 if type(result) == "table" then
56 response = {jsonrpc=req.jsonrpc, id=req.id,
57 result=result.result, error=result.error}
61 response = {jsonrpc=req.jsonrpc, id=req.id,
62 result=nil, error={code=srv.ERRNO_INTERNAL,
63 message=srv.ERRMSG[ERRNO_INTERNAL]}}
67 responses[k] = response
72 function authenticate(session, type, entity, key)
76 elseif type == "plain" then
77 local pwe = nixio.getsp and nixio.getsp(entity) or nixio.getpw(entity)
78 local pwh = pwe and (pwe.pwdp or pwe.passwd)
79 if not pwh or #pwh < 1 or nixio.crypt(key, pwh) ~= pwh then