public override void PerformCellAction(string strColumnName, PwEntry pe) { //Copy OTP to clipboard if (strColumnName == null) { return; } if (KeePassOTPExt.CopyOTP(pe) || OTPDAO.OTPDefined(pe) != OTPDAO.OTPDefinition.None) { return; } //Show 2FA setup instructions if available if (!Config.CheckTFA) { return; } string url = pe.Strings.ReadSafe(PwDefs.UrlField); string target = TFASites.GetTFAUrl(url); PluginDebug.AddInfo("Show 2FA instructions", 0, "URL: " + target); try { System.Diagnostics.Process.Start(target); } catch { } }
public override string GetCellData(string strColumnName, PwEntry pe) { if (strColumnName == null) { return(string.Empty); } if (pe == null) { return(string.Empty); } Random r = new Random(); string otp = string.Empty; bool bForUsage = new System.Diagnostics.StackTrace().GetFrames().FirstOrDefault(x => x.GetMethod().Name == "OnPwListItemDrag") != null; if (bForUsage) { otp = OTPDAO.GetOTP(pe).GetOTP(); } else { otp = OTPDAO.GetReadableOTP(pe); } if (!string.IsNullOrEmpty(otp)) { if (bForUsage || strColumnName == OTPColumn_Verbose) { return(otp); } return(PluginTranslation.PluginTranslate.TFADefined); } if (!Config.CheckTFA) { return(string.Empty); } string url = pe.Strings.ReadSafe(PwDefs.UrlField); if (string.IsNullOrEmpty(url)) { return(string.Empty); } TFASites.TFAPossible TFAPossible = TFASites.IsTFAPossible(url); if (TFAPossible == TFASites.TFAPossible.Yes) { return(PluginTranslation.PluginTranslate.SetupTFA); } else if (TFAPossible == TFASites.TFAPossible.Unknown) { return("Checking 2FA"); } else { return(string.Empty); } }
public override bool Initialize(IPluginHost host) { Terminate(); if (host == null) { return(false); } m_host = host; PluginTranslate.Init(this, Program.Translation.Properties.Iso6391Code); Tools.DefaultCaption = PluginTranslate.PluginName; Tools.PluginURL = "https://github.com/rookiestyle/keepassotp/"; var t = typeof(Program).Assembly.GetType("KeePass.Native.NativeMethods"); try { m_miSetForegroundWindowEx = t.GetMethod("SetForegroundWindowEx", BindingFlags.Static | BindingFlags.NonPublic); } catch { } if (m_miSetForegroundWindowEx == null) { PluginDebug.AddError("Could not locate method 'SetForegroundEx'", 0); } try { m_miGetForegroundWindowHandle = t.GetMethod("GetForegroundWindowHandle", BindingFlags.Static | BindingFlags.NonPublic); } catch { } if (m_miGetForegroundWindowHandle == null) { PluginDebug.AddError("Could not locate method 'GetForegroundWindowHandle'", 0); } m_miAutoType = m_host.MainWindow.GetType().GetMethod("ExecuteGlobalAutoType", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null); if (m_miSetForegroundWindowEx == null) { PluginDebug.AddError("Could not locate method 'ExecuteGlobalAutoType'", 0); } CreateMenu(); AddTray(); Config.Init(); m_columnOTP = new KeePassOTPColumnProvider(); m_host.ColumnProviderPool.Add(m_columnOTP); m_columnOTP.StartTimer(); SprEngine.FilterCompile += SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Add(Config.Placeholder); TFASites.Init(false); OTPDAO.Init(); PTHotKeyManager.HotKeyPressed += PTHotKeyManager_HotKeyPressed; m_host.MainWindow.FileOpened += MainWindow_FileOpened; GlobalWindowManager.WindowAdded += GlobalWindowManager_WindowAdded; return(true); }
private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e) { if (e.form.DialogResult != DialogResult.OK) { return; } bool shown; Options options = (Options)Tools.GetPluginFromOptions(this, out shown); if (!shown) { return; } Dictionary <PwDatabase, Options.DBSettings> dDB = options.OTPDBSettings; foreach (KeyValuePair <PwDatabase, Options.DBSettings> kvp in dDB) { kvp.Key.UseDBForOTPSeeds(kvp.Value.UseOTPDB); kvp.Key.PreloadOTPDB(kvp.Value.Preload); } Config.CheckTFA = options.cgbCheckTFA.Checked; Config.Hotkey = options.hkcKPOTP.HotKey; string sOldPlaceholder = Config.Placeholder; Config.KPOTPAutoSubmit = options.cbAutoSubmit.Checked; Config.Placeholder = options.tbPlaceholder.Text; if ((sOldPlaceholder != Config.Placeholder) && (Tools.AskYesNo(string.Format(PluginTranslate.MigratePlaceholder, sOldPlaceholder, Config.Placeholder)) == DialogResult.Yes)) { MigratePlacholderInOpenDatabases(sOldPlaceholder, Config.Placeholder); } if (m_ContextMenuAutotype != null) { m_ContextMenuAutotype.Text = Config.Placeholder; } if (m_MainMenuAutotype != null) { m_MainMenuAutotype.Text = Config.Placeholder; } TFASites.Init(false); }