public List <P2PBackup.Common.Node> GetNodesHavingPlugin(int?groupId, string pluginName) { List <P2PBackup.Common.Node> nodes = new DAL.NodeDAO(sessionUser).GetAllHavingPlugin(groupId, pluginName); foreach (P2PBackup.Common.Node n in nodes) { if (Hub.NodesList.Contains(n.Id)) { n.Status = NodeStatus.Idle; } } return(nodes); }
/*[PrincipalPermission(SecurityAction.Demand, Role="SuperViewer")] * [PrincipalPermission(SecurityAction.Demand, Role="Admin")] * [PrincipalPermission(SecurityAction.Demand, Role="SuperAdmin")]*/ public List <P2PBackup.Common.Node> GetNodes(int?groupId) { List <P2PBackup.Common.Node> nodes = new DAL.NodeDAO(sessionUser).GetAll(groupId); foreach (P2PBackup.Common.Node n in nodes) { if (Hub.NodesList.Contains(n.Id)) { n.Status = Hub.NodesList.GetById(n.Id).Status; } } return(nodes); }
private PeerNode CreateNewNode(string ip, NodeCertificate cert) { var node = new PeerNode(); node.Name = Dns.GetHostEntry(ip).HostName; node.IP = ip; node.Locked = true; node.Status = NodeStatus.New; node = new DAL.NodeDAO().Save(node); cert.NodeId = node.Id; cert = new DAL.CertificateDAO().Save(cert); Logger.Append("HUBRN", Severity.INFO, "Created new node #" + node.Id + " with cert #" + cert.Id + " for client " + ip); return(node); }
private PeerNode AuthenticateNode(SslStream clientSslStream, Socket clientSocket) { string nodeIP = clientSocket.RemoteEndPoint.ToString().Split(':')[0]; // if cert is empty or come with the default/harcoded hash, this a new node. // Generate and send him a certificate if (clientSslStream.RemoteCertificate == null || clientSslStream.RemoteCertificate.GetCertHashString() == "3EE15BE077586D9CB9AEC105AE8AB0613ED6C34B") { //TODO : make certmanager directly return an X509Certificate2 //TODO : store the whole cert into a 'Password' structure (need private key if client // node is lost (or its certificate is lost), or to do cross-restores Mono.Security.X509.PKCS12 newCert = GenerateNewClientCertificate(nodeIP); // new node, unknown by hub. let's add it in "pending for approval" status var x509cert2 = new System.Security.Cryptography.X509Certificates.X509Certificate2(); x509cert2.Import(newCert.Certificates[0].RawData, "", System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.PersistKeySet | System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable); var u = CreateNewNode(nodeIP, new NodeCertificate(x509cert2)); u.SetSockets(clientSslStream, clientSocket); u.SendCertificate(newCert.GetBytes()); u.Disconnect(); return(null); } X509Certificate2 remoteCert = new X509Certificate2(clientSslStream.RemoteCertificate); PeerNode node = new DAL.NodeDAO().NodeApproved(remoteCert.GetSerialNumber()); node.IP = nodeIP; if (node != null) { Logger.Append("HUBRN", Severity.TRIVIA, "Newly connected node : Id=" + node.Id + ", NodeName=" + node.Name + ",IP=" + node.IP + ", status=" + node.Status); if (!node.Locked) { node.Status = NodeStatus.Idle; } else { node.Status = NodeStatus.Locked; // pending for manual approval Logger.Append("HUBRN", Severity.NOTICE, "Newly connected node #" + node.Id + " is locked."); } } node.SetSockets(clientSslStream, clientSocket); node.SendAuthStatus(); return(node); }
/// <summary> /// Delete the specified NodeGroup. /// Also update any member node to point to 'no group' (id = -1) /// </summary> /// <param name="ng">Ng.</param> public void Delete(NodeGroup ng) { if (ng.Id <= 0) // prevent deleting 'default' and 'no group' groups { throw new ArgumentOutOfRangeException("Cannot delete a Group with Id < 0"); } var nodeDao = new NodeDAO(sessionUser); var memberNodes = nodeDao.GetAll(ng.Id); foreach (Node n in memberNodes) { n.Group = -1; nodeDao.Update(n); } using (dbc = DAL.Instance.GetDb()){ dbc.Delete <NodeGroup>(ng); } }
internal static List <P2PBackup.Common.Node> DiscoverVms(int hypervisorId) { List <P2PBackup.Common.Node> newNodes = new List <P2PBackup.Common.Node>(); using (P2PBackupHub.Virtualization.HypervisorManager hvm = new P2PBackupHub.Virtualization.HypervisorManager()){ Hypervisor hv = new DAL.HypervisorDAO().GetById(hypervisorId); hvm.Id = hv.Id; hvm.Kind = hv.Kind; hvm.Url = hv.Url; hvm.UserName = hv.UserName; hvm.Password = hv.Password; hv.LastDiscover = DateTime.Now; new DAL.HypervisorDAO().Update(hv); Console.WriteLine("DiscoverVms() 0"); List <P2PBackup.Common.Node> discoveredNodes = hvm.Discover(); Console.WriteLine("DiscoverVms() 1"); Logger.Append("HUBRN", Severity.DEBUG, "Discovered " + discoveredNodes.Count + " VMs"); foreach (P2PBackup.Common.Node newN in discoveredNodes) { Console.WriteLine("DiscoverVms() 3, cur newn=" + newN.Name); try{ P2PBackup.Common.Node existingNode = new DAL.NodeDAO().GetByInternalId(newN.InternalId); Console.WriteLine("DiscoverVms() 3.1"); if (existingNode == null) { Logger.Append("HUBRN", Severity.DEBUG, "The VM " + newN.Name + " has been added to the client nodes."); newN.Hypervisor = hypervisorId; existingNode = new DAL.NodeDAO().Save((PeerNode)newN); if (existingNode != null) { existingNode.Status = NodeStatus.New; newNodes.Add(existingNode); } } } catch (Exception e) { Logger.Append("HUBRN", Severity.ERROR, "Could not add new discovered node : " + e.ToString()); } } } return(newNodes); }