-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (51 loc) · 1.92 KB
/
index.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
const { spawn } = require("node-pty");
const puppeteer = require('puppeteer-core');
const devices = require('puppeteer-core/DeviceDescriptors');
const evasions = require('./apply-evasions.js');
//Login selectors
const USERNAME_SELECTOR = '#user';
const PASSWORD_SELECTOR = '#pass';
const LOGIN_BUTTON_SELECTOR = 'input[type="submit"]';
//Door selectors
const OPEN_DOOR_SELECTOR = 'form[name="confirmOpenDoor"]';
const RESPONSE_SELECTOR = '#content > div:nth-child(6) > div > div > div > div > h3 > strong';
//Door unlock service login
const USERNAME = 'username_here';
const PASSWORD = 'password_here';
const pyProcess = spawn("python3", ["./main.py"]);
(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-infobars', '--noerrdialogs', '--disable-session-crashed-bubble', '--disable-gpu'],
headless: true,
executablePath: 'chromium-browser',
ignoreHTTPSErrors: true,
//slowMo: 50,
});
const page = await browser.newPage();
await evasions(page);
await page.emulate(devices['iPhone 6']);
await page.goto('https://cardadmin.iit.edu');
await login(page);
pyProcess.on("data", data => {
if (Math.abs(parseInt(data)) >= 10 && Math.abs(parseInt(data)) <= 20) {
open_door(page);
}
console.log(data);
});
pyProcess.on("exit", exitCode => {
console.log("Exiting with code " + exitCode);
});
await page.waitFor(1000 * 60 * 10);
await browser.close();
})();
async function login(page) {
await page.type(USERNAME_SELECTOR, USERNAME);
await page.type(PASSWORD_SELECTOR, PASSWORD);
await Promise.all([page.click(LOGIN_BUTTON_SELECTOR), page.waitForNavigation()])
};
async function open_door(page) {
await page.goto('https://cardadmin.iit.edu/student/openmydoor.php');
await Promise.all([page.click(OPEN_DOOR_SELECTOR), page.waitForNavigation()])
const response = await page.$eval(RESPONSE_SELECTOR, e => e.innerHTML);
console.log(response);
};