Exemple #1
0
        public void ApplyHostModprobes()
        {
            Host = LoadHostModel();
            var launcher = new CommandLauncher();

            foreach (var modprobe in Host.Modprobes)
            {
                launcher.Launch(modprobe.SetCmd, modprobe.StoredValues);
            }
        }
Exemple #2
0
        public void ApplyHostBlacklistModules()
        {
            Host = LoadHostModel();
            var existing   = File.ReadAllLines("/etc/modprobe.d/blacklist.conf").Select(_ => _.Replace("blacklist", "").Trim());
            var configured = Host.ModulesBlacklist;
            var merge      = existing.Union(configured).ToArray();

            Host.ModulesBlacklist = merge;
            File.WriteAllLines("/etc/modprobe.d/blacklist.conf", Host.ModulesBlacklist.Select(_ => $"blacklist {_}"));
            Export(Host);
        }
Exemple #3
0
 public void SetHostRemoveModules(IEnumerable <string> modules)
 {
     Host = LoadHostModel();
     Host.RemoveModules = new HostParameter {
         SetCmd       = "modprobe",
         StoredValues = new Dictionary <string, string> {
             { "$package", string.Join(" ", modules) }
         }
     };
     Export(Host);
 }
Exemple #4
0
        public void ApplyNsSwitch()
        {
            Host = LoadHostModel();
            var existing   = File.ReadAllLines("/etc/nsswitch.conf");
            var configured = Host.NsSwitchContent;
            var merge      = existing.Union(configured).ToArray();

            Host.NsSwitchContent = merge;
            File.WriteAllLines("/etc/nsswitch.conf", Host.NsSwitchContent);
            Export(Host);
        }
Exemple #5
0
        public async Task <bool> Register()
        {
            var model = new HostModel {
                Host = _settings.UrlHost
            };
            var httpClient = Initialize();

            var response = await httpClient.PostAsJsonAsync("register", model);

            return(await response.Content.ReadAsAsync <bool>());
        }
Exemple #6
0
        public string[] GetHostModprobes()
        {
            Host = LoadHostModel();
            var result = new List <string>();

            foreach (Dictionary <string, string> dict in Host.Modprobes.Select(_ => _.StoredValues))
            {
                result.AddRange(dict.Select(_ => _.Value));
            }
            return(result.ToArray());
        }
Exemple #7
0
        //private void createWorkers(HostModel hwm)
        //{
        //    WorkerListModel _wlm = new WorkerListModel();
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(10000, 0, "sensors/temp", "Temp")));
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(10000, 0, "sensors/humidity", "Humidity")));
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(10000, 0, "sensors/light", "Light")));
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(10000, 0, "sensors/vdd3", "Voltage")));
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(10000, 0, "", "Ping")));
        //    _wlm.Workers.Add(new WorkerModel(hwm.Host, hwm.Host.Resource, hwm.Rate, new Resource(hwm.Rate, 1024, "data/buffer", "Troughput")));
        //    int i = 0;
        //    _wlm.Workers.OrderBy(x => x.Worker.MethodToRun.Method.Name);
        //    foreach (WorkerModel w in _wlm.Workers)
        //    {
        //        w.Worker._startTime = (w.Worker.Rate / _wlm.Workers.Count) * i++;
        //        Thread t = new Thread(w.Worker.Work);
        //        t.IsBackground = true;
        //        SharedData._threads.Add(t);
        //        t.Start();
        //        if (SharedData._running)
        //        {
        //            w.Worker.Run();
        //        }
        //    }
        //    _wlm.Workers.ToList().ForEach(x => SharedData._workerList.Workers.Add(x));
        //    hwm.Host.Running = false;
        //}

        private void removeWorkers(HostModel hwm)
        {
            List <WorkerModel> _wl = SharedData._workerList.Workers.ToList().FindAll(x => x.Worker.Host.IP.Equals(hwm.IP));

            foreach (WorkerModel _w in _wl)
            {
                _w.Worker.Stop();
                _w.Worker.Host.Running = false;
                SharedData._workerList.Workers.Remove(_w);
            }
        }
 public void SetOpeningHostStatus()
 {
     foreach (OpeningModel com in ComparedOpenings)
     {
         HostModel comparedHost = ComparedHosts.Where(e => e.ElementId.IntegerValue == com.HostId.IntegerValue).FirstOrDefault();
         if (comparedHost != null)
         {
             com.HostStatus = comparedHost.HostStatus;
         }
     }
 }
