diff --git a/vpnplugins/CMakeLists.txt b/vpnplugins/CMakeLists.txt index 7335cb0..341e5d7 100644 --- a/vpnplugins/CMakeLists.txt +++ b/vpnplugins/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(pptp) add_subdirectory(strongswan) add_subdirectory(vpnc) add_subdirectory(openconnect) +add_subdirectory(libreswan) diff --git a/vpnplugins/libreswan/CMakeLists.txt b/vpnplugins/libreswan/CMakeLists.txt new file mode 100644 index 0000000..8312db8 --- /dev/null +++ b/vpnplugins/libreswan/CMakeLists.txt @@ -0,0 +1,22 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs/ui) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs/ui/security) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs/internals) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../libs/internals) + +set(libreswan_SRCS + libreswan.cpp + libreswanwidget.cpp + libreswanauth.cpp + ) + +kde4_add_ui_files(libreswan_SRCS libreswan.ui libreswanauth.ui) + +kde4_add_plugin(networkmanagement_libreswanui ${libreswan_SRCS}) + +target_link_libraries(networkmanagement_libreswanui ${KDE4_KIO_LIBS} knminternals knmui) + +install(TARGETS networkmanagement_libreswanui DESTINATION ${PLUGIN_INSTALL_DIR}) + +install( FILES networkmanagement_libreswanui.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/vpnplugins/libreswan/networkmanagement_libreswanui.desktop b/vpnplugins/libreswan/networkmanagement_libreswanui.desktop new file mode 100644 index 0000000..d188672 --- /dev/null +++ b/vpnplugins/libreswan/networkmanagement_libreswanui.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Type=Service +Icon= +ServiceTypes=NetworkManagement/VpnUiPlugin +X-KDE-Library=networkmanagement_libreswanui +X-NetworkManager-Services=org.freedesktop.NetworkManager.libreswan +X-KDE-PluginInfo-Author=Jan Grulich +X-KDE-PluginInfo-Email=jgrulich@redhat.com +X-KDE-PluginInfo-Name=networkmanagement_libreswanui +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=VPNService +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +Name=Libreswan +Name[x-test]=xxLibreswanxx +Comment=Libreswan Plugin +Comment[x-test]=xxLibreswan Pluginxx diff --git a/vpnplugins/libreswan/nm-openswan-service.h b/vpnplugins/libreswan/nm-openswan-service.h new file mode 100644 index 0000000..2b7b9f8 --- /dev/null +++ b/vpnplugins/libreswan/nm-openswan-service.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager-libreswan -- libreswan plugin for Network manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2010 Red Hat, Inc. + */ + + +#ifndef NM_OPENSWAN_PLUGIN_H +#define NM_OPENSWAN_PLUGIN_H + +#define NM_DBUS_SERVICE_OPENSWAN "org.freedesktop.NetworkManager.libreswan" +#define NM_DBUS_INTERFACE_OPENSWAN "org.freedesktop.NetworkManager.libreswan" +#define NM_DBUS_PATH_OPENSWAN "/org/freedesktop/NetworkManager/libreswan" + +#define NM_OPENSWAN_RIGHT "right" +#define NM_OPENSWAN_LEFTID "leftid" +#define NM_OPENSWAN_PSK_VALUE "pskvalue" +#define NM_OPENSWAN_PSK_INPUT_MODES "pskinputmodes" +#define NM_OPENSWAN_LEFTXAUTHUSER "leftxauthusername" +#define NM_OPENSWAN_XAUTH_PASSWORD "xauthpassword" +#define NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES "xauthpasswordinputmodes" +#define NM_OPENSWAN_DOMAIN "Domain" +#define NM_OPENSWAN_DHGROUP "dhgroup" +#define NM_OPENSWAN_PFSGROUP "pfsgroup" +#define NM_OPENSWAN_DPDTIMEOUT "dpdtimeout" +#define NM_OPENSWAN_IKE "ike" +#define NM_OPENSWAN_ESP "esp" + +#define NM_OPENSWAN_PW_TYPE_SAVE "save" +#define NM_OPENSWAN_PW_TYPE_ASK "ask" +#define NM_OPENSWAN_PW_TYPE_UNUSED "unused" + +#endif /* NM_OPENSWAN_PLUGIN_H */ diff --git a/vpnplugins/libreswan/libreswan.cpp b/vpnplugins/libreswan/libreswan.cpp new file mode 100644 index 0000000..aa63e07 --- /dev/null +++ b/vpnplugins/libreswan/libreswan.cpp @@ -0,0 +1,87 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "libreswan.h" + +#include + +#include "libreswanwidget.h" +#include "libreswanauth.h" +#include "connection.h" + + +K_PLUGIN_FACTORY( LibreswanUiPluginFactory, registerPlugin(); ) +K_EXPORT_PLUGIN( LibreswanUiPluginFactory( "networkmanagement_libreswanui", "libknetworkmanager" ) ) + +LibreswanUiPlugin::LibreswanUiPlugin(QObject *parent, const QVariantList &) + : VpnUiPlugin(parent) +{ + +} + +LibreswanUiPlugin::~LibreswanUiPlugin() +{ + +} + +SettingWidget *LibreswanUiPlugin::widget(Knm::Connection *connection, QWidget *parent) +{ + return new LibreswanWidget(connection, parent); +} + +SettingWidget *LibreswanUiPlugin::askUser(Knm::Connection *connection, QWidget *parent) +{ + return new LibreswanAuthDialog(connection, parent); +} + +QString LibreswanUiPlugin::suggestedFileName(Knm::Connection *connection) const +{ + Q_UNUSED(connection); + + // TODO : implement suggested file name + return QString(); +} + +QString LibreswanUiPlugin::supportedFileExtensions() const +{ + // TODO : return supported file extensions + return QString(); +} + +QVariantList LibreswanUiPlugin::importConnectionSettings(const QString &fileName) +{ + Q_UNUSED(fileName); + + // TODO : import the Libreswan connection from file and return settings + mError = VpnUiPlugin::NotImplemented; + return QVariantList(); +} + +bool LibreswanUiPlugin::exportConnectionSettings(Knm::Connection *connection, const QString &fileName) +{ + Q_UNUSED(connection); + Q_UNUSED(fileName); + + // TODO : export Libreswan connection to file + mError = VpnUiPlugin::NotImplemented; + return false; +} + +// vim: sw=4 sts=4 et tw=100 diff --git a/vpnplugins/libreswan/libreswan.h b/vpnplugins/libreswan/libreswan.h new file mode 100644 index 0000000..4aacde1 --- /dev/null +++ b/vpnplugins/libreswan/libreswan.h @@ -0,0 +1,47 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KNM_LIBRESWAN_H +#define KNM_LIBRESWAN_H + +#include "vpnuiplugin.h" + +#include + +namespace Knm +{ + class Connection; +} // namespace Knm + +class LibreswanUiPlugin : public VpnUiPlugin +{ +Q_OBJECT +public: + LibreswanUiPlugin(QObject *parent = 0, const QVariantList & = QVariantList()); + virtual ~LibreswanUiPlugin(); + SettingWidget *widget(Knm::Connection *, QWidget *parent = 0); + SettingWidget *askUser(Knm::Connection *, QWidget *parent = 0); + QString suggestedFileName(Knm::Connection *connection) const; + QString supportedFileExtensions() const; + QVariantList importConnectionSettings(const QString &fileName); + bool exportConnectionSettings(Knm::Connection *connection, const QString &fileName); +}; + +#endif // KNM_LIBRESWAN_H diff --git a/vpnplugins/libreswan/libreswan.ui b/vpnplugins/libreswan/libreswan.ui new file mode 100644 index 0000000..17f2299 --- /dev/null +++ b/vpnplugins/libreswan/libreswan.ui @@ -0,0 +1,200 @@ + + + LibreswanWidget + + + + 0 + 0 + 446 + 300 + + + + Open Swan VPN + + + + + + Gateway: + + + + + + + + + + Group name: + + + + + + + + + + User password: + + + + + + + + + true + + + + + + + + Store + + + + + Always Ask + + + + + Not Required + + + + + + + + + + Group password: + + + + + + + + + true + + + + + + + + Store + + + + + Always Ask + + + + + Not Required + + + + + + + + + + Show passwords + + + + + + + Qt::Vertical + + + + 20 + 28 + + + + + + + + User name: + + + + + + + + + + Phase1 algorithms: + + + + + + + + + + Phase2 algorithms: + + + + + + + + + + Domain: + + + + + + + + + + + KComboBox + QComboBox +
kcombobox.h
+
+ + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + gateway + groupname + userPassword + cbUsernamePasswordMode + groupPassword + cbGroupPasswordMode + ckShowPasswords + username + phase1 + phase2 + domain + + + +
diff --git a/vpnplugins/libreswan/libreswanauth.cpp b/vpnplugins/libreswan/libreswanauth.cpp new file mode 100644 index 0000000..543cf96 --- /dev/null +++ b/vpnplugins/libreswan/libreswanauth.cpp @@ -0,0 +1,115 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "libreswanauth.h" +#include "ui_libreswanauth.h" + +#include + +#include +#include + +#include "nm-openswan-service.h" +#include "connection.h" + +class LibreswanAuthDialogPrivate +{ +public: + Ui_LibreswanAuth ui; + Knm::VpnSetting * setting; +}; + +LibreswanAuthDialog::LibreswanAuthDialog(Knm::Connection *connection, QWidget *parent) + : SettingWidget(connection, parent), d_ptr(new LibreswanAuthDialogPrivate) +{ + Q_D(LibreswanAuthDialog); + d->ui.setupUi(this); + d->setting = static_cast(connection->setting(Knm::Setting::Vpn)); + connect(d->ui.cbShowPasswords, SIGNAL(toggled(bool)), this, SLOT(showPasswordsChanged(bool))); + + readSecrets(); + + KAcceleratorManager::manage(this); +} + +LibreswanAuthDialog::~LibreswanAuthDialog() +{ + delete d_ptr; +} + +void LibreswanAuthDialog::readSecrets() +{ + Q_D(LibreswanAuthDialog); + const QStringMap data = d->setting->data(); + const QStringMap secrets = d->setting->vpnSecrets(); + + const QString groupName = data.value(NM_OPENSWAN_LEFTID); + if (!groupName.isEmpty()) { + d->ui.leGroupName->setText(groupName); + } + + bool haveUserPassword = true; + if (data.value(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES) != NM_OPENSWAN_PW_TYPE_UNUSED) { + d->ui.leUserPassword->setText(secrets.value(NM_OPENSWAN_XAUTH_PASSWORD)); + } else { + d->ui.leUserPassword->setVisible(false); + d->ui.userPasswordLabel->setVisible(false); + haveUserPassword = false; + } + + bool haveGroupPassword = true; + if (data.value(NM_OPENSWAN_PSK_INPUT_MODES) != NM_OPENSWAN_PW_TYPE_UNUSED) { + d->ui.leGroupPassword->setText(secrets.value(NM_OPENSWAN_PSK_VALUE)); + } else { + d->ui.leGroupPassword->setVisible(false); + d->ui.groupPasswordLabel->setVisible(false); + haveGroupPassword = false; + } + + if (haveUserPassword && d->ui.leUserPassword->text().isEmpty()) { + d->ui.leUserPassword->setFocus(Qt::OtherFocusReason); + } else if (haveGroupPassword && d->ui.leGroupPassword->text().isEmpty()) { + d->ui.leGroupPassword->setFocus(Qt::OtherFocusReason); + } +} + +void LibreswanAuthDialog::writeConfig() +{ + Q_D(LibreswanAuthDialog); + + QStringMap secrets; + + if (!d->ui.leUserPassword->text().isEmpty()) { + secrets.insert(NM_OPENSWAN_XAUTH_PASSWORD, d->ui.leUserPassword->text()); + } + + if (!d->ui.leGroupPassword->text().isEmpty()) { + secrets.insert(NM_OPENSWAN_PSK_VALUE, d->ui.leGroupPassword->text()); + } + + d->setting->setVpnSecrets(secrets); +} + +void LibreswanAuthDialog::showPasswordsChanged(bool show) +{ + Q_D(LibreswanAuthDialog); + d->ui.leUserPassword->setPasswordMode(!show); + d->ui.leGroupPassword->setPasswordMode(!show); +} diff --git a/vpnplugins/libreswan/libreswanauth.h b/vpnplugins/libreswan/libreswanauth.h new file mode 100644 index 0000000..c3f9d92 --- /dev/null +++ b/vpnplugins/libreswan/libreswanauth.h @@ -0,0 +1,54 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KNM_LIBRESWAN_AUTH_H +#define KNM_LIBRESWAN_AUTH_H + +#include "settingwidget.h" + +#include "settings/vpn.h" + +namespace Knm +{ + class Connection; +} // namespace Knm + +class LibreswanAuthDialogPrivate; + +class LibreswanAuthDialog : public SettingWidget +{ + Q_OBJECT + Q_DECLARE_PRIVATE(LibreswanAuthDialog) +public: + explicit LibreswanAuthDialog(Knm::Connection *, QWidget *parent = 0); + ~LibreswanAuthDialog(); + void readSecrets(); + void readConfig() {}; + void writeConfig(); +protected Q_SLOTS: + void validate() {}; +private slots: + void showPasswordsChanged(bool); + +private: + LibreswanAuthDialogPrivate * d_ptr; +}; + +#endif // KNM_LIBRESWAN_AUTH_H diff --git a/vpnplugins/libreswan/libreswanauth.ui b/vpnplugins/libreswan/libreswanauth.ui new file mode 100644 index 0000000..7d5c4a2 --- /dev/null +++ b/vpnplugins/libreswan/libreswanauth.ui @@ -0,0 +1,95 @@ + + + LibreswanAuth + + + + 0 + 0 + 408 + 136 + + + + + + + Group name: + + + false + + + leGroupName + + + + + + + false + + + + + + + User password: + + + false + + + leUserPassword + + + + + + + true + + + + + + + Group password: + + + false + + + leGroupPassword + + + + + + + true + + + + + + + Show passwords + + + false + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + +
diff --git a/vpnplugins/libreswan/libreswanwidget.cpp b/vpnplugins/libreswan/libreswanwidget.cpp new file mode 100644 index 0000000..590f691 --- /dev/null +++ b/vpnplugins/libreswan/libreswanwidget.cpp @@ -0,0 +1,226 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "libreswanwidget.h" +#include "ui_libreswan.h" +#include "nm-openswan-service.h" + +#include +#include +#include + +#include "connection.h" + +class LibreswanWidgetPrivate +{ +public: + Ui::LibreswanWidget ui; + Knm::VpnSetting * setting; + enum AuthType {PrivateKey = 0, SshAgent, Smartcard, Eap}; +}; + + +LibreswanWidget::LibreswanWidget(Knm::Connection *connection, QWidget *parent): + SettingWidget(connection, parent), d_ptr(new LibreswanWidgetPrivate) +{ + Q_D(LibreswanWidget); + d->ui.setupUi(this); + d->setting = static_cast(connection->setting(Knm::Setting::Vpn)); + connect(d->ui.cbUsernamePasswordMode, SIGNAL(currentIndexChanged(int)), SLOT(userPasswordTypeChanged(int))); + connect(d->ui.cbGroupPasswordMode, SIGNAL(currentIndexChanged(int)), SLOT(groupPasswordTypeChanged(int))); + + connect(d->ui.ckShowPasswords, SIGNAL(toggled(bool)), SLOT(showPassword(bool))); + + connect(d->ui.gateway, SIGNAL(textChanged(QString)), SLOT(slotWidgetChanged())); + connect(d->ui.groupname, SIGNAL(textChanged(QString)), SLOT(slotWidgetChanged())); + + KAcceleratorManager::manage(this); +} + +LibreswanWidget::~LibreswanWidget() +{ + delete d_ptr; +} + +void LibreswanWidget::readConfig() +{ + Q_D(LibreswanWidget); + + const QStringMap data = d->setting->data(); + + const QString gateway = data.value(NM_OPENSWAN_RIGHT); + if (!gateway.isEmpty()) { + d->ui.gateway->setText(gateway); + } + + const QString groupName = data.value(NM_OPENSWAN_LEFTID); + if (!groupName.isEmpty()) { + d->ui.groupname->setText(groupName); + } + + const QString userPasswordMode = data.value(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES); + if (userPasswordMode == NM_OPENSWAN_PW_TYPE_SAVE) { + d->ui.cbUsernamePasswordMode->setCurrentIndex(0); + } else if (userPasswordMode == NM_OPENSWAN_PW_TYPE_ASK) { + d->ui.cbUsernamePasswordMode->setCurrentIndex(1); + } else if (userPasswordMode == NM_OPENSWAN_PW_TYPE_UNUSED) { + d->ui.cbUsernamePasswordMode->setCurrentIndex(2); + } + + const QString groupPasswordMode = data.value(NM_OPENSWAN_PSK_INPUT_MODES); + if (groupPasswordMode == NM_OPENSWAN_PW_TYPE_SAVE) { + d->ui.cbGroupPasswordMode->setCurrentIndex(0); + } else if (groupPasswordMode == NM_OPENSWAN_PW_TYPE_ASK) { + d->ui.cbGroupPasswordMode->setCurrentIndex(1); + } else if (groupPasswordMode == NM_OPENSWAN_PW_TYPE_UNUSED) { + d->ui.cbGroupPasswordMode->setCurrentIndex(2); + } + + const QString username = data.value(NM_OPENSWAN_LEFTXAUTHUSER); + if (!username.isEmpty()) { + d->ui.username->setText(username); + } + + const QString phase1 = data.value(NM_OPENSWAN_IKE); + if (!phase1.isEmpty()) { + d->ui.phase1->setText(phase1); + } + + const QString phase2 = data.value(NM_OPENSWAN_ESP); + if (!phase2.isEmpty()) { + d->ui.phase2->setText(phase2); + } + + const QString domain = data.value(NM_OPENSWAN_DOMAIN); + if (!domain.isEmpty()) { + d->ui.domain->setText(domain); + } +} + +void LibreswanWidget::readSecrets() +{ + Q_D(LibreswanWidget); + QStringMap secrets = d->setting->vpnSecrets(); + + const QString userPassword = secrets.value(NM_OPENSWAN_XAUTH_PASSWORD); + if (!userPassword.isEmpty()) { + d->ui.userPassword->setText(userPassword); + } + + const QString groupPassword = secrets.value(NM_OPENSWAN_PSK_VALUE); + if (!groupPassword.isEmpty()) { + d->ui.groupPassword->setText(groupPassword); + } +} + +void LibreswanWidget::writeConfig() +{ + Q_D(LibreswanWidget); + + d->setting->setServiceType(QLatin1String(NM_DBUS_SERVICE_OPENSWAN)); + QStringMap data; + QStringMap secrets; + + if (!d->ui.gateway->text().isEmpty()) { + data.insert(NM_OPENSWAN_RIGHT, d->ui.gateway->text()); + } + + if (!d->ui.groupname->text().isEmpty()) { + data.insert(NM_OPENSWAN_LEFTID, d->ui.groupname->text()); + } + + if (!d->ui.userPassword->text().isEmpty()) { + secrets.insert(NM_OPENSWAN_XAUTH_PASSWORD, d->ui.userPassword->text()); + } + + const int usernamePasswordMode = d->ui.cbUsernamePasswordMode->currentIndex(); + if (usernamePasswordMode == 0) { + data.insert(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES, NM_OPENSWAN_PW_TYPE_SAVE); + data.insert(NM_OPENSWAN_XAUTH_PASSWORD"-flags", QString::number(Knm::Setting::AgentOwned)); + } else if (usernamePasswordMode == 1) { + data.insert(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES, NM_OPENSWAN_PW_TYPE_ASK); + data.insert(NM_OPENSWAN_XAUTH_PASSWORD"-flags", QString::number(Knm::Setting::NotSaved)); + } else { + data.insert(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES, NM_OPENSWAN_PW_TYPE_UNUSED); + data.insert(NM_OPENSWAN_XAUTH_PASSWORD"-flags", QString::number(Knm::Setting::NotRequired)); + } + + if (!d->ui.groupPassword->text().isEmpty()) { + secrets.insert(NM_OPENSWAN_PSK_VALUE, d->ui.groupPassword->text()); + } + + const int groupPasswordMode = d->ui.cbGroupPasswordMode->currentIndex(); + if (groupPasswordMode == Store) { + data.insert(NM_OPENSWAN_PSK_INPUT_MODES, NM_OPENSWAN_PW_TYPE_SAVE); + data.insert(NM_OPENSWAN_PSK_VALUE"-flags", QString::number(Knm::Setting::AgentOwned)); + } else if (groupPasswordMode == AlwaysAsk) { + data.insert(NM_OPENSWAN_PSK_INPUT_MODES, NM_OPENSWAN_PW_TYPE_ASK); + data.insert(NM_OPENSWAN_PSK_VALUE"-flags", QString::number(Knm::Setting::NotSaved)); + } else if (groupPasswordMode == NotRequired) { + data.insert(NM_OPENSWAN_PSK_INPUT_MODES, NM_OPENSWAN_PW_TYPE_UNUSED); + data.insert(NM_OPENSWAN_PSK_VALUE"-flags", QString::number(Knm::Setting::NotRequired)); + } + + if (!d->ui.username->text().isEmpty()) { + data.insert(NM_OPENSWAN_LEFTXAUTHUSER, d->ui.username->text()); + } + + if (!d->ui.phase1->text().isEmpty()) { + data.insert(NM_OPENSWAN_IKE, d->ui.phase1->text()); + } + + if (!d->ui.phase2->text().isEmpty()) { + data.insert(NM_OPENSWAN_ESP, d->ui.phase2->text()); + } + + if (!d->ui.domain->text().isEmpty()) { + data.insert(NM_OPENSWAN_DOMAIN, d->ui.domain->text()); + } + + d->setting->setData(data); + d->setting->setVpnSecrets(secrets); +} + +void LibreswanWidget::userPasswordTypeChanged(int index) +{ + Q_D(LibreswanWidget); + if (index == AlwaysAsk || index == NotRequired) { + d->ui.userPassword->setEnabled(false); + } else { + d->ui.userPassword->setEnabled(true); + } +} + +void LibreswanWidget::groupPasswordTypeChanged(int index) +{ + Q_D(LibreswanWidget); + if (index == AlwaysAsk || index == NotRequired) { + d->ui.groupPassword->setEnabled(false); + } else { + d->ui.groupPassword->setEnabled(true); + } +} + +void LibreswanWidget::showPassword(bool show) +{ + Q_D(LibreswanWidget); + d->ui.userPassword->setPasswordMode(!show); + d->ui.groupPassword->setPasswordMode(!show); +} diff --git a/vpnplugins/libreswan/libreswanwidget.h b/vpnplugins/libreswan/libreswanwidget.h new file mode 100644 index 0000000..6e559bf --- /dev/null +++ b/vpnplugins/libreswan/libreswanwidget.h @@ -0,0 +1,62 @@ +/* + Copyright 2013 Jan Grulich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KNM_LIBRESWAN_WIDGET_H +#define KNM_LIBRESWAN_WIDGET_H + +#include "settingwidget.h" +#include "settings/vpn.h" + +namespace Knm +{ + class Connection; +} // namespace Knm + +namespace Ui +{ +class LibreswanWidget; +} +class LibreswanWidgetPrivate; + +class LibreswanWidget : public SettingWidget +{ +Q_OBJECT +Q_DECLARE_PRIVATE(LibreswanWidget) +public: + enum PasswordStorageType { Store = 0, AlwaysAsk, NotRequired }; + + LibreswanWidget(Knm::Connection *, QWidget *parent = 0); + ~LibreswanWidget(); + + void readConfig(); + void readSecrets(); + void writeConfig(); +protected Q_SLOTS: + void validate() {}; +private slots: + void userPasswordTypeChanged(int index); + void groupPasswordTypeChanged(int index); + void showPassword(bool show); + +private: + LibreswanWidgetPrivate *d_ptr; +}; + +#endif // KNM_LIBRESWAN_WIDGET_H