-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.js
209 lines (176 loc) · 4.8 KB
/
html.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
import pkg from './package.json';
const buildHTML = (style, script, body) => {
return `
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>${style || ''}</style>
<script>${script}</script>
</head>
<body>${body}
<footer>
<p hidden>${pkg.name}:${pkg.version}</p>
</footer>
</body>
</html>
`;
};
const buildMainPage = () => {
const mainPageStyle = `
textarea {
width: 100%;
resize: vertical;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
}
.radios {
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
width: fit-content;
}
input[type="radio"] {
width: 10px;
border: 1px solid #ccc;
border-radius: 2px;
box-sizing: border-box;
margin-top: 10px;
}
input[type="checkbox"] {
width: 10px;
border: 1px solid #ccc;
border-radius: 2px;
box-sizing: border-box;
margin-top: 10px;
}
input {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
font-size: 16px;
}
footer {
font-size: 9px;
}
.container {
background-color: #f1f1f1;
padding: 20px;
}
`;
const mainHtml = `
<div class="container">
<h3>Secret Sharing</h3>
<form action="share" method="POST">
<label for="secret">Secret</label>
<textarea id="secret" name="secret" rows="5" spellcheck="false" required></textarea>
<label for="password">Encryption Password</label>
<input type="password" id="password" name="password" pattern=".{8,}" minlength="8" title="8 characters minimum">
<label for="radios">Expiry</label>
<div class="radios">
<input id="radio1" type="radio" name="expiry" value="120" checked>
<label for="radio1">2 Minutes</label><br>
<input id="radio2" type="radio" name="expiry" value="900">
<label for="radio2">15 Minutes</label><br>
<input id="radio3" type="radio" name="expiry" value="86400">
<label for="radio3">24 Hours</label><br>
<input id="tickbox" type="checkbox" name="delete" checked="checked">
<label for="tickbox">Delete after read</label><br>
</div>
<input type="submit" value="Share">
</form>
</div>
`;
return buildHTML(mainPageStyle, '', mainHtml);
};
const buildSharePage = (secureRandomStorageKey) => {
const shareHtmlStyle = `
input {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
}
button {
background-color: #4CAF50;
color: white;
font-size: 16px;
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
}
.container {
background-color: #f1f1f1;
padding: 20px;
}
`;
const shareHtmlBody = `
<body class="container">
<div>
<input id="url" value="https://shhh.benedridge.com/reveal/${secureRandomStorageKey}" size="128" readonly/>
</div>
<button onclick="clipboard()">Copy</button>
<script>
function clipboard() {
var copyText = document.getElementById("url");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Copied URL");
}
</script>
`;
return buildHTML(shareHtmlStyle, '', shareHtmlBody);
};
const buildRevealPage = () => {
const passwordPromptScript = `
function init(){
let password = prompt("Please enter decryption password.");
if(password){
let form = document.getElementById("form");
form.action = window.location.href;
document.getElementById("password").value = password;
form.submit();
} else {
document.getElementById("message").innerHTML = "Did Not Decrypt Secret";
}
}
window.onload = function() {
init();
};
`;
const passwordPromptHtml = `
<p id="message"></p>
<form style="display: none" action="" method="POST" id="form">
<input type="hidden" id="password" name="password" value=""/>
</form>
`;
return buildHTML('', passwordPromptScript, passwordPromptHtml);
};
export {
buildMainPage,
buildSharePage,
buildRevealPage
};