2019-08-24 20:47:32 +02:00
|
|
|
|
#ifndef CONNECTIONCONTROLLER_H
|
|
|
|
|
|
#define CONNECTIONCONTROLLER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2019-09-16 19:24:39 +02:00
|
|
|
|
#include <string_view>
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
class MasterController;
|
|
|
|
|
|
class ConnectionConfig;
|
2021-07-04 19:33:06 +02:00
|
|
|
|
class ConnectionConfigurationWidget;
|
2019-08-24 20:47:32 +02:00
|
|
|
|
class ConnectionList;
|
2019-08-25 15:33:51 +02:00
|
|
|
|
class ConnectionTreeModel;
|
2019-08-24 20:47:32 +02:00
|
|
|
|
class ConnectionManagerWindow;
|
|
|
|
|
|
class PasswordManager;
|
2019-09-01 16:06:08 +02:00
|
|
|
|
class QTimer;
|
2022-09-05 07:33:08 +02:00
|
|
|
|
class QSqlDatabase;
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
2021-07-04 20:07:20 +02:00
|
|
|
|
|
|
|
|
|
|
class PassphraseResult {
|
|
|
|
|
|
public:
|
|
|
|
|
|
bool success;
|
|
|
|
|
|
QString passphrase;
|
|
|
|
|
|
int rememberForMinutes;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-24 20:47:32 +02:00
|
|
|
|
class ConnectionController : public QObject {
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit ConnectionController(MasterController *parent = nullptr);
|
|
|
|
|
|
~ConnectionController();
|
|
|
|
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
2019-08-25 15:33:51 +02:00
|
|
|
|
ConnectionTreeModel *getConnectionTreeModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_connectionTreeModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-24 20:47:32 +02:00
|
|
|
|
void showConnectionManager();
|
2019-08-27 20:12:00 +02:00
|
|
|
|
void openSqlWindowForConnection(QModelIndex index);
|
|
|
|
|
|
void openBackupDlgForConnection(QModelIndex index);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
/// Starts the form for creating a new conncetion.
|
|
|
|
|
|
/// This function returns immidiatly!
|
|
|
|
|
|
void createConnection();
|
|
|
|
|
|
/// Starts the form for editing a conncetion.
|
|
|
|
|
|
/// This function returns immidiatly!
|
2019-08-27 20:12:00 +02:00
|
|
|
|
void editConnection(QModelIndex index);
|
2021-03-31 16:03:34 +02:00
|
|
|
|
void editCopy(QModelIndex index);
|
|
|
|
|
|
void addGroup();
|
2019-09-01 06:42:21 +02:00
|
|
|
|
void removeGroup(QModelIndex index);
|
2019-09-01 14:07:58 +02:00
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<PasswordManager> passwordManager();
|
2021-07-04 19:33:06 +02:00
|
|
|
|
/** Retrieves the connection password from the user (directly or through the psk db)
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool retrieveConnectionPassword(ConnectionConfig &cc);
|
|
|
|
|
|
|
|
|
|
|
|
bool UnlockPasswordManagerIfNeeded();
|
|
|
|
|
|
|
|
|
|
|
|
bool decodeConnectionPassword(QUuid id, QByteArray encoded, QString &out_password);
|
2022-09-05 07:33:08 +02:00
|
|
|
|
void resetPasswordManager();
|
2019-08-24 20:47:32 +02:00
|
|
|
|
private:
|
|
|
|
|
|
MasterController *m_masterController;
|
|
|
|
|
|
ConnectionList *m_connectionList = nullptr;
|
2019-08-25 15:33:51 +02:00
|
|
|
|
ConnectionTreeModel *m_connectionTreeModel = nullptr;
|
2019-08-24 20:47:32 +02:00
|
|
|
|
ConnectionManagerWindow *m_connectionManagerWindow = nullptr;
|
2019-09-01 16:06:08 +02:00
|
|
|
|
QTimer *m_relockTimer = nullptr;
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
/** Using long lived object so it can remember its master password for sometime
|
|
|
|
|
|
* if the user wishes it.
|
|
|
|
|
|
*/
|
|
|
|
|
|
std::shared_ptr<PasswordManager> m_passwordManager;
|
|
|
|
|
|
|
2021-07-04 19:33:06 +02:00
|
|
|
|
bool retrieveFromPasswordManager(const std::string &password_id, const std::string_view &enc_password, std::string &password);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
2021-07-04 19:33:06 +02:00
|
|
|
|
/// Expects the plaintext password to be the password that needs encoding.
|
|
|
|
|
|
bool encryptPassword(ConnectionConfig &cc);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
2021-07-04 19:33:06 +02:00
|
|
|
|
static std::string getPskId(QUuid connectionid);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
2021-07-04 20:07:20 +02:00
|
|
|
|
void editConfig(ConnectionConfig &cc);
|
2021-07-04 19:33:06 +02:00
|
|
|
|
void saveConnection(ConnectionConfigurationWidget &w);
|
2021-07-04 20:07:20 +02:00
|
|
|
|
void setRelockTimer(int rem_minutes);
|
|
|
|
|
|
PassphraseResult PassphrasePrompt();
|
|
|
|
|
|
/// Asks user for new passphares and initialize the password manager.
|
|
|
|
|
|
bool InitializePasswordManager();
|
2019-09-01 16:06:08 +02:00
|
|
|
|
private slots:
|
|
|
|
|
|
void relock();
|
2019-08-24 20:47:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CONNECTIONCONTROLLER_H
|