-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathapp.js
643 lines (535 loc) · 19.7 KB
/
app.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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
var Omegle = require('./omegle.js').Omegle;
var onOmegleReady = require('./omegle.js').onReady;
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/static'));
var request = require('request');
var http = require('http');
var https = require('https');
var httpServer = http.Server(app);
var io = require('socket.io')(httpServer);
var settings = require('./settings.json');
//var Cleverbot = require('./cleverbot.js');
//var Sham = require('./shamchat.js').Sham;
app.get('/', function(req, res) {
res.sendFile(__dirname+'/static/index.htm');
});
// Handle connections
io.on('connection', function(socket) {
// List of omegle clients for this person
var omegleClients = {};
// List of clever bot clients
//var cleverClients = {};
// Stores challenge omegle clients
var challenges = {};
// Stores proxy info
var proxyInfo = null;
var proxyEnabled = false;
var requiredConnections = [];
var buildingConnection = false;
var currentPain = null;
function buildConnections() {
// Any connections required?
if(!buildingConnection && requiredConnections.length > 0) {
// Stop multiple from happening
buildingConnection = true;
var args = requiredConnections.shift();
// Store the current pain
currentPain = args.painID;
// Make a connection
makeConnection(args, false);
}
}
// Makes the actual connection
function makeConnection(args, reconnect) {
// Create the new omegle instance
var om = new Omegle(args);
// Store the args
om.args = args;
// A store for the clientID
var realClientID;
// Handle errors
om.errorHandler(function(msg) {
socket.emit('omegleError', args, msg);
});
om.on('newid', function(client_id) {
// Store the client
omegleClients[client_id] = om;
// Send this ID to the user
socket.emit('newOmegle', client_id, args);
// Store client ID
realClientID = client_id;
});
// Omegle has banned us
om.on('antinudeBanned', function() {
if(!reconnect) {
// No longer building a connection
buildingConnection = false;
// Move on
buildConnections();
}
// Send this ID to the user
socket.emit('omegleBanned', args);
});
// There was an error
om.on('error', function(err) {
// Send this ID to the user
socket.emit('omegleError', args, err);
});
// Omegle is finding a partner
om.on('waiting', function() {
// Tell the client
socket.emit('omegleWaiting', realClientID);
});
// Omegle found us a partner
om.on('connected', function(peerID) {
// Tell the client
socket.emit('omegleConnected', realClientID, peerID);
// Make sure we're not reconnecting
if(!reconnect) {
// Give a brief delay before making a new connection
setTimeout(function() {
// No current pain
currentPain = null;
// No longer building the connection
buildingConnection = false;
// Try to build any remaining connections
buildConnections();
}, 100);
}
});
// Omegle is telling us our common likes
om.on('commonLikes', function(commonLikes) {
// Tell the client
socket.emit('omegleCommonLikes', realClientID, commonLikes);
});
// Omegle is sending us status info
om.on('statusInfo', function(statusInfo) {
// Tell the client
socket.emit('omegleStatusInfo', statusInfo);
});
// Omegle is telling us our partner's college
om.on('partnerCollege', function(college) {
// Tell the client
socket.emit('omeglePartnerCollege', realClientID, college);
});
// Omegle sent us a question
om.on('question', function(question) {
// Tell the client
socket.emit('omegleQuestion', realClientID, question);
});
// Handle the capcha
function handleCaptcha(code) {
// Are we trying to avoid this BS?
if(proxyEnabled && proxyInfo) {
// Tell them
socket.emit('proxyMessage', 'Server sent a capcha, seaching for a new proxy...', args);
// Try to find a new proxy to use
tryFindNewProxy(function() {
// Con failed due to proxy issues
socket.emit('conFailedProxy', args);
});
return;
}
// Use the new captcha method
socket.emit('omegleNewChallenge', args, code);
challenges[code] = om;
// Don't run the old method
return;
// URL with challenge data
var toFetch = 'https://www.google.com/recaptcha/api/challenge?k='+code+'&cahcestop='+Math.random();
https.get(toFetch, function(res) {
// Ensure the request worked
if (res.statusCode !== 200) {
socket.emit('omegleError', args, 'Captcha failed.');
return;
}
// Process the event
om.getAllData(res, function(data) {
// Make sure we got some data
if(data != null) {
// Copy important data
var a = data.indexOf('\'')+1;
var b = data.indexOf('\'', a)-1;
// Grab the challenge
var challenge = data.substring(a, b+1);
// Store it
challenges[challenge] = om;
// Send to client to solve
socket.emit('omegleChallenge', args, code, challenge);
} else {
// Failure
socket.emit('omegleError', args, 'Capcha, no data passed!');
}
});
}).on('error', function(e) {
// Send to client
socket.emit('omegleError', args, 'Got capcha error: ' + e.message);
});
}
// Recaptcha
om.on('recaptchaRejected', handleCaptcha);
om.on('recaptchaRequired', handleCaptcha);
// Stranger has disconnected
om.on('strangerDisconnected', function() {
// Tell client
socket.emit('omegleStrangerDisconnected', realClientID);
});
// A spy disconnected
om.on('spyDisconnected', function(spy) {
// Tell client
socket.emit('omegleSpyDisconnected', realClientID, spy);
});
// Stranger sent us a message
om.on('gotMessage', function(msg) {
// Tell client
socket.emit('omegleGotMessage', realClientID, msg);
});
// Got a spy message
om.on('spyMessage', function(spy, msg) {
// Tell client
socket.emit('omegleSpyMessage', realClientID, spy, msg);
});
// We have disconnected
om.on('disconnected', function() {
// Tell client
socket.emit('omegleDisconnected', realClientID);
});
// Stranger started typing
om.on('typing', function() {
// Tell client
socket.emit('omegleTyping', realClientID);
});
// Stranger stopped typing
om.on('stoppedTyping', function() {
// Tell client
socket.emit('omegleStoppedTyping', realClientID);
});
// Debug events
if(settings.debug) {
om.on('debugEvent', function(reason) {
// Tell client
socket.emit('debugEvent', realClientID, reason);
});
}
// Are we doing a reconnect?
if(reconnect) {
// Reconnect to a client
om.reconnect(function(err) {
if (err) {
// Send to client
socket.emit('omegleError', args, 'Error reconnecting: ' + err);
}
});
} else {
// Connect to a client
om.start(function(err) {
if (err) {
if(proxyEnabled && proxyInfo) {
// Tell them
socket.emit('proxyMessage', 'Broken proxy, seaching for a new proxy...', args);
// Try to find a new proxy to use
tryFindNewProxy(function() {
// Con failed due to proxy issues
socket.emit('conFailedProxy', args);
});
} else {
// Send to client
socket.emit('omegleError', args, 'Error starting: ' + err);
}
}
}, proxyEnabled && proxyInfo);
}
}
// Creates a new connection
function setupNewConnection(args) {
// Ensure we have args
if(args == null) args = {};
// Another connection is required
requiredConnections.push(args);
// Set the connection up
buildConnections();
}
// Client wants to fix broken search
socket.on('omegleUnlock', function() {
// No longer building the connection
buildingConnection = false;
// Try to build any remaining connections
buildConnections();
});
// Cleanup a client when they disconnect
socket.on('disconnect', function(){
for(var key in omegleClients) {
// Remove reference to it
delete omegleClients[key];
}
/*for(var key in cleverClients) {
if(cleverClients[key] != null) {
delete cleverClients[key];
}
}*/
});
// Client wants us to disconnect a stranger
socket.on('omegleDisconnect', function(client_id, painID) {
// Check if the client even exists
if(omegleClients[client_id] != null) {
// Disconnect it
omegleClients[client_id].disconnect();
// Delete it
omegleClients[client_id] = null;
}
// Remove any queued requests for this painID
for(var i=0;i<requiredConnections.length;i++) {
// Strip the solutions
if(requiredConnections[i].painID == painID) {
requiredConnections.splice(i--, 1);
}
}
// Are we dealing with a pain at the moment?
if(currentPain == painID) {
// No current pain anymore
currentPain = null;
// No longer building the connection
buildingConnection = false;
// Try to build any remaining connections
buildConnections();
}
});
// Client wants us to blackhole a stranger
socket.on('omegleBlackhole', function(client_id, painID) {
// Remove any queued requests for this painID
for(var i=0;i<requiredConnections.length;i++) {
// Strip the solutions
if(requiredConnections[i].painID == painID) {
requiredConnections.splice(i--, 1);
}
}
// Are we dealing with a pain at the moment?
if(currentPain == painID) {
// No current pain anymore
currentPain = null;
// No longer building the connection
buildingConnection = false;
// Try to build any remaining connections
buildConnections();
}
});
// Client wants to send a message to a stranger
socket.on('omegleSend', function(client_id, msg, callbackNum) {
var om = omegleClients[client_id];
// Check if the client even exists
if(om) {
// Send the message
om.send(msg, function(err) {
if (err) {
// Send to client
socket.emit('omegleError', om.args, 'Error sending: ' + err);
// Send callback
if(callbackNum) {
// Failure callback
socket.emit('omegleCallback', client_id, callbackNum, false);
}
} else {
// Send callback
if(callbackNum) {
// Success callback
socket.emit('omegleCallback', client_id, callbackNum, true);
}
}
});
}
});
// Client is trying to answer a captcha
socket.on('omegleChallenge', function(code, answer) {
var om = challenges[code];
if(om != null) {
om.recaptcha(answer);
}
});
// Client started typing
socket.on('omegleTyping', function(client_id) {
var om = omegleClients[client_id];
// Check if the client even exists
if(om) {
// Send the message
om.startTyping(function(err) {
if(err) {
// Send to client
socket.emit('omegleError', om.args, 'Error typing: ' + err);
}
});
}
});
// Client stopped typing
socket.on('omegleStopTyping', function(client_id) {
var om = omegleClients[client_id];
// Check if the client even exists
if(om) {
// Send the message
om.stopTyping(function(err) {
if(err) {
// Send to client
socket.emit('omegleError', om.args, 'Error stopping typing: ' + err);
}
});
}
});
// Client is asking for a new omegle client
socket.on('newOmegle', function(args){
// Check if we should force it or not
if(args.forceSearch) {
// Check if we are already building
if(buildingConnection) {
// Force build
makeConnection(args, false);
} else {
// Setup a new connection
setupNewConnection(args);
}
} else {
// Setup a new connection
setupNewConnection(args);
}
});
// Omegle logging feature
socket.on('omegleLog', function(cacheNumber, toCache) {
// Make the request
var postData = 'log=' + toCache + '&host=1';
// Debug mode
if(settings.debug) {
console.log('Requesting: http://logs.omegle.com/generate');
console.log(postData);
}
var postOptions = {
host: 'logs.omegle.com',
port: '80',
path: '/generate',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
},
agent:false
};
var allData = '';
var postRequest = http.request(postOptions, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
allData += chunk;
});
res.on('end', function() {
var leftIndexMarker = 'http://logs.Omegle.com/';
var leftIndex = allData.indexOf(leftIndexMarker);
var ret = '';
if(leftIndex != -1) {
var rightIndex = allData.indexOf('"', leftIndex + leftIndexMarker.length);
if(rightIndex != -1) {
ret = allData.substring(leftIndex, rightIndex);
}
}
socket.emit('omegleLog', cacheNumber, ret);
});
});
// post the data
postRequest.write(postData);
postRequest.end();
});
// Reconnects a client
socket.on('reconnectOmegle', function(args) {
// Attempt to reconnect
makeConnection(args, true);
});
// Client is asking for a new clever client
/*socket.on('newClever', function(args){
// Find the first free clientID
var i = 0;
while(cleverClients['clever'+(++i)] != null) {};
// Create the bot
cleverClients['clever'+i] = new Cleverbot();
// Forward the handler to them
socket.emit('newClever', 'clever'+i, args);
});
// Send a message to clever bot
socket.on('cleverSend', function(client_id, msg){
// Check if the client even exists
if(cleverClients[client_id]) {
// Send the message
cleverClients[client_id].write(msg, function(resp) {
// Forward message to our client
socket.emit('cleverGotMessage', client_id, resp['message']);
});
}
});*/
// Attempt to find a new proxy
function tryFindNewProxy(callback) {
if(!proxyEnabled) return;
request('http://gimmeproxy.com/api/getProxy?get=true&protocol=http', function(err, res, body) {
if(err) {
tryFindNewProxy(callback);
return;
}
try {
var data = JSON.parse(body);
var ip = data.ip;
var port = data.port;
if(ip && port) {
request('http://' + ip + ':' + port + '/', {timeout: 500}, function(err, res) {
if(err || res.statusCode >= 500) {
tryFindNewProxy(callback);
} else {
// Seems to be working
proxyInfo = {
ip: ip,
port: port
};
// Tell them their proxy is ready
socket.emit('proxyMessage', 'Routing intial connection through ' + ip + ':' + port + ' to avoid captcha!');
if(callback) {
callback(ip, port);
}
}
});
} else {
// Try again
tryFindNewProxy(callback)
}
} catch(e) {
// Try again?
tryFindNewProxy(callback)
}
});
}
// Find a new proxy
socket.on('newProxy', function() {
proxyEnabled = true;
// Tell them searching has begun
socket.emit('proxyMessage', 'Searching for a proxy to route initial connection through...');
// Try to find a new proxy
tryFindNewProxy();
});
// Disables proxy
socket.on('disableProxy', function() {
// Disable proxy
proxyEnabled = false;
// Tell them
socket.emit('proxyMessage', 'Captcha bypass turned off. No proxy will be used.');
})
});
var omeglePortNumber = 3000;
httpServer.listen(omeglePortNumber, function() {
console.log('Listening on port ' + omeglePortNumber + ', searching for omegle servers...');
});
// Run callback for when omegle is ready
Omegle.onReady(function(serverList) {
// Print out the server list
console.log('Found the following servers: ' + serverList.join(', ') + '\n\n' + Omegle.getSelectedServer() + ' was selected!\n');
console.log('Visit 127.0.0.1:' + omeglePortNumber + ' in your web browser to view the GUI.');
});
/*var test = new Sham();
test.start(function(err) {
console.log(err);
});
test.on('newid', function(client_id) {
console.log('Got a newID: ' + client_id);
});
*/