-
Notifications
You must be signed in to change notification settings - Fork 7
/
monitor.html
344 lines (332 loc) · 16.1 KB
/
monitor.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="custom.css">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title></title>
</head>
<body>
<div class="container-fluid">
<!-- top bar: logo, version, settings button -->
<div class="row" id="top-bar">
<div class="col-xs-2 text-xs-left">
<img id="logo-icon" src="assets/logo-old.png">
</div>
<div class="col-xs-8 text-xs-center text-white">
<form action="https://geph.io/billing/login" target="_blank" method="get">
<input type="hidden" id="uname" name="uname">
<input type="hidden" id="pwd" name="pwd">
<input type="hidden" name="next" value="/billing/dashboard">
<button type="submit" class="btn btn-primary btn-sm" data-l10n="upgradeblurb" id="upgradeblurb" style="display: none">
</button>
</form>
</div>
<div class="col-xs-2 text-white text-xs-right">
<a id="settings-btn" href="#">
<img id="settings-icon" src="assets/settings.svg">
</a>
</div>
</div>
<!-- status icon and text -->
<div class="row">
<div class="col-xs-12 text-xs-center">
<table id="status-table">
<tr>
<td><img id="status-icon" src="assets/loading.gif"></td>
<td>
<span id="status-text">status-text</span><br>
<span id="tooltip-text" class="text-muted">tooltip-text</span>
</td>
</tr>
</table>
</div>
</div>
<!-- detailed info -->
<div class="row" id="infotab">
<hr>
<div class="col-xs-5 text-xs-right">
<b data-l10n="ipLabel"></b><br>
<b data-l10n="connModeLabel"></b><br>
<b data-l10n="planLabel"></b><br>
<b data-l10n="balanceLabel" id="balance-label"></b>
<b data-l10n="remtimeLabel" id="remtime-label" style="display:none"></b>
</div>
<div class="col-xs-7">
<img id="exit-flag" src="assets/flags/un.svg">
<span id="exit-value">...</span><br>
<span id="connmode-value">...</span><br>
<span id="plan-value">...</span><br>
<span id="balance-value">...</span>
<span id="remtime-value" style="display:none">...</span>
</div>
</div>
<!-- buttons -->
<div class="row">
<div class="col-xs-12 text-xs-center">
<hr>
<button type="button" class="btn btn-primary"
data-l10n="connectBtn"
id="connect-btn"></button>
<button type="button" class="btn btn-warning"
data-l10n="disconnectBtn"
id="disconnect-btn">disconnect-btn</button>
</div>
</div>
<!-- modal for bad accounts -->
<div class="modal fade" id="error-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="error-title">
error-title
</h4>
</div>
<div class="modal-body">
<p id="error-text">error-text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="error-dismiss">
error-dismiss
</button>
</div>
</div>
</div>
</div>
<!-- modal for settings -->
<div class="modal fade" id="settings-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="settings-title" data-l10n="settingsTitle"></h4>
</div>
<div class="modal-body text-xs-center">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"
id="chk-autoconfig-browser" value="">
<span id="lab-autoconfig-browser"
data-l10n="autoconfigBrowser"></span>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"
id="chk-avoid-china" value="">
<span id="lab-avoid-china" data-l10n="avoidChina"></span>
</label>
</div>
<div class="form-group">
<label>
<span data-l10n="langSelect"></span>
<select class="custom-select" id="lang-dropdown">
<option value="en">English</option>
<option value="zht">正體中文</option>
<option value="zhs">简体中文</option>
</select>
</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="settings-dismiss"
data-l10n="settingsDismiss">
</button>
</div>
</div>
</div>
</div>
</div>
<script>
window.$ = window.jQuery = require('./jquery.js')
</script>
<script src="bootstrap/js/bootstrap.js"></script>
<script src="l10n.js"></script>
<script src="daemon.js"></script>
<script src="autoupdate.js"></script>
<script>
// kill the daemon when we exit
window.onbeforeunload = function (e) {
console.log("Cleaning up...")
stopDaemon()
}
// state transitions
let state = ""
function setStatusConnecting() {
$("#status-text").html(l10n["statusConnecting"])
$("#tooltip-text").html("")
// prevent the animation from resetting
if (state != "connecting") {
$("#status-icon").attr("src", "assets/loading.gif")
}
$("#connect-btn").hide()
$("#disconnect-btn").show()
$("#infotab").addClass("faded")
state = "connecting"
}
function setStatusConnected() {
$("#status-text").html(l10n["statusConnected"])
if (localStorage.getItem("gephpref.autoconfig-browser") == "true") {
$("#tooltip-text").html(l10n["tooltipBrowser"])
} else {
$("#tooltip-text").html(l10n["tooltipProxy"])
}
$("#status-icon").attr("src", "assets/connected.png")
$("#infotab").removeClass("faded")
state = "connected"
}
function setStatusDisconnected() {
location.replace("login.html")
$("#status-text").html(l10n["statusDisconnected"])
$("#tooltip-text").html("")
$("#status-icon").attr("src", "assets/disconnected.png")
$("#disconnect-btn").hide()
$("#infotab").addClass("faded")
state = "disconnected"
}
// initialize labels function
function initLabels() {
$("title").text(l10n["geph"] + " " + currentVersion)
setStatusConnecting()
}
// one iteration of the monitoring loop
let monCount = 0
let lastTrans = 0
function monitorOnce() {
$.getJSON("http://127.0.0.1:8790/summary", function(data) {
if (data.Status == "connected") {
setStatusConnected()
let omc = monCount
monCount++
// update account info every 30 seconds
if (omc % 30 == 0) {
$.getJSON("http://127.0.0.1:8790/accinfo", function(data) {
// plan text
if (data.PremiumInfo.Plan != "") {
let lang = localStorage.getItem("gephpref.lang")
$("#plan-value").text(data.PremiumInfo.Desc.Name[lang])
$("#upgradeblurb").text(l10n["managesub"])
$("#upgradeblurb").show()
} else {
$("#plan-value").text(l10n["planFree"])
$("#upgradeblurb").text(l10n["upgradeblurb"])
$("#upgradeblurb").show()
}
// balance
if (data.PremiumInfo.Unlimited) {
$("#remtime-label").show()
$("#balance-label").hide()
$("#remtime-value").show()
$("#balance-value").hide()
let daysleft = (data.PremiumInfo.ExpUnix - (new Date().getTime()/1000))/86400
if (daysleft > 10000) {
$("#remtime-value").html("Forever<br>")
} else {
$("#remtime-value").html(daysleft.toFixed(2) +
" " + l10n["days"] + "<br>")
}
} else {
if (data.FreeBalance > 1000){
$("#remtime-label").hide()
$("#balance-label").show()
$("#remtime-value").hide()
$("#balance-value").show()
$("#balance-value").html((data.FreeBalance/1000.0).toFixed(2) + " GB" + "<br>")
} else {
$("#balance-value").html((data.FreeBalance) + " MB" + "<br>")
}
}
})
}
// update net info
$.getJSON("http://127.0.0.1:8790/netinfo", function(data) {
// Exit node flag and IP
$("#exit-value").text(data.Exit)
$("#exit-flag").attr("src", "assets/flags/" +
data.ExitCountry.toLowerCase() + ".svg")
// Connection mode
if (data.Entry != "") {
$("#connmode-value").html(l10n["connModeDirect"] + " (" +
data.Entry.substring(0,6) + ")")
$("#connmode-value").attr("class", "text-success")
} else {
$("#connmode-value").html(l10n["connModeBackup"])
$("#connmode-value").attr("class", "text-danger")
}
})
} else {
setStatusConnecting()
}
})
}
// start monitoring
function startMonitor() {
setInterval(monitorOnce, 1000)
}
// account problems
function dieCannotLogin() {
$("#error-title").text(l10n["errTitle"])
$("#error-text").text(l10n["errCannotLogin"])
$("#error-dismiss").text(l10n["errLogOut"])
$("#error-dismiss").off().click(() => location.replace("login.html"))
$("#error-modal").modal({show: true, backdrop: "static", keyboard: false})
localStorage.removeItem("gephpref.uname")
localStorage.removeItem("gephpref.pword")
}
// entry point
$(document).ready(function(){
// upgrade button
$("#uname").val(localStorage.getItem("gephpref.uname"))
$("#pwd").val(localStorage.getItem("gephpref.pword"))
// settings button
$("#settings-btn").on('click', function() {
$("#settings-modal").modal({backdrop:"static", keyboard:false})
// fill in the checkboxes
$("#chk-autoconfig-browser").prop("checked",
localStorage.getItem("gephpref.autoconfig-browser") == "true")
$("#chk-avoid-china").prop("checked",
localStorage.getItem("gephpref.avoid-china") == "true")
$("#lang-dropdown").val(localStorage.getItem("gephpref.lang"))
})
// save settings
$("#settings-dismiss").on('click', function() {
localStorage.setItem("gephpref.autoconfig-browser",
$("#chk-autoconfig-browser").prop("checked"))
localStorage.setItem("gephpref.avoid-china",
$("#chk-avoid-china").prop("checked"))
localStorage.setItem("gephpref.lang",
$("#lang-dropdown").val())
// relabel everything
loadLang()
// restart the daemon by clicking on the buttons
if (gephDaemon != null) {
$("#disconnect-btn").click()
$("#connect-btn").click()
}
// hide the modal
$("#settings-modal").modal("hide")
})
// disconnect button
$("#disconnect-btn").click(function() {
stopDaemon()
setStatusDisconnected()
})
// connect button
$("#connect-btn").click(function() {
startDaemon()
setStatusConnecting()
})
initLabels()
startMonitor()
startDaemon()
gephDaemon.on('close', function(code) {
if (code == 43) {
stopDaemon()
setStatusDisconnected()
dieCannotLogin()
}
})
})
</script>
</body>
</html>