Beispiel #1
0
        private void addRelayMapButton_Click(object sender, EventArgs e)
        {
            AddRelayMapForm form = new AddRelayMapForm(meshcentral);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                // Add a new port map
                MapUserControl map = new MapUserControl();
                map.xdebug     = debug;
                map.inaddrany  = inaddrany;
                map.protocol   = form.getProtocol();
                map.localPort  = form.getLocalPort();
                map.remotePort = form.getRemotePort();
                map.remoteIP   = form.getRemoteIP();
                map.appId      = form.getAppId();
                map.node       = form.getNode();
                map.host       = serverNameComboBox.Text;
                map.authCookie = meshcentral.authCookie;
                map.certhash   = meshcentral.wshash;
                map.parent     = this;
                map.Dock       = DockStyle.Top;
                map.Start();

                mapPanel.Controls.Add(map);
                noMapLabel.Visible = false;
            }
        }
Beispiel #2
0
        private void Meshcentral_onNodesChanged()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MeshCentralServer.onNodeListChangedHandler(Meshcentral_onNodesChanged)); return;
            }
            addRelayButton.Enabled = addButton.Enabled = ((meshcentral.nodes != null) && (meshcentral.nodes.Count > 0));

            // Update any active mappings
            foreach (Control c in mapPanel.Controls)
            {
                if (c.GetType() == typeof(MapUserControl))
                {
                    MapUserControl cc = (MapUserControl)c;
                    cc.UpdateInfo();
                }
            }

            addArgMappings();
            reconnectUdpMaps();
        }
Beispiel #3
0
 private void reconnectUdpMaps()
 {
     foreach (Control c in mapPanel.Controls)
     {
         if (c == noMapLabel)
         {
             continue;
         }
         MapUserControl map = (MapUserControl)c;
         if ((map.protocol == 2) && (map.mapper.totalConnectCounter == 0))
         {
             // This is an unconnected UDP map, check if the target node is connected.
             foreach (NodeClass n in meshcentral.nodes.Values)
             {
                 if ((map.node == n) && ((n.conn & 1) != 0))
                 {
                     // Reconnect the UDP map
                     map.Start();
                 }
             }
         }
     }
 }
Beispiel #4
0
        public void QuickMap(int protocol, int port, int appId, NodeClass node)
        {
            // See if we already have the right port mapping
            foreach (Control c in mapPanel.Controls)
            {
                if (c.GetType() == typeof(MapUserControl))
                {
                    MapUserControl cc = (MapUserControl)c;
                    if ((cc.protocol == protocol) && (cc.remotePort == port) && (cc.appId == appId) && (cc.node == node))
                    {
                        // Found a match
                        cc.appButton_Click(this, null);
                        return;
                    }
                }
            }

            // Add a new port map
            MapUserControl map = new MapUserControl();

            map.xdebug     = debug;
            map.inaddrany  = false;    // Loopback only
            map.protocol   = protocol; // 1 = TCP, 2 = UDP
            map.localPort  = 0;        // Any
            map.remotePort = port;     // HTTP
            map.appId      = appId;    // 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
            map.node       = node;
            map.host       = serverNameComboBox.Text;
            map.authCookie = meshcentral.authCookie;
            map.certhash   = meshcentral.wshash;
            map.parent     = this;
            map.Dock       = DockStyle.Top;
            map.Start();
            mapPanel.Controls.Add(map);
            noMapLabel.Visible = false;
            map.appButton_Click(this, null);
        }
Beispiel #5
0
 public MappingStats(MapUserControl mapControl)
 {
     this.mapControl = mapControl;
     InitializeComponent();
 }
Beispiel #6
0
 public void removeMap(MapUserControl map)
 {
     mapPanel.Controls.Remove(map);
     noMapLabel.Visible = (mapPanel.Controls.Count <= 1);
 }
