Beispiel #1
0
        private void LoadCurrent(bool bUpdate = false)
        {
            if (!bUpdate)
            {
                Program.Config.AccessLevels NetAccess = Program.Config.AccessLevels.Unconfigured;

                cmbAccess.Background = ProgramControl.GetAccessColor(NetAccess);
                WpfFunc.CmbSelect(cmbAccess, NetAccess.ToString());
            }

            btnApply.IsEnabled = false;

            ProgramList.ID id = mEventList.ElementAt(curIndex);
            Tuple <Program, List <Program.LogEntry> > list = mEvents[id];

            int PID = list.Item2.Count > 0 ? list.Item2.First().PID : 0;

            imgIcon.Source = ImgFunc.GetIcon(list.Item1.GetIcon(), imgIcon.Width);
            //lblName.Text = id.GetDisplayName(false);
            grpBox.Header = id.GetDisplayName(false);
            lblPID.Text   = string.Format("{0} ({1})", System.IO.Path.GetFileName(id.Path), PID);
            switch (id.Type)
            {
            //case ProgramList.Types.Program: lblSubName.Text = ""; break;
            case ProgramList.Types.Service: lblSubName.Text = id.Name; break;

            case ProgramList.Types.App: lblSubName.Text = App.engine.appMgr.GetAppName(id.Name); break;

            default: lblSubName.Text = ""; break;
            }
            lblPath.Text = id.Path;

            /*lstEvents.Items.Clear();
             * foreach (Program.LogEntry entry in list.Item2)
             * {
             *  string info = "";
             *  info += NetFunc.Protocol2SStr(entry.Protocol) + "://";
             *
             *  switch (entry.Protocol)
             *  {
             *      case (int)FirewallRule.KnownProtocols.TCP:
             *      case (int)FirewallRule.KnownProtocols.UDP:
             *          info += entry.RemoteAddress + ":" + entry.RemotePort;
             *          break;
             *  }
             *
             *  lstEvents.Items.Add(new ListBoxItem() { Content = info});
             * }*/

            consGrid.Items.Clear();
            foreach (Program.LogEntry entry in list.Item2)
            {
                consGrid.Items.Insert(0, new ConEntry(entry));
            }
        }
Beispiel #2
0
        private bool MakeCustom(ProgramList.ID id, long expiration, ConEntry entry = null)
        {
            FirewallRule rule = new FirewallRule()
            {
                guid = Guid.Empty, Profile = (int)Firewall.Profiles.All, Interface = (int)Firewall.Interfaces.All, Enabled = true
            };

            rule.mID        = id;
            rule.Name       = Translate.fmt("custom_rule", id.GetDisplayName());
            rule.Grouping   = FirewallRule.RuleGroup;
            rule.Expiration = expiration;

            if (entry != null)
            {
                rule.Direction = entry.Entry.Direction;
                rule.Protocol  = entry.Entry.Protocol;
                switch (entry.Entry.Protocol)
                {
                /*case (int)FirewallRule.KnownProtocols.ICMP:
                 * case (int)FirewallRule.KnownProtocols.ICMPv6:
                 *
                 *  break;*/
                case (int)FirewallRule.KnownProtocols.TCP:
                case (int)FirewallRule.KnownProtocols.UDP:
                    rule.LocalPorts  = "*";
                    rule.RemotePorts = entry.Entry.RemotePort.ToString();
                    break;
                }
                rule.LocalAddresses  = "*";
                rule.RemoteAddresses = entry.Entry.RemoteAddress.ToString();
            }
            else
            {
                rule.Direction = Firewall.Directions.Bidirectiona;
            }

            RuleWindow ruleWnd = new RuleWindow(new List <ProgramList.ID>()
            {
                id
            }, rule);

            if (ruleWnd.ShowDialog() != true)
            {
                return(false);
            }

            if (!App.itf.UpdateRule(rule))
            {
                MessageBox.Show(Translate.fmt("msg_rule_failed"), App.mName, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }

            return(true);
        }