forked from snoopysecurity/dvws-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc_server.js
48 lines (36 loc) · 1.38 KB
/
rpc_server.js
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
var xmlrpc = require('xmlrpc');
var needle = require('needle');
// Creates an XML-RPC server to listen to XML-RPC method calls
var server = xmlrpc.createServer({ port: 9090, path: '/xmlrpc' })
// Handle methods not found
server.on('NotFound', function (method, params) {
console.log('Method ' + method + ' does not exist');
})
// Handle method calls by listening for events with the method call name
server.on('dvws.RpcVersion', function (err, params, callback) {
callback(null, '1.3.2')
})
server.on('system.listMethods', function (err, params, callback) {
let methodarray = ['system.listMethods', 'dvws.rpcversion', 'dvws.checkuptime, pingback.ping'];
callback(null, methodarray)
})
server.on('pingback.ping', function (err, params, callback) {
callback(null, 'Method Disabled')
})
server.on('dvws.CheckUptime', function (err, params, callback) {
module.exports.get = function (url) {
var result = needle.get(url, { timeout: 3000 }, function (error, response) {
if (!error && response.statusCode == 200) {
console.log('Method call params for \'checkuptime\': ' + url)
var rp = response.body
}
return rp;
});
return result;
}
var get_result = module.exports.get(params.toString());
// ...perform an action...
// Send a method response with a value
callback(null, get_result)
})
console.log('XML-RPC server listening on port 9090')