forked from Izurii/modem-vivo-avancado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (45 loc) · 1.64 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
const Vars = require("./vars");
const Utils = require("./utils");
async function getFreshSessionId() {
const any = await fetch(`http://${Vars.IP}/login.asp`);
const cookies = any.headers.getSetCookie();
const cookiesObj = {};
cookies.forEach((cookie) => {
const [key, value] = cookie.split("=");
cookiesObj[key.trim()] = value;
});
const sessionId = cookiesObj["_httpdSessionId_"].split(";")[0];
return sessionId;
}
async function doLogin() {
const sessionId = await getFreshSessionId();
const headers = new Headers();
headers.append(
"Cookie",
`SessionID=${sessionId}; LoginRole=system; _httpdSessionId_=${sessionId}`
);
const urlencoded = new URLSearchParams();
urlencoded.append("loginUsername", Vars.user);
urlencoded.append("loginPassword", Vars.pass);
await fetch(`http://${Vars.IP}/cgi-bin/te_acceso_router.cgi`, {
method: "POST",
body: urlencoded,
headers,
});
return sessionId;
}
(async function () {
const platform = Utils.getPlatform();
if (platform !== "win32" && platform !== "linux" && platform != "darwin") {
console.error("Plataforma não suportada. Esse script suporta apenas Linux, Windows e MacOS");
process.exit(1);
}
const sessionId = await doLogin();
const driver = Utils.getWebDriver(platform);
await driver.manage().window().maximize();
await driver.get(`http://${Vars.IP}/login.asp`);
await driver.manage().addCookie({ name: "SessionID", value: sessionId });
await driver.manage().addCookie({ name: "LoginRole", value: "system" });
await driver.manage().addCookie({ name: "_httpdSessionId_", value: sessionId, httpOnly: true });
await driver.navigate().to(`http://${Vars.IP}/avanzada.asp`);
})();