2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-07-27 13:31:13 +02:00
|
|
|
|
2011-06-21 12:44:52 +02:00
|
|
|
#include "genericlinuxdeviceconfigurationwizardpages.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
#include "ui_genericlinuxdeviceconfigurationwizardsetuppage.h"
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
#include "publickeydeploymentdialog.h"
|
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2018-12-21 14:01:17 +01:00
|
|
|
#include <ssh/sshkeycreationdialog.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QVBoxLayout>
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class GenericLinuxDeviceConfigurationWizardSetupPagePrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Ui::GenericLinuxDeviceConfigurationWizardSetupPage ui;
|
2018-12-21 14:01:17 +01:00
|
|
|
LinuxDevice::Ptr device;
|
2011-06-16 17:03:43 +02:00
|
|
|
};
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
class GenericLinuxDeviceConfigurationWizardFinalPagePrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QLabel infoLabel;
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2019-01-09 10:59:42 +01:00
|
|
|
GenericLinuxDeviceConfigurationWizardSetupPage::GenericLinuxDeviceConfigurationWizardSetupPage(
|
|
|
|
|
QWidget *parent) :
|
2011-09-15 09:10:10 +02:00
|
|
|
QWizardPage(parent), d(new Internal::GenericLinuxDeviceConfigurationWizardSetupPagePrivate)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
d->ui.setupUi(this);
|
2013-10-09 11:20:26 +02:00
|
|
|
setTitle(tr("Connection"));
|
2011-06-16 17:03:43 +02:00
|
|
|
setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
|
2016-06-30 23:04:57 +03:00
|
|
|
connect(d->ui.nameLineEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged);
|
|
|
|
|
connect(d->ui.hostNameLineEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged);
|
|
|
|
|
connect(d->ui.userNameLineEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericLinuxDeviceConfigurationWizardSetupPage::~GenericLinuxDeviceConfigurationWizardSetupPage()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericLinuxDeviceConfigurationWizardSetupPage::initializePage()
|
|
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
d->ui.nameLineEdit->setText(d->device->displayName());
|
|
|
|
|
d->ui.hostNameLineEdit->setText(d->device->sshParameters().host());
|
|
|
|
|
d->ui.userNameLineEdit->setText(d->device->sshParameters().userName());
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericLinuxDeviceConfigurationWizardSetupPage::isComplete() const
|
|
|
|
|
{
|
2017-12-19 12:45:46 +01:00
|
|
|
return !configurationName().isEmpty()
|
|
|
|
|
&& !d->ui.hostNameLineEdit->text().trimmed().isEmpty()
|
2018-12-21 14:01:17 +01:00
|
|
|
&& !d->ui.userNameLineEdit->text().trimmed().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericLinuxDeviceConfigurationWizardSetupPage::validatePage()
|
|
|
|
|
{
|
|
|
|
|
d->device->setDisplayName(configurationName());
|
|
|
|
|
SshConnectionParameters sshParams = d->device->sshParameters();
|
|
|
|
|
sshParams.url = url();
|
|
|
|
|
d->device->setSshParameters(sshParams);
|
|
|
|
|
return true;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString GenericLinuxDeviceConfigurationWizardSetupPage::configurationName() const
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->ui.nameLineEdit->text().trimmed();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 12:45:46 +01:00
|
|
|
QUrl GenericLinuxDeviceConfigurationWizardSetupPage::url() const
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2017-12-19 12:45:46 +01:00
|
|
|
QUrl url;
|
|
|
|
|
url.setHost(d->ui.hostNameLineEdit->text().trimmed());
|
|
|
|
|
url.setUserName(d->ui.userNameLineEdit->text().trimmed());
|
|
|
|
|
url.setPort(22);
|
|
|
|
|
return url;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardSetupPage::setDevice(const LinuxDevice::Ptr &device)
|
|
|
|
|
{
|
|
|
|
|
d->device = device;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 10:59:42 +01:00
|
|
|
GenericLinuxDeviceConfigurationWizardFinalPage::GenericLinuxDeviceConfigurationWizardFinalPage(
|
|
|
|
|
QWidget *parent)
|
2018-12-21 14:01:17 +01:00
|
|
|
: QWizardPage(parent), d(new Internal::GenericLinuxDeviceConfigurationWizardFinalPagePrivate)
|
|
|
|
|
{
|
|
|
|
|
setTitle(tr("Summary"));
|
|
|
|
|
setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
|
|
|
|
|
d->infoLabel.setWordWrap(true);
|
|
|
|
|
auto const layout = new QVBoxLayout(this);
|
|
|
|
|
layout->addWidget(&d->infoLabel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericLinuxDeviceConfigurationWizardFinalPage::~GenericLinuxDeviceConfigurationWizardFinalPage()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardFinalPage::initializePage()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
d->infoLabel.setText(infoText());
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
QString GenericLinuxDeviceConfigurationWizardFinalPage::infoText() const
|
2011-09-28 10:14:16 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
return tr("The new device configuration will now be created.\n"
|
|
|
|
|
"In addition, device connectivity will be tested.");
|
2011-09-28 10:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
struct GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::Private
|
|
|
|
|
{
|
2021-09-27 18:30:36 +02:00
|
|
|
FilePaths defaultKeys() const
|
2018-12-21 14:01:17 +01:00
|
|
|
{
|
2021-09-27 18:30:36 +02:00
|
|
|
const FilePath baseDir = FileUtils::homePath() / ".ssh";
|
|
|
|
|
return {baseDir / "id_rsa", baseDir / "id_ecdsa", baseDir / "id_ed25519"};
|
2018-12-21 14:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PathChooser keyFileChooser;
|
|
|
|
|
QLabel iconLabel;
|
|
|
|
|
LinuxDevice::Ptr device;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::GenericLinuxDeviceConfigurationWizardKeyDeploymentPage(QWidget *parent)
|
|
|
|
|
: QWizardPage(parent), d(new Private)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
setTitle(tr("Key Deployment"));
|
|
|
|
|
setSubTitle(" ");
|
|
|
|
|
const QString info = tr("We recommend that you log into your device using public key "
|
|
|
|
|
"authentication.\n"
|
|
|
|
|
"If your device is already set up for this, you do not have to do "
|
|
|
|
|
"anything here.\n"
|
|
|
|
|
"Otherwise, please deploy the public key for the private key "
|
|
|
|
|
"with which to connect in the future.\n"
|
|
|
|
|
"If you do not have a private key yet, you can also "
|
|
|
|
|
"create one here.");
|
|
|
|
|
d->keyFileChooser.setExpectedKind(PathChooser::File);
|
|
|
|
|
d->keyFileChooser.setHistoryCompleter("Ssh.KeyFile.History");
|
|
|
|
|
d->keyFileChooser.setPromptDialogTitle(tr("Choose a Private Key File"));
|
|
|
|
|
auto const deployButton = new QPushButton(tr("Deploy Public Key"), this);
|
|
|
|
|
connect(deployButton, &QPushButton::clicked,
|
|
|
|
|
this, &GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::deployKey);
|
|
|
|
|
auto const createButton = new QPushButton(tr("Create New Key Pair"), this);
|
|
|
|
|
connect(createButton, &QPushButton::clicked,
|
|
|
|
|
this, &GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::createKey);
|
|
|
|
|
auto const mainLayout = new QVBoxLayout(this);
|
|
|
|
|
auto const keyLayout = new QHBoxLayout;
|
|
|
|
|
auto const deployLayout = new QHBoxLayout;
|
|
|
|
|
mainLayout->addWidget(new QLabel(info));
|
|
|
|
|
keyLayout->addWidget(new QLabel(tr("Private key file:")));
|
|
|
|
|
keyLayout->addWidget(&d->keyFileChooser);
|
|
|
|
|
keyLayout->addWidget(createButton);
|
|
|
|
|
keyLayout->addStretch();
|
|
|
|
|
mainLayout->addLayout(keyLayout);
|
|
|
|
|
deployLayout->addWidget(deployButton);
|
|
|
|
|
deployLayout->addWidget(&d->iconLabel);
|
|
|
|
|
deployLayout->addStretch();
|
|
|
|
|
mainLayout->addLayout(deployLayout);
|
|
|
|
|
connect(&d->keyFileChooser, &PathChooser::pathChanged, this, [this, deployButton] {
|
2020-04-09 11:05:50 +02:00
|
|
|
deployButton->setEnabled(d->keyFileChooser.filePath().exists());
|
2018-12-21 14:01:17 +01:00
|
|
|
d->iconLabel.clear();
|
|
|
|
|
emit completeChanged();
|
|
|
|
|
});
|
2021-09-27 18:30:36 +02:00
|
|
|
for (const FilePath &defaultKey : d->defaultKeys()) {
|
|
|
|
|
if (defaultKey.exists()) {
|
|
|
|
|
d->keyFileChooser.setFilePath(defaultKey);
|
2018-12-21 14:01:17 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::~GenericLinuxDeviceConfigurationWizardKeyDeploymentPage()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::setDevice(const LinuxDevice::Ptr &device)
|
2011-06-21 12:44:52 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
d->device = device;
|
2011-06-21 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::initializePage()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
if (!d->device->sshParameters().privateKeyFile.isEmpty())
|
2021-09-27 18:30:36 +02:00
|
|
|
d->keyFileChooser.setFilePath(privateKeyFilePath());
|
2018-12-21 14:01:17 +01:00
|
|
|
d->iconLabel.clear();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
bool GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::isComplete() const
|
|
|
|
|
{
|
2020-04-09 11:35:12 +02:00
|
|
|
return d->keyFileChooser.filePath().toString().isEmpty() || d->keyFileChooser.filePath().exists();
|
2018-12-21 14:01:17 +01:00
|
|
|
}
|
2011-06-21 12:44:52 +02:00
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
bool GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::validatePage()
|
2011-06-21 12:44:52 +02:00
|
|
|
{
|
2021-09-27 18:30:36 +02:00
|
|
|
if (!d->defaultKeys().contains(d->keyFileChooser.filePath())) {
|
2018-12-21 14:01:17 +01:00
|
|
|
SshConnectionParameters sshParams = d->device->sshParameters();
|
|
|
|
|
sshParams.authenticationType = SshConnectionParameters::AuthenticationTypeSpecificKey;
|
2021-09-27 18:23:27 +02:00
|
|
|
sshParams.privateKeyFile = d->keyFileChooser.filePath();
|
2018-12-21 14:01:17 +01:00
|
|
|
d->device->setSshParameters(sshParams);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 18:30:36 +02:00
|
|
|
FilePath GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::privateKeyFilePath() const
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
2021-09-27 18:30:36 +02:00
|
|
|
return d->keyFileChooser.filePath();
|
2011-06-21 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::createKey()
|
2011-06-21 12:44:52 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
SshKeyCreationDialog dlg(this);
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
2021-09-27 16:30:57 +02:00
|
|
|
d->keyFileChooser.setFilePath(dlg.privateKeyFilePath());
|
2011-06-21 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 14:01:17 +01:00
|
|
|
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::deployKey()
|
2011-06-21 12:44:52 +02:00
|
|
|
{
|
2018-12-21 14:01:17 +01:00
|
|
|
PublicKeyDeploymentDialog dlg(d->device, privateKeyFilePath() + ".pub", this);
|
|
|
|
|
d->iconLabel.setPixmap((dlg.exec() == QDialog::Accepted ? Icons::OK : Icons::BROKEN).pixmap());
|
2011-06-21 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
} // namespace RemoteLinux
|