Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/res/puppeteer/tor.js
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
"use strict";
2
+
function puppeteerDelay(time) {
3
+
return new Promise(function(resolve) {
4
+
setTimeout(resolve, time)
5
+
});
6
+
}
7
+
const puppeteer = require('puppeteer');
8
+
(async () => {
9
+
var args = process.argv.slice(2);
10
+
process.on('unhandledRejection', up => { throw up })
11
+
var argarr = ['--no-sandbox', '--disable-setuid-sandbox'];
12
+
if(args[2] != 'default')
13
+
{
14
+
argarr.push("--user-agent=" + args[2]);
15
+
}
16
+
argarr.push("--proxy-server=socks5://127.0.0.1:9050");
17
+
18
+
const browser = await puppeteer.launch({ignoreHTTPSErrors:true, args: argarr});
19
+
20
+
if(args[6] != '1')
21
+
{
22
+
//check if tor ok
23
+
const page2 = (await browser.pages())[0];
24
+
if(args[5] != 'default')
25
+
{
26
+
await page2.setDefaultNavigationTimeout(args[5]);
27
+
}
28
+
await page2.goto('https://check.torproject.org/');
29
+
const isUsingTor = await page2.$eval('body', el =>
30
+
el.innerHTML.includes('Congratulations. This browser is configured to use Tor')
31
+
);
32
+
if (!isUsingTor) {
33
+
console.log('CRAWLOMATIC NOT USING TOR!');
34
+
await browser.close()
35
+
return;
36
+
}
37
+
}
38
+
//continue
39
+
const page = (await browser.pages())[0];
40
+
if(args[9] != undefined && args[9] != 'default' && args[9] != '' && args[9] != null)
41
+
{
42
+
var localStorageVar = args[9];
43
+
localStorageVar = localStorageVar.replace(/\\/g, '');
44
+
await page.evaluateOnNewDocument((localStorageVar) =>
45
+
{
46
+
localStorageVar = localStorageVar.split(";");
47
+
var k;
48
+
for (k = 0; k < localStorageVar.length; k++) {
49
+
localx = localStorageVar[k].split("=");
50
+
if(localx[1] != undefined && localx[1] != '' && localx[1] != null)
51
+
{
52
+
localStorage.setItem(localx[0], localx[1]);
53
+
}
54
+
else
55
+
{
56
+
if(localx[0] != '')
57
+
{
58
+
localStorage.setItem(localx[0], '');
59
+
}
60
+
}
61
+
}
62
+
}, localStorageVar);
63
+
}
64
+
if(args[3] != 'default')
65
+
{
66
+
var kkarr = args[3].split(';');
67
+
kkarr.forEach(async function (value)
68
+
{
69
+
var cookiesobje = '';
70
+
var splitCookie = value.split('=');
71
+
if(splitCookie[1] !== undefined)
72
+
{
73
+
try {
74
+
cookiesobje += '{"name": "' + splitCookie[0].trim() + '","value": "' + decodeURIComponent(splitCookie[1]) + '", "url": "' + args[0] + '"}';
75
+
} catch (error) {
76
+
cookiesobje += '{"name": "' + splitCookie[0].trim() + '","value": "' + splitCookie[1] + '", "url": "' + args[0] + '"}';
77
+
}
78
+
if(cookiesobje != '')
79
+
{
80
+
try
81
+
{
82
+
var cookiesobjex = JSON.parse(cookiesobje);
83
+
await page.setCookie(cookiesobjex);
84
+
}
85
+
catch(error)
86
+
{
87
+
}
88
+
}
89
+
}
90
+
});
91
+
}
92
+
if(args[4] != 'default')
93
+
{
94
+
var xres = args[4].split(":");
95
+
if(xres[1] != undefined)
96
+
{
97
+
var user = xres[0];
98
+
var pass = xres[1];
99
+
const auth = new Buffer(`${user}:${pass}`).toString('base64');
100
+
await page.setExtraHTTPHeaders({
101
+
'Authorization': `Basic ${auth}`
102
+
});
103
+
}
104
+
}
105
+
if(args[5] != 'default')
106
+
{
107
+
await page.setDefaultNavigationTimeout(args[5]);
108
+
}
109
+
await page.goto(args[0], {waitUntil: 'networkidle2'});
110
+
const bodyWidth = await page.evaluate(() => document.body.scrollWidth);
111
+
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
112
+
await page.setViewport({ width: bodyWidth, height: bodyHeight });
113
+
if(args[7] != 'default' && args[7] != '' && args[7] != '0')
114
+
{
115
+
await puppeteerDelay(args[7]);
116
+
}
117
+
if(args[8] != undefined && args[8] != 'default' && args[8] != '' && args[8] != null)
118
+
{
119
+
var evalVar = args[8];
120
+
evalVar = evalVar.replace(/\\/g, '');
121
+
await page.evaluate((evalVar) =>
122
+
{
123
+
eval(evalVar);
124
+
}, evalVar);
125
+
}
126
+
let bodyHTML = await page.content();
127
+
console.log(bodyHTML);
128
+
await browser.close();
129
+
})();