forked from agusalex/modemReboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovistar_Mitrastar_2541GNAC.js
79 lines (72 loc) · 1.96 KB
/
Movistar_Mitrastar_2541GNAC.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
/*
* Reboot Mitrastar HGU GPT-2541GNAC Movistar modem.
*
* Puppeteer container for rebooting an Mitrastar 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.
*/
const puppeteer = require('puppeteer');
const date = require('date-and-time');
const isDocker = require('is-docker');
const PASS = "process.env.PASS" || ""; //Unique for every modem
const URL = process.env.URL || "http://192.168.1.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, {
waitUntil: 'load',
timeout: 0
});;
await delay(2000);
await page.type('input[type="password"]', PASS, {
delay: 10
});
await delay(2000);
const form = await page.$('#acceptLogin');
await form.evaluate( form => form.click() );
await delay(10000);
await page.goto(URL+'/configsetting.html', {
waitUntil: 'load',
timeout: 0
});
timeMe(1, 'Go to reboots...');
await delay(4000);
await page.evaluate(() => {
btnReset();
});
timeMe(1, 'Rebooting...');
await delay(10000);
timeMe(1, 'Exiting...');
await browser.close();
process.exit(1);
})()