コード例 #1
0
        public void Add(Program prog, Program.LogEntry entry)
        {
            ProgramList.ID id = entry.mID;

            Tuple <Program, List <Program.LogEntry> > list;

            if (!mEvents.TryGetValue(id, out list))
            {
                list = new Tuple <Program, List <Program.LogEntry> >(prog, new List <Program.LogEntry>());
                mEvents.Add(id, list);
                mEventList.Add(id);
            }

            list.Item2.Add(entry);

            if (curIndex >= mEventList.Count)
            {
                curIndex = mEventList.Count - 1;
            }

            UpdateIndex();

            int index = mEventList.FindIndex((x) => { return(id.CompareTo(x) == 0); });

            if (curIndex == index)
            {
                LoadCurrent();
            }
        }
コード例 #2
0
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            ProgramList.ID id         = mEventList.ElementAt(curIndex);
            long           expiration = GetExpiration();

            Program.Config.AccessLevels NetAccess = (Program.Config.AccessLevels)(cmbAccess.SelectedItem as ComboBoxItem).Tag;

            if (NetAccess == Program.Config.AccessLevels.CustomConfig)
            {
                if (!MakeCustom(id, expiration))
                {
                    return;
                }
            }
            else if (NetAccess == Program.Config.AccessLevels.StopNotify)
            {
                Program prog = App.itf.GetProgram(id);

                if (expiration != 0)
                {
                    prog.config.SilenceUntill = expiration;
                }
                else
                {
                    prog.config.Notify = false;
                }
                App.itf.UpdateProgram(prog.guid, prog.config);
            }
            else
            {
                switch (NetAccess)
                {
                case Program.Config.AccessLevels.FullAccess:

                    // add and enable allow all rule
                    App.itf.UpdateRule(FirewallRule.MakeAllowRule(id, Firewall.Directions.Bidirectiona, expiration));
                    break;

                case Program.Config.AccessLevels.LocalOnly:

                    // create block rule only of we operate in blacklist mode
                    //if (App.itf.GetFilteringMode() == Firewall.FilteringModes.BlackList)
                    //{
                    //add and enable block rules for the internet
                    App.itf.UpdateRule(FirewallRule.MakeBlockInetRule(id, Firewall.Directions.Bidirectiona, expiration));
                    //}

                    //add and enable allow rules for the lan
                    App.itf.UpdateRule(FirewallRule.MakeAllowLanRule(id, Firewall.Directions.Bidirectiona, expiration));
                    break;

                case Program.Config.AccessLevels.BlockAccess:

                    // add and enable broad block rules
                    App.itf.UpdateRule(FirewallRule.MakeBlockRule(id, Firewall.Directions.Bidirectiona, expiration));
                    break;
                }
            }
            PopEntry();
        }
コード例 #3
0
        private void cmbProgram_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ContentControl program = (cmbProgram.SelectedItem as ContentControl);

            if (program == null)
            {
                return;
            }

            ProgramList.ID id = (program.Tag as ProgramList.ID);

            txtPath.Text = id.Path;
            switch (id.Type)
            {
            case ProgramList.Types.Service:
                txtService.Text = ServiceHelper.GetServiceName(id.Name) + " (" + id.Name + ")";
                break;

            case ProgramList.Types.App:
                txtApp.Text = AppManager.SidToPackageID(id.Name);
                break;
            }
            txtService.IsEnabled = id.Type == ProgramList.Types.Service;
            txtApp.IsEnabled     = id.Type == ProgramList.Types.App;
        }
コード例 #4
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));
            }
        }
コード例 #5
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);
        }
コード例 #6
0
        private void consGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ConEntry entry = (ConEntry)consGrid.SelectedItem;

            if (entry == null)
            {
                return;
            }

            ProgramList.ID id         = mEventList.ElementAt(curIndex);
            long           expiration = GetExpiration();

            if (MakeCustom(id, expiration, entry))
            {
                PopEntry();
            }
        }
コード例 #7
0
        private void PopEntry()
        {
            ProgramList.ID id = mEventList.ElementAt(curIndex);

            mEventList.RemoveAt(curIndex);
            mEvents.Remove(id);

            if (curIndex >= mEventList.Count)
            {
                curIndex = mEventList.Count - 1;
            }
            if (curIndex < 0)
            {
                curIndex = 0;
                this.Close();
                return;
            }

            UpdateIndex();
            LoadCurrent();
        }