Exemple #9
0
 public RabbitMQ(HostModel hostModel)
 {
     // 创建连接工厂
     factory = new ConnectionFactory
     {
         UserName    = hostModel.UserName, //连接用户名
         Password    = hostModel.PassWord, //连接密码
         HostName    = "localhost",        //连接地址
         Port        = hostModel.Port,     //端口号
         VirtualHost = hostModel.VirtualHost
     };
 }
Exemple #10
0
 private void Remove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         HostModel host = SharedData._hostList.Hosts.SingleOrDefault(h => h.IP.Equals(((HostModel)host_list.SelectedItem).IP));
         SharedData._hostList.Hosts.Remove(host);
         removeWorkers(host);
     }
     catch (Exception)
     {
     }
 }
Exemple #11
0
        public HostInfoModel GetHostInfo()
        {
            Host = LoadHostModel();
            var host = new HostInfoModel {
                Name       = Host.HostName.StoredValues["$host_name"],
                Chassis    = Host.HostName.StoredValues["$host_chassis"],
                Deployment = Host.HostName.StoredValues["$host_deployment"],
                Location   = Host.HostName.StoredValues["$host_location"]
            };

            return(host);
        }
Exemple #12
0
 public void SetHostOsParameters(Dictionary <string, string> parameters)
 {
     Host = LoadHostModel();
     Host.OsParameters = parameters.Select(_ => new HostParameter {
         SetCmd       = "echo-write",
         StoredValues = new Dictionary <string, string> {
             { "$file", _.Key },
             { "$value", _.Value.Replace("\r", "") }
         }
     }).ToArray();
     Export(Host);
 }
Exemple #13
0
        public void ApplyHostInfo()
        {
            Host = LoadHostModel();
            var launcher = new CommandLauncher();

            launcher.Launch(Host.HostName.SetCmd, Host.HostName.StoredValues);
            launcher.Launch(Host.HostChassis.SetCmd, Host.HostChassis.StoredValues);
            launcher.Launch(Host.HostDeployment.SetCmd, Host.HostDeployment.StoredValues);
            launcher.Launch(Host.HostLocation.SetCmd, Host.HostLocation.StoredValues);
            var name = Host.HostName.StoredValues["$host_name"];

            File.WriteAllText("/etc/hostname", name);
        }
Exemple #14
0
 public void SetHostServices(IEnumerable <string> services)
 {
     Host          = LoadHostModel();
     Host.Services =
         services.Select(
             _ =>
             new HostParameter {
         SetCmd       = "systemctl-restart",
         StoredValues = new Dictionary <string, string> {
             { "$service", _ }
         }
     }).ToArray();
     Export(Host);
 }
Exemple #15
0
 public void SetHostModprobes(IEnumerable <string> modules)
 {
     Host           = LoadHostModel();
     Host.Modprobes =
         modules.Select(
             _ =>
             new HostParameter {
         SetCmd       = "modprobe",
         StoredValues = new Dictionary <string, string> {
             { "$package", _ }
         }
     }).ToArray();
     Export(Host);
 }
Exemple #16
0
        //格式化Rule数据
        private static JArray formatRuleData(ArrayList rules, string type)
        {
            JArray result = new JArray();

            for (int i = 0, len = rules.Count; i < len; i++)
            {
                //生成Json数据
                JObject temp = new JObject();

                if (type == "host")
                {
                    HostModel rule = rules[i] as HostModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("ip", rule.IP);
                    temp.Add("port", rule.Port);
                    temp.Add("url", rule.Url);
                }
                else if (type == "file")
                {
                    FileModel rule = rules[i] as FileModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("url", rule.Url);
                    temp.Add("path", rule.Path);
                }
                else if (type == "https")
                {
                    HttpsModel rule = rules[i] as HttpsModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("url", rule.Url);
                }
                else if (type == "header")
                {
                    HeaderModel rule = rules[i] as HeaderModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("type", rule.Type);
                    temp.Add("url", rule.Url);
                    temp.Add("key", rule.Key);
                    temp.Add("value", rule.Value);
                }
                //填充进数组中
                result.Add(temp);
            }

            return(result);
        }
