Ejemplo n.º 1
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            //首页获取搜索栏
            Dictionary <string, string> pm = new Dictionary <string, string>();

            pm.Add("email", loginUserEmail);
            pm.Add("timestamp", SecurityUtil.GetTimestamp());
            string sign = SecurityUtil.CreateSign(pm);

            pm.Add("sign", sign);
            string result = HttpUtil.SendGet(ConstantUrl.agentConditionUrl, pm);

            if (!string.IsNullOrEmpty(result))
            {
                IDictionary <string, List <string> > data = JsonConvert.DeserializeObject <IDictionary <string, List <string> > >(result);
                List <string> mainNameList = new List <string>();
                mainNameList.Add("一级分类");
                mainNameList.AddRange(data["mainNameList"]);
                this.mainNameBox.DataSource    = mainNameList;
                this.mainNameBox.SelectedIndex = 0;

                List <string> subNameList = new List <string>();
                subNameList.Add("二级分类");
                subNameList.AddRange(data["subNameList"]);
                this.subNameBox.DataSource    = subNameList;
                this.subNameBox.SelectedIndex = 0;

                List <string> managerList = new List <string>();
                managerList.Add("管理员");
                managerList.AddRange(data["managerList"]);
                this.managerBox.DataSource    = managerList;
                this.managerBox.SelectedIndex = 0;

                this.searchTypeBox.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("查询异常,请联系管理员!", "提示");
                return;
            }

            Dictionary <string, string> pm2 = new Dictionary <string, string>();

            pm2.Add("email", loginUserEmail);
            pm2.Add("timestamp", SecurityUtil.GetTimestamp());
            string sign2 = SecurityUtil.CreateSign(pm2);

            pm2.Add("sign", sign2);
            string result2 = HttpUtil.SendGet(ConstantUrl.agentListUrl, pm2);

            if (!string.IsNullOrEmpty(result2))
            {
                List <AgentInfo> data2 = JsonConvert.DeserializeObject <List <AgentInfo> >(result2);
                DataTable        dt    = DataTableExtensions.ToDataTable(data2);
                this.agentDataGrid.DataSource = dt;
            }
            else
            {
                MessageBox.Show("查询异常,请联系管理员!", "提示");
            }
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //搜索
            Dictionary <string, string> pm = new Dictionary <string, string>();

            pm.Add("timestamp", SecurityUtil.GetTimestamp());
            pm.Add("email", loginUserEmail);

            string mainName = mainNameBox.Text;

            if (!"一级分类".Equals(mainName) && !"".Equals(mainName))
            {
                pm.Add("mainName", mainName);
            }

            string subName = subNameBox.Text;

            if (!"二级分类".Equals(subName) && !"".Equals(subName))
            {
                pm.Add("subName", subName);
            }

            string manager = managerBox.Text;

            if (!"管理员".Equals(manager) && !"".Equals(manager))
            {
                pm.Add("manager", manager);
            }

            string searchType    = searchTypeBox.Text;
            string searchContent = searchContentTxt.Text;

            if (!"".Equals(searchContent))
            {
                if ("IP".Equals(searchType))
                {
                    pm.Add("agentIp", searchContent);
                }
                else if ("资产名称".Equals(searchType))
                {
                    pm.Add("agentName", searchContent);
                }
                else if ("资产号".Equals(searchType))
                {
                    pm.Add("asset", searchContent);
                }
                else
                {
                    //不搜索
                }
            }

            string sign = SecurityUtil.CreateSign(pm);

            pm.Add("sign", sign);

            string result = HttpUtil.SendPost(ConstantUrl.agentListUrl, pm);

            if (!string.IsNullOrEmpty(result))
            {
                List <AgentInfo> data2 = JsonConvert.DeserializeObject <List <AgentInfo> >(result);
                DataTable        dt    = DataTableExtensions.ToDataTable(data2);
                this.agentDataGrid.DataSource = dt;
            }
            else
            {
                MessageBox.Show("查询异常,请联系管理员!", "提示");
                this.agentDataGrid.DataSource = null;
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //运行命令获取结果
            string command = textBox1.Text;

            if ("".Equals(command))
            {
                MessageBox.Show("命令为空,请输入命令!", "提示");
                return;
            }

            this.button1.Enabled = false;


            List <int> jobs = new List <int>();


            if (agentDataGrid.Rows.Count > 0)
            {
                for (int i = 0; i < agentDataGrid.Rows.Count; i++)
                {
                    agentDataGrid.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
                    string _selectValue = agentDataGrid.Rows[i].Cells["ck_column"].EditedFormattedValue.ToString();
                    if (_selectValue == "True")
                    {
                        jobs.Add(i);
                    }
                }
            }


            if (jobs.Count == 0)
            {
                MessageBox.Show("请选择机器!", "提示");
            }
            else
            {
                foreach (int index in jobs)
                {
                    DataGridViewRow row = agentDataGrid.Rows[index];
                    string          ip  = row.Cells["AgentIp"].EditedFormattedValue.ToString();

                    Dictionary <string, string> pm = new Dictionary <string, string>();
                    pm.Add("email", loginUserEmail);
                    pm.Add("ip", ip);
                    pm.Add("command", command);
                    pm.Add("timestamp", SecurityUtil.GetTimestamp());
                    string sign = SecurityUtil.CreateSign(pm);
                    pm.Add("sign", sign);

                    Thread oGetArgThread = new Thread(new System.Threading.ThreadStart(() =>
                    {
                        string result = HttpUtil.SendPost(ConstantUrl.runCommandUrl, pm);
                        if (String.IsNullOrEmpty(result))
                        {
                            row.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
                            row.Cells["Result"].Value      = "bumblebee server error";
                        }
                        else
                        {
                            Dictionary <string, Object> data = JsonConvert.DeserializeObject <Dictionary <string, Object> >(result);
                            if (data == null || data["code"] == null || int.Parse(data["code"].ToString()) != 0)
                            {
                                //失败
                                row.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                //成功
                                row.DefaultCellStyle.BackColor = System.Drawing.Color.PaleGreen;
                            }
                            row.Cells["Result"].Value = data["data"];
                        }
                    }));
                    oGetArgThread.IsBackground = true;
                    oGetArgThread.Start();
                }
            }
            this.button1.Enabled = true;
        }
