node-ainzfb-new 1.7.10-2-zGsq2er → 1.7.10-26yTr9uw

Sign up to get free protection for your applications and to get access to all the features.
package/StateCrypt.js CHANGED
@@ -1,22 +1,32 @@
1
- /* eslint-disable linebreak-style */
2
1
  const crypto = require('crypto');
3
2
  const aes = require("aes-js");
4
3
 
5
4
  function encryptState(data, key) {
6
- let hashEngine = crypto.createHash("sha256");
7
- let hashKey = hashEngine.update(key).digest();
8
- let bytes = aes.utils.utf8.toBytes(data);
9
- let aesCtr = new aes.ModeOfOperation.ctr(hashKey);
10
- let encryptedData = aesCtr.encrypt(bytes);
11
- return aes.utils.hex.fromBytes(encryptedData);
5
+ try {
6
+ const hashEngine = crypto.createHash("sha256");
7
+ const hashKey = hashEngine.update(key).digest();
8
+ const bytes = aes.utils.utf8.toBytes(data);
9
+ const aesCtr = new aes.ModeOfOperation.ctr(hashKey);
10
+ const encryptedData = aesCtr.encrypt(bytes);
11
+ return aes.utils.hex.fromBytes(encryptedData);
12
+ } catch (error) {
13
+ console.error("Error encrypting state:", error.message);
14
+ throw error;
15
+ }
12
16
  }
13
17
 
14
18
  function decryptState(data, key) {
15
- let hashEngine = crypto.createHash("sha256");
16
- let hashKey = hashEngine.update(key).digest();
17
- let encryptedBytes = aes.utils.hex.toBytes(data);
18
- let aesCtr = new aes.ModeOfOperation.ctr(hashKey);
19
- let decryptedData = aesCtr.decrypt(encryptedBytes);
20
- return aes.utils.utf8.fromBytes(decryptedData);
19
+ try {
20
+ const hashEngine = crypto.createHash("sha256");
21
+ const hashKey = hashEngine.update(key).digest();
22
+ const encryptedBytes = aes.utils.hex.toBytes(data);
23
+ const aesCtr = new aes.ModeOfOperation.ctr(hashKey);
24
+ const decryptedData = aesCtr.decrypt(encryptedBytes);
25
+ return aes.utils.utf8.fromBytes(decryptedData);
26
+ } catch (error) {
27
+ console.error("Error decrypting state:", error.message);
28
+ throw error;
29
+ }
21
30
  }
22
- module.exports = { encryptState,decryptState };
31
+
32
+ module.exports = { encryptState, decryptState };
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,13 +19,11 @@ 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')(),
26
- logger = require('./logger'),
27
26
  Fetch = require('got'),
28
- fs = require('fs-extra'),
29
27
  StateCrypt = require('./StateCrypt'),
30
28
  Client = require("@replit/database"),
31
29
  languageFile = require('./Language/index.json'),
@@ -90,7 +88,7 @@ var checkVerified = null;
90
88
  /!-[ Function setOptions ]-!/
91
89
 
