-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
121 lines (106 loc) · 3.87 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>License File Verification</title>
<style>
textarea {
width: 100%;
height: 200px;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<h1>License File Verification</h1>
<form id="licenseForm">
<label for="publicKey">Public Key:</label>
<input type="text" id="publicKey" name="publicKey" value="e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788" required>
<br><br>
<label for="licenseKey">License Key:</label>
<input type="text" id="licenseKey" name="licenseKey" value="8750AB-30B7BD-023BA9-31B601-4550A2-V3" required>
<br><br>
<label>
<input type="radio" name="licenseInputMethod" value="upload" id="uploadRadio" checked>
Upload License File
</label>
<br>
<label>
<input type="radio" name="licenseInputMethod" value="input" id="inputRadio">
Input License File
</label>
<br><br>
<div id="uploadContainer">
<label for="licenseFile">License File:</label>
<input type="file" id="licenseFile" name="licenseFile" accept=".lic">
</div>
<div id="inputContainer" class="hidden">
<label for="licenseText">License File:</label>
<textarea id="licenseText" name="licenseText" placeholder="Paste license file content here"></textarea>
</div>
<br>
<button type="submit">Verify</button>
</form>
<h2>License Details</h2>
<textarea id="licenseOutput" readonly></textarea>
<script type="module">
import { decode, verify, decrypt } from './keygen.js'
const form = document.getElementById('licenseForm')
const output = document.getElementById('licenseOutput')
const uploadRadio = document.getElementById('uploadRadio')
const inputRadio = document.getElementById('inputRadio')
const uploadContainer = document.getElementById('uploadContainer')
const inputContainer = document.getElementById('inputContainer')
// toggle input method visibility based on selected radio button
uploadRadio.addEventListener('change', () => {
uploadContainer.classList.remove('hidden')
inputContainer.classList.add('hidden')
})
inputRadio.addEventListener('change', () => {
inputContainer.classList.remove('hidden')
uploadContainer.classList.add('hidden')
})
// initial state
if (uploadRadio.checked) {
uploadContainer.classList.remove('hidden')
inputContainer.classList.add('hidden')
} else {
inputContainer.classList.remove('hidden')
uploadContainer.classList.add('hidden')
}
form.addEventListener('submit', async (event) => {
event.preventDefault() // prevent form from refreshing the page
const formData = new FormData(form)
const publicKey = formData.get('publicKey')
const licenseKey = formData.get('licenseKey')
const file = formData.get('licenseFile')
const text = formData.get('licenseText').trim()
// determine which input to use based on the selected radio button
let licenseFile = ''
if (uploadRadio.checked && file) {
licenseFile = await file.text() // use uploaded file content
} else if (inputRadio.checked && text) {
licenseFile = text // use manually entered text
} else {
output.value = 'Please provide a license file by uploading or inputting the text.'
return
}
try {
const { enc, sig } = await decode({ licenseFile })
const ok = await verify({ enc, sig, publicKey })
if (ok) {
const lic = await decrypt({ enc, licenseKey })
output.value = JSON.stringify(lic, null, 2)
} else {
output.value = 'License verification failed.'
}
} catch (e) {
output.value = `An error occurred: ${e.message}`
}
})
</script>
</body>
</html>