1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added launching built-in desktop/files from URL link.

This commit is contained in:
Ylian Saint-Hilaire
2021-05-21 09:48:25 -07:00
parent 53c92b48c3
commit b418493e95

View File

@@ -227,15 +227,15 @@ namespace MeshCentralRouter
// Automatic mappings // Automatic mappings
autoNodeId = getValueFromQueryString(authLoginUrl.Query, "nodeid"); autoNodeId = getValueFromQueryString(authLoginUrl.Query, "nodeid");
autoRemoteIp = getValueFromQueryString(authLoginUrl.Query, "remoteip"); autoRemoteIp = getValueFromQueryString(authLoginUrl.Query, "remoteip");
autoRemotePort = int.Parse(getValueFromQueryString(authLoginUrl.Query, "remoteport")); int.TryParse(getValueFromQueryString(authLoginUrl.Query, "remoteport"), out autoRemotePort);
autoProtocol = int.Parse(getValueFromQueryString(authLoginUrl.Query, "protocol")); int.TryParse(getValueFromQueryString(authLoginUrl.Query, "protocol"), out autoProtocol);
autoAppId = int.Parse(getValueFromQueryString(authLoginUrl.Query, "appid")); int.TryParse(getValueFromQueryString(authLoginUrl.Query, "appid"), out autoAppId);
autoExit = (getValueFromQueryString(authLoginUrl.Query, "autoexit") == "1"); autoExit = (getValueFromQueryString(authLoginUrl.Query, "autoexit") == "1");
string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport"); string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport");
if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); } if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); }
} }
catch (Exception) { } catch (Exception) { }
if ((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) { if (((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) || ((autoNodeId != null) && ((autoAppId == 6) || (autoAppId == 7)))) {
Dictionary<string, object> map = new Dictionary<string, object>(); Dictionary<string, object> map = new Dictionary<string, object>();
map.Add("nodeId", autoNodeId); map.Add("nodeId", autoNodeId);
if (autoRemoteIp != null) { map.Add("remoteIP", autoRemoteIp); } if (autoRemoteIp != null) { map.Add("remoteIP", autoRemoteIp); }
@@ -247,7 +247,7 @@ namespace MeshCentralRouter
map.Add("launch", 1); map.Add("launch", 1);
mappingsToSetup = new ArrayList(); mappingsToSetup = new ArrayList();
mappingsToSetup.Add(map); mappingsToSetup.Add(map);
devicesTabControl.SelectedIndex = 1; if ((autoAppId != 6) && (autoAppId != 7)) { devicesTabControl.SelectedIndex = 1; }
} }
} }
@@ -913,15 +913,15 @@ namespace MeshCentralRouter
// Automatic mappings // Automatic mappings
autoNodeId = getValueFromQueryString(authLoginUrl2.Query, "nodeid"); autoNodeId = getValueFromQueryString(authLoginUrl2.Query, "nodeid");
autoRemoteIp = getValueFromQueryString(authLoginUrl2.Query, "remoteip"); autoRemoteIp = getValueFromQueryString(authLoginUrl2.Query, "remoteip");
autoRemotePort = int.Parse(getValueFromQueryString(authLoginUrl2.Query, "remoteport")); int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "remoteport"), out autoRemotePort);
autoProtocol = int.Parse(getValueFromQueryString(authLoginUrl2.Query, "protocol")); int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "protocol"), out autoProtocol);
autoAppId = int.Parse(getValueFromQueryString(authLoginUrl2.Query, "appid")); int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "appid"), out autoAppId);
autoExit = (getValueFromQueryString(authLoginUrl2.Query, "autoexit") == "1"); autoExit = (getValueFromQueryString(authLoginUrl2.Query, "autoexit") == "1");
string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport"); string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport");
if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); } if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); }
} }
catch (Exception) { } catch (Exception) { }
if ((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) if (((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) || ((autoNodeId != null) && ((autoAppId == 6) || (autoAppId == 7))))
{ {
Dictionary<string, object> map = new Dictionary<string, object>(); Dictionary<string, object> map = new Dictionary<string, object>();
map.Add("nodeId", autoNodeId); map.Add("nodeId", autoNodeId);
@@ -934,7 +934,7 @@ namespace MeshCentralRouter
map.Add("launch", 1); map.Add("launch", 1);
mappingsToSetup = new ArrayList(); mappingsToSetup = new ArrayList();
mappingsToSetup.Add(map); mappingsToSetup.Add(map);
devicesTabControl.SelectedIndex = 1; if ((autoAppId != 6) && (autoAppId != 7)) { devicesTabControl.SelectedIndex = 1; }
setupMappings(); setupMappings();
cancelAutoClose(); cancelAutoClose();
} }
@@ -1568,40 +1568,66 @@ namespace MeshCentralRouter
NodeClass node = null; NodeClass node = null;
try { node = meshcentral.nodes[nodeId]; } catch (Exception) { } try { node = meshcentral.nodes[nodeId]; } catch (Exception) { }
if (node == null) continue; if (node == null) continue;
int appId = (int)x["appId"];
// Add a new port map if (appId == 6)
MapUserControl map = new MapUserControl(); {
map.xdebug = debug; // MeshCentral Router Desktop
map.inaddrany = inaddrany; if ((node.conn & 1) == 0) return; // Agent not connected on this device
if (x.ContainsKey("name")) { map.name = x["name"].ToString(); } else { map.name = ""; } startNewDesktopViewer(node, 0);
map.protocol = (int)x["protocol"]; }
map.localPort = (int)x["localPort"]; else if (appId == 7)
if (x.ContainsKey("remoteIP")) { map.remoteIP = (string)x["remoteIP"]; } {
map.remotePort = (int)x["remotePort"]; // MeshCentral Router Files
map.appId = (int)x["appId"]; if ((node.conn & 1) == 0) return; // Agent not connected on this device
if (x.ContainsKey("autoExit")) { map.autoexit = (bool)x["autoExit"]; } if (node.fileViewer == null)
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
map.parent = this;
map.Dock = DockStyle.Top;
map.Start();
mapPanel.Controls.Add(map);
noMapLabel.Visible = false;
// Launch any executable
if (x.ContainsKey("launch")) {
if (x["launch"].GetType() == typeof(int)) { map.appButton_Click(this, null); }
if (x["launch"].GetType() == typeof(string))
{ {
try node.fileViewer = new FileViewer(meshcentral, node);
node.fileViewer.Show();
node.fileViewer.MenuItemConnect_Click(null, null);
}
else
{
node.fileViewer.Focus();
}
}
else
{
// Add a new port map
MapUserControl map = new MapUserControl();
map.xdebug = debug;
map.inaddrany = inaddrany;
if (x.ContainsKey("name")) { map.name = x["name"].ToString(); } else { map.name = ""; }
map.protocol = (int)x["protocol"];
map.localPort = (int)x["localPort"];
if (x.ContainsKey("remoteIP")) { map.remoteIP = (string)x["remoteIP"]; }
map.remotePort = (int)x["remotePort"];
map.appId = (int)x["appId"];
if (x.ContainsKey("autoExit")) { map.autoexit = (bool)x["autoExit"]; }
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
map.parent = this;
map.Dock = DockStyle.Top;
map.Start();
mapPanel.Controls.Add(map);
noMapLabel.Visible = false;
// Launch any executable
if (x.ContainsKey("launch"))
{
if (x["launch"].GetType() == typeof(int)) { map.appButton_Click(this, null); }
if (x["launch"].GetType() == typeof(string))
{ {
string lanuchString = (string)x["launch"]; try
lanuchString = lanuchString.Replace("{port}", x["localPort"].ToString()); {
System.Diagnostics.Process.Start(lanuchString); string lanuchString = (string)x["launch"];
lanuchString = lanuchString.Replace("{port}", x["localPort"].ToString());
System.Diagnostics.Process.Start(lanuchString);
}
catch (Exception) { }
} }
catch (Exception) { }
} }
} }
} }