fca-nguyendz 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fca-nguyendz might be problematic. Click here for more details.

Files changed (103) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.cache/replit/nix/env.json +1 -0
  3. package/.config/configstore/update-notifier-npm.json +10 -0
  4. package/.config/configstore/update-notifier-npm.json.1735545094 +4 -0
  5. package/.gitattributes +2 -0
  6. package/.replit +80 -0
  7. package/Extra/Database/index.js +358 -0
  8. package/Extra/ExtraAddons.js +78 -0
  9. package/Extra/ExtraFindUID.js +60 -0
  10. package/Extra/ExtraGetThread.js +118 -0
  11. package/Extra/ExtraScreenShot.js +430 -0
  12. package/Extra/ExtraUptimeRobot.js +26 -0
  13. package/Extra/Html/Classic/script.js +119 -0
  14. package/Extra/Html/Classic/style.css +8 -0
  15. package/Extra/Security/Index.js +146 -0
  16. package/Extra/Security/Step_1.js +11 -0
  17. package/Extra/Security/Step_2.js +20 -0
  18. package/Extra/Security/Step_3.js +20 -0
  19. package/Extra/Src/History.js +115 -0
  20. package/Extra/Src/Last-Run.js +65 -0
  21. package/Extra/Src/Premium.js +84 -0
  22. package/Func/AcceptAgreement.js +32 -0
  23. package/Func/ClearCache.js +64 -0
  24. package/Func/ReportV1.js +54 -0
  25. package/LICENSE +24 -0
  26. package/Language/index.json +177 -0
  27. package/README.md +134 -0
  28. package/SECURITY.md +17 -0
  29. package/broadcast.js +38 -0
  30. package/index.js +1381 -0
  31. package/logger.js +65 -0
  32. package/package.json +97 -0
  33. package/replit.nix +8 -0
  34. package/src/Dev_Horizon_Data.js +125 -0
  35. package/src/Premium.js +30 -0
  36. package/src/Screenshot.js +85 -0
  37. package/src/addExternalModule.js +16 -0
  38. package/src/addUserToGroup.js +79 -0
  39. package/src/changeAdminStatus.js +79 -0
  40. package/src/changeArchivedStatus.js +41 -0
  41. package/src/changeAvt.js +85 -0
  42. package/src/changeBio.js +65 -0
  43. package/src/changeBlockedStatus.js +36 -0
  44. package/src/changeGroupImage.js +106 -0
  45. package/src/changeNickname.js +45 -0
  46. package/src/changeThreadColor.js +62 -0
  47. package/src/changeThreadEmoji.js +42 -0
  48. package/src/createNewGroup.js +70 -0
  49. package/src/createPoll.js +60 -0
  50. package/src/deleteMessage.js +45 -0
  51. package/src/deleteThread.js +43 -0
  52. package/src/forwardAttachment.js +48 -0
  53. package/src/getAccessToken.js +32 -0
  54. package/src/getCurrentUserID.js +7 -0
  55. package/src/getEmojiUrl.js +27 -0
  56. package/src/getFriendsList.js +73 -0
  57. package/src/getMessage.js +80 -0
  58. package/src/getThreadHistory.js +537 -0
  59. package/src/getThreadInfo.js +348 -0
  60. package/src/getThreadList.js +213 -0
  61. package/src/getThreadMain.js +220 -0
  62. package/src/getThreadPictures.js +59 -0
  63. package/src/getUID.js +59 -0
  64. package/src/getUserID.js +62 -0
  65. package/src/getUserInfo.js +129 -0
  66. package/src/getUserInfoMain.js +65 -0
  67. package/src/getUserInfoV2.js +36 -0
  68. package/src/getUserInfoV3.js +63 -0
  69. package/src/getUserInfoV4.js +55 -0
  70. package/src/getUserInfoV5.js +61 -0
  71. package/src/handleFriendRequest.js +46 -0
  72. package/src/handleMessageRequest.js +49 -0
  73. package/src/httpGet.js +49 -0
  74. package/src/httpPost.js +48 -0
  75. package/src/httpPostFormData.js +41 -0
  76. package/src/listenMqtt.js +702 -0
  77. package/src/logout.js +68 -0
  78. package/src/markAsDelivered.js +48 -0
  79. package/src/markAsRead.js +70 -0
  80. package/src/markAsReadAll.js +43 -0
  81. package/src/markAsSeen.js +51 -0
  82. package/src/muteThread.js +47 -0
  83. package/src/removeUserFromGroup.js +49 -0
  84. package/src/resolvePhotoUrl.js +37 -0
  85. package/src/searchForThread.js +43 -0
  86. package/src/sendMessage.js +334 -0
  87. package/src/sendTypingIndicator.js +80 -0
  88. package/src/setMessageReaction.js +109 -0
  89. package/src/setPostReaction.js +102 -0
  90. package/src/setTitle.js +74 -0
  91. package/src/threadColors.js +39 -0
  92. package/src/unfriend.js +43 -0
  93. package/src/unsendMessage.js +40 -0
  94. package/test/data/shareAttach.js +146 -0
  95. package/test/data/something.mov +0 -0
  96. package/test/data/test.png +0 -0
  97. package/test/data/test.txt +7 -0
  98. package/test/env/.env +0 -0
  99. package/test/example-config.json +18 -0
  100. package/test/test-page.js +140 -0
  101. package/test/test.js +385 -0
  102. package/test/testv2.js +3 -0
  103. package/utils.js +1648 -0
