fb-deku-remake 0.0.1-security → 7.6.22

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

Potentially problematic release.


This version of fb-deku-remake might be problematic. Click here for more details.

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