Exemple #17
0
        public async Task <bool> UpdateItemAsync(HostModel item)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].HostName.Equals(item.HostName))
                {
                    items[i] = item;
                    break;
                }
            }

            await Store();

            return(await Task.FromResult(true));
        }
Exemple #18
0
        public override ConsoleResultModel Run()
        {
            var lst = new List <HostModel>();

            // double-check host access:
            if (User.IsSuperUser)
            {
                lst.Add(HostModel.Current());
            }

            return(new ConsoleResultModel(string.Empty)
            {
                Data = lst, Output = LocalizeString("Prompt_GetHost_OkMessage")
            });
        }
        public ConsoleResultModel Run()
        {
            List <HostModel> lst = new List <HostModel>();

            // double-check host access:
            if (base.User.IsSuperUser)
            {
                lst.Add(HostModel.Current());
            }

            return(new ConsoleResultModel(string.Empty)
            {
                data = lst
            });
        }
Exemple #20
0
        public async Task <bool> UnRegister(string serviceUrl)
        {
            var model = new HostModel {
                Host = serviceUrl
            };

            var httpClient = Initialize();

            var request = new HttpRequestMessage(HttpMethod.Delete, "register");

            request.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
            var response = await httpClient.SendAsync(request);

            return(await response.Content.ReadAsAsync <bool>());
        }
Exemple #21
0
        private void setInputText()
        {
            if (_parentIndex < 0 || _index < 0)
            {
                return;
            }

            //获取数据
            HostModel rule = Main.mainData.getRuleByIndex <HostModel>(_parentIndex, _index);

            //设置数据
            this.ip.Text   = rule.IP;
            this.port.Text = rule.Port;
            this.url.Text  = rule.Url;
        }
Exemple #22
0
 readonly string queueName;    ///队列名称
 public RabbitMQModel(HostModel model)
 {
     /// <summary>
     /// 创建连接工厂
     /// </summary>
     factory = new ConnectionFactory
     {
         UserName = model.UserName,
         Password = model.PassWord,
         HostName = "localhost",
         Port     = model.Port,
     };
     exchangeName = model.ExChangeModel.ExChangeName;
     routeKey     = model.ExChangeModel.RouteKey;
     queueName    = model.ExChangeModel.QueueName;
 }
Exemple #23
0
        private void initInputText()
        {
            //小于0代表是新增,直接返回
            if (_index < 0)
            {
                return;
            }

            //获取数据
            HostModel rule = Main.mainData[_index] as HostModel;

            //设置数据
            this.ip.Text   = rule.IP;
            this.port.Text = rule.Port;
            this.url.Text  = rule.Url;
        }
Exemple #24
0
        public static HostEntity ToEntity(this HostModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new HostEntity
            {
                Id = model.Id,
                IpAddress = model.IpAddress,
                MacAddress = model.MacAddress,
                Hostname = model.Hostname,
                Netmask = model.Netmask
            });
        }
