summaryrefslogtreecommitdiffhomepage
path: root/libs/lucid-rpc/luasrc/lucid/rpc/system.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-06-13 08:56:43 +0000
committerSteven Barth <steven@midlink.org>2009-06-13 08:56:43 +0000
commit120a7f558e27f2ca11b3dae251528d7100ca259d (patch)
treecbf5421d6bcd30da4e094a95ab8c7a3a3e2e15a7 /libs/lucid-rpc/luasrc/lucid/rpc/system.lua
parent90ce9746c230510f690407b7ccc1330bdca48bbd (diff)
GSoC: Add LuCId RPC-Slave
Diffstat (limited to 'libs/lucid-rpc/luasrc/lucid/rpc/system.lua')
-rw-r--r--libs/lucid-rpc/luasrc/lucid/rpc/system.lua86
1 files changed, 86 insertions, 0 deletions
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 <steven@midlink.org>
+
+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