2
Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) version 3, or any
8
later version accepted by the membership of KDE e.V. (or its
9
successor approved by the membership of KDE e.V.), which shall
10
act as a proxy defined in Section 6 of version 3 of the license.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#include "vpncadvancedwidget.h"
22
#include "ui_vpncadvanced.h"
23
#include "nm-vpnc-service.h"
25
#include <KLocalizedString>
26
#include <KAcceleratorManager>
28
VpncAdvancedWidget::VpncAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent) :
30
m_ui(new Ui::VpncAdvancedWidget)
34
setWindowTitle(i18n("Advanced VPNC properties"));
37
m_ui->vendor->addItem(i18nc("VPNC vendor name", "Cisco"), NM_VPNC_VENDOR_CISCO);
38
m_ui->vendor->addItem(i18nc("VPNC vendor name", "Netscreen"), NM_VPNC_VENDOR_NETSCREEN);
41
m_ui->encryption->addItem(i18nc("VPNC encryption method", "Secure (default)"));
42
m_ui->encryption->addItem(i18nc("VPNC encryption method", "Weak (use with caution)"), NM_VPNC_KEY_SINGLE_DES);
43
m_ui->encryption->addItem(i18nc("VPNC encryption method", "None (completely insecure)"), NM_VPNC_KEY_NO_ENCRYPTION);
46
m_ui->nat->addItem(i18nc("NAT traversal method", "NAT-T when available (default)"), NM_VPNC_NATT_MODE_NATT);
47
m_ui->nat->addItem(i18nc("NAT traversal method", "NAT-T always"), NM_VPNC_NATT_MODE_NATT_ALWAYS);
48
m_ui->nat->addItem(i18nc("NAT traversal method", "Cisco UDP"), NM_VPNC_NATT_MODE_CISCO);
49
m_ui->nat->addItem(i18nc("NAT traversal method", "Disabled"), NM_VPNC_NATT_MODE_NONE);
52
m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 1"), NM_VPNC_DHGROUP_DH1);
53
m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 2 (default)"), NM_VPNC_DHGROUP_DH2);
54
m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 5"), NM_VPNC_DHGROUP_DH5);
57
m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "Server (default)"), NM_VPNC_PFS_SERVER);
58
m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "None"), NM_VPNC_PFS_NOPFS);
59
m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 1"), NM_VPNC_PFS_DH1);
60
m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 2"), NM_VPNC_PFS_DH2);
61
m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 5"), NM_VPNC_PFS_DH5);
65
KAcceleratorManager::manage(this);
68
VpncAdvancedWidget::~VpncAdvancedWidget()
73
void VpncAdvancedWidget::loadConfig(const NetworkManager::VpnSetting::Ptr &setting)
75
m_ui->domain->setText(setting->data().value(NM_VPNC_KEY_DOMAIN));
77
const QString vendor = setting->data().value(NM_VPNC_KEY_VENDOR);
78
if (!vendor.isEmpty())
79
m_ui->vendor->setCurrentIndex(m_ui->vendor->findData(vendor));
81
if (setting->data().value(NM_VPNC_KEY_SINGLE_DES) == "yes")
82
m_ui->encryption->setCurrentIndex(m_ui->encryption->findData(NM_VPNC_KEY_SINGLE_DES));
83
else if (setting->data().value(NM_VPNC_KEY_NO_ENCRYPTION) == "yes")
84
m_ui->encryption->setCurrentIndex(m_ui->encryption->findData(NM_VPNC_KEY_NO_ENCRYPTION));
86
const QString nat = setting->data().value(NM_VPNC_KEY_NAT_TRAVERSAL_MODE);
88
m_ui->nat->setCurrentIndex(m_ui->nat->findData(nat));
90
const QString dhGroup = setting->data().value(NM_VPNC_KEY_DHGROUP);
91
if (!dhGroup.isEmpty())
92
m_ui->dhGroup->setCurrentIndex(m_ui->dhGroup->findData(dhGroup));
94
m_ui->dhGroup->setCurrentIndex(m_ui->dhGroup->findData(NM_VPNC_DHGROUP_DH2)); // default
96
const QString pfs = setting->data().value(NM_VPNC_KEY_PERFECT_FORWARD);
98
m_ui->pfs->setCurrentIndex(m_ui->pfs->findData(pfs));
101
const uint dpd = setting->data().value(NM_VPNC_KEY_DPD_IDLE_TIMEOUT).toUInt(&ok);
102
m_ui->deadPeer->setChecked(ok && dpd == 0);
105
NMStringMap VpncAdvancedWidget::setting() const
108
if (!m_ui->domain->text().isEmpty())
109
result.insert(NM_VPNC_KEY_DOMAIN, m_ui->domain->text());
111
result.insert(NM_VPNC_KEY_VENDOR, m_ui->vendor->itemData(m_ui->vendor->currentIndex()).toString());
113
const QString encData = m_ui->encryption->itemData(m_ui->encryption->currentIndex()).toString();
114
if (!encData.isEmpty()) {
115
if (encData == NM_VPNC_KEY_SINGLE_DES)
116
result.insert(NM_VPNC_KEY_SINGLE_DES, "yes");
117
else if (encData == NM_VPNC_KEY_NO_ENCRYPTION)
118
result.insert(NM_VPNC_KEY_NO_ENCRYPTION, "yes");
121
result.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, m_ui->nat->itemData(m_ui->nat->currentIndex()).toString());
123
result.insert(NM_VPNC_KEY_DHGROUP, m_ui->dhGroup->itemData(m_ui->dhGroup->currentIndex()).toString());
125
result.insert(NM_VPNC_KEY_PERFECT_FORWARD, m_ui->pfs->itemData(m_ui->pfs->currentIndex()).toString());
127
if (m_ui->deadPeer->isChecked())
128
result.insert(NM_VPNC_KEY_DPD_IDLE_TIMEOUT, "0");