fca-duong 0.0.1-security → 7.2.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-duong might be problematic. Click here for more details.
- package/.cache/replit/nix/env.json +1 -0
- package/.replit +2 -0
- package/.upm/store.json +1 -0
- package/DOCS.md +1738 -0
- package/README.md +77 -3
- package/StateCrypt.js +22 -0
- package/broadcast.js +18 -0
- package/index.js +687 -0
- package/languages/languages.json +122 -0
- package/lib/getInfoNew.js +34 -0
- package/lib/getToken.js +44 -0
- package/logger.js +15 -0
- package/package.json +71 -3
- package/replit.nix +9 -0
- package/src/ReportV1.js +55 -0
- package/src/addExternalModule.js +16 -0
- package/src/addUserToGroup.js +78 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeAvt.js +86 -0
- package/src/changeBio.js +65 -0
- package/src/changeBlockedStatus.js +36 -0
- package/src/changeGroupImage.js +106 -0
- package/src/changeName.js +3 -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 +33 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getMessage.js +79 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +206 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUserID.js +62 -0
- package/src/getUserInfo.js +66 -0
- package/src/getUserInfoV2.js +35 -0
- package/src/getUserInfoV3.js +64 -0
- package/src/getUserInfoV4.js +56 -0
- package/src/getUserInfoV5.js +62 -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 +629 -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 +337 -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/utils.js +1246 -0
package/index.js
ADDED
@@ -0,0 +1,687 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require("./utils");
|
4
|
+
var cheerio = require("cheerio");
|
5
|
+
var log = require("npmlog");
|
6
|
+
var logger = require('./logger');
|
7
|
+
var fs = require("fs-extra");
|
8
|
+
var axios = require('axios')
|
9
|
+
if (!fs.existsSync("./FcaConfig.json")) {
|
10
|
+
log.warn("warn", "Không Tìm Thấy Tệp FcaConfig Tiến Hành Tạo Mới")
|
11
|
+
global.fca = new Object ({
|
12
|
+
data: new Object ({
|
13
|
+
languages: "vi",
|
14
|
+
mainName: "[ FCA-DUONG ]",
|
15
|
+
mainColor: "#00FFFF",
|
16
|
+
autoRestartMinutes: 0,
|
17
|
+
encryptSt: false,
|
18
|
+
uptime: true
|
19
|
+
})
|
20
|
+
})
|
21
|
+
fs.writeFileSync("./FcaConfig.json", JSON.stringify(global.fca.data, null, "\t"))
|
22
|
+
return process.exit(1)
|
23
|
+
}
|
24
|
+
try {
|
25
|
+
var langfile = JSON.parse(fs.readFileSync(__dirname + "/languages/languages.json", 'utf-8'));
|
26
|
+
var lang
|
27
|
+
switch (require("../../FcaConfig.json").languages) {
|
28
|
+
case "vi": lang = langfile.vi.index;
|
29
|
+
break;
|
30
|
+
case "en": lang = langfile.en.index;
|
31
|
+
break;
|
32
|
+
case "th": lang = langfile.th.index;
|
33
|
+
break;
|
34
|
+
case "jp": lang = langfile.jp.index;
|
35
|
+
break;
|
36
|
+
default: {
|
37
|
+
log.warn("warn", "Hiện Chỉ Hỗ Trợ 4 Loại Ngôn Ngữ VI, EN, TH & JP, Tự Fix Bằng Cách Tìm Và Xoá Tệp FcaConfig.json")
|
38
|
+
process.exit(0)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
} catch(e) {
|
42
|
+
console.log(e)
|
43
|
+
log.warn("warn", "Không tìm thấy ngôn ngữ phù hợp")
|
44
|
+
process.exit(0)
|
45
|
+
}
|
46
|
+
global.fca = new Object({
|
47
|
+
ObjFcaConfig: require("../../FcaConfig.json"),
|
48
|
+
languages: lang
|
49
|
+
})
|
50
|
+
if (global.fca.ObjFcaConfig['autoRestartMinutes'] != 0) {
|
51
|
+
setInterval(() => {
|
52
|
+
return process.exit(1)
|
53
|
+
}, global.fca.ObjFcaConfig['autoRestartMinutes'] * 1000)
|
54
|
+
}
|
55
|
+
if (global.fca.ObjFcaConfig['uptime']) {
|
56
|
+
var UrlRepl = `https://${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`;
|
57
|
+
try {
|
58
|
+
axios.get(`https://api-1.miraiofficials123.repl.co/upt?add=${UrlRepl}`)
|
59
|
+
logger(global.fca.languages.uptime + UrlRepl, '[ FCA-DUONG ]');
|
60
|
+
}
|
61
|
+
catch {
|
62
|
+
logger(global.fca.languages.erroUptime, '[ FCA-DUONG ]');
|
63
|
+
}
|
64
|
+
}
|
65
|
+
var checkVerified = null;
|
66
|
+
|
67
|
+
var defaultLogRecordSize = 100;
|
68
|
+
log.maxRecordSize = defaultLogRecordSize;
|
69
|
+
function setOptions(globalOptions, options) {
|
70
|
+
Object.keys(options).map(function(key) {
|
71
|
+
switch (key) {
|
72
|
+
case 'pauseLog':
|
73
|
+
if (options.pauseLog) log.pause();
|
74
|
+
break;
|
75
|
+
case 'online':
|
76
|
+
globalOptions.online = Boolean(options.online);
|
77
|
+
break;
|
78
|
+
case 'logLevel':
|
79
|
+
log.level = options.logLevel;
|
80
|
+
globalOptions.logLevel = options.logLevel;
|
81
|
+
break;
|
82
|
+
case 'logRecordSize':
|
83
|
+
log.maxRecordSize = options.logRecordSize;
|
84
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
85
|
+
break;
|
86
|
+
case 'selfListen':
|
87
|
+
globalOptions.selfListen = Boolean(options.selfListen);
|
88
|
+
break;
|
89
|
+
case 'listenEvents':
|
90
|
+
globalOptions.listenEvents = Boolean(options.listenEvents);
|
91
|
+
break;
|
92
|
+
case 'pageID':
|
93
|
+
globalOptions.pageID = options.pageID.toString();
|
94
|
+
break;
|
95
|
+
case 'updatePresence':
|
96
|
+
globalOptions.updatePresence = Boolean(options.updatePresence);
|
97
|
+
break;
|
98
|
+
case 'forceLogin':
|
99
|
+
globalOptions.forceLogin = Boolean(options.forceLogin);
|
100
|
+
break;
|
101
|
+
case 'userAgent':
|
102
|
+
globalOptions.userAgent = options.userAgent;
|
103
|
+
break;
|
104
|
+
case 'autoMarkDelivery':
|
105
|
+
globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
|
106
|
+
break;
|
107
|
+
case 'autoMarkRead':
|
108
|
+
globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
|
109
|
+
break;
|
110
|
+
case 'listenTyping':
|
111
|
+
globalOptions.listenTyping = Boolean(options.listenTyping);
|
112
|
+
break;
|
113
|
+
case 'proxy':
|
114
|
+
if (typeof options.proxy != "string") {
|
115
|
+
delete globalOptions.proxy;
|
116
|
+
utils.setProxy();
|
117
|
+
} else {
|
118
|
+
globalOptions.proxy = options.proxy;
|
119
|
+
utils.setProxy(globalOptions.proxy);
|
120
|
+
}
|
121
|
+
break;
|
122
|
+
case 'autoReconnect':
|
123
|
+
globalOptions.autoReconnect = Boolean(options.autoReconnect);
|
124
|
+
break;
|
125
|
+
case 'emitReady':
|
126
|
+
globalOptions.emitReady = Boolean(options.emitReady);
|
127
|
+
break;
|
128
|
+
default:
|
129
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
130
|
+
break;
|
131
|
+
}
|
132
|
+
});
|
133
|
+
}
|
134
|
+
function buildAPI(globalOptions, html, jar) {
|
135
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
|
136
|
+
return val.cookieString().split("=")[0] === "c_user";
|
137
|
+
});
|
138
|
+
|
139
|
+
if (maybeCookie.length === 0) throw { error: global.fca.languages.errorLogin };
|
140
|
+
|
141
|
+
if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", global.fca.languages.checkpoint);
|
142
|
+
|
143
|
+
var userID = maybeCookie[0].cookieString().split("=")[1].toString();
|
144
|
+
logger(`${global.fca.languages.loginSu}${userID}`, "[ FCA-DUONG ]");
|
145
|
+
|
146
|
+
try {
|
147
|
+
clearInterval(checkVerified);
|
148
|
+
} catch (e) {
|
149
|
+
console.log(e);
|
150
|
+
}
|
151
|
+
|
152
|
+
var clientID = (Math.random() * 2147483648 | 0).toString(16);
|
153
|
+
|
154
|
+
let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
|
155
|
+
let mqttEndpoint = null;
|
156
|
+
let region = null;
|
157
|
+
let irisSeqID = null;
|
158
|
+
var noMqttData = null;
|
159
|
+
|
160
|
+
if (oldFBMQTTMatch) {
|
161
|
+
irisSeqID = oldFBMQTTMatch[1];
|
162
|
+
mqttEndpoint = oldFBMQTTMatch[2];
|
163
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
164
|
+
logger(`${global.fca.languages.region}${region}`, "[ FCA-DUONG ]");
|
165
|
+
} else {
|
166
|
+
let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
|
167
|
+
if (newFBMQTTMatch) {
|
168
|
+
irisSeqID = newFBMQTTMatch[2];
|
169
|
+
mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
|
170
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
171
|
+
logger(`${global.fca.languages.region}${region}`, "[ FCA-DUONG ]");
|
172
|
+
} else {
|
173
|
+
let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
|
174
|
+
if (legacyFBMQTTMatch) {
|
175
|
+
mqttEndpoint = legacyFBMQTTMatch[4];
|
176
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
177
|
+
log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
|
178
|
+
logger(`${global.fca.languages.region}${region}`, "[ FCA-DUONG ]");
|
179
|
+
logger("login", `[ Unused ] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
|
180
|
+
} else {
|
181
|
+
log.warn("login", global.fca.languages.errorUid);
|
182
|
+
noMqttData = html;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
// All data available to api functions
|
187
|
+
var ctx = {
|
188
|
+
userID: userID,
|
189
|
+
jar: jar,
|
190
|
+
clientID: clientID,
|
191
|
+
globalOptions: globalOptions,
|
192
|
+
loggedIn: true,
|
193
|
+
access_token: 'NONE',
|
194
|
+
clientMutationId: 0,
|
195
|
+
mqttClient: undefined,
|
196
|
+
lastSeqId: irisSeqID,
|
197
|
+
syncToken: undefined,
|
198
|
+
mqttEndpoint,
|
199
|
+
region,
|
200
|
+
firstListen: true
|
201
|
+
};
|
202
|
+
var api = {
|
203
|
+
setOptions: setOptions.bind(null, globalOptions),
|
204
|
+
getAppState: function getAppState() {
|
205
|
+
return utils.getAppState(jar);
|
206
|
+
}
|
207
|
+
};
|
208
|
+
if (noMqttData) api["htmlData"] = noMqttData;
|
209
|
+
const apiFuncNames = [
|
210
|
+
'addExternalModule',
|
211
|
+
'addUserToGroup',
|
212
|
+
'changeAdminStatus',
|
213
|
+
'changeArchivedStatus',
|
214
|
+
'changeAvt',
|
215
|
+
'changeBio',
|
216
|
+
'changeBlockedStatus',
|
217
|
+
'changeGroupImage',
|
218
|
+
'changeName',
|
219
|
+
'changeNickname',
|
220
|
+
'changeThreadColor',
|
221
|
+
'changeThreadEmoji',
|
222
|
+
'createNewGroup',
|
223
|
+
'createPoll',
|
224
|
+
'deleteMessage',
|
225
|
+
'deleteThread',
|
226
|
+
'forwardAttachment',
|
227
|
+
'getAccessToken',
|
228
|
+
'getCurrentUserID',
|
229
|
+
'getEmojiUrl',
|
230
|
+
'getFriendsList',
|
231
|
+
'getThreadHistory',
|
232
|
+
'getThreadInfo',
|
233
|
+
'getThreadList',
|
234
|
+
'getThreadPictures',
|
235
|
+
'getUserID',
|
236
|
+
'getUserInfo',
|
237
|
+
'getUserInfoV2',
|
238
|
+
'getUserInfoV3',
|
239
|
+
'getUserInfoV4',
|
240
|
+
'getUserInfoV5',
|
241
|
+
'handleMessageRequest',
|
242
|
+
'listenMqtt',
|
243
|
+
'logout',
|
244
|
+
'markAsDelivered',
|
245
|
+
'markAsRead',
|
246
|
+
'markAsReadAll',
|
247
|
+
'markAsSeen',
|
248
|
+
'muteThread',
|
249
|
+
'removeUserFromGroup',
|
250
|
+
'resolvePhotoUrl',
|
251
|
+
'ReportV1',
|
252
|
+
'searchForThread',
|
253
|
+
'sendMessage',
|
254
|
+
'sendTypingIndicator',
|
255
|
+
'setMessageReaction',
|
256
|
+
'setTitle',
|
257
|
+
'threadColors',
|
258
|
+
'unsendMessage',
|
259
|
+
'unfriend',
|
260
|
+
'setPostReaction',
|
261
|
+
// HTTP
|
262
|
+
'httpGet',
|
263
|
+
'httpPost',
|
264
|
+
'httpPostFormData',
|
265
|
+
// Deprecated features
|
266
|
+
"getThreadListDeprecated",
|
267
|
+
'getThreadHistoryDeprecated',
|
268
|
+
'getThreadInfoDeprecated'
|
269
|
+
];
|
270
|
+
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
271
|
+
|
272
|
+
// Load all api functions in a loop
|
273
|
+
apiFuncNames.map(v => api[v] = require('./src/' + v)(defaultFuncs, api, ctx));
|
274
|
+
|
275
|
+
return [ctx, defaultFuncs, api];
|
276
|
+
}
|
277
|
+
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
278
|
+
return function(res) {
|
279
|
+
var html = res.body;
|
280
|
+
var $ = cheerio.load(html);
|
281
|
+
var arr = [];
|
282
|
+
|
283
|
+
// This will be empty, but just to be sure we leave it
|
284
|
+
$("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
285
|
+
|
286
|
+
arr = arr.filter(function(v) {
|
287
|
+
return v.val && v.val.length;
|
288
|
+
});
|
289
|
+
var form = utils.arrToForm(arr);
|
290
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
291
|
+
form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
|
292
|
+
form.email = email;
|
293
|
+
form.pass = password;
|
294
|
+
form.default_persistent = '0';
|
295
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
296
|
+
form.locale = 'en_US';
|
297
|
+
form.timezone = '240';
|
298
|
+
form.lgnjs = ~~(Date.now() / 1000);
|
299
|
+
// Getting cookies from the HTML page... (kill me now plz)
|
300
|
+
// we used to get a bunch of cookies in the headers of the response of the
|
301
|
+
// request, but FB changed and they now send those cookies inside the JS.
|
302
|
+
// They run the JS which then injects the cookies in the page.
|
303
|
+
// The "solution" is to parse through the html and find those cookies
|
304
|
+
// which happen to be conveniently indicated with a _js_ in front of their
|
305
|
+
// variable name.
|
306
|
+
//
|
307
|
+
// ---------- Very Hacky Part Starts -----------------
|
308
|
+
var willBeCookies = html.split("\"_js_");
|
309
|
+
willBeCookies.slice(1).map(function(val) {
|
310
|
+
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
311
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
312
|
+
});
|
313
|
+
// ---------- Very Hacky Part Ends -----------------
|
314
|
+
logger(global.fca.languages.login, "[ FCA-DUONG ]");
|
315
|
+
return utils
|
316
|
+
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
317
|
+
.then(utils.saveCookies(jar))
|
318
|
+
.then(function(res) {
|
319
|
+
var headers = res.headers;
|
320
|
+
if (!headers.location) throw { error: global.fca.languages.loginError };
|
321
|
+
|
322
|
+
// This means the account has login approvals turned on.
|
323
|
+
if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
|
324
|
+
logger(global.fca.languages.errorFa, "[ FCA-DUONG ]");
|
325
|
+
var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
|
326
|
+
|
327
|
+
return utils
|
328
|
+
.get(headers.location, jar, null, loginOptions)
|
329
|
+
.then(utils.saveCookies(jar))
|
330
|
+
.then(function(res) {
|
331
|
+
var html = res.body;
|
332
|
+
// Make the form in advance which will contain the fb_dtsg and nh
|
333
|
+
var $ = cheerio.load(html);
|
334
|
+
var arr = [];
|
335
|
+
$("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
336
|
+
|
337
|
+
arr = arr.filter(function(v) {
|
338
|
+
return v.val && v.val.length;
|
339
|
+
});
|
340
|
+
|
341
|
+
var form = utils.arrToForm(arr);
|
342
|
+
if (html.indexOf("checkpoint/?next") > -1) {
|
343
|
+
setTimeout(() => {
|
344
|
+
checkVerified = setInterval((_form) => {}, 5000, {
|
345
|
+
fb_dtsg: form.fb_dtsg,
|
346
|
+
jazoest: form.jazoest,
|
347
|
+
dpr: 1
|
348
|
+
});
|
349
|
+
}, 2500);
|
350
|
+
throw {
|
351
|
+
error: 'login-approval',
|
352
|
+
continue: function submit2FA(code) {
|
353
|
+
form.approvals_code = code;
|
354
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
355
|
+
var prResolve = null;
|
356
|
+
var prReject = null;
|
357
|
+
var rtPromise = new Promise(function(resolve, reject) {
|
358
|
+
prResolve = resolve;
|
359
|
+
prReject = reject;
|
360
|
+
});
|
361
|
+
if (typeof code == "string") {
|
362
|
+
utils
|
363
|
+
.post(nextURL, jar, form, loginOptions)
|
364
|
+
.then(utils.saveCookies(jar))
|
365
|
+
.then(function(res) {
|
366
|
+
var $ = cheerio.load(res.body);
|
367
|
+
var error = $("#approvals_code").parent().attr("data-xui-error");
|
368
|
+
if (error) {
|
369
|
+
throw {
|
370
|
+
error: 'login-approval',
|
371
|
+
errordesc: "Invalid 2FA code.",
|
372
|
+
lerror: error,
|
373
|
+
continue: submit2FA
|
374
|
+
};
|
375
|
+
}
|
376
|
+
})
|
377
|
+
.then(function() {
|
378
|
+
// Use the same form (safe I hope)
|
379
|
+
delete form.no_fido;
|
380
|
+
delete form.approvals_code;
|
381
|
+
form.name_action_selected = 'dont_save'; //'save_device';
|
382
|
+
|
383
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
384
|
+
})
|
385
|
+
.then(function(res) {
|
386
|
+
var headers = res.headers;
|
387
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with login approvals." };
|
388
|
+
|
389
|
+
var appState = utils.getAppState(jar);
|
390
|
+
|
391
|
+
if (callback === prCallback) {
|
392
|
+
callback = function(err, api) {
|
393
|
+
if (err) return prReject(err);
|
394
|
+
return prResolve(api);
|
395
|
+
};
|
396
|
+
}
|
397
|
+
|
398
|
+
// Simply call loginHelper because all it needs is the jar
|
399
|
+
// and will then complete the login process
|
400
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
401
|
+
})
|
402
|
+
.catch(function(err) {
|
403
|
+
// Check if using Promise instead of callback
|
404
|
+
if (callback === prCallback) prReject(err);
|
405
|
+
else callback(err);
|
406
|
+
});
|
407
|
+
} else {
|
408
|
+
utils
|
409
|
+
.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" })
|
410
|
+
.then(utils.saveCookies(jar))
|
411
|
+
.then(res => {
|
412
|
+
try {
|
413
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
414
|
+
} catch (ex) {
|
415
|
+
clearInterval(checkVerified);
|
416
|
+
logger(global.fca.languages.okweb, "[ FCA-DUONG ]");
|
417
|
+
if (callback === prCallback) {
|
418
|
+
callback = function(err, api) {
|
419
|
+
if (err) return prReject(err);
|
420
|
+
return prResolve(api);
|
421
|
+
};
|
422
|
+
}
|
423
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
424
|
+
}
|
425
|
+
})
|
426
|
+
.catch(ex => {
|
427
|
+
log.error("login", ex);
|
428
|
+
if (callback === prCallback) prReject(ex);
|
429
|
+
else callback(ex);
|
430
|
+
});
|
431
|
+
}
|
432
|
+
return rtPromise;
|
433
|
+
}
|
434
|
+
};
|
435
|
+
} else {
|
436
|
+
if (!loginOptions.forceLogin) throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
|
437
|
+
|
438
|
+
if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
|
439
|
+
else form['submit[This Is Okay]'] = "This Is Okay";
|
440
|
+
|
441
|
+
return utils
|
442
|
+
.post(nextURL, jar, form, loginOptions)
|
443
|
+
.then(utils.saveCookies(jar))
|
444
|
+
.then(function() {
|
445
|
+
// Use the same form (safe I hope)
|
446
|
+
form.name_action_selected = 'save_device';
|
447
|
+
|
448
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
449
|
+
})
|
450
|
+
.then(function(res) {
|
451
|
+
var headers = res.headers;
|
452
|
+
|
453
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
|
454
|
+
|
455
|
+
var appState = utils.getAppState(jar);
|
456
|
+
|
457
|
+
// Simply call loginHelper because all it needs is the jar
|
458
|
+
// and will then complete the login process
|
459
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
460
|
+
})
|
461
|
+
.catch(e => callback(e));
|
462
|
+
}
|
463
|
+
});
|
464
|
+
}
|
465
|
+
|
466
|
+
return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
|
467
|
+
});
|
468
|
+
};
|
469
|
+
}
|
470
|
+
function makeid(length) {
|
471
|
+
var result = '';
|
472
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
473
|
+
var charactersLength = characters.length;
|
474
|
+
for ( var i = 0; i < length; i++ ) {
|
475
|
+
result += characters.charAt(Math.floor(Math.random() *
|
476
|
+
charactersLength));
|
477
|
+
}
|
478
|
+
return result;
|
479
|
+
}
|
480
|
+
// Helps the login
|
481
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
482
|
+
var mainPromise = null;
|
483
|
+
var jar = utils.getJar();
|
484
|
+
|
485
|
+
// If we're given an appState we loop through it and save each cookie
|
486
|
+
// back into the jar.
|
487
|
+
try {
|
488
|
+
if (appState) {
|
489
|
+
if (global.fca.ObjFcaConfig['encryptSt']) {
|
490
|
+
try {
|
491
|
+
if (fs.existsSync('./../.env')) {
|
492
|
+
require('dotenv').config({ path: './../.env' });
|
493
|
+
}
|
494
|
+
else {
|
495
|
+
fs.writeFileSync('./../.env', ``);
|
496
|
+
require('dotenv').config({ path: './../.env' });
|
497
|
+
}
|
498
|
+
}
|
499
|
+
catch (e) {
|
500
|
+
console.log(e);
|
501
|
+
process.exit(1);
|
502
|
+
}
|
503
|
+
if (!process.env['FBKEY']) {
|
504
|
+
try {
|
505
|
+
var ans = makeid(49)
|
506
|
+
process.env["FBKEY"] = ans;
|
507
|
+
fs.writeFile('./../.env', `FBKEY=${ans}`, function (err) {
|
508
|
+
if (err) {
|
509
|
+
logger(global.fca.languages.errorEnv, "[ FCA-DUONG ]");
|
510
|
+
}
|
511
|
+
else logger(global.fca.languages.env,"[ FCA-DUONG ]")
|
512
|
+
});
|
513
|
+
}
|
514
|
+
catch (e) {
|
515
|
+
console.log(e);
|
516
|
+
logger(global.fca.languages.errorPassRandom, "[ FCA-DUONG ]");
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
if (process.env['FBKEY']) {
|
521
|
+
try {
|
522
|
+
appState = JSON.stringify(appState);
|
523
|
+
if (appState.includes('[')) {
|
524
|
+
logger(global.fca.languages.appstateDec, '[ FCA-DUONG ]');
|
525
|
+
} else {
|
526
|
+
try {
|
527
|
+
appState = JSON.parse(appState);
|
528
|
+
var StateCrypt = require('./StateCrypt');
|
529
|
+
appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
|
530
|
+
logger(global.fca.languages.appstate, '[ FCA-DUONG ]');
|
531
|
+
}
|
532
|
+
catch (e) {
|
533
|
+
logger(global.fca.languages.appstateError, '[ FCA-DUONG ]');
|
534
|
+
}
|
535
|
+
}
|
536
|
+
}
|
537
|
+
catch (e) {
|
538
|
+
console.log(e);
|
539
|
+
}
|
540
|
+
}
|
541
|
+
try {
|
542
|
+
appState = JSON.parse(appState);
|
543
|
+
}
|
544
|
+
catch (e) {
|
545
|
+
try {
|
546
|
+
appState = appState;
|
547
|
+
}
|
548
|
+
catch (e) {
|
549
|
+
return logger(global.fca.languages.appstateError, '[ FCA-DUONG ]')
|
550
|
+
}
|
551
|
+
}
|
552
|
+
}
|
553
|
+
try {
|
554
|
+
appState.map(function(c) {
|
555
|
+
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
556
|
+
jar.setCookie(str, "http://" + c.domain);
|
557
|
+
});
|
558
|
+
|
559
|
+
// Load the main page.
|
560
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
561
|
+
} catch (e) {
|
562
|
+
return logger(global.fca.languages.appstateError, '[ FCA-DUONG ]')
|
563
|
+
}
|
564
|
+
} else {
|
565
|
+
// Open the main page, then we login with the given credentials and finally
|
566
|
+
// load the main page again (it'll give us some IDs that we need)
|
567
|
+
mainPromise = utils
|
568
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
569
|
+
.then(utils.saveCookies(jar))
|
570
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
571
|
+
.then(function() {
|
572
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
|
573
|
+
});
|
574
|
+
}
|
575
|
+
} catch (e) {
|
576
|
+
console.log(e);
|
577
|
+
}
|
578
|
+
var ctx = null;
|
579
|
+
var _defaultFuncs = null;
|
580
|
+
var api = null;
|
581
|
+
|
582
|
+
mainPromise = mainPromise
|
583
|
+
.then(function(res) {
|
584
|
+
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
585
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
586
|
+
var redirect = reg.exec(res.body);
|
587
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
588
|
+
return res;
|
589
|
+
})
|
590
|
+
.then(function(res) {
|
591
|
+
var html = res.body;
|
592
|
+
var stuff = buildAPI(globalOptions, html, jar);
|
593
|
+
ctx = stuff[0];
|
594
|
+
_defaultFuncs = stuff[1];
|
595
|
+
api = stuff[2];
|
596
|
+
return res;
|
597
|
+
});
|
598
|
+
|
599
|
+
// given a pageID we log in as a page
|
600
|
+
if (globalOptions.pageID) {
|
601
|
+
mainPromise = mainPromise
|
602
|
+
.then(function() {
|
603
|
+
return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
604
|
+
})
|
605
|
+
.then(function(resData) {
|
606
|
+
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
607
|
+
url = url.substring(0, url.length - 1);
|
608
|
+
return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
609
|
+
});
|
610
|
+
}
|
611
|
+
// At the end we call the callback or catch an exception
|
612
|
+
mainPromise
|
613
|
+
.then(function() {
|
614
|
+
logger(global.fca.languages.oklogin, "[ FCA-DUONG ]");
|
615
|
+
//!---------- Auto Check, Update START -----------------!//
|
616
|
+
var axios = require('axios');
|
617
|
+
var { readFileSync } = require('fs-extra');
|
618
|
+
const { execSync } = require('child_process');
|
619
|
+
axios.get('https://raw.githubusercontent.com/ThanhDuong465052998/fca-duonggg/main/Update-7.2.0').then(async (res) => {
|
620
|
+
const localbrand = JSON.parse(readFileSync('./node_modules/fca-duong/package.json')).version;
|
621
|
+
if (localbrand != res.data.version) {
|
622
|
+
log.warn("UPDATE > ",`${global.fca.languages.newVersion}${JSON.parse(readFileSync('./node_modules/fca-duong/package.json')).version} => ${res.data.version}`);
|
623
|
+
log.warn("UPDATE > ",`${global.fca.languages.autoUpdate}`);
|
624
|
+
try {
|
625
|
+
execSync('npm install fca-duong@latest', { stdio: 'inherit' });
|
626
|
+
logger(global.fca.languages.okUpdate,"UPDATE")
|
627
|
+
logger(global.fca.languages.restart, '[ FCA-DUONG ]');
|
628
|
+
await new Promise(resolve => setTimeout(resolve,5*1000));
|
629
|
+
console.clear();process.exit(1);
|
630
|
+
}
|
631
|
+
catch (err) {
|
632
|
+
log.warn(global.fca.languages.errorUpdate + err);
|
633
|
+
}
|
634
|
+
}
|
635
|
+
else {
|
636
|
+
logger(`${global.fca.languages.checkVersion}` + localbrand + ' !', "[ FCA-DUONG ]");
|
637
|
+
logger(global.fca.languages.chucAdmin, "[ FCA-DUONG ]");
|
638
|
+
await new Promise(resolve => setTimeout(resolve, 3*1000));
|
639
|
+
callback(null, api);
|
640
|
+
}
|
641
|
+
});
|
642
|
+
}).catch(function(e) {
|
643
|
+
log.error("login", e.error || e);
|
644
|
+
callback(e);
|
645
|
+
});
|
646
|
+
//!---------- Auto Check, Update END -----------------!//
|
647
|
+
}
|
648
|
+
function login(loginData, options, callback) {
|
649
|
+
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
650
|
+
callback = options;
|
651
|
+
options = {};
|
652
|
+
}
|
653
|
+
var globalOptions = {
|
654
|
+
selfListen: false,
|
655
|
+
listenEvents: true,
|
656
|
+
listenTyping: false,
|
657
|
+
updatePresence: false,
|
658
|
+
forceLogin: false,
|
659
|
+
autoMarkDelivery: false,
|
660
|
+
autoMarkRead: false,
|
661
|
+
autoReconnect: true,
|
662
|
+
logRecordSize: defaultLogRecordSize,
|
663
|
+
online: true,
|
664
|
+
emitReady: false,
|
665
|
+
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
|
666
|
+
};
|
667
|
+
//! bằng 1 cách nào đó tắt online sẽ đánh lừa được facebook :v
|
668
|
+
//! phải có that có this chứ :v
|
669
|
+
setOptions(globalOptions, options);
|
670
|
+
var prCallback = null;
|
671
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
672
|
+
var rejectFunc = null;
|
673
|
+
var resolveFunc = null;
|
674
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
675
|
+
resolveFunc = resolve;
|
676
|
+
rejectFunc = reject;
|
677
|
+
});
|
678
|
+
prCallback = function(error, api) {
|
679
|
+
if (error) return rejectFunc(error);
|
680
|
+
return resolveFunc(api);
|
681
|
+
};
|
682
|
+
callback = prCallback;
|
683
|
+
}
|
684
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
685
|
+
return returnPromise;
|
686
|
+
}
|
687
|
+
module.exports = login;
|