-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
128 lines (100 loc) · 3.11 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const electron = require('electron')
const { app, BrowserWindow, protocol, net } = electron;
const fs = require('fs');
const moment = require('moment');
const express = require('express')
const bodyParser = require('body-parser')
var expressApp, bankExpressApp, bankServer;
var captchaBank = [];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
app.on('ready', () => {
initCaptchaWindow();
})
async function initCaptchaWindow() {
captchaWindow = new BrowserWindow({
width: 480,
height: 680,
webPreferences: {
allowRunningInsecureContent: true
}
})
SetupIntercept();
//User agents chrome allows sign in on electron, due to chrome's new rules. DO NOT use this when connecting to your site.
captchaWindow.loadURL('https://accounts.google.com', {userAgent: 'Chrome'});
await sleep(1000)
captchaWindow.on('close', function(e){
captchaWindow = null;
});
captchaWindow.webContents.session.webRequest.onBeforeRequest({urls: ['https://myaccount.google.com/*']}, (details, callback) => {
callback({redirectURL: 'http://www.supplystore.com.au/'})
})
};
function SetupIntercept() {
protocol.interceptBufferProtocol('http', (req, callback) => {
if(req.url == 'http://www.supplystore.com.au/') {
fs.readFile(__dirname + '/captcha.html', 'utf8', function(err, html){
callback({mimeType: 'text/html', data: Buffer.from(html)});
});
}else{
const request = net.request(req)
request.on('response', res => {
const chunks = []
res.on('data', chunk => {
chunks.push(Buffer.from(chunk))
})
res.on('end', async () => {
const file = Buffer.concat(chunks)
callback(file)
})
})
if (req.uploadData) {
req.uploadData.forEach(part => {
if (part.bytes) {
request.write(part.bytes)
} else if (part.file) {
request.write(readFileSync(part.file))
}
})
}
request.end()
}
})
};
electron.ipcMain.on('openCapWindow', function(event, args) {
initCaptchaWindow();
});
electron.ipcMain.on('sendCaptcha', function(event, token) {
captchaBank.push({
token: token,
timestamp: moment(),
host: 'http://www.supplystore.com.au/',
sitekey: '6LfucpUUAAAAAC1oYq1gsmm2MXk8TjrH_mkcLeL8'
})
});
setInterval(function(){
for (var i = 0; i < captchaBank.length; i++) {
if (moment().diff(moment(captchaBank[i].timestamp), 'seconds') > 110) {
//console.log('Removing Expired Captcha Token')
captchaBank.splice(0,1)
}
}
}, 1000);
function initBankServer() {
bankExpressApp = express()
let port = '8080';
console.log('Bank server listening on port: ' + port);
bankExpressApp.set('port', port);
bankExpressApp.use(bodyParser.json());
bankExpressApp.use(bodyParser.urlencoded({ extended: true }));
bankExpressApp.get('/trigger', function(req, res) {
initCaptchaWindow();
});
bankExpressApp.get('/fetch', function(req, res) {
return res.json(captchaBank),
captchaBank.splice(0,1);
});
bankServer = bankExpressApp.listen(bankExpressApp.get('port'));
}
initBankServer();