forked from agusalex/modemReboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZTE_MF258.js
88 lines (75 loc) · 2.34 KB
/
ZTE_MF258.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
/*
* @name Reboot ZTE MF258A modem. Should work with pretty much any ZTE modem
* Used by Italian LTE Providers (TIM, PosteMobile, etc...)
*
* @desc Puppeteer script for rebooting a ZTE 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.
* Created by github.com/shiner66
*
*/
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, 'Logging in.');
const page = await browser.newPage();
await page.setViewport({
width: 1366,
height: 768
});
await delay(1000);
await page.goto(URL + '/pub/#.htm', {
waitUntil: 'load',
timeout: 0
});;
await page.type('#username', USER, {
delay: 10
});
await page.type('input[type="password"]', PASS, {
delay: 10
});
/* Need it to correctly pass the login click
It's ugly, I know. */
const form = await page.$('#button');
await form.evaluate(form => form.click());
/* We need this delay to correctly load the page before navigating, else we'll be redirected to login */
await delay(5000)
timeMe(1, 'Going to restart.');
await page.goto(URL + '/system_wait.asp', {
waitUntil: 'load',
timeout: 0
});
timeMe(1, 'Waiting 10s');
await delay(10000);
timeMe(1, 'Terminating. All Done!');
await browser.close();
process.exit(1);
})()