Exemplo n.º 1
0
        public KeeMAMOverrideForm(string domain, MatchAccuracyMethod?mam, List <string> otherKeys)
        {
            InitializeComponent();
            Icon      = global::KeePassRPC.Properties.Resources.KPRPCico;
            Domain    = domain;
            OtherKeys = otherKeys;
            MAM       = mam.GetValueOrDefault(MatchAccuracyMethod.Domain);

            textBox1.Text = Domain;

            switch (MAM)
            {
            case MatchAccuracyMethod.Exact: radioButton3.Checked = true; break;

            case MatchAccuracyMethod.Hostname: radioButton2.Checked = true; break;

            case MatchAccuracyMethod.Domain: radioButton1.Checked = true; break;
            }

            if (string.IsNullOrEmpty(domain))
            {
                Text = "Add Override";
            }
            else
            {
                Text = "Edit Override";
            }
        }
Exemplo n.º 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                Domain = textBox1.Text;
            }
            else
            {
                DialogResult = DialogResult.None;
            }

            if (OtherKeys.Contains(Domain))
            {
                MessageBox.Show(this, "An override for '" + Domain + "' has already been added. Cancel, then find and Edit the existing override.");
                DialogResult = DialogResult.None;
                return;
            }

            DomainName domain;

            DomainName.TryParse(Domain, out domain);
            if (domain == null || domain.RegistrableDomain == null || domain.RegistrableDomain != Domain)
            {
                MessageBox.Show(this, "Invalid domain name");
                DialogResult = DialogResult.None;
                return;
            }

            MAM = DetermineDefaultMatchAccuracy();
        }
Exemplo n.º 3
0
        public MatchAccuracyMethod SelectsCorrectMatchAccuracyMethod(
            string urlSearch,
            MatchAccuracyMethod entryMam,
            MatchAccuracyMethod defaultMam,
            string[] overrideURLs = null,
            MatchAccuracyMethod[] overrideMethods = null)
        {
            var pwe  = new PwEntry(true, true);
            var conf = new EntryConfig(entryMam);

            pwe.SetKPRPCConfig(conf);
            var urlSummary = URLSummary.FromURL(urlSearch);
            var dbConf     = new DatabaseConfig()
            {
                DefaultMatchAccuracy = defaultMam
            };

            if (overrideURLs != null)
            {
                for (int i = 0; i < overrideURLs.Length; i++)
                {
                    dbConf.MatchedURLAccuracyOverrides.Add(overrideURLs[i], overrideMethods[i]);
                }
            }

            return(pwe.GetMatchAccuracyMethod(urlSummary, dbConf));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntryConfig"/> class.
        /// Match configuration depends on defaults in DB settings
        /// </summary>
        public EntryConfig(MatchAccuracyMethod accuracyMethod)
        {
            switch (accuracyMethod)
            {
            case MatchAccuracyMethod.Exact: BlockDomainOnlyMatch = false; BlockHostnameOnlyMatch = true; break;

            case MatchAccuracyMethod.Hostname: BlockDomainOnlyMatch = true; BlockHostnameOnlyMatch = false; break;

            case MatchAccuracyMethod.Domain: BlockDomainOnlyMatch = false; BlockHostnameOnlyMatch = false; break;
            }
        }
Exemplo n.º 5
0
        private void AddURLListItem(string domain, MatchAccuracyMethod mam)
        {
            switch (mam)
            {
            case MatchAccuracyMethod.Domain:
                listView1.Items.Add(new ListViewItem(new string[] { domain, "Domain" }));
                break;

            case MatchAccuracyMethod.Hostname:
                listView1.Items.Add(new ListViewItem(new string[] { domain, "Hostname" }));
                break;

            case MatchAccuracyMethod.Exact:
                listView1.Items.Add(new ListViewItem(new string[] { domain, "Exact" }));
                break;
            }
        }
Exemplo n.º 6
0
 /// <remarks>This has to be a method because Jayrock</remarks>
 public void SetMatchAccuracyMethod(MatchAccuracyMethod value)
 {
     if (value == MatchAccuracyMethod.Domain)
     {
         BlockDomainOnlyMatch   = false;
         BlockHostnameOnlyMatch = false;
     }
     else if (value == MatchAccuracyMethod.Hostname)
     {
         BlockDomainOnlyMatch   = true;
         BlockHostnameOnlyMatch = false;
     }
     else
     {
         BlockDomainOnlyMatch   = false;
         BlockHostnameOnlyMatch = true;
     }
 }
Exemplo n.º 7
0
        public MatchAccuracyEnum CalculatesCorrectMatchAccuracyScore(string urlEntry, string urlSearch, MatchAccuracyMethod entryMam)
        {
            var pwe = new PwEntry(true, true);

            pwe.Strings.Set("URL", new ProtectedString(false, urlEntry));
            var conf = new EntryConfig(entryMam);

            pwe.SetKPRPCConfig(conf);
            var urlSummary = URLSummary.FromURL(urlSearch);

            return((MatchAccuracyEnum)KeePassRPCService.BestMatchAccuracyForAnyURL(pwe, conf, urlSearch, urlSummary, entryMam));
        }
Exemplo n.º 8
0
 public DatabaseConfig()
 {
     DefaultMatchAccuracy        = MatchAccuracyMethod.Domain;
     MatchedURLAccuracyOverrides = new Dictionary <string, MatchAccuracyMethod>();
     DefaultPlaceholderHandling  = PlaceholderHandling.Disabled;
 }
Exemplo n.º 9
0
        public static EntryConfig GetKPRPCConfig(this PwEntry entry, MatchAccuracyMethod mam)
        {
            List <string> dummy = null;

            return(entry.GetKPRPCConfig(null, ref dummy, mam));
        }
Exemplo n.º 10
0
        public static EntryConfig GetKPRPCConfig(this PwEntry entry, ProtectedStringDictionary strings, MatchAccuracyMethod mam)
        {
            List <string> dummy = null;

            return(entry.GetKPRPCConfig(strings, ref dummy, mam));
        }
Exemplo n.º 11
0
        public static EntryConfig GetKPRPCConfig(this PwEntry entry, ProtectedStringDictionary strings, ref List <string> configErrors, MatchAccuracyMethod mam)
        {
            if (strings == null)
            {
                strings = entry.Strings;
            }
            EntryConfig conf = null;
            string      json = strings.ReadSafe("KPRPC JSON");

            if (string.IsNullOrEmpty(json))
            {
                conf = new EntryConfig(mam);
            }
            else
            {
                try
                {
                    conf = (EntryConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(EntryConfig), json);
                }
                catch (Exception)
                {
                    var url = strings.ReadSafe("URL");
                    if (string.IsNullOrEmpty(url))
                    {
                        url = "<unknown>";
                    }
                    if (configErrors != null)
                    {
                        string entryUserName = strings.ReadSafe(PwDefs.UserNameField);
                        //entryUserName = KeePassRPCPlugin.GetPwEntryStringFromDereferencableValue(entry, entryUserName, db);
                        configErrors.Add("Username: "******". URL: " + url);
                    }
                    else
                    {
                        MessageBox.Show("There are configuration errors in this entry. To fix the entry and prevent this warning message appearing, please edit the value of the 'KPRPC JSON' advanced string. Please ask for help on https://forum.kee.pm if you're not sure how to fix this. The URL of the entry is: " + url + " and the full configuration data is: " + json, "Warning: Configuration errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    return(null);
                }
            }
            return(conf);
        }