Beispiel #1
0
        private void cmbProgram_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ContentControl program = (cmbProgram.SelectedItem as ContentControl);

            if (program == null)
            {
                return;
            }

            ProgIDChanged = true;

            ProgramID id = (program.Tag as ProgramID);

            txtPath.Text = id.Path;
            switch (id.Type)
            {
            case ProgramID.Types.Service:
                txtService.Text = id.GetServiceId();
                break;

            case ProgramID.Types.App:
                string SID = id.GetPackageSID();
                txtApp.Text = SID != null?AppModel.GetInstance().GetAppPkgBySid(SID)?.ID ?? "" : "";

                break;
            }
            txtService.IsEnabled = id.Type == ProgramID.Types.Service;
            txtApp.IsEnabled     = id.Type == ProgramID.Types.App;
        }
Beispiel #2
0
        public ProgramWnd(ProgramID 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 = ProgramID.NewID(ProgramID.Types.Program);
            }
            else
            {
                switch (ID.Type)
                {
                case ProgramID.Types.Program:
                    radProgram.IsChecked = true;
                    cmbPath.Text         = ID.GetPath();
                    break;

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

                case ProgramID.Types.App:
                    radApp.IsChecked = true;
                    foreach (AppModel.AppPkg app in cmbApp.Items)
                    {
                        if (MiscFunc.StrCmp(app.Value, ID.GetPackageSID()))
                        {
                            cmbApp.SelectedItem = app;
                            break;
                        }
                    }
                    if (cmbApp.SelectedItem == null)
                    {
                        cmbApp.Text = ID.GetPackageSID();
                    }
                    break;
                }
            }

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

            SuspendChange--;
        }
        private void LoadCurrent(bool bUpdate = false)
        {
            if (!bUpdate)
            {
                ProgramConfig.AccessLevels NetAccess = ProgramConfig.AccessLevels.Unconfigured;

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

                btnApply.IsEnabled = false;
            }

            ProgramID id = mEventList.ElementAt(curIndex);
            Tuple <Program, List <Priv10Engine.FwEventArgs> > list = mEvents[id];

            //int PID = list.Item2.Count > 0 ? list.Item2.First().FwEvent.ProcessId : 0;
            string FilePath = list.Item2.Count > 0 ? list.Item2.First().entry.FwEvent.ProcessFileName : "";

            imgIcon.Source = ImgFunc.GetIcon(FilePath, imgIcon.Width); // todo: use .progSet.GetIcon instead?
            //lblName.Text = id.GetDisplayName(false);
            grpBox.Header = list.Item1.Description;
            //lblPID.Text = string.Format("{0} ({1})", System.IO.Path.GetFileName(id.Path), PID);
            lblPID.Text = System.IO.Path.GetFileName(id.Path);

            List <string> services = new List <string>();

            //btnIgnore.IsEnabled = true;
            IgnoreSB.IsEnabled = true;
            consGrid.Items.Clear();
            foreach (Priv10Engine.FwEventArgs args in list.Item2)
            {
                consGrid.Items.Insert(0, new ConEntry(args.entry));

                if (args.services != null)
                {
                    foreach (var service in args.services)
                    {
                        if (!services.Contains(service))
                        {
                            services.Add(service);
                        }
                    }
                }
            }

            if (services.Count > 0)
            {
                cmbService.Visibility = Visibility.Visible;
                cmbService.Items.Clear();
                foreach (var service in services)
                {
                    cmbService.Items.Add(service);
                }
                cmbService.SelectedIndex = -1;
                cmbService.Text          = Translate.fmt("msg_pick_svc");
            }
            else
            {
                cmbService.Visibility = Visibility.Collapsed;
                switch (id.Type)
                {
                //case ProgramList.Types.Program: lblSubName.Text = ""; break;
                case ProgramID.Types.Service:
                    lblSubName.Text = id.GetServiceId();
                    break;

                case ProgramID.Types.App:
                    string SID = id.GetPackageSID();
                    lblSubName.Text = SID != null?AppModel.GetInstance().GetAppPkgBySid(SID)?.ID ?? SID : "";

                    break;

                default: lblSubName.Text = ""; break;
                }
            }
            lblPath.Text = id.Path;
        }
