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