-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.html
287 lines (271 loc) · 13.9 KB
/
manage.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
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='/style.css' rel='stylesheet' type='text/css'>
</head>
<body>
<div style="display: flex; justify-content: center; flex-direction: column; align-items: center;">
<input placeholder="Website URL" type="text" id="name">
<div onclick="Create()" class="customButton">Add Website</div>
<input placeholder="IP Address" type="text" id="ip">
<div onclick="IP()" class="customButton">Set public address</div>
<div onclick="Update()" class="customButton">Update server</div>
<div onclick="UpdateOculusDB()" class="customButton">Update OculusDB server</div>
<div style="width: 90%; background-color: #bbbbbb; height: 10px;"><div style="background-color: #42bbeb; height: 100%; width: 0%;" id="progress"></div></div>
<div onclick="Export()" class="customButton">Export all data</div>
<div onclick="location.href = '/console'" class="customButton">View console</div>
<input placeholder="webhookUrl" type="password" id="webhook">
<div onclick="MasterWebhook()" class="customButton">Set master Discord webhook url (boy above)</div>
<a href="/config" download="ComputerAnalyticsConfig.json">Download config</a>
<div onclick="Config()" class="customButton">Upload config</div>
<div onclick="MasterToken()" class="customButton">Renew master token</div>
<div onclick="Restart()" class="customButton">Restart server</div>
<div onclick="Shutdown()" class="customButton" style="background-color: #DA3633">Shutdown server</div>
<table>
<tr>
<td class="left">Ram usage</td>
<td class="right" id="ram"></td>
</tr>
<tr>
<td class="left">Working directory</td>
<td class="right" id="working"></td>
</tr>
</table>
<h4>Websites</h4>
<div id="websites">
</div>
<div style="display: flex; align-items: center; justify-content: center; background-color: #00000044; visibility: hidden; position: absolute; width: 100vw; height: 100vh;" id="confirm">
<div style="background-color: #000000EE; padding: 20px;">
<table>
<tr>
<td class="left">Public token</td>
<td><input placeholder="Public token" type="text" id="public" style="width: 700px;"></td>
</tr>
<tr>
<td class="left">Website URL</td>
<td><input placeholder="website url" type="text" id="url" style="width: 700px;"></td>
</tr>
<tr>
<td class="left"><div onclick="RealDelete()" class="customButton" style="background-color: #DA3633">Confirm Deletion</div></td>
<td><div onclick="document.getElementById('confirm').style.visibility = 'hidden'" class="customButton">Abort</div></td>
</tr>
</table>
</div>
</div>
</div>
<script src="/script.js"></script>
<script>
const websites = document.getElementById("websites")
const progress = document.getElementById("progress")
function Update() {
var input = document.createElement("input")
input.setAttribute("type", "file")
input.onchange = function (e) {
if (!this.files[0]) {
return;
}
var reader = new FileReader();
var fileName = this.files[0].name
reader.onloadend = function () {
var changelog = prompt("Enter changelog (optional)")
var xhr = new XMLHttpRequest()
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
progress.style.width = percentComplete + "%"
if (percentComplete === 100) {
alert("Update has started. Please reaload the page in a few seconds")
}
}
}, false);
xhr.open("POST", "/update?changelog=" + changelog)
xhr.send(reader.result)
}
reader.readAsArrayBuffer(this.files[0]);
}
input.click()
}
function UpdateOculusDB() {
var input = document.createElement("input")
input.setAttribute("type", "file")
input.onchange = function (e) {
if (!this.files[0]) {
return;
}
var reader = new FileReader();
var fileName = this.files[0].name
reader.onloadend = function () {
var changelog = prompt("Enter changelog (optional)")
var xhr = new XMLHttpRequest()
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
progress.style.width = percentComplete + "%"
if (percentComplete === 100) {
alert("Update has started. Please reaload the page in a few seconds")
}
}
}, false);
xhr.open("POST", "/updateoculusdb?changelog=" + changelog)
xhr.send(reader.result)
}
reader.readAsArrayBuffer(this.files[0]);
}
input.click()
}
function Config() {
var input = document.createElement("input")
input.setAttribute("type", "file")
input.onchange = function (e) {
if (!this.files[0]) {
return;
}
var reader = new FileReader();
var fileName = this.files[0].name
reader.onloadend = function () {
fetch("/config", {
method: "POST",
body: reader.result
}).then(res => res.text().then(res => alert(res)))
}
reader.readAsArrayBuffer(this.files[0]);
}
input.click()
}
var spublic = ""
var surl = ""
function Delete(url, public) {
spublic = public
surl = url
document.getElementById('confirm').style.visibility = 'visible'
}
function RealDelete() {
if(document.getElementById("url").value == surl && document.getElementById("public").value == spublic) {
fetch("/website", {
method: "DELETE",
body: surl
}).then(res => {
res.text().then(t => {
alert(t)
location.reload()
})
})
} else {
alert("public token and url must match the website you want to delete")
}
}
function Restart() {
POST("/restart", "")
}
function MasterToken() {
POST("/renewmastertoken", "")
}
function Shutdown() {
POST("/shutdown", "")
}
function Renew(url, token) {
POST("/renewtokens", url + '|' + token)
}
function MasterWebhook() {
POST("/masterwebhook", document.getElementById("webhook").value)
}
function Webhook(id, url) {
POST("/webhook?url=" + url, document.getElementById(id).value)
}
function POST(url, body) {
fetch(url, {
method: "POST",
body: body
}).then(res => {
res.text().then(t => {
alert(t)
location.reload()
})
})
}
function Export() {
window.open("/requestexport", "_blank")
}
function Create() {
var url = document.getElementById("name").value
if(url.endsWith("/")) url = url.substring(0, url.length - 1)
fetch("/website", {
method: "POST",
body: url
}).then(res => {
res.text().then(t => {
alert(t)
location.reload()
})
})
}
function IP() {
var url = document.getElementById("ip").value
if(url.endsWith("/")) url = url.substring(0, url.length - 1)
POST("/publicaddress", url)
}
fetch("/publicaddress").then(res => res.text().then(t => {
document.getElementById("ip").value = t
}))
fetch("/metrics").then(res => res.json().then(json => {
document.getElementById("ram").innerHTML = json.ramUsageString
document.getElementById("working").innerHTML = json.workingDirectory
}))
fetch("/masterwebhook").then(res => res.text().then(t => {
document.getElementById("webhook").value = t
}))
function GetUTCDate(date) {
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
date.getUTCMilliseconds(),
)
}
function AddToken(url, expiration) {
POST("/addtoken", url + "|" + new Date(expiration).toISOString())
}
function DeleteToken(url, token) {
POST("/deletetoken", url + "|" + token)
}
fetch("/websites").then(res => {
res.json().then(w => {
var i = 0
w.forEach(e => {
var tokens = ""
e.privateTokens.forEach(token => {
var expires = new Date(token.expires)
tokens += `<div style="display: flex; margin-top: 20px; flex-direction: column; background-color: #333333; padding: 10px;">
<div><code>${token.value}</code></div>
<div style="margin-top: 8px;">Expires on ${expires.toUTCString()}</div>
<div class="customButton" onclick="Renew('${e.url}', '${token.value}')">Renew this token</div>
<div class="customButton" onclick="DeleteToken('${e.url}', '${token.value}')">Remove this token</div>
</div>`
})
websites.innerHTML += `<div style="display: flex; flex-direction: column; border: #EEEEEE 1px solid; width: 100%; padding: 15px;">
<a style="font-weight: bold;" href="${e.url}">${e.url}</a>
<div>public: <code>${e.publicToken}</code></div>
<div class="customButton" onclick="Renew('${e.url}', '${e.publicToken}')">Renew public token</div>
<div style="display: flex; flex-direction: column">private: ${tokens}</div>
<input style="margin-top: 20px;" placeholder="webhookUrl" value="${e.discordWebhookUrl}" type="password" id="${i}">
<div onclick="Webhook('${i}', '${e.url}')" class="customButton">Set Discord webhook url</div>
<div class="customButton" onclick="Renew('${e.url}', '')">Renew all tokens</div>
<div style="display: flex; margin-top: 20px; flex-direction: column; background-color: #333333; padding: 10px;">
<input type="datetime-local" id="${e.url}">
<div class="customButton" onclick="AddToken('${e.url}', document.getElementById('${e.url}').value)">Add Token</div>
</div>
<div class="customButton" onclick="Delete('${e.url}', '${e.publicToken}')" style="background-color: #DA3633">Delete Website (not undoable)</div>
</div>`
i++
})
})
})
</script>
</body>
</html>