From b88e9109b09cfe4afc21b1dffa698f0121f27b62 Mon Sep 17 00:00:00 2001 From: jb Date: Thu, 26 Jan 2023 17:58:57 +0100 Subject: [PATCH] wake up support --- src/MainForm.Designer.cs | 12 ++++++++- src/MainForm.cs | 58 ++++++++++++++++++++++++++++++---------- src/MainForm.resx | 12 +++++++++ src/Translate.cs | 23 ++++++++++++++++ 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/src/MainForm.Designer.cs b/src/MainForm.Designer.cs index 0897163..e24117f 100644 --- a/src/MainForm.Designer.cs +++ b/src/MainForm.Designer.cs @@ -108,6 +108,7 @@ this.rdpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sshToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.scpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.wolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.devicesImageList = new System.Windows.Forms.ImageList(this.components); this.noSearchResultsLabel = new System.Windows.Forms.Label(); this.noDevicesLabel = new System.Windows.Forms.Label(); @@ -677,7 +678,9 @@ this.httpsToolStripMenuItem, this.rdpToolStripMenuItem, this.sshToolStripMenuItem, - this.scpToolStripMenuItem}); + this.scpToolStripMenuItem, + this.wolToolStripMenuItem, + }); this.devicesContextMenuStrip.Name = "devicesContextMenuStrip"; resources.ApplyResources(this.devicesContextMenuStrip, "devicesContextMenuStrip"); this.devicesContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.devicesContextMenuStrip_Opening); @@ -763,6 +766,12 @@ resources.ApplyResources(this.scpToolStripMenuItem, "scpToolStripMenuItem"); this.scpToolStripMenuItem.Click += new System.EventHandler(this.scpToolStripMenuItem_Click); // + // wolToolStripMenuItem + // + this.wolToolStripMenuItem.Name = "wolToolStripMenuItem"; + resources.ApplyResources(this.wolToolStripMenuItem, "wolToolStripMenuItem"); + this.wolToolStripMenuItem.Click += new System.EventHandler(this.wolToolStripMenuItem_Click); + // // devicesImageList // this.devicesImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("devicesImageList.ImageStream"))); @@ -1137,6 +1146,7 @@ private System.Windows.Forms.ToolStripMenuItem rdpToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem sshToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem scpToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem wolToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem addMapToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem addRelayMapToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; diff --git a/src/MainForm.cs b/src/MainForm.cs index 6bf6978..0aef2db 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -2045,24 +2045,42 @@ namespace MeshCentralRouter if (devicesListView.SelectedItems.Count != 1) { e.Cancel = true; return; } // Device not selected ListViewItem selecteditem = devicesListView.SelectedItems[0]; NodeClass node = (NodeClass)selecteditem.Tag; - if (((node.conn & 1) == 0) && (node.mtype != 3)) { e.Cancel = true; return; } // Agent not connected on this device - if (node.agentid < 6) - { - // Windows OS + if (((node.conn & 1) == 0) && (node.mtype != 3)) + { // Agent not connected on this device and not local device + addMapToolStripMenuItem.Visible = false; + addRelayMapToolStripMenuItem.Visible = false; + remoteDesktopToolStripMenuItem.Visible = false; + remoteFilesToolStripMenuItem.Visible = false; + httpToolStripMenuItem.Visible = false; + httpsToolStripMenuItem.Visible = false; + rdpToolStripMenuItem.Visible = false; sshToolStripMenuItem.Visible = false; scpToolStripMenuItem.Visible = false; - rdpToolStripMenuItem.Visible = true; + wolToolStripMenuItem.Visible = true; // Wol not allowed for local devices } - else - { - // Other OS - sshToolStripMenuItem.Visible = true; - scpToolStripMenuItem.Visible = true; - rdpToolStripMenuItem.Visible = false; + else{ // Agent connected or local device + if (node.agentid < 6) + { + // Windows OS + sshToolStripMenuItem.Visible = false; + scpToolStripMenuItem.Visible = false; + rdpToolStripMenuItem.Visible = true; + } + else + { + // Other OS + sshToolStripMenuItem.Visible = true; + scpToolStripMenuItem.Visible = true; + rdpToolStripMenuItem.Visible = false; + } + addMapToolStripMenuItem.Visible = true; + httpToolStripMenuItem.Visible = true; + httpsToolStripMenuItem.Visible = true; + addRelayMapToolStripMenuItem.Visible = (node.mtype != 3); // Relay mappings are not allowed for local devices + remoteDesktopToolStripMenuItem.Visible = ((node.agentcaps & 1) != 0); // Only display remote desktop if it's supported by the agent (1 = Desktop) + remoteFilesToolStripMenuItem.Visible = ((node.agentcaps & 4) != 0); // Only display remote desktop if it's supported by the agent (4 = Files) } - addRelayMapToolStripMenuItem.Visible = (node.mtype != 3); // Relay mappings are not allowed for local devices - remoteDesktopToolStripMenuItem.Visible = ((node.agentcaps & 1) != 0); // Only display remote desktop if it's supported by the agent (1 = Desktop) - remoteFilesToolStripMenuItem.Visible = ((node.agentcaps & 4) != 0); // Only display remote desktop if it's supported by the agent (4 = Files) + } private void httpToolStripMenuItem_Click(object sender, EventArgs e) @@ -2111,6 +2129,18 @@ namespace MeshCentralRouter if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 22, 5, node); // WinSCP } + + private void wolToolStripMenuItem_Click(object sender, EventArgs e) + { + if (devicesListView.SelectedItems.Count != 1) { return; } + ListViewItem selecteditem = devicesListView.SelectedItems[0]; + NodeClass node = (NodeClass)selecteditem.Tag; + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device + // List of actions : https://github.com/Ylianst/MeshCentral/blob/f5db131693386147731f2ec93b9378bf035b5861/agents/meshcore.js#L1110 + // https://github.com/Ylianst/MeshCentral/blob/f5db131693386147731f2ec93b9378bf035b5861/amtmanager.js#L347 + // https://github.com/Ylianst/MeshCentral/blob/f5db131693386147731f2ec93b9378bf035b5861/meshuser.js#L5285 + meshcentral.sendCommand("{ \"action\": \"wakedevices\", \"nodeids\": [\"" + node.nodeid + "\"]}"); + } private void addMapToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/src/MainForm.resx b/src/MainForm.resx index 69d8a4a..7ce76db 100644 --- a/src/MainForm.resx +++ b/src/MainForm.resx @@ -1695,6 +1695,12 @@ Remote Files... + + 198, 24 + + + Wake Up... + 198, 24 @@ -6243,6 +6249,12 @@ Click "Add" to get started. System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + wolToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + httpToolStripMenuItem diff --git a/src/Translate.cs b/src/Translate.cs index 3a20c82..9de59e9 100644 --- a/src/Translate.cs +++ b/src/Translate.cs @@ -4086,6 +4086,29 @@ namespace MeshCentralRouter {"ru","Спросите согласия"} } }, + { + "Wake Up...", + new Dictionary() { + {"de","Wach auf..."}, + {"hi","जगाना..."}, + {"fr","Reveiller..."}, + {"zh-chs","醒来..."}, + {"fi","herätä..."}, + {"tr","uyanmak..."}, + {"cs","vzbudit..."}, + {"ja","起きろ..."}, + {"es","despertar..."}, + {"pl","budzić się..."}, + {"pt","acordar..."}, + {"nl","word wakker..."}, + {"pt-br","acordar..."}, + {"sv","vakna..."}, + {"da","Vågn op..."}, + {"ko","깨우다..."}, + {"it","svegliati..."}, + {"ru","просыпайся..."} + } + }, { "Remote Desktop...", new Dictionary() {