mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-22 14:22:23 +00:00
.
This commit is contained in:
parent
a187d290f1
commit
c9fd8de007
@ -17,9 +17,47 @@ ZT1ControllerClient.prototype.status = function(callback)
|
|||||||
'X-ZT1-Auth': this.authToken
|
'X-ZT1-Auth': this.authToken
|
||||||
}
|
}
|
||||||
},function(error,response,body) {
|
},function(error,response,body) {
|
||||||
if ((error)||(response.statusCode !== 200))
|
if (error)
|
||||||
return callback(error,{});
|
return callback(error,{});
|
||||||
return callback(null,JSON.parse(body));
|
if (response.statusCode !== 200)
|
||||||
|
return callback(new Error('server responded with '+response.statusCode),{});
|
||||||
|
var controllerStatus = JSON.parse(body);
|
||||||
|
if (controllerStatus.controller === true) {
|
||||||
|
request({
|
||||||
|
url: this.url + 'status',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'X-ZT1-Auth': this.authToken
|
||||||
|
}
|
||||||
|
},function(error,response,body) {
|
||||||
|
if (error)
|
||||||
|
return callback(error,{});
|
||||||
|
if (response.statusCode !== 200)
|
||||||
|
return callback(new Error('server responded with '+response.statusCode),{});
|
||||||
|
var nodeStatus = JSON.parse(body);
|
||||||
|
for(var k in controllerStatus)
|
||||||
|
nodeStatus[k] = controllerStatus[k];
|
||||||
|
return callback(null,nodeStatus);
|
||||||
|
}.bind(this));
|
||||||
|
} else return callback(new Error('No "controller==true" test value present.'),{});
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
ZT1ControllerClient.prototype.listNetworks = function(callback)
|
||||||
|
{
|
||||||
|
request({
|
||||||
|
url: this.url + 'controller/network',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'X-ZT1-Auth': this.authToken
|
||||||
|
}
|
||||||
|
},function(error,response,body) {
|
||||||
|
if (error)
|
||||||
|
return callback(error,{});
|
||||||
|
if (response.statusCode !== 200)
|
||||||
|
return callback(new Error('server responded with '+response.statusCode),{});
|
||||||
|
var r = JSON.parse(body);
|
||||||
|
return callback(null,Array.isArray(r) ? r : []);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,5 +3,12 @@ var ZT1ControllerClient = require('./index.js').ZT1ControllerClient;
|
|||||||
var zt1c = new ZT1ControllerClient('http://127.0.0.1:9993/','5d6181b71fae2684f9cc64ed');
|
var zt1c = new ZT1ControllerClient('http://127.0.0.1:9993/','5d6181b71fae2684f9cc64ed');
|
||||||
|
|
||||||
zt1c.status(function(err,status) {
|
zt1c.status(function(err,status) {
|
||||||
|
if (err)
|
||||||
|
console.log(err);
|
||||||
console.log(status);
|
console.log(status);
|
||||||
|
zt1c.listNetworks(function(err,networks) {
|
||||||
|
if (err)
|
||||||
|
console.log(err);
|
||||||
|
console.log(networks);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user