Esempio n. 1
0
        public override void DoJob()
        {
            if (Application.CurrentConfiguration.Cluster.Active == false)
            {
                return;
            }
            var clusterStatus = Application.ClusterChecklist;

            if (clusterStatus == null)
            {
                return;
            }
            if (clusterStatus.Length < 1)
            {
                return;
            }
            var nodesKnownHosts = new List <KnownHost>();

            for (var i = 0; i < clusterStatus.Length; i++)
            {
                var nodeIPs     = clusterStatus[i].DiscoveredIpsReach;
                var nodeName    = clusterStatus[i].Hostname;
                var commonNames = new string[] {
                    CommonString.Append(nodeName, "int", i.ToString())
                };
                for (var p = 0; p < nodeIPs.Length; p++)
                {
                    var knownHost = new KnownHost()
                    {
                        IpAddr      = nodeIPs[p].IpAddress,
                        CommonNames = commonNames
                    };
                    nodesKnownHosts.Add(knownHost);
                }
            }
            var currentKnownHosts = Application.CurrentConfiguration.Network.KnownHosts.ToList();

            foreach (var nodeHost in nodesKnownHosts)
            {
                //i casi possono essere tre:
                //  1) l'ip non è presente nella CurrentConfiguration   -> aggiungo il nuovo KnownHost
                //  2) l'ip è presente ma i CommonNames sono differenti -> aggiorno solamente i CommonNames del KnownHost corrispondente
                //  3) l'ip è presente e i CommonNames coincidono       -> non faccio nulla
                if (!currentKnownHosts.Any(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true))
                {
                    currentKnownHosts.Add(nodeHost);
                }
                else
                {
                    var existingCn = currentKnownHosts.FirstOrDefault(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true).CommonNames;
                    if (CommonString.AreEquals(CommonString.Build(existingCn), CommonString.Build(nodeHost.CommonNames)) == false)
                    {
                        currentKnownHosts.FirstOrDefault(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true).CommonNames = nodeHost.CommonNames;
                    }
                }
            }
            Application.CurrentConfiguration.Network.KnownHosts = currentKnownHosts.ToArray();
            ConfigRepo.Save();
            Dns.Set();
        }
Esempio n. 2
0
        public DnsModule() : base("/dns")
        {
            Post["/apply"] = x => {
                Dns.Set();
                return(HttpStatusCode.OK);
            };

            Post["/set/resolv"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <DnsClientConfiguration>(data);
                Application.CurrentConfiguration.Network.KnownDns = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/set/hosts"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <KnownHost[]>(data);
                Application.CurrentConfiguration.Network.KnownHosts = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/set/networks"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <KnownNetwork[]>(data);
                Application.CurrentConfiguration.Network.KnownNetworks = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };
        }
Esempio n. 3
0
        public NetworkModule() : base("/network")
        {
            Get["/primarydomain"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.PrimaryDomain));
            };

            Get["/knowndns"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.KnownDns));
            };

            Get["/knownhosts"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.KnownHosts));
            };

            Get["/knownnetworks"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.KnownNetworks));
            };

            Get["/internalnetwork"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.InternalNetwork));
            };

            Get["/externalnetwork"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.ExternalNetwork));
            };

            Get["/networkinterfaces"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.NetworkInterfaces));
            };

            Get["/routingtables"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.RoutingTables));
            };

            Get["/routing"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.Routing));
            };

            Get["/devices"] = x => {
                return(JsonConvert.SerializeObject(cmds.Network.GetAllNames()));
            };

            Get["/devices/addr"] = x => {
                return(JsonConvert.SerializeObject(cmds.Network.GetAllLocalAddress()));
            };

            Get["/interfaces"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.NetworkInterfaces));
            };

            Get["/default/hosts"] = x => {
                return(JsonConvert.SerializeObject(Dns.DefaultHosts));
            };

            Get["/default/networks"] = x => {
                return(JsonConvert.SerializeObject(Dns.DefaultNetworks));
            };

            Get["/tuns"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.Tuns));
            };

            Get["/taps"] = x => {
                return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Network.Taps));
            };

            Post["/save/knowndns"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <DnsClientConfiguration>(data);
                Application.CurrentConfiguration.Network.KnownDns = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/knownhosts"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <KnownHost[]>(data);
                Application.CurrentConfiguration.Network.KnownHosts = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/knownnetworks"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <KnownNetwork[]>(data);
                Application.CurrentConfiguration.Network.KnownNetworks = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/internalnetwork"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <SubNetwork>(data);
                Application.CurrentConfiguration.Network.InternalNetwork = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/externalnetwork"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <SubNetwork>(data);
                Application.CurrentConfiguration.Network.ExternalNetwork = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/networkinterfaces"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetInterface[]>(data);
                Application.CurrentConfiguration.Network.NetworkInterfaces = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/routingtables"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetRoutingTable[]>(data);
                Application.CurrentConfiguration.Network.RoutingTables = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/routing"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetRoute[]>(data);
                Application.CurrentConfiguration.Network.Routing = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/interfaces"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetInterface[]>(data);
                Application.CurrentConfiguration.Network.NetworkInterfaces = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/tuns"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetTun[]>(data);
                Application.CurrentConfiguration.Network.Tuns = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/save/taps"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <NetTap[]>(data);
                Application.CurrentConfiguration.Network.Taps = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };

            Post["/apply/knowndns"] = x => {
                Dns.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/knownhosts"] = x => {
                Dns.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/knownnetworks"] = x => {
                Dns.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/internalnetwork"] = x => {
                return(HttpStatusCode.OK);
            };

            Post["/apply/externalnetwork"] = x => {
                return(HttpStatusCode.OK);
            };

            Post["/apply/networkinterfaces"] = x => {
                cmds.Network.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/routingtables"] = x => {
                Route.SetRoutingTable();
                return(HttpStatusCode.OK);
            };

            Post["/apply/routing"] = x => {
                Route.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/interfaces"] = x => {
                cmds.Network.Set();
                return(HttpStatusCode.OK);
            };

            Post["/apply/tuns"] = x => {
                cmds.Network.SetTuns();
                return(HttpStatusCode.OK);
            };

            Post["/apply/taps"] = x => {
                cmds.Network.SetTaps();
                return(HttpStatusCode.OK);
            };
        }