X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Flucid-rpc%2Fluasrc%2Flucid%2Frpc%2Fsystem.lua;fp=libs%2Flucid-rpc%2Fluasrc%2Flucid%2Frpc%2Fsystem.lua;h=4f7f0b5c29ceb17a7cbc95f49900b8c7f6921b92;hp=0000000000000000000000000000000000000000;hb=120a7f558e27f2ca11b3dae251528d7100ca259d;hpb=90ce9746c230510f690407b7ccc1330bdca48bbd diff --git a/libs/lucid-rpc/luasrc/lucid/rpc/system.lua b/libs/lucid-rpc/luasrc/lucid/rpc/system.lua new file mode 100644 index 0000000000..4f7f0b5c29 --- /dev/null +++ b/libs/lucid-rpc/luasrc/lucid/rpc/system.lua @@ -0,0 +1,86 @@ +--[[ +LuCI - Lua Development Framework + +Copyright 2009 Steven Barth + +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$ +]] + +local type, ipairs = type, ipairs +local srv = require "luci.lucid.rpc.server" +local nixio = require "nixio" +local lucid = require "luci.lucid" + +module "luci.lucid.rpc.system" + +function _factory() + local mod = srv.Module("System functions"):register({ + echo = echo, + void = void, + multicall = srv.Method.extended(multicall), + authenticate = srv.Method.extended(authenticate) + }) + mod.checkrestricted = function(self, session, request, ...) + if request ~= "authenticate" then + return srv.Module.checkrestricted(self, session, request, ...) + end + end + return mod +end + + +function echo(object) + return object +end + +function void() + +end + +function multicall(session, ...) + local server, responses, response = session.server, {}, nil + for k, req in ipairs({...}) do + response = nil + if type(req) == "table" and type(req.method) == "string" + and (not req.params or type(req.params) == "table") then + req.params = req.params or {} + result = server.root:process(session, req.method, req.params) + if type(result) == "table" then + if req.id ~= nil then + response = {jsonrpc=req.jsonrpc, id=req.id, + result=result.result, error=result.error} + end + else + if req.id ~= nil then + response = {jsonrpc=req.jsonrpc, id=req.id, + result=nil, error={code=srv.ERRNO_INTERNAL, + message=srv.ERRMSG[ERRNO_INTERNAL]}} + end + end + end + responses[k] = response + end + return responses +end + +function authenticate(session, type, entity, key) + if not type then + session.user = nil + return true + elseif type == "plain" then + local pwe = nixio.getsp and nixio.getsp(entity) or nixio.getpw(entity) + local pwh = pwe and (pwe.pwdp or pwe.passwd) + if not pwh or #pwh < 1 or nixio.crypt(key, pwh) ~= pwh then + return nil + else + session.user = entity + return true + end + end +end \ No newline at end of file