-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
257 lines (222 loc) · 8.14 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anon File Upload</title>
<style>
body {
font-family: 'Inter', sans-serif;
line-height: 1.6;
background-color: #0d1117;
color: #e6edf3;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
width: 100%;
max-width: 500px;
background: #161b22;
padding: 24px;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
border: 1px solid #30363d;
}
h2 {
color: #ff0000;
margin-bottom: 16px;
border-bottom: 2px solid #30363d;
padding-bottom: 8px;
display: flex;
align-items: center;
font-weight: 600;
}
h2 img {
margin-right: 2px;
height: 32px;
}
form {
margin-bottom: 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
input[type="file"] {
display: none;
}
.custom-file-upload, button[type=submit] {
padding: 12px;
background: linear-gradient(135deg, #238636, #2ea043);
color: #ffffff;
font-weight: 600;
border: none;
border-radius: 8px;
cursor: pointer;
text-align: center;
transition: transform 0.2s ease, background 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.custom-file-upload:hover, button[type=submit]:hover {
background: linear-gradient(135deg, #2ea043, #3fb950);
transform: scale(1.05);
}
.download-link {
margin-top: 12px;
padding: 12px;
background-color: #21262d;
border: 1px solid #30363d;
border-radius: 8px;
text-align: center;
word-wrap: break-word;
font-size: 14px;
}
.footer-links {
margin-top: 20px;
text-align: center;
}
.footer-links a {
color: #58a6ff;
text-decoration: none;
margin: 0 8px;
transition: color 0.2s ease;
}
.footer-links a:hover {
color: #79c0ff;
}
.storage-message {
text-align: center;
margin-top: 12px;
font-size: 14px;
color: #8b949e;
}
progress {
width: 100%;
height: 12px;
margin-top: 12px;
display: none;
border-radius: 6px;
overflow: hidden;
background-color: #30363d;
}
progress[value]::-webkit-progress-value {
background: linear-gradient(90deg, #ffa600, #ff4500);
border-radius: 6px;
}
progress[value]::-moz-progress-bar {
background: linear-gradient(90deg, #ffa600, #ff4500);
border-radius: 6px;
}
</style>
</head>
<body>
<div class="container">
<h2><img src="logo.png" alt="Logo">non File Upload</h2>
<form id="upload-form">
<label for="file-input" class="custom-file-upload">Choose File</label>
<input type="file" id="file-input" required>
<button type="submit">Upload</button>
<progress id="upload-progress" value="0" max="100"></progress>
</form>
<div class="storage-message">
Files are encrypted client-side and stored for 360 days. Max. file size: 500MB
</div>
<div id="link-container" class="download-link" style="display: none;">
File uploaded successfully. Download link: <a id="download-link" href="#"></a>
</div>
<div class="footer-links">
<a href="https://github.com/umutcamliyurt/Anon-File-Upload" target="_blank">Source Code</a>
<a href="/privacy-policy.html">Privacy Policy</a>
<a href="/terms-of-use.html">Terms of Use</a>
<a href="https://github.com/umutcamliyurt/Anon-File-Upload?tab=readme-ov-file#donate-to-support-development-of-this-project">Donate ❤️</a>
</div>
</div>
<script>
async function generateKey() {
return window.crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"]
);
}
async function encryptFile(file, key) {
const iv = window.crypto.getRandomValues(new Uint8Array(12));
const algorithm = {
name: "AES-GCM",
iv: iv
};
const fileBuffer = await file.arrayBuffer();
const encryptedBuffer = await window.crypto.subtle.encrypt(
algorithm,
key,
fileBuffer
);
return { iv, encryptedBuffer };
}
async function exportKey(key) {
const exported = await window.crypto.subtle.exportKey(
"raw",
key
);
return Array.from(new Uint8Array(exported)).map(b => b.toString(16).padStart(2, '0')).join('');
}
document.getElementById('upload-form').addEventListener('submit', async (e) => {
e.preventDefault();
const fileInput = document.getElementById('file-input');
if (fileInput.files.length === 0) {
alert('Please select a file.');
return;
}
const file = fileInput.files[0];
const key = await generateKey();
const { iv, encryptedBuffer } = await encryptFile(file, key);
const exportedKey = await exportKey(key);
const formData = new FormData();
formData.append('file', new Blob([iv, encryptedBuffer], { type: file.type }), file.name);
const progressBar = document.getElementById('upload-progress');
progressBar.style.display = 'block'; // Show progress bar before upload starts
const uploadUrl = 'upload.php';
// Using XMLHttpRequest to monitor upload progress
const xhr = new XMLHttpRequest();
xhr.open('POST', uploadUrl, true);
// Update progress bar on progress event
xhr.upload.addEventListener('progress', function(event) {
if (event.lengthComputable) {
const percentComplete = (event.loaded / event.total) * 100;
progressBar.value = percentComplete;
}
});
xhr.onload = async function() {
if (xhr.status === 200) {
const fileName = xhr.responseText;
const downloadLink = `${window.location.origin}/download.html#${exportedKey}-${fileName}`;
// Display the download link on the page
document.getElementById('link-container').style.display = 'block';
document.getElementById('download-link').href = downloadLink;
document.getElementById('download-link').textContent = downloadLink;
// Hide progress bar after upload completes
progressBar.style.display = 'none';
} else {
alert('File upload failed.');
progressBar.style.display = 'none'; // Hide progress bar on error
}
};
xhr.onerror = function() {
alert('File upload failed. Please try again.');
progressBar.style.display = 'none'; // Hide progress bar on error
};
xhr.send(formData);
});
</script>
</body>
</html>