private void fillNodesInDropDown() { if (selectedNode != null) { return; } MeshClass mesh = (MeshClass)groupComboBox.SelectedItem; // Fill the nodes dropdown nodeComboBox.Items.Clear(); if (meshcentral.nodes != null) { foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; if (((node.meshid == mesh.meshid) || ((mesh.meshid == null) && (meshcentral.userRights.ContainsKey(node.nodeid)))) && ((node.conn & 1) != 0)) { nodeComboBox.Items.Add(node); } } } if (nodeComboBox.Items.Count > 0) { nodeComboBox.SelectedIndex = 0; } }
private void AddPortMapForm_Load(object sender, EventArgs e) { // Fill the groups groupComboBox.Items.Clear(); foreach (string meshid in meshcentral.meshes.Keys) { MeshClass mesh = meshcentral.meshes[meshid]; if (mesh.type == 2) { int nodeCount = 0; foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; if ((node.meshid == mesh.meshid) && ((node.conn & 1) != 0)) { nodeCount++; } } if (nodeCount > 0) { groupComboBox.Items.Add(mesh); } } } // Set default selection if (groupComboBox.Items.Count > 0) { groupComboBox.SelectedIndex = 0; } appComboBox.SelectedIndex = 1; fillNodesInDropDown(); }
private void fillNodesInDropDown() { MeshClass mesh = (MeshClass)groupComboBox.SelectedItem; // Fill the nodes dropdown nodeComboBox.Items.Clear(); foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; if ((node.meshid == mesh.meshid) && ((node.conn & 1) != 0)) { nodeComboBox.Items.Add(node); } } if (nodeComboBox.Items.Count > 0) { nodeComboBox.SelectedIndex = 0; } }
private void AddRelayMapForm_Load(object sender, EventArgs e) { if (selectedNode == null) { // Fill the groups groupComboBox.Items.Clear(); foreach (string meshid in meshcentral.meshes.Keys) { MeshClass mesh = meshcentral.meshes[meshid]; if (mesh.type == 2) { int nodeCount = 0; foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; if ((node.meshid == mesh.meshid) && ((node.conn & 1) != 0)) { nodeCount++; } } if (nodeCount > 0) { groupComboBox.Items.Add(mesh); } } } // If the user has indivitual device rights, add an extra device group if (meshcentral.userRights != null) { bool indivitualDevices = false; foreach (string id in meshcentral.userRights.Keys) { if (id.StartsWith("node/")) { indivitualDevices = true; } } if (indivitualDevices) { MeshClass m = new MeshClass(); m.name = Properties.Resources.IndividualDevices; groupComboBox.Items.Add(m); } } // Set default selection if (groupComboBox.Items.Count > 0) { groupComboBox.SelectedIndex = 0; } appComboBox.SelectedIndex = 1; fillNodesInDropDown(); } else { if (selectedNode.mesh == null) { MeshClass m = new MeshClass(); m.name = Properties.Resources.IndividualDevices; groupComboBox.Items.Add(m); } else { groupComboBox.Items.Add(selectedNode.mesh); } groupComboBox.SelectedIndex = 0; groupComboBox.Enabled = false; nodeComboBox.Items.Add(selectedNode); nodeComboBox.SelectedIndex = 0; nodeComboBox.Enabled = false; appComboBox.SelectedIndex = 1; } nameTextBox.Focus(); }
public void processServerData(string data) { if (debug) { File.AppendAllText("debug.log", "ServerData-" + data + "\r\n"); } // Parse the received JSON Dictionary <string, object> jsonAction = new Dictionary <string, object>(); jsonAction = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(data); if (jsonAction == null || jsonAction["action"].GetType() != typeof(string)) { return; } string action = jsonAction["action"].ToString(); switch (action) { case "close": { disconnectCause = jsonAction["cause"].ToString(); disconnectMsg = jsonAction["msg"].ToString(); if (jsonAction.ContainsKey("email2fa")) { disconnectEmail2FA = (bool)jsonAction["email2fa"]; } else { disconnectEmail2FA = false; } if (jsonAction.ContainsKey("email2fasent")) { disconnectEmail2FASent = (bool)jsonAction["email2fasent"]; } else { disconnectEmail2FASent = false; } break; } case "serverinfo": { wc.WriteStringWebSocket("{\"action\":\"meshes\"}"); wc.WriteStringWebSocket("{\"action\":\"nodes\"}"); wc.WriteStringWebSocket("{\"action\":\"authcookie\"}"); wc.WriteStringWebSocket("{\"action\":\"logincookie\"}"); break; } case "authcookie": { authCookie = jsonAction["cookie"].ToString(); changeState(2); break; } case "logincookie": { loginCookie = jsonAction["cookie"].ToString(); if (onLoginTokenChanged != null) { onLoginTokenChanged(); } break; } case "userinfo": { Dictionary <string, object> userinfo = (Dictionary <string, object>)jsonAction["userinfo"]; userid = (string)userinfo["_id"]; break; } case "event": { Dictionary <string, object> ev = (Dictionary <string, object>)jsonAction["event"]; string action2 = ev["action"].ToString(); switch (action2) { case "meshchange": { // Get the new values string meshid = ev["meshid"].ToString(); string meshname = (string)ev["name"]; string meshdesc = (string)ev["desc"]; int meshtype = (int)ev["mtype"]; ulong meshrights = 0; Dictionary <string, object> links = ((Dictionary <string, object>)ev["links"]); if (links.ContainsKey(userid)) { Dictionary <string, object> urights = ((Dictionary <string, object>)links[userid]); if (urights != null) { if (urights["rights"].GetType() == typeof(int)) { meshrights = (ulong)((int)urights["rights"]); } if (urights["rights"].GetType() == typeof(Int64)) { meshrights = (ulong)((Int64)urights["rights"]); } } } // Update the mesh if (meshes.ContainsKey(meshid)) { MeshClass mesh = (MeshClass)meshes[meshid]; mesh.name = meshname; mesh.desc = meshdesc; mesh.rights = meshrights; } else { MeshClass mesh = new MeshClass(); mesh.name = meshname; mesh.desc = meshdesc; mesh.rights = meshrights; mesh.type = meshtype; meshes[meshid] = mesh; } wc.WriteStringWebSocket("{\"action\":\"nodes\"}"); if (onNodesChanged != null) { onNodesChanged(); } break; } case "changenode": { Dictionary <string, object> node = (Dictionary <string, object>)ev["node"]; string nodeid = (string)node["_id"]; if (nodes.ContainsKey(nodeid)) { // Change existing node lock (nodes) { NodeClass n = (NodeClass)nodes[nodeid]; n.name = (string)node["name"]; if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } n.icon = (int)node["icon"]; if (node.ContainsKey("rdpport")) { n.rdpport = (int)node["rdpport"]; } ulong nodeRights = 0; if (node.ContainsKey("links")) { Dictionary <string, object> links = ((Dictionary <string, object>)node["links"]); if (links.ContainsKey(userid)) { Dictionary <string, object> linksEx = ((Dictionary <string, object>)links[userid]); if (linksEx.ContainsKey("rights")) { nodeRights = (ulong)(int)linksEx["rights"]; } } } n.rights = nodeRights; if ((n.rights == 0) && (meshes.ContainsKey(n.meshid) == false)) { // We have no rights to this device, remove it nodes.Remove(n.nodeid); } else { // Update the node nodes[n.nodeid] = n; } } if (onNodesChanged != null) { onNodesChanged(); } } else { wc.WriteStringWebSocket("{\"action\":\"nodes\"}"); } break; } case "nodeconnect": { string nodeid = (string)ev["nodeid"]; if (nodes.ContainsKey(nodeid)) { lock (nodes) { NodeClass n = (NodeClass)nodes[nodeid]; if (ev.ContainsKey("conn")) { n.conn = (int)ev["conn"]; } nodes[n.nodeid] = n; } if (onNodesChanged != null) { onNodesChanged(); } } break; } } break; } case "meshes": { meshes = new Dictionary <string, MeshClass>(); ArrayList meshList = (ArrayList)jsonAction["meshes"]; for (int i = 0; i < meshList.Count; i++) { Dictionary <string, object> mesh = (Dictionary <string, object>)meshList[i]; MeshClass m = new MeshClass(); m.meshid = (string)mesh["_id"]; m.name = (string)mesh["name"]; m.desc = (string)mesh["desc"]; m.rights = 0; Dictionary <string, object> links = ((Dictionary <string, object>)mesh["links"]); if (links.ContainsKey(userid)) { Dictionary <string, object> urights = ((Dictionary <string, object>)links[userid]); if (urights != null) { if (urights["rights"].GetType() == typeof(int)) { m.rights = (ulong)((int)urights["rights"]); } if (urights["rights"].GetType() == typeof(Int64)) { m.rights = (ulong)((Int64)urights["rights"]); } } } if (mesh["mtype"].GetType() == typeof(string)) { m.type = int.Parse((string)mesh["mtype"]); } if (mesh["mtype"].GetType() == typeof(int)) { m.type = (int)mesh["mtype"]; } meshes[m.meshid] = m; } break; } case "nodes": { if (nodes == null) { nodes = new Dictionary <string, NodeClass>(); } Dictionary <string, NodeClass> nodes2 = new Dictionary <string, NodeClass>(); lock (nodes) { Dictionary <string, object> groups = (Dictionary <string, object>)jsonAction["nodes"]; foreach (string meshid in groups.Keys) { ArrayList nodesinMesh = (ArrayList)groups[meshid]; for (int i = 0; i < nodesinMesh.Count; i++) { Dictionary <string, object> node = (Dictionary <string, object>)nodesinMesh[i]; string nodeid = (string)node["_id"]; if (nodes.ContainsKey(nodeid)) { NodeClass n = (NodeClass)nodes[nodeid]; n.nodeid = nodeid; if (node.ContainsKey("agent")) { n.agentid = (int)((Dictionary <string, object>)node["agent"])["id"]; } else { n.agentid = -1; } n.name = (string)node["name"]; n.meshid = meshid; if (node.ContainsKey("rdpport")) { n.rdpport = (int)node["rdpport"]; } else { n.rdpport = 3389; } if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } else { n.conn = 0; } if (node.ContainsKey("icon")) { n.icon = (int)node["icon"]; } n.rights = 0; if (node.ContainsKey("links")) { Dictionary <string, object> links = ((Dictionary <string, object>)node["links"]); if (links.ContainsKey(userid)) { Dictionary <string, object> linksEx = ((Dictionary <string, object>)links[userid]); if (linksEx.ContainsKey("rights")) { n.rights = (ulong)(int)linksEx["rights"]; } } } nodes2[n.nodeid] = n; } else { NodeClass n = new NodeClass(); n.nodeid = nodeid; if (node.ContainsKey("agent")) { n.agentid = (int)((Dictionary <string, object>)node["agent"])["id"]; } else { n.agentid = -1; } n.name = (string)node["name"]; n.meshid = meshid; if (node.ContainsKey("rdpport")) { n.rdpport = (int)node["rdpport"]; } else { n.rdpport = 3389; } if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } else { n.conn = 0; } if (node.ContainsKey("icon")) { n.icon = (int)node["icon"]; } n.rights = 0; if (node.ContainsKey("links")) { Dictionary <string, object> links = ((Dictionary <string, object>)node["links"]); if (links.ContainsKey(userid)) { Dictionary <string, object> linksEx = ((Dictionary <string, object>)links[userid]); if (linksEx.ContainsKey("rights")) { n.rights = (ulong)(int)linksEx["rights"]; } } } nodes2[n.nodeid] = n; } } } } nodes = nodes2; if (onNodesChanged != null) { onNodesChanged(); } break; } default: { break; } } }
public void processServerData(string data) { if (debug) { File.AppendAllText("debug.log", "ServerData-" + data + "\r\n"); } // Parse the received JSON Dictionary <string, object> jsonAction = new Dictionary <string, object>(); jsonAction = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(data); if (jsonAction == null || jsonAction["action"].GetType() != typeof(string)) { return; } string action = jsonAction["action"].ToString(); switch (action) { case "close": { disconnectCause = jsonAction["cause"].ToString(); disconnectMsg = jsonAction["msg"].ToString(); break; } case "serverinfo": { wc.WriteStringWebSocket("{\"action\":\"meshes\"}"); wc.WriteStringWebSocket("{\"action\":\"nodes\"}"); wc.WriteStringWebSocket("{\"action\":\"authcookie\"}"); wc.WriteStringWebSocket("{\"action\":\"logincookie\"}"); break; } case "authcookie": { authCookie = jsonAction["cookie"].ToString(); changeState(2); break; } case "logincookie": { loginCookie = jsonAction["cookie"].ToString(); if (onLoginTokenChanged != null) { onLoginTokenChanged(); } break; } case "userinfo": { break; } case "event": { Dictionary <string, object> ev = (Dictionary <string, object>)jsonAction["event"]; string action2 = ev["action"].ToString(); switch (action2) { case "changenode": { Dictionary <string, object> node = (Dictionary <string, object>)ev["node"]; string nodeid = (string)node["_id"]; if (nodes.ContainsKey(nodeid)) { NodeClass n = (NodeClass)nodes[nodeid]; n.nodeid = (string)node["_id"]; n.name = (string)node["name"]; if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } n.icon = (int)node["icon"]; nodes[n.nodeid] = n; if (onNodesChanged != null) { onNodesChanged(); } } break; } case "nodeconnect": { string nodeid = (string)ev["nodeid"]; if (nodes.ContainsKey(nodeid)) { NodeClass n = (NodeClass)nodes[nodeid]; if (ev.ContainsKey("conn")) { n.conn = (int)ev["conn"]; } nodes[n.nodeid] = n; if (onNodesChanged != null) { onNodesChanged(); } } break; } } break; } case "meshes": { meshes = new Dictionary <string, MeshClass>(); ArrayList meshList = (ArrayList)jsonAction["meshes"]; for (int i = 0; i < meshList.Count; i++) { Dictionary <string, object> mesh = (Dictionary <string, object>)meshList[i]; MeshClass m = new MeshClass(); m.meshid = (string)mesh["_id"]; m.name = (string)mesh["name"]; m.desc = (string)mesh["desc"]; if (mesh["mtype"].GetType() == typeof(string)) { m.type = int.Parse((string)mesh["mtype"]); } if (mesh["mtype"].GetType() == typeof(int)) { m.type = (int)mesh["mtype"]; } meshes[m.meshid] = m; } break; } case "nodes": { nodes = new Dictionary <string, NodeClass>(); Dictionary <string, object> groups = (Dictionary <string, object>)jsonAction["nodes"]; foreach (string meshid in groups.Keys) { ArrayList nodesinMesh = (ArrayList)groups[meshid]; for (int i = 0; i < nodesinMesh.Count; i++) { Dictionary <string, object> node = (Dictionary <string, object>)nodesinMesh[i]; NodeClass n = new NodeClass(); n.nodeid = (string)node["_id"]; n.name = (string)node["name"]; n.meshid = meshid; if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } else { n.conn = 0; } n.icon = (int)node["icon"]; nodes[n.nodeid] = n; } } if (onNodesChanged != null) { onNodesChanged(); } break; } default: { break; } } }