Beispiel #4
0
        public RuleWindow(List <Program> progs, FirewallRuleEx rule)
        {
            InitializeComponent();

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

            this.grpRule.Header = Translate.fmt("lbl_rule");
            this.lblName.Text   = Translate.fmt("lbl_name");
            this.lblGroup.Text  = Translate.fmt("lbl_group");

            this.grpProgram.Header  = Translate.fmt("lbl_program");
            this.lblProgram.Text    = Translate.fmt("lbl_program");
            this.lblExecutable.Text = Translate.fmt("lbl_exe");
            this.lblService.Text    = Translate.fmt("lbl_svc");
            this.lblApp.Text        = Translate.fmt("lbl_app");

            this.grpAction.Header = Translate.fmt("grp_action");
            this.lblAction.Text   = Translate.fmt("lbl_action");

            this.radProfileAll.Content    = Translate.fmt("lbl_prof_all");
            this.radProfileCustom.Content = Translate.fmt("lbl_prof_sel");
            this.chkPublic.Content        = Translate.fmt("lbl_prof_pub");
            this.chkDomain.Content        = Translate.fmt("lbl_prof_dmn");
            this.chkPrivate.Content       = Translate.fmt("lbl_prof_priv");

            this.radNicAll.Content    = Translate.fmt("lbl_itf_all");
            this.radNicCustom.Content = Translate.fmt("lbl_itf_select");
            this.chkLAN.Content       = Translate.fmt("lbl_itf_lan");
            this.chkVPN.Content       = Translate.fmt("lbl_itf_vpn");
            this.chkWiFi.Content      = Translate.fmt("lbl_itf_wifi");

            this.grpNetwork.Header = Translate.fmt("grp_network");
            this.lblDirection.Text = Translate.fmt("lbl_direction");
            this.lblProtocol.Text  = Translate.fmt("lbl_protocol");

            this.lblLocalPorts.Text  = Translate.fmt("lbl_local_port");
            this.lblRemotePorts.Text = Translate.fmt("lbl_remote_port");

            this.lblICMP.Text = Translate.fmt("lbl_icmp");

            this.lblLocalIP.Text  = Translate.fmt("lbl_local_ip");
            this.lblRemoteIP.Text = Translate.fmt("lbl_remote_ip");

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

            Rule = rule;
            bool bNew = Rule.guid == null;

            viewModel   = new RuleWindowViewModel();
            DataContext = viewModel;

            //txtName.Text = Rule.Name;
            viewModel.RuleName   = Rule.Name;
            cmbGroup.ItemsSource = GroupModel.GetInstance().GetGroups();
            if (!WpfFunc.CmbSelect(cmbGroup, Rule.Grouping))
            {
                cmbGroup.Text = Rule.Grouping;
            }
            txtInfo.Text = Rule.Description;

            if (progs != null)
            {
                foreach (Program prog in progs)
                {
                    ContentControl program = new ContentControl()
                    {
                        Content = prog.Description, Tag = prog.ID
                    };
                    cmbProgram.Items.Add(program);
                    if (Rule.ProgID != null && prog.ID.CompareTo(Rule.ProgID) == 0)
                    {
                        cmbProgram.SelectedItem = program;
                    }
                }
            }
            else
            {
                ContentControl program = new ContentControl()
                {
                    Content = ProgramControl.FormatProgID(Rule.ProgID), Tag = Rule.ProgID
                };
                cmbProgram.Items.Add(program);
                cmbProgram.SelectedItem = program;
            }

            txtPath.Text    = rule.BinaryPath ?? "";
            txtService.Text = rule.ServiceTag ?? "";
            txtApp.Text     = rule.AppSID != null?AppModel.GetInstance().GetAppPkgBySid(rule.AppSID)?.ID ?? rule.AppSID : "";

            cmbAction.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_allow"), Tag = FirewallRule.Actions.Allow
            });
            cmbAction.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_block"), Tag = FirewallRule.Actions.Block
            });
            //WpfFunc.CmbSelect(cmbAction, Rule.Action.ToString());
            viewModel.RuleAction = WpfFunc.CmbPick(cmbAction, Rule.Action.ToString());

            if (Rule.Profile == (int)FirewallRule.Profiles.All)
            {
                radProfileAll.IsChecked = true;
                chkPrivate.IsChecked    = true;
                chkDomain.IsChecked     = true;
                chkPublic.IsChecked     = true;
            }
            else
            {
                radProfileCustom.IsChecked = true;
                chkPrivate.IsChecked       = ((Rule.Profile & (int)FirewallRule.Profiles.Private) != 0);
                chkDomain.IsChecked        = ((Rule.Profile & (int)FirewallRule.Profiles.Domain) != 0);
                chkPublic.IsChecked        = ((Rule.Profile & (int)FirewallRule.Profiles.Public) != 0);
            }

            if (Rule.Interface == (int)FirewallRule.Interfaces.All)
            {
                radNicAll.IsChecked = true;
                chkLAN.IsChecked    = true;
                chkVPN.IsChecked    = true;
                chkWiFi.IsChecked   = true;
            }
            else
            {
                radNicCustom.IsChecked = true;
                chkLAN.IsChecked       = ((Rule.Interface & (int)FirewallRule.Interfaces.Lan) != 0);
                chkVPN.IsChecked       = ((Rule.Interface & (int)FirewallRule.Interfaces.RemoteAccess) != 0);
                chkWiFi.IsChecked      = ((Rule.Interface & (int)FirewallRule.Interfaces.Wireless) != 0);
            }

            if (bNew)
            {
                cmbDirection.Items.Add(new ContentControl()
                {
                    Content = Translate.fmt("str_inandout"), Tag = FirewallRule.Directions.Bidirectiona
                });
            }
            cmbDirection.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_outbound"), Tag = FirewallRule.Directions.Outbound
            });
            cmbDirection.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_inbound"), Tag = FirewallRule.Directions.Inbound
            });
            WpfFunc.CmbSelect(cmbDirection, Rule.Direction.ToString());

            cmbProtocol.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("pro_any"), Tag = (int)NetFunc.KnownProtocols.Any
            });
            for (int i = (int)NetFunc.KnownProtocols.Min; i <= (int)NetFunc.KnownProtocols.Max; i++)
            {
                string name = NetFunc.Protocol2Str((UInt32)i);
                if (name != null)
                {
                    cmbProtocol.Items.Add(new ContentControl()
                    {
                        Content = i.ToString() + " - " + name, Tag = i
                    });
                }
            }
            //if (!WpfFunc.CmbSelect(cmbProtocol, Rule.Protocol.ToString()))
            //    cmbProtocol.Text = Rule.Protocol.ToString();
            viewModel.Protocol = WpfFunc.CmbPick(cmbProtocol, Rule.Protocol.ToString());
            if (viewModel.Protocol == null)
            {
                viewModel.ProtocolTxt = Rule.Protocol.ToString();
            }

            UpdatePorts();

            addrDest.Address = Rule.RemoteAddresses;
            addrSrc.Address  = Rule.LocalAddresses;

            App.LoadWnd(this, "Rule");
        }