-
Notifications
You must be signed in to change notification settings - Fork 1
/
secure.html
256 lines (222 loc) · 8.1 KB
/
secure.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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Send Me File</title>
<!-- jQuery library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
<!-- jQuery Modal -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
<!-- <script src="http://malsup.github.com/jquery.form.js"></script> -->
<!-- Popper JS -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> -->
<!-- Bootstrap 4 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!-- p5.js CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<!-- Temporary script -->
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark sticky-top navbar-style" style="padding: 0px 16px">
<div class="container-fluid">
<a class="navbar-brand text-uppercase" href="#">Send me file</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="/secure">Home</a></li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/Vladimir-125/file-exchanger" target="_blank">Project Page</a></li>
<li class="nav-item">
<a class="nav-link" href="https://vladimir-125.github.io/resume/" target="_blank">Contact Me</a></li>
<li class="nav-item">
<a class="nav-link" href="#" id="user_name"></a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row h-100">
<div class="col-md-6 my-auto border border-secondary pt-3 rounded bg-light">
<div class="text-center">
<form action="/uploadfile" enctype="multipart/form-data" method="POST" id='uploadForm'>
<div class="custom-file mb-3">
<input type="file" class="custom-file-input" id="file" name="file" value="" required>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
<div class="d-flex justify-content-between">
<div>
<label for="password">Password:</label>
<input type="password" name="password" id="password" class="btn-lg" required />
</div>
<div>
<input type="submit" class="btn btn-outline-secondary btn-lg" value="Send"/>
</div>
</div>
</form>
</div>
<!-- Progress bar -->
<div id="uploaded" class="my-3">
</div>
</div>
<div class="col-md-6 my-auto border border-secondary pt-3 rounded bg-light">
<div class="text-center">
<form action="/download" method="POST" id='download'>
<div class="custom-file mb-3">
<input type="text" name="fileId" class="form-control" placeholder="Enter Key" id="keyNum">
</div>
<input type="submit" class="btn btn-outline-secondary btn-lg" value="Receive"/>
</form>
</div>
</div>
</div>
</div>
<script>
$( document ).ready(function() {
console.log('Page loaded!');
$.ajax({
url: '/name',
type: 'POST'
})
.done(function(res) {
console.log(res);
$('#user_name').html('Welcome, '+res+'!');
});
});
// Add the name of the file appear on select
$(".custom-file-input").on("change", function() {
var fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
});
// delete form value after file is sent
$('#uploadForm').submit(function(e) {
e.preventDefault(); // prevent multiple submits
if($('#file').val()==''){
alert('File is not selected!\nSelect a file and try again.');
}else{
// TODO: add asinc file upload here
var form = $(this);
addProgressBar();
var progress = $('.progress-bar');
var fname = $('#file').val();
fname = fname.substr(fname.lastIndexOf('\\')+1);
form.ajaxSubmit({
beforeSend: function() {
//status.empty();
var percentVal = '0%';
progress.css('width' , percentVal);
progress.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
progress.css('width' , percentVal);
progress.html(percentVal);
},
error: function(xhr) {
status('Error: ' + xhr.status);
},
success: function(response) {
var percentVal = '100%';
progress.css('width', percentVal);
progress.html(percentVal);
setTimeout(()=>{
$('.progress').remove();
//$( "#uploaded" ).append(name);
addUpload(response.key, response.time, fname)
//alert(response);
}, 500);
}
});
$('#file').val(''); // clear input file
// remove file name from input
$('.custom-file-label').removeClass('selected').html('Choose file');
$('#password').val(''); // clear input password
}
return false;
});
// delete form value after file is sent
$('#download').submit(function(e) {
e.preventDefault(); // don't submit multiple times
const key = $('#keyNum').val();
$.ajax({
url: '/validate',
type: 'POST',
data:{key:key}
})
.done(function(res) {
console.log(res);
if(res=='ok'){
util.post('/download', {key:key});
}
else if (res=='enc'){
const pass = prompt('Enter passowrd:');
$.ajax({
url: '/validate',
type: 'POST',
data:{key:key, password:pass}
}).done(function(res) {
if(res=='ok'){
util.post('/download', {key:key, password:pass});
}else{
alert('Wrong password!');
}
});
}else{
// received isnx message
alert('Does not exist!');
}
});
$('#keyNum').val('')
return false;
});
function addProgressBar(){
const uploaded = $('#uploaded')
const progress = $('<div></div>').addClass('progress')
progress.append($('<div>0%</div>').addClass('progress-bar').css('width','0%'));
uploaded.append(progress);
}
</script>
<script>
function addUpload(key, time, filename){
const timerId = randHex(12);
const qrCodeId = randHex(12);
var file = `
<div class="card mb-2">
<div class="card-body p-2">
<div class="container">
<div class="row">
<div class="col-sm-9">
<h5 class="card-title mb-0">Download Key: ${key}</h5>
<p class="card-text">${filename}<br>Expire time: <span id="${timerId}">${time}</span></p>
</div>
<div class="col-sm-3" id="${qrCodeId}">
</div>
</div>
</div>
</div>
</div>
`
$('#uploaded').append($(file));
var qrcode = new QRCode(document.getElementById(qrCodeId), {
width : 80,
height : 80
});
qrcode.makeCode(window.location.origin+'/download?key='+key);
countTime(time, timerId);
}
</script>
<!-- Get backgroud script -->
<script type="text/javascript" src="js/background.js"></script>
<!-- custom script -->
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script type="text/javascript" src="/js/script.js"></script>
<!-- qrcode generator -->
<script type="text/javascript" src="js/qrcode.min.js"></script>
</body>
</html>