Beispiel #1
0
        // Menu methods for ListView ================================================================

        private void MenuItem_CmdSend_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            if (sock == null || sock.State != SockState.Opened)
            {
                return;
            }

            // 发送所有选中的命令,目前只支持发送第一条命令...
            foreach (CmdUnit item in lstViewCmd.SelectedItems)
            {
                // init data which is sended out to remote ep
                byte[] raw_data = SockConvert.ParseCmdstrToBytes(item.Cmd, '#');
                string str_data = Convert.ToBase64String(raw_data);
                //if (item.Encrypt)
                //    raw_data = Encoding.UTF8.GetBytes(Convert.ToBase64String(EncryptSym.AESEncrypt(raw_data)));

                // add internal header just for translating in SockMaster
                IPEndPoint ep  = sock.Type != SockType.accept ? sock.Lep : sock.Rep;
                object     req = new {
                    id     = "service.sesssend",
                    sessid = sock.SESSID,
                    data   = str_data,
                };
                core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
                break;
            }
        }
Beispiel #2
0
        private void MenuItem_CmdGet_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            //if (sock == null || sock.State != SockState.Opened) return;

            // 发送所有选中的命令,目前只支持发送第一条命令...
            foreach (CmdUnit item in lstViewCmd.SelectedItems)
            {
                try {
                    HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(item.Cmd);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                        String buffer = "";
                        while ((buffer = reader.ReadLine()) != null)
                        {
                            txtBoxMsg.AppendText(buffer);
                        }
                    }
                } catch (Exception excption) {
                    txtBoxMsg.AppendText(excption.Message + "\n");
                }

                break;
            }
        }
Beispiel #3
0
        // Menu methods for TreeView =============================================================

        private void MenuItem_SockOpen_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            if (sock == null || sock.State != SockState.Closed)
            {
                return;
            }

            sock.State = SockState.Opening;

            IPEndPoint ep = sock.Type == SockType.listen ? sock.Lep : sock.Rep;
            string     id = "service.sesslisten";

            if (sock.Type == SockType.connect)
            {
                id = "service.sessconnect";
            }
            object req = new {
                id   = id,
                ip   = ep.Address.ToString(),
                port = ep.Port,
            };

            core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
        }
Beispiel #4
0
 private void OnSessOpen(object sender, SockSess sess)
 {
     if (sess is SockSessServer)
     {
         uidata.OpenSockUnit(SockType.listen, sess.lep, sess.rep, sess.id);
     }
     else if (sess is SockSessClient)
     {
         uidata.OpenSockUnit(SockType.connect, sess.lep, sess.rep, sess.id);
     }
     else
     {
         SockUnit sockUnit = new SockUnit()
         {
             ID     = "at" + sess.rep.ToString(),
             SESSID = sess.id,
             Name   = "accept",
             Type   = SockType.accept,
             Lep    = sess.lep,
             Rep    = sess.rep,
             State  = SockState.Opened,
         };
         uidata.AddSockUnit(sockUnit);
     }
 }
Beispiel #5
0
        private void MenuItem_SockEdit_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            if (sock == null || sock.State != SockState.Closed)
            {
                return;
            }

            using (SockInputDialog input = new SockInputDialog()) {
                input.Owner            = this;
                input.Title            = "Edit";
                input.textBoxID.Text   = sock.ID;
                input.textBoxName.Text = sock.Name;
                if (sock.Type == SockType.listen)
                {
                    input.textBoxEP.Text = sock.Lep.ToString();
                    input.radioButtonListen.IsChecked = true;
                }
                else
                {
                    input.textBoxEP.Text = sock.Rep.ToString();
                    input.radioButtonConnect.IsChecked = true;
                }
                input.checkBoxAutorun.IsChecked = sock.Autorun;
                input.textBoxEP.Focus();
                input.textBoxEP.SelectionStart = input.textBoxEP.Text.Length;

                if (input.ShowDialog() == false)
                {
                    return;
                }

                sock.ID   = input.textBoxID.Text;
                sock.Name = input.textBoxName.Text;

                string[] str = input.textBoxEP.Text.Split(':');
                if (str.Count() != 2)
                {
                    return;
                }
                if (input.radioButtonListen.IsChecked == true)
                {
                    sock.Type = SockType.listen;
                    sock.Lep  = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                }
                else
                {
                    sock.Type = SockType.connect;
                    var host = Dns.GetHostEntry(str[0]);
                    sock.Rep = new IPEndPoint(host.AddressList[0], int.Parse(str[1]));
                }

                sock.Autorun = (bool)input.checkBoxAutorun.IsChecked;
                sock.UpdateTitle();
            }
        }