コード例 #8
0
        public void Add(Program prog, Program.LogEntry entry)
        {
            ProgramList.ID id = entry.mID;

            Tuple <Program, List <Program.LogEntry> > list;

            if (!mEvents.TryGetValue(id, out list))
            {
                list = new Tuple <Program, List <Program.LogEntry> >(prog, new List <Program.LogEntry>());
                mEvents.Add(id, list);
                mEventList.Add(id);
            }

            list.Item2.Add(entry);

            int oldIndex = curIndex;

            if (curIndex < 0)
            {
                curIndex = 0;
            }
            else if (curIndex >= mEventList.Count)
            {
                curIndex = mEventList.Count - 1;
            }

            UpdateIndex();

            // don't update if the event is for a different entry
            int index = mEventList.FindIndex((x) => { return(id.CompareTo(x) == 0); });

            if (curIndex != index)
            {
                return;
            }

            LoadCurrent(oldIndex == curIndex);
        }
コード例 #9
0
 public bool RemoveProgram(Guid guid, ProgramList.ID id = null)
 {
     return(RemoteExec("RemoveProgram", new object[2] {
         guid, id
     }, false));
 }
コード例 #10
0
 public bool SplitPrograms(Guid from, ProgramList.ID id)
 {
     return(RemoteExec("SplitPrograms", new object[2] {
         from, id
     }, false));
 }
コード例 #11
0
 public bool AddProgram(ProgramList.ID id, Guid guid)
 {
     return(RemoteExec("AddProgram", new object[2] {
         id, guid
     }, false));
 }
コード例 #12
0
 public Program GetProgram(ProgramList.ID id, bool canAdd = false)
 {
     return(RemoteExec <Program>("GetProgram", new object[2] {
         id, canAdd
     }, null));
 }
コード例 #13
0
 public bool ClearRules(ProgramList.ID id, bool bDisable)
 {
     return(RemoteExec("ClearRules", new object[2] {
         id, bDisable
     }, false));
 }
コード例 #14
0
        public ProgramControl(Program prog, CategoryModel Categories)
        {
            InitializeComponent();

            chkNotify.Content = Translate.fmt("lbl_notify");
            btnAdd.Content    = Translate.fmt("lbl_add");
            btnSplit.Content  = Translate.fmt("lbl_split");
            btnRemove.Content = Translate.fmt("lbl_remove");

            progGrid.Columns[1].Header = Translate.fmt("lbl_name");
            progGrid.Columns[2].Header = Translate.fmt("lbl_progam");

            SuspendChange++;

            progArea.Visibility = Visibility.Collapsed;

            CatModel = Categories;
            //category.ItemsSource = CatModel.Categorys;
            category.ItemsSource = CatModel.GetCategorys();

            //mBorderBrush = name.BorderBrush;
            //name.BorderBrush = Brushes.Transparent;

            cmbAccess.Items.Add(new ComboBoxItem()
            {
                Content = Translate.fmt("acl_none"), Tag = Program.Config.AccessLevels.Unconfigured
            });
            cmbAccess.Items.Add(new ComboBoxItem()
            {
                Content = Translate.fmt("acl_allow"), Tag = Program.Config.AccessLevels.FullAccess
            });
            cmbAccess.Items.Add(new ComboBoxItem()
            {
                Content = Translate.fmt("acl_edit"), Tag = Program.Config.AccessLevels.CustomConfig
            });
            cmbAccess.Items.Add(new ComboBoxItem()
            {
                Content = Translate.fmt("acl_lan"), Tag = Program.Config.AccessLevels.LocalOnly
            });
            cmbAccess.Items.Add(new ComboBoxItem()
            {
                Content = Translate.fmt("acl_block"), Tag = Program.Config.AccessLevels.BlockAccess
            });
            foreach (ComboBoxItem item in cmbAccess.Items)
            {
                item.Background = GetAccessColor((Program.Config.AccessLevels)item.Tag);
            }

            SuspendChange--;

            Program = prog;

            DoUpdate();

            ProgramList.ID id = prog.IDs.First();
            if (id.Type == ProgramList.Types.Global || id.Type == ProgramList.Types.System)
            {
                btnIDs.IsEnabled = false;
                //btnCustimize.Visibility = Visibility.Hidden;
                cmbAccess.Visibility = Visibility.Hidden;
                //category.Visibility = Visibility.Hidden;
            }
            if (id.Type == ProgramList.Types.Global)
            {
                chkNotify.Visibility = Visibility.Hidden;
            }

            rect.MouseDown += new MouseButtonEventHandler(rect_Click);
            //name.MouseDown += new MouseButtonEventHandler(rect_Click);
            name.PreviewMouseDown += new MouseButtonEventHandler(rect_Click);
            //progGrid.PreviewMouseDown += new MouseButtonEventHandler(rect_Click);
            icon.MouseDown += new MouseButtonEventHandler(rect_Click);
            info.MouseDown += new MouseButtonEventHandler(rect_Click);

            category.PreviewMouseWheel += ctrl_PreviewMouseWheel;
            //progGrid.PreviewMouseWheel += ctrl_PreviewMouseWheel;
        }
