Ylianst / MeshCentral

A complete web-based remote monitoring and management web site. Once setup you can install agents and perform remote desktop session to devices on the local network or over the Internet.
https://meshcentral.com
Apache License 2.0
3.97k stars 535 forks source link

pluginHandler, error in detection http url #6362

Closed BubonicPestilence closed 1 week ago

BubonicPestilence commented 1 week ago

Describe the bug

https://github.com/Ylianst/MeshCentral/blob/master/pluginHandler.js#L366

pluginHandler's url.parse(dl_url, true) give q.protocol value of http: if downloadUrl in config.json is used with http protocol also conflicts with next line:

var http = (q.protocol == "http") ? require('http') : require('https');

P.S. using this, to develop local plugins from local url

Quick, but ugly Fix

if (q.protocol == "http:") {
    q.protocol = "http";
}
si458 commented 1 week ago

Plugins are not officially supported

What plugins are you using so I can do some testing first before I just push that commit u suggested

BubonicPestilence commented 1 week ago

I'm creating new plugin. Instead of github i'm using local server. I replicated config.json & other files.

my config.json for plugin looks like:

{
  "name": "localplugin1",
  "shortName": "localplugin1",
  "version": "0.0.2",
  "author": "Bubonic Pestilence",
  "description": "",
  "hasAdminPanel": false,
  "homepage": "http://localhost/localplugin1/",
  "changelogUrl": "http://localhost/localplugin1/changelog.md",
  "configUrl": "http://localhost/localplugin1/config.json",
  "downloadUrl": "http://localhost/localplugin1-latest.zip",
  "repository": {
    "type": "git",
    "url": ""
  },
  "versionHistoryUrl": "http://localhost/localplugin1/",
  "meshCentralCompat": ">=0.9.98"
}

You can easily confirm this behavior by doing:

dl_url = "http://example.com/test/1.zip";
var q = url.parse(dl_url, true);
console.log(q, dl_url);

before this: https://github.com/Ylianst/MeshCentral/blob/master/pluginHandler.js#L366

and this code gave me output in syslog:

2024-09-06T01:58:04.348092 venik node[3155633]: Url {
2024-09-06T01:58:04.348182 venik node[3155633]:   protocol: 'http:',
2024-09-06T01:58:04.348219 venik node[3155633]:   slashes: true,
2024-09-06T01:58:04.348250 venik node[3155633]:   auth: null,
2024-09-06T01:58:04.348280 venik node[3155633]:   host: 'example.com',
2024-09-06T01:58:04.348317 venik node[3155633]:   port: null,
2024-09-06T01:58:04.348362 venik node[3155633]:   hostname: 'example.com',
2024-09-06T01:58:04.348432 venik node[3155633]:   hash: null,
2024-09-06T01:58:04.348471 venik node[3155633]:   search: null,
2024-09-06T01:58:04.348526 venik node[3155633]:   query: [Object: null prototype] {},
2024-09-06T01:58:04.348555 venik node[3155633]:   pathname: '/test/1.zip',
2024-09-06T01:58:04.348594 venik node[3155633]:   path: '/test/1.zip',
2024-09-06T01:58:04.348638 venik node[3155633]:   href: 'http://example.com/test/1.zip'
2024-09-06T01:58:04.348687 venik node[3155633]: } http://example.com/test/1.zip

I do understand, plugins aren't supported, just report that url.parse doesn't like "http" urls :)

si458 commented 1 week ago

This isn't actually a bug, this is nodejs itself!

https://nodejs.org/docs/latest-v16.x/api/url.html#urlprotocol

We use node 16 as the min for docs and features

Nodejs returns the protocol as http:

So, really, you need your plugin to remove the colon at the end and not meshcentral itself

si458 commented 1 week ago

Oh hang on, I see what you mean about the next line!

I will have a look tomorrow incase this was done by mistake or it's always been like this...

BubonicPestilence commented 1 week ago

Oh hang on, I see what you mean about the next line!

I will have a look tomorrow incase this was done by mistake or it's always been like this...

exactly :)

si458 commented 1 week ago

ok have fixed here for you https://github.com/Ylianst/MeshCentral/commit/390991123a566aba8b8c380b952c4e65c009396f according to nodejs the http and https protocols should still be http: and https: anyways https://nodejs.org/docs/latest-v16.x/api/http.html#httprequestoptions-callback