-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasyncPup.js
111 lines (101 loc) · 3.41 KB
/
asyncPup.js
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
//------------------- Puppeteer.conf
const puppeteer = require('puppeteer');
const iPhone = puppeteer.devices['iPhone X'];
// ------------------- Server.conf
var sys = require("sys"),
my_http = require("http");
const request = require('request');
var fs = require('fs');
/*
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
function getJSTodecrypt(){
return new Promise(resolve => {
setTimeout(() => {
request
.get('http://127.0.0.1:6050')
.on('response', function(response) {
console.log(response.statusCode) // 200
console.log(response.headers['content-type']) // 'image/png'
console.log(decode_utf8(response.toJSON()))
})
resolve('JS ricevuto');
}, 10000);
});
}
*/
async function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
//await page.setCookie();
await page.emulate(iPhone);
await page.goto('https://www.off---white.com/en/IT/cart');
await page.setRequestInterception(true)
page.on('request', request => {
var headers = request.headers();
console.log(headers);
})
await page.screenshot({path: 'screenshot.png'})
owCookies = await page._client.send('Network.getAllCookies');
await page.close();
//console.log(headers);
//owCookies = await page.cookies();
console.log(owCookies);
console.log('====================================================================')
// console.log(typeof owCookies);
console.log(process.argv)
//JS importa i cookies da OW e PY si collega e si scarica i cookies
var requestToServer = 0;
console.log('Server part:')
async function serverCook(callback){
my_http.createServer(function(request,response){
console.log("sto dentro")
if(requestToServer == 0){
console.log("Rispondo per cookies");
response.writeHeader(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(owCookies));
}
requestToServer++;
console.log("Richieste :");
console.log(requestToServer);
if(requestToServer == 2){
response.writeHeader(200, {"Content-Type": "application/json"});
response.end();
callback();
}
}).listen(process.argv[2]);
}
async function recuperoIPP(){
var ippSign;
console.log("sono prima dell'if");
if(requestToServer == 2){
console.log('IPP_SIGN in arrivo');
//await page.setCacheEnabled(false);
const page = await browser.newPage();
await page.emulate(iPhone);
await page.goto('file:///home/tob/Documents/OWBot/jsToDecrypt.html',{waitUntil: "load"});
await page.waitFor(1000);
page.on('dialog', async dialog => {
ippSign = dialog.message();
console.log(dialog.message());
await dialog.dismiss();
await browser.close();
my_http.createServer(function(request,response){
console.log("Rispondo per per ipp");
response.writeHeader(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(ippSign));
}).listen(process.argv[3]);
});
}
}
//serverC.close()
//Se py mi sta dicendo che posso partire con il decrypt (se ho fatto una seconda richiesta)
//var result = await getJSTodecrypt();
serverCook(recuperoIPP);
})();