Beispiel #7
0
        private void addArgMappings()
        {
            // Add mappings
            for (int i = 0; i < this.args.Length; i++)
            {
                if (processedArgs.Contains(i))
                {
                    continue;
                }                                            // This map was already added
                string arg = this.args[i];

                if (arg.Length > 5 && arg.Substring(0, 5).ToLower() == "-map:")
                {
                    string[] x = arg.Substring(5).Split(':');
                    if (x.Length == 5)
                    {
                        // Protocol
                        int protocol = 0;
                        if (x[0].ToLower() == "tcp")
                        {
                            protocol = 1;
                        }
                        if (x[0].ToLower() == "udp")
                        {
                            protocol = 2;
                        }
                        if (protocol == 0)
                        {
                            continue;
                        }

                        // LocalPort
                        ushort localPort = 0;
                        if (ushort.TryParse(x[1], out localPort) == false)
                        {
                            continue;
                        }

                        // Node
                        string    nodename = x[2];
                        NodeClass node     = null;
                        foreach (NodeClass n in meshcentral.nodes.Values)
                        {
                            if (((n.conn & 1) != 0) && (n.name.ToLower() == nodename.ToLower()))
                            {
                                node = n;
                            }
                        }
                        if (node == null)
                        {
                            continue;
                        }

                        // AppId
                        int appId = 0;
                        if (protocol == 1)
                        {
                            if (x[3].ToLower() == "http")
                            {
                                appId = 1;
                            }
                            else if (x[3].ToLower() == "https")
                            {
                                appId = 2;
                            }
                            else if (x[3].ToLower() == "rdp")
                            {
                                appId = 3;
                            }
                            else if (x[3].ToLower() == "putty")
                            {
                                appId = 4;
                            }
                            else if (x[3].ToLower() == "winscp")
                            {
                                appId = 5;
                            }
                        }

                        // RemotePort
                        ushort remotePort = 0;
                        if (ushort.TryParse(x[4], out remotePort) == false)
                        {
                            continue;
                        }

                        // Add a new port map
                        MapUserControl map = new MapUserControl();
                        map.xdebug     = debug;
                        map.inaddrany  = inaddrany;
                        map.protocol   = protocol;
                        map.localPort  = (int)localPort;
                        map.remotePort = (int)remotePort;
                        map.appId      = appId;
                        map.node       = node;
                        map.host       = serverNameComboBox.Text;
                        map.authCookie = meshcentral.authCookie;
                        map.certhash   = meshcentral.wshash;
                        map.parent     = this;
                        map.Dock       = DockStyle.Top;
                        map.Start();

                        mapPanel.Controls.Add(map);
                        noMapLabel.Visible = false;
                        processedArgs.Add(i);
                    }
                }
                else if (arg.Length > 10 && arg.Substring(0, 10).ToLower() == "-relaymap:")
                {
                    string[] x = arg.Substring(10).Split(':');
                    if (x.Length == 6)
                    {
                        // Protocol
                        int protocol = 0;
                        if (x[0].ToLower() == "tcp")
                        {
                            protocol = 1;
                        }
                        if (x[0].ToLower() == "udp")
                        {
                            protocol = 2;
                        }
                        if (protocol == 0)
                        {
                            continue;
                        }

                        // LocalPort
                        ushort localPort = 0;
                        if (ushort.TryParse(x[1], out localPort) == false)
                        {
                            continue;
                        }

                        // Node
                        string    nodename = x[2];
                        NodeClass node     = null;
                        foreach (NodeClass n in meshcentral.nodes.Values)
                        {
                            if (((n.conn & 1) != 0) && (n.name.ToLower() == nodename.ToLower()))
                            {
                                node = n;
                            }
                        }
                        if (node == null)
                        {
                            continue;
                        }

                        // AppId
                        int appId = 0;
                        if (protocol == 1)
                        {
                            if (x[3].ToLower() == "http")
                            {
                                appId = 1;
                            }
                            else if (x[3].ToLower() == "https")
                            {
                                appId = 2;
                            }
                            else if (x[3].ToLower() == "rdp")
                            {
                                appId = 3;
                            }
                            else if (x[3].ToLower() == "putty")
                            {
                                appId = 4;
                            }
                            else if (x[3].ToLower() == "winscp")
                            {
                                appId = 5;
                            }
                        }

                        // Remote host
                        IPAddress remoteIp;
                        if (IPAddress.TryParse(x[4], out remoteIp) == false)
                        {
                            continue;
                        }

                        // RemotePort
                        ushort remotePort = 0;
                        if (ushort.TryParse(x[5], out remotePort) == false)
                        {
                            continue;
                        }

                        // Add a new port map
                        MapUserControl map = new MapUserControl();
                        map.xdebug     = debug;
                        map.inaddrany  = inaddrany;
                        map.protocol   = protocol;
                        map.localPort  = (int)localPort;
                        map.remoteIP   = remoteIp.ToString();
                        map.remotePort = (int)remotePort;
                        map.appId      = appId;
                        map.node       = node;
                        map.host       = serverNameComboBox.Text;
                        map.authCookie = meshcentral.authCookie;
                        map.certhash   = meshcentral.wshash;
                        map.parent     = this;
                        map.Dock       = DockStyle.Top;
                        map.Start();

                        mapPanel.Controls.Add(map);
                        noMapLabel.Visible = false;
                        processedArgs.Add(i);
                    }
                }
            }
        }
 public MappingStats(MapUserControl mapControl)
 {
     this.mapControl = mapControl;
     InitializeComponent();
     Translate.TranslateControl(this);
 }