Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to configure timeout for remote process #11271

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,14 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Timeout:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source> seconds</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatabaseTabWidget</name>
Expand Down
11 changes: 10 additions & 1 deletion src/gui/remote/DatabaseSettingsWidgetRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ DatabaseSettingsWidgetRemote::DatabaseSettingsWidgetRemote(QWidget* parent)
connect(m_ui->nameLineEdit, &QLineEdit::textChanged, setModified);
connect(m_ui->downloadCommand, &QLineEdit::textChanged, setModified);
connect(m_ui->inputForDownload, &QPlainTextEdit::textChanged, setModified);
connect(m_ui->downloadTimeout, QOverload<int>::of(&QSpinBox::valueChanged), setModified);
connect(m_ui->uploadCommand, &QLineEdit::textChanged, setModified);
connect(m_ui->inputForUpload, &QPlainTextEdit::textChanged, setModified);
connect(m_ui->uploadTimeout, QOverload<int>::of(&QSpinBox::valueChanged), setModified);
}

DatabaseSettingsWidgetRemote::~DatabaseSettingsWidgetRemote() = default;
Expand Down Expand Up @@ -100,8 +102,10 @@ void DatabaseSettingsWidgetRemote::saveCurrentSettings()
params->name = m_ui->nameLineEdit->text();
params->downloadCommand = m_ui->downloadCommand->text();
params->downloadInput = m_ui->inputForDownload->toPlainText();
params->downloadTimeout = m_ui->downloadTimeout->value();
params->uploadCommand = m_ui->uploadCommand->text();
params->uploadInput = m_ui->inputForUpload->toPlainText();
params->uploadTimeout = m_ui->uploadTimeout->value();

m_remoteSettings->addRemoteParams(params);
updateSettingsList();
Expand Down Expand Up @@ -145,8 +149,10 @@ void DatabaseSettingsWidgetRemote::editCurrentSettings()
m_ui->nameLineEdit->setText(params->name);
m_ui->downloadCommand->setText(params->downloadCommand);
m_ui->inputForDownload->setPlainText(params->downloadInput);
m_ui->downloadTimeout->setValue(params->downloadTimeout);
m_ui->uploadCommand->setText(params->uploadCommand);
m_ui->inputForUpload->setPlainText(params->uploadInput);
m_ui->uploadTimeout->setValue(params->uploadTimeout);
m_modified = false;
}

Expand All @@ -165,8 +171,10 @@ void DatabaseSettingsWidgetRemote::clearFields()
m_ui->nameLineEdit->setText("");
m_ui->downloadCommand->setText("");
m_ui->inputForDownload->setPlainText("");
m_ui->downloadTimeout->setValue(10);
m_ui->uploadCommand->setText("");
m_ui->inputForUpload->setPlainText("");
m_ui->uploadTimeout->setValue(10);
m_modified = false;
}

Expand All @@ -176,6 +184,7 @@ void DatabaseSettingsWidgetRemote::testDownload()
params->name = m_ui->nameLineEdit->text();
params->downloadCommand = m_ui->downloadCommand->text();
params->downloadInput = m_ui->inputForDownload->toPlainText();
params->downloadTimeout = m_ui->downloadTimeout->value();

QScopedPointer<RemoteHandler> remoteHandler(new RemoteHandler(this));
if (params->downloadCommand.isEmpty()) {
Expand All @@ -197,4 +206,4 @@ void DatabaseSettingsWidgetRemote::testDownload()
}

