fca-rqzax-remake 0.0.1-security → 2.6.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fca-rqzax-remake might be problematic. Click here for more details.
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.gitattributes +2 -0
- package/.travis.yml +6 -0
- package/CHANGELOG.md +2 -0
- package/DOCS.md +1738 -0
- package/LICENSE-MIT +21 -0
- package/README.md +213 -3
- package/index.html +1200 -0
- package/index.js +542 -0
- package/package.json +65 -3
- package/replit.nix +9 -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/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/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +171 -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/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +49 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/listenMqtt.js +663 -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 +321 -0
- package/src/sendTypingIndicator.js +80 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +64 -0
- package/src/setTitle.js +74 -0
- package/src/threadColors.js +41 -0
- package/src/unfriend.js +43 -0
- package/src/unsendMessage.js +40 -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/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/utils.js +1234 -0
package/index.js
ADDED
@@ -0,0 +1,542 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const chalk = require('chalk');
|
4
|
+
function randomColor() {
|
5
|
+
var color = "";
|
6
|
+
for (var i = 0; i < 3; i++) {
|
7
|
+
var sub = Math.floor(Math.random() * 256).toString(16);
|
8
|
+
color += (sub.length == 1 ? "0" + sub : sub);
|
9
|
+
}
|
10
|
+
return "#" + color;
|
11
|
+
};
|
12
|
+
|
13
|
+
var utils = require("./utils");
|
14
|
+
var cheerio = require("cheerio");
|
15
|
+
var log = require("npmlog");
|
16
|
+
|
17
|
+
|
18
|
+
var checkVerified = null;
|
19
|
+
|
20
|
+
var defaultLogRecordSize = 100;
|
21
|
+
log.maxRecordSize = defaultLogRecordSize;
|
22
|
+
|
23
|
+
function setOptions(globalOptions, options) {
|
24
|
+
Object.keys(options).map(function(key) {
|
25
|
+
switch (key) {
|
26
|
+
case 'pauseLog':
|
27
|
+
if (options.pauseLog) log.pause();
|
28
|
+
break;
|
29
|
+
case 'online':
|
30
|
+
globalOptions.online = Boolean(options.online);
|
31
|
+
break;
|
32
|
+
case 'logLevel':
|
33
|
+
log.level = options.logLevel;
|
34
|
+
globalOptions.logLevel = options.logLevel;
|
35
|
+
break;
|
36
|
+
case 'logRecordSize':
|
37
|
+
log.maxRecordSize = options.logRecordSize;
|
38
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
39
|
+
break;
|
40
|
+
case 'selfListen':
|
41
|
+
globalOptions.selfListen = Boolean(options.selfListen);
|
42
|
+
break;
|
43
|
+
case 'listenEvents':
|
44
|
+
globalOptions.listenEvents = Boolean(options.listenEvents);
|
45
|
+
break;
|
46
|
+
case 'pageID':
|
47
|
+
globalOptions.pageID = options.pageID.toString();
|
48
|
+
break;
|
49
|
+
case 'updatePresence':
|
50
|
+
globalOptions.updatePresence = Boolean(options.updatePresence);
|
51
|
+
break;
|
52
|
+
case 'forceLogin':
|
53
|
+
globalOptions.forceLogin = Boolean(options.forceLogin);
|
54
|
+
break;
|
55
|
+
case 'userAgent':
|
56
|
+
globalOptions.userAgent = options.userAgent;
|
57
|
+
break;
|
58
|
+
case 'autoMarkDelivery':
|
59
|
+
globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
|
60
|
+
break;
|
61
|
+
case 'autoMarkRead':
|
62
|
+
globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
|
63
|
+
break;
|
64
|
+
case 'listenTyping':
|
65
|
+
globalOptions.listenTyping = Boolean(options.listenTyping);
|
66
|
+
break;
|
67
|
+
case 'proxy':
|
68
|
+
if (typeof options.proxy != "string") {
|
69
|
+
delete globalOptions.proxy;
|
70
|
+
utils.setProxy();
|
71
|
+
} else {
|
72
|
+
globalOptions.proxy = options.proxy;
|
73
|
+
utils.setProxy(globalOptions.proxy);
|
74
|
+
}
|
75
|
+
break;
|
76
|
+
case 'autoReconnect':
|
77
|
+
globalOptions.autoReconnect = Boolean(options.autoReconnect);
|
78
|
+
break;
|
79
|
+
case 'emitReady':
|
80
|
+
globalOptions.emitReady = Boolean(options.emitReady);
|
81
|
+
break;
|
82
|
+
default:
|
83
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
});
|
87
|
+
}
|
88
|
+
|
89
|
+
function buildAPI(globalOptions, html, jar, data, option) {
|
90
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
|
91
|
+
return val.cookieString().split("=")[0] === "c_user";
|
92
|
+
});
|
93
|
+
|
94
|
+
if (maybeCookie.length === 0) throw { error: "Phát Hiện Lỗi Vị Trí ! Hãy Thử Đăng Nhập Vô Trình Duyệt Chorme Ẩn Danh Và Thử Lại !" };
|
95
|
+
|
96
|
+
if (html.indexOf("/checkpoint/block/?next") > -1) console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]", "Phát Hiện CheckPoint !, Hãy Thử Đăng Nhập Vô Trình Duyệt Ẩn Danh Và Thử Lại !"));
|
97
|
+
|
98
|
+
var userID = maybeCookie[0].cookieString().split("=")[1].toString();
|
99
|
+
console.log(chalk.bold.hex(randomColor()).bold("\n[ FCA ]",`Đăng Nhập Tại ID: ${userID} `));
|
100
|
+
|
101
|
+
try {
|
102
|
+
clearInterval(checkVerified);
|
103
|
+
} catch (e) {
|
104
|
+
console.log(e);
|
105
|
+
}
|
106
|
+
|
107
|
+
var clientID = (Math.random() * 2147483648 | 0).toString(16);
|
108
|
+
|
109
|
+
let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
|
110
|
+
let mqttEndpoint = null;
|
111
|
+
let region = null;
|
112
|
+
let irisSeqID = null;
|
113
|
+
var noMqttData = null;
|
114
|
+
|
115
|
+
if (oldFBMQTTMatch) {
|
116
|
+
irisSeqID = oldFBMQTTMatch[1];
|
117
|
+
mqttEndpoint = oldFBMQTTMatch[2];
|
118
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
119
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]",`Đã Lấy Được Vị Trí Tin Nhắn Của Tài Khoản Là : ${region}`));
|
120
|
+
} else {
|
121
|
+
let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
|
122
|
+
if (newFBMQTTMatch) {
|
123
|
+
irisSeqID = newFBMQTTMatch[2];
|
124
|
+
mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
|
125
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
126
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]",`Đã Lấy Được Vị Trí Tin Nhắn Của Tài Khoản Là : ${region}`));
|
127
|
+
} else {
|
128
|
+
let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
|
129
|
+
if (legacyFBMQTTMatch) {
|
130
|
+
mqttEndpoint = legacyFBMQTTMatch[4];
|
131
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
132
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`) + data);
|
133
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]",`Đã Lấy Được Vị Trí Tin Nhắn Của Tài Khoản Là : ${region}`));
|
134
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]",`[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`));
|
135
|
+
} else {
|
136
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]","Không Thể Lấy ID Hãy Thử Lại !"));
|
137
|
+
noMqttData = html;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
// All data available to api functions
|
143
|
+
var ctx = {
|
144
|
+
userID: userID,
|
145
|
+
jar: jar,
|
146
|
+
clientID: clientID,
|
147
|
+
globalOptions: globalOptions,
|
148
|
+
loggedIn: true,
|
149
|
+
access_token: 'NONE',
|
150
|
+
clientMutationId: 0,
|
151
|
+
mqttClient: undefined,
|
152
|
+
lastSeqId: irisSeqID,
|
153
|
+
syncToken: undefined,
|
154
|
+
mqttEndpoint,
|
155
|
+
region,
|
156
|
+
firstListen: true
|
157
|
+
};
|
158
|
+
|
159
|
+
var api = {
|
160
|
+
setOptions: setOptions.bind(null, globalOptions),
|
161
|
+
getAppState: function getAppState() {
|
162
|
+
return utils.getAppState(jar);
|
163
|
+
}
|
164
|
+
};
|
165
|
+
|
166
|
+
if (noMqttData) api["htmlData"] = noMqttData;
|
167
|
+
|
168
|
+
const apiFuncNames = [
|
169
|
+
'addExternalModule',
|
170
|
+
'addUserToGroup',
|
171
|
+
'changeAdminStatus',
|
172
|
+
'changeArchivedStatus',
|
173
|
+
'changeBio',
|
174
|
+
'changeBlockedStatus',
|
175
|
+
'changeGroupImage',
|
176
|
+
'changeNickname',
|
177
|
+
'changeThreadColor',
|
178
|
+
'changeThreadEmoji',
|
179
|
+
'createNewGroup',
|
180
|
+
'createPoll',
|
181
|
+
'deleteMessage',
|
182
|
+
'deleteThread',
|
183
|
+
'forwardAttachment',
|
184
|
+
'getCurrentUserID',
|
185
|
+
'getEmojiUrl',
|
186
|
+
'getFriendsList',
|
187
|
+
'getThreadHistory',
|
188
|
+
'getThreadInfo',
|
189
|
+
'getThreadList',
|
190
|
+
'getThreadPictures',
|
191
|
+
'getUserID',
|
192
|
+
'getUserInfo',
|
193
|
+
'handleMessageRequest',
|
194
|
+
'listenMqtt',
|
195
|
+
'logout',
|
196
|
+
'markAsDelivered',
|
197
|
+
'markAsRead',
|
198
|
+
'markAsReadAll',
|
199
|
+
'markAsSeen',
|
200
|
+
'muteThread',
|
201
|
+
'removeUserFromGroup',
|
202
|
+
'resolvePhotoUrl',
|
203
|
+
'searchForThread',
|
204
|
+
'sendMessage',
|
205
|
+
'sendTypingIndicator',
|
206
|
+
'setMessageReaction',
|
207
|
+
'setTitle',
|
208
|
+
'threadColors',
|
209
|
+
'unsendMessage',
|
210
|
+
'unfriend',
|
211
|
+
|
212
|
+
// HTTP
|
213
|
+
'httpGet',
|
214
|
+
'httpPost',
|
215
|
+
|
216
|
+
// Deprecated features
|
217
|
+
"getThreadListDeprecated",
|
218
|
+
'getThreadHistoryDeprecated',
|
219
|
+
'getThreadInfoDeprecated',
|
220
|
+
];
|
221
|
+
|
222
|
+
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
223
|
+
|
224
|
+
// Load all api functions in a loop
|
225
|
+
apiFuncNames.map(v => api[v] = require('./src/' + v)(defaultFuncs, api, ctx));
|
226
|
+
|
227
|
+
return [ctx, defaultFuncs, api];
|
228
|
+
}
|
229
|
+
|
230
|
+
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
231
|
+
return function(res) {
|
232
|
+
var html = res.body;
|
233
|
+
var $ = cheerio.load(html);
|
234
|
+
var arr = [];
|
235
|
+
|
236
|
+
// This will be empty, but just to be sure we leave it
|
237
|
+
$("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
238
|
+
|
239
|
+
arr = arr.filter(function(v) {
|
240
|
+
return v.val && v.val.length;
|
241
|
+
});
|
242
|
+
|
243
|
+
var form = utils.arrToForm(arr);
|
244
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
245
|
+
form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
|
246
|
+
form.email = email;
|
247
|
+
form.pass = password;
|
248
|
+
form.default_persistent = '0';
|
249
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
250
|
+
form.locale = 'en_US';
|
251
|
+
form.timezone = '240';
|
252
|
+
form.lgnjs = ~~(Date.now() / 1000);
|
253
|
+
|
254
|
+
|
255
|
+
// Getting cookies from the HTML page... (kill me now plz)
|
256
|
+
// we used to get a bunch of cookies in the headers of the response of the
|
257
|
+
// request, but FB changed and they now send those cookies inside the JS.
|
258
|
+
// They run the JS which then injects the cookies in the page.
|
259
|
+
// The "solution" is to parse through the html and find those cookies
|
260
|
+
// which happen to be conveniently indicated with a _js_ in front of their
|
261
|
+
// variable name.
|
262
|
+
//
|
263
|
+
// ---------- Very Hacky Part Starts -----------------
|
264
|
+
var willBeCookies = html.split("\"_js_");
|
265
|
+
willBeCookies.slice(1).map(function(val) {
|
266
|
+
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
267
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
268
|
+
});
|
269
|
+
// ---------- Very Hacky Part Ends -----------------
|
270
|
+
|
271
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]","Logging in..."));
|
272
|
+
return utils
|
273
|
+
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
274
|
+
.then(utils.saveCookies(jar))
|
275
|
+
.then(function(res) {
|
276
|
+
var headers = res.headers;
|
277
|
+
if (!headers.location) throw { error: "Sai Mật Khẩu Hoặc Tài Khoản !" };
|
278
|
+
|
279
|
+
// This means the account has login approvals turned on.
|
280
|
+
if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
|
281
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]", "Heyyy M Bật Hai Bảo Mật Kìa"));
|
282
|
+
var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
|
283
|
+
|
284
|
+
return utils
|
285
|
+
.get(headers.location, jar, null, loginOptions)
|
286
|
+
.then(utils.saveCookies(jar))
|
287
|
+
.then(function(res) {
|
288
|
+
var html = res.body;
|
289
|
+
// Make the form in advance which will contain the fb_dtsg and nh
|
290
|
+
var $ = cheerio.load(html);
|
291
|
+
var arr = [];
|
292
|
+
$("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
293
|
+
|
294
|
+
arr = arr.filter(function(v) {
|
295
|
+
return v.val && v.val.length;
|
296
|
+
});
|
297
|
+
|
298
|
+
var form = utils.arrToForm(arr);
|
299
|
+
if (html.indexOf("checkpoint/?next") > -1) {
|
300
|
+
setTimeout(() => {
|
301
|
+
checkVerified = setInterval((_form) => {}, 5000, {
|
302
|
+
fb_dtsg: form.fb_dtsg,
|
303
|
+
jazoest: form.jazoest,
|
304
|
+
dpr: 1
|
305
|
+
});
|
306
|
+
}, 2500);
|
307
|
+
throw {
|
308
|
+
error: 'login-approval',
|
309
|
+
continue: function submit2FA(code) {
|
310
|
+
form.approvals_code = code;
|
311
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
312
|
+
var prResolve = null;
|
313
|
+
var prReject = null;
|
314
|
+
var rtPromise = new Promise(function(resolve, reject) {
|
315
|
+
prResolve = resolve;
|
316
|
+
prReject = reject;
|
317
|
+
});
|
318
|
+
if (typeof code == "string") {
|
319
|
+
utils
|
320
|
+
.post(nextURL, jar, form, loginOptions)
|
321
|
+
.then(utils.saveCookies(jar))
|
322
|
+
.then(function(res) {
|
323
|
+
var $ = cheerio.load(res.body);
|
324
|
+
var error = $("#approvals_code").parent().attr("data-xui-error");
|
325
|
+
if (error) {
|
326
|
+
throw {
|
327
|
+
error: 'login-approval',
|
328
|
+
errordesc: "Invalid 2FA code.",
|
329
|
+
lerror: error,
|
330
|
+
continue: submit2FA
|
331
|
+
};
|
332
|
+
}
|
333
|
+
})
|
334
|
+
.then(function() {
|
335
|
+
// Use the same form (safe I hope)
|
336
|
+
delete form.no_fido;
|
337
|
+
delete form.approvals_code;
|
338
|
+
form.name_action_selected = 'dont_save'; //'save_device';
|
339
|
+
|
340
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
341
|
+
})
|
342
|
+
.then(function(res) {
|
343
|
+
var headers = res.headers;
|
344
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with login approvals." };
|
345
|
+
|
346
|
+
var appState = utils.getAppState(jar);
|
347
|
+
|
348
|
+
if (callback === prCallback) {
|
349
|
+
callback = function(err, api) {
|
350
|
+
if (err) return prReject(err);
|
351
|
+
return prResolve(api);
|
352
|
+
};
|
353
|
+
}
|
354
|
+
|
355
|
+
// Simply call loginHelper because all it needs is the jar
|
356
|
+
// and will then complete the login process
|
357
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
358
|
+
})
|
359
|
+
.catch(function(err) {
|
360
|
+
// Check if using Promise instead of callback
|
361
|
+
if (callback === prCallback) prReject(err);
|
362
|
+
else callback(err);
|
363
|
+
});
|
364
|
+
} else {
|
365
|
+
utils
|
366
|
+
.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" })
|
367
|
+
.then(utils.saveCookies(jar))
|
368
|
+
.then(res => {
|
369
|
+
try {
|
370
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
371
|
+
} catch (ex) {
|
372
|
+
clearInterval(checkVerified);
|
373
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]","Verified from browser. Logging in...") + chalk.bold.hex(randomColor()).bold(data));
|
374
|
+
if (callback === prCallback) {
|
375
|
+
callback = function(err, api) {
|
376
|
+
if (err) return prReject(err);
|
377
|
+
return prResolve(api);
|
378
|
+
};
|
379
|
+
}
|
380
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
381
|
+
}
|
382
|
+
})
|
383
|
+
.catch(ex => {
|
384
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]", ex) + chalk.bold.hex(randomColor()).bold(data));
|
385
|
+
if (callback === prCallback) prReject(ex);
|
386
|
+
else callback(ex);
|
387
|
+
});
|
388
|
+
}
|
389
|
+
return rtPromise;
|
390
|
+
}
|
391
|
+
};
|
392
|
+
} else {
|
393
|
+
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." };
|
394
|
+
|
395
|
+
if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
|
396
|
+
else form['submit[This Is Okay]'] = "This Is Okay";
|
397
|
+
|
398
|
+
return utils
|
399
|
+
.post(nextURL, jar, form, loginOptions)
|
400
|
+
.then(utils.saveCookies(jar))
|
401
|
+
.then(function() {
|
402
|
+
// Use the same form (safe I hope)
|
403
|
+
form.name_action_selected = 'save_device';
|
404
|
+
|
405
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
406
|
+
})
|
407
|
+
.then(function(res) {
|
408
|
+
var headers = res.headers;
|
409
|
+
|
410
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
|
411
|
+
|
412
|
+
var appState = utils.getAppState(jar);
|
413
|
+
|
414
|
+
// Simply call loginHelper because all it needs is the jar
|
415
|
+
// and will then complete the login process
|
416
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
417
|
+
})
|
418
|
+
.catch(e => callback(e));
|
419
|
+
}
|
420
|
+
});
|
421
|
+
}
|
422
|
+
|
423
|
+
return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
|
424
|
+
});
|
425
|
+
};
|
426
|
+
}
|
427
|
+
|
428
|
+
// Helps the login
|
429
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
430
|
+
var mainPromise = null;
|
431
|
+
var jar = utils.getJar();
|
432
|
+
|
433
|
+
// If we're given an appState we loop through it and save each cookie
|
434
|
+
// back into the jar.
|
435
|
+
if (appState) {
|
436
|
+
appState.map(function(c) {
|
437
|
+
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
438
|
+
jar.setCookie(str, "http://" + c.domain);
|
439
|
+
});
|
440
|
+
|
441
|
+
// Load the main page.
|
442
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
443
|
+
} else {
|
444
|
+
// Open the main page, then we login with the given credentials and finally
|
445
|
+
// load the main page again (it'll give us some IDs that we need)
|
446
|
+
mainPromise = utils
|
447
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
448
|
+
.then(utils.saveCookies(jar))
|
449
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
450
|
+
.then(function() {
|
451
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
|
452
|
+
});
|
453
|
+
}
|
454
|
+
|
455
|
+
var ctx = null;
|
456
|
+
var _defaultFuncs = null;
|
457
|
+
var api = null;
|
458
|
+
|
459
|
+
mainPromise = mainPromise
|
460
|
+
.then(function(res) {
|
461
|
+
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
462
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
463
|
+
var redirect = reg.exec(res.body);
|
464
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
465
|
+
return res;
|
466
|
+
})
|
467
|
+
.then(function(res) {
|
468
|
+
var html = res.body;
|
469
|
+
var stuff = buildAPI(globalOptions, html, jar);
|
470
|
+
ctx = stuff[0];
|
471
|
+
_defaultFuncs = stuff[1];
|
472
|
+
api = stuff[2];
|
473
|
+
return res;
|
474
|
+
});
|
475
|
+
|
476
|
+
// given a pageID we log in as a page
|
477
|
+
if (globalOptions.pageID) {
|
478
|
+
mainPromise = mainPromise
|
479
|
+
.then(function() {
|
480
|
+
return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
481
|
+
})
|
482
|
+
.then(function(resData) {
|
483
|
+
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
484
|
+
url = url.substring(0, url.length - 1);
|
485
|
+
return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
486
|
+
});
|
487
|
+
}
|
488
|
+
|
489
|
+
// At the end we call the callback or catch an exception
|
490
|
+
mainPromise
|
491
|
+
.then(function() {
|
492
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]",'Hoàn Thành Quá Trình Đăng Nhập !\n'));
|
493
|
+
return callback(null, api);
|
494
|
+
})
|
495
|
+
.catch(function(e) {
|
496
|
+
console.log(chalk.bold.hex(randomColor()).bold("[ FCA ]", e.error || e) + chalk.bold.hex(randomColor()).bold(data));
|
497
|
+
callback(e);
|
498
|
+
});
|
499
|
+
}
|
500
|
+
|
501
|
+
function login(loginData, options, callback) {
|
502
|
+
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
503
|
+
callback = options;
|
504
|
+
options = {};
|
505
|
+
}
|
506
|
+
|
507
|
+
var globalOptions = {
|
508
|
+
selfListen: false,
|
509
|
+
listenEvents: true,
|
510
|
+
listenTyping: false,
|
511
|
+
updatePresence: false,
|
512
|
+
forceLogin: false,
|
513
|
+
autoMarkDelivery: false,
|
514
|
+
autoMarkRead: false,
|
515
|
+
autoReconnect: true,
|
516
|
+
logRecordSize: defaultLogRecordSize,
|
517
|
+
online: false,
|
518
|
+
emitReady: false,
|
519
|
+
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"
|
520
|
+
};
|
521
|
+
|
522
|
+
setOptions(globalOptions, options);
|
523
|
+
|
524
|
+
var prCallback = null;
|
525
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
526
|
+
var rejectFunc = null;
|
527
|
+
var resolveFunc = null;
|
528
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
529
|
+
resolveFunc = resolve;
|
530
|
+
rejectFunc = reject;
|
531
|
+
});
|
532
|
+
prCallback = function(error, api) {
|
533
|
+
if (error) return rejectFunc(error);
|
534
|
+
return resolveFunc(api);
|
535
|
+
};
|
536
|
+
callback = prCallback;
|
537
|
+
}
|
538
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
539
|
+
return returnPromise;
|
540
|
+
}
|
541
|
+
|
542
|
+
module.exports = login;
|
package/package.json
CHANGED
@@ -1,6 +1,68 @@
|
|
1
1
|
{
|
2
2
|
"name": "fca-rqzax-remake",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"version": "2.6.5",
|
4
|
+
"description": "Facebook Chat Api",
|
5
|
+
"scripts": {
|
6
|
+
"test": "mocha",
|
7
|
+
"lint": "./node_modules/.bin/eslint **.js",
|
8
|
+
"prettier": "prettier utils.js src/* --write"
|
9
|
+
},
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "git://github.com/RqzaX040/Fca-RqzaX-Remake.git"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"facebook",
|
16
|
+
"chat",
|
17
|
+
"api"
|
18
|
+
],
|
19
|
+
"bugs": {
|
20
|
+
"url": "https://github.com/RqzaX040/Fca-RqzaX-Remake/issues"
|
21
|
+
},
|
22
|
+
"author": "Avery, David, Maude, Benjamin, Kanzu",
|
23
|
+
"license": "MIT",
|
24
|
+
"dependencies": {
|
25
|
+
"bluebird": "^2.11.0",
|
26
|
+
"chalk": "^4.1.2",
|
27
|
+
"cheerio": "^1.0.0-rc.10",
|
28
|
+
"https-proxy-agent": "^4.0.0",
|
29
|
+
"mqtt": "^4.2.8",
|
30
|
+
"npmlog": "^1.2.0",
|
31
|
+
"request": "^2.53.0",
|
32
|
+
"websocket-stream": "^5.5.0"
|
33
|
+
},
|
34
|
+
"engines": {
|
35
|
+
"node": ">=10.x"
|
36
|
+
},
|
37
|
+
"devDependencies": {
|
38
|
+
"eslint": "^7.5.0",
|
39
|
+
"mocha": "^7.0.1",
|
40
|
+
"prettier": "^1.11.1"
|
41
|
+
},
|
42
|
+
"eslintConfig": {
|
43
|
+
"env": {
|
44
|
+
"es6": true,
|
45
|
+
"node": true
|
46
|
+
},
|
47
|
+
"extends": "eslint:recommended",
|
48
|
+
"parserOptions": {
|
49
|
+
"sourceType": "module"
|
50
|
+
},
|
51
|
+
"rules": {
|
52
|
+
"linebreak-style": [
|
53
|
+
"error",
|
54
|
+
"unix"
|
55
|
+
],
|
56
|
+
"semi": [
|
57
|
+
"error",
|
58
|
+
"always"
|
59
|
+
],
|
60
|
+
"no-unused-vars": [
|
61
|
+
1,
|
62
|
+
{
|
63
|
+
"argsIgnorePattern": "^_"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}
|
67
|
+
}
|
6
68
|
}
|
package/replit.nix
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
return function addExternalModule(moduleObj) {
|
7
|
+
if (utils.getType(moduleObj) == "Object") {
|
8
|
+
for (let apiName in moduleObj) {
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function") api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
10
|
+
else throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
|
11
|
+
|
12
|
+
}
|
13
|
+
}
|
14
|
+
else throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
|
15
|
+
};
|
16
|
+
};
|