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