fca-kzii 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. package/.gitattributes +2 -0
  2. package/Extra/Bypass/956/index.js +234 -0
  3. package/Extra/Bypass/test/aaaa.json +170 -0
  4. package/Extra/Bypass/test/index.js +188 -0
  5. package/Extra/Database/index.js +469 -0
  6. package/Extra/ExtraAddons.js +82 -0
  7. package/Extra/ExtraFindUID.js +62 -0
  8. package/Extra/ExtraGetThread.js +365 -0
  9. package/Extra/ExtraScreenShot.js +430 -0
  10. package/Extra/ExtraUptimeRobot.js +38 -0
  11. package/Extra/Html/Classic/script.js +119 -0
  12. package/Extra/Html/Classic/style.css +8 -0
  13. package/Extra/Security/AES_256_GCM/index.js +0 -0
  14. package/Extra/Security/Base/Step_1.js +6 -0
  15. package/Extra/Security/Base/Step_2.js +22 -0
  16. package/Extra/Security/Base/Step_3.js +22 -0
  17. package/Extra/Security/Base/index.js +191 -0
  18. package/Extra/Security/Index.js +5 -0
  19. package/Extra/Security/Step_1.js +6 -0
  20. package/Extra/Security/Step_2.js +22 -0
  21. package/Extra/Security/Step_3.js +22 -0
  22. package/Extra/Src/Change_Environment.js +24 -0
  23. package/Extra/Src/Check_Update.js +67 -0
  24. package/Extra/Src/History.js +115 -0
  25. package/Extra/Src/Instant_Update.js +65 -0
  26. package/Extra/Src/Last-Run.js +65 -0
  27. package/Extra/Src/Premium.js +81 -0
  28. package/Extra/Src/Release_Memory.js +160 -0
  29. package/Extra/Src/Websocket.js +213 -0
  30. package/Extra/Src/image/checkmate.jpg +0 -0
  31. package/Extra/Src/test.js +28 -0
  32. package/Extra/Src/uuid.js +137 -0
  33. package/Func/AcceptAgreement.js +31 -0
  34. package/Func/ClearCache.js +64 -0
  35. package/Func/ReportV1.js +54 -0
  36. package/LICENSE +21 -0
  37. package/Language/index.json +222 -0
  38. package/Main.js +1266 -0
  39. package/README.md +152 -0
  40. package/SECURITY.md +18 -0
  41. package/broadcast.js +44 -0
  42. package/index.js +448 -0
  43. package/logger.js +66 -0
  44. package/package.json +97 -0
  45. package/src/Dev_Horizon_Data.js +125 -0
  46. package/src/Dev_getThreadInfoOLD.js +422 -0
  47. package/src/Dev_shareTest2.js +68 -0
  48. package/src/Dev_shareTest3.js +71 -0
  49. package/src/Premium.js +25 -0
  50. package/src/Screenshot.js +83 -0
  51. package/src/addExternalModule.js +16 -0
  52. package/src/addUserToGroup.js +79 -0
  53. package/src/changeAdminStatus.js +79 -0
  54. package/src/changeArchivedStatus.js +41 -0
  55. package/src/changeAvt.js +85 -0
  56. package/src/changeBio.js +65 -0
  57. package/src/changeBlockedStatus.js +36 -0
  58. package/src/changeGroupImage.js +106 -0
  59. package/src/changeNickname.js +45 -0
  60. package/src/changeThreadColor.js +62 -0
  61. package/src/changeThreadEmoji.js +42 -0
  62. package/src/createNewGroup.js +70 -0
  63. package/src/createPoll.js +60 -0
  64. package/src/deleteMessage.js +45 -0
  65. package/src/deleteThread.js +43 -0
  66. package/src/editMessage.js +53 -0
  67. package/src/forwardAttachment.js +48 -0
  68. package/src/getAccessToken.js +28 -0
  69. package/src/getCurrentUserID.js +7 -0
  70. package/src/getEmojiUrl.js +27 -0
  71. package/src/getFriendsList.js +73 -0
  72. package/src/getMessage.js +103 -0
  73. package/src/getThreadHistory.js +537 -0
  74. package/src/getThreadInfo.js +424 -0
  75. package/src/getThreadInfoOLD.js +422 -0
  76. package/src/getThreadList.js +213 -0
  77. package/src/getThreadMain.js +220 -0
  78. package/src/getThreadPictures.js +59 -0
  79. package/src/getUID.js +59 -0
  80. package/src/getUserID.js +62 -0
  81. package/src/getUserInfo.js +112 -0
  82. package/src/getUserInfoMain.js +65 -0
  83. package/src/getUserInfoV2.js +32 -0
  84. package/src/getUserInfoV3.js +63 -0
  85. package/src/getUserInfoV4.js +55 -0
  86. package/src/getUserInfoV5.js +61 -0
  87. package/src/handleFriendRequest.js +46 -0
  88. package/src/handleMessageRequest.js +49 -0
  89. package/src/httpGet.js +49 -0
  90. package/src/httpPost.js +48 -0
  91. package/src/httpPostFormData.js +41 -0
  92. package/src/listenMqtt.js +930 -0
  93. package/src/listenMqttV1.js +846 -0
  94. package/src/logout.js +68 -0
  95. package/src/markAsDelivered.js +48 -0
  96. package/src/markAsRead.js +70 -0
  97. package/src/markAsReadAll.js +43 -0
  98. package/src/markAsSeen.js +51 -0
  99. package/src/muteThread.js +47 -0
  100. package/src/removeUserFromGroup.js +49 -0
  101. package/src/resolvePhotoUrl.js +37 -0
  102. package/src/searchForThread.js +43 -0
  103. package/src/sendMessage.js +386 -0
  104. package/src/sendMqttMessage.js +71 -0
  105. package/src/sendTypingIndicator.js +80 -0
  106. package/src/setMessageReaction.js +109 -0
  107. package/src/setPostReaction.js +102 -0
  108. package/src/setTitle.js +74 -0
  109. package/src/shareContact.js +55 -0
  110. package/src/shareLink.js +58 -0
  111. package/src/threadColors.js +39 -0
  112. package/src/unfriend.js +43 -0
  113. package/src/unsendMessage.js +40 -0
  114. package/test/Database_Test.js +4 -0
  115. package/test/Db2.js +530 -0
  116. package/test/Horizon_Database/A_README.md +1 -0
  117. package/test/Horizon_Database/Database.db +0 -0
  118. package/test/data/shareAttach.js +146 -0
  119. package/test/data/something.mov +0 -0
  120. package/test/data/test.png +0 -0
  121. package/test/data/test.txt +7 -0
  122. package/test/env/.env +0 -0
  123. package/test/example-config.json +18 -0
  124. package/test/example-db.db +0 -0
  125. package/test/memoryleak.js +18 -0
  126. package/test/test-page.js +140 -0
  127. package/test/test.js +385 -0
  128. package/test/testname.js +1342 -0
  129. package/test/testv2.js +3 -0
  130. package/utils.js +3038 -0
