-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
522 lines (468 loc) · 14.1 KB
/
app.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
'use strict'
// Disclaimer: this code is quite messy, and will need a rewrite sometime
// read at your own risk ;)
const React = require('react')
const ReactDOM = require('react-dom')
const create = require('create-react-class')
const Promise = require('bluebird')
const rfetch = require('fetch-retry')
const urllib = require('url')
const icons = require('./icons.js')
let apiUrl = urllib.parse("https://federationtester.matrix.org/api/report")
let options = {retries: 5, retryDelay: 200}
let App = create({
displayName: "App",
getInitialState: function() {
return({
json: undefined
})
},
componentDidMount: function() {
setTimeout(() => {
if (window.location.hash) {
var hash = window.location.hash.substring(1)
this.state.ref.value = hash
this.submit()
}
}, 100)
},
setRef: function(e) {
if (e == null) {
return
}
e.addEventListener('keydown', (e) => {
if (e.keyCode == 13) {
this.submit()
}
})
e.focus()
this.setState({
ref: e
})
},
submit: function() {
window.location.hash = this.state.ref.value.toLowerCase();
let url = Object.assign(apiUrl, {
query: {
server_name: this.state.ref.value.toLowerCase()
}
})
this.setState({
loading: true,
json: undefined
})
console.log("Querying API", urllib.format(url))
rfetch(urllib.format(url), options)
.then((res) => res.json())
.then((json) => {
// The tldr block will be displayed before the full table
let tldr = []
Object.keys(json.ConnectionReports).forEach((ip) => {
let report = json.ConnectionReports[ip]
if (!report.Checks.ValidCertificates) {
tldr.push(<div className="warning" key={`cert-${tldr.length}`}>
WARN: Could not find a valid certificate for {ip}.
See <a href="https://github.com/matrix-org/synapse/blob/master/docs/MSC1711_certificates_FAQ.md#configuring-certificates-for-compatibility-with-synapse-100">this
documentation</a> for instructions on how to fix this.
</div>)
}
json.ConnectionReports[ip].Errors.forEach((err) => {
let msg = err.Message
// Found an error
tldr.push(<div className="error" key={`${msg}-${tldr.length}`}>
ERROR: on {ip}: {msg}
</div>)
})
})
if (Object.values(json.ConnectionReports).some(e=>!e.Checks.MatchingServerName)) {
tldr.push(
<div className="warning" key={`servername-${tldr.length}`}>
It is possible that the MatchingServerName error below is
caused by you entering the wrong URL in the federation tester,
not because there is an actual issue with your federation.
You should enter the server name into the Federation Tester,
not the location where your server is. The server name is the
public facing name of your server that appears at the end of
usernames and room aliases.
</div>
)
}
this.setState({
json: json,
tldr: tldr,
loading: false
})
})
},
render: function() {
let result
let errors
let active = ""
if (this.state.loading) {
active = " active";
}
if (this.state.json != undefined) {
// Display server version information
const serverVersion = this.state.json.Version;
let version;
if (serverVersion == undefined) {
version = "This homeserver does not supply version information"
} else if (serverVersion.error != undefined) {
version = `There was an error looking up homeserver version information: ${serverVersion.error}`;
} else {
version = `Homeserver version: ${serverVersion.name} ${serverVersion.version}`;
}
let reportCount = Object.keys(this.state.json.ConnectionReports).length
result = <>
Got {reportCount} connection report{reportCount > 1 && <>s</>}.
{reportCount == 0 && <> This usually means at least one error happened.</>}
{reportCount > 0 &&
<div className="serverVersion">
<p>{version}</p>
</div>
}
<div className="tldr">
{this.state.tldr}
</div>
<TestResults json={this.state.json}/>
</>
}
return (
<div className="block">
<div className="text">
The Matrix Federation Tester can help debug your Matrix instance.<br />
Enter your server name in the field below, then hit "Go" to get your report.<br/><br/>
Made with love by <a href="https://f.0x52.eu">f0x</a>, sourcecode <a href="https://github.com/matrix-org/fed-tester-ui">here</a>, powered by the <a href="https://github.com/matrix-org/matrix-federation-tester">matrix-federation-tester</a> backend <br/>
<a href="https://liberapay.com/f0x/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"/></a>
</div>
<div className="input">
<input ref={this.setRef} placeholder="servername.com"/>
<div className={"sk-cube-grid" + active} onClick={this.submit}>
<span>Go</span>
<div className="sk-cube sk-cube1"></div>
<div className="sk-cube sk-cube2"></div>
<div className="sk-cube sk-cube3"></div>
<div className="sk-cube sk-cube4"></div>
<div className="sk-cube sk-cube5"></div>
<div className="sk-cube sk-cube6"></div>
<div className="sk-cube sk-cube7"></div>
<div className="sk-cube sk-cube8"></div>
<div className="sk-cube sk-cube9"></div>
</div>
</div>
{result}
{errors}
</div>
)
}
})
let TestResults = create({
displayName: "TestResults",
render: function() {
return (
<div className="results">
<ConnectionErrors json={this.props.json.ConnectionErrors}/>
<ConnectionReports json={this.props.json.ConnectionReports}/>
<DNSResult json={this.props.json.DNSResult}/>
<API/>
</div>
);
}
})
let ConnectionReports = create({
displayName: "ConnectionErrors",
render: function() {
let j = this.props.json;
if (Object.keys(j).length == 0) {
return null;
}
let connections = Object.keys(j).map((ip, id) => {
let info = j[ip];
return <ReportTable info={info} key={id} ip={ip}/>;
});
return (
<div className="connection">
<h2>Connection Reports</h2>
{connections}
</div>
);
}
});
let ConnectionErrors = create({
displayName: "ConnectionErrors",
render: function() {
let j = this.props.json;
if (Object.keys(j).length == 0) {
return null;
}
let connections = Object.keys(j).map((ip, id) => {
let info = j[ip];
if (info.Message != null) {
return info.Message;
}
return <ReportTable info={info} key={id} ip={ip}/>;
});
return (
<div className="connection err">
<h2>Connection Errors</h2>
{connections}
</div>
);
}
});
let ReportTable = create({
displayName: "ReportTable",
getInitialState: function() {
return ({
collapsed: {
info: true,
checks: this.props.info.Checks.AllChecksOK
}
});
},
toggle: function(element) {
let collapsed = this.state.collapsed
collapsed[element] = !collapsed[element]
this.setState({
collapsed: collapsed
});
},
render: function() {
let checks = <TableFromObject object={this.props.info.Checks} collapsed={this.state.collapsed.checks} tree={1} type="error" />;
let checksIcon = icons.right;
let falseRow = {
symbol: "Error",
className: "false"
}
let trueRow = {
symbol: "Success",
className: "true"
}
let rows = {
checks: falseRow,
cert: {
symbol: "Warning",
className: "warn"
}
}
if (!this.state.collapsed["checks"]) {
checksIcon = icons.down;
}
if (this.props.info.Checks.AllChecksOK) {
rows.checks = trueRow
}
if (this.props.info.Checks.ValidCertificates) {
rows.cert = trueRow
}
return (
<div>
<h3>{this.props.ip}</h3>
<div className="table">
<div className="body">
<div className="row toggle" onClick={() => this.toggle("checks")}>
{checksIcon}
<div className="col">Checks</div>
<div className={"col bool " + rows.checks.className}>{rows.checks.symbol}</div>
</div>
{checks}
</div>
</div>
</div>
);
}
});
function recursiveCheck(objectOrBool, path, bubble) {
if (typeof objectOrBool == typeof true) {
if (!objectOrBool) {
if (bubble) {
bubble(path)
}
return true
}
} else {
let anyErrors
Object.keys(objectOrBool).forEach((childKey) => {
let childValue = objectOrBool[childKey]
if (recursiveCheck(childValue, path + `.${childKey}`, bubble)) {
anyErrors = true
}
})
if (anyErrors) {
return true
}
}
}
let TableFromObject = create({
displayName: "TableFromObject",
getInitialState: function() {
return ({
collapsed: this.props.collapsed
});
},
toggle: function() {
let collapsed = this.state.collapsed;
if (collapsed) {
collapsed = false;
} else {
collapsed = true;
}
this.setState({
collapsed: collapsed
});
},
render: function() {
let objectArray = Object.keys(this.props.object);
return objectArray.map((check, id) => {
let symbol
let className
if (this.props.type == "error") {
symbol = "Error";
className = "false";
if (this.props.object[check]) {
symbol = "Success";
className = "true";
}
}
if (check == "AllChecksOK") {
return null;
} else if (!this.props.collapsed) {
if (typeof(this.props.object[check]) == "boolean") {
return (
<div className={`row tree-${this.props.tree} ${this.props.type}Row`} key={id}>
<div className="col">{check}</div>
<div className={"col bool " + className}>{symbol}</div>
</div>
);
} else {
let childrenBool = "true"
let childrenSymbol = "Success"
if (recursiveCheck(this.props.object[check], "Checks")) {
//will return true if any children are false
childrenBool = "false"
childrenSymbol = "Error"
}
return (
<div key={id}>
<div className={"row tree-" + this.props.tree} onClick={this.toggle}>
<div className="col">{check}</div>
<div className={"col bool " + childrenBool}>{childrenSymbol}</div>
</div>
<TableFromObject object={this.props.object[check]} collapsed={false} key={id} tree={this.props.tree+1} />
</div>
);
}
}
return null;
});
}
});
let DNSResult = create({
displayName: "DNS",
render: function() {
const j = this.props.json;
const srvRecordsTable = function() {
if (j.SRVSkipped) {
return <p>server name/.well-known result contains explicit port number: no SRV lookup done</p>;
} else if (j.SRVRecords == null) {
return <p>No SRV records found</p>;
} else {
const recordRows = j.SRVRecords.map((record, id) => {
return (
<div className="row" key={id}>
<div className="col">{record.Target}</div>
<div className="col">{record.Port}</div>
<div className="col">{record.Priority}</div>
<div className="col">{record.Weight}</div>
</div>
);
});
return (
<>
<h3>DNS records for {j.SRVCName}</h3>
<div className="table">
<div className="header">
<span className="col">Target</span>
<span className="col">Port</span>
<span className="col">Priority</span>
<span className="col">Weight</span>
</div>
<div className="body">
{recordRows}
</div>
</div>
</>
);
}
}();
const hosts = j.Hosts ? Object.keys(j.Hosts).map((host) => {
const addressTable = function() {
const addresses = function() {
if (j.Hosts[host].Addrs != null) {
return j.Hosts[host].Addrs.map((address, id) => {
return (
<div className="row" key={id}>
<div className="col">{address}</div>
</div>
);
});
}
}();
return (<>
<div className="head">
Addresses
</div>
<div className="body">
{addresses}
</div>
</>);
}();
const errorTable = function() {
if (j.Hosts[host].Error != null) {
return (<>
<div className="head error">
Errors
</div>
<div className="body error">
<div className="row" key={host}>
<div className="col">{j.Hosts[host].Error.Message}</div>
</div>
</div>
</>);
}
}();
return (
<>
<h4>{host}</h4>
<div className="table">
{addressTable}
</div>
<div className="table">
{errorTable}
</div>
</>
);
}) : null;
return (
<div className="dns">
<h2>DNS results</h2>
{srvRecordsTable}
<h3>Hosts</h3>
{hosts}
</div>
);
}
});
let API = create({
displayName: "API",
render: function() {
return (
<div className="apiLink">
View the <a href={urllib.format(apiUrl)}>json report</a>.
</div>
);
}
});
ReactDOM.render(
<App />,
document.getElementById('root')
)