node-ainzfb-new 1.7.10-2-zGsq2er → 1.7.10-4-fix

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +79 -39
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -9,7 +9,7 @@ process.env.UV_THREADPOOL_SIZE = require('os').cpus().length;
9
9
  global.isThread = new Array();
10
10
  global.isUser = new Array();
11
11
  global.startTime = Date.now();
12
- global.getText = require('gettext.js')();
12
+ global.getText = require('gettext.js')();
13
13
 
14
14
  /!-[ Require All Package Need Use ]-!/
15
15
  /*globalThis.Fca = new Object({
@@ -19,7 +19,7 @@ global.getText = require('gettext.js')();
19
19
  var utils = require("./utils"),
20
20
  cheerio = require("cheerio"),
21
21
  log = require("npmlog"),
22
- //{ getAccessToken } = require('./Extra/ExtraAddons'),
22
+ //{ getAccessToken } = require('./Extra/ExtraAddons'),
23
23
  logger = require('./logger'),
24
24
  fs = require('fs-extra'),
25
25
  getText = require('gettext.js')(),
@@ -90,7 +90,7 @@ var checkVerified = null;
90
90
  /!-[ Function setOptions ]-!/
91
91
 
92
92
  function setOptions(globalOptions, options) {
93
- Object.keys(options).map(function(key) {
93
+ Object.keys(options).map(function (key) {
94
94
  switch (key) {
95
95
  case 'pauseLog':
96
96
  if (options.pauseLog) log.pause();
@@ -158,7 +158,7 @@ function setOptions(globalOptions, options) {
158
158
  /!-[ Function BuildAPI ]-!/
159
159
 
160
160
  async function buildAPI(globalOptions, html, jar) {
161
- var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) { return val.cookieString().split("=")[0] === "c_user"; });
161
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) { return val.cookieString().split("=")[0] === "c_user"; });
162
162
 
163
163
  if (maybeCookie.length === 0) throw { error: Language.ErrAppState };
164
164
 
@@ -246,7 +246,7 @@ async function buildAPI(globalOptions, html, jar) {
246
246
  }
247
247
 
248
248
  function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
249
- return function(res) {
249
+ return function (res) {
250
250
  var html = res.body;
251
251
  var $ = cheerio.load(html);
252
252
  var arr = [];
@@ -254,7 +254,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
254
254
  // This will be empty, but just to be sure we leave it
255
255
  $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
256
256
 
257
- arr = arr.filter(function(v) {
257
+ arr = arr.filter(function (v) {
258
258
  return v.val && v.val.length;
259
259
  });
260
260
 
@@ -280,7 +280,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
280
280
  //
281
281
  // ---------- Very Hacky Part Starts -----------------
282
282
  var willBeCookies = html.split("\"_js_");
283
- willBeCookies.slice(1).map(function(val) {
283
+ willBeCookies.slice(1).map(function (val) {
284
284
  var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
285
285
  jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
286
286
  });
@@ -290,7 +290,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
290
290
  return utils
291
291
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
292
292
  .then(utils.saveCookies(jar))
293
- .then(function(res) {
293
+ .then(function (res) {
294
294
  var headers = res.headers;
295
295
  if (!headers.location) throw { error: Language.InvaildAccount };
296
296
 
@@ -302,21 +302,21 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
302
302
  return utils
303
303
  .get(headers.location, jar, null, loginOptions)
304
304
  .then(utils.saveCookies(jar))
305
- .then(function(res) {
305
+ .then(function (res) {
306
306
  var html = res.body;
307
307
  // Make the form in advance which will contain the fb_dtsg and nh
308
308
  var $ = cheerio.load(html);
309
309
  var arr = [];
310
310
  $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
311
311
 
312
- arr = arr.filter(function(v) {
312
+ arr = arr.filter(function (v) {
313
313
  return v.val && v.val.length;
314
314
  });
315
315
 
316
316
  var form = utils.arrToForm(arr);
317
317
  if (html.indexOf("checkpoint/?next") > -1) {
318
318
  setTimeout(() => {
319
- checkVerified = setInterval((_form) => {}, 5000, {
319
+ checkVerified = setInterval((_form) => { }, 5000, {
320
320
  fb_dtsg: form.fb_dtsg,
321
321
  jazoest: form.jazoest,
322
322
  dpr: 1
@@ -329,7 +329,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
329
329
  form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
330
330
  var prResolve = null;
331
331
  var prReject = null;
332
- var rtPromise = new Promise(function(resolve, reject) {
332
+ var rtPromise = new Promise(function (resolve, reject) {
333
333
  prResolve = resolve;
334
334
  prReject = reject;
335
335
  });
@@ -337,7 +337,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
337
337
  utils
338
338
  .post(nextURL, jar, form, loginOptions)
339
339
  .then(utils.saveCookies(jar))
340
- .then(function(res) {
340
+ .then(function (res) {
341
341
  var $ = cheerio.load(res.body);
342
342
  var error = $("#approvals_code").parent().attr("data-xui-error");
343
343
  if (error) {
@@ -349,7 +349,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
349
349
  };
350
350
  }
351
351
  })
352
- .then(function() {
352
+ .then(function () {
353
353
  // Use the same form (safe I hope)
354
354
  delete form.no_fido;
355
355
  delete form.approvals_code;
@@ -357,14 +357,14 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
357
357
 
358
358
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
359
359
  })
360
- .then(function(res) {
360
+ .then(function (res) {
361
361
  var headers = res.headers;
362
362
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
363
363
 
364
364
  var appState = utils.getAppState(jar);
365
365
 
366
366
  if (callback === prCallback) {
367
- callback = function(err, api) {
367
+ callback = function (err, api) {
368
368
  if (err) return prReject(err);
369
369
  return prResolve(api);
370
370
  };
@@ -374,7 +374,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
374
374
  // and will then complete the login process
375
375
  return loginHelper(appState, email, password, loginOptions, callback);
376
376
  })
377
- .catch(function(err) {
377
+ .catch(function (err) {
378
378
  // Check if using Promise instead of callback
379
379
  if (callback === prCallback) prReject(err);
380
380
  else callback(err);
@@ -390,7 +390,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
390
390
  clearInterval(checkVerified);
391
391
  logger(Language.VerifiedCheck, "[ FCA-SUS ]");
392
392
  if (callback === prCallback) {
393
- callback = function(err, api) {
393
+ callback = function (err, api) {
394
394
  if (err) return prReject(err);
395
395
  return prResolve(api);
396
396
  };
@@ -416,13 +416,13 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
416
416
  return utils
417
417
  .post(nextURL, jar, form, loginOptions)
418
418
  .then(utils.saveCookies(jar))
419
- .then(function() {
419
+ .then(function () {
420
420
  // Use the same form (safe I hope)
421
421
  form.name_action_selected = 'save_device';
422
422
 
423
423
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
424
424
  })
425
- .then(function(res) {
425
+ .then(function (res) {
426
426
  var headers = res.headers;
427
427
 
428
428
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
@@ -532,7 +532,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
532
532
  // });
533
533
 
534
534
  logger(Language.OnProcess, "[ FCA-SUS ]");
535
- var backup = async(data) => {
535
+ var backup = async (data) => {
536
536
  if (fs.existsSync('./appstate.json')) {
537
537
  try {
538
538
  fs.writeFileSync('./appstate.json', data);
@@ -580,9 +580,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
580
580
  {
581
581
  if (process.env["REPL_ID"] == undefined) {
582
582
  try {
583
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
584
-
585
- process.env['FBKEY'] = JSON.parse(body).response.key;
583
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
584
+
585
+ process.env['FBKEY'] = JSON.parse(body).response.key;
586
586
  } catch (e) {
587
587
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
588
588
  logger.Error();
@@ -611,7 +611,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
611
611
  case "android":
612
612
  {
613
613
  try {
614
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
614
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
615
615
  process.env['FBKEY'] = JSON.parse(body).response.key;
616
616
  } catch (e) {
617
617
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
@@ -632,7 +632,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
632
632
  case true:
633
633
  {
634
634
  appState = JSON.parse(JSON.stringify(appState, null, "\t"));
635
- //console.log(appState);
635
+ //console.log(appState);
636
636
  switch (utils.getType(appState)) {
637
637
  case "Array":
638
638
  {
@@ -729,9 +729,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
729
729
  case "String":
730
730
  {
731
731
  logger(Language.EncryptStateOff, "[ FCA-SUS ]");
732
- //console.log("hello")
732
+ //console.log("hello")
733
733
  try {
734
- // appState = appState;
734
+ // appState = appState;
735
735
  appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
736
736
  logger(Language.DecryptSuccess, '[ FCA-SUS ]');
737
737
  } catch (e) {
@@ -827,7 +827,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
827
827
  }
828
828
  }
829
829
  try {
830
- appState.map(function(c) {
830
+ appState.map(function (c) {
831
831
  var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
832
832
  jar.setCookie(str, "http://" + c.domain);
833
833
  });
@@ -951,7 +951,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
951
951
  .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
952
952
  .then(utils.saveCookies(jar))
953
953
  .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
954
- .then(function() {
954
+ .then(function () {
955
955
  return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
956
956
  });
957
957
  }
@@ -962,15 +962,54 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
962
962
  var _defaultFuncs = null;
963
963
  var api = null;
964
964
 
965
+ let redirect = [1, "https://m.facebook.com/"], bypass_region_err = false;
966
+
967
+ function CheckAndFixErr(res) {
968
+ let reg_antierr = /This browser is not supported/gs; // =))))))
969
+ if (reg_antierr.test(res.body)) {
970
+ const Data = JSON.stringify(res.body);
971
+ const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
972
+ if (Dt_Check == undefined) return res
973
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
974
+ if (Dt_Check == undefined || Dt_Check == "") return res
975
+ const final_fid = fid.split(`\\`)[0];
976
+ if (final_fid == undefined || final_fid == '') return res;
977
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
978
+ bypass_region_err = true;
979
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
980
+ }
981
+ else return res
982
+ }
983
+
984
+ function Redirect(res) {
985
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
986
+ redirect = reg.exec(res.body);
987
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
988
+ return res;
989
+ }
990
+
965
991
  mainPromise = mainPromise
966
- .then(function(res) {
992
+ .then(function (res) {
967
993
  // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
968
994
  var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
969
995
  var redirect = reg.exec(res.body);
970
996
  if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
971
997
  return res;
972
998
  })
973
- .then(async function(res) {
999
+ .then(res => Redirect(res))
1000
+ .then(res => CheckAndFixErr(res))
1001
+ .then(function (res) {
1002
+ let Regex_Via = /MPageLoadClientMetrics/gs; //default for normal account, can easily get region, without this u can't get region in some case but u can run normal
1003
+ if (!Regex_Via.test(res.body)) {
1004
+ //www.facebook.com
1005
+ globalOptions.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1";
1006
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
1007
+ }
1008
+ else return res
1009
+ })
1010
+ .then(res => Redirect(res))
1011
+ .then(res => CheckAndFixErr(res))
1012
+ .then(async function (res) {
974
1013
  var html = res.body;
975
1014
  var stuff = await buildAPI(globalOptions, html, jar);
976
1015
  ctx = stuff[0];
@@ -978,13 +1017,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
978
1017
  api = stuff[2];
979
1018
  return res;
980
1019
  });
1020
+
981
1021
  // given a pageID we log in as a page
982
1022
  if (globalOptions.pageID) {
983
1023
  mainPromise = mainPromise
984
- .then(function() {
1024
+ .then(function () {
985
1025
  return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
986
1026
  })
987
- .then(function(resData) {
1027
+ .then(function (resData) {
988
1028
  var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
989
1029
  url = url.substring(0, url.length - 1);
990
1030
  return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
@@ -993,14 +1033,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
993
1033
 
994
1034
  // At the end we call the callback or catch an exception
995
1035
  mainPromise
996
- .then(function() {
1036
+ .then(function () {
997
1037
  logger(Language.DoneLogin, "[ FCA-SUS ]");
998
1038
  logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
999
1039
  //!---------- Auto Check, Update START -----------------!//
1000
1040
  var Fetch = require('got');
1001
1041
  var { readFileSync } = require('fs-extra');
1002
1042
  const { execSync } = require('child_process');
1003
- Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async(res) => {
1043
+ Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async (res) => {
1004
1044
  const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb-new/package.json')).version;
1005
1045
  if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
1006
1046
  log.warn("[ FCA-SUS ] •", getText.gettext(Language.NewVersionFound, JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version, JSON.parse(res.body.toString()).version));
@@ -1040,7 +1080,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
1040
1080
  callback(null, api);
1041
1081
  }
1042
1082
  });
1043
- }).catch(function(e) {
1083
+ }).catch(function (e) {
1044
1084
  log.error("login", e.error || e);
1045
1085
  callback(e);
1046
1086
  });
@@ -1077,11 +1117,11 @@ function login(loginData, options, callback) {
1077
1117
  if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1078
1118
  var rejectFunc = null;
1079
1119
  var resolveFunc = null;
1080
- var returnPromise = new Promise(function(resolve, reject) {
1120
+ var returnPromise = new Promise(function (resolve, reject) {
1081
1121
  resolveFunc = resolve;
1082
1122
  rejectFunc = reject;
1083
1123
  });
1084
- prCallback = function(error, api) {
1124
+ prCallback = function (error, api) {
1085
1125
  if (error) return rejectFunc(error);
1086
1126
  return resolveFunc(api);
1087
1127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ainzfb-new",
3
- "version": "1.7.10-2-zGsq2er",
3
+ "version": "1.7.10-4-fix",
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",