package/Main.js ADDED
@@ -0,0 +1,1266 @@
1
+ 'use strict';
2
+
3
+ //-[ Require config and use ]-!/
4
+
5
+ if (global.Fca.Require.FastConfig.Config != 'default') {
6
+ //do ssth
7
+ }
8
+
9
+ const Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == global.Fca.Require.FastConfig.Language).Folder.Index;
10
+
11
+ //-[ Require All Package Need Use ]-!/
12
+
13
+ var utils = global.Fca.Require.utils,
14
+ logger = global.Fca.Require.logger,
15
+ fs = global.Fca.Require.fs,
16
+ getText = global.Fca.getText,
17
+ log = global.Fca.Require.log,
18
+ express = require("express")(),
19
+ { join } = require('path'),
20
+ cheerio = require("cheerio"),
21
+ { readFileSync, writeFileSync } = require('fs-extra'),
22
+ Database = require("./Extra/Database"),
23
+ readline = require("readline"),
24
+ chalk = require("chalk"),
25
+ figlet = require("figlet"),
26
+ os = require("os"),
27
+ deasync = require('deasync'),
28
+ Security = require("./Extra/Security/Base"),
29
+ { getAll, deleteAll } = require('./Extra/ExtraGetThread'),
30
+ ws = require('ws'),
31
+ Websocket = require('./Extra/Src/Websocket'),
32
+ Convert = require('ansi-to-html');
33
+
34
+ //-[ Set Variable For Process ]-!/
35
+
36
+ log.maxRecordSize = 100;
37
+ var checkVerified = null;
38
+ const Boolean_Option = ['online','selfListen','listenEvents','updatePresence','forceLogin','autoMarkDelivery','autoMarkRead','listenTyping','autoReconnect','emitReady'];
39
+
40
+ //-[ Set And Check Template HTML ]-!/
41
+
42
+ const css = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'style.css'));
43
+ const js = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'script.js'));
44
+
45
+ //-[ Function Generate HTML Template ]-!/
46
+
47
+ /**
48
+ * It returns a string of HTML code.
49
+ * @param UserName - The username of the user
50
+ * @param Type - The type of user, either "Free" or "Premium"
51
+ * @param link - The link to the music you want to play
52
+ * @returns A HTML file
53
+ */
54
+
55
+ function ClassicHTML(UserName,Type,link) {
56
+ return `<!DOCTYPE html>
57
+ <html lang="en" >
58
+ <head>
59
+ <meta charset="UTF-8">
60
+ <title>Horizon</title>
61
+ <link rel="stylesheet" href="./style.css">
62
+ </head>
63
+ <body>
64
+ <center>
65
+ <marquee><b>waiting for u :d</b></marquee>
66
+ <h2>Horizon User Infomation</h2>
67
+ <h3>UserName: ${UserName} | Type: ${Type}</h3>
68
+ <canvas id="myCanvas"></canvas>
69
+ <script src="./script.js"></script>
70
+ <footer class="footer">
71
+ <div id="music">
72
+ <audio autoplay="false" controls="true" loop="true" src="${link}" __idm_id__="5070849">Your browser does not support the audio element.</audio>
73
+ <br><b>Session ID:</b> ${global.Fca.Require.Security.create().uuid}<br>
74
+ <br>Thanks For Using <b>Fca-Horizon-Remastered</b> - From <b>Kanzu</b> <3<br>
75
+ </div>
76
+ </footer>
77
+ </div>
78
+ </center>
79
+ </html>
80
+ </body>`
81
+ //lazy to change
82
+ }
83
+
84
+
85
+
86
+ //-[ Stating Http Infomation ]-!/
87
+
88
+ express.set('DFP', (process.env.PORT || process.env.port || 80));
89
+
90
+ express.use(function(req, res, next) {
91
+ switch (req.url.split('?')[0]) {
92
+ case '/script.js': {
93
+ res.writeHead(200, { 'Content-Type': 'text/javascript' });
94
+ res.write(js);
95
+ break;
96
+ }
97
+ case '/style.css': {
98
+ res.writeHead(200, { 'Content-Type': 'text/css' });
99
+ res.write(css);
100
+ break;
101
+ }
102
+ default: {
103
+ res.writeHead(200, "OK", { "Content-Type": "text/html" });
104
+ res.write(ClassicHTML(global.Fca.Require.FastConfig.HTML.UserName, "Premium Access", global.Fca.Require.FastConfig.HTML.MusicLink));
105
+ }
106
+ }
107
+ res.end();
108
+ })
109
+ var Server;
110
+ if (global.Fca.Require.FastConfig.HTML.HTML) Server= express.listen(express.get('DFP'));
111
+
112
+ /*
113
+ function escapeHTML(input) {
114
+ const entityMap = {'&': '&','<': '<','>': '>','"': '"',"'": '\''};
115
+ return String(input).replace(/[&<>"'`=\/]/g, function(s) {
116
+ return entityMap[s];
117
+ });
118
+ }
119
+ //avoid html injection
120
+
121
+ if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
122
+ var convert = new Convert();
123
+ if (Server != undefined) {
124
+ const WebSocket = new ws.Server({ noServer: true });
125
+ const { Client, WSS } = Websocket.connect(WebSocket);
126
+ Server.on('upgrade', (req, socket, head) => {
127
+ const escapedReq = escapeHTML(req);
128
+ const escapedSocket = escapeHTML(socket);
129
+ const escapedHead = escapeHTML(head);
130
+ WSS.handleUpgrade(escapedReq, escapedSocket, escapedHead, (wss) => {
131
+ const escapedWss = escapeHTML(wss);
132
+ const escapedReq = escapeHTML(req);
133
+
134
+ escapedWss.emit('connection', escapedWss, escapedReq);
135
+ });
136
+ });
137
+ console._log = console.__log
138
+ console.log = function(data) {
139
+ const All = Object.keys(Client)
140
+ console._log.apply(data,arguments)
141
+ try {
142
+ const log = (convert.toHtml(data) || data || "Nothing to show")
143
+ console.history.push(log)
144
+ if (console.history.length > 80) {
145
+ console.history.shift();
146
+ }
147
+ for (let i of All) {
148
+ if (Client[i].Status) {
149
+ Client[i].Websocket.send(JSON.stringify({ Type: "Console", Data: log }));
150
+ }
151
+ else continue;
152
+ }
153
+ }
154
+ catch (e) {
155
+ return;
156
+ }
157
+ }
158
+ }
159
+ else {
160
+ const WebSocket = new ws.Server({ port: 80 });
161
+ const { Client } = Websocket.connect(WebSocket);
162
+ console._log = console.__log
163
+ console.log = function(data) {
164
+ const All = Object.keys(Client)
165
+ console._log.apply(data,arguments)
166
+ try {
167
+ const log = convert.toHtml(data)
168
+ console.history.push(log)
169
+ if (console.history.length > 80) {
170
+ console.history.shift();
171
+ }
172
+ for (let i of All) {
173
+ if (Client[i].Status) {
174
+ Client[i].Websocket.send(JSON.stringify({ Type: "Console", Data: log }));
175
+ }
176
+ else continue;
177
+ }
178
+ }
179
+ catch (e) {
180
+ return
181
+ }
182
+ }
183
+ }
184
+
185
+ }
186
+ **/
187
+ //-[ Function setOptions ]-!/
188
+
189
+ /**
190
+ * @param {{ [x: string]: boolean; selfListen?: boolean; listenEvents?: boolean; listenTyping?: boolean; updatePresence?: boolean; forceLogin?: boolean; autoMarkDelivery?: boolean; autoMarkRead?: boolean; autoReconnect?: boolean; logRecordSize: any; online?: boolean; emitReady?: boolean; userAgent: any; logLevel?: any; pageID?: any; proxy?: any; }} globalOptions
191
+ * @param {{ [x: string]: any; logLevel?: any; forceLogin?: boolean; userAgent?: any; pauseLog?: any; logRecordSize?: any; pageID?: any; proxy?: any; }} options
192
+ */
193
+
194
+ function setOptions(globalOptions, options) {
195
+ Object.keys(options).map(function(key) {
196
+ switch (Boolean_Option.includes(key)) {
197
+ case true: {
198
+ globalOptions[key] = Boolean(options[key]);
199
+ break;
200
+ }
201
+ case false: {
202
+ switch (key) {
203
+ case 'pauseLog': {
204
+ if (options.pauseLog) log.pause();
205
+ else log.resume();
206
+ break;
207
+ }
208
+ case 'logLevel': {
209
+ log.level = options.logLevel;
210
+ globalOptions.logLevel = options.logLevel;
211
+ break;
212
+ }
213
+ case 'logRecordSize': {
214
+ log.maxRecordSize = options.logRecordSize;
215
+ globalOptions.logRecordSize = options.logRecordSize;
216
+ break;
217
+ }
218
+ case 'pageID': {
219
+ globalOptions.pageID = options.pageID.toString();
220
+ break;
221
+ }
222
+ case 'userAgent': {
223
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36');
224
+ break;
225
+ }
226
+ case 'proxy': {
227
+ if (typeof options.proxy != "string") {
228
+ delete globalOptions.proxy;
229
+ utils.setProxy();
230
+ } else {
231
+ globalOptions.proxy = options.proxy;
232
+ utils.setProxy(globalOptions.proxy);
233
+ }
234
+ break;
235
+ }
236
+ default: {
237
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
238
+ break;
239
+ }
240
+ }
241
+ break;
242
+ }
243
+ }
244
+ });
245
+ }
246
+
247
+ //-[ Function BuildAPI ]-!/
248
+
249
+ /**
250
+ * @param {any} globalOptions
251
+ * @param {string} html
252
+ * @param {{ getCookies: (arg0: string) => any[]; }} jar
253
+ */
254
+
255
+ function buildAPI(globalOptions, html, jar, bypass_region) {
256
+ //check tiktik
257
+ var userID;
258
+ var cookie = jar.getCookies("https://www.facebook.com");
259
+ var maybeUser = cookie.filter(function(val) { return val.cookieString().split("=")[0] === "c_user"; });
260
+ var maybeTiktik = cookie.filter(function(val) { return val.cookieString().split("=")[0] === "i_user"; });
261
+
262
+ if (maybeUser.length === 0 && maybeTiktik.length === 0) {
263
+ if (global.Fca.Require.FastConfig.AutoLogin) {
264
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
265
+ global.Fca.Action('AutoLogin')
266
+ });
267
+ }
268
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
269
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
270
+ }
271
+ }
272
+ else {
273
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
274
+
275
+ if (maybeTiktik[0] && maybeTiktik[0].cookieString().includes('i_user')) {
276
+ userID = maybeTiktik[0].cookieString().split("=")[1].toString();
277
+
278
+ }
279
+ else userID = maybeUser[0].cookieString().split("=")[1].toString();
280
+ process.env['UID'] = logger.Normal(getText(Language.UID,userID), userID);
281
+
282
+ try {
283
+ clearInterval(checkVerified);
284
+ } catch (e) {
285
+ console.log(e);
286
+ }
287
+
288
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
289
+
290
+ var CHECK_MQTT = {
291
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
292
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
293
+ legacyFBMQTTMatch: html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/)
294
+ }
295
+
296
+ let Slot = Object.keys(CHECK_MQTT);
297
+
298
+ var mqttEndpoint,region,irisSeqID;
299
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
300
+ if (CHECK_MQTT[MQTT] && !region) {
301
+ switch (Slot.indexOf(MQTT)) {
302
+ case 0: {
303
+ irisSeqID = CHECK_MQTT[MQTT][1];
304
+ mqttEndpoint = CHECK_MQTT[MQTT][2];
305
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
306
+ return;
307
+ }
308
+ case 1: {
309
+ irisSeqID = CHECK_MQTT[MQTT][2];
310
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
311
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
312
+ return;
313
+ }
314
+ case 2: {
315
+ mqttEndpoint = CHECK_MQTT[MQTT][4];
316
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
317
+ return;
318
+ }
319
+ }
320
+ return;
321
+ }
322
+ });
323
+ var ctx = {
324
+ userID: userID,
325
+ jar: jar,
326
+ clientID: clientID,
327
+ globalOptions: globalOptions,
328
+ loggedIn: true,
329
+ access_token: 'NONE',
330
+ clientMutationId: 0,
331
+ mqttClient: undefined,
332
+ lastSeqId: irisSeqID,
333
+ syncToken: undefined,
334
+ mqttEndpoint: mqttEndpoint,
335
+ region: region,
336
+ firstListen: true,
337
+ req_ID: 0,
338
+ callback_Task: {}
339
+ };
340
+
341
+ var api = {
342
+ setOptions: setOptions.bind(null, globalOptions),
343
+ getAppState: function getAppState() {
344
+ return utils.getAppState(jar);
345
+ }
346
+ };
347
+
348
+ if (region && mqttEndpoint) {
349
+ //do sth
350
+ }
351
+ else {
352
+ if (bypass_region) {
353
+ logger.Normal(Language.NoAreaDataBypass);
354
+ }
355
+ else {
356
+ log.warn("login", getText(Language.NoAreaData));
357
+ api["htmlData"] = html;
358
+ }
359
+ }
360
+
361
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
362
+
363
+ fs.readdirSync(__dirname + "/src").filter((/** @type {string} */File) => File.endsWith(".js") && !File.includes('Dev_')).map((/** @type {string} */File) => {
364
+ if (File == 'getThreadInfo.js' && global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo != true || File == 'getUserInfo.js' && global.Fca.Require.FastConfig.AntiGetInfo.AntiGetUserInfo != true) api[File.split('.').slice(0, -1).join('.')] = require('./src/' + (File.includes('getThreadInfo') ? 'getThreadMain.js' : 'getUserInfoMain.js'))(defaultFuncs, api, ctx)
365
+ else api[File.split('.').slice(0, -1).join('.')] = require('./src/' + File)(defaultFuncs, api, ctx)
366
+ });
367
+
368
+ return {
369
+ ctx,
370
+ defaultFuncs,
371
+ api
372
+ };
373
+ }
374
+ }
375
+
376
+ //-[ Function makeLogin ]-!/
377
+
378
+ /**
379
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
380
+ * @param {any} email
381
+ * @param {any} password
382
+ * @param {{ forceLogin: any; }} loginOptions
383
+ * @param {(err: any, api: any) => any} callback
384
+ * @param {any} prCallback
385
+ */
386
+
387
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
388
+ return function(res) {
389
+ var html = res.body,$ = cheerio.load(html),arr = [];
390
+
391
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
392
+
393
+ arr = arr.filter(function(v) {
394
+ return v.val && v.val.length;
395
+ });
396
+ var form = utils.arrToForm(arr);
397
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
398
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
399
+ form.email = email;
400
+ form.pass = password;
401
+ form.default_persistent = '0';
402
+ form.locale = 'en_US';
403
+ form.timezone = '240';
404
+ form.lgnjs = ~~(Date.now() / 1000);
405
+
406
+ html.split("\"_js_").slice(1).map((val) => {
407
+ jar.setCookie(utils.formatCookie(JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]"), "facebook"),"https://www.facebook.com")
408
+ });
409
+
410
+ logger.Normal(Language.OnLogin);
411
+ return utils
412
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
413
+ .then(utils.saveCookies(jar))
414
+ .then(function(/** @type {{ headers: any; }} */res) {
415
+ var headers = res.headers;
416
+ if (!headers.location) throw { error: Language.InvaildAccount };
417
+
418
+ // This means the account has login approvals turned on.
419
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
420
+ logger.Warning(Language.TwoAuth);
421
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
422
+
423
+ return utils
424
+ .get(headers.location, jar, null, loginOptions)
425
+ .then(utils.saveCookies(jar))
426
+ .then(function(res) {
427
+ if (!Database().get('ThroughAcc')) {
428
+ Database().set('ThroughAcc', email);
429
+ }
430
+ else {
431
+ if (String((Database().get('ThroughAcc'))).replace(RegExp('"','g'), '') != String(email).replace(RegExp('"','g'), '')) {
432
+ Database().set('ThroughAcc', email);
433
+ if (Database().get('Through2Fa')) {
434
+ Database().delete('Through2Fa');
435
+ }
436
+ }
437
+ }
438
+ var html = res.body,$ = cheerio.load(html), arr = [];
439
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
440
+ arr = arr.filter(v => { return v.val && v.val.length });
441
+ var form = utils.arrToForm(arr);
442
+ if (html.indexOf("checkpoint/?next") > -1) {
443
+ setTimeout(() => {
444
+ checkVerified = setInterval((_form) => {}, 5000, {
445
+ fb_dtsg: form.fb_dtsg,
446
+ jazoest: form.jazoest,
447
+ dpr: 1
448
+ });
449
+ }, 2500);
450
+ switch (global.Fca.Require.FastConfig.Login2Fa) {
451
+ case true: {
452
+ const question = question => {
453
+ const rl = readline.createInterface({
454
+ input: process.stdin,
455
+ output: process.stdout
456
+ });
457
+ var done,answ;
458
+ rl.question(question, answer => {
459
+ rl.close();
460
+ answ = answer;
461
+ done = true
462
+ })
463
+ deasync.loopWhile(function(){
464
+ return !done;
465
+ });
466
+ return answ;
467
+ };
468
+ try {
469
+ const Old_Cookie = Database().get('Through2Fa');
470
+ if (Old_Cookie) {
471
+ Old_Cookie.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
472
+ let str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
473
+ jar.setCookie(str, "http://" + c.domain);
474
+ });
475
+ let Form = utils.arrToForm(arr);
476
+ Form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
477
+ Form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
478
+ Form.email = email;
479
+ Form.pass = password;
480
+ Form.default_persistent = '0';
481
+ Form.locale = 'en_US';
482
+ Form.timezone = '240';
483
+ Form.lgnjs = ~~(Date.now() / 1000);
484
+ return utils
485
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, Form, loginOptions)
486
+ .then(utils.saveCookies(jar))
487
+ .then(function(res) {
488
+ let headers = res.headers
489
+ if (!headers['set-cookie'][0].includes('deleted')) {
490
+ logger.Warning(Language.ErrThroughCookies, function() {
491
+ Database().delete('Through2Fa');
492
+ });
493
+ process.exit(1);
494
+ }
495
+ if (headers.location && headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
496
+ return utils
497
+ .get(headers.location, jar, null, loginOptions)
498
+ .then(utils.saveCookies(jar))
499
+ .then(function(res) {
500
+ var html = res.body,$ = cheerio.load(html), arr = [];
501
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
502
+ arr = arr.filter(v => { return v.val && v.val.length });
503
+ var Form = utils.arrToForm(arr);
504
+
505
+ if (html.indexOf("checkpoint/?next") > -1) {
506
+ setTimeout(() => {
507
+ checkVerified = setInterval((_form) => {}, 5000, {
508
+ fb_dtsg: Form.fb_dtsg,
509
+ jazoest: Form.jazoest,
510
+ dpr: 1
511
+ });
512
+ }, 2500);
513
+
514
+ if (!res.headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
515
+ try {
516
+ delete Form.name_action_selected;
517
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
518
+ return utils
519
+ .post(nextURL, jar, Form, loginOptions)
520
+ .then(utils.saveCookies(jar))
521
+ .then(function() {
522
+ Form['submit[This was me]'] = "This was me";
523
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
524
+ })
525
+ .then(function() {
526
+ delete Form['submit[This was me]'];
527
+ Form.name_action_selected = 'save_device';
528
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
529
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
530
+ })
531
+ .then(function(res) {
532
+ var headers = res.headers;
533
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
534
+ Database().delete('Through2Fa');
535
+ process.exit(1);
536
+ }
537
+ var appState = utils.getAppState(jar,false);
538
+ Database().set('Through2Fa', appState);
539
+ return loginHelper(appState, email, password, loginOptions, callback);
540
+ })
541
+ .catch((e) => callback(e));
542
+ }
543
+ catch (e) {
544
+ console.log(e)
545
+ }
546
+ }
547
+ }
548
+ })
549
+ }
550
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
551
+ })
552
+ .catch((e) => console.log(e));
553
+ }
554
+ }
555
+ catch (e) {
556
+ Database().delete('Through2Fa');
557
+ }
558
+ const Otp_code = require('totp-generator');
559
+ const Code = global.Fca.Require.FastConfig.AuthString.includes('|') == false ? Otp_code(global.Fca.Require.FastConfig.AuthString.includes(" ") ? global.Fca.Require.FastConfig.AuthString.replace(RegExp(" ", 'g'), "") : global.Fca.Require.FastConfig.AuthString) : question(Language.EnterSecurityCode);
560
+ try {
561
+ const approvals = function(N_Code) {
562
+ form.approvals_code = N_Code;
563
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
564
+ var prResolve,prReject;
565
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
566
+
567
+ if (typeof N_Code == "string") {
568
+ utils
569
+ .post(nextURL, jar, form, loginOptions)
570
+ .then(utils.saveCookies(jar))
571
+ .then(function(res) {
572
+ var $ = cheerio.load(res.body);
573
+ var error = $("#approvals_code").parent().attr("data-xui-error");
574
+ if (error) {
575
+ logger.Warning(Language.InvaildTwoAuthCode,function() { approvals(question(Language.EnterSecurityCode)) }); //bruh loop
576
+ };
577
+ })
578
+ .then(function() {
579
+ delete form.no_fido;delete form.approvals_code;
580
+ form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
581
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
582
+ })
583
+ .then(function(res) {
584
+ var headers = res.headers;
585
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
586
+ try {
587
+ delete form.name_action_selected;
588
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
589
+ return utils
590
+ .post(nextURL, jar, form, loginOptions)
591
+ .then(utils.saveCookies(jar))
592
+ .then(function() {
593
+ form['submit[This was me]'] = "This was me";
594
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
595
+ })
596
+ .then(function() {
597
+ delete form['submit[This was me]'];
598
+ form.name_action_selected = 'save_device';
599
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
600
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
601
+ })
602
+ .then(function(res) {
603
+ var headers = res.headers;
604
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
605
+ var appState = utils.getAppState(jar,false);
606
+ Database().set('Through2Fa', appState);
607
+ return loginHelper(appState, email, password, loginOptions, callback);
608
+ })
609
+ .catch((e) => callback(e));
610
+ }
611
+ catch (e) {
612
+ console.log(e)
613
+ }
614
+ }
615
+ var appState = utils.getAppState(jar,false);
616
+ if (callback === prCallback) {
617
+ callback = function(err, api) {
618
+ if (err) return prReject(err);
619
+ return prResolve(api);
620
+ };
621
+ }
622
+ Database().set('Through2Fa', appState);
623
+ return loginHelper(appState, email, password, loginOptions, callback);
624
+ })
625
+ .catch(function(err) {
626
+ if (callback === prCallback) prReject(err);
627
+ else callback(err);
628
+ });
629
+ }
630
+ else {
631
+ utils
632
+ .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, { "Referer": "https://www.facebook.com/checkpoint/?next" })
633
+ .then(utils.saveCookies(jar))
634
+ .then(function(res) {
635
+ try {
636
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
637
+ } catch (ex) {
638
+ clearInterval(checkVerified);
639
+ logger.Warning(Language.VerifiedCheck);
640
+ if (callback === prCallback) {
641
+ callback = function(err, api) {
642
+ if (err) return prReject(err);
643
+ return prResolve(api);
644
+ };
645
+ }
646
+ let appState = utils.getAppState(jar,false);
647
+ return loginHelper(appState, email, password, loginOptions, callback);
648
+ }
649
+ })
650
+ .catch((ex) => {
651
+ log.error("login", ex);
652
+ if (callback === prCallback) prReject(ex);
653
+ else callback(ex);
654
+ });
655
+ }
656
+ return rtPromise;
657
+ }
658
+ return approvals(Code)
659
+ }
660
+ catch (e) {
661
+ logger.Error(e)
662
+ logger.Error();
663
+ process.exit(0);
664
+ }
665
+ }
666
+ case false: {
667
+ throw {
668
+ error: 'login-approval',
669
+ continue: function submit2FA(code) {
670
+ form.approvals_code = code;
671
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
672
+ var prResolve,prReject;
673
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
674
+ if (typeof code == "string") {
675
+ utils
676
+ .post(nextURL, jar, form, loginOptions)
677
+ .then(utils.saveCookies(jar))
678
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
679
+ var $ = cheerio.load(res.body);
680
+ var error = $("#approvals_code").parent().attr("data-xui-error");
681
+ if (error) {
682
+ throw {
683
+ error: 'login-approval',
684
+ errordesc: Language.InvaildTwoAuthCode,
685
+ lerror: error,
686
+ continue: submit2FA
687
+ };
688
+ }
689
+ })
690
+ .then(function() {
691
+ delete form.no_fido;delete form.approvals_code;
692
+ form.name_action_selected = 'dont_save'; //'save_device' || 'dont_save;
693
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
694
+ })
695
+ .then(function(res) {
696
+ var headers = res.headers;
697
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: Language.ApprovalsErr };
698
+ var appState = utils.getAppState(jar,false);
699
+ if (callback === prCallback) {
700
+ callback = function(err, api) {
701
+ if (err) return prReject(err);
702
+ return prResolve(api);
703
+ };
704
+ }
705
+ return loginHelper(appState, email, password, loginOptions, callback);
706
+ })
707
+ .catch(function(err) {
708
+ if (callback === prCallback) prReject(err);
709
+ else callback(err);
710
+ });
711
+ } else {
712
+ utils
713
+ .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, { "Referer": "https://www.facebook.com/checkpoint/?next" })
714
+ .then(utils.saveCookies(jar))
715
+ .then((res) => {
716
+ try {
717
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
718
+ } catch (ex) {
719
+ clearInterval(checkVerified);
720
+ logger.Warning(Language.VerifiedCheck);
721
+ if (callback === prCallback) {
722
+ callback = function(err, api) {
723
+ if (err) return prReject(err);
724
+ return prResolve(api);
725
+ };
726
+ }
727
+ return loginHelper(utils.getAppState(jar,false), email, password, loginOptions, callback);
728
+ }
729
+ })
730
+ .catch((ex) => {
731
+ log.error("login", ex);
732
+ if (callback === prCallback) prReject(ex);
733
+ else callback(ex);
734
+ });
735
+ }
736
+ return rtPromise;
737
+ }
738
+ };
739
+ }
740
+ }
741
+ } else {
742
+ if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
743
+
744
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
745
+ else form['submit[This Is Okay]'] = "This Is Okay";
746
+
747
+ return utils
748
+ .post(nextURL, jar, form, loginOptions)
749
+ .then(utils.saveCookies(jar))
750
+ .then(function() {
751
+ form.name_action_selected = 'dont_save';
752
+
753
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
754
+ })
755
+ .then(function(res) {
756
+ var headers = res.headers;
757
+
758
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
759
+
760
+ var appState = utils.getAppState(jar,false);
761
+
762
+ return loginHelper(appState, email, password, loginOptions, callback);
763
+ })
764
+ .catch((e) => callback(e));
765
+ }
766
+ });
767
+ }
768
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
769
+ });
770
+ };
771
+ }
772
+
773
+ //-[ Function backup ]-!/
774
+
775
+ /**
776
+ * @param {string} data
777
+ * @param {any} globalOptions
778
+ * @param {any} callback
779
+ * @param {any} prCallback
780
+ */
781
+
782
+ function backup(data,globalOptions, callback, prCallback) {
783
+ try {
784
+ var appstate;
785
+ try {
786
+ appstate = JSON.parse(data)
787
+ }
788
+ catch(e) {
789
+ appstate = data;
790
+ }
791
+ logger.Warning(Language.BackupNoti);
792
+ try {
793
+ loginHelper(appstate,null,null,globalOptions, callback, prCallback)
794
+ }
795
+ catch (e) {
796
+ logger.Error(Language.ErrBackup);
797
+ process.exit(0);
798
+ }
799
+ }
800
+ catch (e) {
801
+ return logger.Error();
802
+ }
803
+ }
804
+
805
+ //-[ function loginHelper ]-!/
806
+
807
+ /**
808
+ * @param {string | any[]} appState
809
+ * @param {any} email
810
+ * @param {any} password
811
+ * @param {{ selfListen?: boolean; listenEvents?: boolean; listenTyping?: boolean; updatePresence?: boolean; forceLogin?: boolean; autoMarkDelivery?: boolean; autoMarkRead?: boolean; autoReconnect?: boolean; logRecordSize?: number; online?: boolean; emitReady?: boolean; userAgent?: string; pageID?: any; }} globalOptions
812
+ * @param {(arg0: any, arg1: undefined) => void} callback
813
+ * @param {(error: any, api: any) => any} [prCallback]
814
+ */
815
+
816
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
817
+ var mainPromise = null;
818
+ var jar = utils.getJar();
819
+
820
+ try {
821
+ if (appState) {
822
+ logger.Normal(Language.OnProcess);
823
+ switch (Database().has("FBKEY")) {
824
+ case true: {
825
+ process.env.FBKEY = Database().get("FBKEY");
826
+ }
827
+ break;
828
+ case false: {
829
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
830
+ process.env['FBKEY'] = SecurityKey;
831
+ Database().set('FBKEY', SecurityKey);
832
+ }
833
+ break;
834
+ default: {
835
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
836
+ process.env['FBKEY'] = SecurityKey;
837
+ Database().set('FBKEY', SecurityKey);
838
+ }
839
+ }
840
+ try {
841
+ switch (global.Fca.Require.FastConfig.EncryptFeature) {
842
+ case true: {
843
+ appState = JSON.parse(JSON.stringify(appState, null, "\t"));
844
+ switch (utils.getType(appState)) {
845
+ case "Array": {
846
+ switch (utils.getType(appState[0])) {
847
+ case "Object": {
848
+ logger.Normal(Language.NotReadyToDecrypt);
849
+ }
850
+ break;
851
+ case "String": {
852
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
853
+ logger.Normal(Language.DecryptSuccess);
854
+ }
855
+ break;
856
+ default: {
857
+ logger.Warning(Language.InvaildAppState);
858
+ process.exit(0)
859
+ }
860
+ }
861
+ }
862
+ break;
863
+ default: {
864
+ logger.Warning(Language.InvaildAppState);
865
+ process.exit(0)
866
+ }
867
+ }
868
+ }
869
+ break;
870
+ case false: {
871
+ switch (utils.getType(appState)) {
872
+ case "Array": {
873
+ switch (utils.getType(appState[0])) {
874
+ case "Object": {
875
+ logger.Normal(Language.EncryptStateOff);
876
+ }
877
+ break;
878
+ case "String": {
879
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
880
+ logger.Normal(Language.EncryptStateOff);
881
+ logger.Normal(Language.DecryptSuccess);
882
+ }
883
+ break;
884
+ default: {
885
+ logger.Warning(Language.InvaildAppState);
886
+ process.exit(0)
887
+ }
888
+ }
889
+ }
890
+ break;
891
+ default: {
892
+ logger.Warning(Language.InvaildAppState);
893
+ process.exit(0)
894
+ }
895
+ }
896
+ }
897
+ break;
898
+ default: {
899
+ logger.Warning(getText(Language.IsNotABoolean,global.Fca.Require.FastConfig.EncryptFeature))
900
+ process.exit(0);
901
+ }
902
+ }
903
+ }
904
+ catch (e) {
905
+ console.log(e);
906
+ }
907
+
908
+ try {
909
+ appState = JSON.parse(appState);
910
+ }
911
+ catch (e) {
912
+ try {
913
+ appState = appState;
914
+ }
915
+ catch (e) {
916
+ return logger.Error();
917
+ }
918
+ }
919
+ try {
920
+ global.Fca.Data.AppState = appState;
921
+ appState.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
922
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
923
+ jar.setCookie(str, "http://" + c.domain);
924
+ });
925
+ Database().set('Backup', appState);
926
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
927
+ }
928
+ catch (e) {
929
+ try {
930
+ if (Database().has('Backup')) {
931
+ return backup(Database().get('Backup'),globalOptions, callback, prCallback);
932
+ }
933
+ else {
934
+ logger.Warning(Language.ErrBackup);
935
+ process.exit(0);
936
+ }
937
+ }
938
+ catch (e) {
939
+ logger.Warning(Language.ErrBackup);
940
+ process.exit(0);
941
+ }
942
+ }
943
+ }
944
+
945
+ else {
946
+ mainPromise = utils
947
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
948
+ .then(utils.saveCookies(jar))
949
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
950
+ .then(function() {
951
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
952
+ });
953
+ }
954
+ } catch (e) {
955
+ console.log(e);
956
+ }
957
+
958
+ function CheckAndFixErr(res) {
959
+ let reg_antierr = /This browser is not supported/gs; // =))))))
960
+ if (reg_antierr.test(res.body)) {
961
+ const Data = JSON.stringify(res.body);
962
+ const Dt_Check = Data.split('2Fhome.php&amp;gfid=')[1];
963
+ if (Dt_Check == undefined) return res
964
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
965
+ if (Dt_Check == undefined || Dt_Check == "") return res
966
+ const final_fid = fid.split(`\\`)[0];
967
+ if (final_fid == undefined || final_fid == '') return res;
968
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
969
+ bypass_region_err = true;
970
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
971
+ }
972
+ else return res
973
+ }
974
+
975
+ function Redirect(res) {
976
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
977
+ redirect = reg.exec(res.body);
978
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
979
+ return res;
980
+ }
981
+
982
+ let redirect = [1, "https://m.facebook.com/"];
983
+ let bypass_region_err = false;
984
+ var ctx,api;
985
+ mainPromise = mainPromise
986
+ .then(res => Redirect(res))
987
+ .then(res => CheckAndFixErr(res))
988
+
989
+ //fix via login with defaut UA return WWW.facebook.com not m.facebook.com
990
+
991
+ .then(function(res) {
992
+ 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
993
+ if (!Regex_Via.test(res.body)) {
994
+ //www.facebook.com
995
+ 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";
996
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
997
+ }
998
+ else return res
999
+ })
1000
+ .then(res => Redirect(res))
1001
+ .then(res => CheckAndFixErr(res))
1002
+ // .then(function(res) {
1003
+ // let reg_old_web = /Switch Default Site/gs;
1004
+ // if (reg_old_web.test(res.body)) {
1005
+ // let Data_Resp = JSON.stringify(res.body);
1006
+ // const link = Data_Resp.split('settings/site')[1].split("\"")[0].replace('\\', '')
1007
+ // const redirect_link2 = redirect[1] + "settings/site" + utils.cleanHTML(link)
1008
+ // console.log(redirect_link2)
1009
+ // return utils.get("https://www.facebook.com/", jar, null, globalOptions).then(utils.saveCookies(jar)); // try ag
1010
+ // }
1011
+ // else return res;
1012
+ // })
1013
+ // .then(function(res) {
1014
+ // var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1015
+ // redirect = reg.exec(res.body);
1016
+ // if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1017
+ // return res;
1018
+ // })
1019
+ .then(function(res){
1020
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar,bypass_region_err);
1021
+ ctx = Obj.ctx;
1022
+ api = Obj.api;
1023
+ return res;
1024
+ });
1025
+ if (globalOptions.pageID) {
1026
+ mainPromise = mainPromise
1027
+ .then(function() {
1028
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
1029
+ })
1030
+ .then(function(resData) {
1031
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
1032
+ url = url.substring(0, url.length - 1);
1033
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
1034
+ });
1035
+ }
1036
+ mainPromise
1037
+ .then(async() => {
1038
+ logger.Normal(getText(Language.LocalVersion,global.Fca.Version));
1039
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1040
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1041
+ require('./Extra/ExtraUptimeRobot')();
1042
+ callback(null, api);
1043
+ }).catch(function(/** @type {{ error: any; }} */e) {
1044
+ log.error("login", e.error || e);
1045
+ callback(e);
1046
+ });
1047
+ }
1048
+
1049
+ /**
1050
+ * It asks the user for their account and password, and then saves it to the database.
1051
+ */
1052
+
1053
+ function setUserNameAndPassWord() {
1054
+ let rl = readline.createInterface({
1055
+ input: process.stdin,
1056
+ output: process.stdout
1057
+ });
1058
+
1059
+ console.clear();
1060
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1061
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1062
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1063
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1064
+ try {
1065
+ rl.question(Language.TypeAccount, (Account) => {
1066
+ if (!Account.includes("@") && global.Fca.Require.utils.getType(parseInt(Account)) != "Number") return logger.Normal(Language.TypeAccountError, function () { process.exit(1) }); //Very Human
1067
+ else rl.question(Language.TypePassword, function (Password) {
1068
+ rl.close();
1069
+ try {
1070
+ Database().set("Account", Account);
1071
+ Database().set("Password", Password);
1072
+ }
1073
+ catch (e) {
1074
+ logger.Warning(Language.ErrDataBase);
1075
+ logger.Error();
1076
+ process.exit(0);
1077
+ }
1078
+ if (global.Fca.Require.FastConfig.ResetDataLogin) {
1079
+ global.Fca.Require.FastConfig.ResetDataLogin = false;
1080
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/FastConfigFca.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1081
+ }
1082
+ logger.Success(Language.SuccessSetData);
1083
+ process.exit(1);
1084
+ });
1085
+ })
1086
+ }
1087
+ catch (e) {
1088
+ logger.Error(e)
1089
+ }
1090
+ }
1091
+
1092
+ /**
1093
+ * @param {{ email: any; password: any; appState: any; }} loginData
1094
+ * @param {{}} options
1095
+ * @param {(error: any, api: any) => any} callback
1096
+ */
1097
+
1098
+ function login(loginData, options, callback) {
1099
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1100
+ callback = options;
1101
+ options = {};
1102
+ }
1103
+
1104
+ var globalOptions = {
1105
+ selfListen: false,
1106
+ listenEvents: true,
1107
+ listenTyping: false,
1108
+ updatePresence: false,
1109
+ forceLogin: false,
1110
+ autoMarkDelivery: false,
1111
+ autoMarkRead: false,
1112
+ autoReconnect: true,
1113
+ logRecordSize: 100,
1114
+ online: false,
1115
+ emitReady: false,
1116
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
1117
+ };
1118
+
1119
+ var prCallback = null;
1120
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1121
+ var rejectFunc = null;
1122
+ var resolveFunc = null;
1123
+ var returnPromise = new Promise(function(resolve, reject) {
1124
+ resolveFunc = resolve;
1125
+ rejectFunc = reject;
1126
+ });
1127
+ prCallback = function(error, api) {
1128
+ if (error) return rejectFunc(error);
1129
+ return resolveFunc(api);
1130
+ };
1131
+ callback = prCallback;
1132
+ }
1133
+
1134
+ if (loginData.email && loginData.password) {
1135
+ setOptions(globalOptions, {
1136
+ logLevel: "silent",
1137
+ forceLogin: true,
1138
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"
1139
+ });
1140
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1141
+ }
1142
+ else if (loginData.appState) {
1143
+ setOptions(globalOptions, options);
1144
+ let All = (getAll()).filter(i => i.data.messageCount !== undefined);
1145
+ if (All.length >= 1) {
1146
+ deleteAll(All.map(obj => obj.data.threadID));
1147
+ }
1148
+ /*
1149
+ if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
1150
+ const UserName = Database().get('Ws_UserName');
1151
+ const PassWord = Database().get("Ws_PassWord");
1152
+ if (!UserName || !PassWord || global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1153
+ const question = question => {
1154
+ const rl = readline.createInterface({
1155
+ input: process.stdin,
1156
+ output: process.stdout
1157
+ });
1158
+ var done,answ;
1159
+ rl.question(question, answer => {
1160
+ rl.close();
1161
+ answ = answer;
1162
+ done = true
1163
+ })
1164
+ deasync.loopWhile(function(){
1165
+ return !done;
1166
+ });
1167
+ return answ;
1168
+ };
1169
+ console.clear();
1170
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1171
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1172
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1173
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1174
+ const UserName = question(Language.Ws_TypeUserName);
1175
+ const PassWord = question(Language.Ws_TypePassWord);
1176
+ if (!UserName || !PassWord) {
1177
+ logger.Warning("Dangerous action detected! Proceeding to automatically disable websocket_extension.");
1178
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1179
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1180
+ }
1181
+ else {
1182
+ try {
1183
+ Database().set('Ws_UserName', UserName);
1184
+ Database().set('Ws_PassWord', PassWord);
1185
+ logger.Success(Language.Ws_Success, function() {
1186
+ const speakeasy = require('speakeasy');
1187
+ const secret = (speakeasy.generateSecret({ length: 20 }));
1188
+ logger.Warning(getText(Language.Ws_2Fa, secret.base32))
1189
+ Database().set('Ws_2Fa', secret.base32);
1190
+ if (global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1191
+ global.Fca.Require.FastConfig.Websocket_Extension.ResetData = false;
1192
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/FastConfigFca.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1193
+ }
1194
+ question("Enter To Continue!");
1195
+ const ask = function() {
1196
+ const TFa_Check = question(Language.Ws_2Fa_Check)
1197
+ if (TFa_Check != speakeasy.totp({
1198
+ secret: secret.base32,
1199
+ encoding: 'base32'
1200
+ })) {
1201
+ logger.Warning("Mã Không Đúng vui lòng nhập lại(Incorrect code, please enter again.)")
1202
+ ask();
1203
+ }
1204
+ else {
1205
+ logger.Success("Success!");
1206
+ process.exit(1);
1207
+ }
1208
+ }
1209
+ return ask();
1210
+ });
1211
+ }
1212
+ catch (e) {
1213
+ console.log(e)
1214
+ logger.Warning("Error, auto turn off Websocket_extension");
1215
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1216
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1217
+ process.exit(1);
1218
+ }
1219
+ }
1220
+ }
1221
+ }
1222
+ **/
1223
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
1224
+ case true: {
1225
+ if (global.Fca.Require.FastConfig.ResetDataLogin) return setUserNameAndPassWord();
1226
+ else {
1227
+ try {
1228
+ const TempState = Database().get("TempState")
1229
+ if (TempState) {
1230
+ try {
1231
+ loginData.appState = JSON.parse(TempState);
1232
+ }
1233
+ catch (_) {
1234
+ loginData.appState = TempState;
1235
+ }
1236
+ Database().delete("TempState");
1237
+ }
1238
+ }
1239
+ catch (e) {
1240
+ console.log(e)
1241
+ Database().delete("TempState");
1242
+ logger.Warning(Language.ErrDataBase);
1243
+ logger.Error();
1244
+ process.exit(0);
1245
+ }
1246
+ try {
1247
+ if (Database().has('Account') && Database().has('Password')) return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1248
+ else return setUserNameAndPassWord();
1249
+ }
1250
+ catch (e) {
1251
+ console.log(e)
1252
+ logger.Warning(Language.ErrDataBase);
1253
+ logger.Error();
1254
+ process.exit(0);
1255
+ }
1256
+ }
1257
+ }
1258
+ case false: {
1259
+ return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1260
+ }
1261
+ }
1262
+ }
1263
+ return returnPromise;
1264
+ }
1265
+
1266
+ module.exports = login;