2015-05-06 03:53:30 +00:00
|
|
|
var ZeroTierNode = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
address: '----------',
|
|
|
|
online: false,
|
2015-05-07 00:28:11 +00:00
|
|
|
version: '_._._',
|
|
|
|
_networks: [],
|
|
|
|
_peers: []
|
2015-05-06 03:53:30 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-05-07 00:28:11 +00:00
|
|
|
ago: function(ms) {
|
2015-05-07 00:42:29 +00:00
|
|
|
if (ms > 0) {
|
|
|
|
var tmp = Math.round((Date.now() - ms) / 1000);
|
|
|
|
return ((tmp > 0) ? tmp : 0);
|
|
|
|
} else return 0;
|
2015-05-07 00:28:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updatePeers: function() {
|
|
|
|
Ajax.call({
|
|
|
|
url: 'peer?auth='+this.props.authToken,
|
|
|
|
cache: false,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(data) {
|
|
|
|
if (data) {
|
|
|
|
var pl = JSON.parse(data);
|
|
|
|
if (Array.isArray(pl)) {
|
|
|
|
this.setState({_peers: pl});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this),
|
|
|
|
error: function() {
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateNetworks: function() {
|
|
|
|
Ajax.call({
|
|
|
|
url: 'network?auth='+this.props.authToken,
|
|
|
|
cache: false,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(data) {
|
|
|
|
if (data) {
|
|
|
|
var nwl = JSON.parse(data);
|
|
|
|
if (Array.isArray(nwl)) {
|
|
|
|
this.setState({_networks: nwl});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this),
|
|
|
|
error: function() {
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
},
|
2015-05-06 03:53:30 +00:00
|
|
|
updateAll: function() {
|
|
|
|
Ajax.call({
|
|
|
|
url: 'status?auth='+this.props.authToken,
|
|
|
|
cache: false,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(data) {
|
|
|
|
if (data)
|
|
|
|
this.setState(JSON.parse(data));
|
2015-05-07 00:28:11 +00:00
|
|
|
this.updateNetworks();
|
|
|
|
this.updatePeers();
|
2015-05-06 03:53:30 +00:00
|
|
|
}.bind(this),
|
|
|
|
error: function() {
|
2015-05-07 00:28:11 +00:00
|
|
|
this.setState({online: false});
|
2015-05-06 03:53:30 +00:00
|
|
|
}.bind(this)
|
2015-05-07 00:28:11 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
joinNetwork: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
alert('foo');
|
|
|
|
},
|
|
|
|
handleNetworkIdEntry: function(event) {
|
|
|
|
var nid = event.target.value;
|
|
|
|
if (nid) {
|
|
|
|
nid = nid.toLowerCase();
|
|
|
|
var nnid = '';
|
|
|
|
for(var i=0;((i<nid.length)&&(i<16));++i) {
|
|
|
|
if ("0123456789abcdef".indexOf(nid.charAt(i)) >= 0)
|
|
|
|
nnid += nid.charAt(i);
|
|
|
|
}
|
|
|
|
this.networkToJoin = nnid;
|
|
|
|
event.target.value = nnid;
|
|
|
|
} else {
|
|
|
|
this.networkToJoin = '';
|
|
|
|
event.target.value = '';
|
|
|
|
}
|
2015-05-06 03:53:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
2015-05-07 00:28:11 +00:00
|
|
|
this.tabIndex = 0;
|
2015-05-06 03:53:30 +00:00
|
|
|
this.updateAll();
|
2015-05-07 00:42:29 +00:00
|
|
|
this.updateIntervalId = setInterval(this.updateAll,2500);
|
2015-05-06 03:53:30 +00:00
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
2015-05-07 00:28:11 +00:00
|
|
|
clearInterval(this.updateIntervalId);
|
2015-05-06 03:53:30 +00:00
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-05-07 00:28:11 +00:00
|
|
|
<div className="zeroTierNode">
|
|
|
|
<div className="top">
|
|
|
|
<button disabled={this.tabIndex === 0} onClick={function() {this.tabIndex = 0; this.forceUpdate();}.bind(this)}>Networks</button>
|
|
|
|
<button disabled={this.tabIndex === 1} onClick={function() {this.tabIndex = 1; this.forceUpdate();}.bind(this)}>Peers</button>
|
|
|
|
</div>
|
|
|
|
<div className="middle">
|
|
|
|
<div className="middleScroll">
|
|
|
|
{
|
|
|
|
(this.tabIndex === 1) ? (
|
|
|
|
<div className="peers">
|
2015-05-07 00:42:29 +00:00
|
|
|
<div className="peerHeader">
|
|
|
|
<div className="f">Address</div>
|
|
|
|
<div className="f">Version</div>
|
|
|
|
<div className="f">Latency</div>
|
|
|
|
<div className="f">Direct Paths</div>
|
|
|
|
<div className="f">Role</div>
|
2015-05-07 00:28:11 +00:00
|
|
|
</div>
|
|
|
|
{
|
|
|
|
this.state._peers.map(function(peer) {
|
|
|
|
return (
|
|
|
|
<div className="peer">
|
|
|
|
<div className="f zeroTierAddress">{peer['address']}</div>
|
|
|
|
<div className="f">{(peer['version'] === '-1.-1.-1') ? '-' : peer['version']}</div>
|
|
|
|
<div className="f">{peer['latency']}</div>
|
|
|
|
<div className="f">
|
|
|
|
{
|
|
|
|
(peer['paths'].length === 0) ? (
|
|
|
|
<div className="peerPath"><i>(none)</i></div>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
{
|
|
|
|
peer['paths'].map(function(path) {
|
|
|
|
if ((path.active)||(path.fixed)) {
|
|
|
|
return (
|
2015-05-07 00:42:29 +00:00
|
|
|
<div className="peerPath">{path.address} {this.ago(path.lastSend)} {this.ago(path.lastReceive)}{path.preferred ? ' *' : ''}</div>
|
2015-05-07 00:28:11 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div className="peerPathInactive">{path.address} {this.ago(path.lastSend)} {this.ago(path.lastReceive)}</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}.bind(this))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div className="f">{peer['role']}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}.bind(this))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="networks">
|
|
|
|
{
|
|
|
|
this.state._networks.map(function(network) {
|
|
|
|
return React.createElement('div',{className: 'network'},React.createElement(ZeroTierNetwork,network));
|
|
|
|
}.bind(this))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
2015-05-06 03:53:30 +00:00
|
|
|
</div>
|
2015-05-07 00:28:11 +00:00
|
|
|
<div className="bottom">
|
|
|
|
<div className="left">
|
|
|
|
<span className="statusLine"><span className="zeroTierAddress">{this.state.address}</span> {this.state.online ? 'ONLINE' : 'OFFLINE'} {this.state.version}</span>
|
2015-05-06 03:53:30 +00:00
|
|
|
</div>
|
2015-05-07 00:28:11 +00:00
|
|
|
<div className="right">
|
|
|
|
<form onSubmit={this.joinNetwork}><input type="text" placeholder="################" onChange={this.handleNetworkIdEntry} size="16"/><button type="submit">Join</button></form>
|
2015-05-06 03:53:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|