From b661c3ad7e2000b27b4cfc44b16b2b0333583cf7 Mon Sep 17 00:00:00 2001 From: Dominik Chrastecky Date: Tue, 27 Sep 2022 00:53:05 +0200 Subject: [PATCH] Add option to delete everything --- harbour-bitsailor.pro | 3 + qml/pages/CleanupPage.qml | 106 +++++++++++++++++++++++++++ qml/pages/SettingsPage.qml | 26 ++++++- rpm/harbour-bitsailor.yaml | 3 +- src/fileaccessor.cpp | 32 ++++++++ src/fileaccessor.h | 18 +++++ src/harbour-bitsailor.cpp | 2 + src/secretshandler.h | 2 +- translations/harbour-bitsailor-cs.ts | 98 +++++++++++++++++++++---- translations/harbour-bitsailor.ts | 55 ++++++++++++++ 10 files changed, 327 insertions(+), 18 deletions(-) create mode 100644 qml/pages/CleanupPage.qml create mode 100644 src/fileaccessor.cpp create mode 100644 src/fileaccessor.h diff --git a/harbour-bitsailor.pro b/harbour-bitsailor.pro index 8711306..36d2312 100644 --- a/harbour-bitsailor.pro +++ b/harbour-bitsailor.pro @@ -19,6 +19,7 @@ SOURCES += src/harbour-bitsailor.cpp \ src/appsettings.cpp \ src/bitwardencli.cpp \ src/bitwardencliinstaller.cpp \ + src/fileaccessor.cpp \ src/pathhelper.cpp \ src/runtimecache.cpp \ src/secretshandler.cpp \ @@ -36,6 +37,7 @@ DISTFILES += qml/harbour-bitsailor.qml \ qml/components/Toaster.qml \ qml/cover/CoverPage.qml \ qml/helpers.js \ + qml/pages/CleanupPage.qml \ qml/pages/ConfirmSettingPage.qml \ qml/pages/InstallBitwardenCliPage.qml \ qml/pages/ItemDetailPage.qml \ @@ -73,6 +75,7 @@ HEADERS += \ src/appsettings.h \ src/bitwardencli.h \ src/bitwardencliinstaller.h \ + src/fileaccessor.h \ src/pathhelper.h \ src/runtimecache.h \ src/secretshandler.h \ diff --git a/qml/pages/CleanupPage.qml b/qml/pages/CleanupPage.qml new file mode 100644 index 0000000..9c6f98f --- /dev/null +++ b/qml/pages/CleanupPage.qml @@ -0,0 +1,106 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +import cz.chrastecky.bitsailor 1.0 + +Page { + property var secretsCleared: null + property var loggedOut: null + property var temporaryFilesDeleted: null + property var permanentFilesDeleted: null + property var configFilesDeleted: null + + id: page + allowedOrientations: Orientation.All + + BitwardenCli { + id: cli + onLogoutFinished: { + loggedOut = true; + secretsCleared = true; + } + } + + SecretsHandler { + id: secrets + } + + FileAccessor { + id: fileAccessor + } + + SilicaFlickable { + anchors.fill: parent + contentHeight: column.height + + Column { + id: column + + width: page.width + spacing: Theme.paddingLarge + PageHeader { + title: qsTr("Cleaning Up") + } + + IconTextSwitch { + property alias propertyToCheck: page.secretsCleared + property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel" + icon.source: "image://theme/" + iconName + icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor + text: qsTr("Deleted all secrets") + automaticCheck: false + checked: propertyToCheck + description: qsTr("Includes secrets like your password, username or PIN code.") + } + IconTextSwitch { + property alias propertyToCheck: page.loggedOut + property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel" + icon.source: "image://theme/" + iconName + icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor + text: qsTr("Logged out of Bitwarden CLI") + automaticCheck: false + checked: propertyToCheck + description: qsTr("The Bitwarden CLI could be used on its own even without this app, that's why it's safer to log out.") + } + IconTextSwitch { + property alias propertyToCheck: page.temporaryFilesDeleted + property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel" + icon.source: "image://theme/" + iconName + icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor + text: qsTr("Deleted temporary files") + automaticCheck: false + checked: propertyToCheck + description: qsTr("Temporary files include your cached vault for faster loading.") + } + IconTextSwitch { + property alias propertyToCheck: page.permanentFilesDeleted + property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel" + icon.source: "image://theme/" + iconName + icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor + text: qsTr("Deleted all permanent files") + automaticCheck: false + checked: propertyToCheck + description: qsTr("Permanent files include Bitwarden CLI (if it was installed using this app).") + } + IconTextSwitch { + property alias propertyToCheck: page.configFilesDeleted + property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel" + icon.source: "image://theme/" + iconName + icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor + text: qsTr("Deleted all config files") + automaticCheck: false + checked: propertyToCheck + description: qsTr("Config files include all the settings you have made in this app.") + } + } + } + + onStatusChanged: { + if (status === PageStatus.Active) { + cli.logout(); + temporaryFilesDeleted = fileAccessor.deleteTemporaryFilesDirectory(); + permanentFilesDeleted = fileAccessor.deletePermanentFilesDirectory(); + configFilesDeleted = fileAccessor.deleteConfigDirectory(); + } + } +} diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 9e43702..3b90ca4 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -10,6 +10,8 @@ Page { property string errorText property string authCheckType + property var doAfterLoad: [] + id: page allowedOrientations: Orientation.All @@ -55,6 +57,22 @@ Page { contentHeight: column.height visible: !busyIndicator.running + PushUpMenu { + MenuItem { + text: qsTr("Clean Up Everything"); + onClicked: { + const dialog = pageStack.push("ConfirmSettingPage.qml", { + description: qsTr("This will delete everything that this app stores on your system, including system secrets collection, Bitwarden CLI (if it was installed via this app), temporary files etc. Bitwarden CLI will also be logged out. Do you wish to continue?") + }); + dialog.accepted.connect(function() { + doAfterLoad.push(function() { + pageStack.replace("CleanupPage.qml"); + }); + }); + } + } + } + Column { id: column @@ -228,6 +246,12 @@ Page { } } - Component.onCompleted: { + onStatusChanged: { + if (status == PageStatus.Active) { + while (doAfterLoad.length) { + const callable = doAfterLoad.shift(); + callable(); + } + } } } diff --git a/rpm/harbour-bitsailor.yaml b/rpm/harbour-bitsailor.yaml index 5597360..f47278e 100644 --- a/rpm/harbour-bitsailor.yaml +++ b/rpm/harbour-bitsailor.yaml @@ -33,7 +33,8 @@ Requires: - sailfishsilica-qt5 >= 0.10.9 - sailfishsecretsdaemon-secretsplugins-default - sailfish-polkit-agent - - nodejs >= 18 + - nodejs + - npm # All installed files Files: diff --git a/src/fileaccessor.cpp b/src/fileaccessor.cpp new file mode 100644 index 0000000..a7da287 --- /dev/null +++ b/src/fileaccessor.cpp @@ -0,0 +1,32 @@ +#include "fileaccessor.h" + +#include "pathhelper.h" + +#include +#include + +FileAccessor::FileAccessor(QObject *parent) : QObject(parent) +{ + +} + +bool FileAccessor::deleteConfigDirectory() +{ + return deleteDirectory(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); +} + +bool FileAccessor::deleteTemporaryFilesDirectory() +{ + return deleteDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); +} + +bool FileAccessor::deletePermanentFilesDirectory() +{ + return deleteDirectory(getDataPath()); +} + +bool FileAccessor::deleteDirectory(QString path) +{ + QDir dir(path); + return dir.removeRecursively(); +} diff --git a/src/fileaccessor.h b/src/fileaccessor.h new file mode 100644 index 0000000..b064576 --- /dev/null +++ b/src/fileaccessor.h @@ -0,0 +1,18 @@ +#ifndef FILEACCESSOR_H +#define FILEACCESSOR_H + +#include + +class FileAccessor : public QObject +{ + Q_OBJECT +public: + explicit FileAccessor(QObject *parent = nullptr); + Q_INVOKABLE bool deleteConfigDirectory(); + Q_INVOKABLE bool deleteTemporaryFilesDirectory(); + Q_INVOKABLE bool deletePermanentFilesDirectory(); +private: + bool deleteDirectory(QString path); +}; + +#endif // FILEACCESSOR_H diff --git a/src/harbour-bitsailor.cpp b/src/harbour-bitsailor.cpp index 1e3d700..4177246 100644 --- a/src/harbour-bitsailor.cpp +++ b/src/harbour-bitsailor.cpp @@ -17,6 +17,7 @@ #include "appsettings.h" #include "runtimecache.h" #include "systemauthchecker.h" +#include "fileaccessor.h" int main(int argc, char *argv[]) { @@ -28,6 +29,7 @@ int main(int argc, char *argv[]) qmlRegisterType("cz.chrastecky.bitsailor", 1, 0, "BitwardenCli"); qmlRegisterType("cz.chrastecky.bitsailor", 1, 0, "SecretsHandler"); qmlRegisterType("cz.chrastecky.bitsailor", 1, 0, "SystemAuthChecker"); + qmlRegisterType("cz.chrastecky.bitsailor", 1, 0, "FileAccessor"); v->rootContext()->setContextProperty("settings", new AppSettings(app.data())); v->rootContext()->setContextProperty("runtimeCache", RuntimeCache::getInstance(app.data())); diff --git a/src/secretshandler.h b/src/secretshandler.h index f472f28..d1b259d 100644 --- a/src/secretshandler.h +++ b/src/secretshandler.h @@ -28,7 +28,7 @@ class SecretsHandler : public QObject Q_INVOKABLE void removePassword(); Q_INVOKABLE bool hasSessionId(); Q_INVOKABLE void removeSessionId(); - bool clearAllSecrets(); + Q_INVOKABLE bool clearAllSecrets(); void setSessionId(const QString &sessionId); void setUsername(const QString &username); diff --git a/translations/harbour-bitsailor-cs.ts b/translations/harbour-bitsailor-cs.ts index 34e1539..38cd075 100644 --- a/translations/harbour-bitsailor-cs.ts +++ b/translations/harbour-bitsailor-cs.ts @@ -1,6 +1,64 @@ + + CleanupPage + + + Cleaning Up + Čištění + + + + Deleted all secrets + Smazány všechny citlivé údaje + + + + Includes secrets like your password, username or PIN code. + Zahrnuje například vaše heslo, uživatelské jméno nebo PIN kód. + + + + Logged out of Bitwarden CLI + Odhlášeno z Bitwarden CLI + + + + The Bitwarden CLI could be used on its own even without this app, that's why it's safer to log out. + Bitwarden CLI lze používat i bez této aplikace, proto je bezpečnější se odhlásit. + + + + Deleted temporary files + Smazány dočasné soubory + + + + Temporary files include your cached vault for faster loading. + Dočasné soubory zahrnují váš trezor v cache pro rychlejší načítání. + + + + Config files include all the settings you have made in this app. + Konfigurační soubory zahrnují všechna nastavení této aplikace. + + + + Deleted all permanent files + Smazány všechny trvalé soubory + + + + Permanent files include Bitwarden CLI (if it was installed using this app). + Travalé soubory zahrnují Bitwarden CLI (pokud bylo nainstalováno přes tuto aplikaci). + + + + Deleted all config files + Smazány všechny konfigurační soubory + + ConfirmSettingPage @@ -306,67 +364,77 @@ SettingsPage - + The password you provided is invalid. Zadali jste neplatné heslo. - + Validating password Kontrola hesla + + + Clean Up Everything + Vyčistit data + + This will delete everything that this app stores on your system, including system secrets collection, Bitwarden CLI (if it was installed via this app), temporary files etc. Bitwarden CLI will also be logged out. Do you wish to continue? + Tato možnost smaže všechna data, která má tato aplikace uložena ve vašem zařízení, včetně uložiště citlivých údajů, Bitwarden CLI (pokud bylo nainstalováno touto apolikací), dočasné soubory atd. Budete také odhlášeni z Bitwarden CLI. Přejete si pokračovat? + + + Settings Nastavení - + Lock vault when app is closed Zamknout trezor při zavření aplikace - + Load vault items eagerly in main view Načítat trezor na hlavní obrazovce - + When this option is enabled, all items are loaded right when you enter the main screen. If disabled, the options are only loaded when you actually need to load them, meaning when you enter an item list like '%1', '%2' etc. Pokud je tato možnost povolena, všechny položky trezoru jsou načteny při vstupu na hlavní obrazovku. Při vypnutí jsou položky načteny až když jsou potřeba, tedy když kliknete na jednotlivé položky, jako např. '%1' nebo '%2'. - + Logins Přihlášení - + Cards Karty - + Enabling this option will fasten load times for items in the vault significantly but it means that your vault is dumped to disk <strong>unencrypted</strong>. While a great care has been taken to avoid dumping any sensitive information (passwords, credit card numbers etc.), bugs are possible and those sensitive informations could be leaked. Enable at your own risk. Povolením této možnosti zásadně zrychlíte načítání trezoru, ale znamená to, že vaše údaje budou uloženy na disk <strong>nezašifrované</strong>. Přestože byla učiněna opatření, aby se na disk neuložily žádné citlivé údaje (hesla, čísla kreditních karet atd.), je vždy možné, že se objeví chyba, díky které budou tyto údaje vyzrazeny. Používejte na vlastní nebezpečí. - + Fast authentication Rychlá autentizace - + Use OS authorization to unlock vault Použít autorizaci OS pro odemčení trezoru - + OS authorization check failed. Kontrola autorizace OS selhala. - + Note that this is normal when running inside emulator. Toto je normální, pokud aplikaci spouštíte uvnitř emulátoru. @@ -376,17 +444,17 @@ - + Save items in cache for faster load Uložit položky v cache pro rychlé načtení - + When this option is enabled, authentication is skipped and you are assumed to be logged in regardless of the actual status. What this means in practice is that logged in check is postponed until you're on the main page and is done in the background, this gives anyone opening this app a few seconds to look around before transfering you to the login/unlock screen. This should be ok because all vault operations fail when you're not logged in. <strong>Warning</strong>: if used in combination with the setting <strong>'%1'</strong> some data may be leaked to whoever opens this app. Use at your own risk. Pokud je tato možnost povolena, autentizace je přeskočena a aplikace se chová, jako byste byli přihlášeni bez ohledu na skutečný stav. V praxi to znamená, že kontrola přihlášení je přesunuta na později, konkrétně na hlavní obrazovku, a je provedena na pozadí. To umožňuje komukoliv, kdo otevře tuto aplikaci, pár sekund na procházení, než bude přesměrován na přihlašovací obrazovku. To by nemělo ničemu vadit, protože všechny operace s trezorem selžou, pokud nejste přihlášeni. <strong>Varování</strong>: při použití v kombinaci s <strong>'%1'</strong> mohou být komukoliv, kdo otevře tuto aplikaci, vyzrazena nějaká data. Používejte na vlastní nebezpečí. - + Use PIN to unlock vault Použít PIN pro odemknutí trezoru diff --git a/translations/harbour-bitsailor.ts b/translations/harbour-bitsailor.ts index 2fe947b..135d0a9 100644 --- a/translations/harbour-bitsailor.ts +++ b/translations/harbour-bitsailor.ts @@ -1,6 +1,53 @@ + + CleanupPage + + Cleaning Up + + + + Deleted all secrets + + + + Logged out of Bitwarden CLI + + + + Deleted all permanent files + + + + Deleted all config files + + + + Includes secrets like your password, username or PIN code. + + + + The Bitwarden CLI could be used on its own even without this app, that's why it's safer to log out. + + + + Deleted temporary files + + + + Temporary files include your cached vault for faster loading. + + + + Permanent files include Bitwarden CLI (if it was installed using this app). + + + + Config files include all the settings you have made in this app. + + + ConfirmSettingPage @@ -314,6 +361,14 @@ Use OS authorization to unlock vault + + Clean Up Everything + + + + This will delete everything that this app stores on your system, including system secrets collection, Bitwarden CLI (if it was installed via this app), temporary files etc. Bitwarden CLI will also be logged out. Do you wish to continue? + + SetupPinPage