node-ainzfb-new 1.7.10-8 → 1.7.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/StateCrypt.js +24 -14
  2. package/index.js +130 -121
  3. package/package.json +4 -4
  4. package/utils.js +16 -5
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
@@ -23,10 +23,9 @@ var utils = require("./utils"),
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'),
28
+ { execSync } = require('child_process'),
30
29
  Client = require("@replit/database"),
31
30
  languageFile = require('./Language/index.json'),
32
31
  ObjFastConfig = {
@@ -459,78 +458,72 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
459
458
  var mainPromise = null;
460
459
  var jar = utils.getJar();
461
460
 
461
+ const envPath = process.cwd() + '/.env';
462
+
463
+ const loadDotenv = async () => {
464
+ try {
465
+ // Check if dotenv is already installed
466
+ let dotenv;
467
+ try {
468
+ dotenv = require('dotenv');
469
+ } catch (err) {
470
+ if (err.code === 'MODULE_NOT_FOUND') {
471
+ console.log('.env file does not exist. Installing dotenv...');
472
+ execSync('npm install dotenv'); // Install dotenv if missing
473
+ dotenv = require('dotenv'); // Require dotenv after installation
474
+ } else {
475
+ throw err; // Re-throw other errors
476
+ }
477
+ }
478
+
479
+ // Load the .env file if it exists
480
+ if (fs.existsSync(envPath)) {
481
+ dotenv.config({ path: envPath });
482
+ }
483
+ } catch (error) {
484
+ //console.error('Error loading dotenv or installing:', error);
485
+ }
486
+ };
487
+
488
+ await loadDotenv(); // Ensure dotenv is loaded before proceeding
489
+
490
+ const setEnvVariable = (key, value) => {
491
+ try {
492
+ if (process.env[key]) {
493
+ return true; // Variable already exists, no need to set it
494
+ }
495
+
496
+ let envContent = '';
497
+ if (fs.existsSync(envPath)) {
498
+ envContent = fs.readFileSync(envPath, 'utf8');
499
+
500
+ const envLines = envContent.split('\n');
501
+ for (const line of envLines) {
502
+ if (line.startsWith(`${key}=`)) {
503
+ process.env[key] = line.split('=')[1];
504
+ return true;
505
+ }
506
+ }
507
+
508
+ envContent += `\n${key}=${value}`;
509
+ } else {
510
+ envContent = `${key}=${value}`;
511
+ }
512
+
513
+ fs.writeFileSync(envPath, envContent);
514
+ process.env[key] = value;
515
+
516
+ return true;
517
+ } catch (error) {
518
+ console.error('Error setting environment variable:', error);
519
+ return false;
520
+ }
521
+ };
522
+
462
523
  // If we're given an appState we loop through it and save each cookie
463
524
  // back into the jar.
464
525
  try {
465
526
  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
527
  logger(Language.OnProcess, "[ FCA-SUS ]");
535
528
  var backup = async (data) => {
536
529
  if (fs.existsSync('./appstate.json')) {
@@ -563,76 +556,93 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
563
556
  } else return logger.Error();
564
557
  }
565
558
 
559
+
566
560
  switch (process.platform) {
567
- case "win32":
568
- {
561
+ case "win32": {
562
+ try {
563
+ // Only fetch new key if one doesn't exist
564
+ if (!process.env['FBKEY']) {
565
+ const { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
566
+ const key = JSON.parse(body).response.key;
567
+ if (!setEnvVariable('FBKEY', key)) {
568
+ throw new Error('Failed to set environment variable');
569
+ }
570
+ }
571
+ } catch (e) {
572
+ logger(Language.ErrGetPassWord);
573
+ logger.Error();
574
+ process.exit(1);
575
+ }
576
+ break;
577
+ }
578
+ case "linux": {
579
+ if (process.env["REPL_ID"] == undefined) {
569
580
  try {
570
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
571
- process.env['FBKEY'] = JSON.parse(body).response.key;
581
+ // Only fetch new key if one doesn't exist
582
+ if (!process.env['FBKEY']) {
583
+ const { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
584
+ const key = JSON.parse(body).response.key;
585
+ if (!setEnvVariable('FBKEY', key)) {
586
+ throw new Error('Failed to set environment variable');
587
+ }
588
+ }
572
589
  } catch (e) {
573
- logger(Language.ErrGetPassWord);
590
+ logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
574
591
  logger.Error();
575
592
  process.exit(1);
576
593
  }
577
- }
578
- break;
579
- case "linux":
580
- {
581
- if (process.env["REPL_ID"] == undefined) {
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;
586
- } catch (e) {
587
- logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
588
- logger.Error();
589
- process.exit(1);
590
- }
591
- } else {
592
- try {
593
- const client = new Client();
594
- let key = await client.get("FBKEY");
594
+ } else {
595
+ try {
596
+ const client = new Client();
597
+ // Check process.env first
598
+ let key = process.env['FBKEY'];
599
+ if (!key) {
600
+ // Then check client storage
601
+ key = await client.get("FBKEY");
595
602
  if (!key) {
596
- await client.set("FBKEY", makeid(49));
597
- let key = await client.get("FBKEY");
598
- process.env['FBKEY'] = key;
599
- } else {
600
- process.env['FBKEY'] = key;
603
+ key = makeid(49);
604
+ await client.set("FBKEY", key);
605
+ }
606
+ if (!setEnvVariable('FBKEY', key)) {
607
+ throw new Error('Failed to set environment variable');
601
608
  }
602
- } catch (e) {
603
- logger(Language.ErrGenerateKey, '[ FCA-SUS ]');
604
- logger(e, '[ FCA-SUS ]');
605
- logger.Error();
606
- process.exit(0)
607
609
  }
610
+ } catch (e) {
611
+ logger(Language.ErrGenerateKey, '[ FCA-SUS ]');
612
+ logger(e, '[ FCA-SUS ]');
613
+ logger.Error();
614
+ process.exit(0);
608
615
  }
609
616
  }
610
617
  break;
611
- case "android":
612
- {
613
- try {
614
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
615
- process.env['FBKEY'] = JSON.parse(body).response.key;
616
- } catch (e) {
617
- logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
618
- return logger.Error();
618
+ }
619
+ case "android": {
620
+ try {
621
+ // Only fetch new key if one doesn't exist
622
+ if (!process.env['FBKEY']) {
623
+ const { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
624
+ const key = JSON.parse(body).response.key;
625
+ if (!setEnvVariable('FBKEY', key)) {
626
+ throw new Error('Failed to set environment variable');
627
+ }
619
628
  }
629
+ } catch (e) {
630
+ logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
631
+ return logger.Error();
620
632
  }
621
633
  break;
622
- default:
623
- {
624
- logger(Language.UnsupportedDevice, '[ FCA-SUS ]');
625
- logger.Error();
626
- process.exit(0);
627
- }
634
+ }
635
+ default: {
636
+ logger(Language.UnsupportedDevice, '[ FCA-SUS ]');
637
+ logger.Error();
638
+ process.exit(0);
639
+ }
628
640
  }
629
-
630
641
  try {
631
642
  switch (require("../../FastConfigFca.json").EncryptFeature) {
632
643
  case true:
633
644
  {
634
645
  appState = JSON.parse(JSON.stringify(appState, null, "\t"));
635
- //console.log(appState);
636
646
  switch (utils.getType(appState)) {
637
647
  case "Array":
638
648
  {
@@ -729,9 +739,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
729
739
  case "String":
730
740
  {
731
741
  logger(Language.EncryptStateOff, "[ FCA-SUS ]");
732
- //console.log("hello")
733
742
  try {
734
- // appState = appState;
735
743
  appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
736
744
  logger(Language.DecryptSuccess, '[ FCA-SUS ]');
737
745
  } catch (e) {
@@ -1087,6 +1095,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
1087
1095
  //!---------- Auto Check, Update END -----------------!//
1088
1096
  }
1089
1097
 
1098
+
1090
1099
  function login(loginData, options, callback) {
1091
1100
  if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1092
1101
  callback = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ainzfb-new",
3
- "version": "1.7.10-8",
3
+ "version": "1.7.11",
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",
@@ -28,19 +28,19 @@
28
28
  "better-sqlite3": "^7.6.2",
29
29
  "bluebird": "^2.11.0",
30
30
  "chalk": "^4.1.2",
31
- "cheerio": "latest",
31
+ "cheerio": "^0.20.0",
32
32
  "crypto": "^1.0.1",
33
33
  "gettext.js": "^1.1.1",
34
34
  "got": "^11.8.3",
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": "^7.0.1",
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",
package/utils.js CHANGED
@@ -1326,8 +1326,8 @@ function decodeClientPayload(payload) {
1326
1326
  }
1327
1327
 
1328
1328
 
1329
-
1330
1329
  /*function getAppState(jar) {
1330
+ var StateCrypt = require('./StateCrypt');
1331
1331
  try {
1332
1332
  var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1333
1333
 
@@ -1356,11 +1356,22 @@ function getAppState(jar) {
1356
1356
  var StateCrypt = require('./StateCrypt');
1357
1357
  var logger = require('./logger');
1358
1358
  logger('Encrypted Appstate Successfully!', '[ FCA-SUS ]');
1359
- 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
+
1360
1371
  if (process.env['FBKEY']) {
1361
- return StateCrypt.encryptState(JSON.stringify(appstate),process.env['FBKEY']);
1372
+ return StateCrypt.encryptState(JSON.stringify(appstate), process.env['FBKEY']);
1362
1373
  }
1363
- else return appstate;
1374
+ else return appstate;
1364
1375
  }
1365
1376
 
1366
1377
  module.exports = {
@@ -1403,4 +1414,4 @@ module.exports = {
1403
1414
  getAdminTextMessageType,
1404
1415
  setProxy,
1405
1416
  getCurrentTimestamp
1406
- };
1417
+ };