This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
forked from Miserlou/DirtyShare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
330 lines (272 loc) · 11 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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>DirtyShare</title>
<LINK REL="SHORTCUT ICON" HREF="/public/favicon.ico" />
<meta name="keywords" content="node, nodejs, javascript, p2p, filesharing, webp2p, web peer to peer, p2pweb, open source" />
<meta name="description" content="DirtyShare is a proof of concept Peer to Peer filesharing system written in pure Javascript with Socket.io and Node.js." />
<link href="/public/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href='http://fonts.googleapis.com/css?family=Trade+Winds' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Monsieur+La+Doulaise' rel='stylesheet' type='text/css'>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/public/socket.io.js"></script>
<script type="text/javascript" src="/public/jquery.url.js"></script>
</head>
<body>
<div id="header">
<b>Dirty</b>Share
</div>
<script type="text/javascript">
$(document).ready(function() {
filth =
[
"\"My God, That\'s Filthy!\"",
"\"You Dirty Bastards!\"",
"\"Sheer And Utter Filth!\"",
"\"What a Shame!\"",
];
$('#subheader').html('<i>' + filth[Math.floor(Math.random()*filth.length)] + '</i>');
});
</script>
<div id="subheader">
</div>
<div id="description">
This is WebP2P version 0.1, aka 'DirtyShare', a pure JavaScript "peer to peer" filesharing system written in Node.js and Socket.io. Don't use this for anything. What's wrong with you?
</div>
<div id="drop_zone" onClick="$('#files').click()" >
<div id="clicky"><br /><br /><br /><br />Loading..</div>
<div id="fileslist">
</div>
</div>
<input type="file" id="files" name="files[]" multiple style="height: 20px; opacity: 0; filter:alpha(opacity: 0); position: relative; top: -40px; left: -20px;" />
<div id="infoholder">
<div id="host">
</div>
<div id="peer">
Awaiting peer..
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#shareurl').html('<b>http://${domain}/' + $.url().segment(1) + '</b>');
});
</script>
<br />
<div id="description">
Share this URL: <div id="shareurl"></div>
</div>
<div id="what">
<i><a onClick="$('#about').slideDown('slow');">What is this?</a><i>
</div>
<div id="about" style="display: none;">
<b>Dirty</b>Share is a proof of concept "Peer to Peer" filesharing system written in <b>pure Javascript</b> with Socket.io and Node.js. It's called <b>Dirty</b>Share because it's dirty as hell across the whole stack, from the concept to the code to the use case. <br/><br/>
File transfers in <b>Dirty</b>Share happen from a host client to a peer client, in chunks which go through the webserver over WebSockets provided by Socket.IO. The web server only holds onto the data while it is being received and transmitted through it, so there is <i>no data ever permanently stored on the web server</i>. This makes it perfect for sending dirty pictures!<br/><br/>
Ideally, the WebSockets will only be used to establish the P2P connections which will go over the HTML5 PeerConnection object, however, <i>no modern browsers support this feature yet</i>. Hopefully, it will become available within the next 6 months or so, and <b>we will be ready</b> for it !<br /><br />
Let's make a purely browser based, ad-free, Free and Open Source private filesharing system!
</div>
<div id="credits">
<b>Dirty</b>Share is written by <b>Rich Jones</b> of <b><a href="http://gun.io" target="_blank">Gun.io</a></b>. <br/><br/>
<a href="https://github.com/Miserlou/DirtyShare" target="_blank">Source code</a> is here.<br/> Patches graciously accepted! <br/><br/>
Interested in dicussing/hacking on web peer to peer software? Shoot an email to <b>[email protected]</b> and you'll be part of the mailing list!
</div>
<div id="lower">
<div id="info">
</div>
<div id="warnings">
</div>
</center>
<script>
var fid = 0;
var files = {};
var downfiles = {};
var socket = io.connect('http://${domain}');
//read the requested bytes
var reader;
var canHost = true;
if (typeof FileReader !== "undefined"){
reader = new FileReader();
}
else{
$('#clicky').html('<br /><br />Your browser is not modern enough to serve as a host. :( <br /><br />(Try Chrome or Firefox!)');
canHost = false;
}
var chunksize = 65536;
socket.on('connect', function(data){
socket.emit('joiner', $.url().segment(1));
});
socket.on('fileslist', function(data){
$('#fileslist').show();
$('#clicky').html('');
$('#clicky').hide();
$('#fileslist').html('');
$('#fileslist').html(function(i,v){
return '<table id="filestable" cellspacing="0" summary=""><tr><th scope="col" abbr="Filename" class="nobg" width="60%">Filename</th><th scope="col" abbr="Status" width="20%" >Size</th> <th scope="col" abbr="Size"width="20%" >Action</th></tr>' + v;
});
files = {};
files = JSON.parse(data);
for (var file in files) {
console.log(file);
if (files.hasOwnProperty(file)) {
$('#filestable').append('<tr><th scope="row" class="spec">' + files[file][0] + '</th><td>' + files[file][1] + '</td><td class="end" ><div id="fidspan' + fid + '"></div><a href="" onclick="beginTransfer(\'' + files[file][0] + '\', ' + fid + ', ' + files[file][1] + '); return false;" id="fid' + fid + '">Transfer</a><a href="data:' + files[file][2] + ';base64," target="_blank" id="fidsave' + fid + '" style="display:none">Save to disk!</a></td></tr>');
fid++;
};
}
});
socket.on('warn', function(data){
$('#warnings').html(data);
});
socket.on('host', function(data){
if(canHost){
$('#host').html("You're hosting this party!");
$('#clicky').html("<br /><br /><br /><br />Click here to choose files");
$('#fileslist').hide();
}
});
socket.on('peer', function(data){
$('#peer').html("You're connected as a peer!");
$('#host').html("Host connected.");
$('#drop_zone').attr("onclick", function() {
return;
});
$('#files').remove();
$('#drop_zone').css("cursor", "default");
$('#fileslist').hide();
$('#clicky').html('Awaiting file list..');
});
socket.on('peerconnected', function(data){
$('#peer').html("Peer connected!");
});
socket.on('peerdisconnected', function(data){
$('#peer').html("Peer disconnected.");
});
socket.on('hostdisconnected', function(data){
$('#host').html("Host disconnected.");
$('#peer').html("You're disconnected!");
});
socket.on('info', function(data){
$('#info').append(data);
});
socket.on('begintransfer', function(file, chunk){
if(chunk == 0){
$('#info').append("Begining Transfer..");
}
fileholder= files[file];
fileo= files[file][3]; //ugly
start = chunk * chunksize;
if((parseInt(fileholder[1]) - 1) <= start + chunksize - 1){
stop = parseInt(fileholder[1]) - 1;
}
else{
stop = start + chunksize - 1;
}
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
var data = evt.target.result;
socket.emit('datatransfer', data, file, chunk);
}
};
if (fileo.webkitSlice) {
var blob = fileo.webkitSlice(start, stop + 1);
} else if (fileo.mozSlice) {
var blob = fileo.mozSlice(start, stop + 1);
}
else{
alert("It won't work in your browser. Please use Chrome or Firefox.");
}
reader.readAsBinaryString(blob);
});
socket.on('datatransfer', function(data, file, chunk){
f = downfiles[file];
f.data = f.data + data;
if(f.chunks == chunk){
var fspan = "#fidspan" + f.fid;
$(fspan).html('');
$(fspan).hide();
var fsave = "#fidsave" + f.fid;
$(fsave).show();
$(fsave).attr('href', $(fsave).attr('href') + encode64(f.data));
$('#info').append("Transfer finished!");
}
else{
var fspan = "#fidspan" + f.fid;
$(fspan).html(Math.floor(((chunk/f.chunks) * 100)) + '%');
var nextchunk = parseInt(chunk);
socket.emit('begintransfer', file, nextchunk+1);
}
});
function beginTransfer(file, fid, size){
var f = "#fidspan" + fid;
$(f).html('0%');
f = "#fid" + fid;
$(f).hide();
var chunks = size/chunksize;
if(chunks% 1 != 0){
chunks = Math.floor(chunks) + 1;
}
downfiles[file] = {data:'', chunk:0, chunks:chunks, fid:fid};
socket.emit('begintransfer', file, 0);
};
function handleFileSelect(evt) {
var viles = evt.target.files; // FileList object
files = {};
// Loop through the FileList and append files to list.
for (var i = 0, f; f = viles[i]; i++) {
if (!files.hasOwnProperty(f)) {
files[f.name] = [f.name, f.size, f.type, f];
};
}
socket.emit('listfiles', JSON.stringify(files));
$('#fileslist').show();
$('#clicky').html('');
$('#clicky').hide();
$('#fileslist').html('');
$('#fileslist').html(function(i,v){
return '<table id="filestable" cellspacing="0" summary=""><tr><th scope="col" abbr="Filename" class="nobg" width="60%">Filename</th><th scope="col" abbr="Status" width="20%" >Size</th> <th scope="col" abbr="Size"width="20%" >Action</th></tr>' + v;
});
for (var file in files) {
if (files.hasOwnProperty(file)) {
$('#filestable').append('<tr><th scope="row" class="spec">' + files[file][0] + '</th><td>' + files[file][1] + '</td><td class="end"><b>Sharing!</b></td></tr>');
};
}
};
document.getElementById('files').addEventListener('change', handleFileSelect, false);
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
function encode64(input) {
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
</script>
</body>
</html>