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