problem with custom plugin to directly 'login' as users from admin

petersconsult

Verified User
Joined
Sep 10, 2021
Messages
87
Hello All,
i've had a custom plugin for years now that i iterate for each user of the server, and which makes it a 1-click trip to login as a given user

This plugin has, at times, worked perfectly, then been disabled completely, and now sorta works, but not really -- now, it looks like it doesn't work, but if i refresh the page, it works..

The plugin itself is just 1 line of JavaScript; only the theusername changes..
the same line, wrapped in a html a href tag exists in both admin_img.html and admin_txt.html placed in /usr/local/directadmin/plugins/mypluginname/hooks/

breaking it down, it looks like this:
JavaScript:
var xhr=new XMLHttpRequest();
var url='/api/session/login-as/switch?json=yes&redirect=yes';
xhr.open('POST',url,true);
xhr.setRequestHeader('Content-Type','application/json');
var data=JSON.stringify({'json':'yes','username':'theusername','referer':'/'});
xhr.onload <equals>() =>{window.location.reload();};
xhr.send(data);

However, like i said, clicking on it takes me to a blank page, but if i manually refresh it, it takes me to the expected user page..

if anyone has the knowledge to help me fix this, i would greatly appreciate it, as i find it extremely useful to be able to directly login to individual user pages directly from the admin home page..

Thank You All!

PS: i had to change the = to <equals> in the second to last line because it was interfering with the post..
 
so.. after spending an inordinate amount of time on this, i've narrowed it down to this:
window.location.reload();
same problem if i try:
window.location.replace('/evo/')

it's directadmin that's preventing any script from reloading the browser -- the plugins are in some sort of iframe or something, which prevents the script from acting on the 'main' page..
 
Back
Top