Ejemplo n.º 4
0
        private void login_btn_Click(object sender, EventArgs e)
        {
            string account = this.account_txt.Text;
            string pwd     = this.pwd_txt.Text;

            if (String.IsNullOrEmpty(account))
            {
                MessageBox.Show("请输入登录邮箱", "提示");
                this.account_txt.Focus();
                return;
            }

            if (String.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("请输入登录密码!", "提示");
                this.pwd_txt.Focus();
                return;
            }

            this.login_btn.Enabled = false;

            Dictionary <string, string> pm = new Dictionary <string, string>();

            Login.EMAIL  = account;
            Login.PWDKEY = SecurityUtil.CreateMD5Hash(pwd);
            //Login.PWDKEY = "";
            pm.Add("version", Login.VERSION);
            pm.Add("email", Login.EMAIL);
            //pm.Add("pwd", pwd);
            pm.Add("timestamp", SecurityUtil.GetTimestamp());
            string sign = SecurityUtil.CreateSign(pm, Login.PWDKEY);

            pm.Add("sign", sign);
            try
            {
                string result = HttpUtil.SendPost(ConstantUrl.loginUrl, pm);
                if (String.IsNullOrEmpty(result.Trim()))
                {
                    MessageBox.Show("登录失败,帐号密码错误!", "提示");
                }
                else
                {
                    Dictionary <string, string> r = JsonConvert.DeserializeObject <Dictionary <string, string> >(result);
                    if (r["code"] == "0")
                    {
                        if (!string.IsNullOrEmpty(r["msg"].Trim()))
                        {
                            MessageBox.Show(r["msg"].Trim(), "提示");
                        }
                        MainWindow main = new MainWindow(this);
                        main.StartPosition = FormStartPosition.Manual;
                        int xWidth  = SystemInformation.PrimaryMonitorSize.Width;
                        int yHeight = SystemInformation.PrimaryMonitorSize.Height;
                        main.Location = new Point((xWidth - main.Width) / 2, (yHeight - main.Height) / 2);
                        this.Hide();
                        main.Show();
                    }
                    else
                    {
                        MessageBox.Show(r["msg"].Trim(), "提示");
                    }
                }
            }
            catch (Exception ee) {
                MessageBox.Show("登录失败,服务端异常!(" + ee.Message + ")", "提示");
            }
            this.login_btn.Enabled = true;
        }
