forked from kd7lxl/mtr-web
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.v2.html
153 lines (143 loc) · 4.77 KB
/
index.v2.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html ng-app="MtrApp">
<head>
<meta charset="utf-8" />
<title>Websocket-based interface to MTR</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<style type="text/css">
.table-very-condensed {
margin-bottom: 0;
}
.table-very-condensed > tbody > tr > th {
font-size: smaller;
vertical-align: middle;
color: #777;
white-space: nowrap;
padding: 2px 5px;
}
.table-very-condensed > tbody > tr > td {
padding: 2px 5px;
}
.table-very-condensed > tbody > tr > td:first-child {
text-align: right;
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="https://cdn.rawgit.com/AngularClass/angular-websocket/v2.0.0/dist/angular-websocket.min.js"></script>
<section ng-controller="SomeController">
<form class="form-inline" ng-submit="submit(hostname, protocol, version, dns)">
<table class="table table-very-condensed">
<tr>
<th> </th>
<th>
<input type='text' class="form-control" id="wsaddr" placeholder="Type websocket address here." ng-model="wsaddr" style="width:100%;">
</th>
<th>
<input type="text" class="form-control" id="hostname" placeholder="Type hostname here." ng-model="hostname" style="width:100%;" autofocus required>
</th>
<th colspan="6">
<select class="form-control" ng-model="protocol">
<option value="ICMP" selected>ICMP</option>
<option value="TCP">TCP SYN</option>
<option value="UDP">UDP</option>
</select>
<select class="form-control" ng-model="version">
<option value="" selected>IPv4 or IPv6</option>
<option value="4">IPv4</option>
<option value="6">IPv6</option>
</select>
<label class="checkbox-inline">
<input type="checkbox" value="dns" ng-model="dns" > Use DNS
</label>
<button type="submit" class="btn btn-default">Trace</button>
</th>
</tr>
<tr>
<th> </th>
<th>Hostname</th>
<th>Loss</th>
<th>Received</th>
<th>Sent</th>
<th>Last/Cur</th>
<th>Avg</th>
<th>Min/Best</th>
<th>Max/Worst</th>
<th>stdev</th>
<th>gmean</th>
<th>jitter</th>
<th>javg</th>
<th>jworst</th>
<th>jinta</th>
</tr>
<tr ng-repeat="line in mtr.response track by $index|orderBy:'0'">
<td ng-repeat="col in line track by $index">{{ col }}</td>
</tr>
</table>
</form>
</section>
<script>
var godArray = new Array(300);
var godAlt = [];
var godCounter = 0;
var dLast = 0;
angular.module('MtrApp', ['ngWebSocket'])
.factory('mtr', function($websocket) {
var response = new Array(30);
var ws = {close: function(message) {}};
var methods = {
response: response,
trace: function(message) {
ws.close();
for (var i=0; i<response.length; i++) {
response[i] = [];
}
ws = $websocket('ws://' + document.getElementById('wsaddr').value);
//var url = new URL(window.location.href);
//url.protocol = url.protocol.replace('http', 'ws');
//url.href = url.href + "mtr"
//ws = $websocket(url.href);
//console.log("log: ws " + ws);
console.log("log: wsaddr " + document.getElementById('wsaddr').value);
ws.onMessage(function(message) {
var data = JSON.parse(message.data);
//a bit hacky. if packets are not in order this will break
if (data[0] < dLast) {
godCounter++;
dLast = 0;
} else {
dLast++;
}
if (angular.isArray(data)) {
response[data[0]] = data;
godArray[godCounter, data[0]] = data;
godAlt[godCounter, data[0]] = data;
} else {
// error message
response[0] = [0, data];
}
});
ws.send(message);
}
};
return methods;
})
.controller('SomeController', function($scope, mtr) {
$scope.mtr = mtr;
$scope.protocol = 'ICMP';
$scope.version = '4';
$scope.dns = false;
$scope.submit = function(hostname, protocol, version, dns) {
// if (!hostname) { return; }
mtr.trace(JSON.stringify({
hostname: hostname,
protocol: protocol,
version: version,
no_dns: !dns
}));
};
});
</script>
</body>
</html>