Exemple #25
0
        //添加Rule控件
        public void addRuleToUI(BaseModel model)
        {
            string type = Main.mainData.type;
            //创建UI对象
            Label label = new Label();
            //Item控件
            Label item = null;

            if (type == "host")
            {
                //设置UI对象属性
                HostModel rule = model as HostModel;
                label.Template    = Resources["main_content_host"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.host.Children[rule.ParentIndex] as Label;
            }
            else if (type == "file")
            {
                //设置UI对象属性
                FileModel rule = model as FileModel;
                label.Template    = Resources["main_content_file"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.file.Children[rule.ParentIndex] as Label;
            }
            else if (type == "https")
            {
                //设置UI对象属性
                HttpsModel rule = model as HttpsModel;
                label.Template    = Resources["main_content_https"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.https.Children[rule.ParentIndex] as Label;
            }

            //首先执行一次ApplyTemplate,确保模板应用到了渲染树中
            item.ApplyTemplate();
            //获取对应的内容
            StackPanel content = item.Template.FindName("content", item) as StackPanel;

            //添加Rule控件
            content.Children.Add(label);
        }
Exemple #26
0
        private void addHostRule(object sender, MouseButtonEventArgs e)
        {
            string ip   = this.ip.Text;
            string port = this.port.Text;
            string url  = this.url.Text;

            if (ip.Length == 0)
            {
                Fiddler.FiddlerApplication.DoNotifyUser("请填写IP", "输入提示");
                return;
            }

            if (url.Length == 0)
            {
                Fiddler.FiddlerApplication.DoNotifyUser("请填写URL", "输入提示");
                return;
            }

            //生产参数
            JObject param = new JObject();

            param["ip"]   = ip;
            param["port"] = port;
            param["url"]  = url;

            if (_index >= 0 && _type != "copy")
            {
                //修改数据
                Main.mainData.modifyRuleByIndex(_parentIndex, _index, param);
            }
            else
            {
                //添加Rule数据
                HostModel rule = Main.mainData.addRuleToItem <HostModel>(_parentIndex, param);
                //添加UI
                Main.container.addRuleToUI(rule);
                //获取Item数据
                ItemModel item = Main.mainData.getItemByIndex(_parentIndex);
                //显示对应区域
                item.Show = true;
            }

            //关闭弹框
            (this.Parent as Window).Close();
        }
Exemple #27
0
 public ActionResult New()
 {
     try
     {
         ViewBag.Head = "New Staff";
         HostModel usr = new HostModel()
         {
             UserId = 0, Status = (int)HostModel.StatusTypes.Active
         };
         usr.SelectedSbEntity = new List <CLayer.SBEntity>();
         return(View("Edit", usr));
     }
     catch (Exception ex)
     {
         Common.LogHandler.HandleError(ex);
         return(Redirect("~/Admin/ErrorPage"));
     }
 }
 private void SetCloudHosts()
 {
     CloudHosts = new List <HostModel>();
     foreach (SerializedHostInfo shi in CloudHostsSerialized)
     {
         HostModel hostModel = new HostModel();
         hostModel.ElementId  = new ElementId(shi.ElementId);
         hostModel.HostStatus = shi.HostStatus;
         hostModel.HostType   = shi.HostType;
         BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
         XYZ            minBox         = new XYZ(shi.BoxMinX, shi.BoxMinY, shi.BoxMinZ);
         XYZ            maxBox         = new XYZ(shi.BoxMaxX, shi.BoxMaxY, shi.BoxMaxZ);
         boundingBoxXYZ.Min       = minBox;
         boundingBoxXYZ.Max       = maxBox;
         hostModel.BoundingBoxXYZ = boundingBoxXYZ;
         hostModel.Thickness      = shi.Thickness;
         CloudHosts.Add(hostModel);
     }
 }
Exemple #29
0
 public void ApplyNsResolv()
 {
     Host = LoadHostModel();
     if (!File.Exists("/etc/resolv.conf"))
     {
         File.WriteAllText("/etc/resolv.conf", "");
     }
     try {
         var existing   = File.ReadAllLines("/etc/resolv.conf");
         var configured = Host.NsResolvContent;
         var merge      = existing.Union(configured).ToArray();
         Host.NsResolvContent = merge;
         File.WriteAllLines("/etc/resolv.conf", Host.NsResolvContent);
         Export(Host);
     }
     catch (Exception) {
         return;
     }
 }
Exemple #30
0
        public HostEditPage(HostsViewModel viewModel, HostModel editHost)
        {
            InitializeComponent();

            hostsModel  = viewModel;
            addedOrEdit = editHost == null;
            Item        = editHost ?? new HostModel()
            {
                SSLVerify = true
            };
            ShowDeleteBtn      = !addedOrEdit;
            EnableEditHostName = addedOrEdit;

            foreach (var h in Item.LoadBalance)
            {
                LoadBalance.Add(h);
            }

            BindingContext = this;
        }