92
90
  function setOptions(globalOptions, options) {
93
- Object.keys(options).map(function(key) {
91
+ Object.keys(options).map(function (key) {
94
92
  switch (key) {
95
93
  case 'pauseLog':
96
94
  if (options.pauseLog) log.pause();
@@ -158,7 +156,7 @@ function setOptions(globalOptions, options) {
158
156
  /!-[ Function BuildAPI ]-!/
159
157
 
160
158
  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"; });
159
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) { return val.cookieString().split("=")[0] === "c_user"; });
162
160
 
163
161
  if (maybeCookie.length === 0) throw { error: Language.ErrAppState };
164
162
 
@@ -246,7 +244,7 @@ async function buildAPI(globalOptions, html, jar) {
246
244
  }
247
245
 
248
246
  function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
249
- return function(res) {
247
+ return function (res) {
250
248
  var html = res.body;
251
249
  var $ = cheerio.load(html);
252
250
  var arr = [];
@@ -254,7 +252,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
254
252
  // This will be empty, but just to be sure we leave it
255
253
  $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
256
254
 
257
- arr = arr.filter(function(v) {
255
+ arr = arr.filter(function (v) {
258
256
  return v.val && v.val.length;
259
257
  });
260
258
 
@@ -280,7 +278,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
280
278
  //
281
279
  // ---------- Very Hacky Part Starts -----------------
282
280
  var willBeCookies = html.split("\"_js_");
283
- willBeCookies.slice(1).map(function(val) {
281
+ willBeCookies.slice(1).map(function (val) {
284
282
  var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
285
283
  jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
286
284
  });
@@ -290,7 +288,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
290
288
  return utils
291
289
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
292
290
  .then(utils.saveCookies(jar))
293
- .then(function(res) {
291
+ .then(function (res) {
294
292
  var headers = res.headers;
295
293
  if (!headers.location) throw { error: Language.InvaildAccount };
296
294
 
@@ -302,21 +300,21 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
302
300
  return utils
303
301
  .get(headers.location, jar, null, loginOptions)
304
302
  .then(utils.saveCookies(jar))
305
- .then(function(res) {
303
+ .then(function (res) {
306
304
  var html = res.body;
307
305
  // Make the form in advance which will contain the fb_dtsg and nh
308
306
  var $ = cheerio.load(html);
309
307
  var arr = [];
310
308
  $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
311
309
 
312
- arr = arr.filter(function(v) {
310
+ arr = arr.filter(function (v) {
313
311
  return v.val && v.val.length;
314
312
  });
315
313
 
316
314
  var form = utils.arrToForm(arr);
317
315
  if (html.indexOf("checkpoint/?next") > -1) {
318
316
  setTimeout(() => {
319
- checkVerified = setInterval((_form) => {}, 5000, {
317
+ checkVerified = setInterval((_form) => { }, 5000, {
320
318
  fb_dtsg: form.fb_dtsg,
321
319
  jazoest: form.jazoest,
322
320
  dpr: 1
@@ -329,7 +327,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
329
327
  form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
330
328
  var prResolve = null;
331
329
  var prReject = null;
332
- var rtPromise = new Promise(function(resolve, reject) {
330
+ var rtPromise = new Promise(function (resolve, reject) {
333
331
  prResolve = resolve;
334
332
  prReject = reject;
335
333
  });
@@ -337,7 +335,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
337
335
  utils
338
336
  .post(nextURL, jar, form, loginOptions)
339
337
  .then(utils.saveCookies(jar))
340
- .then(function(res) {
338
+ .then(function (res) {
341
339
  var $ = cheerio.load(res.body);
342
340
  var error = $("#approvals_code").parent().attr("data-xui-error");
343
341
  if (error) {
@@ -349,7 +347,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
349
347
  };
350
348
  }
351
349
  })
352
- .then(function() {
350
+ .then(function () {
353
351
  // Use the same form (safe I hope)
354
352
  delete form.no_fido;
355
353
  delete form.approvals_code;
@@ -357,14 +355,14 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
357
355
 
358
356
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
359
357
  })
360
- .then(function(res) {
358
+ .then(function (res) {
361
359
  var headers = res.headers;
362
360
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
363
361
 
364
362
  var appState = utils.getAppState(jar);
365
363
 
366
364
  if (callback === prCallback) {
367
- callback = function(err, api) {
365
+ callback = function (err, api) {
368
366
  if (err) return prReject(err);
369
367
  return prResolve(api);
370
368
  };
@@ -374,7 +372,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
374
372
  // and will then complete the login process
375
373
  return loginHelper(appState, email, password, loginOptions, callback);
376
374
  })
377
- .catch(function(err) {
375
+ .catch(function (err) {
378
376
  // Check if using Promise instead of callback
379
377
  if (callback === prCallback) prReject(err);
380
378
  else callback(err);
@@ -390,7 +388,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
390
388
  clearInterval(checkVerified);
391
389
  logger(Language.VerifiedCheck, "[ FCA-SUS ]");
392
390
  if (callback === prCallback) {
393
- callback = function(err, api) {
391
+ callback = function (err, api) {
394
392
  if (err) return prReject(err);
395
393
  return prResolve(api);
396
394
  };
@@ -416,13 +414,13 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
416
414
  return utils
417
415
  .post(nextURL, jar, form, loginOptions)
418
416
  .then(utils.saveCookies(jar))
419
- .then(function() {
417
+ .then(function () {
420
418
  // Use the same form (safe I hope)
421
419
  form.name_action_selected = 'save_device';
422
420
 
423
421
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
424
422
  })
425
- .then(function(res) {
423
+ .then(function (res) {
426
424
  var headers = res.headers;
427
425
 
428
426
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
@@ -463,76 +461,8 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
463
461
  // back into the jar.
464
462
  try {
465
463
  if (appState) {
466
- //const readline = require("readline");
467
- //const chalk = require("chalk");
468
- //const figlet = require("figlet");
469
- //const os = require("os");
470
- //const { execSync } = require('child_process');
471
- // let rl = readline.createInterface({
472
- // input: process.stdin,
473
- // output: process.stdout,
474
- // prompt: chalk.hex('#00CCCC').bold('[FCA-SUS] • ')
475
- // });
476
- // let type = {
477
- // 1: {
478
- // "name": "Tạo Mật Khẩu Cho Appstate",
479
- // onRun: async function() {
480
- // try {
481
- // rl.question("Hãy Nhập Mật Khẩu Bạn Muốn Đặt Cho Appstate !", (answer) => {
482
- // console.log("Được Rồi Mật Khẩu Của Bạn Là: " + answer + ", Bạn Hãy Nhớ Kĩ Nhé !");
483
- // process.env["FBKEY"] = answer;
484
- // fs.writeFile('../.env', `FBKEY=${answer}`, function (err) {
485
- // if (err) {
486
- // submiterr(err)
487
- // logger("Tạo File ENV Thất Bại !", "[ FCA-SUS ]")
488
- // rl.pause();
489
- // }
490
- // else logger("Tạo Thành Công File ENV !","[ FCA-SUS ]")
491
- // rl.pause();
492
- // });
493
- // })
494
- // }
495
- // catch (e) {
496
- // console.log(e);
497
- // logger("Đã Có Lỗi Khi Đang Try Tạo Ra Câu Hỏi =))", "[ FCA-SUS ]");
498
- // rl.pause();
499
- // }
500
- // }
501
- // },
502
- // 2: {
503
- // "name": "Tiếp Tục Chạy Fca Mà Không Cần Mã Hóa AppState",
504
- // onRun: async function () {
505
- // rl.pause();
506
- // }
507
- // },
508
- // 3: {
509
- // "name": "Đổi Mật Khẩu AppState (Comming Soon..)",
510
- // onRun: async function () {
511
- // console.log(chalk.red.bold("Đã bảo là comming soon rồi mà >:v"));
512
- // }
513
- // }
514
- // }
515
- // const localbrand = JSON.parse(readFileSync('./package.json')).name;
516
- // const localbrand2 = JSON.parse(readFileSync('./node_modules/fca-sus/package.json')).version;
517
- // var axios = require('axios');
518
- // axios.get('https://raw.githubusercontent.com/amogusdevlol/fca-sus/main/package.json').then(async (res) => {
519
- // if (localbrand.toUpperCase() == 'HORIZON') {
520
- // console.group(chalk.bold.cyan('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
521
- // console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Hệ Điều Hành: " + chalk.bold.red(os.type()));
522
- // console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Thông Tin Máy: " + chalk.bold.red(os.version()));
523
- // console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Phiên Bản Hiện Tại: " + chalk.bold.red(localbrand2));
524
- // console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Phiên Bản Mới Nhất: " + chalk.bold.red(res.data.version));
525
- // console.groupEnd();
526
- // }
527
- // else {
528
- // console.clear();
529
- // console.log(figlet.textSync('TeamHorizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }))
530
- // console.log(chalk.hex('#9966CC')(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`));
531
- // }
532
- // });
533
-
534
464
  logger(Language.OnProcess, "[ FCA-SUS ]");
535
- var backup = async(data) => {
465
+ var backup = async (data) => {
536
466
  if (fs.existsSync('./appstate.json')) {
537
467
  try {
538
468
  fs.writeFileSync('./appstate.json', data);
@@ -580,9 +510,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
580
510
  {
581
511
  if (process.env["REPL_ID"] == undefined) {
582
512
  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;
513
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
514
+
515
+ process.env['FBKEY'] = JSON.parse(body).response.key;
586
516
  } catch (e) {
587
517
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
588
518
  logger.Error();
@@ -611,7 +541,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
611
541
  case "android":
612
542
  {
613
543
  try {
614
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
544
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
615
545
  process.env['FBKEY'] = JSON.parse(body).response.key;
616
546
  } catch (e) {
617
547
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
@@ -632,7 +562,6 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
632
562
  case true:
633
563
  {
634
564
  appState = JSON.parse(JSON.stringify(appState, null, "\t"));
635
- //console.log(appState);
636
565
  switch (utils.getType(appState)) {
637
566
  case "Array":
638
567
  {
@@ -729,9 +658,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
729
658
  case "String":
730
659
  {
731
660
  logger(Language.EncryptStateOff, "[ FCA-SUS ]");
732
- //console.log("hello")
733
661
  try {
734
- // appState = appState;
735
662
  appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
736
663
  logger(Language.DecryptSuccess, '[ FCA-SUS ]');
737
664
  } catch (e) {
@@ -827,7 +754,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
827
754
  }
828
755
  }
829
756
  try {
830
- appState.map(function(c) {
757
+ appState.map(function (c) {
831
758
  var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
832
759
  jar.setCookie(str, "http://" + c.domain);
833
760
  });
@@ -879,7 +806,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
879
806
  mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
880
807
  } catch (e) {
881
808
 
882
- if (process.env.Backup != undefined && process.env.Backup) {
809
+ if (process.env.Backup != undefined && process.env.Backup) {
883
810
  return backup(process.env.Backup);
884
811
  }
885
812
  switch (process.platform) {
@@ -951,7 +878,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
951
878
  .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
952
879
  .then(utils.saveCookies(jar))
953
880
  .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
954
- .then(function() {
881
+ .then(function () {
955
882
  return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
956
883
  });
957
884
  }
@@ -962,15 +889,54 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
962
889
  var _defaultFuncs = null;
963
890
  var api = null;
964
891
 
892
+ let redirect = [1, "https://m.facebook.com/"], bypass_region_err = false;
893
+
894
+ function CheckAndFixErr(res) {
895
+ let reg_antierr = /This browser is not supported/gs; // =))))))
896
+ if (reg_antierr.test(res.body)) {
897
+ const Data = JSON.stringify(res.body);
898
+ const Dt_Check = Data.split('2Fhome.php&amp;gfid=')[1];
899
+ if (Dt_Check == undefined) return res
900
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
901
+ if (Dt_Check == undefined || Dt_Check == "") return res
902
+ const final_fid = fid.split(`\\`)[0];
903
+ if (final_fid == undefined || final_fid == '') return res;
904
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
905
+ bypass_region_err = true;
906
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
907
+ }
908
+ else return res
909
+ }
910
+
911
+ function Redirect(res) {
912
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
913
+ redirect = reg.exec(res.body);
914
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
915
+ return res;
916
+ }
917
+
965
918
  mainPromise = mainPromise
966
- .then(function(res) {
919
+ .then(function (res) {
967
920
  // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
968
921
  var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
969
922
  var redirect = reg.exec(res.body);
970
923
  if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
971
924
  return res;
972
925
  })
973
- .then(async function(res) {
926
+ .then(res => Redirect(res))
927
+ .then(res => CheckAndFixErr(res))
928
+ .then(function (res) {
929
+ 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
930
+ if (!Regex_Via.test(res.body)) {
931
+ //www.facebook.com
932
+ 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";
933
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
934
+ }
935
+ else return res
936
+ })
937
+ .then(res => Redirect(res))
938
+ .then(res => CheckAndFixErr(res))
939
+ .then(async function (res) {
974
940
  var html = res.body;
975
941
  var stuff = await buildAPI(globalOptions, html, jar);
976
942
  ctx = stuff[0];
@@ -978,13 +944,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
978
944
  api = stuff[2];
979
945
  return res;
980
946
  });
947
+
981
948
  // given a pageID we log in as a page
982
949
  if (globalOptions.pageID) {
983
950
  mainPromise = mainPromise
984
- .then(function() {
951
+ .then(function () {
985
952
  return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
986
953
  })
987
- .then(function(resData) {
954
+ .then(function (resData) {
988
955
  var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
989
956
  url = url.substring(0, url.length - 1);
990
957
  return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
@@ -993,14 +960,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
993
960
 
994
961
  // At the end we call the callback or catch an exception
995
962
  mainPromise
996
- .then(function() {
963
+ .then(function () {
997
964
  logger(Language.DoneLogin, "[ FCA-SUS ]");
998
965
  logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
999
966
  //!---------- Auto Check, Update START -----------------!//
1000
967
  var Fetch = require('got');
1001
968
  var { readFileSync } = require('fs-extra');
1002
969
  const { execSync } = require('child_process');
1003
- Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async(res) => {
970
+ Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async (res) => {
1004
971
  const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb-new/package.json')).version;
1005
972
  if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
1006
973
  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,13 +1007,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
1040
1007
  callback(null, api);
1041
1008
  }
1042
1009
  });
1043
- }).catch(function(e) {
1010
+ }).catch(function (e) {
1044
1011
  log.error("login", e.error || e);
1045
1012
  callback(e);
1046
1013
  });
1047
1014
  //!---------- Auto Check, Update END -----------------!//
1048
1015
  }
1049
1016
 
1017
+
1050
1018
  function login(loginData, options, callback) {
1051
1019
  if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1052
1020
  callback = options;
@@ -1077,11 +1045,11 @@ function login(loginData, options, callback) {
1077
1045
  if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1078
1046
  var rejectFunc = null;
1079
1047
  var resolveFunc = null;
1080
- var returnPromise = new Promise(function(resolve, reject) {
1048
+ var returnPromise = new Promise(function (resolve, reject) {
1081
1049
  resolveFunc = resolve;
1082
1050
  rejectFunc = reject;
1083
1051
  });
1084
- prCallback = function(error, api) {
1052
+ prCallback = function (error, api) {
1085
1053
  if (error) return rejectFunc(error);
1086
1054
  return resolveFunc(api);
1087
1055
  };
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-26yTr9uw",
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",
@@ -35,12 +35,12 @@
35
35
  "https-proxy-agent": "latest",
36
36
  "is-hexcolor": "^1.0.0",
37
37
  "lodash": "",
38
- "mqtt": "^4.3.7",
38
+ "mqtt": "^4.3.8",
39
39
  "node-superfetch": "^0.2.3",
40
40
  "npmlog": "latest",
41
41
  "path": "latest",
42
- "pretty-ms": "latest",
43
42
  "pm2": "^5.3.0",
43
+ "pretty-ms": "^7.0.1",
44
44
  "request": "latest",
45
45
  "semver": "latest",
46
46
  "sus-support": "git+https://github.com/amogusdevlol/sus-support.git",
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ const { generateOfflineThreadingID, getCurrentTimestamp } = require('../utils');
4
+
5
+ function isCallable(func) {
6
+ try {
7
+ Reflect.apply(func, null, []);
8
+ return true;
9
+ } catch (error) {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ module.exports = function (defaultFuncs, api, ctx) {
15
+ return function pinMessage(pinMode, messageID, threadID, callback) {
16
+ if (!ctx.mqttClient) {
17
+ throw new Error('Not connected to MQTT');
18
+ }
19
+
20
+ ctx.wsReqNumber += 1;
21
+ ctx.wsTaskNumber += 1;
22
+
23
+ const taskLabel = pinMode ? '430' : '431';
24
+ const queueNamePrefix = pinMode ? 'pin_msg_v2_' : 'unpin_msg_v2_';
25
+
26
+ const taskPayload = {
27
+ thread_key: threadID,
28
+ message_id: messageID,
29
+ timestamp_ms: getCurrentTimestamp(),
30
+ };
31
+
32
+ const task = {
33
+ failure_count: null,
34
+ label: taskLabel,
35
+ payload: JSON.stringify(taskPayload),
36
+ queue_name: `${queueNamePrefix}${threadID}`,
37
+ task_id: ctx.wsTaskNumber,
38
+ };
39
+
40
+ const content = {
41
+ app_id: '2220391788200892',
42
+ payload: JSON.stringify({
43
+ data_trace_id: null,
44
+ epoch_id: parseInt(generateOfflineThreadingID()),
45
+ tasks: [task],
46
+ version_id: '25095469420099952',
47
+ }),
48
+ request_id: ctx.wsReqNumber,
49
+ type: 3,
50
+ };
51
+
52
+ if (isCallable(callback)) {
53
+ // to be implemented
54
+ }
55
+
56
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
57
+ };
58
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return async function shareContact(text, senderID, threadID, mentionID, userID, leaverID, callback) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function (err, data) {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(data);
18
+ };
19
+ }
20
+ let count_req = 0;
21
+ var form = JSON.stringify({
22
+ "app_id": "2220391788200892",
23
+ "payload": JSON.stringify({
24
+ tasks: [{
25
+ label: '359',
26
+ payload: JSON.stringify({
27
+ "contact_id": senderID,
28
+ "sync_group": 1,
29
+ "text": text || "",
30
+ "thread_id": threadID
31
+ }),
32
+ queue_name: 'messenger_contact_sharing',
33
+ task_id: Math.random() * 1001 << 0,
34
+ failure_count: null,
35
+ }],
36
+ epoch_id: utils.generateOfflineThreadingID(),
37
+ version_id: '7214102258676893',
38
+ }),
39
+ "request_id": ++count_req,
40
+ "type": 3
41
+ });
42
+ ctx.mqttClient.publish('/ls_req', form);
43
+
44
+ return returnPromise;
45
+ };
46
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return async function shareLink(text, url, threadID, callback) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function (err, data) {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(data);
18
+ };
19
+ }
20
+ ctx.mqttClient.publish('/ls_req',
21
+ JSON.stringify({
22
+ "app_id": "2220391788200892",
23
+ "payload": JSON.stringify({
24
+ tasks: [{
25
+ label: 46,
26
+ payload: JSON.stringify({
27
+ "otid": utils.generateOfflineThreadingID(),
28
+ "source": 524289,
29
+ "sync_group": 1,
30
+ "send_type": 6,
31
+ "mark_thread_read": 0,
32
+ "url": url || "",
33
+ "text": text || "",
34
+ "thread_id": threadID,
35
+ "initiating_source": 0
36
+ }),
37
+ queue_name: threadID,
38
+ task_id: Math.random() * 1001 << 0,
39
+ failure_count: null,
40
+ }],
41
+ epoch_id: utils.generateOfflineThreadingID(),
42
+ version_id: '7191105584331330',
43
+ }),
44
+ "request_id": ++ctx.req_ID,
45
+ "type": 3
46
+ }),
47
+ {
48
+ qos: 1,
49
+ retain: false,
50
+ }
51
+ )
52
+ return returnPromise;
53
+ };
54
+ };
package/utils.js CHANGED
@@ -150,6 +150,12 @@ function generateThreadingID(clientID) {
150
150
  return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
151
151
  }
152
152
 
153
+ function getCurrentTimestamp() {
154
+ const date = new Date();
155
+ const unixTime = date.getTime();
156
+ return unixTime;
157
+ }
158
+
153
159
  function binaryToDecimal(data) {
154
160
  var ret = "";
155
161
  while (data !== "0") {
@@ -1320,8 +1326,8 @@ function decodeClientPayload(payload) {
1320
1326
  }
1321
1327
 
1322
1328
 
1323
-
1324
1329
  /*function getAppState(jar) {
1330
+ var StateCrypt = require('./StateCrypt');
1325
1331
  try {
1326
1332
  var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1327
1333
 
@@ -1350,11 +1356,22 @@ function getAppState(jar) {
1350
1356
  var StateCrypt = require('./StateCrypt');
1351
1357
  var logger = require('./logger');
1352
1358
  logger('Encrypted Appstate Successfully!', '[ FCA-SUS ]');
1353
- logger(`Process Done: ${prettyMilliseconds(Date.now() - process.env.startTime)}`, '[ FCA-SUS ]');
1359
+
1360
+ let processDuration = 0;
1361
+ if (process.env.startTime) {
1362
+ processDuration = Date.now() - parseInt(process.env.startTime);
1363
+ }
1364
+
1365
+ if (isFinite(processDuration)) {
1366
+ logger(`Process Done: ${prettyMilliseconds(processDuration)}`, '[ FCA-SUS ]');
1367
+ } else {
1368
+ logger(`Process Done: Unable to calculate duration`, '[ FCA-SUS ]');
1369
+ }
1370
+
1354
1371
  if (process.env['FBKEY']) {
1355
- return StateCrypt.encryptState(JSON.stringify(appstate),process.env['FBKEY']);
1372
+ return StateCrypt.encryptState(JSON.stringify(appstate), process.env['FBKEY']);
1356
1373
  }
1357
- else return appstate;
1374
+ else return appstate;
1358
1375
  }
1359
1376
 
1360
1377
  module.exports = {
@@ -1395,5 +1412,6 @@ module.exports = {
1395
1412
  decodeClientPayload,
1396
1413
  getAppState,
1397
1414
  getAdminTextMessageType,
1398
- setProxy
1415
+ setProxy,
1416
+ getCurrentTimestamp
1399
1417
  };