Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get web relay url via websocket #6484

Open
YiuTerran opened this issue Oct 30, 2024 · 12 comments
Open

Get web relay url via websocket #6484

YiuTerran opened this issue Oct 30, 2024 · 12 comments
Assignees

Comments

@YiuTerran
Copy link

Is your feature request related to a problem? Please describe.

Currently, we expose MeshCentral to users through an embedded iframe, and other functions work fine. However, when using the web relay feature, we cannot directly interact to obtain the relay URL via WebSocket; we must directly embed the General Information tab. This exposes too much information to users, while we only need a single link address.

Describe the solution you'd like
We can directly send commands to MeshCentral via WebSocket, and it will return a usable link. The browser can then open this link to complete the web relay.

Describe alternatives you've considered
Place the web relay-related buttons on a separate webpage instead of combining them with other general information. This way, we can avoid exposing too much information.

@si458
Copy link
Collaborator

si458 commented Oct 30, 2024

The webrelay works slightly differently

It gives u the url of ur relaydns or ur cert+relayport

But then uses a special unique cookie, which then identifies what service etc u wanted to be relayed

The is no special url as such! It's the cookie that makes it unique,

So we would have to return the url and a cookie for u to set of that makes sense

Would a simple json reply be ok?

@YiuTerran
Copy link
Author

@si458 JSON data is certainly fine. Our main concern is that we don’t want to expose the entire General Tab to users, as it contains too much information.

@YiuTerran
Copy link
Author

I believe that directly passing the cookie as a URL parameter to MeshCentral is also feasible.

@si458
Copy link
Collaborator

si458 commented Oct 30, 2024

@YiuTerran no that's understandable!
I will double check the code next week when i get chance, as the might possibly already a way I'm just not 100% sure

@si458
Copy link
Collaborator

si458 commented Nov 10, 2024

so after checking source code you actually generate the URL yourself based on information you should have

var servername = serverinfo.name;
if ((servername.indexOf('.') == -1) || ((features & 2) != 0)) { servername = window.location.hostname; } // If the server name is not set or it's in LAN-only mode, use the URL hostname as server name.
if (webRelayDns != '') { servername = webRelayDns; }
var url = 'https://' + servername + ':' + webRelayPort + '/control-redirect.ashx?n=' + nodeid + '&p=' + port + '&appid=' + protocol + '&c=' + authRelayCookie; // Protocol: 1 = HTTP, 2 = HTTPS
if (addr != null) { url += '&addr=' + addr; }
if (relayid != null) { url += '&relayid=' + relayid; }
safeNewWindow(url, 'WebRelay');

you get the authRelayCookie after you call authcookie its under message.rcookie
so basically its https://mc.mydomain.com:4567/control-redirect.ashx?n=NODEISHERE&p=443&appid=2&c=COOKIEHERE
and then when u visit that url it diverts you to https://mc.mydomain.com:4567/ where you web app is relayed

also appid=1 - HTTP appid=2 - HTTPS

i do agree tho maybe a websocket command to generate this URl would be a good idea tho! 💡

@si458 si458 self-assigned this Nov 10, 2024
@si458
Copy link
Collaborator

si458 commented Nov 15, 2024

just started to implement this feature and then realised this already partly exists
you create a devicesharing and this will return a url which can be used for web relay
only difference is you can restrict what the devicesharing does,
ie who can access it, when, remote desktop, web relay, etc
also creates a link in the web ui so u can see what links are created and u can delete them too
did you wanna try that and see if thats better for you?
code is inside meshctrl under devicesharing

if its not ideal i can add the webrelay to the websocket but it will only return basically the same code thats listed above
and a link to a url to do web relay but you will have no record of this

@YiuTerran
Copy link
Author

Thanks, i will try devicesharing tomorrow.

@YiuTerran
Copy link
Author

It seems {"action":"createDeviceShareLink"} does not work for the device group with a relay id. For Normal device, it works good.

@YiuTerran
Copy link
Author

if (webRelayDns != '') { servername = webRelayDns; }

If I configured multiple relay domains , how can i get a valid one to use?

@si458
Copy link
Collaborator

si458 commented Nov 19, 2024

@YiuTerran it does work for relay groups, check out the meshctrl.js for source code, how it creates the websocket data

Also I believe if u have multiple dns set for the relay it just round robins them so if one already in use it moved onto the next then the next then the next etc

@si458
Copy link
Collaborator

si458 commented Nov 19, 2024

@YiuTerran sorry ive just relooked and rechecked, you are correct,
you cant create a share link for device groups which is a relay group
so did you want me to add the feature in so it returns a url for you over websockets?

@YiuTerran
Copy link
Author

Also I believe if u have multiple dns set for the relay it just round robins them so if one already in use it moved onto the next then the next then the next etc

But only meshcentral know which one is in use, I can't get it in my code...

so did you want me to add the feature in so it returns a url for you over websockets?

Yep! Currently, when configured with multiple relay domains, there is no perfect way to obtain the relay URL. The only solution is to add a new WebSocket interface to achieve this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants