From a93b22f89ae997216b38349e4eef2ba2bbdffa6c Mon Sep 17 00:00:00 2001 From: varjolintu Date: Thu, 15 Aug 2019 12:35:11 +0300 Subject: [PATCH] Add support for skipping Auto-Submit with Browser Integration --- src/browser/BrowserService.cpp | 12 ++++ src/browser/BrowserService.h | 2 + src/gui/entry/EditEntryWidget.cpp | 54 +++++++++++++++++ src/gui/entry/EditEntryWidget.h | 11 ++++ src/gui/entry/EditEntryWidgetBrowser.ui | 80 +++++++++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 src/gui/entry/EditEntryWidgetBrowser.ui diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 0f9fb7da1..ce8b3ab78 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -50,6 +50,9 @@ static int KEEPASSXCBROWSER_DEFAULT_ICON = 1; const char BrowserService::LEGACY_ASSOCIATE_KEY_PREFIX[] = "Public Key: "; static const char KEEPASSHTTP_NAME[] = "KeePassHttp Settings"; static const char KEEPASSHTTP_GROUP_NAME[] = "KeePassHttp Passwords"; +// Extra entry related options saved in custom data +const char BrowserService::OPTION_SKIP_AUTO_SUBMIT[] = "BrowserSkipAutoSubmit"; +const char BrowserService::OPTION_HIDE_ENTRY[] = "BrowserHideEntry"; BrowserService::BrowserService(DatabaseTabWidget* parent) : m_dbTabWidget(parent) @@ -375,6 +378,11 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id, QList pwEntriesToConfirm; QList pwEntries; for (Entry* entry : searchEntries(url, keyList)) { + if (entry->customData()->contains(BrowserService::OPTION_HIDE_ENTRY) && + entry->customData()->value(BrowserService::OPTION_HIDE_ENTRY) == "true") { + continue; + } + // HTTP Basic Auth always needs a confirmation if (!ignoreHttpAuth && httpAuth) { pwEntriesToConfirm.append(entry); @@ -839,6 +847,10 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry) res["expired"] = "true"; } + if (entry->customData()->contains(BrowserService::OPTION_SKIP_AUTO_SUBMIT)) { + res["skipAutoSubmit"] = entry->customData()->value(BrowserService::OPTION_SKIP_AUTO_SUBMIT); + } + if (browserSettings()->supportKphFields()) { const EntryAttributes* attr = entry->attributes(); QJsonArray stringFields; diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index d6f14f8e9..2958155b4 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -72,6 +72,8 @@ public: static const char KEEPASSXCBROWSER_OLD_NAME[]; static const char ASSOCIATE_KEY_PREFIX[]; static const char LEGACY_ASSOCIATE_KEY_PREFIX[]; + static const char OPTION_SKIP_AUTO_SUBMIT[]; + static const char OPTION_HIDE_ENTRY[]; public slots: QJsonArray findMatchingEntries(const QString& id, diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 14520650b..0238131f5 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -19,6 +19,7 @@ #include "EditEntryWidget.h" #include "ui_EditEntryWidgetAdvanced.h" #include "ui_EditEntryWidgetAutoType.h" +#include "ui_EditEntryWidgetBrowser.h" #include "ui_EditEntryWidgetHistory.h" #include "ui_EditEntryWidgetMain.h" #include "ui_EditEntryWidgetSSHAgent.h" @@ -49,6 +50,9 @@ #include "sshagent/KeeAgentSettings.h" #include "sshagent/SSHAgent.h" #endif +#ifdef WITH_XC_BROWSER +#include "browser/BrowserService.h" +#endif #include "gui/Clipboard.h" #include "gui/EditWidgetIcons.h" #include "gui/EditWidgetProperties.h" @@ -68,6 +72,7 @@ EditEntryWidget::EditEntryWidget(QWidget* parent) , m_autoTypeUi(new Ui::EditEntryWidgetAutoType()) , m_sshAgentUi(new Ui::EditEntryWidgetSSHAgent()) , m_historyUi(new Ui::EditEntryWidgetHistory()) + , m_browserUi(new Ui::EditEntryWidgetBrowser()) , m_customData(new CustomData()) , m_mainWidget(new QWidget()) , m_advancedWidget(new QWidget()) @@ -75,6 +80,9 @@ EditEntryWidget::EditEntryWidget(QWidget* parent) , m_autoTypeWidget(new QWidget()) #ifdef WITH_XC_SSHAGENT , m_sshAgentWidget(new QWidget()) +#endif +#ifdef WITH_XC_BROWSER + , m_browserWidget(new QWidget()) #endif , m_editWidgetProperties(new EditWidgetProperties()) , m_historyWidget(new QWidget()) @@ -103,6 +111,10 @@ EditEntryWidget::EditEntryWidget(QWidget* parent) } #endif +#ifdef WITH_XC_BROWSER + setupBrowser(); +#endif + setupProperties(); setupHistory(); setupEntryUpdate(); @@ -246,6 +258,27 @@ void EditEntryWidget::setupAutoType() // clang-format on } +#ifdef WITH_XC_BROWSER +void EditEntryWidget::setupBrowser() +{ + m_browserUi->setupUi(m_browserWidget); + + if (config()->get("Browser/Enabled", false).toBool()) { + addPage(tr("Browser Integration"), FilePath::instance()->icon("apps", "internet-web-browser"), m_browserWidget); + connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowser())); + connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowser())); + } +} + +void EditEntryWidget::updateBrowser() +{ + auto skip = m_browserUi->skipAutoSubmitCheckbox->isChecked(); + auto hide = m_browserUi->hideEntryCheckbox->isChecked(); + m_customData->set(BrowserService::OPTION_SKIP_AUTO_SUBMIT, (skip ? QString("true") : QString("false"))); + m_customData->set(BrowserService::OPTION_HIDE_ENTRY, (hide ? QString("true") : QString("false"))); +} +#endif + void EditEntryWidget::setupProperties() { addPage(tr("Properties"), FilePath::instance()->icon("actions", "document-properties"), m_editWidgetProperties); @@ -330,6 +363,13 @@ void EditEntryWidget::setupEntryUpdate() connect(m_sshAgentUi->lifetimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setModified())); } #endif + +#ifdef WITH_XC_BROWSER + if (config()->get("Browser/Enabled", false).toBool()) { + connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), this, SLOT(setModified())); + connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), this, SLOT(setModified())); + } +#endif } void EditEntryWidget::emitHistoryEntryActivated(const QModelIndex& index) @@ -820,6 +860,20 @@ void EditEntryWidget::setForms(Entry* entry, bool restore) } #endif +#ifdef WITH_XC_BROWSER + if (m_customData->contains(BrowserService::OPTION_SKIP_AUTO_SUBMIT)) { + m_browserUi->skipAutoSubmitCheckbox->setChecked(m_customData->value(BrowserService::OPTION_SKIP_AUTO_SUBMIT) == "true"); + } else { + m_browserUi->skipAutoSubmitCheckbox->setChecked(false); + } + + if (m_customData->contains(BrowserService::OPTION_HIDE_ENTRY)) { + m_browserUi->hideEntryCheckbox->setChecked(m_customData->value(BrowserService::OPTION_HIDE_ENTRY) == "true"); + } else { + m_browserUi->hideEntryCheckbox->setChecked(false); + } +#endif + m_editWidgetProperties->setFields(entry->timeInfo(), entry->uuid()); if (!m_history && !restore) { diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index 9a90097b0..e70c548c3 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -51,6 +51,7 @@ namespace Ui { class EditEntryWidgetAdvanced; class EditEntryWidgetAutoType; + class EditEntryWidgetBrowser; class EditEntryWidgetSSHAgent; class EditEntryWidgetMain; class EditEntryWidgetHistory; @@ -118,12 +119,18 @@ private slots: void decryptPrivateKey(); void copyPublicKey(); #endif +#ifdef WITH_XC_BROWSER + void updateBrowser(); +#endif private: void setupMain(); void setupAdvanced(); void setupIcon(); void setupAutoType(); +#ifdef WITH_XC_BROWSER + void setupBrowser(); +#endif #ifdef WITH_XC_SSHAGENT void setupSSHAgent(); #endif @@ -157,6 +164,7 @@ private: const QScopedPointer m_autoTypeUi; const QScopedPointer m_sshAgentUi; const QScopedPointer m_historyUi; + const QScopedPointer m_browserUi; const QScopedPointer m_customData; QWidget* const m_mainWidget; @@ -165,6 +173,9 @@ private: QWidget* const m_autoTypeWidget; #ifdef WITH_XC_SSHAGENT QWidget* const m_sshAgentWidget; +#endif +#ifdef WITH_XC_BROWSER + QWidget* const m_browserWidget; #endif EditWidgetProperties* const m_editWidgetProperties; QWidget* const m_historyWidget; diff --git a/src/gui/entry/EditEntryWidgetBrowser.ui b/src/gui/entry/EditEntryWidgetBrowser.ui new file mode 100644 index 000000000..73e64dfb3 --- /dev/null +++ b/src/gui/entry/EditEntryWidgetBrowser.ui @@ -0,0 +1,80 @@ + + + EditEntryWidgetBrowser + + + + 0 + 0 + 400 + 348 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + These settings affect to the entry's behaviour with the browser extension. + + + + + + + General + + + + + + Skip Auto-Submit for this entry + + + + + + + Hide this entry from the browser extension + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + skipAutoSubmitCheckbox + hideEntryCheckbox + + + +