fca-zeid 0.0.1-security → 1.6.0

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

Potentially problematic release.


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

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