mirror of
https://gitlab.com/octospacc/Snippets.git
synced 2025-02-13 09:50:39 +01:00
Update TP-Link Hacks.user.js
This commit is contained in:
parent
e9b679e12e
commit
ff0f43f6fc
@ -19,114 +19,83 @@ var Ips = GM_getValue('IPs');
|
|||||||
var IsPageAllowed = (Ips.length == 0 || (Ips.length > 0 && Ips.includes(location.hostname)));
|
var IsPageAllowed = (Ips.length == 0 || (Ips.length > 0 && Ips.includes(location.hostname)));
|
||||||
|
|
||||||
if (IsPageAllowed) {
|
if (IsPageAllowed) {
|
||||||
|
// Note: localStorage is reset on new login and isn't reliable, we must use sessionStorage
|
||||||
//var Intvs = {};
|
var Opts = new URLSearchParams(location.hash.toLowerCase()).get('tplinkhacks');
|
||||||
//var Cmd = new URLSearchParams(window.location.hash.toLowerCase()).get('hackcmd');
|
if (Opts !== null) {
|
||||||
//if (Cmd) {
|
sessionStorage.setItem('HacksPrevOpts', Opts);
|
||||||
// localStorage.setItem('PrevCmd', Cmd);
|
} else {
|
||||||
//} else {
|
Opts = sessionStorage.getItem('HacksPrevOpts');
|
||||||
// Cmd = localStorage.getItem('PrevCmd');
|
sessionStorage.removeItem('HacksPrevOpts');
|
||||||
// localStorage.removeItem('PrevCmd');
|
|
||||||
//};
|
|
||||||
|
|
||||||
// Note: localStorage is reset on new login and isn't reliable, we must use sessionStorage
|
|
||||||
var Opts = new URLSearchParams(location.hash.toLowerCase()).get('tplinkhacks');
|
|
||||||
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 IntvKey(Name) {
|
|
||||||
// return `${Date.now()}-${Name}`;
|
|
||||||
//};
|
|
||||||
|
|
||||||
function WaitTill(Cond, Fun) {
|
|
||||||
/*Intvs[Key]*/
|
|
||||||
var Intv = setInterval(function(){
|
|
||||||
if (Cond()) {
|
|
||||||
//console.log(Key);
|
|
||||||
clearInterval(Intv/*Intvs[Key]*/);
|
|
||||||
Fun();
|
|
||||||
};
|
|
||||||
}, 100);
|
|
||||||
//function Call() {
|
|
||||||
// if (Cond) Fun();
|
|
||||||
// else { Rept(); console.log(0); }
|
|
||||||
//};
|
|
||||||
//function Rept() { setTimeout(Call, 50); };
|
|
||||||
//Rept();
|
|
||||||
};
|
|
||||||
|
|
||||||
function WaitElClick(Query, Fun) {
|
|
||||||
WaitTill(function(){ return qs(Query); }, function(){
|
|
||||||
qs(Query).click();
|
|
||||||
if (Fun) Fun();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function AfterCmd() {
|
|
||||||
console.log('[TP-Link Hacks] Command completed.');
|
|
||||||
if (Opts.closeafter) {
|
|
||||||
var Wait = 5000;
|
|
||||||
console.log(`[TP-Link Hacks] CloseAfter was specified. The page will close itself in ${Wait/1000} seconds.`);
|
|
||||||
setTimeout(function(){ window.close(); }, 5000);
|
|
||||||
};
|
};
|
||||||
};
|
Opts = JSON.parse(Opts);
|
||||||
|
|
||||||
function ReLogin() {
|
function qs(Query) {
|
||||||
// Attempt to logout if needed
|
return document.querySelector(Query);
|
||||||
//qs('#logout-button a').click();
|
};
|
||||||
//qs('#global-confirm #global-confirm-btn-ok a').click();
|
|
||||||
|
|
||||||
// Attempt to login if needed
|
function WaitTill(Cond, Fun) {
|
||||||
//try {
|
var Intv = setInterval(function(){
|
||||||
WaitTill(function(){ return qs('#local-login-pwd input'); }, function(){
|
if (Cond()) {
|
||||||
qs('#local-login-pwd input').value = GM_getValue('Password');
|
clearInterval(Intv);
|
||||||
WaitElClick('#local-login-button a');
|
Fun();
|
||||||
});
|
};
|
||||||
//qs('#local-login-pwd input').value = GM_getValue('Password', 'admin');
|
}, 100);
|
||||||
//qs('#local-login-button a').click();
|
};
|
||||||
//} catch(Ex) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
function Reboot() {
|
function WaitElClick(Query, Fun) {
|
||||||
WaitElClick('#main-menu *[navi-value="advanced"] a', function(){
|
WaitTill(function(){ return qs(Query); }, function(){
|
||||||
WaitElClick('#navigator *[navi-value="reboot"] a', function(){
|
qs(Query).click();
|
||||||
WaitElClick('#reboot-button a', function(){
|
if (Fun) Fun();
|
||||||
WaitElClick('#global-confirm #global-confirm-btn-ok a', function(){
|
});
|
||||||
AfterCmd();
|
};
|
||||||
}); }); }); });
|
|
||||||
};
|
|
||||||
|
|
||||||
function OpenLogs() {
|
function AfterCmd() {
|
||||||
WaitElClick('#main-menu *[navi-value="advanced"] a', function(){
|
console.log('[TP-Link Hacks] Command completed.');
|
||||||
WaitElClick('#navigator *[navi-value="sysLog"] a', function(){
|
if (Opts.closeafter) {
|
||||||
AfterCmd();
|
var Wait = 5000;
|
||||||
}); });
|
console.log(`[TP-Link Hacks] CloseAfter was specified. The page will close itself in ${Wait/1000} seconds.`);
|
||||||
};
|
setTimeout(function(){ window.close(); }, 5000);
|
||||||
|
|
||||||
function Main() {
|
|
||||||
if (Opts && Opts.cmd) {
|
|
||||||
console.log(`[TP-Link Hacks] Trying to call command: ${Opts.cmd}.`);
|
|
||||||
ReLogin();
|
|
||||||
switch (Opts.cmd.toLowerCase()) {
|
|
||||||
case 'reboot': Reboot(); break;
|
|
||||||
case 'openlogs': OpenLogs(); break;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('load', function(){
|
function ReLogin() {
|
||||||
// Wait a bit for the WebUI to settle down, accounting for slow machines/connections
|
WaitTill(function(){ return qs('#local-login-pwd input'); }, function(){
|
||||||
setTimeout(Main, 1500);
|
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 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 {
|
} else {
|
||||||
console.log('[TP-Link Hacks] Script matched this page but the IP whitelist check is negative. Stopping.');
|
console.log('[TP-Link Hacks] Script matched this page but the IP whitelist check is negative. Stopping.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user