Beispiel #6
0
        private void MenuItem_SockDel_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            if (sock == null || sock.State != SockState.Closed)
            {
                return;
            }

            (treeSock.ItemsSource as ObservableCollection <SockUnit>).Remove(sock);
        }
Beispiel #7
0
        private void MenuItem_SockClose_Click(object sender, RoutedEventArgs e)
        {
            SockUnit sock = treeSock.SelectedItem as SockUnit;

            if (sock == null || sock.State != SockState.Opened)
            {
                return;
            }

            sock.State = SockState.Closing;

            IPEndPoint ep  = sock.Type != SockType.accept ? sock.Lep : sock.Rep;
            object     req = new {
                id     = "service.sessclose",
                sessid = sock.SESSID,
            };

            core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
        }
Beispiel #8
0
        private void MenuItem_SockAdd_Click(object sender, RoutedEventArgs e)
        {
            using (SockInputDialog input = new SockInputDialog()) {
                input.Owner = this;
                input.Title = "Add";
                input.textBoxID.Focus();

                if (input.ShowDialog() == false)
                {
                    return;
                }

                SockUnit sock = new SockUnit();
                sock.ID   = input.textBoxID.Text;
                sock.Name = input.textBoxName.Text;

                string[] str = input.textBoxEP.Text.Split(':');
                if (str.Count() != 2)
                {
                    return;
                }
                if (input.radioButtonListen.IsChecked == true)
                {
                    sock.Type = SockType.listen;
                    sock.Lep  = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                }
                else
                {
                    sock.Type = SockType.connect;
                    sock.Rep  = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                }

                sock.Autorun = (bool)input.checkBoxAutorun.IsChecked;
                sock.UpdateTitle();
                (treeSock.ItemsSource as ObservableCollection <SockUnit>).Add(sock);
            }
        }
Beispiel #9
0
        public void Config()
        {
            if (File.Exists(BASE_DIR + CONF_NAME) == false)
            {
                System.Windows.MessageBox.Show(CONF_NAME + ": can't find it.");
                return;
            }

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(BASE_DIR + CONF_NAME);

                // cmdtable
                foreach (XmlNode item in doc.SelectNodes("/configuration/commands/cmditem"))
                {
                    CmdUnit cmd = new CmdUnit();
                    cmd.ID          = item.Attributes["id"].Value;
                    cmd.Name        = item.Attributes["name"].Value;
                    cmd.Cmd         = item.Attributes["content"].Value;
                    cmd.Encrypt     = bool.Parse(item.Attributes["encrypt"].Value);
                    cmd.ContentMode = (ServiceRequestContentMode)Enum.Parse(typeof(ServiceRequestContentMode), item.Attributes["content-mode"].Value);
                    uidata.CmdTable.Add(cmd);
                }

                /// sockunit
                foreach (XmlNode item in doc.SelectNodes("/configuration/sockets/sockitem"))
                {
                    string[]   str      = item.Attributes["ep"].Value.Split(':');
                    IPEndPoint ep       = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                    SockType   sockType = (SockType)Enum.Parse(typeof(SockType), item.Attributes["type"].Value);
                    SockUnit   sockUnit = new SockUnit()
                    {
                        ID      = item.Attributes["id"].Value,
                        Name    = item.Attributes["name"].Value,
                        Type    = sockType,
                        Lep     = sockType == SockType.listen ? ep : null,
                        Rep     = sockType == SockType.connect ? ep : null,
                        State   = SockState.Closed,
                        Autorun = bool.Parse(item.Attributes["autorun"].Value),
                    };
                    uidata.AddSockUnit(sockUnit);

                    if (sockUnit.Autorun)
                    {
                        string id = "service.sesslisten";
                        if (sockType == SockType.connect)
                        {
                            id = "service.sessconnect";
                        }
                        object req = new {
                            id   = id,
                            ip   = ep.Address.ToString(),
                            port = ep.Port,
                        };
                        core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
                    }
                }
            } catch (Exception) {
                System.Windows.MessageBox.Show(CONF_NAME + ": syntax error.");
            }
        }