-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTP-Link Web Hacks.user.js
103 lines (90 loc) · 3.06 KB
/
TP-Link Web Hacks.user.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
100
101
102
103
// ==UserScript==
// @name TP-Link Web Hacks
// @description Let's hack some useful features into the TP-Link WebUI! (Tested on AC750 RE200)
// @version 1.1
// @author OctoSpacc
// @namespace https://octt.eu.org
// @match http://192.168.*.*/*
// @match http://tplinkrepeater.net/*
// @grant GM_getValue
// @grant GM_setValue
// @grant window.close
// ==/UserScript==
(function(){
GM_setValue('Password', GM_getValue('Password', 'admin'));
GM_setValue('IPs', GM_getValue('IPs', []));
var Ips = GM_getValue('IPs');
var IsPageAllowed = (Ips.length == 0 || (Ips.length > 0 && Ips.includes(location.hostname)));
if (IsPageAllowed) {
// Note: localStorage is reset on new login and isn't reliable, we must use sessionStorage
var Opts = new URLSearchParams(location.hash.toLowerCase()).get('tplinkwebhacks');
if (Opts !== null) {
sessionStorage.setItem('HacksPrevOpts', Opts);
} else {
Opts = sessionStorage.getItem('HacksPrevOpts');
sessionStorage.removeItem('HacksPrevOpts');
};
Opts = JSON.parse(Opts);
function qs(Query) {
return document.querySelector(Query);
};
function WaitTill(Cond, Fun) {
var Intv = setInterval(function(){
if (Cond()) {
clearInterval(Intv);
Fun();
};
}, 100);
};
function WaitElClick(Query, Fun) {
WaitTill(function(){ return qs(Query); }, function(){
qs(Query).click();
if (Fun) Fun();
});
};
function AfterCmd() {
console.log('[TP-Link Web Hacks] Command completed.');
if (Opts.closeafter) {
var Wait = 5000;
console.log(`[TP-Link Web Hacks] CloseAfter was specified. The page will close itself in ${Wait/1000} seconds.`);
setTimeout(function(){ window.close(); }, Wait);
};
};
function ReLogin() {
WaitTill(function(){ return qs('#local-login-pwd input'); }, function(){
qs('#local-login-pwd input').value = GM_getValue('Password');
WaitElClick('#local-login-button a');
});
};
function Reboot() {
WaitElClick('#main-menu *[navi-value="advanced"] a', function(){
WaitElClick('#navigator *[navi-value="reboot"] a', function(){
WaitElClick('#reboot-button a', function(){
WaitElClick('#global-confirm #global-confirm-btn-ok a', function(){
AfterCmd();
}); }); }); });
};
function OpenLogs() {
WaitElClick('#main-menu *[navi-value="advanced"] a', function(){
WaitElClick('#navigator *[navi-value="sysLog"] a', function(){
AfterCmd();
}); });
};
function Main() {
if (Opts && Opts.cmd) {
console.log(`[TP-Link Web Hacks] Trying to call command: ${Opts.cmd}.`);
ReLogin();
switch (Opts.cmd.toLowerCase()) {
case 'reboot': Reboot(); break;
case 'openlogs': OpenLogs(); break;
};
};
};
window.addEventListener('load', function(){
// Wait a bit for the WebUI to settle down, accounting for slow machines/connections
setTimeout(Main, 1500);
});
} else {
console.log('[TP-Link Web Hacks] Script matched this page but the IP whitelist check is negative. Stopping.');
};
})();