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.
Files changed (4) hide show
  1. package/index.js +277 -225
  2. package/package.json +3 -3
  3. package/deleted.js +0 -587
  4. 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
- 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((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
254
-
255
- arr = arr.filter(function(v) {
256
- return v.val && v.val.length;
257
- });
258
-
259
- var form = utils.arrToForm(arr);
260
- form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
261
- form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
262
- form.email = email;
263
- form.pass = password;
264
- form.default_persistent = '0';
265
- form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
266
- form.locale = 'en_US';
267
- form.timezone = '240';
268
- form.lgnjs = ~~(Date.now() / 1000);
269
-
270
-
271
- // Getting cookies from the HTML page... (kill me now plz)
272
- // we used to get a bunch of cookies in the headers of the response of the
273
- // request, but FB changed and they now send those cookies inside the JS.
274
- // They run the JS which then injects the cookies in the page.
275
- // The "solution" is to parse through the html and find those cookies
276
- // which happen to be conveniently indicated with a _js_ in front of their
277
- // variable name.
278
- //
279
- // ---------- Very Hacky Part Starts -----------------
280
- var willBeCookies = html.split("\"_js_");
281
- willBeCookies.slice(1).map(function(val) {
282
- var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
283
- jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
284
- });
285
- // ---------- Very Hacky Part Ends -----------------
286
-
287
- logger(Language.OnLogin, "[ FCA-SUS ]");
288
- return utils
289
- .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
290
- .then(utils.saveCookies(jar))
291
- .then(function(res) {
292
- var headers = res.headers;
293
- if (!headers.location) throw { error: Language.InvaildAccount };
294
-
295
- // This means the account has login approvals turned on.
296
- if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
297
- logger(Language.TwoAuth, "[ FCA-SUS ]");
298
- var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
299
-
300
- return utils
301
- .get(headers.location, jar, null, loginOptions)
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(function(res) {
304
- var html = res.body;
305
- // Make the form in advance which will contain the fb_dtsg and nh
306
- var $ = cheerio.load(html);
307
- var arr = [];
308
- $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
309
-
310
- arr = arr.filter(function(v) {
311
- return v.val && v.val.length;
312
- });
313
-
314
- var form = utils.arrToForm(arr);
315
- if (html.indexOf("checkpoint/?next") > -1) {
316
- setTimeout(() => {
317
- checkVerified = setInterval((_form) => {}, 5000, {
318
- fb_dtsg: form.fb_dtsg,
319
- jazoest: form.jazoest,
320
- dpr: 1
321
- });
322
- }, 2500);
323
- throw {
324
- error: 'login-approval',
325
- continue: function submit2FA(code) {
326
- form.approvals_code = code;
327
- form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
328
- var prResolve = null;
329
- var prReject = null;
330
- var rtPromise = new Promise(function(resolve, reject) {
331
- prResolve = resolve;
332
- prReject = reject;
333
- });
334
- if (typeof code == "string") {
335
- utils
336
- .post(nextURL, jar, form, loginOptions)
337
- .then(utils.saveCookies(jar))
338
- .then(function(res) {
339
- var $ = cheerio.load(res.body);
340
- var error = $("#approvals_code").parent().attr("data-xui-error");
341
- if (error) {
342
- throw {
343
- error: 'login-approval',
344
- errordesc: Language.InvaildTwoAuthCode,
345
- lerror: error,
346
- continue: submit2FA
347
- };
348
- }
349
- })
350
- .then(function() {
351
- // Use the same form (safe I hope)
352
- delete form.no_fido;
353
- delete form.approvals_code;
354
- form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
355
-
356
- return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
357
- })
358
- .then(function(res) {
359
- var headers = res.headers;
360
- if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
361
-
362
- var appState = utils.getAppState(jar);
363
-
364
- if (callback === prCallback) {
365
- callback = function(err, api) {
366
- if (err) return prReject(err);
367
- return prResolve(api);
368
- };
369
- }
370
-
371
- // Simply call loginHelper because all it needs is the jar
372
- // and will then complete the login process
373
- return loginHelper(appState, email, password, loginOptions, callback);
374
- })
375
- .catch(function(err) {
376
- // Check if using Promise instead of callback
377
- if (callback === prCallback) prReject(err);
378
- else callback(err);
379
- });
380
- } else {
381
- utils
382
- .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, { "Referer": "https://www.facebook.com/checkpoint/?next" })
383
- .then(utils.saveCookies(jar))
384
- .then(res => {
385
- try {
386
- JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
387
- } catch (ex) {
388
- clearInterval(checkVerified);
389
- logger(Language.VerifiedCheck, "[ FCA-SUS ]");
390
- if (callback === prCallback) {
391
- callback = function(err, api) {
392
- if (err) return prReject(err);
393
- return prResolve(api);
394
- };
395
- }
396
- return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
397
- }
398
- })
399
- .catch(ex => {
400
- log.error("login", ex);
401
- if (callback === prCallback) prReject(ex);
402
- else callback(ex);
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
- if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
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
- return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
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
- callback = options;
542
- options = {};
593
+ callback = options;
594
+ options = {};
543
595
  }
544
-
596
+
545
597
  var globalOptions = {
546
- selfListen: false,
547
- listenEvents: true,
548
- listenTyping: false,
549
- updatePresence: false,
550
- forceLogin: false,
551
- autoMarkDelivery: false,
552
- autoMarkRead: false,
553
- autoReconnect: true,
554
- logRecordSize: 100,
555
- online: false,
556
- emitReady: false,
557
- 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"
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
- var rejectFunc = null;
568
- var resolveFunc = null;
569
- var returnPromise = new Promise(function(resolve, reject) {
570
- resolveFunc = resolve;
571
- rejectFunc = reject;
572
- });
573
- prCallback = function(error, api) {
574
- if (error) return rejectFunc(error);
575
- return resolveFunc(api);
576
- };
577
- callback = prCallback;
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.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": "latest",
29
+ "better-sqlite3": "^8.2.0",
30
30
  "bluebird": "^2.11.0",
31
31
  "chalk": "^4.1.2",
32
32
  "cheerio": "latest",