node-ainzfb-new 1.7.10-16tfwiu → 1.7.10-24ejweqr

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/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,9 +23,7 @@ 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'),
30
28
  Client = require("@replit/database"),
31
29
  languageFile = require('./Language/index.json'),
@@ -455,7 +453,7 @@ function makeid(length) {
455
453
 
456
454
 
457
455
  // Helps the login
458
- async function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
456
+ /*async function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
459
457
  var mainPromise = null;
460
458
  var jar = utils.getJar();
461
459
 
@@ -1085,8 +1083,244 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
1085
1083
  callback(e);
1086
1084
  });
1087
1085
  //!---------- Auto Check, Update END -----------------!//
1086
+ }*/
1087
+
1088
+
1089
+ async function loginHelper(
1090
+ appState,
1091
+ email,
1092
+ password,
1093
+ globalOptions,
1094
+ callback,
1095
+ prCallback
1096
+ ) {
1097
+ var mainPromise = null;
1098
+ var jar = utils.getJar();
1099
+
1100
+ // If we're given an appState we loop through it and save each cookie
1101
+ // back into the jar.
1102
+ if (appState) {
1103
+
1104
+
1105
+ // Decrypt the appState if FBKEY is provided
1106
+ if (process.env['FBKEY']) {
1107
+ try {
1108
+ appState = JSON.parse(StateCrypt.decryptState(appState, process.env['FBKEY']));
1109
+ console.log("AppState decrypted successfully");
1110
+ } catch (e) {
1111
+ console.error("Failed to decrypt AppState:", e.message);
1112
+ return callback(new Error("Failed to decrypt AppState"));
1113
+ }
1114
+ }
1115
+
1116
+ if (!Array.isArray(appState)) {
1117
+ return callback(new Error("AppState must be an array"));
1118
+ }
1119
+
1120
+ appState.map(function (c) {
1121
+ var str =
1122
+ c.key +
1123
+ '=' +
1124
+ c.value +
1125
+ '; expires=' +
1126
+ c.expires +
1127
+ '; domain=' +
1128
+ c.domain +
1129
+ '; path=' +
1130
+ c.path +
1131
+ ';';
1132
+ jar.setCookie(str, 'http://' + c.domain);
1133
+ });
1134
+
1135
+ // Load the main page.
1136
+ mainPromise = utils
1137
+ .get('https://www.facebook.com/', jar, null, globalOptions, {
1138
+ noRef: true,
1139
+ })
1140
+ .then(utils.saveCookies(jar));
1141
+ } else {
1142
+ // Open the main page, then we login with the given credentials and finally
1143
+ // load the main page again (it'll give us some IDs that we need)
1144
+ mainPromise = utils
1145
+ .get('https://www.facebook.com/', null, null, globalOptions, {
1146
+ noRef: true,
1147
+ })
1148
+ .then(utils.saveCookies(jar))
1149
+ .then(
1150
+ makeLogin(jar, email, password, globalOptions, callback, prCallback)
1151
+ )
1152
+ .then(function () {
1153
+ return utils
1154
+ .get('https://www.facebook.com/', jar, null, globalOptions)
1155
+ .then(utils.saveCookies(jar));
1156
+ });
1157
+ }
1158
+
1159
+ var ctx = null;
1160
+ var _defaultFuncs = null;
1161
+ var api = null;
1162
+
1163
+ let redirect = [1, "https://m.facebook.com/"], bypass_region_err = false;
1164
+
1165
+ function CheckAndFixErr(res) {
1166
+ let reg_antierr = /This browser is not supported/gs;
1167
+ if (reg_antierr.test(res.body)) {
1168
+ const Data = JSON.stringify(res.body);
1169
+ const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
1170
+ if (Dt_Check == undefined) return res
1171
+ const fid = Dt_Check.split("\\\\")[0];
1172
+ if (Dt_Check == undefined || Dt_Check == "") return res
1173
+ const final_fid = fid.split(`\\`)[0];
1174
+ if (final_fid == undefined || final_fid == '') return res;
1175
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
1176
+ bypass_region_err = true;
1177
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
1178
+ }
1179
+ else return res
1180
+ }
1181
+
1182
+ function Redirect(res) {
1183
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1184
+ redirect = reg.exec(res.body);
1185
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1186
+ return res;
1187
+ }
1188
+
1189
+ mainPromise = mainPromise
1190
+ .then(function (res) {
1191
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1192
+ var redirect = reg.exec(res.body);
1193
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1194
+ return res;
1195
+ })
1196
+ .then(res => Redirect(res))
1197
+ .then(res => CheckAndFixErr(res))
1198
+ .then(function (res) {
1199
+ let Regex_Via = /MPageLoadClientMetrics/gs;
1200
+ if (!Regex_Via.test(res.body)) {
1201
+ 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";
1202
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
1203
+ }
1204
+ else return res
1205
+ })
1206
+ .then(res => Redirect(res))
1207
+ .then(res => CheckAndFixErr(res))
1208
+ .then(async function (res) {
1209
+ var html = res.body;
1210
+ var stuff = await buildAPI(globalOptions, html, jar);
1211
+ ctx = stuff[0];
1212
+ _defaultFuncs = stuff[1];
1213
+ api = stuff[2];
1214
+ return res;
1215
+ });
1216
+
1217
+ if (globalOptions.pageID) {
1218
+ mainPromise = mainPromise
1219
+ .then(function () {
1220
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
1221
+ })
1222
+ .then(function (resData) {
1223
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
1224
+ url = url.substring(0, url.length - 1);
1225
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
1226
+ });
1227
+ }
1228
+
1229
+ mainPromise
1230
+ .then(function () {
1231
+ // Encrypt and save the appState
1232
+ if (process.env['FBKEY']) {
1233
+ try {
1234
+ const currentAppState = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1235
+ const encryptedAppState = StateCrypt.encryptState(JSON.stringify(currentAppState), process.env['FBKEY']);
1236
+ // Save the encrypted appState (you might want to implement a save function)
1237
+ saveAppState(encryptedAppState, (err) => {
1238
+ if (err) {
1239
+ console.error("Failed to encrypt and save AppState:", err.message);
1240
+ } else {
1241
+ console.log("AppState encrypted and saved successfully");
1242
+ }
1243
+ callback(null, api);
1244
+ });
1245
+ console.log("AppState encrypted and saved successfully");
1246
+ } catch (e) {
1247
+ console.error("Failed to encrypt and save AppState:", e.message);
1248
+ }
1249
+ }
1250
+ //callback(null, api);
1251
+ })
1252
+
1253
+ // At the end we call the callback or catch an exception
1254
+ mainPromise
1255
+ .then(function () {
1256
+ logger(Language.DoneLogin, "[ FCA-SUS ]");
1257
+ logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
1258
+ //!---------- Auto Check, Update START -----------------!//
1259
+ var Fetch = require('got');
1260
+ var { readFileSync } = require('fs-extra');
1261
+ const { execSync } = require('child_process');
1262
+ Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async (res) => {
1263
+ const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb-new/package.json')).version;
1264
+ if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
1265
+ log.warn("[ FCA-SUS ] •", getText.gettext(Language.NewVersionFound, JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version, JSON.parse(res.body.toString()).version));
1266
+ log.warn("[ FCA-SUS ] •", Language.AutoUpdate);
1267
+ try {
1268
+ execSync('npm install node-ainzfb-new@latest', { stdio: 'inherit' });
1269
+ logger(Language.UpdateSuccess, "[ FCA-SUS ]")
1270
+ logger(Language.RestartAfterUpdate, '[ FCA-SUS ]');
1271
+ await new Promise(resolve => setTimeout(resolve, 5 * 1000));
1272
+ console.clear();
1273
+ process.exit(1);
1274
+ } catch (err) {
1275
+ log.warn('Error Update: ' + err);
1276
+ logger(Language.UpdateFailed, "[ FCA-SUS ]");
1277
+ try {
1278
+ require.resolve('sus-support');
1279
+ } catch (e) {
1280
+ logger(Language.InstallSupportTool, "[ FCA-SUS ]");
1281
+ execSync('npm install git+https://github.com/amogusdevlol/sus-support.git', { stdio: 'inherit' });
1282
+ process.exit(1);
1283
+ }
1284
+ var fcasp = require('sus-support');
1285
+ try {
1286
+ fcasp.onError()
1287
+ } catch (e) {
1288
+ logger(Language.NotiAfterUseToolFail, "[ Fca - Helper ]")
1289
+ logger("rmdir ./node_modules then enter npm i && npm start", "[ Fca - Helper ]");
1290
+ process.exit(0);
1291
+ }
1292
+
1293
+ }
1294
+ } else {
1295
+ logger(getText.gettext(Language.LocalVersion, localbrand), "[ FCA-SUS ]");
1296
+ logger(Language.WishMessage[Math.floor(Math.random() * Language.WishMessage.length)], "[ FCA-SUS ]");
1297
+ require('./Extra/ExtraUptimeRobot')()
1298
+ await new Promise(resolve => setTimeout(resolve, 5 * 1000));
1299
+ return callback(null, api);
1300
+ }
1301
+ });
1302
+ })
1303
+ .catch(function (e) {
1304
+ log.error("login", e.error || e);
1305
+ callback(e);
1306
+ });
1088
1307
  }
1089
1308
 
1309
+
1310
+ function saveAppState(encryptedAppState, callback) {
1311
+ const appStatePath = './appstate.json';
1312
+ fs.writeFile(appStatePath, encryptedAppState, 'utf8', (err) => {
1313
+ if (err) {
1314
+ console.error("Error saving AppState:", err.message);
1315
+ callback(err);
1316
+ } else {
1317
+ console.log("AppState saved successfully to:", appStatePath);
1318
+ callback(null);
1319
+ }
1320
+ });
1321
+ }
1322
+
1323
+
1090
1324
  function login(loginData, options, callback) {
1091
1325
  if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1092
1326
  callback = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ainzfb-new",
3
- "version": "1.7.10-16tfwiu",
3
+ "version": "1.7.10-24ejweqr",
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",
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