alicezetion 1.6.2 → 1.6.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/index.js +104 -284
- package/package.json +1 -1
- package/utils.js +1282 -1356
@@ -1 +1 @@
|
|
1
|
-
{"nonce":
|
1
|
+
{"nonce":2713507693407859680,"last_updated":{"seconds":1693627168,"nanos":391066000}}
|
package/index.js
CHANGED
@@ -4,17 +4,12 @@ var utils = require("./utils");
|
|
4
4
|
var cheerio = require("cheerio");
|
5
5
|
var log = require("npmlog");
|
6
6
|
|
7
|
-
var checkVerified = null;
|
8
|
-
|
9
7
|
var defaultLogRecordSize = 100;
|
10
8
|
log.maxRecordSize = defaultLogRecordSize;
|
11
9
|
|
12
10
|
function setOptions(globalOptions, options) {
|
13
|
-
Object.keys(options).map(function
|
11
|
+
Object.keys(options).map(function(key) {
|
14
12
|
switch (key) {
|
15
|
-
case 'online':
|
16
|
-
globalOptions.online = Boolean(options.online);
|
17
|
-
break;
|
18
13
|
case 'logLevel':
|
19
14
|
log.level = options.logLevel;
|
20
15
|
globalOptions.logLevel = options.logLevel;
|
@@ -24,46 +19,28 @@ function setOptions(globalOptions, options) {
|
|
24
19
|
globalOptions.logRecordSize = options.logRecordSize;
|
25
20
|
break;
|
26
21
|
case 'selfListen':
|
27
|
-
globalOptions.selfListen =
|
22
|
+
globalOptions.selfListen = options.selfListen;
|
28
23
|
break;
|
29
24
|
case 'listenEvents':
|
30
|
-
globalOptions.listenEvents =
|
25
|
+
globalOptions.listenEvents = options.listenEvents;
|
31
26
|
break;
|
32
27
|
case 'pageID':
|
33
28
|
globalOptions.pageID = options.pageID.toString();
|
34
29
|
break;
|
35
30
|
case 'updatePresence':
|
36
|
-
globalOptions.updatePresence =
|
31
|
+
globalOptions.updatePresence = options.updatePresence;
|
37
32
|
break;
|
38
33
|
case 'forceLogin':
|
39
|
-
globalOptions.forceLogin =
|
34
|
+
globalOptions.forceLogin = options.forceLogin;
|
40
35
|
break;
|
41
36
|
case 'userAgent':
|
42
37
|
globalOptions.userAgent = options.userAgent;
|
43
38
|
break;
|
44
39
|
case 'autoMarkDelivery':
|
45
|
-
globalOptions.autoMarkDelivery =
|
40
|
+
globalOptions.autoMarkDelivery = options.autoMarkDelivery;
|
46
41
|
break;
|
47
42
|
case 'autoMarkRead':
|
48
|
-
globalOptions.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);
|
43
|
+
globalOptions.autoMarkRead = options.autoMarkRead;
|
67
44
|
break;
|
68
45
|
default:
|
69
46
|
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
@@ -73,61 +50,18 @@ function setOptions(globalOptions, options) {
|
|
73
50
|
}
|
74
51
|
|
75
52
|
function buildAPI(globalOptions, html, jar) {
|
76
|
-
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function
|
53
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
|
77
54
|
return val.cookieString().split("=")[0] === "c_user";
|
78
55
|
});
|
79
56
|
|
80
|
-
if
|
81
|
-
throw {
|
82
|
-
}
|
83
|
-
|
84
|
-
if (html.indexOf("/checkpoint/block/?next") > -1) {
|
85
|
-
log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
|
57
|
+
if(maybeCookie.length === 0) {
|
58
|
+
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."};
|
86
59
|
}
|
87
60
|
|
88
61
|
var userID = maybeCookie[0].cookieString().split("=")[1].toString();
|
89
|
-
|
90
|
-
|
91
|
-
try {
|
92
|
-
clearInterval(checkVerified);
|
93
|
-
} catch (_) { }
|
94
|
-
|
62
|
+
//log.info("login", "Logged in");
|
95
63
|
var clientID = (Math.random() * 2147483648 | 0).toString(16);
|
96
64
|
|
97
|
-
|
98
|
-
let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
|
99
|
-
let mqttEndpoint = null;
|
100
|
-
let region = null;
|
101
|
-
let irisSeqID = null;
|
102
|
-
var noMqttData = null;
|
103
|
-
|
104
|
-
if (oldFBMQTTMatch) {
|
105
|
-
irisSeqID = oldFBMQTTMatch[1];
|
106
|
-
mqttEndpoint = oldFBMQTTMatch[2];
|
107
|
-
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
108
|
-
log.info("login", `Got this account's message region: ${region}`);
|
109
|
-
} else {
|
110
|
-
let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
|
111
|
-
if (newFBMQTTMatch) {
|
112
|
-
irisSeqID = newFBMQTTMatch[2];
|
113
|
-
mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
|
114
|
-
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
115
|
-
log.info("login", `Got this account's message region: ${region}`);
|
116
|
-
} else {
|
117
|
-
let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
|
118
|
-
if (legacyFBMQTTMatch) {
|
119
|
-
mqttEndpoint = legacyFBMQTTMatch[4];
|
120
|
-
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
121
|
-
log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
|
122
|
-
log.info("login", `Got this account's message region: ${region}`);
|
123
|
-
log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
|
124
|
-
} else {
|
125
|
-
log.warn("login", "Cannot get MQTT region & sequence ID.");
|
126
|
-
noMqttData = html;
|
127
|
-
}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
65
|
// All data available to api functions
|
132
66
|
var ctx = {
|
133
67
|
userID: userID,
|
@@ -138,36 +72,26 @@ function buildAPI(globalOptions, html, jar) {
|
|
138
72
|
access_token: 'NONE',
|
139
73
|
clientMutationId: 0,
|
140
74
|
mqttClient: undefined,
|
141
|
-
lastSeqId:
|
142
|
-
syncToken: undefined
|
143
|
-
mqttEndpoint,
|
144
|
-
region,
|
145
|
-
firstListen: true
|
75
|
+
lastSeqId: 0,
|
76
|
+
syncToken: undefined
|
146
77
|
};
|
147
78
|
|
148
79
|
var api = {
|
149
80
|
setOptions: setOptions.bind(null, globalOptions),
|
150
81
|
getAppState: function getAppState() {
|
151
82
|
return utils.getAppState(jar);
|
152
|
-
}
|
83
|
+
},
|
153
84
|
};
|
154
85
|
|
155
|
-
if (noMqttData) {
|
156
|
-
api["htmlData"] = noMqttData;
|
157
|
-
}
|
158
|
-
|
159
86
|
const apiFuncNames = [
|
160
|
-
'addExternalModule',
|
161
87
|
'addUserToGroup',
|
162
88
|
'changeAdminStatus',
|
163
89
|
'changeArchivedStatus',
|
164
|
-
'changeBio',
|
165
90
|
'changeBlockedStatus',
|
166
91
|
'changeGroupImage',
|
167
92
|
'changeNickname',
|
168
93
|
'changeThreadColor',
|
169
94
|
'changeThreadEmoji',
|
170
|
-
'createNewGroup',
|
171
95
|
'createPoll',
|
172
96
|
'deleteMessage',
|
173
97
|
'deleteThread',
|
@@ -187,54 +111,46 @@ function buildAPI(globalOptions, html, jar) {
|
|
187
111
|
'markAsDelivered',
|
188
112
|
'markAsRead',
|
189
113
|
'markAsReadAll',
|
190
|
-
'markAsSeen',
|
191
114
|
'muteThread',
|
192
115
|
'removeUserFromGroup',
|
193
116
|
'resolvePhotoUrl',
|
194
|
-
'searchForThread',
|
195
117
|
'chat',
|
118
|
+
'sendMessage',
|
196
119
|
'sendTypingIndicator',
|
197
120
|
'setMessageReaction',
|
198
121
|
'setTitle',
|
199
122
|
'threadColors',
|
200
123
|
'unsendMessage',
|
201
124
|
|
202
|
-
// HTTP
|
203
|
-
'httpGet',
|
204
|
-
'httpPost',
|
205
|
-
|
206
125
|
// Deprecated features
|
207
126
|
"getThreadListDeprecated",
|
208
127
|
'getThreadHistoryDeprecated',
|
209
128
|
'getThreadInfoDeprecated',
|
129
|
+
'listen'
|
210
130
|
];
|
211
131
|
|
212
132
|
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
213
133
|
|
214
134
|
// Load all api functions in a loop
|
215
|
-
apiFuncNames.map(function
|
216
|
-
api[v] = require('./
|
135
|
+
apiFuncNames.map(function(v) {
|
136
|
+
api[v] = require('./leiamnash/' + v)(defaultFuncs, api, ctx);
|
217
137
|
});
|
218
138
|
|
219
|
-
//Removing original `listen` that uses pull.
|
220
|
-
//Map it to listenMqtt instead for backward compatibly.
|
221
|
-
api.listen = api.listenMqtt;
|
222
|
-
|
223
139
|
return [ctx, defaultFuncs, api];
|
224
140
|
}
|
225
141
|
|
226
|
-
function makeLogin(jar, email, password, loginOptions, callback
|
227
|
-
return function
|
142
|
+
function makeLogin(jar, email, password, loginOptions, callback) {
|
143
|
+
return function(res) {
|
228
144
|
var html = res.body;
|
229
145
|
var $ = cheerio.load(html);
|
230
146
|
var arr = [];
|
231
147
|
|
232
148
|
// This will be empty, but just to be sure we leave it
|
233
|
-
$("#login_form input").map(function
|
234
|
-
arr.push({
|
149
|
+
$("#login_form input").map(function(i, v){
|
150
|
+
arr.push({val: $(v).val(), name: $(v).attr("name")});
|
235
151
|
});
|
236
152
|
|
237
|
-
arr = arr.filter(function
|
153
|
+
arr = arr.filter(function(v) {
|
238
154
|
return v.val && v.val.length;
|
239
155
|
});
|
240
156
|
|
@@ -260,20 +176,20 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
260
176
|
//
|
261
177
|
// ---------- Very Hacky Part Starts -----------------
|
262
178
|
var willBeCookies = html.split("\"_js_");
|
263
|
-
willBeCookies.slice(1).map(function
|
179
|
+
willBeCookies.slice(1).map(function(val) {
|
264
180
|
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
265
181
|
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
266
182
|
});
|
267
183
|
// ---------- Very Hacky Part Ends -----------------
|
268
184
|
|
269
|
-
log.info("login", "Logging in...");
|
185
|
+
//log.info("login", "Logging in...");
|
270
186
|
return utils
|
271
|
-
.post("https://www.facebook.com/login
|
187
|
+
.post("https://www.facebook.com/login.php?login_attempt=1&lwv=110", jar, form, loginOptions)
|
272
188
|
.then(utils.saveCookies(jar))
|
273
|
-
.then(function
|
189
|
+
.then(function(res) {
|
274
190
|
var headers = res.headers;
|
275
191
|
if (!headers.location) {
|
276
|
-
throw {
|
192
|
+
throw {error: "Wrong username/password."};
|
277
193
|
}
|
278
194
|
|
279
195
|
// This means the account has login approvals turned on.
|
@@ -284,150 +200,57 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
284
200
|
return utils
|
285
201
|
.get(headers.location, jar, null, loginOptions)
|
286
202
|
.then(utils.saveCookies(jar))
|
287
|
-
.then(function
|
203
|
+
.then(function(res) {
|
288
204
|
var html = res.body;
|
289
205
|
// Make the form in advance which will contain the fb_dtsg and nh
|
290
206
|
var $ = cheerio.load(html);
|
291
207
|
var arr = [];
|
292
|
-
$("form input").map(function
|
293
|
-
arr.push({
|
208
|
+
$("form input").map(function(i, v){
|
209
|
+
arr.push({val: $(v).val(), name: $(v).attr("name")});
|
294
210
|
});
|
295
211
|
|
296
|
-
arr = arr.filter(function
|
212
|
+
arr = arr.filter(function(v) {
|
297
213
|
return v.val && v.val.length;
|
298
214
|
});
|
299
215
|
|
300
216
|
var form = utils.arrToForm(arr);
|
301
217
|
if (html.indexOf("checkpoint/?next") > -1) {
|
302
|
-
setTimeout(() => {
|
303
|
-
checkVerified = setInterval((_form) => {
|
304
|
-
/* utils
|
305
|
-
.post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
|
306
|
-
"Referer": "https://www.facebook.com/checkpoint/?next"
|
307
|
-
})
|
308
|
-
.then(utils.saveCookies(jar))
|
309
|
-
.then(res => {
|
310
|
-
try {
|
311
|
-
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
|
312
|
-
} catch (ex) {
|
313
|
-
clearInterval(checkVerified);
|
314
|
-
log.info("login", "Verified from browser. Logging in...");
|
315
|
-
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
316
|
-
}
|
317
|
-
})
|
318
|
-
.catch(ex => {
|
319
|
-
log.error("login", ex);
|
320
|
-
}); */
|
321
|
-
}, 5000, {
|
322
|
-
fb_dtsg: form.fb_dtsg,
|
323
|
-
jazoest: form.jazoest,
|
324
|
-
dpr: 1
|
325
|
-
});
|
326
|
-
}, 2500);
|
327
218
|
throw {
|
328
219
|
error: 'login-approval',
|
329
|
-
continue: function
|
220
|
+
continue: function(code) {
|
330
221
|
form.approvals_code = code;
|
331
|
-
form['submit[Continue]'] =
|
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
|
-
form.name_action_selected = 'dont_save'; //'save_device';
|
359
|
-
|
360
|
-
return utils
|
361
|
-
.post(nextURL, jar, form, loginOptions)
|
362
|
-
.then(utils.saveCookies(jar));
|
363
|
-
})
|
364
|
-
.then(function (res) {
|
365
|
-
var headers = res.headers;
|
366
|
-
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
367
|
-
throw { error: "Something went wrong with login approvals." };
|
368
|
-
}
|
369
|
-
|
370
|
-
var appState = utils.getAppState(jar);
|
371
|
-
|
372
|
-
if (callback === prCallback) {
|
373
|
-
callback = function (err, api) {
|
374
|
-
if (err) {
|
375
|
-
return prReject(err);
|
376
|
-
}
|
377
|
-
return prResolve(api);
|
378
|
-
};
|
379
|
-
}
|
380
|
-
|
381
|
-
// Simply call loginHelper because all it needs is the jar
|
382
|
-
// and will then complete the login process
|
383
|
-
return loginHelper(appState, email, password, loginOptions, callback);
|
384
|
-
})
|
385
|
-
.catch(function (err) {
|
386
|
-
// Check if using Promise instead of callback
|
387
|
-
if (callback === prCallback) {
|
388
|
-
prReject(err);
|
389
|
-
} else {
|
390
|
-
callback(err);
|
391
|
-
}
|
392
|
-
});
|
393
|
-
} else {
|
394
|
-
utils
|
395
|
-
.post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, {
|
396
|
-
"Referer": "https://www.facebook.com/checkpoint/?next"
|
397
|
-
})
|
398
|
-
.then(utils.saveCookies(jar))
|
399
|
-
.then(res => {
|
400
|
-
try {
|
401
|
-
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
402
|
-
} catch (ex) {
|
403
|
-
clearInterval(checkVerified);
|
404
|
-
log.info("login", "Verified from browser. Logging in...");
|
405
|
-
if (callback === prCallback) {
|
406
|
-
callback = function (err, api) {
|
407
|
-
if (err) {
|
408
|
-
return prReject(err);
|
409
|
-
}
|
410
|
-
return prResolve(api);
|
411
|
-
};
|
412
|
-
}
|
413
|
-
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
414
|
-
}
|
415
|
-
})
|
416
|
-
.catch(ex => {
|
417
|
-
log.error("login", ex);
|
418
|
-
if (callback === prCallback) {
|
419
|
-
prReject(ex);
|
420
|
-
} else {
|
421
|
-
callback(ex);
|
422
|
-
}
|
423
|
-
});
|
424
|
-
}
|
425
|
-
return rtPromise;
|
222
|
+
form['submit[Continue]'] = 'Continue';
|
223
|
+
return utils
|
224
|
+
.post(nextURL, jar, form, loginOptions)
|
225
|
+
.then(utils.saveCookies(jar))
|
226
|
+
.then(function() {
|
227
|
+
// Use the same form (safe I hope)
|
228
|
+
form.name_action_selected = 'save_device';
|
229
|
+
|
230
|
+
return utils
|
231
|
+
.post(nextURL, jar, form, loginOptions)
|
232
|
+
.then(utils.saveCookies(jar));
|
233
|
+
})
|
234
|
+
.then(function(res) {
|
235
|
+
var headers = res.headers;
|
236
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
237
|
+
throw {error: "Something went wrong with login approvals."};
|
238
|
+
}
|
239
|
+
|
240
|
+
var appState = utils.getAppState(jar);
|
241
|
+
|
242
|
+
// Simply call loginHelper because all it needs is the jar
|
243
|
+
// and will then complete the login process
|
244
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
245
|
+
})
|
246
|
+
.catch(function(err) {
|
247
|
+
callback(err);
|
248
|
+
});
|
426
249
|
}
|
427
250
|
};
|
428
251
|
} else {
|
429
252
|
if (!loginOptions.forceLogin) {
|
430
|
-
throw {
|
253
|
+
throw {error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again."};
|
431
254
|
}
|
432
255
|
if (html.indexOf("Suspicious Login Attempt") > -1) {
|
433
256
|
form['submit[This was me]'] = "This was me";
|
@@ -438,7 +261,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
438
261
|
return utils
|
439
262
|
.post(nextURL, jar, form, loginOptions)
|
440
263
|
.then(utils.saveCookies(jar))
|
441
|
-
.then(function
|
264
|
+
.then(function() {
|
442
265
|
// Use the same form (safe I hope)
|
443
266
|
form.name_action_selected = 'save_device';
|
444
267
|
|
@@ -446,11 +269,11 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
446
269
|
.post(nextURL, jar, form, loginOptions)
|
447
270
|
.then(utils.saveCookies(jar));
|
448
271
|
})
|
449
|
-
.then(function
|
272
|
+
.then(function(res) {
|
450
273
|
var headers = res.headers;
|
451
274
|
|
452
275
|
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
|
453
|
-
throw {
|
276
|
+
throw {error: "Something went wrong with review recent login."};
|
454
277
|
}
|
455
278
|
|
456
279
|
var appState = utils.getAppState(jar);
|
@@ -459,7 +282,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
459
282
|
// and will then complete the login process
|
460
283
|
return loginHelper(appState, email, password, loginOptions, callback);
|
461
284
|
})
|
462
|
-
.catch(function
|
285
|
+
.catch(function(e) {
|
463
286
|
callback(e);
|
464
287
|
});
|
465
288
|
}
|
@@ -474,30 +297,30 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
474
297
|
}
|
475
298
|
|
476
299
|
// Helps the login
|
477
|
-
function loginHelper(appState, email, password, globalOptions, callback
|
300
|
+
function loginHelper(appState, email, password, globalOptions, callback) {
|
478
301
|
var mainPromise = null;
|
479
302
|
var jar = utils.getJar();
|
480
303
|
|
481
304
|
// If we're given an appState we loop through it and save each cookie
|
482
305
|
// back into the jar.
|
483
|
-
if
|
484
|
-
appState.map(function
|
306
|
+
if(appState) {
|
307
|
+
appState.map(function(c) {
|
485
308
|
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
486
309
|
jar.setCookie(str, "http://" + c.domain);
|
487
310
|
});
|
488
311
|
|
489
312
|
// Load the main page.
|
490
313
|
mainPromise = utils
|
491
|
-
.get('https://www.facebook.com/', jar, null, globalOptions
|
314
|
+
.get('https://www.facebook.com/', jar, null, globalOptions)
|
492
315
|
.then(utils.saveCookies(jar));
|
493
316
|
} else {
|
494
317
|
// Open the main page, then we login with the given credentials and finally
|
495
318
|
// load the main page again (it'll give us some IDs that we need)
|
496
319
|
mainPromise = utils
|
497
|
-
.get("https://www.facebook.com/", null, null, globalOptions
|
320
|
+
.get("https://www.facebook.com/", null, null, globalOptions)
|
498
321
|
.then(utils.saveCookies(jar))
|
499
|
-
.then(makeLogin(jar, email, password, globalOptions, callback
|
500
|
-
.then(function
|
322
|
+
.then(makeLogin(jar, email, password, globalOptions, callback))
|
323
|
+
.then(function() {
|
501
324
|
return utils
|
502
325
|
.get('https://www.facebook.com/', jar, null, globalOptions)
|
503
326
|
.then(utils.saveCookies(jar));
|
@@ -505,11 +328,11 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
505
328
|
}
|
506
329
|
|
507
330
|
var ctx = null;
|
508
|
-
var
|
331
|
+
var defaultFuncs = null;
|
509
332
|
var api = null;
|
510
333
|
|
511
334
|
mainPromise = mainPromise
|
512
|
-
.then(function
|
335
|
+
.then(function(res) {
|
513
336
|
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
514
337
|
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
515
338
|
var redirect = reg.exec(res.body);
|
@@ -520,23 +343,41 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
520
343
|
}
|
521
344
|
return res;
|
522
345
|
})
|
523
|
-
.then(function
|
346
|
+
.then(function(res) {
|
524
347
|
var html = res.body;
|
525
348
|
var stuff = buildAPI(globalOptions, html, jar);
|
526
349
|
ctx = stuff[0];
|
527
|
-
|
350
|
+
defaultFuncs = stuff[1];
|
528
351
|
api = stuff[2];
|
529
352
|
return res;
|
353
|
+
})
|
354
|
+
.then(function() {
|
355
|
+
var form = {
|
356
|
+
reason: 6
|
357
|
+
};
|
358
|
+
// log.info("login", 'Request to reconnect');
|
359
|
+
return defaultFuncs
|
360
|
+
.get("https://www.facebook.com/ajax/presence/reconnect.php", ctx.jar, form)
|
361
|
+
.then(utils.saveCookies(ctx.jar));
|
362
|
+
})
|
363
|
+
.then(function() {
|
364
|
+
var presence = utils.generatePresence(ctx.userID);
|
365
|
+
ctx.jar.setCookie("presence=" + presence + "; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
|
366
|
+
ctx.jar.setCookie("presence=" + presence + "; path=/; domain=.messenger.com; secure", "https://www.messenger.com");
|
367
|
+
ctx.jar.setCookie("locale=en_US; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
|
368
|
+
ctx.jar.setCookie("locale=en_US; path=/; domain=.messenger.com; secure", "https://www.messenger.com");
|
369
|
+
ctx.jar.setCookie("a11y=" + utils.generateAccessiblityCookie() + "; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
|
370
|
+
return true;
|
530
371
|
});
|
531
372
|
|
532
373
|
// given a pageID we log in as a page
|
533
374
|
if (globalOptions.pageID) {
|
534
375
|
mainPromise = mainPromise
|
535
|
-
.then(function
|
376
|
+
.then(function() {
|
536
377
|
return utils
|
537
378
|
.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
538
379
|
})
|
539
|
-
.then(function
|
380
|
+
.then(function(resData) {
|
540
381
|
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
541
382
|
url = url.substring(0, url.length - 1);
|
542
383
|
|
@@ -547,18 +388,18 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
547
388
|
|
548
389
|
// At the end we call the callback or catch an exception
|
549
390
|
mainPromise
|
550
|
-
.then(function
|
551
|
-
|
391
|
+
.then(function() {
|
392
|
+
// log.info("login", 'Done logging in.');
|
552
393
|
return callback(null, api);
|
553
394
|
})
|
554
|
-
.catch(function
|
395
|
+
.catch(function(e) {
|
555
396
|
log.error("login", e.error || e);
|
556
397
|
callback(e);
|
557
398
|
});
|
558
399
|
}
|
559
400
|
|
560
401
|
function login(loginData, options, callback) {
|
561
|
-
if
|
402
|
+
if(utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
562
403
|
callback = options;
|
563
404
|
options = {};
|
564
405
|
}
|
@@ -566,38 +407,17 @@ function login(loginData, options, callback) {
|
|
566
407
|
var globalOptions = {
|
567
408
|
selfListen: false,
|
568
409
|
listenEvents: false,
|
569
|
-
listenTyping: false,
|
570
410
|
updatePresence: false,
|
571
|
-
forceLogin:
|
411
|
+
forceLogin: true,
|
572
412
|
autoMarkDelivery: true,
|
573
413
|
autoMarkRead: false,
|
574
|
-
autoReconnect: true,
|
575
414
|
logRecordSize: defaultLogRecordSize,
|
576
|
-
|
577
|
-
emitReady: false,
|
578
|
-
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"
|
415
|
+
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]"
|
579
416
|
};
|
580
417
|
|
581
418
|
setOptions(globalOptions, options);
|
582
419
|
|
583
|
-
|
584
|
-
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
585
|
-
var rejectFunc = null;
|
586
|
-
var resolveFunc = null;
|
587
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
588
|
-
resolveFunc = resolve;
|
589
|
-
rejectFunc = reject;
|
590
|
-
});
|
591
|
-
prCallback = function (error, api) {
|
592
|
-
if (error) {
|
593
|
-
return rejectFunc(error);
|
594
|
-
}
|
595
|
-
return resolveFunc(api);
|
596
|
-
};
|
597
|
-
callback = prCallback;
|
598
|
-
}
|
599
|
-
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
600
|
-
return returnPromise;
|
420
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback);
|
601
421
|
}
|
602
422
|
|
603
|
-
module.exports = login;
|
423
|
+
module.exports = login;
|