-
Notifications
You must be signed in to change notification settings - Fork 2
/
freerevSDK.js
72 lines (62 loc) · 1.67 KB
/
freerevSDK.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var http = require('http');
var config = require('./config').config;
var querystring = require('querystring');
var conn = require('./conn');
var ddns = require('./ddns');
var _generateToken = require('./token')._generateToken;
var returnError = require('./error');
var freerevAPI = function () {
// BEGIN OF .connect()
function connect(auth, cb) {
if (!auth.login || !auth.passwd) {
return cb(returnError.emptyAuth);
}
var data = querystring.stringify(auth);
var options = {
host: config.host,
port: config.port,
path: '/login.php',
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'content-length': data.length
}
};
var req = http.request(options, function(res) {
if(res.statusCode === 302) {
var cookie = res.headers['set-cookie'];
_generateToken(cookie, function (error, token) {
if(error) {
return cb(error);
}
else {
return cb('', token);
}
});
}
else {
return cb(returnError.wrongAuth);
}
});
req.write(data);
req.end();
};
// END OF .CONNECT
return {
connect: connect,
getStatus: conn.getStatus,
remotePingStatus: conn.remotePingStatus,
changeRemotePing: conn.changeRemotePing,
remoteAccessStatus: conn.remoteAccessStatus,
changeRemoteAccess: conn.changeRemoteAccess,
wakeOnLanStatus: conn.wakeOnLanStatus,
changeWOL: conn.changeWOL,
getLogs: conn.getLogs,
flushLogs: conn.flushLogs,
getDDNS: ddns.getDDNS,
configureDDNS: ddns.configureDDNS
// generateToken: token.generateToken
// _verifyToken: token._verifyToken
};
};
module.exports = freerevAPI();