-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.lua
56 lines (49 loc) · 1.29 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--require "/home/zapotek/workspace/arachni-rpc-lua/connection"
require "connection"
--
-- Arachni RPC Client
--
-- Provides a simple way perform Arachni-RPC calls.
--
ArachniRPCClient = {}
--
-- opts:
-- * host = remote host address -- REQUIRED
-- * port = port number -- REQUIRED
-- * token = authentication token -- OPTIONAL
-- * key = SSL key in PEM format
-- * certificate = SSL cert in PEM format
-- * cafile = CA file in PEM format
--
function ArachniRPCClient:new( opts )
opts = opts or {}
setmetatable( opts, self )
self.__index = self
return opts
end
--
-- Performs a RPC call and returns the result
--
-- @param String method the name of the remote to be called
-- @param Array args arguments for the remote method
--
-- @return Object
---
function ArachniRPCClient:call( method, args )
-- make a copy of the opts in self before passing them on
c_opts = {}
for k, v in pairs( self ) do c_opts[k] = v end
conn = ArachniRPCConnection:new( c_opts )
conn:send_object({
message = method,
args = {args},
token = self.token
})
res = conn:receive_object()
conn:close()
if type( res.obj ) == 'table' and res.obj.exception then
error( res.obj.exception )
else
return res.obj
end
end