Ejemplo n.º 1
0
 protected void SavePwDatabaseToPath(IOConnectionInfo fileInfo)
 {
     pluginLogger.Log("Save database to: " + fileInfo.Path, LogStatusType.Info);
     KPMainWindowSwLogger.StartLogging(KPRes.SavingDatabase, true);
     database.SaveAs(fileInfo, false, KPMainWindowSwLogger);
     KPMainWindowSwLogger.EndLogging();
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override void Import(PwDatabase db, System.IO.Stream input, IStatusLogger logger)
        {
            try
            {
                ImportDialog form;

                while (true)
                {
                    form = new ImportDialog(db);

                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    if (string.IsNullOrEmpty(form.ProfilePath))
                    {
                        MessageBox.Show(
                            "No Profile Selected. Use Load More Profiles",
                            "Profile Required",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                            );
                    }
                    else
                    {
                        break;
                    }
                }

                try
                {
                    logger.StartLogging("Importing Firefox Passwords", false);
                    logger.SetText("Logging in", LogStatusType.Info);

                    using (var profile = new Profile(form.ProfilePath, form.Password))
                    {
                        logger.SetText("Reading the signon file", LogStatusType.Info);
                        IEnumerable <Signon> signons = profile.GetSignons();
                        ProcessSignonsAsync(signons, form, db, logger).GetAwaiter().GetResult();
                    }
                }
                finally
                {
                    logger.EndLogging();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Failed to Validate Password"))
                {
                    MessageBox.Show(ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    ErrorDialog.Show("Import Failed", ex);
                }
            }
        }
Ejemplo n.º 3
0
        public override void Import(PwDatabase pwDatabase, Stream input, IStatusLogger statusLogger)
        {
            ConfigurationForm configurationForm = new ConfigurationForm();

            statusLogger.StartLogging("OPVault file import", true);

            if (configurationForm.ShowDialog() == DialogResult.OK)
            {
                statusLogger.SetText("Parsing OPVault file...", LogStatusType.Info);

                string          defaultDir = Path.Combine(configurationForm.ImportDirPath, "default");
                Records.Profile profile    = oneVaultParser.ParseProfile(Path.Combine(defaultDir, "profile.js"), configurationForm.MasterPassword);

                if (profile == null)
                {
                    MessageBox.Show("Could not read profile file.", "Invalid OPVault", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (profile.masterKey == null || profile.overviewKey == null)
                {
                    MessageBox.Show("Please check the master password is correct.", "Error processing OPVault", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    List <Records.BaseRecord> records = oneVaultParser.ParseFolders(Path.Combine(defaultDir, "folders.js"), profile);
                    Dictionary <string, Records.AttachmentMetadata> attachments = new Dictionary <string, Records.AttachmentMetadata>();

                    for (int i = 0; i < 16; i++)
                    {
                        records.AddRange(oneVaultParser.ParseItems(Path.Combine(defaultDir, string.Format("band_{0:X}.js", i)), profile));
                    }

                    foreach (string attachmentFilePath in Directory.GetFiles(defaultDir, "*.attachment"))
                    {
                        Records.AttachmentMetadata attachmentMetadata = oneVaultParser.ParseAttachments(attachmentFilePath, profile);
                        Records.BaseRecord         item = records.Find(r => r.uuid.Equals(attachmentMetadata.itemUUID));
                        if (item is Records.ItemRecord)
                        {
                            (item as Records.ItemRecord).AddAttachment(attachmentFilePath, attachmentMetadata);
                        }
                    }

                    statusLogger.SetText(string.Format("Importing {0} parsed records...", records.Count), LogStatusType.Info);
                    oneVaultImporter.Import(records, pwDatabase, statusLogger, configurationForm.GetUserPrefs());
                    statusLogger.SetText("Finished import.", LogStatusType.Info);
                }
            }
            else
            {
                statusLogger.SetText("Import cancelled.", LogStatusType.Info);
            }

            statusLogger.EndLogging();
        }
Ejemplo n.º 4
0
            private void OTPDB_Save()
            {
                if (!Valid || !OTPDB_Opened || !OTPDB.Modified)
                {
                    return;
                }
                OTPDB.Modified = false;
                UpdateDBHeader();
                PwExportInfo pei = new PwExportInfo(OTPDB.RootGroup, OTPDB);

                using (var s = new MemoryStream())
                {
                    IStatusLogger sl = Program.MainForm.CreateShowWarningsLogger();
                    sl.StartLogging(PluginTranslate.OTPDB_Save, true);
                    m_FFP.Export(pei, s, sl);
                    sl.EndLogging();
                    s.Flush();
                    SetOTPDBData(s.GetBuffer());
                }
                FlagChanged(false);
            }
Ejemplo n.º 5
0
        public override void Import(PwDatabase pwDatabase, Stream input, IStatusLogger statusLogger)
        {
            ConfigurationForm configurationForm = new ConfigurationForm();

            statusLogger.StartLogging("1PIF file import", true);

            if (configurationForm.ShowDialog() == DialogResult.OK)
            {
                statusLogger.SetText("Parsing 1PIF file...", LogStatusType.Info);
                List <Records.BaseRecord> records;
                using (Stream importFileStream = File.OpenRead(configurationForm.ImportFilePath))
                    records = onePIFParser.Parse(importFileStream);
                statusLogger.SetText(string.Format("Importing {0} parsed records...", records.Count), LogStatusType.Info);
                onePIFImporter.Import(records, pwDatabase, statusLogger, configurationForm.GetUserPrefs());
                statusLogger.SetText("Finished import.", LogStatusType.Info);
            }
            else
            {
                statusLogger.SetText("Import cancelled.", LogStatusType.Info);
            }

            statusLogger.EndLogging();
        }
Ejemplo n.º 6
0
        private void UpdatePlugins(bool bUpdateTranslationsOnly)
        {
            PluginDebug.AddInfo("UpdatePlugins start ", DebugPrint);
            Form fUpdateLog = null;

            m_slUpdatePlugins = StatusUtil.CreateStatusDialog(GlobalWindowManager.TopWindow, out fUpdateLog, PluginTranslate.PluginUpdateCaption, string.Empty, true, true);

            bool   success            = false;
            string sTempPluginsFolder = PluginUpdateHandler.GetTempFolder();

            ThreadStart ts = new ThreadStart(() =>
            {
                m_slUpdatePlugins.StartLogging(PluginTranslate.PluginUpdateCaption, false);

                PluginDebug.AddInfo("Use temp folder", PluginUpdateHandler.Shieldify.ToString(), sTempPluginsFolder, DebugPrint);

                //Download files
                foreach (PluginUpdate upd in PluginUpdateHandler.Plugins)
                {
                    if (!upd.Selected)
                    {
                        continue;
                    }
                    success |= UpdatePlugin(upd, sTempPluginsFolder, bUpdateTranslationsOnly);
                }
            });
            Thread t = new Thread(ts);

            t.IsBackground = true;
            t.Start();
            while (true && t.IsAlive)
            {
                if (!m_slUpdatePlugins.ContinueWork())
                {
                    t.Abort();
                    break;
                }
            }
            if (t != null && t.IsAlive)
            {
                t.Abort();
            }
            if (m_slUpdatePlugins != null)
            {
                m_slUpdatePlugins.EndLogging();
                m_slUpdatePlugins = null;
            }
            if (fUpdateLog != null)
            {
                fUpdateLog.Dispose();
            }

            //Move files from temp folder to plugin folder
            success &= PluginUpdateHandler.MoveAll(sTempPluginsFolder);
            foreach (var pu in PluginUpdateHandler.Plugins)
            {
                if (!pu.Selected)
                {
                    continue;
                }
                if (pu is OwnPluginUpdate)
                {
                    (pu as OwnPluginUpdate).UpdateTranslationInfo(true);
                }
            }
            if (success)
            {
                PluginUpdateHandler.Cleanup(sTempPluginsFolder);
            }
            success = true;
            //Restart KeePass to use new plugin versions
            PluginDebug.AddInfo("Update finished", "Succes: " + success.ToString(), DebugPrint);
            if (success && !bUpdateTranslationsOnly)
            {
                if (Tools.AskYesNo(PluginTranslate.PluginUpdateSuccess, PluginTranslate.PluginUpdateCaption) == DialogResult.Yes)
                {
                    if (m_bRestartInvoke)
                    {
                        m_host.MainWindow.Invoke(new KeePassLib.Delegates.GAction(() => { Restart(); }));
                    }
                    else
                    {
                        Restart();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);
            dlg.ExportInfo = pwExportInfo;

            bool bStatusActive = false;

            try
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    FileFormatProvider ffp = dlg.ResultFormat;
                    if (ffp == null)
                    {
                        Debug.Assert(false); return(false);
                    }

                    IOConnectionInfo ioc = null;
                    if (ffp.RequiresFile)
                    {
                        string[] vFiles = dlg.ResultFiles;
                        if (vFiles == null)
                        {
                            Debug.Assert(false); return(false);
                        }
                        if (vFiles.Length == 0)
                        {
                            Debug.Assert(false); return(false);
                        }
                        Debug.Assert(vFiles.Length == 1);

                        string strFile = vFiles[0];
                        if (string.IsNullOrEmpty(strFile))
                        {
                            Debug.Assert(false); return(false);
                        }

                        ioc = IOConnectionInfo.FromPath(strFile);
                    }

                    if (slLogger != null)
                    {
                        slLogger.StartLogging(KPRes.ExportingStatusMsg, true);
                        bStatusActive = true;
                    }

                    Application.DoEvents();                     // Redraw parent window
                    return(Export(pwExportInfo, ffp, ioc, slLogger));
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                UIUtil.DestroyForm(dlg);
                if (bStatusActive)
                {
                    slLogger.EndLogging();
                }
            }

            return(false);
        }