Ejemplo n.º 1
0
        private static void Procedures()
        {
            Logger.Info("[config] procedures");
            if (!Parameter.IsUnix)
            {
                return;
            }

            #region [    Users    ]
            var manageMaster = new ManageMaster();
            manageMaster.Setup();
            if (Parameter.IsUnix)
            {
                UserConfiguration.Import();
                UserConfiguration.Set();
            }
            Logger.Info("users config ready");
            #endregion

            #region [    Host Configuration    ]
            HostConfiguration.ApplyHostInfo();
            Logger.Info("host configured");
            #endregion

            #region [    Name Service    ]
            HostConfiguration.ApplyNsHosts();
            HostConfiguration.ApplyNsNetworks();
            HostConfiguration.ApplyNsResolv();
            HostConfiguration.ApplyNsSwitch();
            Logger.Info("name service ready");
            #endregion

            #region [    Network    ]
            NetworkConfiguration.Start();
            NetworkConfiguration.ApplyDefaultInterfaceSetting();
            #endregion

            #region [    Firewall    ]
            if (FirewallConfiguration.IsActive())
            {
                FirewallConfiguration.Set();
            }
            #endregion

            #region [    Dhcpd    ]
            if (DhcpdConfiguration.IsActive())
            {
                DhcpdConfiguration.Set();
            }
            #endregion

            #region [    Bind    ]
            if (BindConfiguration.IsActive())
            {
                BindConfiguration.Set();
            }
            #endregion
        }
Ejemplo n.º 2
0
        public AntdNetworkModule()
        {
            Get["/network"] = x => {
                var physicalInterfaces = NetworkConfiguration.InterfacePhysicalModel.ToList();
                var bridgeInterfaces   = NetworkConfiguration.InterfaceBridgeModel.ToList();
                var bondInterfaces     = NetworkConfiguration.InterfaceBondModel.ToList();
                var virtualInterfaces  = NetworkConfiguration.InterfaceVirtualModel.ToList();
                foreach (var vif in virtualInterfaces)
                {
                    if (physicalInterfaces.Any(_ => _.Interface == vif.Interface) ||
                        bridgeInterfaces.Any(_ => _.Interface == vif.Interface) ||
                        bondInterfaces.Any(_ => _.Interface == vif.Interface))
                    {
                        virtualInterfaces.Remove(vif);
                    }
                }
                var model = new PageNetworkModel {
                    NetworkPhysicalIf = physicalInterfaces,
                    NetworkBridgeIf   = bridgeInterfaces,
                    NetworkBondIf     = bondInterfaces,
                    NetworkVirtualIf  = virtualInterfaces,
                    NetworkIfList     = NetworkConfiguration.NetworkInterfaces
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/network/restart"] = x => {
                NetworkConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/network/interface"] = x => {
                string Interface    = Request.Form.Interface;
                string mode         = Request.Form.Mode;
                string status       = Request.Form.Status;
                string staticAddres = Request.Form.StaticAddres;
                string staticRange  = Request.Form.StaticRange;
                string txqueuelen   = Request.Form.Txqueuelen;
                string mtu          = Request.Form.Mtu;
                string route        = Request.Form.Route;
                string gateway      = Request.Form.Gateway;
                var    model        = new NetworkInterfaceConfigurationModel {
                    Interface     = Interface,
                    Mode          = (NetworkInterfaceMode)Enum.Parse(typeof(NetworkInterfaceMode), mode),
                    Status        = (NetworkInterfaceStatus)Enum.Parse(typeof(NetworkInterfaceStatus), status),
                    StaticAddress = staticAddres,
                    StaticRange   = staticRange,
                    Txqueuelen    = txqueuelen,
                    Mtu           = mtu,
                    Type          = NetworkAdapterType.Physical,
                    Route         = route,
                    Gateway       = gateway
                };
                NetworkConfiguration.AddInterfaceSetting(model);
                return(HttpStatusCode.OK);
            };

            Post["/network/interface/del"] = x => {
                string guid = Request.Form.Guid;
                NetworkConfiguration.RemoveInterfaceSetting(guid);
                return(HttpStatusCode.OK);
            };

            Post["/network/interface/bridge"] = x => {
                string Interface    = Request.Form.Interface;
                string mode         = Request.Form.Mode;
                string status       = Request.Form.Status;
                string staticAddres = Request.Form.StaticAddres;
                string staticRange  = Request.Form.StaticRange;
                string txqueuelen   = Request.Form.Txqueuelen;
                string mtu          = Request.Form.Mtu;
                string ifs          = Request.Form.InterfaceList;
                string route        = Request.Form.Route;
                string gateway      = Request.Form.Gateway;
                var    ifList       = ifs.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                CommandLauncher.Launch("brctl-add", new Dictionary <string, string> {
                    { "$bridge", Interface }
                });
                foreach (var nif in ifList)
                {
                    CommandLauncher.Launch("brctl-add-if", new Dictionary <string, string> {
                        { "$bridge", Interface }, { "$net_if", nif }
                    });
                }
                var model = new NetworkInterfaceConfigurationModel {
                    Interface     = Interface,
                    Mode          = (NetworkInterfaceMode)Enum.Parse(typeof(NetworkInterfaceMode), mode),
                    Status        = (NetworkInterfaceStatus)Enum.Parse(typeof(NetworkInterfaceStatus), status),
                    StaticAddress = staticAddres,
                    StaticRange   = staticRange,
                    Txqueuelen    = txqueuelen,
                    Mtu           = mtu,
                    Type          = NetworkAdapterType.Bridge,
                    InterfaceList = ifList,
                    Route         = route,
                    Gateway       = gateway
                };
                NetworkConfiguration.AddInterfaceSetting(model);
                return(HttpStatusCode.OK);
            };

            Post["/network/interface/bond"] = x => {
                string Interface    = Request.Form.Interface;
                string mode         = Request.Form.Mode;
                string status       = Request.Form.Status;
                string staticAddres = Request.Form.StaticAddres;
                string staticRange  = Request.Form.StaticRange;
                string txqueuelen   = Request.Form.Txqueuelen;
                string mtu          = Request.Form.Mtu;
                string ifs          = Request.Form.InterfaceList;
                string route        = Request.Form.Route;
                string gateway      = Request.Form.Gateway;
                var    ifList       = ifs.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                CommandLauncher.Launch("bond-set", new Dictionary <string, string> {
                    { "$bond", Interface }
                });
                foreach (var nif in ifList)
                {
                    CommandLauncher.Launch("bond-add-if", new Dictionary <string, string> {
                        { "$bond", Interface }, { "$net_if", nif }
                    });
                }
                var model = new NetworkInterfaceConfigurationModel {
                    Interface     = Interface,
                    Mode          = (NetworkInterfaceMode)Enum.Parse(typeof(NetworkInterfaceMode), mode),
                    Status        = (NetworkInterfaceStatus)Enum.Parse(typeof(NetworkInterfaceStatus), status),
                    StaticAddress = staticAddres,
                    StaticRange   = staticRange,
                    Txqueuelen    = txqueuelen,
                    Mtu           = mtu,
                    Type          = NetworkAdapterType.Bond,
                    InterfaceList = ifList,
                    Route         = route,
                    Gateway       = gateway
                };
                NetworkConfiguration.AddInterfaceSetting(model);
                return(HttpStatusCode.OK);
            };
        }