fca-dongdev-remake 0.0.1-security → 1.7.8

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

Potentially problematic release.


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

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