alicezetion 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +601 -386
- package/leiamnash/addExternalModule.js +19 -16
- package/leiamnash/addUserToGroup.js +113 -79
- package/leiamnash/changeAdminStatus.js +79 -79
- package/leiamnash/changeArchivedStatus.js +55 -41
- package/leiamnash/changeBio.js +77 -65
- package/leiamnash/changeBlockedStatus.js +47 -36
- package/leiamnash/changeGroupImage.js +129 -106
- package/leiamnash/changeNickname.js +59 -45
- package/leiamnash/changeThreadColor.js +71 -62
- package/leiamnash/changeThreadEmoji.js +55 -42
- package/leiamnash/chat.js +459 -374
- package/leiamnash/createNewGroup.js +86 -70
- package/leiamnash/createPoll.js +71 -60
- package/leiamnash/deleteMessage.js +56 -45
- package/leiamnash/deleteThread.js +56 -43
- package/leiamnash/forwardAttachment.js +60 -48
- package/leiamnash/getCurrentUserID.js +7 -7
- package/leiamnash/getEmojiUrl.js +29 -27
- package/leiamnash/getFriendsList.js +84 -73
- package/leiamnash/getThreadHistory.js +645 -537
- package/leiamnash/getThreadHistoryDeprecated.js +93 -0
- package/leiamnash/getThreadInfo.js +206 -425
- package/leiamnash/getThreadInfoDeprecated.js +80 -0
- package/leiamnash/getThreadList.js +238 -213
- package/leiamnash/getThreadListDeprecated.js +75 -0
- package/leiamnash/getThreadPictures.js +79 -59
- package/leiamnash/getUserID.js +66 -62
- package/leiamnash/getUserInfo.js +72 -113
- package/leiamnash/handleFriendRequest.js +61 -46
- package/leiamnash/handleMessageRequest.js +65 -49
- package/leiamnash/httpGet.js +52 -49
- package/leiamnash/httpPost.js +52 -48
- package/leiamnash/listenMqtt.js +789 -787
- package/leiamnash/logout.js +75 -68
- package/leiamnash/markAsDelivered.js +58 -48
- package/leiamnash/markAsRead.js +80 -70
- package/leiamnash/markAsReadAll.js +49 -42
- package/leiamnash/markAsSeen.js +59 -51
- package/leiamnash/muteThread.js +52 -47
- package/leiamnash/removeUserFromGroup.js +79 -49
- package/leiamnash/resolvePhotoUrl.js +45 -37
- package/leiamnash/searchForThread.js +53 -43
- package/leiamnash/sendTypingIndicator.js +103 -80
- package/leiamnash/setMessageReaction.js +117 -109
- package/leiamnash/setPostReaction.js +76 -102
- package/leiamnash/setTitle.js +86 -74
- package/leiamnash/threadColors.js +57 -39
- package/leiamnash/unfriend.js +52 -43
- package/leiamnash/unsendMessage.js +49 -40
- package/package.json +72 -90
- package/utils.js +1356 -1684
- package/Extra/Database/index.js +0 -469
- package/Extra/ExtraAddons.js +0 -82
- package/Extra/ExtraFindUID.js +0 -62
- package/Extra/ExtraGetThread.js +0 -340
- package/Extra/ExtraScreenShot.js +0 -430
- package/Extra/ExtraUptimeRobot.js +0 -38
- package/Extra/Html/Classic/script.js +0 -119
- package/Extra/Html/Classic/style.css +0 -8
- package/Extra/Security/AES_256_GCM/index.js +0 -0
- package/Extra/Security/Base/Step_1.js +0 -6
- package/Extra/Security/Base/Step_2.js +0 -22
- package/Extra/Security/Base/Step_3.js +0 -22
- package/Extra/Security/Base/index.js +0 -174
- package/Extra/Security/Index.js +0 -5
- package/Extra/Security/Step_1.js +0 -6
- package/Extra/Security/Step_2.js +0 -22
- package/Extra/Security/Step_3.js +0 -22
- package/Extra/Src/Change_Environment.js +0 -24
- package/Extra/Src/Check_Update.js +0 -67
- package/Extra/Src/History.js +0 -115
- package/Extra/Src/Instant_Update.js +0 -65
- package/Extra/Src/Last-Run.js +0 -65
- package/Extra/Src/Premium.js +0 -81
- package/Extra/Src/Release_Memory.js +0 -41
- package/Extra/Src/Websocket.js +0 -213
- package/Extra/Src/image/checkmate.jpg +0 -0
- package/Extra/Src/uuid.js +0 -137
- package/Func/AcceptAgreement.js +0 -31
- package/Func/ClearCache.js +0 -64
- package/Func/ReportV1.js +0 -54
- package/Language/index.json +0 -217
- package/Main.js +0 -1270
- package/broadcast.js +0 -40
- package/leiamnash/Dev_Horizon_Data.js +0 -125
- package/leiamnash/Premium.js +0 -25
- package/leiamnash/Screenshot.js +0 -83
- package/leiamnash/changeAvt.js +0 -85
- package/leiamnash/getAccessToken.js +0 -28
- package/leiamnash/getMessage.js +0 -80
- package/leiamnash/getThreadMain.js +0 -220
- package/leiamnash/getUID.js +0 -59
- package/leiamnash/getUserInfoMain.js +0 -65
- package/leiamnash/getUserInfoV2.js +0 -32
- package/leiamnash/getUserInfoV3.js +0 -63
- package/leiamnash/getUserInfoV4.js +0 -55
- package/leiamnash/getUserInfoV5.js +0 -61
- package/leiamnash/httpPostFormData.js +0 -41
- package/leiamnash/sendMessage.js +0 -379
- package/logger.js +0 -66
package/index.js
CHANGED
@@ -1,386 +1,601 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
//
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
//
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("./utils");
|
4
|
+
var cheerio = require("cheerio");
|
5
|
+
var log = require("npmlog");
|
6
|
+
|
7
|
+
var checkVerified = null;
|
8
|
+
|
9
|
+
var defaultLogRecordSize = 100;
|
10
|
+
log.maxRecordSize = defaultLogRecordSize;
|
11
|
+
|
12
|
+
function setOptions(globalOptions, options) {
|
13
|
+
Object.keys(options).map(function (key) {
|
14
|
+
switch (key) {
|
15
|
+
case 'online':
|
16
|
+
globalOptions.online = Boolean(options.online);
|
17
|
+
break;
|
18
|
+
case 'logLevel':
|
19
|
+
log.level = options.logLevel;
|
20
|
+
globalOptions.logLevel = options.logLevel;
|
21
|
+
break;
|
22
|
+
case 'logRecordSize':
|
23
|
+
log.maxRecordSize = options.logRecordSize;
|
24
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
25
|
+
break;
|
26
|
+
case 'selfListen':
|
27
|
+
globalOptions.selfListen = Boolean(options.selfListen);
|
28
|
+
break;
|
29
|
+
case 'listenEvents':
|
30
|
+
globalOptions.listenEvents = Boolean(options.listenEvents);
|
31
|
+
break;
|
32
|
+
case 'pageID':
|
33
|
+
globalOptions.pageID = options.pageID.toString();
|
34
|
+
break;
|
35
|
+
case 'updatePresence':
|
36
|
+
globalOptions.updatePresence = Boolean(options.updatePresence);
|
37
|
+
break;
|
38
|
+
case 'forceLogin':
|
39
|
+
globalOptions.forceLogin = Boolean(options.forceLogin);
|
40
|
+
break;
|
41
|
+
case 'userAgent':
|
42
|
+
globalOptions.userAgent = options.userAgent;
|
43
|
+
break;
|
44
|
+
case 'autoMarkDelivery':
|
45
|
+
globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
|
46
|
+
break;
|
47
|
+
case 'autoMarkRead':
|
48
|
+
globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
|
49
|
+
break;
|
50
|
+
case 'listenTyping':
|
51
|
+
globalOptions.listenTyping = Boolean(options.listenTyping);
|
52
|
+
break;
|
53
|
+
case 'proxy':
|
54
|
+
if (typeof options.proxy != "string") {
|
55
|
+
delete globalOptions.proxy;
|
56
|
+
utils.setProxy();
|
57
|
+
} else {
|
58
|
+
globalOptions.proxy = options.proxy;
|
59
|
+
utils.setProxy(globalOptions.proxy);
|
60
|
+
}
|
61
|
+
break;
|
62
|
+
case 'autoReconnect':
|
63
|
+
globalOptions.autoReconnect = Boolean(options.autoReconnect);
|
64
|
+
break;
|
65
|
+
case 'emitReady':
|
66
|
+
globalOptions.emitReady = Boolean(options.emitReady);
|
67
|
+
break;
|
68
|
+
default:
|
69
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
});
|
73
|
+
}
|
74
|
+
|
75
|
+
function buildAPI(globalOptions, html, jar) {
|
76
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) {
|
77
|
+
return val.cookieString().split("=")[0] === "c_user";
|
78
|
+
});
|
79
|
+
|
80
|
+
if (maybeCookie.length === 0) {
|
81
|
+
throw { error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify." };
|
82
|
+
}
|
83
|
+
|
84
|
+
if (html.indexOf("/checkpoint/block/?next") > -1) {
|
85
|
+
log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
|
86
|
+
}
|
87
|
+
|
88
|
+
var userID = maybeCookie[0].cookieString().split("=")[1].toString();
|
89
|
+
try {
|
90
|
+
clearInterval(checkVerified);
|
91
|
+
} catch (_) { }
|
92
|
+
|
93
|
+
var clientID = (Math.random() * 2147483648 | 0).toString(16);
|
94
|
+
|
95
|
+
|
96
|
+
let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
|
97
|
+
let mqttEndpoint = null;
|
98
|
+
let region = null;
|
99
|
+
let irisSeqID = null;
|
100
|
+
var noMqttData = null;
|
101
|
+
|
102
|
+
if (oldFBMQTTMatch) {
|
103
|
+
irisSeqID = oldFBMQTTMatch[1];
|
104
|
+
mqttEndpoint = oldFBMQTTMatch[2];
|
105
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
106
|
+
//log.info("login", `Got this account's message region: ${region}`);
|
107
|
+
} else {
|
108
|
+
let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
|
109
|
+
if (newFBMQTTMatch) {
|
110
|
+
irisSeqID = newFBMQTTMatch[2];
|
111
|
+
mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
|
112
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
113
|
+
// log.info("login", `Got this account's message region: ${region}`);
|
114
|
+
} else {
|
115
|
+
let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
|
116
|
+
if (legacyFBMQTTMatch) {
|
117
|
+
mqttEndpoint = legacyFBMQTTMatch[4];
|
118
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
119
|
+
/* log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
|
120
|
+
log.info("login", `Got this account's message region: ${region}`);
|
121
|
+
log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);*/
|
122
|
+
} else {
|
123
|
+
log.warn("login", "Cannot get MQTT region & sequence ID.");
|
124
|
+
noMqttData = html;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
// All data available to api functions
|
130
|
+
var ctx = {
|
131
|
+
userID: userID,
|
132
|
+
jar: jar,
|
133
|
+
clientID: clientID,
|
134
|
+
globalOptions: globalOptions,
|
135
|
+
loggedIn: true,
|
136
|
+
access_token: 'NONE',
|
137
|
+
clientMutationId: 0,
|
138
|
+
mqttClient: undefined,
|
139
|
+
lastSeqId: irisSeqID,
|
140
|
+
syncToken: undefined,
|
141
|
+
mqttEndpoint,
|
142
|
+
region,
|
143
|
+
firstListen: true
|
144
|
+
};
|
145
|
+
|
146
|
+
var api = {
|
147
|
+
setOptions: setOptions.bind(null, globalOptions),
|
148
|
+
getAppState: function getAppState() {
|
149
|
+
return utils.getAppState(jar);
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
if (noMqttData) {
|
154
|
+
api["htmlData"] = noMqttData;
|
155
|
+
}
|
156
|
+
|
157
|
+
const apiFuncNames = [
|
158
|
+
'addExternalModule',
|
159
|
+
'addUserToGroup',
|
160
|
+
'changeAdminStatus',
|
161
|
+
'changeArchivedStatus',
|
162
|
+
'changeBio',
|
163
|
+
'changeBlockedStatus',
|
164
|
+
'changeGroupImage',
|
165
|
+
'changeNickname',
|
166
|
+
'changeThreadColor',
|
167
|
+
'changeThreadEmoji',
|
168
|
+
'createNewGroup',
|
169
|
+
'createPoll',
|
170
|
+
'deleteMessage',
|
171
|
+
'deleteThread',
|
172
|
+
'forwardAttachment',
|
173
|
+
'getCurrentUserID',
|
174
|
+
'getEmojiUrl',
|
175
|
+
'getFriendsList',
|
176
|
+
'getThreadHistory',
|
177
|
+
'getThreadInfo',
|
178
|
+
'getThreadList',
|
179
|
+
'getThreadPictures',
|
180
|
+
'getUserID',
|
181
|
+
'getUserInfo',
|
182
|
+
'handleMessageRequest',
|
183
|
+
'listenMqtt',
|
184
|
+
'logout',
|
185
|
+
'markAsDelivered',
|
186
|
+
'markAsRead',
|
187
|
+
'markAsReadAll',
|
188
|
+
'markAsSeen',
|
189
|
+
'muteThread',
|
190
|
+
'removeUserFromGroup',
|
191
|
+
'resolvePhotoUrl',
|
192
|
+
'searchForThread',
|
193
|
+
'chat',
|
194
|
+
'sendTypingIndicator',
|
195
|
+
'setMessageReaction',
|
196
|
+
'setTitle',
|
197
|
+
'threadColors',
|
198
|
+
'unsendMessage',
|
199
|
+
|
200
|
+
// HTTP
|
201
|
+
'httpGet',
|
202
|
+
'httpPost',
|
203
|
+
|
204
|
+
// Deprecated features
|
205
|
+
"getThreadListDeprecated",
|
206
|
+
'getThreadHistoryDeprecated',
|
207
|
+
'getThreadInfoDeprecated',
|
208
|
+
];
|
209
|
+
|
210
|
+
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
211
|
+
|
212
|
+
// Load all api functions in a loop
|
213
|
+
apiFuncNames.map(function (v) {
|
214
|
+
api[v] = require('./leiamnash/' + v)(defaultFuncs, api, ctx);
|
215
|
+
});
|
216
|
+
|
217
|
+
//Removing original `listen` that uses pull.
|
218
|
+
//Map it to listenMqtt instead for backward compatibly.
|
219
|
+
api.listen = api.listenMqtt;
|
220
|
+
|
221
|
+
return [ctx, defaultFuncs, api];
|
222
|
+
}
|
223
|
+
|
224
|
+
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
225
|
+
return function (res) {
|
226
|
+
var html = res.body;
|
227
|
+
var $ = cheerio.load(html);
|
228
|
+
var arr = [];
|
229
|
+
|
230
|
+
// This will be empty, but just to be sure we leave it
|
231
|
+
$("#login_form input").map(function (i, v) {
|
232
|
+
arr.push({ val: $(v).val(), name: $(v).attr("name") });
|
233
|
+
});
|
234
|
+
|
235
|
+
arr = arr.filter(function (v) {
|
236
|
+
return v.val && v.val.length;
|
237
|
+
});
|
238
|
+
|
239
|
+
var form = utils.arrToForm(arr);
|
240
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
241
|
+
form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
|
242
|
+
form.email = email;
|
243
|
+
form.pass = password;
|
244
|
+
form.default_persistent = '0';
|
245
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
246
|
+
form.locale = 'en_US';
|
247
|
+
form.timezone = '240';
|
248
|
+
form.lgnjs = ~~(Date.now() / 1000);
|
249
|
+
|
250
|
+
|
251
|
+
// Getting cookies from the HTML page... (kill me now plz)
|
252
|
+
// we used to get a bunch of cookies in the headers of the response of the
|
253
|
+
// request, but FB changed and they now send those cookies inside the JS.
|
254
|
+
// They run the JS which then injects the cookies in the page.
|
255
|
+
// The "solution" is to parse through the html and find those cookies
|
256
|
+
// which happen to be conveniently indicated with a _js_ in front of their
|
257
|
+
// variable name.
|
258
|
+
//
|
259
|
+
// ---------- Very Hacky Part Starts -----------------
|
260
|
+
var willBeCookies = html.split("\"_js_");
|
261
|
+
willBeCookies.slice(1).map(function (val) {
|
262
|
+
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
263
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
264
|
+
});
|
265
|
+
// ---------- Very Hacky Part Ends -----------------
|
266
|
+
|
267
|
+
// log.info("login", "Logging in...");
|
268
|
+
return utils
|
269
|
+
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
270
|
+
.then(utils.saveCookies(jar))
|
271
|
+
.then(function (res) {
|
272
|
+
var headers = res.headers;
|
273
|
+
if (!headers.location) {
|
274
|
+
throw { error: "Wrong username/password." };
|
275
|
+
}
|
276
|
+
|
277
|
+
// This means the account has login approvals turned on.
|
278
|
+
if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
|
279
|
+
log.info("login", "You have login approvals turned on.");
|
280
|
+
var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
|
281
|
+
|
282
|
+
return utils
|
283
|
+
.get(headers.location, jar, null, loginOptions)
|
284
|
+
.then(utils.saveCookies(jar))
|
285
|
+
.then(function (res) {
|
286
|
+
var html = res.body;
|
287
|
+
// Make the form in advance which will contain the fb_dtsg and nh
|
288
|
+
var $ = cheerio.load(html);
|
289
|
+
var arr = [];
|
290
|
+
$("form input").map(function (i, v) {
|
291
|
+
arr.push({ val: $(v).val(), name: $(v).attr("name") });
|
292
|
+
});
|
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) => {
|
302
|
+
/* utils
|
303
|
+
.post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
|
304
|
+
"Referer": "https://www.facebook.com/checkpoint/?next"
|
305
|
+
})
|
306
|
+
.then(utils.saveCookies(jar))
|
307
|
+
.then(res => {
|
308
|
+
try {
|
309
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
|
310
|
+
} catch (ex) {
|
311
|
+
clearInterval(checkVerified);
|
312
|
+
log.info("login", "Verified from browser. Logging in...");
|
313
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
314
|
+
}
|
315
|
+
})
|
316
|
+
.catch(ex => {
|
317
|
+
log.error("login", ex);
|
318
|
+
}); */
|
319
|
+
}, 5000, {
|
320
|
+
fb_dtsg: form.fb_dtsg,
|
321
|
+
jazoest: form.jazoest,
|
322
|
+
dpr: 1
|
323
|
+
});
|
324
|
+
}, 2500);
|
325
|
+
throw {
|
326
|
+
error: 'login-approval',
|
327
|
+
continue: function submit2FA(code) {
|
328
|
+
form.approvals_code = code;
|
329
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
330
|
+
var prResolve = null;
|
331
|
+
var prReject = null;
|
332
|
+
var rtPromise = new Promise(function (resolve, reject) {
|
333
|
+
prResolve = resolve;
|
334
|
+
prReject = reject;
|
335
|
+
});
|
336
|
+
if (typeof code == "string") {
|
337
|
+
utils
|
338
|
+
.post(nextURL, jar, form, loginOptions)
|
339
|
+
.then(utils.saveCookies(jar))
|
340
|
+
.then(function (res) {
|
341
|
+
var $ = cheerio.load(res.body);
|
342
|
+
var error = $("#approvals_code").parent().attr("data-xui-error");
|
343
|
+
if (error) {
|
344
|
+
throw {
|
345
|
+
error: 'login-approval',
|
346
|
+
errordesc: "Invalid 2FA code.",
|
347
|
+
lerror: error,
|
348
|
+
continue: submit2FA
|
349
|
+
};
|
350
|
+
}
|
351
|
+
})
|
352
|
+
.then(function () {
|
353
|
+
// Use the same form (safe I hope)
|
354
|
+
delete form.no_fido;
|
355
|
+
delete form.approvals_code;
|
356
|
+
form.name_action_selected = 'dont_save'; //'save_device';
|
357
|
+
|
358
|
+
return utils
|
359
|
+
.post(nextURL, jar, form, loginOptions)
|
360
|
+
.then(utils.saveCookies(jar));
|
361
|
+
})
|
362
|
+
.then(function (res) {
|
363
|
+
var headers = res.headers;
|
364
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
365
|
+
throw { error: "Something went wrong with login approvals." };
|
366
|
+
}
|
367
|
+
|
368
|
+
var appState = utils.getAppState(jar);
|
369
|
+
|
370
|
+
if (callback === prCallback) {
|
371
|
+
callback = function (err, api) {
|
372
|
+
if (err) {
|
373
|
+
return prReject(err);
|
374
|
+
}
|
375
|
+
return prResolve(api);
|
376
|
+
};
|
377
|
+
}
|
378
|
+
|
379
|
+
// Simply call loginHelper because all it needs is the jar
|
380
|
+
// and will then complete the login process
|
381
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
382
|
+
})
|
383
|
+
.catch(function (err) {
|
384
|
+
// Check if using Promise instead of callback
|
385
|
+
if (callback === prCallback) {
|
386
|
+
prReject(err);
|
387
|
+
} else {
|
388
|
+
callback(err);
|
389
|
+
}
|
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, {
|
394
|
+
"Referer": "https://www.facebook.com/checkpoint/?next"
|
395
|
+
})
|
396
|
+
.then(utils.saveCookies(jar))
|
397
|
+
.then(res => {
|
398
|
+
try {
|
399
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
400
|
+
} catch (ex) {
|
401
|
+
clearInterval(checkVerified);
|
402
|
+
//log.info("login", "Verified from browser. Logging in...");
|
403
|
+
if (callback === prCallback) {
|
404
|
+
callback = function (err, api) {
|
405
|
+
if (err) {
|
406
|
+
return prReject(err);
|
407
|
+
}
|
408
|
+
return prResolve(api);
|
409
|
+
};
|
410
|
+
}
|
411
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
412
|
+
}
|
413
|
+
})
|
414
|
+
.catch(ex => {
|
415
|
+
log.error("login", ex);
|
416
|
+
if (callback === prCallback) {
|
417
|
+
prReject(ex);
|
418
|
+
} else {
|
419
|
+
callback(ex);
|
420
|
+
}
|
421
|
+
});
|
422
|
+
}
|
423
|
+
return rtPromise;
|
424
|
+
}
|
425
|
+
};
|
426
|
+
} else {
|
427
|
+
if (!loginOptions.forceLogin) {
|
428
|
+
throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
|
429
|
+
}
|
430
|
+
if (html.indexOf("Suspicious Login Attempt") > -1) {
|
431
|
+
form['submit[This was me]'] = "This was me";
|
432
|
+
} else {
|
433
|
+
form['submit[This Is Okay]'] = "This Is Okay";
|
434
|
+
}
|
435
|
+
|
436
|
+
return utils
|
437
|
+
.post(nextURL, jar, form, loginOptions)
|
438
|
+
.then(utils.saveCookies(jar))
|
439
|
+
.then(function () {
|
440
|
+
// Use the same form (safe I hope)
|
441
|
+
form.name_action_selected = 'save_device';
|
442
|
+
|
443
|
+
return utils
|
444
|
+
.post(nextURL, jar, form, loginOptions)
|
445
|
+
.then(utils.saveCookies(jar));
|
446
|
+
})
|
447
|
+
.then(function (res) {
|
448
|
+
var headers = res.headers;
|
449
|
+
|
450
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
451
|
+
throw { error: "Something went wrong with review recent login." };
|
452
|
+
}
|
453
|
+
|
454
|
+
var appState = utils.getAppState(jar);
|
455
|
+
|
456
|
+
// Simply call loginHelper because all it needs is the jar
|
457
|
+
// and will then complete the login process
|
458
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
459
|
+
})
|
460
|
+
.catch(function (e) {
|
461
|
+
callback(e);
|
462
|
+
});
|
463
|
+
}
|
464
|
+
});
|
465
|
+
}
|
466
|
+
|
467
|
+
return utils
|
468
|
+
.get('https://www.facebook.com/', jar, null, loginOptions)
|
469
|
+
.then(utils.saveCookies(jar));
|
470
|
+
});
|
471
|
+
};
|
472
|
+
}
|
473
|
+
|
474
|
+
// Helps the login
|
475
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
476
|
+
var mainPromise = null;
|
477
|
+
var jar = utils.getJar();
|
478
|
+
|
479
|
+
// If we're given an appState we loop through it and save each cookie
|
480
|
+
// back into the jar.
|
481
|
+
if (appState) {
|
482
|
+
appState.map(function (c) {
|
483
|
+
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
484
|
+
jar.setCookie(str, "http://" + c.domain);
|
485
|
+
});
|
486
|
+
|
487
|
+
// Load the main page.
|
488
|
+
mainPromise = utils
|
489
|
+
.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
|
490
|
+
.then(utils.saveCookies(jar));
|
491
|
+
} else {
|
492
|
+
// Open the main page, then we login with the given credentials and finally
|
493
|
+
// load the main page again (it'll give us some IDs that we need)
|
494
|
+
mainPromise = utils
|
495
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
496
|
+
.then(utils.saveCookies(jar))
|
497
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
498
|
+
.then(function () {
|
499
|
+
return utils
|
500
|
+
.get('https://www.facebook.com/', jar, null, globalOptions)
|
501
|
+
.then(utils.saveCookies(jar));
|
502
|
+
});
|
503
|
+
}
|
504
|
+
|
505
|
+
var ctx = null;
|
506
|
+
var _defaultFuncs = null;
|
507
|
+
var api = null;
|
508
|
+
|
509
|
+
mainPromise = mainPromise
|
510
|
+
.then(function (res) {
|
511
|
+
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
512
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
513
|
+
var redirect = reg.exec(res.body);
|
514
|
+
if (redirect && redirect[1]) {
|
515
|
+
return utils
|
516
|
+
.get(redirect[1], jar, null, globalOptions)
|
517
|
+
.then(utils.saveCookies(jar));
|
518
|
+
}
|
519
|
+
return res;
|
520
|
+
})
|
521
|
+
.then(function (res) {
|
522
|
+
var html = res.body;
|
523
|
+
var stuff = buildAPI(globalOptions, html, jar);
|
524
|
+
ctx = stuff[0];
|
525
|
+
_defaultFuncs = stuff[1];
|
526
|
+
api = stuff[2];
|
527
|
+
return res;
|
528
|
+
});
|
529
|
+
|
530
|
+
// given a pageID we log in as a page
|
531
|
+
if (globalOptions.pageID) {
|
532
|
+
mainPromise = mainPromise
|
533
|
+
.then(function () {
|
534
|
+
return utils
|
535
|
+
.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
536
|
+
})
|
537
|
+
.then(function (resData) {
|
538
|
+
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
539
|
+
url = url.substring(0, url.length - 1);
|
540
|
+
|
541
|
+
return utils
|
542
|
+
.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
543
|
+
});
|
544
|
+
}
|
545
|
+
|
546
|
+
// At the end we call the callback or catch an exception
|
547
|
+
mainPromise
|
548
|
+
.then(function () {
|
549
|
+
// log.info("login", 'Done logging in.');
|
550
|
+
return callback(null, api);
|
551
|
+
})
|
552
|
+
.catch(function (e) {
|
553
|
+
log.error("login", e.error || e);
|
554
|
+
callback(e);
|
555
|
+
});
|
556
|
+
}
|
557
|
+
|
558
|
+
function login(loginData, options, callback) {
|
559
|
+
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
560
|
+
callback = options;
|
561
|
+
options = {};
|
562
|
+
}
|
563
|
+
|
564
|
+
var globalOptions = {
|
565
|
+
selfListen: false,
|
566
|
+
listenEvents: false,
|
567
|
+
listenTyping: false,
|
568
|
+
updatePresence: false,
|
569
|
+
forceLogin: false,
|
570
|
+
autoMarkDelivery: true,
|
571
|
+
autoMarkRead: false,
|
572
|
+
autoReconnect: true,
|
573
|
+
logRecordSize: defaultLogRecordSize,
|
574
|
+
online: true,
|
575
|
+
emitReady: false,
|
576
|
+
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 [FBAN/FBIOS;FBAV/68.0.0.49.70;FBBV/41924288;FBRV/0;FBDV/iPhone9,4;FBMD/iPhone;FBSN/iOS;FBSV/9.3.5;FBSS/2;FBCR/carrier;FBID/phone;FBLC/en_US;FBOP/5]"
|
577
|
+
};
|
578
|
+
|
579
|
+
setOptions(globalOptions, options);
|
580
|
+
|
581
|
+
var prCallback = null;
|
582
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
583
|
+
var rejectFunc = null;
|
584
|
+
var resolveFunc = null;
|
585
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
586
|
+
resolveFunc = resolve;
|
587
|
+
rejectFunc = reject;
|
588
|
+
});
|
589
|
+
prCallback = function (error, api) {
|
590
|
+
if (error) {
|
591
|
+
return rejectFunc(error);
|
592
|
+
}
|
593
|
+
return resolveFunc(api);
|
594
|
+
};
|
595
|
+
callback = prCallback;
|
596
|
+
}
|
597
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
598
|
+
return returnPromise;
|
599
|
+
}
|
600
|
+
|
601
|
+
module.exports = login;
|