-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathindex.html
More file actions
295 lines (258 loc) · 8.62 KB
/
index.html
File metadata and controls
295 lines (258 loc) · 8.62 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Fingertip</title>
<style>
body {
font-size: 16px;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
}
h1 {
color: #444444;
}
.c {
max-width: 600px;
margin: 2em auto 0;
}
.step {
background: #0e0e0e;
color: #fff;
width: 1.5em;
height: 1.5em;
display: inline-block;
text-align: center;
line-height: 1.5em;
border-radius: 1.5em;
padding: 0.2em;
margin-right: 0.5em;
font-size: 0.8em;
}
.btn {
background-color: #464646;
color: #fff;
border: none;
border-radius: 4px;
padding: 0.8em 1.2em;
font-size: 0.8em;
margin-left: 0.1em;
text-decoration: none;
}
a {
text-decoration: none;
}
.navbar {
border-radius: 4px;
background-color: #333333;
display: flex;
align-items: center;
font-size: 12px;
}
.navbar a {
color: #e7e7e7;
}
.navbar ul {
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
align-items: center;
}
.navbar ul li a {
color: #e7e7e7;
padding: 1em;
display: block;
}
.navbar ul li:nth-child(1) a {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.navbar ul a:hover,
.navbar ul a:focus,
.navbar ul .active {
background-color: #272727;
}
tr {
height: 2em;
}
table {
margin-top: 1em;
width: 100%;
background-color: #fdfdfd;
border: 1px solid #e5e5e5;
border-radius: 4px;
padding: 1em;
}
.success {
color: green;
font-weight: 600;
}
.error {
color: red;
font-weight: 600;
}
.warning {
color: orange;
font-weight: 600;
}
td:nth-child(1) {
padding-left: 0.84em;
}
td:nth-child(2) {
width: 140px;
}
</style>
</head>
<body>
<div class="c">
<h1>Fingertip</h1>
<nav class="navbar">
<ul>
<li>
<a class="active" href="{{.NavStatusLink}}">Status</a>
</li>
<li>
<a href="{{.NavSetupLink}}">Manual Setup</a>
</li>
</ul>
</nav>
<p class="firefox" style="display: none;padding:0.5em">Tip: You may need to quit Firefox completely and restart for the certificate settings to apply
(Right click on the Firefox icon in the dock and click quit)</p>
<table>
<tbody>
<tr>
<td>Handshake Resolver Status</td>
<td data-key="resolverStatus"><span class="warning">Syncing ...</span></td>
</tr>
<tr>
<td>Block height</td>
<td data-key="blockHeight">--</td>
</tr>
<tr>
<td>Certificate installed</td>
<td data-key="certInstalled">Checking ...</td>
</tr>
<tr>
<td>Browser using Fingertip</td>
<td data-key="probeReached">Checking ...</td>
</tr>
<tr>
<td>DNS Interference Test</td>
<td data-key="dnsTest">Checking ...</td>
</tr>
<tr style="display: none">
<td data-key="dnsTestErr" style="color:red;" colspan="2"></td>
</tr>
</tbody>
</table>
<footer style="margin-top: 2em; margin-bottom: 2em; border-top: 1px solid #e5e5e5;">
<small>Fingertip v{{.Version}}</small>
</footer>
</div>
<script>
const handshakeStatus = document.querySelector('[data-key="resolverStatus"]')
const blockHeight = document.querySelector('[data-key="blockHeight"]')
const certInstalled = document.querySelector('[data-key="certInstalled"]')
const probeReached = document.querySelector('[data-key="probeReached"]')
const dnsTest = document.querySelector('[data-key="dnsTest"]')
const dnsTestErr = document.querySelector('[data-key="dnsTestErr"]')
const firefoxNotice = document.querySelector('.firefox');
let probeUrl = "";
// number of times proxy probe was
// checked without success
let probeChecks = 0;
let certStatus = -1;
let intervalId;
let defaultDuration = 300;
let maxDuration = 5000;
let currentDuration = defaultDuration;
let errors = 0;
let init = true;
function heyFingertip(probe) {
// say hi this request will fail
// but fingertip will detect it's being used by
// this browser
fetch(probe).catch(() => {
// do nothing
});
}
function newDataHandler(data) {
if (!data)
return;
if (!data.proxyProbeReached) {
if (probeUrl === "" || (probeChecks > 5 && probeUrl === data.proxyProbeUrl)) {
heyFingertip(data.proxyProbeUrl);
probeUrl = data.proxyProbeUrl;
probeChecks = 0;
}
probeChecks++;
} else {
probeChecks = 0;
}
const progress = Math.round(data.progress * 100 * 100) / 100;
handshakeStatus.innerHTML = data.syncing ? `<span class='warning'>Syncing (${progress}%)</span>` :
"<span class='success'>Ready</span>";
blockHeight.innerText = data.blockHeight;
if (data.proxyProbeUrl === probeUrl) {
// delay showing status if the test may not have
// completed yet
if (data.proxyProbeReached || probeChecks > 5) {
probeReached.innerHTML = data.proxyProbeReached ? "<span class='success'>Yes</span>" :
"<span class='error'>No</span>";
}
}
// hide cert installed test it only checks the system store
// we don't know for sure if firefox accepts the cert
const isFirefox = (navigator.userAgent.indexOf('Firefox') !== -1);
if (isFirefox) {
// show firefox install check tip
if (data.certInstalled) {
firefoxNotice.style.display = 'block';
}
certInstalled.closest('tr').style.display = 'none';
} else {
certInstalled.innerHTML = data.certInstalled ? "<span class='success'>Yes</span>" :
"<span class='error'>No</span>";
// if cert status changed reload the page
// to redo all checks
newCertStatus = data.certInstalled ? 1 : 0;
if (certStatus !== -1 && certStatus !== newCertStatus) {
window.location.reload();
return;
}
certStatus = newCertStatus;
}
if (data.dnsTestPassed) {
dnsTest.innerHTML = "<span class='success'>Passed</span>";
} else if (data.dnsTestInProgress) {
dnsTest.innerHTML = "Checking ...";
} else if (data.dnsTestError !== "") {
dnsTest.innerHTML = "<span class='error'>Failed</span>";
dnsTestErr.innerText = 'error: ' + data.dnsTestError;
dnsTestErr.closest('tr').style.display = null;
}
}
function poll(duration) {
clearInterval(intervalId);
intervalId = setInterval(fetchNewData, duration);
}
function fetchNewData() {
const shouldInit = init;
init = false;
fetch('info.json' + (shouldInit ? '?init=1' : '')).then(response => {
if (!response.ok) {
errors++;
currentDuration = Math.min(defaultDuration * errors, maxDuration);
poll(currentDuration);
return null;
}
if (errors > 0) {
errors = 0;
poll(defaultDuration);
}
return response.json();
}).then(newDataHandler);
}
poll(defaultDuration);
</script>
</body>
</html>