fca-nx 6.8.4 → 6.8.6
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/module/config.js +3 -0
- package/module/loginHelper.js +27 -43
- package/package.json +3 -3
- package/src/api/socket/core/getSeqID.js +4 -34
- package/src/database/models/index.js +8 -5
package/module/config.js
CHANGED
|
@@ -13,6 +13,9 @@ const defaultConfig = {
|
|
|
13
13
|
apiServer: "",
|
|
14
14
|
apiKey: "",
|
|
15
15
|
credentials: { email: "", password: "", twofactor: "" },
|
|
16
|
+
// Off unless the bot turns it on. Device registration for secret chats
|
|
17
|
+
// is a separate login-like call and is left off by default.
|
|
18
|
+
e2ee: false,
|
|
16
19
|
antiGetInfo: {
|
|
17
20
|
AntiGetThreadInfo: false,
|
|
18
21
|
AntiGetUserInfo: false
|
package/module/loginHelper.js
CHANGED
|
@@ -12,6 +12,22 @@ const { getFrom } = require("../src/utils/constants");
|
|
|
12
12
|
const { loadConfig } = require("./config");
|
|
13
13
|
const { createRemoteClient } = require("../src/remote/remoteClient");
|
|
14
14
|
const { config } = loadConfig();
|
|
15
|
+
|
|
16
|
+
function e2eeEnabled() {
|
|
17
|
+
const on = (v) => v === true || v === "true";
|
|
18
|
+
const off = (v) => v === false || v === "false";
|
|
19
|
+
try {
|
|
20
|
+
const botPath = path.join(process.cwd(), "config.json");
|
|
21
|
+
if (fs.existsSync(botPath)) {
|
|
22
|
+
const bot = JSON.parse(fs.readFileSync(botPath, "utf8"));
|
|
23
|
+
if (bot && Object.prototype.hasOwnProperty.call(bot, "e2ee")) {
|
|
24
|
+
return on(bot.e2ee);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} catch (_) {}
|
|
28
|
+
if (off(config.e2ee)) return false;
|
|
29
|
+
return on(config.e2ee);
|
|
30
|
+
}
|
|
15
31
|
const axiosBase = require("axios");
|
|
16
32
|
const regions = [
|
|
17
33
|
{ code: "PRN", name: "Pacific Northwest Region", location: "Khu vực Tây Bắc Thái Bình Dương" },
|
|
@@ -1136,7 +1152,7 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1136
1152
|
const tokenMatch = html.match(/DTSGInitialData.*?token":"(.*?)"/);
|
|
1137
1153
|
if (tokenMatch) fb_dtsg = tokenMatch[1];
|
|
1138
1154
|
try {
|
|
1139
|
-
if (userID)
|
|
1155
|
+
if (userID) backupAppStateSQL(jar, userID).catch(() => {});
|
|
1140
1156
|
} catch { }
|
|
1141
1157
|
Promise.resolve()
|
|
1142
1158
|
.then(function () {
|
|
@@ -1367,68 +1383,36 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1367
1383
|
logger("An error occurred while refreshing fb_dtsg: " + (e && e.message ? e.message : e), "error");
|
|
1368
1384
|
});
|
|
1369
1385
|
}, 6 * 60 * 60 * 1000);
|
|
1370
|
-
// [Hardened] light session keepalive every 20 min - hits facebook.com so cookies stay warm
|
|
1371
|
-
// [Hardened4] randomised 15-25 min (a perfectly fixed interval looks scripted)
|
|
1372
|
-
(function keepaliveLoop() {
|
|
1373
|
-
const t = setTimeout(function () {
|
|
1374
|
-
try {
|
|
1375
|
-
const { get } = require("../src/utils/request");
|
|
1376
|
-
const { saveCookies } = require("../src/utils/client");
|
|
1377
|
-
if (ctxMain && ctxMain.jar && !ctxMain._ending) {
|
|
1378
|
-
get("https://www.facebook.com/", ctxMain.jar, null, ctxMain.globalOptions, ctxMain)
|
|
1379
|
-
.then(saveCookies(ctxMain.jar))
|
|
1380
|
-
.then(function () { logger("session keepalive ok", "debug"); })
|
|
1381
|
-
.catch(function (e) {
|
|
1382
|
-
logger("session keepalive failed: " + (e && e.message ? e.message : e), "warn");
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
} catch (_) {}
|
|
1386
|
-
keepaliveLoop();
|
|
1387
|
-
}, (18 + Math.random() * 14) * 60 * 1000); // [Hardened5] 18-32 min irregular keepalive
|
|
1388
|
-
if (t.unref) t.unref();
|
|
1389
|
-
})();
|
|
1390
1386
|
}
|
|
1391
1387
|
// ✅ fca-nx core features register
|
|
1392
1388
|
try {
|
|
1389
|
+
if (!e2eeEnabled()) {
|
|
1390
|
+
logger("E2EE off. Set \"e2ee\": true in config.json or fca-config.json to connect secret chats.", "info");
|
|
1391
|
+
} else {
|
|
1393
1392
|
const e2eeModule = require("../src/api/socket/e2ee");
|
|
1394
1393
|
api.e2ee = new e2eeModule.E2EEBridge(ctxMain, api, defaultFuncs);
|
|
1395
1394
|
ctxMain.e2ee = api.e2ee;
|
|
1396
1395
|
api.connectE2EE = (deviceStorePath) => api.e2ee.connect(deviceStorePath, ctxMain.userID);
|
|
1397
1396
|
api.listenE2EE = require("../src/api/socket/listenE2EE")(defaultFuncs, api, ctxMain);
|
|
1398
|
-
|
|
1399
|
-
// Auto-connect E2EE and make it the default listener so existing
|
|
1400
|
-
// bots calling api.listen() OR api.listenMqtt() directly also
|
|
1401
|
-
// receive E2EE (Secret Conversation) messages without any extra
|
|
1402
|
-
// setup or changes on the bot side.
|
|
1403
|
-
//
|
|
1404
|
-
// [Fixed by xalman] IMPORTANT: assign api.listen/api.listenMqtt to the combined
|
|
1405
|
-
// listener SYNCHRONOUSLY, before connectE2EE() resolves. Bots
|
|
1406
|
-
// commonly call api.listenMqtt(callback) immediately in the login
|
|
1407
|
-
// callback - if we waited for the async connectE2EE() promise to
|
|
1408
|
-
// swap these over, that call would already have captured the old
|
|
1409
|
-
// plain-MQTT-only function, permanently missing E2EE (inbox)
|
|
1410
|
-
// messages even after E2EE finished connecting moments later.
|
|
1411
1397
|
api.listen = api.listenE2EE;
|
|
1412
1398
|
api.listenMqtt = api.listenE2EE;
|
|
1413
|
-
|
|
1414
|
-
// [Fixed by xalman] Retry E2EE auto-connect with backoff instead of
|
|
1415
|
-
// giving up forever after one failed attempt - a transient network
|
|
1416
|
-
// blip or momentary FB rate-limit on device registration used to
|
|
1417
|
-
// leave the bot stuck in group-only mode until a full restart.
|
|
1418
1399
|
const connectE2EEWithRetry = async (attempt = 0) => {
|
|
1419
1400
|
try {
|
|
1420
1401
|
await api.connectE2EE();
|
|
1421
1402
|
logger("E2EE auto-connected and merged into api.listen()/api.listenMqtt()");
|
|
1422
1403
|
} catch (e) {
|
|
1423
1404
|
const msg = e && e.message ? e.message : String(e);
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1405
|
+
if (attempt >= 2) {
|
|
1406
|
+
logger(`E2EE auto-connect stopped after ${attempt + 1} tries: ${msg}`, "warn");
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
const delayMs = 15000 * (attempt + 1);
|
|
1427
1410
|
logger(`E2EE auto-connect failed (attempt ${attempt + 1}): ${msg} - retrying in ${Math.round(delayMs / 1000)}s`, "warn");
|
|
1428
1411
|
setTimeout(() => connectE2EEWithRetry(attempt + 1), delayMs);
|
|
1429
1412
|
}
|
|
1430
1413
|
};
|
|
1431
1414
|
connectE2EEWithRetry();
|
|
1415
|
+
}
|
|
1432
1416
|
} catch (e) {
|
|
1433
1417
|
logger(`E2EE init failed (non-fatal): ${e && e.message ? e.message : String(e)}`, "warn");
|
|
1434
1418
|
}
|
|
@@ -1464,7 +1448,7 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1464
1448
|
// used to silently discard it, so only group messages arriving over
|
|
1465
1449
|
// plain MQTT reached bot handlers.
|
|
1466
1450
|
api._listenMqttRaw = stableListenMqtt;
|
|
1467
|
-
if (typeof api.listenE2EE === "function") {
|
|
1451
|
+
if (e2eeEnabled() && typeof api.listenE2EE === "function") {
|
|
1468
1452
|
api.listenMqtt = api.listen = api.listenE2EE;
|
|
1469
1453
|
} else {
|
|
1470
1454
|
api.listenMqtt = api.listen = stableListenMqtt;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fca-nx",
|
|
3
|
-
"version": "6.8.
|
|
4
|
-
"description": "Facebook Messenger API
|
|
3
|
+
"version": "6.8.6",
|
|
4
|
+
"description": "Facebook Messenger API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -103,4 +103,4 @@
|
|
|
103
103
|
"sqlite3"
|
|
104
104
|
]
|
|
105
105
|
}
|
|
106
|
-
}
|
|
106
|
+
}
|
|
@@ -296,48 +296,18 @@ module.exports = function createGetSeqID(deps) {
|
|
|
296
296
|
if (isAuthError) {
|
|
297
297
|
if (retryCount < MAX_RETRIES) {
|
|
298
298
|
const delay = RETRY_DELAY * (retryCount + 1);
|
|
299
|
-
logger(`getSeqID: retry ${retryCount + 1}/${MAX_RETRIES} after ${delay}ms
|
|
299
|
+
logger(`getSeqID: retry ${retryCount + 1}/${MAX_RETRIES} after ${delay}ms, same cookie (error: ${msg})`, "warn");
|
|
300
300
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
301
|
-
|
|
302
|
-
// [Hardened] Always refresh cookies + fb_dtsg before each auth retry
|
|
303
|
-
try {
|
|
304
|
-
logger("getSeqID: refreshing session (cookies + fb_dtsg) before retry...", "info");
|
|
305
|
-
const { get } = require("../../../utils/request");
|
|
306
|
-
const { saveCookies } = require("../../../utils/client");
|
|
307
|
-
await get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, ctx).then(saveCookies(ctx.jar));
|
|
308
|
-
if (api && typeof api.refreshFb_dtsg === "function") {
|
|
309
|
-
try { await api.refreshFb_dtsg(); } catch (_) {}
|
|
310
|
-
}
|
|
311
|
-
// Keep form tokens in sync with refreshed ctx
|
|
312
|
-
if (form) {
|
|
313
|
-
if (ctx.fb_dtsg) form.fb_dtsg = ctx.fb_dtsg;
|
|
314
|
-
if (ctx.jazoest) form.jazoest = ctx.jazoest;
|
|
315
|
-
}
|
|
316
|
-
} catch (refreshErr) {
|
|
317
|
-
logger(`getSeqID: session refresh failed: ${refreshErr && refreshErr.message ? refreshErr.message : String(refreshErr)}`, "warn");
|
|
318
|
-
}
|
|
319
|
-
|
|
320
301
|
return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
|
|
321
302
|
}
|
|
322
303
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const loginResult = await tryAutoLogin(logger, config, ctx, defaultFuncs);
|
|
326
|
-
|
|
327
|
-
if (loginResult) {
|
|
328
|
-
logger("getSeqID: retrying with new session...", "info");
|
|
329
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
330
|
-
return getSeqID(defaultFuncs, api, ctx, globalCallback, form, 0);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// [Hardened] Only permanent-logout on CLEAR blocked signal.
|
|
334
|
-
// Plain "Not logged in" after retries is often a transient cookie race —
|
|
335
|
-
// schedule a long soft-reconnect instead of killing the session forever.
|
|
304
|
+
// A new email/password login here kills the cookie the bot is
|
|
305
|
+
// already using and Facebook treats it as a second device.
|
|
336
306
|
if (/blocked the login|login_blocked|checkpoint_282|checkpoint_956/i.test(msg)) {
|
|
337
307
|
return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
|
|
338
308
|
}
|
|
339
309
|
|
|
340
|
-
logger(`getSeqID: auth still failing
|
|
310
|
+
logger(`getSeqID: auth still failing - keeping this cookie, no new login: ${msg}`, "error");
|
|
341
311
|
// Soft recovery: do NOT set ctx._ending. Notify listener, then retry later.
|
|
342
312
|
try {
|
|
343
313
|
if (typeof globalCallback === "function") {
|
|
@@ -16,16 +16,16 @@ try {
|
|
|
16
16
|
storage: path.join(databasePath, "database.sqlite"),
|
|
17
17
|
logging: false,
|
|
18
18
|
pool: {
|
|
19
|
-
max:
|
|
19
|
+
max: 1,
|
|
20
20
|
min: 0,
|
|
21
|
-
acquire:
|
|
22
|
-
idle:
|
|
21
|
+
acquire: 8000,
|
|
22
|
+
idle: 5000
|
|
23
23
|
},
|
|
24
24
|
retry: {
|
|
25
|
-
max:
|
|
25
|
+
max: 1
|
|
26
26
|
},
|
|
27
27
|
dialectOptions: {
|
|
28
|
-
timeout:
|
|
28
|
+
timeout: 8000
|
|
29
29
|
},
|
|
30
30
|
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
|
|
31
31
|
});
|
|
@@ -69,6 +69,9 @@ try {
|
|
|
69
69
|
if (!sequelize) {
|
|
70
70
|
throw new Error("Sequelize instance not initialized");
|
|
71
71
|
}
|
|
72
|
+
await sequelize.query("PRAGMA journal_mode=WAL;");
|
|
73
|
+
await sequelize.query("PRAGMA synchronous=NORMAL;");
|
|
74
|
+
await sequelize.query("PRAGMA busy_timeout=8000;");
|
|
72
75
|
await sequelize.sync({ force: false });
|
|
73
76
|
} catch (error) {
|
|
74
77
|
console.error("Failed to synchronize models:", error && error.message ? error.message : String(error));
|