-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharris.js
99 lines (85 loc) · 2.23 KB
/
arris.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
/*
* @name Reboot Arris modem.
*
* @desc Puppeteer script for rebooting an Arris modem.
* since the specific navigation for your modem will vary, this
* is more of an example and isn't guaranteed to work for your particular
* modem.
* Many thanks to https://stackoverflow.com/users/6870228/keith for his help!
*
*/
const puppeteer = require('puppeteer');
const date = require('date-and-time');
const isDocker = require('is-docker');
const USER = '***';
const PASS = '***';
const URL = process.env.URL || "http://192.168.0.1";
var browser;
const delay = (ms) =>
new Promise((resolve) => setTimeout(resolve, ms));
async function timeMe(num, txt) {
let now = new Date();
let time = date.format(now, 'dddd MM/DD/YYYY HH:mm:ss, ');
console.log(time, txt);
}
process.on("unhandledRejection", (reason, p) => {
console.error("Unhandled Rejection at: Promise (new page)", p, "reason:", reason);
browser.close();
});
(async() => {
if (isDocker()) {
console.log('Running inside a Docker container');
browser =await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--headless', '--disable-gpu']
});
}
else{
browser = await puppeteer.launch({
headless: false
});
}
timeMe(1, 'Login...');
const page = await browser.newPage();
await page.setViewport({
width: 1366,
height: 768
});
await delay(1000);
await page.goto(URL+'/login.asp', {
waitUntil: 'load',
timeout: 0
});;
await page.type('#id_username', USER, {
delay: 10
});
await page.type('input[type="password"]', PASS, {
delay: 10
});
await page.click('[value="Login"]');
timeMe(1, 'Go to home...');
await page.goto(URL+'/home.asp', {
waitUntil: 'load',
timeout: 0
});
await page.click('#alertExitButton');
timeMe(1, 'Go to Config...');
await page.goto(URL+'/RgConfiguration.asp', {
waitUntil: 'load',
timeout: 0
});
timeMe(1, 'Submit request...');
page.click('input[type=submit]');
timeMe(1, 'Wait for Dialog...');
page.on('dialog', async dialog => {
await dialog.accept();
/* For debugging */
/* await dialog.dismiss(); */
timeMe(1, 'Dismiss Dialog...');
});
timeMe(1, 'Pause...');
await delay(10000);
timeMe(1, 'Exiting...');
await browser.close();
process.exit(1);
})()