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

SSH management improvements #304

Merged
merged 5 commits into from
Jun 26, 2018
Merged
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
26 changes: 23 additions & 3 deletions src/SSHManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ SSHManagement::SSHManagement(QWidget *parent) :
keysModel = new QStandardItemModel(this);
ui->listViewKeys->setModel(keysModel);

// Enable button when a key is selected.
connect(ui->listViewKeys, &QListWidget::clicked, this, [this](const QModelIndex &/*index*/)
{
ui->pushButtonExport->setEnabled(true);
ui->pushButtonDelete->setEnabled(true);
});

QMenu *menu = new QMenu(this);
QAction *action;
action = menu->addAction(tr("Export public key"));
Expand Down Expand Up @@ -97,19 +104,27 @@ void SSHManagement::onServiceExists(const QString service, bool exists)
if (exists)
{
sshProcess = new QProcess(this);
QString program = QCoreApplication::applicationDirPath () + "/mc-agent";
const auto program = QCoreApplication::applicationDirPath () + "/mc-agent";
if (!QFile::exists(program))
{
QMessageBox::critical(this, "Moolticute",
tr("mc-agent isn't bundled with the Moolticute app!\n\nCannot manage SSH keys."));
ui->stackedWidget->setCurrentWidget(ui->pageLocked);
return;
}

QStringList arguments;
arguments << "--output_progress"
<< "cli"
<< "-c"
<< "list";

qInfo() << "Running " << program << " " << arguments;
qInfo() << "Running" << program << arguments;
connect(sshProcess, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitStatus != QProcess::NormalExit)
qWarning() << "SSH agent exits with exit code " << exitCode << " Exit Status : " << exitStatus;
qWarning() << "SSH agent exits with exit code" << exitCode << "Exit Status:" << exitStatus;

if (loaded)
ui->stackedWidget->setCurrentWidget(ui->pageEditSsh);
Expand Down Expand Up @@ -199,6 +214,11 @@ void SSHManagement::readStdOutLoadKeys()
}
}
}

// Clear selection and buttons after loading keys.
ui->listViewKeys->clearSelection();
ui->pushButtonExport->setEnabled(false);
ui->pushButtonDelete->setEnabled(false);
}

void SSHManagement::progressChanged(int total, int current)
Expand Down
66 changes: 31 additions & 35 deletions src/SSHManagement.ui
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ border-right: none;
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>SSH Keys management</string>
<string>SSH Keys Management</string>
</property>
<property name="class" stdset="0">
<string>FrameTitle</string>
Expand Down Expand Up @@ -91,7 +91,7 @@ border-right: none;
<item>
<widget class="QLabel" name="label_27">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;SSH is locked.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Press the unlock button to load SSH keys from the device.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;SSH Keys Not Loaded&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Press the load keys button to load SSH keys from your device.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand All @@ -114,7 +114,7 @@ border-right: none;
<item>
<widget class="QPushButton" name="pushButtonUnlock">
<property name="text">
<string>Unlock</string>
<string>Load Keys</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -266,42 +266,19 @@ border-right: none;
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>SSH Keys management</string>
<string>SSH Keys Management</string>
</property>
<property name="class" stdset="0">
<string>FrameTitle</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="pushButtonImport">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Import a key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="QLabel" name="label">
<property name="text">
<string>Only passphrase-free OpenSSH keys are supported at this moment.</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
Expand All @@ -314,29 +291,48 @@ border-right: none;
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButtonImport">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Import A Key</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonExport">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Export selected</string>
<string>Export Selected</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDelete">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Delete selected</string>
<string>Delete Selected</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -380,7 +376,7 @@ border-right: none;
</size>
</property>
<property name="text">
<string>Quit SSH Management</string>
<string>Leave SSH Keys Management</string>
</property>
</widget>
</item>
Expand Down