m_ui->messageWidget->showMessage(tr("Download successful."), MessageWidget::Positive);
}
}
114 changes: 80 additions & 34 deletions src/gui/remote/DatabaseSettingsWidgetRemote.ui
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,39 @@
<string>Download</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QLabel" name="downloadCommandInputLabel">
<property name="text">
<string>Input:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="downloadCommandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="inputForDownload">
<property name="accessibleName">
<string>Download input field</string>
</property>
<property name="placeholderText">
<string>e.g.:
get DatabaseOnRemote.kdbx {TEMP_DATABASE}
exit
---
{TEMP_DATABASE} is used as placeholder to store the database in a temporary location
The command has to exit. In case of `sftp` as last command `exit` has to be sent
</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
Expand All @@ -160,24 +186,44 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="downloadCommandInputLabel">
<item row="2" column="0">
<widget class="QLabel" name="downloadTimeoutLabel">
<property name="text">
<string>Input:</string>
<string>Timeout:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="downloadTimeout">
<property name="suffix">
<string> seconds</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="uploadTab">
<attribute name="title">
<string>Upload</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="1">
<widget class="QPlainTextEdit" name="inputForDownload">
<widget class="QPlainTextEdit" name="inputForUpload">
<property name="accessibleName">
<string>Download input field</string>
<string>Upload input field</string>
</property>
<property name="placeholderText">
<string>e.g.:
get DatabaseOnRemote.kdbx {TEMP_DATABASE}
put {TEMP_DATABASE} DatabaseOnRemote.kdbx
exit
---
{TEMP_DATABASE} is used as placeholder to store the database in a temporary location
Expand All @@ -186,13 +232,6 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="uploadTab">
<attribute name="title">
<string>Upload</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
<widget class="QLabel" name="uploadCommandInputLabel">
<property name="text">
Expand All @@ -203,13 +242,6 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="uploadCommandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="uploadCommand">
<property name="accessibleName">
Expand All @@ -220,19 +252,33 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="inputForUpload">
<property name="accessibleName">
<string>Upload input field</string>
<item row="0" column="0">
<widget class="QLabel" name="uploadCommandLabel">
<property name="text">
<string>Command:</string>
</property>
<property name="placeholderText">
<string>e.g.:
put {TEMP_DATABASE} DatabaseOnRemote.kdbx
exit
---
{TEMP_DATABASE} is used as placeholder to store the database in a temporary location
The command has to exit. In case of `sftp` as last command `exit` has to be sent
</string>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="uploadTimeoutLabel">
<property name="text">
<string>Timeout:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="uploadTimeout">
<property name="suffix">
<string> seconds</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions src/gui/remote/RemoteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RemoteHandler::RemoteResult RemoteHandler::download(const RemoteParams* params)
remoteProcess->closeWriteChannel();
}

bool finished = remoteProcess->waitForFinished(10000);
bool finished = remoteProcess->waitForFinished(params->downloadTimeout * 1000);
int statusCode = remoteProcess->exitCode();

// TODO: For future use
Expand Down Expand Up @@ -118,7 +118,7 @@ RemoteHandler::RemoteResult RemoteHandler::upload(const QString& filePath, const
remoteProcess->closeWriteChannel();
}

bool finished = remoteProcess->waitForFinished(10000);
bool finished = remoteProcess->waitForFinished(params->uploadTimeout * 1000);
int statusCode = remoteProcess->exitCode();

// TODO: For future use
Expand Down
4 changes: 4 additions & 0 deletions src/gui/remote/RemoteSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ QString RemoteSettings::toConfig() const
object["name"] = params->name;
object["downloadCommand"] = params->downloadCommand;
object["downloadCommandInput"] = params->downloadInput;
object["downloadTimeout"] = params->downloadTimeout;
object["uploadCommand"] = params->uploadCommand;
object["uploadCommandInput"] = params->uploadInput;
object["uploadTimeout"] = params->uploadTimeout;
config << object;
}
QJsonDocument doc(config);
Expand All @@ -108,8 +110,10 @@ void RemoteSettings::fromConfig(const QString& data)
params->name = itemMap["name"].toString();
params->downloadCommand = itemMap["downloadCommand"].toString();
params->downloadInput = itemMap["downloadCommandInput"].toString();
params->downloadTimeout = itemMap.value("downloadTimeout", 10).toInt();
params->uploadCommand = itemMap["uploadCommand"].toString();
params->uploadInput = itemMap["uploadCommandInput"].toString();
params->uploadTimeout = itemMap.value("uploadTimeout", 10).toInt();

m_remoteParams.insert(params->name, params);
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/remote/RemoteSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ struct RemoteParams
QString name;
QString downloadCommand;
QString downloadInput;
int downloadTimeout;
QString uploadCommand;
QString uploadInput;
int uploadTimeout;
};
Q_DECLARE_METATYPE(RemoteParams)

Expand Down