コード例 #15
0
 public IDEntry(ProgramList.ID id)
 {
     mID = id;
 }
コード例 #16
0
        public ProgramWnd(ProgramList.ID id)
        {
            InitializeComponent();

            this.Title = Translate.fmt("wnd_program");

            this.grpProgram.Header  = Translate.fmt("lbl_program");
            this.radProgram.Content = Translate.fmt("lbl_exe");
            this.radService.Content = Translate.fmt("lbl_svc");
            this.radApp.Content     = Translate.fmt("lbl_app");

            this.btnOK.Content     = Translate.fmt("lbl_ok");
            this.btnCancel.Content = Translate.fmt("lbl_cancel");

            ID = id;

            SuspendChange++;

            Paths = new ObservableCollection <PathEntry>();

            ListCollectionView lcv = new ListCollectionView(Paths);

            lcv.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            cmbPath.ItemsSource = lcv;

            Paths.Add(new PathEntry()
            {
                Content = Translate.fmt("pro_browse"), Tag = "*", Group = Translate.fmt("lbl_selec")
            });
            PathEntry itemAll = new PathEntry()
            {
                Content = Translate.fmt("pro_all"), Tag = null, Group = Translate.fmt("lbl_selec")
            };

            Paths.Add(itemAll);

            if (ID != null && ID.Path.Length > 0)
            {
                PathEntry itemPath;
                if (ID.Path.Equals("system"))
                {
                    itemPath = new PathEntry()
                    {
                        Content = Translate.fmt("pro_sys"), Tag = ID.Path, Group = Translate.fmt("lbl_selec")
                    }
                }
                ;
                else
                {
                    itemPath = new PathEntry()
                    {
                        Content = ID.Path, Tag = ID.Path, Group = Translate.fmt("lbl_known")
                    }
                };
                Paths.Add(itemPath);
                cmbPath.SelectedItem = itemPath;
            }
            else
            {
                cmbPath.SelectedItem = itemAll;
            }

            //if (ID != null &&  ((ID.Path.Length == 0 && ID.Name.Length == 0) || ID.Path.Equals("system")))
            if (ID != null)
            {
                radProgram.IsEnabled = false;
                radService.IsEnabled = false;
                radApp.IsEnabled     = false;

                cmbPath.IsEnabled    = false;
                cmbService.IsEnabled = false;
                cmbApp.IsEnabled     = false;
            }

            cmbService.ItemsSource = ServiceModel.GetInstance().GetServices();
            cmbApp.ItemsSource     = AppModel.GetInstance().GetApps();

            if (ID == null)
            {
                radProgram.IsChecked = true;
                ID = new ProgramList.ID(ProgramList.Types.Program);
            }
            else
            {
                switch (ID.Type)
                {
                case ProgramList.Types.Program:
                    radProgram.IsChecked = true;
                    break;

                case ProgramList.Types.Service:
                    radService.IsChecked = true;
                    foreach (ServiceModel.Service service in cmbService.Items)
                    {
                        if (MiscFunc.StrCmp(service.Value, ID.Name))
                        {
                            cmbService.SelectedItem = service;
                            break;
                        }
                    }
                    if (cmbService.SelectedItem == null)
                    {
                        cmbService.Text = ID.Name;
                    }
                    break;

                case ProgramList.Types.App:
                    radApp.IsChecked = true;
                    foreach (AppModel.App app in cmbApp.Items)
                    {
                        if (MiscFunc.StrCmp(app.Value, ID.Name))
                        {
                            cmbService.SelectedItem = app;
                            break;
                        }
                    }
                    if (cmbApp.SelectedItem == null)
                    {
                        cmbApp.Text = AppManager.SidToPackageID(ID.Name);
                    }
                    break;
                }
            }

            if (UwpFunc.IsWindows7OrLower)
            {
                radApp.IsEnabled = false;
                cmbApp.IsEnabled = false;
            }

            SuspendChange--;
        }