Ejemplo n.º 5
0
        private void agentDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                if (e.ColumnIndex != 0)
                {
                    if (e.ColumnIndex == 11)
                    {
                        Random rd   = new Random();
                        string Port = rd.Next(60000, 65535).ToString();
                        try
                        {
                            Process myProcess = new Process();
                            myProcess.StartInfo.UseShellExecute = false;
                            myProcess.StartInfo.FileName        = "cmd.exe";
                            myProcess.StartInfo.Arguments       = "/c nc -i 3 " + agentDataGrid.Rows[e.RowIndex].Cells["AgentIp"].Value.ToString() + " " + Port;
                            myProcess.Start();
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show("本地启动SHELL连接失败!(" + ee.Message + ")", "提示");
                        }
                        Thread oGetArgThread = new Thread(new System.Threading.ThreadStart(() =>
                        {
                            string ip = agentDataGrid.Rows[e.RowIndex].Cells["AgentIp"].Value.ToString();

                            Dictionary <string, string> pm = new Dictionary <string, string>();
                            pm.Add("email", Login.EMAIL);
                            pm.Add("ip", ip);
                            pm.Add("port", Port);
                            pm.Add("timestamp", SecurityUtil.GetTimestamp());
                            string sign = SecurityUtil.CreateSign(pm, Login.PWDKEY);
                            pm.Add("sign", sign);
                            //Console.WriteLine(pm);
                            try
                            {
                                string result = HttpUtil.SendPost(ConstantUrl.runShellUrl, pm);
                                if (String.IsNullOrEmpty(result.Trim()))
                                {
                                    MessageBox.Show("创建连接BumblebeeServer创建SHELL失败!", "提示");
                                }
                                else
                                {
                                    Dictionary <string, Object> data = JsonConvert.DeserializeObject <Dictionary <string, Object> >(result);
                                    if (data == null || data["code"] == null)
                                    {
                                        MessageBox.Show("服务器(" + ip + ")返回异常,创建SHELL失败!", "提示");
                                    }
                                    else if (int.Parse(data["code"].ToString()) != 0)
                                    {
                                        MessageBox.Show(data["data"].ToString(), "提示");
                                    }
                                    else
                                    {
                                        //success
                                    }
                                }
                            }
                            catch (Exception ee)
                            {
                                MessageBox.Show("创建SHELL失败!(" + ee.Message + ")", "提示");
                            }
                        }));
                        oGetArgThread.IsBackground = true;
                        oGetArgThread.Start();
                    }
                    else
                    {
                        this.rsttitle.Text = "IP:" + agentDataGrid.Rows[e.RowIndex].Cells["AgentIp"].Value.ToString() + " Result:";
                        if (agentDataGrid.Rows[e.RowIndex].Cells["rstfull"].Value != null)
                        {
                            this.rst.Text = Unicode2String(agentDataGrid.Rows[e.RowIndex].Cells["rstfull"].Value.ToString()).Replace("\n", "\r\n").Replace("\\n", "\r\n");
                        }
                        else
                        {
                            this.rst.Text = "";
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            //首页获取搜索栏
            Dictionary <string, string> pm = new Dictionary <string, string>();

            pm.Add("email", Login.EMAIL);
            pm.Add("timestamp", SecurityUtil.GetTimestamp());
            string sign = SecurityUtil.CreateSign(pm, Login.PWDKEY);

            pm.Add("sign", sign);
            try
            {
                string result = HttpUtil.SendGet(ConstantUrl.agentConditionUrl, pm);
                if (!string.IsNullOrEmpty(result))
                {
                    IDictionary <string, List <string> > data = JsonConvert.DeserializeObject <IDictionary <string, List <string> > >(result);
                    List <string> mainNameList = new List <string>();
                    mainNameList.Add("一级分类");
                    mainNameList.AddRange(data["mainNameList"]);
                    this.mainNameBox.DataSource    = mainNameList;
                    this.mainNameBox.SelectedIndex = 0;
                    List <string> subNameList = new List <string>();
                    subNameList.Add("二级分类");
                    subNameList.AddRange(data["subNameList"]);
                    this.subNameBox.DataSource    = subNameList;
                    this.subNameBox.SelectedIndex = 0;
                    List <string> managerList = new List <string>();
                    managerList.Add("负责人");
                    managerList.AddRange(data["managerList"]);
                    this.managerBox.DataSource       = managerList;
                    this.managerBox.SelectedIndex    = 0;
                    this.searchTypeBox.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("获取搜索表单异常,数据返回为空!", "提示");
                    return;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("获取搜索表单异常(" + ee.Message + ")", "提示");
                return;
            }
            Dictionary <string, string> pm2 = new Dictionary <string, string>();

            pm2.Add("email", Login.EMAIL);
            pm2.Add("timestamp", SecurityUtil.GetTimestamp());
            string sign2 = SecurityUtil.CreateSign(pm2, Login.PWDKEY);

            pm2.Add("sign", sign2);
            int cnt = 0;

            try
            {
                string result2 = HttpUtil.SendGet(ConstantUrl.agentListUrl, pm2);
                if (!string.IsNullOrEmpty(result2))
                {
                    List <AgentInfo> data2 = JsonConvert.DeserializeObject <List <AgentInfo> >(result2);
                    //foreach data2
                    DataTable dt = DataTableExtensions.ToDataTable(data2);
                    //dt.Columns.Add("rflag", typeof(String));
                    //dt.Columns.Add("Result", typeof(String));
                    this.agentDataGrid.DataSource = dt;
                    cnt = data2.Count;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("默认服务器列表获取异常!(" + ee.Message + ")", "提示");
            }
            this.serverlist.Text = "服务器列表 总数:" + cnt.ToString() + "";
        }
Ejemplo n.º 7
0
        private void execbtn_Click(object sender, EventArgs e)
        {
            jobcnt  = 0;
            succcnt = 0;
            failcnt = 0;
            //运行命令获取结果
            string command = cmdtext.Text;

            if ("".Equals(command.Trim()))
            {
                MessageBox.Show("命令为空,请输入命令!", "提示");
                return;
            }
            List <int> jobs = new List <int>();

            if (agentDataGrid.Rows.Count > 0)
            {
                for (int i = 0; i < agentDataGrid.Rows.Count; i++)
                {
                    agentDataGrid.Rows[i].DefaultCellStyle.BackColor = Color.White;
                    string _selectValue = agentDataGrid.Rows[i].Cells["ck_column"].EditedFormattedValue.ToString();
                    if (_selectValue == "True")
                    {
                        jobs.Add(i);
                    }
                }
            }
            if (jobs.Count == 0)
            {
                MessageBox.Show("请选择机器!", "提示");
            }
            else
            {
                this.execbtn.Text    = "执行中..";
                this.execbtn.Enabled = false;
                execing = true;
                jobcnt  = jobs.Count;
                string uri = "";
                if (this.isdaemon.Checked == true)
                {
                    uri = ConstantUrl.runDaemonCommandUrl;
                }
                else
                {
                    uri = ConstantUrl.runCommandUrl;
                }
                for (int c = 0; c < agentDataGrid.Columns.Count; c++)
                {
                    agentDataGrid.Columns[c].SortMode = DataGridViewColumnSortMode.NotSortable;
                }
                foreach (int index in jobs)
                {
                    string ip = agentDataGrid.Rows[index].Cells["AgentIp"].EditedFormattedValue.ToString();
                    Dictionary <string, string> pm = new Dictionary <string, string>();
                    pm.Add("email", Login.EMAIL);
                    pm.Add("ip", ip);
                    pm.Add("command", command);
                    pm.Add("timestamp", SecurityUtil.GetTimestamp());
                    pm.Add("sign", SecurityUtil.CreateSign(pm, Login.PWDKEY));
                    Thread oGetArgThread = new Thread(new ThreadStart(() =>
                    {
                        Dictionary <string, string> rowrst = this.ThreadEXEC(pm, uri);
                        this.UpdateExecRowACT(rowrst, index);
                    }));
                    oGetArgThread.IsBackground = true;
                    oGetArgThread.Start();
                }
            }
        }
Ejemplo n.º 8
0
        private void searchbtn_Click(object sender, EventArgs e)
        {
            //搜索
            Dictionary <string, string> pm = new Dictionary <string, string>();

            pm.Add("timestamp", SecurityUtil.GetTimestamp());
            pm.Add("email", Login.EMAIL);
            string mainName = mainNameBox.Text;

            if (!"一级分类".Equals(mainName) && !"".Equals(mainName))
            {
                pm.Add("mainName", mainName);
            }
            string subName = subNameBox.Text;

            if (!"二级分类".Equals(subName) && !"".Equals(subName))
            {
                pm.Add("subName", subName);
            }
            string manager = managerBox.Text;

            if (!"负责人".Equals(manager) && !"".Equals(manager))
            {
                pm.Add("manager", manager);
            }
            string searchType    = searchTypeBox.Text;
            string searchContent = searchContentTxt.Text;

            if (!"".Equals(searchContent))
            {
                if ("IP".Equals(searchType))
                {
                    pm.Add("agentIp", searchContent);
                }
                else if ("应用".Equals(searchType))
                {
                    pm.Add("agentName", searchContent);
                }
                else if ("资产号".Equals(searchType))
                {
                    pm.Add("asset", searchContent);
                }
                else
                {
                    MessageBox.Show("请选择搜索条件!", "提示");
                }
            }
            string sign = SecurityUtil.CreateSign(pm, Login.PWDKEY);

            pm.Add("sign", sign);
            int cnt = 0;

            try
            {
                string result = HttpUtil.SendPost(ConstantUrl.agentListUrl, pm);
                if (!string.IsNullOrEmpty(result))
                {
                    List <AgentInfo> data2 = JsonConvert.DeserializeObject <List <AgentInfo> >(result);
                    DataTable        dt    = DataTableExtensions.ToDataTable(data2);
                    //dt.Columns.Add("rflag", typeof(String));
                    //dt.Columns.Add("Result", typeof(String));
                    this.agentDataGrid.DataSource = dt;
                    cnt = data2.Count;
                }
                else
                {
                    MessageBox.Show("查询异常,未返回查询结果!", "提示");
                    this.agentDataGrid.DataSource = null;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("查询异常!(" + ee.Message + ")", "提示");
                this.agentDataGrid.DataSource = null;
            }
            this.serverlist.Text = "服务器列表 总数:" + cnt.ToString() + "";
            //succcnt = 0;failcnt = 0;
            execStatus.Text = "执行中:0,成功:0,失败:0";
        }