node-ainzfb-new 1.4.4 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +277 -225
- package/package.json +3 -3
- package/deleted.js +0 -587
- package/index-backup.js +0 -1089
package/index.js
CHANGED
@@ -244,202 +244,254 @@ async function buildAPI(globalOptions, html, jar) {
|
|
244
244
|
}
|
245
245
|
|
246
246
|
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
247
|
-
return function(res) {
|
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
|
-
|
247
|
+
return function (res) {
|
248
|
+
var html = res.body;
|
249
|
+
var $ = cheerio.load(html);
|
250
|
+
var arr = [];
|
251
|
+
|
252
|
+
// This will be empty, but just to be sure we leave it
|
253
|
+
$("#login_form input").map(function (i, v) {
|
254
|
+
arr.push({ val: $(v).val(), name: $(v).attr("name") });
|
255
|
+
});
|
256
|
+
|
257
|
+
arr = arr.filter(function (v) {
|
258
|
+
return v.val && v.val.length;
|
259
|
+
});
|
260
|
+
|
261
|
+
var form = utils.arrToForm(arr);
|
262
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
263
|
+
form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
|
264
|
+
form.email = email;
|
265
|
+
form.pass = password;
|
266
|
+
form.default_persistent = '0';
|
267
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
268
|
+
form.locale = 'en_US';
|
269
|
+
form.timezone = '240';
|
270
|
+
form.lgnjs = ~~(Date.now() / 1000);
|
271
|
+
|
272
|
+
|
273
|
+
// Getting cookies from the HTML page... (kill me now plz)
|
274
|
+
// we used to get a bunch of cookies in the headers of the response of the
|
275
|
+
// request, but FB changed and they now send those cookies inside the JS.
|
276
|
+
// They run the JS which then injects the cookies in the page.
|
277
|
+
// The "solution" is to parse through the html and find those cookies
|
278
|
+
// which happen to be conveniently indicated with a _js_ in front of their
|
279
|
+
// variable name.
|
280
|
+
//
|
281
|
+
// ---------- Very Hacky Part Starts -----------------
|
282
|
+
var willBeCookies = html.split("\"_js_");
|
283
|
+
willBeCookies.slice(1).map(function (val) {
|
284
|
+
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
285
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
286
|
+
});
|
287
|
+
// ---------- Very Hacky Part Ends -----------------
|
288
|
+
|
289
|
+
log.info("login", "Logging in...");
|
290
|
+
return utils
|
291
|
+
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
292
|
+
.then(utils.saveCookies(jar))
|
293
|
+
.then(function (res) {
|
294
|
+
var headers = res.headers;
|
295
|
+
if (!headers.location) {
|
296
|
+
throw { error: "Wrong username/password." };
|
297
|
+
}
|
298
|
+
|
299
|
+
// This means the account has login approvals turned on.
|
300
|
+
if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
|
301
|
+
log.info("login", "You have login approvals turned on.");
|
302
|
+
var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
|
303
|
+
|
304
|
+
return utils
|
305
|
+
.get(headers.location, jar, null, loginOptions)
|
306
|
+
.then(utils.saveCookies(jar))
|
307
|
+
.then(function (res) {
|
308
|
+
var html = res.body;
|
309
|
+
// Make the form in advance which will contain the fb_dtsg and nh
|
310
|
+
var $ = cheerio.load(html);
|
311
|
+
var arr = [];
|
312
|
+
$("form input").map(function (i, v) {
|
313
|
+
arr.push({ val: $(v).val(), name: $(v).attr("name") });
|
314
|
+
});
|
315
|
+
|
316
|
+
arr = arr.filter(function (v) {
|
317
|
+
return v.val && v.val.length;
|
318
|
+
});
|
319
|
+
|
320
|
+
var form = utils.arrToForm(arr);
|
321
|
+
if (html.indexOf("checkpoint/?next") > -1) {
|
322
|
+
setTimeout(() => {
|
323
|
+
checkVerified = setInterval((_form) => {
|
324
|
+
/* utils
|
325
|
+
.post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
|
326
|
+
"Referer": "https://www.facebook.com/checkpoint/?next"
|
327
|
+
})
|
302
328
|
.then(utils.saveCookies(jar))
|
303
|
-
.then(
|
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
|
-
return rtPromise;
|
406
|
-
}
|
329
|
+
.then(res => {
|
330
|
+
try {
|
331
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
|
332
|
+
} catch (ex) {
|
333
|
+
clearInterval(checkVerified);
|
334
|
+
log.info("login", "Verified from browser. Logging in...");
|
335
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
336
|
+
}
|
337
|
+
})
|
338
|
+
.catch(ex => {
|
339
|
+
log.error("login", ex);
|
340
|
+
}); */
|
341
|
+
}, 5000, {
|
342
|
+
fb_dtsg: form.fb_dtsg,
|
343
|
+
jazoest: form.jazoest,
|
344
|
+
dpr: 1
|
345
|
+
});
|
346
|
+
}, 2500);
|
347
|
+
throw {
|
348
|
+
error: 'login-approval',
|
349
|
+
continue: function submit2FA(code) {
|
350
|
+
form.approvals_code = code;
|
351
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
352
|
+
var prResolve = null;
|
353
|
+
var prReject = null;
|
354
|
+
var rtPromise = new Promise(function (resolve, reject) {
|
355
|
+
prResolve = resolve;
|
356
|
+
prReject = reject;
|
357
|
+
});
|
358
|
+
if (typeof code == "string") {
|
359
|
+
utils
|
360
|
+
.post(nextURL, jar, form, loginOptions)
|
361
|
+
.then(utils.saveCookies(jar))
|
362
|
+
.then(function (res) {
|
363
|
+
var $ = cheerio.load(res.body);
|
364
|
+
var error = $("#approvals_code").parent().attr("data-xui-error");
|
365
|
+
if (error) {
|
366
|
+
throw {
|
367
|
+
error: 'login-approval',
|
368
|
+
errordesc: "Invalid 2FA code.",
|
369
|
+
lerror: error,
|
370
|
+
continue: submit2FA
|
371
|
+
};
|
372
|
+
}
|
373
|
+
})
|
374
|
+
.then(function () {
|
375
|
+
// Use the same form (safe I hope)
|
376
|
+
delete form.no_fido;
|
377
|
+
delete form.approvals_code;
|
378
|
+
form.name_action_selected = 'dont_save'; //'save_device';
|
379
|
+
|
380
|
+
return utils
|
381
|
+
.post(nextURL, jar, form, loginOptions)
|
382
|
+
.then(utils.saveCookies(jar));
|
383
|
+
})
|
384
|
+
.then(function (res) {
|
385
|
+
var headers = res.headers;
|
386
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
387
|
+
throw { error: "Something went wrong with login approvals." };
|
388
|
+
}
|
389
|
+
|
390
|
+
var appState = utils.getAppState(jar);
|
391
|
+
|
392
|
+
if (callback === prCallback) {
|
393
|
+
callback = function (err, api) {
|
394
|
+
if (err) {
|
395
|
+
return prReject(err);
|
396
|
+
}
|
397
|
+
return prResolve(api);
|
398
|
+
};
|
399
|
+
}
|
400
|
+
|
401
|
+
// Simply call loginHelper because all it needs is the jar
|
402
|
+
// and will then complete the login process
|
403
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
404
|
+
})
|
405
|
+
.catch(function (err) {
|
406
|
+
// Check if using Promise instead of callback
|
407
|
+
if (callback === prCallback) {
|
408
|
+
prReject(err);
|
409
|
+
} else {
|
410
|
+
callback(err);
|
411
|
+
}
|
412
|
+
});
|
413
|
+
} else {
|
414
|
+
utils
|
415
|
+
.post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, {
|
416
|
+
"Referer": "https://www.facebook.com/checkpoint/?next"
|
417
|
+
})
|
418
|
+
.then(utils.saveCookies(jar))
|
419
|
+
.then(res => {
|
420
|
+
try {
|
421
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
422
|
+
} catch (ex) {
|
423
|
+
clearInterval(checkVerified);
|
424
|
+
log.info("login", "Verified from browser. Logging in...");
|
425
|
+
if (callback === prCallback) {
|
426
|
+
callback = function (err, api) {
|
427
|
+
if (err) {
|
428
|
+
return prReject(err);
|
429
|
+
}
|
430
|
+
return prResolve(api);
|
407
431
|
};
|
432
|
+
}
|
433
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
434
|
+
}
|
435
|
+
})
|
436
|
+
.catch(ex => {
|
437
|
+
log.error("login", ex);
|
438
|
+
if (callback === prCallback) {
|
439
|
+
prReject(ex);
|
408
440
|
} else {
|
409
|
-
|
410
|
-
|
411
|
-
if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
|
412
|
-
else form['submit[This Is Okay]'] = "This Is Okay";
|
413
|
-
|
414
|
-
return utils
|
415
|
-
.post(nextURL, jar, form, loginOptions)
|
416
|
-
.then(utils.saveCookies(jar))
|
417
|
-
.then(function() {
|
418
|
-
// Use the same form (safe I hope)
|
419
|
-
form.name_action_selected = 'save_device';
|
420
|
-
|
421
|
-
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
422
|
-
})
|
423
|
-
.then(function(res) {
|
424
|
-
var headers = res.headers;
|
425
|
-
|
426
|
-
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
|
427
|
-
|
428
|
-
var appState = utils.getAppState(jar);
|
429
|
-
|
430
|
-
// Simply call loginHelper because all it needs is the jar
|
431
|
-
// and will then complete the login process
|
432
|
-
return loginHelper(appState, email, password, loginOptions, callback);
|
433
|
-
})
|
434
|
-
.catch(e => callback(e));
|
441
|
+
callback(ex);
|
435
442
|
}
|
436
|
-
|
443
|
+
});
|
444
|
+
}
|
445
|
+
return rtPromise;
|
446
|
+
}
|
447
|
+
};
|
448
|
+
} else {
|
449
|
+
if (!loginOptions.forceLogin) {
|
450
|
+
throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
|
451
|
+
}
|
452
|
+
if (html.indexOf("Suspicious Login Attempt") > -1) {
|
453
|
+
form['submit[This was me]'] = "This was me";
|
454
|
+
} else {
|
455
|
+
form['submit[This Is Okay]'] = "This Is Okay";
|
456
|
+
}
|
457
|
+
|
458
|
+
return utils
|
459
|
+
.post(nextURL, jar, form, loginOptions)
|
460
|
+
.then(utils.saveCookies(jar))
|
461
|
+
.then(function () {
|
462
|
+
// Use the same form (safe I hope)
|
463
|
+
form.name_action_selected = 'save_device';
|
464
|
+
|
465
|
+
return utils
|
466
|
+
.post(nextURL, jar, form, loginOptions)
|
467
|
+
.then(utils.saveCookies(jar));
|
468
|
+
})
|
469
|
+
.then(function (res) {
|
470
|
+
var headers = res.headers;
|
471
|
+
|
472
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
473
|
+
throw { error: "Something went wrong with review recent login." };
|
474
|
+
}
|
475
|
+
|
476
|
+
var appState = utils.getAppState(jar);
|
477
|
+
|
478
|
+
// Simply call loginHelper because all it needs is the jar
|
479
|
+
// and will then complete the login process
|
480
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
481
|
+
})
|
482
|
+
.catch(function (e) {
|
483
|
+
callback(e);
|
484
|
+
});
|
437
485
|
}
|
438
|
-
|
439
|
-
|
440
|
-
|
486
|
+
});
|
487
|
+
}
|
488
|
+
|
489
|
+
return utils
|
490
|
+
.get('https://www.facebook.com/', jar, null, loginOptions)
|
491
|
+
.then(utils.saveCookies(jar));
|
492
|
+
});
|
441
493
|
};
|
442
|
-
}
|
494
|
+
}
|
443
495
|
|
444
496
|
function makeid(length) {
|
445
497
|
var result = '';
|
@@ -536,48 +588,48 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
536
588
|
});
|
537
589
|
}
|
538
590
|
|
539
|
-
function login(loginData, options, callback) {
|
591
|
+
function login(loginData, options, callback) {
|
540
592
|
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
541
|
-
|
542
|
-
|
593
|
+
callback = options;
|
594
|
+
options = {};
|
543
595
|
}
|
544
|
-
|
596
|
+
|
545
597
|
var globalOptions = {
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
598
|
+
selfListen: false,
|
599
|
+
listenEvents: false,
|
600
|
+
listenTyping: false,
|
601
|
+
updatePresence: false,
|
602
|
+
forceLogin: false,
|
603
|
+
autoMarkDelivery: true,
|
604
|
+
autoMarkRead: false,
|
605
|
+
autoReconnect: true,
|
606
|
+
logRecordSize: defaultLogRecordSize,
|
607
|
+
online: true,
|
608
|
+
emitReady: false,
|
609
|
+
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
|
558
610
|
};
|
559
|
-
|
560
|
-
//! bằng 1 cách nào đó tắt online sẽ đánh lừa được facebook :v
|
561
|
-
//! phải có that có this chứ :v
|
562
|
-
|
611
|
+
|
563
612
|
setOptions(globalOptions, options);
|
564
|
-
|
613
|
+
|
565
614
|
var prCallback = null;
|
566
615
|
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
}
|
577
|
-
|
616
|
+
var rejectFunc = null;
|
617
|
+
var resolveFunc = null;
|
618
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
619
|
+
resolveFunc = resolve;
|
620
|
+
rejectFunc = reject;
|
621
|
+
});
|
622
|
+
prCallback = function (error, api) {
|
623
|
+
if (error) {
|
624
|
+
return rejectFunc(error);
|
625
|
+
}
|
626
|
+
return resolveFunc(api);
|
627
|
+
};
|
628
|
+
callback = prCallback;
|
578
629
|
}
|
579
630
|
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
580
631
|
return returnPromise;
|
581
|
-
}
|
582
|
-
|
583
|
-
module.exports = login;
|
632
|
+
}
|
633
|
+
|
634
|
+
module.exports = login;
|
635
|
+
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.7",
|
4
4
|
"description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
|
5
5
|
"scripts": {
|
6
6
|
"test": "mocha",
|
@@ -23,10 +23,10 @@
|
|
23
23
|
"author": "Avery, David, Maude, Benjamin, Kanzu",
|
24
24
|
"license": "MIT",
|
25
25
|
"dependencies": {
|
26
|
-
"@replit/database": "2.0.2",
|
26
|
+
"@replit/database": "^2.0.2",
|
27
27
|
"aes-js": "latest",
|
28
28
|
"assert": "latest",
|
29
|
-
"better-sqlite3": "
|
29
|
+
"better-sqlite3": "^8.2.0",
|
30
30
|
"bluebird": "^2.11.0",
|
31
31
|
"chalk": "^4.1.2",
|
32
32
|
"cheerio": "latest",
|