package/index.js ADDED
@@ -0,0 +1,1381 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Developers: @KanzuWakazaki - @HarryWakazaki
5
+ ** A few words about developer appstate security.
6
+ *! Statement renouncing responsibility for the security of appstate encryption of the following operating systems: windows, Android, Linux operating systems,.. (maybe repl.it?),
7
+ *! because the above operating systems are private (except rep.it if the fraudster does not own your account or invite link to join).
8
+ *! If the intruder owns the computer, these private operating systems,the security of this fca cannot guarantee 100% of the time.
9
+ ** If the grammar is wrong, please understand because I'm just a kid 🍵.
10
+ */
11
+
12
+ /!-[ Global Set ]-!/
13
+
14
+ global.Fca = new Object({
15
+ isThread: new Array(),
16
+ isUser: new Array(),
17
+ startTime: Date.now(),
18
+ Setting: new Map(),
19
+ Version: require('./package.json').version,
20
+ Require: new Object({
21
+ fs: require("fs"),
22
+ Fetch: require('got'),
23
+ log: require("npmlog"),
24
+ utils: require("./utils"),
25
+ logger: require('./logger'),
26
+ Security: require("uuid-apikey"),
27
+ languageFile: require('./Language/index.json'),
28
+ Database: require("./Extra/Database")
29
+ }),
30
+ getText: function(/** @type {any[]} */...Data) {
31
+ var Main = (Data.splice(0,1)).toString();
32
+ for (let i = 0; i < Data.length; i++) Main = Main.replace(RegExp(`%${i + 1}`, 'g'), Data[i]);
33
+ return Main;
34
+ },
35
+ Data: new Object({
36
+ ObjFastConfig: {
37
+ "Language": "vi",
38
+ "PreKey": "",
39
+ "AutoUpdate": true,
40
+ "MainColor": "#9900FF",
41
+ "MainName": "[ FCA-HZI ]",
42
+ "Logo": true,
43
+ "Uptime": false,
44
+ "Config": "default",
45
+ "Login2Fa": false,
46
+ "AutoLogin": false,
47
+ "BroadCast": true,
48
+ "AuthString": "SD4S XQ32 O2JA WXB3 FUX2 OPJ7 Q7JZ 4R6Z | https://i.imgur.com/RAg3rvw.png Please remove this !, Recommend If You Using getUserInfoV2",
49
+ "EncryptFeature": true,
50
+ "ResetDataLogin": false,
51
+ "AutoRestartMinutes": 0,
52
+ "HTML": {
53
+ "HTML": true,
54
+ "UserName": "Guest",
55
+ "MusicLink": "https://drive.google.com/uc?id=1zlAALlxk1TnO7jXtEP_O6yvemtzA2ukA&export=download"
56
+ }
57
+ },
58
+ CountTime: function() {
59
+ var fs = global.Fca.Require.fs;
60
+ if (fs.existsSync(__dirname + '/CountTime.json')) {
61
+ try {
62
+ var data = Number(fs.readFileSync(__dirname + '/CountTime.json', 'utf8')),
63
+ hours = Math.floor(data / (60 * 60));
64
+ }
65
+ catch (e) {
66
+ fs.writeFileSync(__dirname + '/CountTime.json', 0);
67
+ hours = 0;
68
+ }
69
+ }
70
+ else {
71
+ hours = 0;
72
+ }
73
+ return `${hours} Hours`;
74
+ }
75
+ }),
76
+ AutoLogin: async function () {
77
+ var Database = global.Fca.Require.Database;
78
+ var logger = global.Fca.Require.logger;
79
+ var Email = (await global.Fca.Require.Database.get('Account')).replace(RegExp('"', 'g'), ''); //hmm IDK
80
+ var PassWord = (await global.Fca.Require.Database.get('Password')).replace(RegExp('"', 'g'), '');
81
+ login({ email: Email, password: PassWord},async (error, api) => {
82
+ if (error) {
83
+ logger.Error(JSON.stringify(error,null,2), function() { logger.Error("AutoLogin Failed!", function() { process.exit(0); }) });
84
+ }
85
+ try {
86
+ await Database.set("TempState", api.getAppState());
87
+ }
88
+ catch(e) {
89
+ logger.Warning(global.Fca.Require.Language.Index.ErrDatabase);
90
+ logger.Error();
91
+ process.exit(0);
92
+ }
93
+ process.exit(1);
94
+ });
95
+ }
96
+ });
97
+
98
+ /!-[ Check File To Run Process ]-!/
99
+
100
+ let Boolean_Fca = ["AutoUpdate","Uptime","BroadCast","EncryptFeature","AutoLogin","ResetDataLogin","Login2Fa","Logo"];
101
+ let String_Fca = ["MainName","PreKey","Language","AuthString","Config"]
102
+ let Number_Fca = ["AutoRestartMinutes"];
103
+ let All_Variable = Boolean_Fca.concat(String_Fca,Number_Fca);
104
+
105
+ try {
106
+ if (!global.Fca.Require.fs.existsSync(process.cwd() + '/FastConfigFca.json')) {
107
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
108
+ process.exit(1);
109
+ }
110
+
111
+ try {
112
+ var DataLanguageSetting = require(process.cwd() + "/FastConfigFca.json");
113
+ }
114
+ catch (e) {
115
+ global.Fca.Require.logger.Error('Detect Your FastConfigFca Settings Invalid!, Carry out default restoration');
116
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
117
+ process.exit(1)
118
+ }
119
+ if (global.Fca.Require.fs.existsSync(process.cwd() + '/FastConfigFca.json')) {
120
+ try {
121
+ if (DataLanguageSetting.Logo == undefined || global.Fca.Require.utils.getType(DataLanguageSetting.Logo) != 'Boolean') {
122
+ DataLanguageSetting.Logo = true
123
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(DataLanguageSetting, null, "\t"));
124
+ }
125
+ }
126
+ catch (e) {
127
+ console.log(e);
128
+ }
129
+ if (!global.Fca.Require.languageFile.some((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language)) {
130
+ global.Fca.Require.logger.Warning("Not Support Language: " + DataLanguageSetting.Language + " Only 'en' and 'vi'");
131
+ process.exit(0);
132
+ }
133
+ var Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language).Folder.Index;
134
+ global.Fca.Require.Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language).Folder;
135
+ } else process.exit(1);
136
+ for (let i in DataLanguageSetting) {
137
+ if (Boolean_Fca.includes(i)) {
138
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "Boolean") return logger.Error(i + " Is Not A Boolean, Need To Be true Or false !", function() { process.exit(0) });
139
+ else continue;
140
+ }
141
+ else if (String_Fca.includes(i)) {
142
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "String") return logger.Error(i + " Is Not A String, Need To Be String!", function() { process.exit(0) });
143
+ else continue;
144
+ }
145
+ else if (Number_Fca.includes(i)) {
146
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "Number") return logger.Error(i + " Is Not A Number, Need To Be Number !", function() { process.exit(0) });
147
+ else continue;
148
+ }
149
+ }
150
+ for (let i of All_Variable) {
151
+ if (!DataLanguageSetting[All_Variable[i]] == undefined) {
152
+ DataLanguageSetting[All_Variable[i]] = global.Fca.Data.ObjFastConfig[All_Variable[i]];
153
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/FastConfigFca.json", JSON.stringify(DataLanguageSetting, null, "\t"));
154
+ }
155
+ else continue;
156
+ }
157
+ global.Fca.Require.FastConfig = DataLanguageSetting;
158
+ }
159
+ catch (e) {
160
+ console.log(e);
161
+ global.Fca.Require.logger.Error();
162
+ }
163
+
164
+ /!-[ Nham Nham Nham ]-!/;
165
+
166
+ if (global.Fca.Require.FastConfig.Logo == true) {
167
+ console.clear()
168
+ setTimeout(async function() {
169
+ for (let i = 0; i < 7; i++) {
170
+ let Text = ['H','O','R','I','Z','O','N']
171
+ console.log(figlet.textSync(Text[i], {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }))
172
+ await new Promise(resolve => setTimeout(resolve, 1*400))
173
+ console.clear()
174
+ }
175
+ await new Promise(resolve => setTimeout(resolve, 1*400))
176
+ console.clear()
177
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }))
178
+ },1 * 400);
179
+ }
180
+
181
+ /!-[ Require config and use ]-!/
182
+
183
+ if (global.Fca.Require.FastConfig.Config != 'default') {
184
+ //do ssth
185
+ }
186
+
187
+ /!-[ Require All Package Need Use ]-!/
188
+
189
+ var utils = global.Fca.Require.utils,
190
+ logger = global.Fca.Require.logger,
191
+ fs = global.Fca.Require.fs,
192
+ getText = global.Fca.getText,
193
+ log = global.Fca.Require.log,
194
+ Fetch = global.Fca.Require.Fetch,
195
+ express = require("express")(),
196
+ { join, resolve } = require('path'),
197
+ cheerio = require("cheerio"),
198
+ StateCrypt = {},
199
+ { readFileSync } = require('fs-extra'),
200
+ Database = require("./Extra/Database"),
201
+ readline = require("readline"),
202
+ chalk = require("chalk"),
203
+ figlet = require("figlet"),
204
+ os = require("os"),
205
+ Security = require("./Extra/Security/Index");
206
+
207
+ /!-[ Set Variable For Process ]-!/
208
+
209
+ log.maxRecordSize = 100;
210
+ var checkVerified = null;
211
+ var Boolean_Option = ['online','selfListen','listenEvents','updatePresence','forceLogin','autoMarkDelivery','autoMarkRead','listenTyping','autoReconnect','emitReady'];
212
+
213
+ /!-[ Set And Check Template HTML ]-!/
214
+
215
+ var css = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'style.css'));
216
+ var js = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'script.js'));
217
+
218
+ /!-[ Function Generate HTML Template ]-!/
219
+
220
+ /**
221
+ * It returns a string of HTML code.
222
+ * @param UserName - The username of the user
223
+ * @param Type - The type of user, either "Free" or "Premium"
224
+ * @param link - The link to the music you want to play
225
+ * @returns A HTML file
226
+ */
227
+
228
+ function ClassicHTML(UserName,Type,link) {
229
+ return `<!DOCTYPE html>
230
+ <html lang="en" >
231
+ <head>
232
+ <meta charset="UTF-8">
233
+ <title>Horizon</title>
234
+ <link rel="stylesheet" href="./style.css">
235
+ </head>
236
+ <body>
237
+ <center>
238
+ <marquee><b>waiting for u :d</b></marquee>
239
+ <h2>Horizon User Infomation</h2>
240
+ <h3>UserName: ${UserName} | Type: ${Type}</h3>
241
+ <canvas id="myCanvas"></canvas>
242
+ <script src="./script.js"></script>
243
+ <footer class="footer">
244
+ <div id="music">
245
+ <audio autoplay="false" controls="true" loop="true" src="${link}" __idm_id__="5070849">Your browser does not support the audio element.</audio>
246
+ <br><b>Session ID:</b> ${global.Fca.Require.Security.create().uuid}<br>
247
+ <br>Thanks For Using <b>Fca-Horizon-Remastered</b> - From <b>Kanzu</b> <3<br>
248
+ </div>
249
+ </footer>
250
+ </div>
251
+ </center>
252
+ </html>
253
+ </body>`
254
+ //lazy to change
255
+ }
256
+
257
+ /!-[ Stating Http Infomation ]-!/
258
+
259
+ express.set('DFP', (process.env.PORT || process.env.port || 1932));
260
+ express.use(function(req, res, next) {
261
+ switch (req.url.split('?')[0]) {
262
+ case '/script.js': {
263
+ res.writeHead(200, { 'Content-Type': 'text/javascript' });
264
+ res.write(js);
265
+ break;
266
+ }
267
+ case '/style.css': {
268
+ res.writeHead(200, { 'Content-Type': 'text/css' });
269
+ res.write(css);
270
+ break;
271
+ }
272
+ // case '/History': {
273
+ // if (req.query.PassWord == process.env.REPL_OWNER) {
274
+ // res.writeHead(200, { 'Content-Type': 'application/json charset=utf-8' });
275
+ // res.write(JSON.stringify(console.history,null,2),'utf8');
276
+ // res.end();
277
+ // }
278
+ // else res.json({
279
+ // Status: false,
280
+ // Error: "Thiếu Params ?PassWord=PassWordCuaBan =))"
281
+ // });
282
+ // break;
283
+ // }
284
+ default: {
285
+ res.writeHead(200, "OK", { "Content-Type": "text/html" });
286
+ res.write(ClassicHTML(global.Fca.Require.FastConfig.HTML.UserName, global.Fca.Data.PremText.includes("Premium") ? "Premium": "Free", global.Fca.Require.FastConfig.HTML.MusicLink));
287
+ }
288
+ }
289
+ res.end();
290
+ })
291
+
292
+ global.Fca.Require.Web = express;
293
+
294
+ /!-[ Function setOptions ]-!/
295
+
296
+ /**
297
+ * @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
298
+ * @param {{ [x: string]: any; logLevel?: any; forceLogin?: boolean; userAgent?: any; pauseLog?: any; logRecordSize?: any; pageID?: any; proxy?: any; }} options
299
+ */
300
+
301
+ function setOptions(globalOptions, options) {
302
+ Object.keys(options).map(function(key) {
303
+ switch (Boolean_Option.includes(key)) {
304
+ case true: {
305
+ globalOptions[key] = Boolean(options[key]);
306
+ break;
307
+ }
308
+ case false: {
309
+ switch (key) {
310
+ case 'pauseLog': {
311
+ if (options.pauseLog) log.pause();
312
+ else log.resume();
313
+ break;
314
+ }
315
+ case 'logLevel': {
316
+ log.level = options.logLevel;
317
+ globalOptions.logLevel = options.logLevel;
318
+ break;
319
+ }
320
+ case 'logRecordSize': {
321
+ log.maxRecordSize = options.logRecordSize;
322
+ globalOptions.logRecordSize = options.logRecordSize;
323
+ break;
324
+ }
325
+ case 'pageID': {
326
+ globalOptions.pageID = options.pageID.toString();
327
+ break;
328
+ }
329
+ case 'userAgent': {
330
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36');
331
+ break;
332
+ }
333
+ case 'proxy': {
334
+ if (typeof options.proxy != "string") {
335
+ delete globalOptions.proxy;
336
+ utils.setProxy();
337
+ } else {
338
+ globalOptions.proxy = options.proxy;
339
+ utils.setProxy(globalOptions.proxy);
340
+ }
341
+ break;
342
+ }
343
+ default: {
344
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
345
+ break;
346
+ }
347
+ }
348
+ break;
349
+ }
350
+ }
351
+ });
352
+ }
353
+
354
+ /!-[ Function BuildAPI ]-!/
355
+
356
+ /**
357
+ * @param {any} globalOptions
358
+ * @param {string} html
359
+ * @param {{ getCookies: (arg0: string) => any[]; }} jar
360
+ */
361
+
362
+ function buildAPI(globalOptions, html, jar) {
363
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(/** @type {{ cookieString: () => string; }} */val) { return val.cookieString().split("=")[0] === "c_user"; });
364
+
365
+ if (maybeCookie.length === 0) {
366
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
367
+ case true: {
368
+ global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
369
+ return global.Fca.AutoLogin();
370
+ });
371
+ break;
372
+ }
373
+ case false: {
374
+ throw { error: global.Fca.Require.Language.Index.ErrAppState };
375
+
376
+ }
377
+ }
378
+ }
379
+
380
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
381
+
382
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
383
+ process.env['UID'] = logger.Normal(getText(Language.UID,userID), userID);
384
+
385
+ try {
386
+ clearInterval(checkVerified);
387
+ } catch (e) {
388
+ console.log(e);
389
+ }
390
+
391
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
392
+
393
+ var CHECK_MQTT = {
394
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
395
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
396
+ legacyFBMQTTMatch: html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/)
397
+ }
398
+
399
+ let Slot = Object.keys(CHECK_MQTT);
400
+
401
+ var mqttEndpoint,region,irisSeqID;
402
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
403
+ if (CHECK_MQTT[MQTT] && !region) {
404
+ switch (Slot.indexOf(MQTT)) {
405
+ case 0: {
406
+ irisSeqID = CHECK_MQTT[MQTT][1];
407
+ mqttEndpoint = CHECK_MQTT[MQTT][2];
408
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
409
+ return;
410
+ }
411
+ case 1: {
412
+ irisSeqID = CHECK_MQTT[MQTT][2];
413
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
414
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
415
+ return;
416
+ }
417
+ case 2: {
418
+ mqttEndpoint = CHECK_MQTT[MQTT][4];
419
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
420
+ return;
421
+ }
422
+ }
423
+ return;
424
+ }
425
+ });
426
+
427
+ var ctx = {
428
+ userID: userID,
429
+ jar: jar,
430
+ clientID: clientID,
431
+ globalOptions: globalOptions,
432
+ loggedIn: true,
433
+ access_token: 'NONE',
434
+ clientMutationId: 0,
435
+ mqttClient: undefined,
436
+ lastSeqId: irisSeqID,
437
+ syncToken: undefined,
438
+ mqttEndpoint: mqttEndpoint,
439
+ region: region,
440
+ firstListen: true
441
+ };
442
+
443
+ var api = {
444
+ setOptions: setOptions.bind(null, globalOptions),
445
+ getAppState: function getAppState() {
446
+ return utils.getAppState(jar);
447
+ }
448
+ };
449
+
450
+ if (region && mqttEndpoint) {
451
+ //do sth
452
+ }
453
+ else {
454
+ log.warn("login", getText(Language.NoAreaData));
455
+ api["htmlData"] = html;
456
+ }
457
+
458
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
459
+
460
+ fs.readdirSync(__dirname + "/src").filter((/** @type {string} */File) => File.endsWith(".js") && !File.includes('Dev_')).map((/** @type {string} */File) => api[File.split('.').slice(0, -1).join('.')] = require('./src/' + File)(defaultFuncs, api, ctx));
461
+
462
+ return {
463
+ ctx,
464
+ defaultFuncs,
465
+ api
466
+ };
467
+ }
468
+
469
+ /!-[ Function makeLogin ]-!/
470
+
471
+ /**
472
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
473
+ * @param {any} email
474
+ * @param {any} password
475
+ * @param {{ forceLogin: any; }} loginOptions
476
+ * @param {(err: any, api: any) => any} callback
477
+ * @param {any} prCallback
478
+ */
479
+
480
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
481
+ return function(/** @type {{ body: any; }} */res) {
482
+ var html = res.body,$ = cheerio.load(html),arr = [];
483
+
484
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
485
+
486
+ arr = arr.filter(function(v) {
487
+ return v.val && v.val.length;
488
+ });
489
+
490
+ var form = utils.arrToForm(arr);
491
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
492
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
493
+ form.email = email;
494
+ form.pass = password;
495
+ form.default_persistent = '0';
496
+ form.locale = 'en_US';
497
+ form.timezone = '240';
498
+ form.lgnjs = ~~(Date.now() / 1000);
499
+
500
+ html.split("\"_js_").slice(1).map((/** @type {any} */val) => {
501
+ jar.setCookie(utils.formatCookie(JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]"), "facebook"),"https://www.facebook.com")
502
+ });
503
+
504
+ logger.Normal(Language.OnLogin);
505
+ return utils
506
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
507
+ .then(utils.saveCookies(jar))
508
+ .then(function(/** @type {{ headers: any; }} */res) {
509
+ var headers = res.headers;
510
+ if (!headers.location) throw { error: Language.InvaildAccount };
511
+
512
+ // This means the account has login approvals turned on.
513
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
514
+ logger.Warning(Language.TwoAuth);
515
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
516
+
517
+ return utils
518
+ .get(headers.location, jar, null, loginOptions)
519
+ .then(utils.saveCookies(jar))
520
+ .then(async function(/** @type {{ body: any; }} */res) {
521
+ if (!await Database.get('ThroughAcc')) {
522
+ await Database.set('ThroughAcc', email);
523
+ }
524
+ else {
525
+ if (String((await Database.get('ThroughAcc'))).replace(RegExp('"','g'), '') != String(email).replace(RegExp('"','g'), '')) {
526
+ await Database.set('ThroughAcc', email);
527
+ if (await Database.get('Through2Fa')) {
528
+ await Database.delete('Through2Fa');
529
+ }
530
+ }
531
+ }
532
+ var html = res.body,$ = cheerio.load(html), arr = [];
533
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
534
+ arr = arr.filter(v => { return v.val && v.val.length });
535
+ var form = utils.arrToForm(arr);
536
+ if (html.indexOf("checkpoint/?next") > -1) {
537
+ setTimeout(() => {
538
+ checkVerified = setInterval((_form) => {}, 5000, {
539
+ fb_dtsg: form.fb_dtsg,
540
+ jazoest: form.jazoest,
541
+ dpr: 1
542
+ });
543
+ }, 2500);
544
+ switch (global.Fca.Require.FastConfig.Login2Fa) {
545
+ case true: {
546
+ try {
547
+ const question = question => {
548
+ const rl = readline.createInterface({
549
+ input: process.stdin,
550
+ output: process.stdout
551
+ });
552
+ return new Promise(resolve => {
553
+ rl.question(question, answer => {
554
+ rl.close();
555
+ return resolve(answer);
556
+ });
557
+ });
558
+ };
559
+ async function EnterSecurityCode() {
560
+ try {
561
+ var Through2Fa = await Database.get('Through2Fa');
562
+ if (Through2Fa) {
563
+ Through2Fa.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
564
+ let str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
565
+ jar.setCookie(str, "http://" + c.domain);
566
+ })
567
+ var from2 = utils.arrToForm(arr);
568
+ from2.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
569
+ from2.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
570
+ from2.email = email;
571
+ from2.pass = password;
572
+ from2.default_persistent = '0';
573
+ from2.locale = 'en_US';
574
+ from2.timezone = '240';
575
+ from2.lgnjs = ~~(Date.now() / 1000);
576
+ return utils
577
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, from2, loginOptions)
578
+ .then(utils.saveCookies(jar))
579
+ .then(function(/** @type {{ headers: any; }} */res) {
580
+ var headers = res.headers;
581
+ if (!headers['set-cookie'][0].includes('deleted')) {
582
+ logger.Warning(Language.ErrThroughCookies, async function() {
583
+ await Database.delete('Through2Fa');
584
+ });
585
+ process.exit(1);
586
+ }
587
+ if (headers.location && headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
588
+ return utils
589
+ .get(headers.location, jar, null, loginOptions)
590
+ .then(utils.saveCookies(jar))
591
+ .then(function(/** @type {{ body: any; }} */res) {
592
+ var html = res.body,$ = cheerio.load(html), arr = [];
593
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
594
+ arr = arr.filter(v => { return v.val && v.val.length });
595
+ var from2 = utils.arrToForm(arr);
596
+
597
+ if (html.indexOf("checkpoint/?next") > -1) {
598
+ setTimeout(() => {
599
+ checkVerified = setInterval((_form) => {}, 5000, {
600
+ fb_dtsg: from2.fb_dtsg,
601
+ jazoest: from2.jazoest,
602
+ dpr: 1
603
+ });
604
+ }, 2500);
605
+ if (!res.headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
606
+ try {
607
+ delete from2.name_action_selected;
608
+ from2['submit[Continue]'] = $("#checkpointSubmitButton").html();
609
+ return utils
610
+ .post(nextURL, jar, from2, loginOptions)
611
+ .then(utils.saveCookies(jar))
612
+ .then(function() {
613
+ from2['submit[This was me]'] = "This was me";
614
+ return utils.post(nextURL, jar, from2, loginOptions).then(utils.saveCookies(jar));
615
+ })
616
+ .then(function() {
617
+ delete from2['submit[This was me]'];
618
+ from2.name_action_selected = 'save_device';
619
+ from2['submit[Continue]'] = $("#checkpointSubmitButton").html();
620
+ return utils.post(nextURL, jar, from2, loginOptions).then(utils.saveCookies(jar));
621
+ })
622
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
623
+ var headers = res.headers;
624
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
625
+ var appState = utils.getAppState(jar,false);
626
+ await Database.set('Through2Fa', appState);
627
+ return loginHelper(appState, email, password, loginOptions, callback);
628
+ })
629
+ .catch((/** @type {any} */e) => callback(e));
630
+ }
631
+ catch (e) {
632
+ console.log(e)
633
+ }
634
+ }
635
+ }
636
+ })
637
+ }
638
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
639
+ }).catch((/** @type {any} */e) => console.log(e));
640
+ }
641
+ }
642
+ catch (e) {
643
+ await Database.delete('Through2Fa');
644
+ }
645
+ var code = await question(Language.EnterSecurityCode);
646
+ try {
647
+ form.approvals_code = code;
648
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
649
+ var prResolve,prReject;
650
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
651
+ if (typeof code == "string") { //always strings
652
+ utils
653
+ .post(nextURL, jar, form, loginOptions)
654
+ .then(utils.saveCookies(jar))
655
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
656
+ var $ = cheerio.load(res.body);
657
+ var error = $("#approvals_code").parent().attr("data-xui-error");
658
+ if (error) {
659
+ logger.Warning(Language.InvaildTwoAuthCode,function() { EnterSecurityCode(); }); //bruh loop
660
+ };
661
+ })
662
+ .then(function() {
663
+ delete form.no_fido;delete form.approvals_code;
664
+ form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
665
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
666
+ })
667
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
668
+ var headers = res.headers;
669
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
670
+ try {
671
+ delete form.name_action_selected;
672
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
673
+ return utils
674
+ .post(nextURL, jar, form, loginOptions)
675
+ .then(utils.saveCookies(jar))
676
+ .then(function() {
677
+ form['submit[This was me]'] = "This was me";
678
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
679
+ })
680
+ .then(function() {
681
+ delete form['submit[This was me]'];
682
+ form.name_action_selected = 'save_device';
683
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
684
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
685
+ })
686
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
687
+ var headers = res.headers;
688
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
689
+ var appState = utils.getAppState(jar,false);
690
+ await Database.set('Through2Fa', appState);
691
+ return loginHelper(appState, email, password, loginOptions, callback);
692
+ })
693
+ .catch((/** @type {any} */e) => callback(e));
694
+ }
695
+ catch (e) {
696
+ console.log(e)
697
+ }
698
+ }
699
+ var appState = utils.getAppState(jar,false);
700
+ if (callback === prCallback) {
701
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
702
+ if (err) return prReject(err);
703
+ return prResolve(api);
704
+ };
705
+ }
706
+ await Database.set('Through2Fa', appState);
707
+ return loginHelper(appState, email, password, loginOptions, callback);
708
+ })
709
+ .catch(function(/** @type {any} */err) {
710
+ if (callback === prCallback) prReject(err);
711
+ else callback(err);
712
+ });
713
+ } else {
714
+ utils
715
+ .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" })
716
+ .then(utils.saveCookies(jar))
717
+ .then(async function(/** @type {{ body: string; }} */res) {
718
+ try {
719
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
720
+ } catch (ex) {
721
+ clearInterval(checkVerified);
722
+ logger.Warning(Language.VerifiedCheck);
723
+ if (callback === prCallback) {
724
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
725
+ if (err) return prReject(err);
726
+ return prResolve(api);
727
+ };
728
+ }
729
+ let appState = utils.getAppState(jar,false);
730
+ return loginHelper(appState, email, password, loginOptions, callback);
731
+ }
732
+ })
733
+ .catch((/** @type {any} */ex) => {
734
+ log.error("login", ex);
735
+ if (callback === prCallback) prReject(ex);
736
+ else callback(ex);
737
+ });
738
+ }
739
+ return rtPromise;
740
+ }
741
+ catch (e) {
742
+ logger.Error(e)
743
+ logger.Error()
744
+ process.exit(0)
745
+ }
746
+ }
747
+ await EnterSecurityCode()
748
+ }
749
+ catch (e) {
750
+ logger.Error(e)
751
+ logger.Error();
752
+ process.exit(0);
753
+ }
754
+ }
755
+ break;
756
+ case false: {
757
+ throw {
758
+ error: 'login-approval',
759
+ continue: function submit2FA(/** @type {any} */code) {
760
+ form.approvals_code = code;
761
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
762
+ var prResolve,prReject;
763
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
764
+ if (typeof code == "string") {
765
+ utils
766
+ .post(nextURL, jar, form, loginOptions)
767
+ .then(utils.saveCookies(jar))
768
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
769
+ var $ = cheerio.load(res.body);
770
+ var error = $("#approvals_code").parent().attr("data-xui-error");
771
+ if (error) {
772
+ throw {
773
+ error: 'login-approval',
774
+ errordesc: Language.InvaildTwoAuthCode,
775
+ lerror: error,
776
+ continue: submit2FA
777
+ };
778
+ }
779
+ })
780
+ .then(function() {
781
+ delete form.no_fido;delete form.approvals_code;
782
+ form.name_action_selected = 'dont_save'; //'save_device' || 'dont_save;
783
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
784
+ })
785
+ .then(function(/** @type {{ headers: any; body: string | string[]; }} */res) {
786
+ var headers = res.headers;
787
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: Language.ApprovalsErr };
788
+ var appState = utils.getAppState(jar,false);
789
+ if (callback === prCallback) {
790
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
791
+ if (err) return prReject(err);
792
+ return prResolve(api);
793
+ };
794
+ }
795
+ return loginHelper(appState, email, password, loginOptions, callback);
796
+ })
797
+ .catch(function(/** @type {any} */err) {
798
+ if (callback === prCallback) prReject(err);
799
+ else callback(err);
800
+ });
801
+ } else {
802
+ utils
803
+ .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" })
804
+ .then(utils.saveCookies(jar))
805
+ .then((/** @type {{ body: string; }} */res) => {
806
+ try {
807
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
808
+ } catch (ex) {
809
+ clearInterval(checkVerified);
810
+ logger.Warning(Language.VerifiedCheck);
811
+ if (callback === prCallback) {
812
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
813
+ if (err) return prReject(err);
814
+ return prResolve(api);
815
+ };
816
+ }
817
+ return loginHelper(utils.getAppState(jar,false), email, password, loginOptions, callback);
818
+ }
819
+ })
820
+ .catch((/** @type {any} */ex) => {
821
+ log.error("login", ex);
822
+ if (callback === prCallback) prReject(ex);
823
+ else callback(ex);
824
+ });
825
+ }
826
+ return rtPromise;
827
+ }
828
+ };
829
+ }
830
+ }
831
+ } else {
832
+ if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
833
+
834
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
835
+ else form['submit[This Is Okay]'] = "This Is Okay";
836
+
837
+ return utils
838
+ .post(nextURL, jar, form, loginOptions)
839
+ .then(utils.saveCookies(jar))
840
+ .then(function() {
841
+ form.name_action_selected = 'dont_save';
842
+
843
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
844
+ })
845
+ .then(function(/** @type {{ headers: any; body: string | string[]; }} */res) {
846
+ var headers = res.headers;
847
+
848
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
849
+
850
+ var appState = utils.getAppState(jar,false);
851
+
852
+ return loginHelper(appState, email, password, loginOptions, callback);
853
+ })
854
+ .catch((/** @type {any} */e) => callback(e));
855
+ }
856
+ });
857
+ }
858
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
859
+ });
860
+ };
861
+ }
862
+
863
+ /!-[ Function backup ]-!/
864
+
865
+ /**
866
+ * @param {string} data
867
+ * @param {any} globalOptions
868
+ * @param {any} callback
869
+ * @param {any} prCallback
870
+ */
871
+
872
+ function backup(data,globalOptions, callback, prCallback) {
873
+ try {
874
+ var appstate;
875
+ try {
876
+ appstate = JSON.parse(data)
877
+ }
878
+ catch(e) {
879
+ appstate = data;
880
+ }
881
+ logger.Warning(Language.BackupNoti);
882
+ try {
883
+ loginHelper(appstate,null,null,globalOptions, callback, prCallback)
884
+ }
885
+ catch (e) {
886
+ logger.Error(Language.ErrBackup);
887
+ process.exit(0);
888
+ }
889
+ }
890
+ catch (e) {
891
+ return logger.Error();
892
+ }
893
+ }
894
+
895
+ /!-[ async function loginHelper ]-!/
896
+
897
+ /**
898
+ * @param {string | any[]} appState
899
+ * @param {any} email
900
+ * @param {any} password
901
+ * @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
902
+ * @param {(arg0: any, arg1: undefined) => void} callback
903
+ * @param {(error: any, api: any) => any} [prCallback]
904
+ */
905
+
906
+ async function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
907
+ var mainPromise = null;
908
+ var jar = utils.getJar();
909
+
910
+ if (fs.existsSync('./backupappstate.json')) {
911
+ fs.unlinkSync('./backupappstate.json');
912
+ }
913
+
914
+ try {
915
+ if (appState) {
916
+ logger.Normal(Language.OnProcess);
917
+ switch (await Database.has("FBKEY")) {
918
+ case true: {
919
+ process.env.FBKEY = await Database.get("FBKEY");
920
+ }
921
+ break;
922
+ case false: {
923
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
924
+ process.env['FBKEY'] = SecurityKey;
925
+ await Database.set('FBKEY', SecurityKey);
926
+ }
927
+ break;
928
+ default: {
929
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
930
+ process.env['FBKEY'] = SecurityKey;
931
+ await Database.set('FBKEY', SecurityKey);
932
+ }
933
+ }
934
+ try {
935
+ switch (global.Fca.Require.FastConfig.EncryptFeature) {
936
+ case true: {
937
+ appState = JSON.parse(JSON.stringify(appState, null, "\t"));
938
+ switch (utils.getType(appState)) {
939
+ case "Array": {
940
+ switch (utils.getType(appState[0])) {
941
+ case "Object": {
942
+ logger.Normal(Language.NotReadyToDecrypt);
943
+ }
944
+ break;
945
+ case "String": {
946
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
947
+ logger.Normal(Language.DecryptSuccess);
948
+ }
949
+ }
950
+ }
951
+ break;
952
+ case "Object": {
953
+ try {
954
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
955
+ logger.Normal(Language.DecryptSuccess);
956
+ }
957
+ catch (e) {
958
+ if (process.env.Backup != undefined && process.env.Backup) {
959
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
960
+ }
961
+ else {
962
+ try {
963
+ if (await Database.has('Backup')) {
964
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
965
+ }
966
+ else {
967
+ logger.Normal(Language.ErrBackup);
968
+ process.exit(0);
969
+ }
970
+ }
971
+ catch (e) {
972
+ logger.Warning(Language.ErrBackup);
973
+ logger.Error();
974
+ process.exit(0);
975
+ }
976
+ }
977
+ logger.Warning(Language.DecryptFailed);
978
+ return logger.Error();
979
+ }
980
+ }
981
+ break;
982
+ case "String": {
983
+ try {
984
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
985
+ logger.Normal(Language.DecryptSuccess);
986
+ }
987
+ catch (e) {
988
+ if (process.env.Backup != undefined && process.env.Backup) {
989
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
990
+ }
991
+ else {
992
+ try {
993
+ if (await Database.has('Backup')) {
994
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
995
+ }
996
+ else {
997
+ logger.Normal(Language.ErrBackup);
998
+ process.exit(0);
999
+ }
1000
+ }
1001
+ catch (e) {
1002
+ logger.Warning(Language.ErrBackup);
1003
+ logger.Error();
1004
+ process.exit(0);
1005
+ }
1006
+ }
1007
+ logger.Warning(Language.DecryptFailed);
1008
+ return logger.Error();
1009
+ }
1010
+ }
1011
+ break;
1012
+ default: {
1013
+ logger.Warning(Language.InvaildAppState);
1014
+ process.exit(0)
1015
+ }
1016
+ }
1017
+ }
1018
+ break;
1019
+ case false: {
1020
+ switch (utils.getType(appState)) {
1021
+ case "Array": {
1022
+ logger.Normal(Language.EncryptStateOff);
1023
+ }
1024
+ break;
1025
+ case "Object": {
1026
+ logger.Normal(Language.EncryptStateOff);
1027
+ try {
1028
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
1029
+ logger.Normal(Language.DecryptSuccess);
1030
+ }
1031
+ catch (e) {
1032
+ if (process.env.Backup != undefined && process.env.Backup) {
1033
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
1034
+ }
1035
+ else {
1036
+ try {
1037
+ if (await Database.has('Backup')) {
1038
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
1039
+ }
1040
+ else {
1041
+ logger.Warning(Language.ErrBackup);
1042
+ process.exit(0);
1043
+ }
1044
+ }
1045
+ catch (e) {
1046
+ logger.Warning(Language.ErrBackup);
1047
+ logger.Error();
1048
+ process.exit(0);
1049
+ }
1050
+ }
1051
+ logger.Warning(Language.DecryptFailed);
1052
+ return logger.Error();
1053
+ }
1054
+ }
1055
+ break;
1056
+ default: {
1057
+ logger.Warning(Language.InvaildAppState);
1058
+ process.exit(0)
1059
+ }
1060
+ }
1061
+ }
1062
+ break;
1063
+ default: {
1064
+ logger.Warning(getText(Language.IsNotABoolean,global.Fca.Require.FastConfig.EncryptFeature))
1065
+ process.exit(0);
1066
+ }
1067
+ }
1068
+ }
1069
+ catch (e) {
1070
+ console.log(e);
1071
+ }
1072
+
1073
+ try {
1074
+ appState = JSON.parse(appState);
1075
+ }
1076
+ catch (e) {
1077
+ try {
1078
+ appState = appState;
1079
+ }
1080
+ catch (e) {
1081
+ return logger.Error();
1082
+ }
1083
+ }
1084
+ try {
1085
+ global.Fca.Data.AppState = appState;
1086
+ appState.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
1087
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
1088
+ jar.setCookie(str, "http://" + c.domain);
1089
+ });
1090
+ process.env.Backup = appState;
1091
+ await Database.set('Backup', appState);
1092
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
1093
+ } catch (e) {
1094
+ console.log(e)
1095
+ if (process.env.Backup != undefined && process.env.Backup) {
1096
+ return await backup(process.env.Backup,globalOptions, callback, prCallback);
1097
+ }
1098
+ try {
1099
+ if (await Database.has('Backup')) {
1100
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
1101
+ }
1102
+ else {
1103
+ logger.Warning(Language.ErrBackup);
1104
+ process.exit(0);
1105
+ }
1106
+ }
1107
+ catch (e) {
1108
+ logger.Warning(Language.ErrBackup);
1109
+ process.exit(0);
1110
+ }
1111
+ return logger.Warning(Language.ErrBackup); // unreachable 👑
1112
+ }
1113
+ } else {
1114
+ mainPromise = utils
1115
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
1116
+ .then(utils.saveCookies(jar))
1117
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
1118
+ .then(function() {
1119
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
1120
+ });
1121
+ }
1122
+ } catch (e) {
1123
+ console.log(e);
1124
+ }
1125
+ var ctx,api;
1126
+ mainPromise = mainPromise
1127
+ .then(function(/** @type {{ body: string; }} */res) {
1128
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/,redirect = reg.exec(res.body);
1129
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1130
+ return res;
1131
+ })
1132
+ .then(function(/** @type {{ body: any; }} */res) {
1133
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar);
1134
+ ctx = Obj.ctx;
1135
+ api = Obj.api;
1136
+ process.env.api = Obj.api;
1137
+ return res;
1138
+ });
1139
+ if (globalOptions.pageID) {
1140
+ mainPromise = mainPromise
1141
+ .then(function() {
1142
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
1143
+ })
1144
+ .then(function(/** @type {{ body: any; }} */resData) {
1145
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
1146
+ url = url.substring(0, url.length - 1);
1147
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
1148
+ });
1149
+ }
1150
+ mainPromise
1151
+ .then(function() {
1152
+ const { execSync } = require('child_process');
1153
+ Fetch('https://raw.githubusercontent.com/KanzuXHorizon/Fca-Horizon-Remastered/main/package.json').then(async (/** @type {{ body: { toString: () => string; }; }} */res) => {
1154
+ const localVersion = global.Fca.Version;
1155
+ if (Number(localVersion.replace(/\./g,"")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g,"")) ) {
1156
+ log.warn("[ FCA-HZI ] •",getText(Language.NewVersionFound,global.Fca.Version,JSON.parse(res.body.toString()).version));
1157
+ if (global.Fca.Require.FastConfig.AutoUpdate == true) {
1158
+ log.warn("[ FCA-HZI ] •",Language.AutoUpdate);
1159
+ try {
1160
+ execSync('npm install fca-horizon-remastered@latest', { stdio: 'inherit' });
1161
+ logger.Success(Language.UpdateSuccess)
1162
+ logger.Normal(Language.RestartAfterUpdate);
1163
+ await new Promise(resolve => setTimeout(resolve,5*1000));
1164
+ console.clear();process.exit(1);
1165
+ }
1166
+ catch (err) {
1167
+ log.warn('Error Update: ' + err);
1168
+ logger.Normal(Language.UpdateFailed);
1169
+ try {
1170
+ const fs = require('fs-extra')
1171
+ try {
1172
+ logger.Error('Cập Nhật Đã Lỗi Tiến Hành Xóa Package');
1173
+ execSync('npm cache clean --force', { stdio: 'ignore'})
1174
+ await new Promise(resolve => setTimeout(resolve, 2*1000))
1175
+ fs.removeSync('../fca-horizon-remastered');
1176
+ // why stdio is not studio :v
1177
+ await new Promise(resolve => setTimeout(resolve, 2*1000))
1178
+ execSync('npm i fca-horizon-remastered@latest', { stdio: 'inherit'})
1179
+ logger.Success("Đã Thành Công - Tiến Hành Restart");
1180
+ process.exit(1);
1181
+ }
1182
+ catch (e) {
1183
+ logger.Warning("Đã Bị Lỗi Hãy Nhập Vào Console Mã Sau Đây Để Fix !");
1184
+ logger.Warning("rmdir -rf ./node_modules/fca-horizon-remastered && npm i fca-horizon-remastered@latest && npm start");
1185
+ logger.Warning("Hãy Copy Hết Những Chữ Trên, Cần Làm Đúng 100% Nếu Ko File Bạn Sẽ Bay Màu ✨")
1186
+ process.exit(0);
1187
+ }
1188
+ }
1189
+ catch (e) {
1190
+ logger.Error(Language.NotiAfterUseToolFail)
1191
+ logger.Warning("rmdir ./node_modules after type npm i && npm start");
1192
+ process.exit(0);
1193
+ }
1194
+ }
1195
+ }
1196
+ }
1197
+ else {
1198
+ logger.Normal(getText(Language.LocalVersion,localVersion));
1199
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1200
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1201
+ require('./Extra/ExtraUptimeRobot')();
1202
+ DataLanguageSetting.HTML.HTML==true? global.Fca.Require.Web.listen(global.Fca.Require.Web.get('DFP')) : global.Fca.Require.Web = null;
1203
+ callback(null, api);
1204
+ };
1205
+ }).catch(async function(e) {
1206
+ console.log(e)
1207
+ logger.Warning(Language.AutoCheckUpdateFailure)
1208
+ logger.Normal(getText(Language.LocalVersion,global.Fca.Version));
1209
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1210
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1211
+ require('./Extra/ExtraUptimeRobot')();
1212
+ DataLanguageSetting.HTML.HTML==true? global.Fca.Require.Web.listen(global.Fca.Require.Web.get('DFP')) : global.Fca.Require.Web = null;
1213
+ callback(null, api);
1214
+ });
1215
+ }).catch(function(/** @type {{ error: any; }} */e) {
1216
+ log.error("login", e.error || e);
1217
+ callback(e);
1218
+ });
1219
+ }
1220
+
1221
+ /**
1222
+ * It asks the user for their account and password, and then saves it to the database.
1223
+ */
1224
+
1225
+ function setUserNameAndPassWord() {
1226
+ let rl = readline.createInterface({
1227
+ input: process.stdin,
1228
+ output: process.stdout
1229
+ });
1230
+ let localbrand2 = global.Fca.Version
1231
+ console.clear();
1232
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1233
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1234
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1235
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(localbrand2) + '\n');
1236
+ try {
1237
+ rl.question(Language.TypeAccount, (Account) => {
1238
+ if (!Account.includes("@") && global.Fca.Require.utils.getType(parseInt(Account)) != "Number") return logger.Normal(Language.TypeAccountError, function () { process.exit(1) }); //Very Human
1239
+ else rl.question(Language.TypePassword,async function (Password) {
1240
+ rl.close();
1241
+ try {
1242
+ await Database.set("Account", Account);
1243
+ await Database.set("Password", Password);
1244
+ }
1245
+ catch (e) {
1246
+ logger.Warning(Language.ErrDataBase);
1247
+ logger.Error();
1248
+ process.exit(0);
1249
+ }
1250
+ if (global.Fca.Require.FastConfig.ResetDataLogin) {
1251
+ global.Fca.Require.FastConfig.ResetDataLogin = false;
1252
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/FastConfigFca.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1253
+ }
1254
+ logger.Success(Language.SuccessSetData);
1255
+ process.exit(1);
1256
+ });
1257
+ })
1258
+ }
1259
+ catch (e) {
1260
+ logger.Error(e)
1261
+ }
1262
+ }
1263
+
1264
+ /**
1265
+ * @param {{ email: any; password: any; appState: any; }} loginData
1266
+ * @param {{}} options
1267
+ * @param {(error: any, api: any) => any} callback
1268
+ */
1269
+
1270
+ function login(loginData, options, callback) {
1271
+
1272
+ if (utils.getType(loginData) == "Array") {
1273
+ if (loginData.length == 3) {
1274
+ options = loginData[1];
1275
+ callback = loginData[2];
1276
+ loginData = loginData[0]
1277
+ }
1278
+ else if (loginData.length == 2) {
1279
+ options = loginData[1];
1280
+ loginData = loginData[0]
1281
+ }
1282
+ else {
1283
+ loginData = loginData[0]
1284
+ }
1285
+ }
1286
+
1287
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1288
+ callback = options;
1289
+ options = {};
1290
+ }
1291
+
1292
+ var globalOptions = {
1293
+ selfListen: false,
1294
+ listenEvents: true,
1295
+ listenTyping: false,
1296
+ updatePresence: false,
1297
+ forceLogin: false,
1298
+ autoMarkDelivery: false,
1299
+ autoMarkRead: false,
1300
+ autoReconnect: true,
1301
+ logRecordSize: 100,
1302
+ online: false,
1303
+ emitReady: false,
1304
+ 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"
1305
+ };
1306
+
1307
+ if (loginData.email && loginData.password) {
1308
+ setOptions(globalOptions, {
1309
+ logLevel: "silent",
1310
+ forceLogin: true,
1311
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"
1312
+ });
1313
+ }
1314
+ else if (loginData.appState) {
1315
+ setOptions(globalOptions, options);
1316
+ }
1317
+
1318
+ var prCallback = null;
1319
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1320
+ var rejectFunc = null;
1321
+ var resolveFunc = null;
1322
+ var returnPromise = new Promise(function(resolve, reject) {
1323
+ resolveFunc = resolve;
1324
+ rejectFunc = reject;
1325
+ });
1326
+ prCallback = function(/** @type {any} */error, /** @type {any} */api) {
1327
+ if (error) return rejectFunc(error);
1328
+ return resolveFunc(api);
1329
+ };
1330
+ callback = prCallback;
1331
+ }
1332
+
1333
+ (async function() {
1334
+ var Premium = require("./Extra/Src/Premium");
1335
+ global.Fca.Data.PremText = await Premium(global.Fca.Require.Security.create().uuid) || "Bạn Đang Sài Phiên Bản: Free !";
1336
+ if (!loginData.email && !loginData.password) {
1337
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
1338
+ case true: {
1339
+ if (global.Fca.Require.FastConfig.ResetDataLogin) return setUserNameAndPassWord();
1340
+ else {
1341
+ try {
1342
+ if (await Database.get("TempState")) {
1343
+ try {
1344
+ loginData.appState = JSON.parse(await Database.get("TempState"));
1345
+ }
1346
+ catch (_) {
1347
+ loginData.appState = await Database.get("TempState");
1348
+ }
1349
+ await Database.delete("TempState");
1350
+ }
1351
+ }
1352
+ catch (e) {
1353
+ console.log(e)
1354
+ await Database.delete("TempState");
1355
+ logger.Warning(Language.ErrDataBase);
1356
+ logger.Error();
1357
+ process.exit(0);
1358
+ }
1359
+ try {
1360
+ if (await Database.has('Account') && await Database.has('Password')) return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1361
+ else return setUserNameAndPassWord();
1362
+ }
1363
+ catch (e) {
1364
+ console.log(e)
1365
+ logger.Warning(Language.ErrDataBase);
1366
+ logger.Error();
1367
+ process.exit(0);
1368
+ }
1369
+ }
1370
+ }
1371
+ case false: {
1372
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1373
+ }
1374
+ }
1375
+ }
1376
+ else loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1377
+ })()
1378
+ return returnPromise;
1379
+ }
1380
+
1381
+ module.exports = login;