diff --git a/plugins/component/AddBtn/addnetbtn.cpp b/plugins/component/AddBtn/addnetbtn.cpp index 811a0c99..858d85a9 100644 --- a/plugins/component/AddBtn/addnetbtn.cpp +++ b/plugins/component/AddBtn/addnetbtn.cpp @@ -37,23 +37,23 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) QHBoxLayout *addLyt = new QHBoxLayout; - QLabel *iconLabel = new QLabel(); - QLabel *textLabel = new QLabel(); + QLabel *iconLabel = new QLabel(this); + m_textLabel = new QLabel(this); if (isWlan) { - textLabel->setText(tr("Add Others")); + m_textLabel->setText(tr("Add Others")); addLyt->addSpacing(8); - addLyt->addWidget(textLabel); + addLyt->addWidget(m_textLabel); } else { - textLabel->setText(tr("Add WiredNetork")); + m_textLabel->setText(tr("Add WiredNetork")); QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic"); - iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24)))); + iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(16, 16)))); iconLabel->setProperty("useIconHighlightEffect", 0x2); // iconLabel->setProperty("iconHighlightEffectMode", 1); addLyt->addStretch(); addLyt->addWidget(iconLabel); - addLyt->addWidget(textLabel); + addLyt->addWidget(m_textLabel); } addLyt->addStretch(); diff --git a/plugins/component/AddBtn/addnetbtn.h b/plugins/component/AddBtn/addnetbtn.h index 959d2d09..85876755 100644 --- a/plugins/component/AddBtn/addnetbtn.h +++ b/plugins/component/AddBtn/addnetbtn.h @@ -25,6 +25,7 @@ #include #include #include +#include class AddNetBtn : public QPushButton { @@ -33,11 +34,18 @@ public: AddNetBtn(bool isWlan, QWidget *parent = nullptr); ~AddNetBtn(); + void setTextLabel(const QString str) { + m_textLabel->setText(str); + } + protected: virtual void leaveEvent(QEvent * event); virtual void enterEvent(QEvent * event); void paintEvent(QPaintEvent *event); +private: + QLabel *m_textLabel; + Q_SIGNALS: void enterWidget(); void leaveWidget(); diff --git a/plugins/vpn/translations/zh_CN.qm b/plugins/vpn/translations/zh_CN.qm new file mode 100644 index 00000000..56074df7 Binary files /dev/null and b/plugins/vpn/translations/zh_CN.qm differ diff --git a/src-vpn/frontend/list-items/vpnlistitem.cpp b/src-vpn/frontend/list-items/vpnlistitem.cpp index eb251470..64679857 100644 --- a/src-vpn/frontend/list-items/vpnlistitem.cpp +++ b/src-vpn/frontend/list-items/vpnlistitem.cpp @@ -200,14 +200,15 @@ void VpnListItem::onInfoButtonClicked() m_vpnDetail->activateWindow(); return; } - m_vpnDetail = new vpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName()); - connect(m_vpnDetail, &vpnDetail::destroyed, [&](){ + m_vpnDetail = new VpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName()); + connect(m_vpnDetail, &VpnDetail::destroyed, [&](){ if (m_vpnDetail != nullptr) { m_vpnDetail = nullptr; } }); m_vpnDetail->show(); + m_vpnDetail->centerToScreen(); } void VpnListItem::updateConnectionState(ConnectState state) diff --git a/src-vpn/frontend/list-items/vpnlistitem.h b/src-vpn/frontend/list-items/vpnlistitem.h index 95fcfcd7..b2be2edc 100644 --- a/src-vpn/frontend/list-items/vpnlistitem.h +++ b/src-vpn/frontend/list-items/vpnlistitem.h @@ -82,7 +82,7 @@ private: QString m_deviceName = ""; - vpnDetail *m_vpnDetail = nullptr; + VpnDetail *m_vpnDetail = nullptr; }; #endif // VPNLISTITEM_H diff --git a/src-vpn/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h index c822c4f4..2855b96b 100644 --- a/src-vpn/frontend/single-pages/singlepage.h +++ b/src-vpn/frontend/single-pages/singlepage.h @@ -43,7 +43,7 @@ using namespace kdk; #define MAIN_LAYOUT_SPACING 0 #define TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 #define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define NET_LAYOUT_MARGINS 8,8,8,8 +#define NET_LAYOUT_MARGINS 8,8,0,8 #define TEXT_HEIGHT 20 #define SETTINGS_LAYOUT_MARGINS 23,0,24,0 diff --git a/src-vpn/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp index 41c8cb70..e2cb274b 100644 --- a/src-vpn/frontend/single-pages/vpnpage.cpp +++ b/src-vpn/frontend/single-pages/vpnpage.cpp @@ -147,11 +147,7 @@ void VpnPage::constructItemArea() } } - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } else { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); } void VpnPage::initVpnArea() @@ -174,14 +170,6 @@ void VpnPage::resetPageHeight() m_listFrame->show(); m_netDivider->show(); } - - for (int i = 0; i < m_mainLayout->count(); i ++) { - QWidget *w = m_mainLayout->itemAt(i)->widget(); - if (w != nullptr && w->isHidden() != true) { - height += w->height(); - } - } - this->setFixedHeight(height + PAGE_SPACE); } bool VpnPage::removeConnectionItem(QMap &connectMap, @@ -203,9 +191,7 @@ bool VpnPage::removeConnectionItem(QMap &connectMap, p_listWidgetItem = nullptr; iter = connectMap.erase(iter); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } + resetListWidgetWidth(); return true; } } @@ -249,9 +235,7 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线 delete p_newItem; p_newItem = nullptr; - if (m_listWidget->count() >= MAX_ITEMS) { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); resetPageHeight(); resetWindowPosition(); this->update(); @@ -338,9 +322,8 @@ void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem) deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid); QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); m_activeItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } + + resetListWidgetWidth(); return; } @@ -356,11 +339,7 @@ void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } else { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); } void VpnPage::updateConnectionState(QMap &connectMap, @@ -700,3 +679,12 @@ void VpnPage::resetWindowPosition() kdk::WindowManager::setGeometry(this->windowHandle(), rect); qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; } + +void VpnPage::resetListWidgetWidth() +{ + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } else { + m_listFrame->setFixedWidth(MAX_WIDTH); + } +} diff --git a/src-vpn/frontend/single-pages/vpnpage.h b/src-vpn/frontend/single-pages/vpnpage.h index 0b7dec31..e5748723 100644 --- a/src-vpn/frontend/single-pages/vpnpage.h +++ b/src-vpn/frontend/single-pages/vpnpage.h @@ -97,7 +97,7 @@ private: QListWidget *vpnListWidget, QString uuid); void resetWindowPosition(); - + void resetListWidgetWidth(); Q_SIGNALS: void vpnAdd(QStringList info); diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.cpp b/src-vpn/frontend/vpndetails/vpnaddpage.cpp new file mode 100644 index 00000000..087470d1 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnaddpage.cpp @@ -0,0 +1,234 @@ +#include "vpnaddpage.h" +#include +#include "vpnconfigpage.h" + +vpnAddPage::vpnAddPage(QWidget *parent) : QWidget(parent) +{ + m_vpnConnOperation = new KyVpnConnectOperation(this); + initWindow(); + initUI(); + initConnection(); + centerToScreen(); +} + +void vpnAddPage::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); + this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); +} + +void vpnAddPage::initWindow() +{ + this->setFixedSize(VPNADDPAGE_SIZE); + this->setWindowTitle(tr("create VPN")); + this->setWindowFlag(Qt::WindowMinMaxButtonsHint,false); + this->setAttribute(Qt::WA_DeleteOnClose); +} + +void vpnAddPage::initUI() +{ + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(VPNADDPAGE_MAINLAYOUT_MARGINS); + mainLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + initVpnTypeFrame(); + initVpnNameFrame(); + initVpnServerFrame(); + initButtonFrame(); + onSetConfimBtnEnable(); + + mainLayout->addWidget(m_vpnTypeFrame); + mainLayout->addWidget(m_vpnNameFrame); + mainLayout->addWidget(m_vpnServerFrame); + mainLayout->addStretch(); + mainLayout->addWidget(m_buttonFrame); + this->setLayout(mainLayout); +} + +void vpnAddPage::initVpnTypeFrame() +{ + m_vpnTypeFrame = new QFrame(this); + m_vpnTypeFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnTypeFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *typeLayout = new QHBoxLayout(m_vpnTypeFrame); + typeLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + typeLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnTypeLabel = new QLabel(tr("VPN Type"), this); + vpnTypeLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnTypeComboBox = new QComboBox(this); + m_vpnTypeComboBox->setInsertPolicy(QComboBox::NoInsert); + m_vpnTypeComboBox->setFixedWidth(VPNADDPAGE_COMBOBOX_FIXEDWIDTH); + m_vpnTypeComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); + + m_vpnTypeComboBox->addItem("L2TP", L2TP); + m_vpnTypeComboBox->addItem("open VPN", OPEN_VPN); + m_vpnTypeComboBox->addItem("PPTP", PPTP); + m_vpnTypeComboBox->addItem("strong-swan", STRONG_SWAN); + + + typeLayout->addWidget(vpnTypeLabel); + typeLayout->addWidget(m_vpnTypeComboBox); + m_vpnTypeFrame->setLayout(typeLayout); +} + +void vpnAddPage::initVpnNameFrame() +{ + m_vpnNameFrame = new QFrame(this); + m_vpnNameFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnNameFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *nameLayout = new QHBoxLayout(m_vpnNameFrame); + nameLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + nameLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnNameLabel = new QLabel(tr("VPN Name"), this); + vpnNameLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnNameLineEdit = new QLineEdit(this); + m_vpnNameLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH); + m_vpnNameLineEdit->setMaxLength(VPNADDPAGE_NAME_MAX_LENGTH); + m_vpnNameLineEdit->setPlaceholderText(tr("Required")); //必填 + + nameLayout->addWidget(vpnNameLabel); + nameLayout->addWidget(m_vpnNameLineEdit); + m_vpnNameFrame->setLayout(nameLayout); +} + +void vpnAddPage::initVpnServerFrame() +{ + m_vpnServerFrame = new QFrame(this); + m_vpnServerFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnServerFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *serverLayout = new QHBoxLayout(m_vpnServerFrame); + serverLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + serverLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnServerLabel = new QLabel(tr("VPN Server"), this); + vpnServerLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnServerLineEdit = new QLineEdit(this); + m_vpnServerLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH); + m_vpnServerLineEdit->setPlaceholderText(tr("Required")); //必填 + + serverLayout->addWidget(vpnServerLabel); + serverLayout->addWidget(m_vpnServerLineEdit); + m_vpnServerFrame->setLayout(serverLayout); + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_vpnServerLineEdit->setValidator(ipExpVal); +} + +void vpnAddPage::initButtonFrame() +{ + m_buttonFrame = new QFrame(this); + m_buttonFrame->setFixedSize(VPNDETAILPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *buttonLayout = new QHBoxLayout(m_buttonFrame); + buttonLayout->setContentsMargins(VPNDETAILPAGE_ITEM_MARGINS); + buttonLayout->setSpacing(VPNDETAILPAGE_NULLSPACE); + + QLabel *autoConnectLabel = new QLabel(this); + m_autoConnectBox = new QCheckBox(this); + autoConnectLabel->setText(tr("Auto Connection")); + QWidget *autoConWidget = new QWidget(this); + QHBoxLayout *autoLayout = new QHBoxLayout(autoConWidget); + + autoLayout->setContentsMargins(VPNDETAILPAGE_NULLMAGINS); + autoLayout->setSpacing(VPNDETAILPAGE_NULLSPACE); + autoLayout->addWidget(m_autoConnectBox); + autoLayout->addWidget(autoConnectLabel); + autoConWidget->setLayout(autoLayout); + + m_confimBtn = new QPushButton(this); + m_confimBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE); + m_confimBtn->setText(tr("Confirm")); + m_cancelBtn = new QPushButton(this); + m_cancelBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE); + m_cancelBtn->setText(tr("Cancel")); + + buttonLayout->addWidget(autoConWidget); + buttonLayout->addStretch(); + buttonLayout->addWidget(m_cancelBtn); + buttonLayout->addSpacing(VPNDETAILPAGE_BUTTON_SPACE); + buttonLayout->addWidget(m_confimBtn); + m_buttonFrame->setLayout(buttonLayout); +} + +void vpnAddPage::initConnection() +{ + if (m_vpnNameLineEdit != nullptr) { + connect(m_vpnNameLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable); + } + + if (m_vpnServerLineEdit != nullptr) { + connect(m_vpnServerLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable); + } + + if (m_cancelBtn != nullptr) { + connect(m_cancelBtn, &QPushButton::clicked, [&] () {this->close();}); + } + + if (m_confimBtn != nullptr) { + connect(m_confimBtn, &QPushButton::clicked, this, &vpnAddPage::onConfimBtnClicked); + } +} + +bool vpnAddPage::checkConfimBtnIsEnabled() +{ + if (m_vpnNameLineEdit->text().isEmpty()) { + qDebug() << "ipv4address empty or invalid"; + return false; + } + + if (m_vpnServerLineEdit->text().isEmpty()) { + qDebug() << "ipv4 netMask empty or invalid"; + return false; + } + return true; +} + +void vpnAddPage::onSetConfimBtnEnable() +{ + m_confimBtn->setEnabled(checkConfimBtnIsEnabled()); +} + +void vpnAddPage::onConfimBtnClicked() +{ + //新建有线连接 + qDebug() << "Confirm create vpn connect"; + if (!createVpnConnect()) { +// setNetdetailSomeEnable(true); +// return; + } + close(); +} + +bool vpnAddPage::createVpnConnect() +{ + KyVpnConfig vpnSetting; + QString connectName = m_vpnNameLineEdit->text(); + vpnSetting.m_gateway = m_vpnServerLineEdit->text(); + vpnSetting.setConnectName(connectName); + vpnSetting.m_vpnName = connectName; + vpnSetting.m_isAutoConnect = m_autoConnectBox->isChecked(); + vpnSetting.m_vpnType = (KyVpnType)m_vpnTypeComboBox->currentData().toInt(); + + m_vpnConnOperation->createVpnConnect(vpnSetting); + return true; +} + +vpnAddPage::~vpnAddPage() +{ + Q_EMIT this->closed(); +} diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.h b/src-vpn/frontend/vpndetails/vpnaddpage.h new file mode 100644 index 00000000..19fe9c64 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnaddpage.h @@ -0,0 +1,90 @@ +#ifndef VPNADDPAGE_H +#define VPNADDPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +#define VPNADDPAGE_MAINLAYOUT_MARGINS 0, 12, 0, 12 +#define VPNADDPAGE_ITEM_MARGINS 24, 0, 24, 0 +#define VPNADDPAGE_NULLMAGINS 0, 0, 0, 0 + +#define VPNADDPAGE_SIZE 520,312 +#define VPNADDPAGE_FRAME_FIXEDSIZE 520, 60 +#define VPNADDPAGE_BUTTON_FIXEDSIZE 96, 36 + +#define VPNADDPAGE_NULLSPACE 0 +#define VPNADDPAGE_BUTTON_SPACE 16 +#define VPNADDPAGE_NAME_MAX_LENGTH 32 +#define VPNADDPAGE_LABLE_FIXEDWIDTH 112 +#define VPNADDPAGE_COMBOBOX_FIXEDWIDTH 360 +#define VPNADDPAGE_INPUTBOX_FIXEDWIDTH 360 + +#define VPNDETAILPAGE_ITEM_MARGINS 24, 0, 24, 0 +#define VPNDETAILPAGE_NULLMAGINS 0, 0, 0, 0 + +#define VPNDETAILPAGE_FRAME_FIXEDSIZE 520, 60 +#define VPNDETAILPAGE_BUTTON_FIXEDSIZE 96, 36 + +#define VPNDETAILPAGE_NULLSPACE 0 +#define VPNDETAILPAGE_BUTTON_SPACE 16 + + + +class vpnAddPage : public QWidget +{ + Q_OBJECT +public: + explicit vpnAddPage(QWidget *parent = nullptr); + void centerToScreen(); + ~vpnAddPage(); + +private: + void initWindow(); + void initUI(); + void initVpnTypeFrame(); + void initVpnNameFrame(); + void initVpnServerFrame(); + void initButtonFrame(); + + void initConnection(); + + bool checkConfimBtnIsEnabled(); + bool createVpnConnect(); + +private: + QFrame *m_vpnTypeFrame = nullptr; + QFrame *m_vpnNameFrame = nullptr; + QFrame *m_vpnServerFrame = nullptr; + QFrame *m_buttonFrame = nullptr; + + QComboBox *m_vpnTypeComboBox = nullptr; + QLineEdit *m_vpnNameLineEdit = nullptr; + QLineEdit *m_vpnServerLineEdit = nullptr; + + QPushButton *m_confimBtn = nullptr; + QPushButton *m_cancelBtn = nullptr; + QCheckBox *m_autoConnectBox = nullptr; + + KyVpnConnectOperation *m_vpnConnOperation = nullptr; + +private Q_SLOTS: + void onConfimBtnClicked(); + void onSetConfimBtnEnable(); + +Q_SIGNALS: + void closed(); +}; + +#endif // VPNADDPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp new file mode 100644 index 00000000..c8a3b08d --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp @@ -0,0 +1,1508 @@ +#include "vpnadvancedpage.h" + +#include +#include +#include +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define LAYOUT_SPACING_SMALL 8 +#define HOR_LAYOUT_SPACING 24 +#define LAYOUT_ADD_SPACING 16 +#define VLAYOUT_ADD_SPACING 24 +#define LISTWIDGET_HEIGHT 184 +#define LISTWIDGET_HEIGHT_SMALL 112 +#define MIN_EDIT_WIDTH 150 +#define FIX_EDIT_WIDTH 200 +#define MIN_LABEL_WIDTH 140 +#define MAX_LABEL_WIDTH 240 +#define ONE_LABEL_WIDTH 440 +#define MAX_MRU_LENGTH 4 +#define ITEM_HEIGHT 36 +#define COMP_MODE_PROTOCOL 3 +#define COMP_MODE_ADDRESS 4 +#define LOG_FLAG "[VPN AdvancedPage]" + +VpnAdvancedPage::VpnAdvancedPage(QWidget *parent) : QFrame(parent) +{ + initUi(); + initConnect(); + initDefalutCheckState(); +} + +void VpnAdvancedPage::setL2tpOrPptpAdiaInfo(const KyVpnConfig &vpnInfo) +{ + //L2TP PPTP共有 + m_mppeECheckbox->setChecked(vpnInfo.m_mppeEnable); + if (m_mppeECheckbox->isChecked()) { + m_mppeECombox->setCurrentIndex((int)vpnInfo.m_mppeEncryptMethod); + } else { + m_mppeECombox->setEnabled(false); + } + m_useStatefulECheckbox->setChecked(vpnInfo.m_isAllowStatefulEncryption); + m_useStatefulECheckbox->setEnabled(vpnInfo.m_mppeEnable); + m_papAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + m_chapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + m_eapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + + m_sendPppEchoPkgCheckbox->setChecked(vpnInfo.m_sendPppPackage); + + //Auth Methods + m_papAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP)); + m_chapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP)); + m_mschapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP)); + m_mschap2AuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2)); + m_eapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP)); + + //Compress Methods + m_bsdCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD)); + m_defaultCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE)); + m_tcpCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP)); + + + //L2TP + if (vpnInfo.m_vpnType == KYVPNTYPE_L2TP) { + m_protocolCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO)); + m_addressCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR)); + + m_mruEdit->setText(vpnInfo.m_mru); + m_mtuEdit->setText(vpnInfo.m_mtu); + } +} + +void VpnAdvancedPage::setOpenVpnAdiaInfo(const KyVpnConfig &vpnInfo) +{ + //General + m_customGatewayPortCheckbox->setChecked(vpnInfo.m_useAssignPort); + m_gatewayPortEdit->setText(vpnInfo.m_assignPort); + + m_customRenegotiaInrCheckbox->setChecked(vpnInfo.m_useRenegSeconds); + m_renogotiaInrEdit->setText(vpnInfo.m_renegSeconds); + + m_compressionCheckbox->setChecked(vpnInfo.m_useCompress); + m_compressionCombox->setCurrentIndex((int)vpnInfo.m_openvpnCompress); + + m_tcpConnCheckbox->setChecked(vpnInfo.m_useTcpLink); + + m_setVDevTypeCheckbox->setChecked(vpnInfo.m_setDevType); + m_setVDevTypeCombox->setCurrentIndex((int)vpnInfo.m_devType); + + m_setVDevNameCheckbox->setChecked(vpnInfo.m_setDevName); + m_setVDevNameEdit->setText(vpnInfo.m_devName); + + m_customMtuCheckbox->setChecked(vpnInfo.m_useTunnelMtu); + m_customMtuEdit->setText(vpnInfo.m_tunnelMtu); + + m_customUdpFragSizeCheckbox->setChecked(vpnInfo.m_useFragmentSize); + m_customUdpFragSizeEdit->setText(vpnInfo.m_fragmentSize); + + m_tcpMssCheckbox->setChecked(vpnInfo.m_mssfix); + + m_randomRemoteHostCheckbox->setChecked(vpnInfo.m_remoteRandom); + + m_ipv6TunLinkCheckbox->setChecked(vpnInfo.m_ipv6TunLink); + + m_specPingInrCheckbox->setChecked(vpnInfo.m_setPingCycle); + m_specPingInrEdit->setText(vpnInfo.m_pingCycle); + + m_specExitPingCheckbox->setChecked(vpnInfo.m_usePingMethod); + m_specExitRestarCombox->setCurrentIndex((int)vpnInfo.m_pingMethod); + m_specExRePingEdit->setText(vpnInfo.m_pingMethodTime); + + m_acceptAuthedPaksCheckbox->setChecked(vpnInfo.m_float); + + m_specMaxRouteCheckbox->setChecked(vpnInfo.m_setMaxRoute); + m_specMaxRouteEdit->setText(vpnInfo.m_maxRoute); + + + //TLS settings + m_serverCertCheckCombox->setCurrentIndex((int)vpnInfo.m_checkServerCa); + + m_subjectMatchEdit->setText(vpnInfo.m_verifyName); + + m_usePreviousCertCheckbox->setChecked(vpnInfo.m_useRemoteCertTls); + m_usePreviousCertCombox->setCurrentIndex((int)vpnInfo.m_remoteCertType); + + m_verifyPeerCertCheckbox->setChecked(vpnInfo.m_useNsCertTls); + m_verifyPeerCertCombox->setCurrentIndex((int)vpnInfo.m_nsCertType); + + m_tlsModeCombox->setCurrentIndex(vpnInfo.m_vpnTlsMode); + m_keyPathEdit->setText(vpnInfo.m_vpnKeyFile); + if (vpnInfo.m_vpnTlsMode == KYVPNTLS_AUTHENTICATION) { + if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ZERO) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ZERO_INDEX); + } else if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ONE) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ONE_INDEX); + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } + + //Proxies + m_proxyTypeCombox->setCurrentIndex((int)vpnInfo.m_vpnProxyType); + m_proxyServerAddEdit->setText(vpnInfo.m_vpnProxyServer); + m_proxyPortEdit->setText(vpnInfo.m_vpnProxyPort); + m_infiniteRetryCheckbox->setChecked(vpnInfo.m_vpnProxyRetry); + m_proxyUsernameEdit->setText(vpnInfo.m_vpnProxyName); + m_proxyPwdEdit->setText(vpnInfo.m_vpnProxyPasswd); + + //Security + m_customKeySizeCheckbox->setChecked(vpnInfo.m_useKeysize); + m_customKeySizeEdit->setText(vpnInfo.m_keySize); + m_hmacAuthCombox->setCurrentIndex((int)vpnInfo.m_hmacAuthMethod); +} + +void VpnAdvancedPage::setStrongSwanAdiaInfo(const KyVpnConfig &vpnInfo) +{ + m_requestInIPCheckbox->setChecked(vpnInfo.m_virtual); + m_udpEncapCheckbox->setChecked(vpnInfo.m_encap); + m_ipCompCheckbox->setChecked(vpnInfo.m_ipcomp); + m_enablCustomCheckbox->setChecked(vpnInfo.m_proposal); + + if (vpnInfo.m_proposal) { + m_ikeEdit->setText(vpnInfo.m_ike); + m_espEdit->setText(vpnInfo.m_esp); + } +} + +bool VpnAdvancedPage::checkIsChanged(const KyVpnConfig &vpnInfo, VpnType &vpnType) +{ + bool isChanged = false; + switch (vpnType) { + case L2TP: + if (checkL2tpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case PPTP: + if (checkPptpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case OPEN_VPN: + if (checkOpenVpnIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case STRONG_SWAN: + if (checkStrongSwanIsChanged(vpnInfo)) { + isChanged = true; + } + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN Type" << vpnType; + break; + } + return isChanged; +} + +bool VpnAdvancedPage::checkL2tpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked() + || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod + || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked() + || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO) != m_protocolCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR) != m_addressCompModeCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_mru != m_mruEdit->text() || vpnInfo.m_mtu != m_mtuEdit->text()) { + isChanged = true; + } + + return isChanged; +} + +bool VpnAdvancedPage::checkPptpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked() + || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod + || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked() + || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked()) { + + isChanged = true; + } + + return isChanged; +} + +bool VpnAdvancedPage::checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + //General + if (vpnInfo.m_useAssignPort != m_customGatewayPortCheckbox->isChecked() + || vpnInfo.m_assignPort != m_gatewayPortEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useRenegSeconds != m_customRenegotiaInrCheckbox->isChecked() + || vpnInfo.m_renegSeconds != m_renogotiaInrEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useCompress != m_compressionCheckbox->isChecked() + || vpnInfo.m_openvpnCompress != m_compressionCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_useTcpLink != m_tcpConnCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setDevType != m_setVDevTypeCheckbox->isChecked() + || vpnInfo.m_devType != m_setVDevTypeCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_setDevName != m_setVDevNameCheckbox->isChecked() + || vpnInfo.m_devName != m_setVDevNameEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useTunnelMtu != m_customMtuCheckbox->isChecked() + || vpnInfo.m_tunnelMtu != m_customMtuEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useFragmentSize != m_customUdpFragSizeCheckbox->isChecked() + || vpnInfo.m_fragmentSize != m_customUdpFragSizeEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_mssfix != m_tcpMssCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_remoteRandom != m_randomRemoteHostCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_ipv6TunLink != m_ipv6TunLinkCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setPingCycle != m_specPingInrCheckbox->isChecked() + || vpnInfo.m_pingCycle != m_specPingInrEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_usePingMethod != m_specExitPingCheckbox->isChecked() + || vpnInfo.m_pingMethod != m_specExitRestarCombox->currentData().toInt() + || vpnInfo.m_pingMethodTime != m_specExRePingEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_float != m_acceptAuthedPaksCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setMaxRoute != m_specMaxRouteCheckbox->isChecked() + || vpnInfo.m_maxRoute != m_specMaxRouteEdit->text()) { + isChanged = true; + } + + + //TLS settings + if (vpnInfo.m_checkServerCa != m_serverCertCheckCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_verifyName != m_subjectMatchEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useRemoteCertTls != m_usePreviousCertCheckbox->isChecked() + || vpnInfo.m_remoteCertType != m_usePreviousCertCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_useNsCertTls != m_verifyPeerCertCheckbox->isChecked() + || vpnInfo.m_nsCertType != m_verifyPeerCertCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_vpnTlsMode != m_tlsModeCombox->currentData().toInt() + || vpnInfo.m_vpnKeyFile != m_keyPathEdit->text() + || vpnInfo.m_vpnTlsTaDir != m_keyDirectionCombox->currentData().toString()) { + isChanged = true; + } + + + //Proxies + int currentProxyType = m_proxyTypeCombox->currentData().toInt(); + if (vpnInfo.m_vpnProxyType != currentProxyType) { + isChanged = true; + } + + if (currentProxyType == HTTP || currentProxyType == SOCKS) { + if (vpnInfo.m_vpnProxyServer != m_proxyServerAddEdit->text() + || vpnInfo.m_vpnProxyPort != m_proxyPortEdit->text() + || vpnInfo.m_vpnProxyRetry != m_infiniteRetryCheckbox->isChecked()) { + isChanged = true; + } + + if (currentProxyType == HTTP) { + if (vpnInfo.m_vpnProxyName != m_proxyUsernameEdit->text() + || vpnInfo.m_vpnProxyPasswd != m_proxyPwdEdit->text()) { + isChanged = true; + } + } + } + + + //Security + if (vpnInfo.m_useKeysize != m_customKeySizeCheckbox->isChecked() + || vpnInfo.m_keySize != m_customKeySizeEdit->text() + || vpnInfo.m_hmacAuthMethod != m_hmacAuthCombox->currentData().toInt()) { + isChanged = true; + } + + + return isChanged; +} + +bool VpnAdvancedPage::checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_virtual != m_requestInIPCheckbox->isChecked() + || vpnInfo.m_encap != m_udpEncapCheckbox->isChecked() + || vpnInfo.m_ipcomp != m_ipCompCheckbox->isChecked() + || vpnInfo.m_proposal != m_enablCustomCheckbox->isChecked()) { + + isChanged = true; + } + + if (m_enablCustomCheckbox->isChecked()) { + if (vpnInfo.m_ike != m_ikeEdit->text() || vpnInfo.m_esp != m_espEdit->text()) { + isChanged = true; + } + } + + return isChanged; +} + +void VpnAdvancedPage::updateL2tpOrPptpAdiaInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_mppeEnable = m_mppeECheckbox->isChecked(); + vpnInfo.m_mppeEncryptMethod = (KyMPPEMethod)m_mppeECombox->currentData().toInt(); + vpnInfo.m_isAllowStatefulEncryption = m_useStatefulECheckbox->isChecked(); + vpnInfo.m_sendPppPackage = m_sendPppEchoPkgCheckbox->isChecked(); + + vpnInfo.m_authMethods.setFlag(KYAUTH2_PAP, m_papAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_CHAP, m_chapAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAP, m_mschapAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAPV2, m_mschap2AuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_EAP, m_eapAuthCheckbox->isChecked()); + + vpnInfo.m_compressMethods.setFlag(KYCOMP_BSD, m_bsdCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_DEFLATE, m_defaultCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_TCP, m_tcpCompModeCheckbox->isChecked()); + + if (!m_compModeListWidget->item(COMP_MODE_PROTOCOL)->isHidden() + && !m_compModeListWidget->item(COMP_MODE_ADDRESS)->isHidden()) { + vpnInfo.m_compressMethods.setFlag(KYCOMP_PROTO, m_protocolCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_ADDR, m_addressCompModeCheckbox->isChecked()); + vpnInfo.m_mru = m_mruEdit->text(); + vpnInfo.m_mtu = m_mtuEdit->text(); + qDebug() << LOG_FLAG << "Update L2TP advanced info finished"; + + } else { + qDebug() << LOG_FLAG << "Update PPTP advanced info finished"; + } +} + +void VpnAdvancedPage::updateOpenVpnAdiaInfo(KyVpnConfig &vpnInfo) +{ + //General + vpnInfo.m_useAssignPort = m_customGatewayPortCheckbox->isChecked(); + vpnInfo.m_assignPort = m_gatewayPortEdit->text(); + + vpnInfo.m_useRenegSeconds = m_customRenegotiaInrCheckbox->isChecked(); + vpnInfo.m_renegSeconds = m_renogotiaInrEdit->text(); + + vpnInfo.m_useCompress = m_compressionCheckbox->isChecked(); + vpnInfo.m_openvpnCompress = (KyCompressMethod2)m_compressionCombox->currentData().toInt(); + + vpnInfo.m_useTcpLink = m_tcpConnCheckbox->isChecked(); + + vpnInfo.m_setDevType = m_setVDevTypeCheckbox->isChecked(); + vpnInfo.m_devType = (KyVirtualDeviceType)m_setVDevTypeCombox->currentData().toInt(); + + vpnInfo.m_setDevName = m_setVDevNameCheckbox->isChecked(); + vpnInfo.m_devName = m_setVDevNameEdit->text(); + + vpnInfo.m_useTunnelMtu = m_customMtuCheckbox->isChecked(); + vpnInfo.m_tunnelMtu = m_customMtuEdit->text(); + + vpnInfo.m_useFragmentSize = m_customUdpFragSizeCheckbox->isChecked(); + vpnInfo.m_fragmentSize = m_customUdpFragSizeEdit->text(); + + vpnInfo.m_mssfix = m_tcpMssCheckbox->isChecked(); + vpnInfo.m_remoteRandom = m_randomRemoteHostCheckbox->isChecked(); + vpnInfo.m_ipv6TunLink = m_ipv6TunLinkCheckbox->isChecked(); + + vpnInfo.m_setPingCycle = m_specPingInrCheckbox->isChecked(); + vpnInfo.m_pingCycle = m_specPingInrEdit->text(); + + vpnInfo.m_usePingMethod = m_specExitPingCheckbox->isChecked(); + vpnInfo.m_pingMethod = (KyVpnPingMethod)m_specExitRestarCombox->currentData().toInt(); + vpnInfo.m_pingMethodTime = m_specExRePingEdit->text(); + + vpnInfo.m_float = m_acceptAuthedPaksCheckbox->isChecked(); + + vpnInfo.m_setMaxRoute = m_specMaxRouteCheckbox->isChecked(); + vpnInfo.m_maxRoute = m_specMaxRouteEdit->text(); + + + //TLS settings + vpnInfo.m_checkServerCa = (KyVpnCheckServerMethod)m_serverCertCheckCombox->currentData().toInt(); + vpnInfo.m_verifyName = m_subjectMatchEdit->text(); + + vpnInfo.m_useRemoteCertTls = m_usePreviousCertCheckbox->isChecked(); + vpnInfo.m_remoteCertType = (KyVpnCertType)m_usePreviousCertCombox->currentData().toInt(); + + vpnInfo.m_useNsCertTls = m_verifyPeerCertCheckbox->isChecked(); + vpnInfo.m_nsCertType = (KyVpnCertType)m_verifyPeerCertCombox->currentData().toInt(); + + vpnInfo.m_vpnTlsMode = (KyVpnTlsMode)m_tlsModeCombox->currentData().toInt(); + vpnInfo.m_vpnKeyFile = m_keyPathEdit->text(); + vpnInfo.m_vpnTlsTaDir = m_keyDirectionCombox->currentData().toString(); + + + //Proxies + vpnInfo.m_vpnProxyType = (KyVpnProxyType)m_proxyTypeCombox->currentData().toInt(); + vpnInfo.m_vpnProxyServer = m_proxyServerAddEdit->text(); + vpnInfo.m_vpnProxyPort = m_proxyPortEdit->text(); + vpnInfo.m_vpnProxyRetry = m_infiniteRetryCheckbox->isChecked(); + vpnInfo.m_vpnProxyName = m_proxyUsernameEdit->text(); + vpnInfo.m_vpnProxyPasswd = m_proxyPwdEdit->text(); + + + //Security + vpnInfo.m_useKeysize = m_customKeySizeCheckbox->isChecked(); + vpnInfo.m_keySize = m_customKeySizeEdit->text(); + vpnInfo.m_hmacAuthMethod = (KyHMACAuthMethod)m_hmacAuthCombox->currentData().toInt(); + + qDebug() << LOG_FLAG << "Update open VPN advanced info finished"; +} + +void VpnAdvancedPage::updateStrongSwanAdiaInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_virtual = m_requestInIPCheckbox->isChecked(); + vpnInfo.m_encap = m_udpEncapCheckbox->isChecked(); + vpnInfo.m_ipcomp = m_ipCompCheckbox->isChecked(); + vpnInfo.m_proposal = m_enablCustomCheckbox->isChecked(); + + vpnInfo.m_ike = m_ikeEdit->text(); + vpnInfo.m_esp = m_espEdit->text(); + + qDebug() << LOG_FLAG << "update strong-swan advanced info finished"; +} + +void VpnAdvancedPage::setVpnAdvancedPage(const VpnType &type) +{ + switch (type) { + case L2TP: + showL2tpAdiaPage(); + break; + case OPEN_VPN: + showOpenVpnAdiaPage(); + break; + case PPTP: + showPptpAdiaPage(); + break; + case STRONG_SWAN: + showSSwanAdiaPage(); + break; + default: + break; + } +} + +void VpnAdvancedPage::paintEvent(QPaintEvent *event) +{ + if (m_authModeListWidget) { + QPalette mpal(m_authModeListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_authModeListWidget->setBackgroundRole(QPalette::Base); + m_authModeListWidget->setAlternatingRowColors(true); + m_authModeListWidget->setPalette(mpal); + } + if (m_compModeListWidget) { + QPalette mpal(m_compModeListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_compModeListWidget->setBackgroundRole(QPalette::Base); + m_compModeListWidget->setAlternatingRowColors(true); + m_compModeListWidget->setPalette(mpal); + } + if (m_optionsListWidget) { + QPalette mpal(m_optionsListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_optionsListWidget->setBackgroundRole(QPalette::Base); + m_optionsListWidget->setAlternatingRowColors(true); + m_optionsListWidget->setPalette(mpal); + } +} + +void VpnAdvancedPage::initUi() +{ + m_defaultAdiaFrame = new QFrame(this); + m_openVpnAdiaFrame = new QFrame(this); + m_sSwanAdiaFrame = new QFrame(this); + + initDefaultAdiaFrame(); + initOpenVpnAdiaFrame(); + initSSwanAdiaFrame(); + + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(NO_SPACE); + mainLayout->addWidget(m_defaultAdiaFrame); + mainLayout->addWidget(m_openVpnAdiaFrame); + mainLayout->addWidget(m_sSwanAdiaFrame); + mainLayout->addSpacing(3); + mainLayout->addStretch(); +} + +void VpnAdvancedPage::initConnect() +{ + connect(m_mppeECheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_mppeECombox->setEnabled(state); + m_useStatefulECheckbox->setEnabled(state); + + m_papAuthCheckbox->setEnabled(!state); + m_chapAuthCheckbox->setEnabled(!state); + m_eapAuthCheckbox->setEnabled(!state); + }); + + //strong-Swan + connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_ikeEspFrame->setEnabled(state); + }); + + //open VPN General + connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_gatewayPortEdit->setEnabled(state); + }); + connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_renogotiaInrEdit->setEnabled(state); + }); + connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_compressionCombox->setEnabled(state); + }); + connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + if (state == Qt::CheckState::Unchecked) { + m_compressionCombox->setCurrentIndex(KYCOMP2_LZODISABLE); + } + }); + connect(m_setVDevTypeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_setVDevTypeCombox->setEnabled(state); + }); + connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_setVDevNameEdit->setEnabled(state); + }); + connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customMtuEdit->setEnabled(state); + }); + connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customUdpFragSizeEdit->setEnabled(state); + }); + connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specPingInrEdit->setEnabled(state); + }); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specExitRestarCombox->setEnabled(state); + }); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specExRePingEdit->setEnabled(state); + }); + connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specMaxRouteEdit->setEnabled(state); + }); + + //open VPN TLS settings + connect(m_serverCertCheckCombox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + if (index == (int)KYCHECKSERVER_NONE) { + m_subjectMatchEdit->setEnabled(false); + } else { + m_subjectMatchEdit->setEnabled(true); + } + }); + connect(m_tlsModeCombox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnAdvancedPage::onTlsModeComboxIndexChanged); + connect(m_usePreviousCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_usePreviousCertCombox->setEnabled(state); + }); + connect(m_verifyPeerCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_verifyPeerCertCombox->setEnabled(state); + }); + //open VPN proxies + connect(m_proxyTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnAdvancedPage::onProxyTypeComboxIndexChanged); + //open VPN security + connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customKeySizeEdit->setEnabled(state); + }); + + connect(m_mruEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_mtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_gatewayPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_renogotiaInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_setVDevNameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customMtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customUdpFragSizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specPingInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specExRePingEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_subjectMatchEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specMaxRouteEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_keyPathEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyServerAddEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyUsernameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyPwdEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customKeySizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_ikeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_espEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + + connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + + connect(m_serverCertCheckCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_tlsModeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_proxyTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_keyPathChooseBtn, &QPushButton::clicked, this, &VpnAdvancedPage::onKeyPathButtonClicked); +} + +void VpnAdvancedPage::initDefaultAdiaFrame() +{ + /**********控件**********/ + m_mppeECheckbox = new QCheckBox(this); + m_useStatefulECheckbox = new QCheckBox(this); + m_sendPppEchoPkgCheckbox = new QCheckBox(this); + m_authModeLabel = new QLabel(this); + m_compModeLabel = new QLabel(this); + m_mruLabel = new QLabel(this); + m_mtuLabel = new QLabel(this); + + m_mppeECombox = new QComboBox(this); + m_authModeListWidget = new QListWidget(this); + m_papAuthCheckbox = new QCheckBox(this); + m_chapAuthCheckbox = new QCheckBox(this); + m_mschapAuthCheckbox = new QCheckBox(this); + m_mschap2AuthCheckbox = new QCheckBox(this); + m_eapAuthCheckbox = new QCheckBox(this); + + m_compModeListWidget = new QListWidget(this); + m_bsdCompModeCheckbox = new QCheckBox(this); + m_defaultCompModeCheckbox = new QCheckBox(this); + m_tcpCompModeCheckbox = new QCheckBox(this); + m_protocolCompModeCheckbox = new QCheckBox(this); + m_addressCompModeCheckbox = new QCheckBox(this); + + m_mruFrame = new QFrame(this); + m_mruEdit = new QLineEdit(this); + m_mtuEdit = new QLineEdit(this); + + m_authModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_authModeListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_authModeListWidget, m_papAuthCheckbox); + addListItem(m_authModeListWidget, m_chapAuthCheckbox); + addListItem(m_authModeListWidget, m_mschapAuthCheckbox); + addListItem(m_authModeListWidget, m_mschap2AuthCheckbox); + addListItem(m_authModeListWidget, m_eapAuthCheckbox); + + m_compModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_compModeListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_compModeListWidget, m_bsdCompModeCheckbox); + addListItem(m_compModeListWidget, m_defaultCompModeCheckbox); + addListItem(m_compModeListWidget, m_tcpCompModeCheckbox); + addListItem(m_compModeListWidget, m_protocolCompModeCheckbox); + addListItem(m_compModeListWidget, m_addressCompModeCheckbox); + + /**********布局**********/ + QVBoxLayout *defaultAdiaVLayout = new QVBoxLayout(m_defaultAdiaFrame); + defaultAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + defaultAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + + QFrame *secuFrame= new QFrame(m_defaultAdiaFrame); + QFormLayout *secuLayout = new QFormLayout(secuFrame); + secuLayout->setContentsMargins(NO_LAYOUT_MARGINS); + secuLayout->setVerticalSpacing(LAYOUT_SPACING_SMALL); + secuLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING); + secuLayout->addRow(m_mppeECheckbox, m_mppeECombox); + secuLayout->addRow(m_useStatefulECheckbox); + secuLayout->addRow(m_sendPppEchoPkgCheckbox); + m_mppeECheckbox->setMinimumWidth(MIN_LABEL_WIDTH); + + QHBoxLayout *mruHLayout = new QHBoxLayout(m_mruFrame); + mruHLayout->setContentsMargins(0, 16, 0, 0); + mruHLayout->setSpacing(HOR_LAYOUT_SPACING); + mruHLayout->addWidget(m_mruLabel); + mruHLayout->addWidget(m_mruEdit); + mruHLayout->addStretch(); + mruHLayout->addWidget(m_mtuLabel); + mruHLayout->addWidget(m_mtuEdit); + m_mruEdit->setFixedWidth(MIN_EDIT_WIDTH); + m_mtuEdit->setFixedWidth(MIN_EDIT_WIDTH); + + defaultAdiaVLayout->addWidget(secuFrame); + defaultAdiaVLayout->addSpacing(4); + defaultAdiaVLayout->addWidget(m_authModeLabel); + defaultAdiaVLayout->addWidget(m_authModeListWidget); + defaultAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING); + defaultAdiaVLayout->addWidget(m_compModeLabel); + defaultAdiaVLayout->addWidget(m_compModeListWidget); + defaultAdiaVLayout->addWidget(m_mruFrame); + m_authModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + + /**********控件显示**********/ + m_mppeECheckbox->setText(tr("MPPE encryption algorithm:")); //MPPE加密算法: + m_useStatefulECheckbox->setText(tr("Use Stateful encryption")); //使用有状态加密 + m_sendPppEchoPkgCheckbox->setText(tr("Send PPP echo packets")); //发送PPP回显包 + m_authModeLabel->setText(tr("Authentication Mode:")); //认证方式: + m_papAuthCheckbox->setText(tr("PAP authentication")); //PAP认证 + m_chapAuthCheckbox->setText(tr("CHAP authentication")); //CHAP认证 + m_mschapAuthCheckbox->setText(tr("MSCHAP authentication")); //MSCHAP认证 + m_mschap2AuthCheckbox->setText(tr("MSCHAP2 authentication")); //MSCHAP2认证 + m_eapAuthCheckbox->setText(tr("EAP authentication")); //EAP认证 + m_compModeLabel->setText(tr("Compression Mode:")); //压缩方式: + m_bsdCompModeCheckbox->setText(tr("Allow BSD data compression")); //允许BSD压缩 + m_defaultCompModeCheckbox->setText(tr("Allow Default data compression")); //允许Default压缩 + m_tcpCompModeCheckbox->setText(tr("Allow TCP header compression")); //允许TCP头压缩 + m_protocolCompModeCheckbox->setText(tr("Use protocol field compression negotiation")); //使用协议域压缩协商 + m_addressCompModeCheckbox->setText(tr("Use Address/Control compression")); //使用地址/控制压缩 + m_mruLabel->setText("MRU"); + m_mtuLabel->setText("MTU"); + m_mruEdit->setText("0"); + m_mtuEdit->setText("0"); + + m_mppeECombox->addItem(tr("All Available"), KYMPPE_DEFAULT); //任意 + m_mppeECombox->addItem(tr("128-bit"), KYMPPE_REQUIRE128); //128位 + m_mppeECombox->addItem(tr("40-bit"), KYMPPE_REQUIRE40); //40位 + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_mruEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_mtuEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_mruEdit->setMaxLength(MAX_MRU_LENGTH); + m_mtuEdit->setMaxLength(MAX_MRU_LENGTH); +} + +void VpnAdvancedPage::initOpenVpnAdiaFrame() +{ + /**********控件**********/ + //General + QLabel *generalLabel = new QLabel(m_openVpnAdiaFrame); + m_customGatewayPortCheckbox = new QCheckBox(this); + m_customRenegotiaInrCheckbox = new QCheckBox(this); + m_compressionCheckbox = new QCheckBox(this); + m_tcpConnCheckbox = new QCheckBox(this); + m_setVDevTypeCheckbox = new QCheckBox(this); + m_setVDevNameCheckbox = new QCheckBox(this); + m_customMtuCheckbox = new QCheckBox(this); + m_customUdpFragSizeCheckbox = new QCheckBox(this); + m_tcpMssCheckbox = new QCheckBox(this); + m_randomRemoteHostCheckbox = new QCheckBox(this); + m_ipv6TunLinkCheckbox = new QCheckBox(this); + m_specPingInrCheckbox = new QCheckBox(this); + m_specExitPingCheckbox = new QCheckBox(this); + m_acceptAuthedPaksCheckbox = new QCheckBox(this); + m_specMaxRouteCheckbox = new QCheckBox(this); + + m_gatewayPortEdit = new QLineEdit(this); + m_renogotiaInrEdit = new QLineEdit(this); + m_setVDevNameEdit = new QLineEdit(this); + m_customMtuEdit = new QLineEdit(this); + m_customUdpFragSizeEdit = new QLineEdit(this); + m_specPingInrEdit = new QLineEdit(this); + m_specExRePingEdit = new QLineEdit(this); + m_specMaxRouteEdit = new QLineEdit(this); + m_compressionCombox = new QComboBox(this); + m_setVDevTypeCombox = new QComboBox(this); + m_specExitRestarCombox = new QComboBox(this); + m_customRenoInrLabel = new FixLabel(this); + m_customMtuLabel = new FixLabel(this); + m_acceptAuthedPaksLabel = new FixLabel(this); + m_customUdpLabel = new FixLabel(this); + + //TLS settings + QLabel *tlsSettingLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *serverCertCheckLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *tlsModeLabel = new QLabel(m_openVpnAdiaFrame); + + FixLabel *usePreviousCertLabel = new FixLabel(m_openVpnAdiaFrame); + FixLabel *verifyPeerCertLabel = new FixLabel(m_openVpnAdiaFrame); + + m_subjectMatchLabel = new QLabel(this); + m_keyPathLabel = new QLabel(this); + m_keyDirectionLabel = new QLabel(this); + m_subjectMatchEdit = new QLineEdit(this); + m_keyPathEdit = new QLineEdit(this); + m_keyPathChooseBtn = new QPushButton(this); + m_usePreviousCertCheckbox = new QCheckBox(this); + m_verifyPeerCertCheckbox = new QCheckBox(this); + m_serverCertCheckCombox = new QComboBox(this); + m_usePreviousCertCombox = new QComboBox(this); + m_verifyPeerCertCombox = new QComboBox(this); + m_tlsModeCombox = new QComboBox(this); + m_keyDirectionCombox = new QComboBox(this); + + //Proxies + QLabel *proxiesLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *proxyTypeLabel = new QLabel(m_openVpnAdiaFrame); + m_proxyServerAddLabel = new QLabel(this); + m_proxyPortLabel = new QLabel(this); + m_proxyUsernameLabel = new QLabel(this); + m_proxyPwdLabel = new QLabel(this); + m_proxyTypeCombox = new QComboBox(this); + m_infiniteRetryCheckbox = new QCheckBox(this); + m_proxyServerAddEdit = new QLineEdit(this); + m_proxyPortEdit = new QLineEdit(this); + m_proxyUsernameEdit = new QLineEdit(this); + m_proxyPwdEdit = new KPasswordEdit(this); + m_proxyPwdEdit->setClearButtonEnabled(false); + + //Security + QLabel *securityLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *hmacLabel = new QLabel(m_openVpnAdiaFrame); + m_customKeySizeCheckbox = new QCheckBox(this); + m_customKeySizeEdit = new QLineEdit(this); + m_hmacAuthCombox = new QComboBox(this); + + + /**********布局**********/ + QVBoxLayout *openVpnAdiaVLayout = new QVBoxLayout(m_openVpnAdiaFrame); + openVpnAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + + //General + QFrame *generalFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *generalLayout = new QFormLayout(generalFrame); + + QWidget *customRenoInrWidget = new QWidget(this); + initCheckWidget(m_customRenegotiaInrCheckbox, m_customRenoInrLabel, customRenoInrWidget); + + QWidget *customMtuWidget = new QWidget(this); + initCheckWidget(m_customMtuCheckbox, m_customMtuLabel, customMtuWidget); + + QWidget *customUdpWidget = new QWidget(this); + initCheckWidget(m_customUdpFragSizeCheckbox, m_customUdpLabel, customUdpWidget); + + QWidget *acceptAuthWidget = new QWidget(this); + initCheckWidget(m_acceptAuthedPaksCheckbox, m_acceptAuthedPaksLabel, acceptAuthWidget); + + QWidget *exitRestarWidget = new QWidget(this); + QHBoxLayout *exitRestarLayout = new QHBoxLayout(exitRestarWidget); + exitRestarLayout->setContentsMargins(NO_LAYOUT_MARGINS); + exitRestarLayout->addWidget(m_specExitRestarCombox); + exitRestarLayout->addWidget(m_specExRePingEdit); + + generalLayout->setContentsMargins(NO_LAYOUT_MARGINS); + generalLayout->addRow(m_customGatewayPortCheckbox, m_gatewayPortEdit); + generalLayout->addRow(customRenoInrWidget, m_renogotiaInrEdit); + generalLayout->addRow(m_compressionCheckbox, m_compressionCombox); + generalLayout->addRow(m_tcpConnCheckbox); + generalLayout->addRow(m_setVDevTypeCheckbox, m_setVDevTypeCombox); + generalLayout->addRow(m_setVDevNameCheckbox, m_setVDevNameEdit); + generalLayout->addRow(customMtuWidget, m_customMtuEdit); + generalLayout->addRow(customUdpWidget, m_customUdpFragSizeEdit); + generalLayout->addRow(m_tcpMssCheckbox); + generalLayout->addRow(m_randomRemoteHostCheckbox); + generalLayout->addRow(m_ipv6TunLinkCheckbox); + generalLayout->addRow(m_specPingInrCheckbox, m_specPingInrEdit); + generalLayout->addRow(m_specExitPingCheckbox, exitRestarWidget); + generalLayout->addRow(acceptAuthWidget); + generalLayout->addRow(m_specMaxRouteCheckbox, m_specMaxRouteEdit); + + //TLS settings + QFrame *tlsSettingsFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *tlsLayout = new QFormLayout(tlsSettingsFrame); + + QWidget *usePreviousCertWidget = new QWidget(this); + initCheckWidget(m_usePreviousCertCheckbox, usePreviousCertLabel, usePreviousCertWidget); + + QWidget *verifyPeerCertWidget = new QWidget(this); + initCheckWidget(m_verifyPeerCertCheckbox, verifyPeerCertLabel, verifyPeerCertWidget); + + QWidget *keyfileWidget = new QWidget(this); + QGridLayout *keyfileLayout = new QGridLayout(keyfileWidget); + keyfileLayout->setContentsMargins(NO_LAYOUT_MARGINS); + keyfileLayout->addWidget(m_keyPathLabel, 0, 0); + keyfileLayout->addWidget(m_keyPathEdit, 0, 1); + keyfileLayout->addWidget(m_keyPathChooseBtn, 0, 2); + keyfileLayout->addWidget(m_keyDirectionLabel, 1, 0); + keyfileLayout->addWidget(m_keyDirectionCombox, 1, 1, 1, 2); + m_keyDirectionLabel->setMinimumWidth(MIN_LABEL_WIDTH); + + tlsLayout->setContentsMargins(NO_LAYOUT_MARGINS); + tlsLayout->addRow(serverCertCheckLabel, m_serverCertCheckCombox); + tlsLayout->addRow(m_subjectMatchLabel, m_subjectMatchEdit); + tlsLayout->addRow(usePreviousCertWidget, m_usePreviousCertCombox); + tlsLayout->addRow(verifyPeerCertWidget, m_verifyPeerCertCombox); + tlsLayout->addRow(tlsModeLabel, m_tlsModeCombox); + tlsLayout->addRow(keyfileWidget); + + //Proxies + QFrame *proxiesFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *proxiesLayout = new QFormLayout(proxiesFrame); + proxiesLayout->setContentsMargins(NO_LAYOUT_MARGINS); + proxiesLayout->addRow(proxyTypeLabel, m_proxyTypeCombox); + proxiesLayout->addRow(m_proxyServerAddLabel, m_proxyServerAddEdit); + proxiesLayout->addRow(m_proxyPortLabel, m_proxyPortEdit); + proxiesLayout->addRow(nullptr, m_infiniteRetryCheckbox); + proxiesLayout->addRow(m_proxyUsernameLabel, m_proxyUsernameEdit); + proxiesLayout->addRow(m_proxyPwdLabel, m_proxyPwdEdit); + m_proxyUsernameLabel->setMinimumWidth(MIN_LABEL_WIDTH); + + //Security + QFrame *securityFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *securityLayout = new QFormLayout(securityFrame); + securityLayout->setContentsMargins(NO_LAYOUT_MARGINS); + securityLayout->addRow(m_customKeySizeCheckbox, m_customKeySizeEdit); + securityLayout->addRow(hmacLabel, m_hmacAuthCombox); + + //all + openVpnAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + openVpnAdiaVLayout->addWidget(generalLabel); + openVpnAdiaVLayout->addWidget(generalFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(tlsSettingLabel); + openVpnAdiaVLayout->addWidget(tlsSettingsFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(proxiesLabel); + openVpnAdiaVLayout->addWidget(proxiesFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(securityLabel); + openVpnAdiaVLayout->addWidget(securityFrame); + + /**********控件显示**********/ + m_customGatewayPortCheckbox->setText(tr("Use custom gateway port")); //使用自定义网关端口 + m_compressionCheckbox->setText(tr("Use compression")); //使用压缩 + m_tcpConnCheckbox->setText(tr("Use a TCP connection")); //使用TCP连接 + m_setVDevTypeCheckbox->setText(tr("Set virtual device type")); //设置虚拟设备类型 + m_setVDevNameCheckbox->setText(tr("Set virtual device name")); //设置虚拟设备名称 + m_tcpMssCheckbox->setText(tr("Limit TCP Maximum Segment Size(MSS)")); //限制TCP最大段尺寸(MSS) + m_randomRemoteHostCheckbox->setText(tr("Randomize remote hosts")); //随机化远程主机 + m_ipv6TunLinkCheckbox->setText(tr("IPv6 tun link")); //IPv6 tun连接 + m_specPingInrCheckbox->setText(tr("Specify ping interval")); //指定ping周期 + m_specExitPingCheckbox->setText(tr("Specify exit or restart ping")); //指定退出或重启的Ping + m_specMaxRouteCheckbox->setText(tr("Specify max routes")); //指定路由上限 + m_infiniteRetryCheckbox->setText(tr("Infinite retry on error")); //出错时无限重试 + m_customKeySizeCheckbox->setText(tr("Use custom key size")); //使用自定义密钥大小 + m_keyPathChooseBtn->setText(tr("Choose")); //选择 + + m_customRenoInrLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customRenoInrLabel->setLabelText(tr("Use custom renegotiation interval")); //使用自定义重协商间隔 + m_customMtuLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customMtuLabel->setLabelText(tr("Use custom tunnel Maximum Transmission Umit(MTU)")); //使用自定义隧道最大单元传输(MTU) + m_customUdpLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customUdpLabel->setLabelText(tr("Use custom UDP fragment size")); //使用自定义UDP分片大小 + m_acceptAuthedPaksLabel->setFixedWidth(440);//文本显示宽度 + m_acceptAuthedPaksLabel->setLabelText(tr("Accept authenticated packets from any address (Float)")); //接受来自任何地址(Float)已通过身份验证的数据包 + + m_subjectMatchLabel->setText(tr("Subject Match")); //主题匹配 + m_keyPathLabel->setText(tr("Key File")); //密钥文件 + m_keyDirectionLabel->setText(tr("Key Direction")); //密钥方向 + + m_proxyServerAddLabel->setText(tr("Server Address")); //服务器地址 + m_proxyPortLabel->setText(tr("Port")); //端口 + m_proxyUsernameLabel->setText(tr("Proxy USername")); //代理用户名 + m_proxyPwdLabel->setText(tr("Proxy Password")); //代理密码 + + generalLabel->setText(tr("General")); //常规 + tlsSettingLabel->setText(tr("TLS settings")); + serverCertCheckLabel->setText(tr("Server Certificate Check")); //服务器证书检验 + usePreviousCertLabel->setFixedWidth(MAX_LABEL_WIDTH); + usePreviousCertLabel->setLabelText(tr("Use the previous authentication end (server) certificate")); //使用前面验证端(服务器)证书 + verifyPeerCertLabel->setFixedWidth(MAX_LABEL_WIDTH); + verifyPeerCertLabel->setLabelText(tr("Verify peer (server) certificate nsCertType specification")); //验证对等点(服务器)证书nsCertType指定 + tlsModeLabel->setText(tr("Mode")); + proxiesLabel->setText(tr("Proxies")); + proxyTypeLabel->setText(tr("Proxy Type")); + securityLabel->setText(tr("Security")); + hmacLabel->setText(tr("HMAC Authentication")); //HMAC认证 + hmacLabel->setFixedWidth(268); //调整控件对齐=MAX_LABEL_WIDTH+28 + + QFont font = generalLabel->font(); + font.setWeight(QFont::Weight::Medium); + generalLabel->setFont(font); + tlsSettingLabel->setFont(font); + proxiesLabel->setFont(font); + securityLabel->setFont(font); + + m_setVDevNameEdit->setPlaceholderText(tr("Input content")); //输入内容 + + m_compressionCombox->addItem(tr("No"), KYCOMP2_LZODISABLE); //否 + m_compressionCombox->addItem("LZO", KYCOMP2_LZO); + m_compressionCombox->addItem("LZ4", KYCOMP2_LZ4); + m_compressionCombox->addItem("LZ4 v2", KYCOMP2_LZ4V2); + m_compressionCombox->addItem(tr("Self-adaption"), KYCOMP2_LZOADAPTIVE); //自适应 + m_compressionCombox->addItem(tr("Automatic"), KYCOMP2_AUTO); //自动 + + m_setVDevTypeCombox->addItem("TUN", KYVIRDEVTYPE_TUN); + m_setVDevTypeCombox->addItem("TAP", KYVIRDEVTYPE_TAP); + + m_specExitRestarCombox->addItem(tr("Exit"), KYVPNPING_EXIT); //退出 + m_specExitRestarCombox->addItem(tr("Restart"), KYVPNPING_RESTART); //重启 + + m_serverCertCheckCombox->addItem(tr("Don't verify certificate identification"), KYCHECKSERVER_NONE); //不验证证书标识 + m_serverCertCheckCombox->addItem(tr("Verify the entire subject exactly"), KYCHECKSERVER_ENTIRETHEME); //确切地验证整个主题 + m_serverCertCheckCombox->addItem(tr("Verify name exactly"), KYCHECKSERVER_ENTIRENAME); //精确验证名称 + m_serverCertCheckCombox->addItem(tr("Verify name by prefix"), KYCHECKSERVER_PRENAME); //按前缀验证名称 + + m_usePreviousCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER); + m_usePreviousCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT); + + m_verifyPeerCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER); + m_verifyPeerCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT); + + m_tlsModeCombox->addItem(tr("None"), NONE); //无 + m_tlsModeCombox->addItem(tr("TLS-Certification"), TLS_CERT); //TLS-认证 + m_tlsModeCombox->addItem(tr("TLS-Encryption"), TLS_ENCRYPTION); //TLS-加密 + + m_keyDirectionCombox->addItem(tr("None"), KEY_DIRECTION_NONE); //无 + m_keyDirectionCombox->addItem("0", KEY_DIRECTION_ZERO); + m_keyDirectionCombox->addItem("1", KEY_DIRECTION_ONE); + + m_proxyTypeCombox->addItem(tr("Not Required"), NO); //不需要 + m_proxyTypeCombox->addItem("HTTP", HTTP); + m_proxyTypeCombox->addItem("SOCKS", SOCKS); + + m_hmacAuthCombox->addItem(tr("Default"), KYHMACAUTH_DEFAULT); //默认 + m_hmacAuthCombox->addItem(tr("None"), KYHMACAUTH_NONE); //无 + m_hmacAuthCombox->addItem("MD-4", KYHMACAUTH_MD4); + m_hmacAuthCombox->addItem("MD-5", KYHMACAUTH_MD5); + m_hmacAuthCombox->addItem("SHA-1", KYHMACAUTH_SHA1); + m_hmacAuthCombox->addItem("SHA-224", KYHMACAUTH_SHA224); + m_hmacAuthCombox->addItem("SHA-256", KYHMACAUTH_SHA256); + m_hmacAuthCombox->addItem("SHA-384", KYHMACAUTH_SHA384); + m_hmacAuthCombox->addItem("SHA-512", KYHMACAUTH_SHA512); + m_hmacAuthCombox->addItem("RIPEMD-160", KYHMACAUTH_RIPEMD160); + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_gatewayPortEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_renogotiaInrEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_customMtuEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_customUdpFragSizeEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specPingInrEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specExRePingEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specMaxRouteEdit->setValidator(new QRegExpValidator(rxNumber, this)); + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + m_proxyServerAddEdit->setValidator(new QRegExpValidator(rxIp, this)); + + //default + m_gatewayPortEdit->setText("1194"); + m_renogotiaInrEdit->setText("0"); + m_customMtuEdit->setText("1500"); + m_customUdpFragSizeEdit->setText("1500"); + m_specPingInrEdit->setText("30"); + m_specExRePingEdit->setText("30"); + m_specMaxRouteEdit->setText("30"); + if (m_serverCertCheckCombox->currentData().toInt() == (int)KYCHECKSERVER_NONE) { + m_subjectMatchEdit->setEnabled(false); + } else { + m_subjectMatchEdit->setEnabled(true); + } + onTlsModeComboxIndexChanged(); + onProxyTypeComboxIndexChanged(); +} + +void VpnAdvancedPage::initSSwanAdiaFrame() +{ + /**********控件**********/ + QLabel *optionsLabel = new QLabel(this); + QLabel *ikeLabel = new QLabel(this); + QLabel *espLabel = new QLabel(this); + m_optionsListWidget = new QListWidget(this); + m_requestInIPCheckbox = new QCheckBox(this); + m_udpEncapCheckbox = new QCheckBox(this); + m_ipCompCheckbox = new QCheckBox(this); + m_enablCustomCheckbox = new QCheckBox(this); + m_ikeEdit = new QLineEdit(this); + m_espEdit = new QLineEdit(this); + m_ikeEspFrame = new QFrame(m_sSwanAdiaFrame); + + /**********布局**********/ + QVBoxLayout *sSwanAdiaVLayout = new QVBoxLayout(m_sSwanAdiaFrame); + sSwanAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + sSwanAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + + QFormLayout *ikeEspFrameLayout = new QFormLayout(m_ikeEspFrame); + ikeEspFrameLayout->setContentsMargins(NO_LAYOUT_MARGINS); + ikeEspFrameLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING); + ikeEspFrameLayout->setVerticalSpacing(LAYOUT_ADD_SPACING); + ikeEspFrameLayout->addRow(ikeLabel, m_ikeEdit); + ikeEspFrameLayout->addRow(espLabel, m_espEdit); + + sSwanAdiaVLayout->addWidget(optionsLabel); + sSwanAdiaVLayout->addWidget(m_optionsListWidget); + sSwanAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING); + sSwanAdiaVLayout->addWidget(m_enablCustomCheckbox); + sSwanAdiaVLayout->addWidget(m_ikeEspFrame); + sSwanAdiaVLayout->addStretch(); + m_optionsListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL); + + /**********控件显示**********/ + optionsLabel->setText(tr("Options:")); //选项: + ikeLabel->setText("IKE"); + espLabel->setText("ESP"); + m_requestInIPCheckbox->setText(tr("Request an inner IP address")); //请求内部IP地址 + m_udpEncapCheckbox->setText(tr("Enforce UDP encapsulation")); //强制UDP封装 + m_ipCompCheckbox->setText(tr("Use IP compression")); //使用IP压缩 + m_enablCustomCheckbox->setText(tr("Enable custom password suggestions")); //启用自定义密码建议 + + m_optionsListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_optionsListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_optionsListWidget, m_requestInIPCheckbox); + addListItem(m_optionsListWidget, m_udpEncapCheckbox); + addListItem(m_optionsListWidget, m_ipCompCheckbox); + + //strong-Swan default + m_enablCustomCheckbox->setChecked(false); + m_ikeEspFrame->setEnabled(false); +} + +void VpnAdvancedPage::initDefalutCheckState() +{ + m_mppeECheckbox->setChecked(false); + m_mppeECombox->setEnabled(m_mppeECheckbox->isChecked()); + + //openVPN + m_customGatewayPortCheckbox->setChecked(true); + m_customRenegotiaInrCheckbox->setChecked(true); + m_compressionCheckbox->setChecked(true); + m_tcpConnCheckbox->setChecked(true); + m_setVDevTypeCheckbox->setChecked(true); + m_setVDevNameCheckbox->setChecked(true); + m_customMtuCheckbox->setChecked(true); + m_customUdpFragSizeCheckbox->setChecked(true); + m_tcpMssCheckbox->setChecked(true); + m_randomRemoteHostCheckbox->setChecked(true); + m_ipv6TunLinkCheckbox->setChecked(true); + m_specPingInrCheckbox->setChecked(true); + m_specExitPingCheckbox->setChecked(true); + m_acceptAuthedPaksCheckbox->setChecked(true); + m_specMaxRouteCheckbox->setChecked(true); + + m_gatewayPortEdit->setEnabled(m_customGatewayPortCheckbox->isChecked()); + m_renogotiaInrEdit->setEnabled(m_customRenegotiaInrCheckbox->isChecked()); + m_setVDevNameEdit->setEnabled(m_setVDevNameCheckbox->isChecked()); + m_customMtuEdit->setEnabled(m_customMtuCheckbox->isChecked()); + m_customUdpFragSizeEdit->setEnabled(m_customUdpFragSizeCheckbox->isChecked()); + m_specPingInrEdit->setEnabled(m_specPingInrCheckbox->isChecked()); + m_specExRePingEdit->setEnabled(m_specExitPingCheckbox->isChecked()); + m_specMaxRouteEdit->setEnabled(m_specMaxRouteCheckbox->isChecked()); + m_compressionCombox->setEnabled(m_compressionCheckbox->isChecked()); + m_setVDevTypeCombox->setEnabled(m_setVDevTypeCheckbox->isChecked()); + m_specExitRestarCombox->setEnabled(m_specExitPingCheckbox->isChecked()); + + m_usePreviousCertCombox->setEnabled(m_usePreviousCertCheckbox->isChecked()); + m_verifyPeerCertCombox->setEnabled(m_verifyPeerCertCheckbox->isChecked()); + + m_customKeySizeEdit->setEnabled(m_customKeySizeCheckbox->isChecked()); +} + +void VpnAdvancedPage::addListItem(QListWidget *listWidget, QWidget *widget) +{ + QListWidgetItem *listWidgetItem = new QListWidgetItem(listWidget); + QWidget *itemWidget = new QWidget(listWidget); + QHBoxLayout *hLayout = new QHBoxLayout(itemWidget); + hLayout->setContentsMargins(16, 0, 0, 0); + hLayout->addWidget(widget); + listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT)); + listWidgetItem->setFlags(Qt::NoItemFlags); + listWidget->addItem(listWidgetItem); + listWidget->setItemWidget(listWidgetItem, itemWidget); +} + +void VpnAdvancedPage::initCheckWidget(QCheckBox *checkBox, FixLabel *label, QWidget *widget) +{ + QHBoxLayout *hLayout = new QHBoxLayout(widget); + hLayout->setContentsMargins(NO_LAYOUT_MARGINS); + hLayout->setSpacing(4); + hLayout->addWidget(checkBox); + hLayout->addWidget(label); + hLayout->addStretch(); +} + +void VpnAdvancedPage::onProxyTypeComboxIndexChanged() +{ + switch (m_proxyTypeCombox->currentData().toInt()) { + case NO: + m_proxyServerAddEdit->clear(); + m_proxyPortEdit->clear(); + m_proxyUsernameEdit->clear(); + m_proxyPwdEdit->clear(); + m_infiniteRetryCheckbox->setChecked(false); + + m_proxyServerAddLabel->setEnabled(false); + m_proxyPortLabel->setEnabled(false); + m_proxyUsernameLabel->setEnabled(false); + m_proxyPwdLabel->setEnabled(false); + m_infiniteRetryCheckbox->setEnabled(false); + m_proxyServerAddEdit->setEnabled(false); + m_proxyPortEdit->setEnabled(false); + m_proxyUsernameEdit->setEnabled(false); + m_proxyPwdEdit->setEnabled(false); + break; + case HTTP: + m_proxyServerAddLabel->setEnabled(true); + m_proxyPortLabel->setEnabled(true); + m_proxyUsernameLabel->setEnabled(true); + m_proxyPwdLabel->setEnabled(true); + m_infiniteRetryCheckbox->setEnabled(true); + m_proxyServerAddEdit->setEnabled(true); + m_proxyPortEdit->setEnabled(true); + m_proxyUsernameEdit->setEnabled(true); + m_proxyPwdEdit->setEnabled(true); + break; + case SOCKS: + m_proxyServerAddLabel->setEnabled(true); + m_proxyPortLabel->setEnabled(true); + m_infiniteRetryCheckbox->setEnabled(true); + m_proxyServerAddEdit->setEnabled(true); + m_proxyPortEdit->setEnabled(true); + m_proxyUsernameLabel->setEnabled(false); + m_proxyPwdLabel->setEnabled(false); + m_proxyUsernameEdit->setEnabled(false); + m_proxyPwdEdit->setEnabled(false); + break; + default: + break; + } +} + +void VpnAdvancedPage::onTlsModeComboxIndexChanged() +{ + switch (m_tlsModeCombox->currentData().toInt()) { + case NONE: + m_keyPathLabel->setEnabled(false); + m_keyPathEdit->setEnabled(false); + m_keyPathChooseBtn->setEnabled(false); + m_keyDirectionLabel->setEnabled(false); + m_keyDirectionCombox->setEnabled(false); + break; + case TLS_CERT: + m_keyPathLabel->setEnabled(true); + m_keyPathEdit->setEnabled(true); + m_keyPathChooseBtn->setEnabled(true); + m_keyDirectionLabel->setEnabled(true); + m_keyDirectionCombox->setEnabled(true); + break; + case TLS_ENCRYPTION: + m_keyPathLabel->setEnabled(true); + m_keyPathEdit->setEnabled(true); + m_keyPathChooseBtn->setEnabled(true); + m_keyDirectionLabel->setEnabled(false); + m_keyDirectionCombox->setEnabled(false); + break; + default: + break; + } +} + +void VpnAdvancedPage::setEnableOfConfirmBtn() +{ + Q_EMIT setAdvancedPageState(checkConfirmBtnIsEnabled()); +} + +void VpnAdvancedPage::onKeyPathButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a private key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_keyPathEdit->blockSignals(true); + m_keyPathEdit->setText(fileName); + m_keyPathEdit->blockSignals(false); + } +} + +void VpnAdvancedPage::showL2tpAdiaPage() +{ + m_defaultAdiaFrame->setHidden(false); + m_mruFrame->setHidden(false); + m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(false); + m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(false); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + + m_openVpnAdiaFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showPptpAdiaPage() +{ + m_defaultAdiaFrame->setHidden(false); + m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(true); + m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(true); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL); + + m_mruFrame->setHidden(true); + m_openVpnAdiaFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showOpenVpnAdiaPage() +{ + m_openVpnAdiaFrame->setHidden(false); + + m_defaultAdiaFrame->setHidden(true); + m_mruFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showSSwanAdiaPage() +{ + m_sSwanAdiaFrame->setHidden(false); + + m_defaultAdiaFrame->setHidden(true); + m_mruFrame->setHidden(true); + m_openVpnAdiaFrame->setHidden(true); +} + +bool VpnAdvancedPage::checkConfirmBtnIsEnabled() +{ + //L2TP + if (!m_mruFrame->isHidden()) { + if (m_mruEdit->text().isEmpty() || m_mtuEdit->text().isEmpty()) { + qDebug() << LOG_FLAG << "MRU or MTU is empty"; + return false; + } + } + + //PPTP 无必填项 + + //OPEN VPN + if (!m_openVpnAdiaFrame->isHidden()) { + if (m_customGatewayPortCheckbox->isChecked() && m_gatewayPortEdit->text().isEmpty()) { + return false; + } + + if (m_customRenegotiaInrCheckbox->isChecked() && m_renogotiaInrEdit->text().isEmpty()) { + return false; + } + + if (m_setVDevNameCheckbox->isChecked() && m_setVDevNameEdit->text().isEmpty()) { + return false; + } + + if (m_customMtuCheckbox->isChecked() && m_customMtuEdit->text().isEmpty()) { + return false; + } + + if (m_customUdpFragSizeCheckbox->isChecked() && m_customUdpFragSizeEdit->text().isEmpty()) { + return false; + } + + if (m_specPingInrCheckbox->isChecked() && m_specPingInrEdit->text().isEmpty()) { + return false; + } + + if (m_specExitPingCheckbox->isChecked() && m_specExRePingEdit->text().isEmpty()) { + return false; + } + + if (m_specMaxRouteCheckbox->isChecked() && m_specMaxRouteEdit->text().isEmpty()) { + return false; + } + + if (m_serverCertCheckCombox->currentData().toInt() != (int)KYCHECKSERVER_NONE + && m_subjectMatchEdit->text().isEmpty()) { + return false; + } + + if (m_tlsModeCombox->currentData().toInt() == TLS_CERT || m_tlsModeCombox->currentData().toInt() == TLS_ENCRYPTION) { + if (m_keyPathEdit->text().isEmpty()) { + return false; + } + } + + if (m_proxyTypeCombox->currentData().toInt() == HTTP || m_proxyTypeCombox->currentData().toInt() == SOCKS) { + if (m_proxyServerAddEdit->text().isEmpty() || !getTextEditState(m_proxyServerAddEdit->text())) { + return false; + } + if (m_proxyPortEdit->text().isEmpty()) { + return false; + } + } + + if(m_customKeySizeCheckbox->isChecked() && m_customKeySizeEdit->text().isEmpty()) { + return false; + } + } + + //strong-swan + if (!m_sSwanAdiaFrame->isHidden()) { + if (m_enablCustomCheckbox->isChecked()) { + if (m_ikeEdit->text().isEmpty() || m_espEdit->text().isEmpty()) { + return false; + } + } + } + return true; +} + +bool VpnAdvancedPage::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.h b/src-vpn/frontend/vpndetails/vpnadvancedpage.h new file mode 100644 index 00000000..4c6be900 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.h @@ -0,0 +1,197 @@ +#ifndef VPNADVANCEDPAGE_H +#define VPNADVANCEDPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kylable.h" +#include "kwidget.h" +#include "kpasswordedit.h" +#include "vpnconfigpage.h" +#include "kyvpnconnectoperation.h" + +using namespace kdk; + +enum TlsMode { + NONE = 0, + TLS_CERT, + TLS_ENCRYPTION +}; + +enum ProxyType { + NO = 0, + HTTP, + SOCKS +}; + +class VpnAdvancedPage : public QFrame +{ + Q_OBJECT +public: + VpnAdvancedPage(QWidget *parent = nullptr); + ~VpnAdvancedPage() = default; + + //Adia: Advanced + void setL2tpOrPptpAdiaInfo(const KyVpnConfig &vpnInfo); + void setOpenVpnAdiaInfo(const KyVpnConfig &vpnInfo); + void setStrongSwanAdiaInfo(const KyVpnConfig &vpnInfo); + + bool checkIsChanged(const KyVpnConfig &vpnInfo, VpnType &vpnType); + bool checkL2tpIsChanged(const KyVpnConfig &vpnInfo); + bool checkPptpIsChanged(const KyVpnConfig &vpnInfo); + bool checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo); + bool checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo); + + void updateL2tpOrPptpAdiaInfo(KyVpnConfig &vpnInfo); + void updateOpenVpnAdiaInfo(KyVpnConfig &vpnInfo); + void updateStrongSwanAdiaInfo(KyVpnConfig &vpnInfo); + +protected: + void paintEvent(QPaintEvent *event); + +private: + bool m_isOpenVpn; + + QFrame *m_defaultAdiaFrame; + QFrame *m_mruFrame; + QFrame *m_openVpnAdiaFrame; + QFrame *m_sSwanAdiaFrame; + + //L2TP PPTP Encryption(E) + QCheckBox *m_mppeECheckbox = nullptr; + QCheckBox *m_useStatefulECheckbox = nullptr; + QCheckBox *m_sendPppEchoPkgCheckbox = nullptr; + + QLabel *m_authModeLabel; + QLabel *m_compModeLabel; + QLabel *m_mruLabel; + QLabel *m_mtuLabel; + QLineEdit *m_mruEdit; + QLineEdit *m_mtuEdit; + QComboBox *m_mppeECombox = nullptr; + //认证方式 + QListWidget *m_authModeListWidget = nullptr; + QCheckBox *m_papAuthCheckbox = nullptr; + QCheckBox *m_chapAuthCheckbox = nullptr; + QCheckBox *m_mschapAuthCheckbox = nullptr; + QCheckBox *m_mschap2AuthCheckbox = nullptr; + QCheckBox *m_eapAuthCheckbox = nullptr; + //压缩方式 + QListWidget *m_compModeListWidget = nullptr; + QCheckBox *m_bsdCompModeCheckbox = nullptr; + QCheckBox *m_defaultCompModeCheckbox = nullptr; + QCheckBox *m_tcpCompModeCheckbox = nullptr; + QCheckBox *m_protocolCompModeCheckbox = nullptr; + QCheckBox *m_addressCompModeCheckbox = nullptr; + + //Open VPN + //general + QCheckBox *m_customGatewayPortCheckbox = nullptr; + QCheckBox *m_customRenegotiaInrCheckbox = nullptr; + QCheckBox *m_compressionCheckbox = nullptr; + QCheckBox *m_tcpConnCheckbox = nullptr; + QCheckBox *m_setVDevTypeCheckbox = nullptr; + QCheckBox *m_setVDevNameCheckbox = nullptr; + QCheckBox *m_customMtuCheckbox = nullptr; + QCheckBox *m_customUdpFragSizeCheckbox = nullptr; + QCheckBox *m_tcpMssCheckbox = nullptr; + QCheckBox *m_randomRemoteHostCheckbox = nullptr; + QCheckBox *m_ipv6TunLinkCheckbox = nullptr; + QCheckBox *m_specPingInrCheckbox = nullptr; + QCheckBox *m_specExitPingCheckbox = nullptr; + QCheckBox *m_acceptAuthedPaksCheckbox = nullptr; + QCheckBox *m_specMaxRouteCheckbox = nullptr; + + QLineEdit *m_gatewayPortEdit; + QLineEdit *m_renogotiaInrEdit; + QLineEdit *m_setVDevNameEdit; + QLineEdit *m_customMtuEdit; + QLineEdit *m_customUdpFragSizeEdit; + QLineEdit *m_specPingInrEdit; + QLineEdit *m_specExRePingEdit; + QLineEdit *m_specMaxRouteEdit; + QComboBox *m_compressionCombox = nullptr; + QComboBox *m_setVDevTypeCombox = nullptr; + QComboBox *m_specExitRestarCombox = nullptr; + FixLabel *m_customRenoInrLabel; + FixLabel *m_customMtuLabel; + FixLabel *m_customUdpLabel; + FixLabel *m_acceptAuthedPaksLabel; + //TLS settings + QLabel *m_subjectMatchLabel; + QLabel *m_keyPathLabel; + QLabel *m_keyDirectionLabel; + QLineEdit *m_subjectMatchEdit; + QLineEdit *m_keyPathEdit; + QPushButton *m_keyPathChooseBtn; + QCheckBox *m_usePreviousCertCheckbox = nullptr; + QCheckBox *m_verifyPeerCertCheckbox = nullptr; + QComboBox *m_serverCertCheckCombox = nullptr; + QComboBox *m_usePreviousCertCombox = nullptr; + QComboBox *m_verifyPeerCertCombox = nullptr; + QComboBox *m_tlsModeCombox = nullptr; + QComboBox *m_keyDirectionCombox = nullptr; + //proxies + QLabel *m_proxyServerAddLabel; + QLabel *m_proxyPortLabel; + QLabel *m_proxyUsernameLabel; + QLabel *m_proxyPwdLabel; + QComboBox *m_proxyTypeCombox = nullptr; + QCheckBox *m_infiniteRetryCheckbox = nullptr; + QLineEdit *m_proxyServerAddEdit; + QLineEdit *m_proxyPortEdit; + QLineEdit *m_proxyUsernameEdit; + KPasswordEdit *m_proxyPwdEdit; + //security + QCheckBox *m_customKeySizeCheckbox = nullptr; + QLineEdit *m_customKeySizeEdit; + QComboBox *m_hmacAuthCombox = nullptr; + + //strongswan + QListWidget *m_optionsListWidget = nullptr; + QCheckBox *m_requestInIPCheckbox = nullptr; + QCheckBox *m_udpEncapCheckbox = nullptr; + QCheckBox *m_ipCompCheckbox = nullptr; + QCheckBox *m_enablCustomCheckbox = nullptr; + QFrame *m_ikeEspFrame; + QLineEdit *m_ikeEdit; + QLineEdit *m_espEdit; + + void initUi(); + void initConnect(); + void initDefaultAdiaFrame(); //L2TP PPTP + void initOpenVpnAdiaFrame(); //Open VPN + void initSSwanAdiaFrame(); //strong-swan + void initDefalutCheckState(); + void addListItem(QListWidget *listWidget, QWidget *widget); + void initCheckWidget(QCheckBox *checkBox, FixLabel *label, QWidget *widget); + + void showL2tpAdiaPage(); + void showPptpAdiaPage(); + void showOpenVpnAdiaPage(); + void showSSwanAdiaPage(); + bool checkConfirmBtnIsEnabled(); + bool getTextEditState(QString text); + +private Q_SLOTS: + void onProxyTypeComboxIndexChanged(); + void onTlsModeComboxIndexChanged(); + void setEnableOfConfirmBtn(); + void onKeyPathButtonClicked(); + +public Q_SLOTS: + void setVpnAdvancedPage(const VpnType &type); + +Q_SIGNALS: + void setAdvancedPageState(bool); +}; + +#endif // VPNADVANCEDPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnconfigpage.cpp b/src-vpn/frontend/vpndetails/vpnconfigpage.cpp new file mode 100644 index 00000000..eeb4e4da --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnconfigpage.cpp @@ -0,0 +1,1055 @@ +#include "vpnconfigpage.h" +#include +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define LEFT_LABEL_WIDTH 100 +#define PIN_MAX_LENGTH 10 +#define PWD_OPTION_THISUSER_INDEX 0 +#define PWD_OPTION_ALLUSERS_INDEX 1 +#define PWD_OPTION_ASKEVERYTIME_INDEX 2 +#define PWD_OPTION_NOTREQUIRED_INDEX 3 +#define LOG_FLAG "[VPN ConfigPage]" + +VpnConfigPage::VpnConfigPage(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); + onVpnTypeComboxIndexChanged(); +} + +VpnType VpnConfigPage::getVpnType() +{ + return VpnType(m_vpnTypeComboBox->currentData().toInt()); +} + +void VpnConfigPage::setVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + m_vpnNameEdit->setText(vpnInfo.m_vpnName); + m_serverAddressEdit->setText(vpnInfo.m_gateway); + m_vpnTypeComboBox->setCurrentIndex(vpnInfo.m_vpnType); + onVpnTypeComboxIndexChanged(); + + switch (vpnInfo.m_vpnType) { + case KYVPNTYPE_L2TP: + setL2tpConfigInfo(vpnInfo); + break; + case KYVPNTYPE_PPTP: + setPptpConfigInfo(vpnInfo); + break; + case KYVPNTYPE_OPENVPN: + setOpenVpnConfigInfo(vpnInfo); + break; + case KYVPNTYPE_STRONGSWAN: + setSSwanVpnConfigInfo(vpnInfo); + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN Type" << vpnInfo.m_vpnType; + break; + } +} + +bool VpnConfigPage::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentVpnType = m_vpnTypeComboBox->currentData().toInt(); + + if (vpnInfo.m_vpnType != currentVpnType + || vpnInfo.m_vpnName != m_vpnNameEdit->text() + || vpnInfo.m_gateway != m_serverAddressEdit->text()) { + + isChanged = true; + } + + switch (currentVpnType) { + case L2TP: + if (checkL2tpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case PPTP: + if (checkPptpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case OPEN_VPN: + if (checkOpenVpnIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case STRONG_SWAN: + if (checkStrongSwanIsChanged(vpnInfo)) { + isChanged = true; + } + default: + break; + } + + return isChanged; +} + +void VpnConfigPage::updateVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_vpnType = (KyVpnType)m_vpnTypeComboBox->currentData().toInt(); + vpnInfo.m_vpnName = m_vpnNameEdit->text(); + vpnInfo.m_gateway = m_serverAddressEdit->text(); + switch (m_vpnTypeComboBox->currentData().toInt()) { + case L2TP: + updateL2tpConfigInfo(vpnInfo); + break; + case OPEN_VPN: + updateOpenVpnConfigInfo(vpnInfo); + break; + case PPTP: + updatePptpConfigInfo(vpnInfo); + break; + case STRONG_SWAN: + updateSSwanVpnConfigInfo(vpnInfo); + break; + default: + break; + } +} + +void VpnConfigPage::initUI() +{ + /**********控件**********/ + //公有 + m_vpnTypeLabel = new QLabel(this); + m_vpnNameLabel = new QLabel(this); + m_serverAddressLabel = new FixLabel(this); + m_vpnTypeComboBox = new QComboBox(this); + m_vpnNameEdit = new QLineEdit(this); + m_serverAddressEdit = new QLineEdit(this); + + //认证方式 Authentication Mode + m_authModeLabel = new FixLabel(this); + m_authModeComboBox = new QComboBox(this); + + //证书 私钥 + m_caCertLabel = new FixLabel(this); + m_userCertLabel = new FixLabel(this); + m_privateKeyLabel = new FixLabel(this); + m_privateKeyPwdLabel = new FixLabel(this); + m_pwdOptionLabel = new FixLabel(this); + + m_caCertPathEdit = new QLineEdit(this); + m_userCertPathEdit = new QLineEdit(this); + m_privateKeyEdit = new QLineEdit(this); + m_privateKeyPwdEdit = new KPasswordEdit(this); + m_pwdOptionCombox = new QComboBox(this); + + m_caCertButton = new QPushButton(this); + m_userCertButton = new QPushButton(this); + m_privateKeyButton = new QPushButton(this); + + //静态密钥 + m_staticKeyLabel = new QLabel(this); + m_keyDirectionLabel = new FixLabel(this); + m_noticesLabel = new QLabel(this); + m_localIpLabel = new QLabel(this); + m_remoteIpLabel = new QLabel(this); + + m_staticKeyPathEdit = new QLineEdit(this); + m_staticKeyButton = new QPushButton(this); + m_keyDirectionCombox = new QComboBox(this); + m_localIpEdit = new QLineEdit(this); + m_remoteIpEdit = new QLineEdit(this); + + //智能卡 PIN码 + m_pinLabel = new QLabel(this); + m_pinEdit = new QLineEdit(this); + + //密码 + m_usernameLabel = new FixLabel(this); + m_userPwdLabel = new QLabel(this); + m_userPwdOptionLabel = new FixLabel(this); + m_usernameEdit = new QLineEdit(this); + m_userPwdEdit = new KPasswordEdit(this); + m_userPwdOptionCombox = new QComboBox(this); + + //L2TP PPTP公有 + m_ntDomainLabel = new QLabel(this); + m_ntDomainEdit = new QLineEdit(this); + + + /**********布局**********/ + m_vpnCommunalFrame = new QFrame(this); + m_authModeFrame = new QFrame(this); + m_caCertFrame = new QFrame(this); + m_userCertFrame = new QFrame(this); + m_staticKeysFrame = new QFrame(this); + m_pinFrame = new QFrame(this); + m_PrivateKeysFrame = new QFrame(this); + m_usersFrame = new QFrame(this); + m_userPwdOpFrame = new QFrame(this); + m_ntFrame = new QFrame(this); + + //布局 + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(VLAYOUT_SPACING); + mainLayout->addWidget(m_vpnCommunalFrame); + mainLayout->addWidget(m_authModeFrame); + mainLayout->addWidget(m_caCertFrame); + mainLayout->addWidget(m_userCertFrame); + mainLayout->addWidget(m_staticKeysFrame); + mainLayout->addWidget(m_pinFrame); + mainLayout->addWidget(m_PrivateKeysFrame); + mainLayout->addWidget(m_usersFrame); + mainLayout->addWidget(m_userPwdOpFrame); + mainLayout->addWidget(m_ntFrame); + mainLayout->addSpacing(3); + mainLayout->addStretch(); + + QGridLayout *vpnCommLayout = new QGridLayout(m_vpnCommunalFrame); + vpnCommLayout->setContentsMargins(NO_LAYOUT_MARGINS); + vpnCommLayout->setHorizontalSpacing(HLAYOUT_SPACING); + vpnCommLayout->setVerticalSpacing(VLAYOUT_SPACING); + vpnCommLayout->addWidget(m_vpnTypeLabel, 0, 0); + vpnCommLayout->addWidget(m_vpnNameLabel, 1, 0); + vpnCommLayout->addWidget(m_serverAddressLabel, 2, 0); + vpnCommLayout->addWidget(m_vpnTypeComboBox, 0, 1); + vpnCommLayout->addWidget(m_vpnNameEdit, 1, 1); + vpnCommLayout->addWidget(m_serverAddressEdit, 2, 1); + m_vpnTypeLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_vpnNameLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_serverAddressLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *authMdLayout = new QHBoxLayout(m_authModeFrame); + authMdLayout->setContentsMargins(NO_LAYOUT_MARGINS); + authMdLayout->setSpacing(HLAYOUT_SPACING); + authMdLayout->addWidget(m_authModeLabel); + authMdLayout->addWidget(m_authModeComboBox); + m_authModeLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *caCertLayout = new QHBoxLayout(m_caCertFrame); + caCertLayout->setContentsMargins(NO_LAYOUT_MARGINS); + caCertLayout->setSpacing(HLAYOUT_SPACING); + caCertLayout->addWidget(m_caCertLabel); + caCertLayout->addWidget(m_caCertPathEdit); + caCertLayout->addWidget(m_caCertButton); + m_caCertLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *userLayout = new QHBoxLayout(m_userCertFrame); + userLayout->setContentsMargins(NO_LAYOUT_MARGINS); + userLayout->setSpacing(HLAYOUT_SPACING); + userLayout->addWidget(m_userCertLabel); + userLayout->addWidget(m_userCertPathEdit); + userLayout->addWidget(m_userCertButton); + m_userCertLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *staticKeyLayout = new QGridLayout(m_staticKeysFrame); + staticKeyLayout->setContentsMargins(NO_LAYOUT_MARGINS); + staticKeyLayout->setHorizontalSpacing(HLAYOUT_SPACING); + staticKeyLayout->setVerticalSpacing(VLAYOUT_SPACING); + staticKeyLayout->addWidget(m_staticKeyLabel, 0, 0); + staticKeyLayout->addWidget(m_staticKeyPathEdit, 0, 1); + staticKeyLayout->addWidget(m_staticKeyButton, 0, 2); + staticKeyLayout->addWidget(m_keyDirectionLabel, 1, 0); + staticKeyLayout->addWidget(m_keyDirectionCombox, 1, 1, 1, 2); + staticKeyLayout->addWidget(m_noticesLabel, 2, 0, 2, 3); + staticKeyLayout->addWidget(m_localIpLabel, 4, 0); + staticKeyLayout->addWidget(m_localIpEdit, 4, 1, 1, 2); + staticKeyLayout->addWidget(m_remoteIpLabel, 5, 0); + staticKeyLayout->addWidget(m_remoteIpEdit, 5, 1, 1, 2); + m_staticKeyLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_keyDirectionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_localIpLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_remoteIpLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *pinLayout = new QHBoxLayout(m_pinFrame); + pinLayout->setContentsMargins(NO_LAYOUT_MARGINS); + pinLayout->setSpacing(HLAYOUT_SPACING); + pinLayout->addWidget(m_pinLabel); + pinLayout->addWidget(m_pinEdit); + m_pinLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *privateKeysLayout = new QGridLayout(m_PrivateKeysFrame); + privateKeysLayout->setContentsMargins(NO_LAYOUT_MARGINS); + privateKeysLayout->setHorizontalSpacing(HLAYOUT_SPACING); + privateKeysLayout->setVerticalSpacing(VLAYOUT_SPACING); + privateKeysLayout->addWidget(m_privateKeyLabel, 0, 0); + privateKeysLayout->addWidget(m_privateKeyPwdLabel, 1, 0); + privateKeysLayout->addWidget(m_pwdOptionLabel, 2, 0); + privateKeysLayout->addWidget(m_privateKeyEdit, 0, 1); + privateKeysLayout->addWidget(m_privateKeyButton, 0, 2); + privateKeysLayout->addWidget(m_privateKeyPwdEdit, 1, 1, 1, 2); + privateKeysLayout->addWidget(m_pwdOptionCombox, 2, 1, 1, 2); + m_privateKeyLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_privateKeyPwdLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_pwdOptionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *usersLayout = new QGridLayout(m_usersFrame); + usersLayout->setContentsMargins(NO_LAYOUT_MARGINS); + usersLayout->setHorizontalSpacing(HLAYOUT_SPACING); + usersLayout->setVerticalSpacing(VLAYOUT_SPACING); + usersLayout->addWidget(m_usernameLabel, 0, 0); + usersLayout->addWidget(m_usernameEdit, 0, 1); + usersLayout->addWidget(m_userPwdLabel, 1, 0); + usersLayout->addWidget(m_userPwdEdit, 1, 1); + m_usernameLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_userPwdLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *userPwdOLayout = new QHBoxLayout(m_userPwdOpFrame); + userPwdOLayout->setContentsMargins(NO_LAYOUT_MARGINS); + userPwdOLayout->setSpacing(HLAYOUT_SPACING); + userPwdOLayout->addWidget(m_userPwdOptionLabel); + userPwdOLayout->addWidget(m_userPwdOptionCombox); + m_userPwdOptionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *ntLayout = new QHBoxLayout(m_ntFrame); + ntLayout->setContentsMargins(NO_LAYOUT_MARGINS); + ntLayout->setSpacing(HLAYOUT_SPACING); + ntLayout->addWidget(m_ntDomainLabel); + ntLayout->addWidget(m_ntDomainEdit); + m_ntDomainLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + /**********控件显示**********/ + m_vpnTypeLabel->setText(tr("Type")); //类型 + m_vpnNameLabel->setText(tr("Name")); //名称 + m_staticKeyLabel->setText(tr("Static Key")); //静态密钥 + m_localIpLabel->setText(tr("Local IP")); //本地IP地址 + m_remoteIpLabel->setText(tr("Remote IP")); //远程IP地址 + m_pinLabel->setText(tr("PIN Code")); //PIN码 + m_userPwdLabel->setText(tr("Password")); //密码 + m_ntDomainLabel->setText(tr("NT Domain")); //NT域 + + m_serverAddressLabel->setLabelText(tr("Server Address")); //服务器地址 + m_authModeLabel->setLabelText(tr("Authentication Mode")); //认证方式 + m_caCertLabel->setLabelText(tr("CA Certificate")); //CA证书 + m_userCertLabel->setLabelText(tr("User Certificate")); //用户证书 + m_keyDirectionLabel->setLabelText(tr("Key Direction")); //密钥方向 + m_privateKeyLabel->setLabelText(tr("Private Key")); //私钥 + m_privateKeyPwdLabel->setLabelText(tr("Private Key Password")); //私有密钥密码 + m_pwdOptionLabel->setLabelText(tr("Password Options")); //密码选项 + m_usernameLabel->setLabelText(tr("Username")); //用户名 + m_userPwdOptionLabel->setLabelText(tr("Password Options")); //密码选项 + + m_noticesLabel->setWordWrap(true); + m_noticesLabel->setText(tr("Notice:\nIf key direction is used, it must be opposite to the VPN side used. " + "If '1' is used, the connection must use '0'. " + "If you are not sure which value to use, please contact your system administrator.")); + QPalette pal; + pal.setColor(QPalette::WindowText, qApp->palette().color(QPalette::Mid)); + m_noticesLabel->setPalette(pal); + + m_caCertButton->setText(tr("Choose")); //选择 + m_userCertButton->setText(tr("Choose")); + m_staticKeyButton->setText(tr("Choose")); + m_privateKeyButton->setText(tr("Choose")); + + m_vpnTypeComboBox->addItem("L2TP", L2TP); + m_vpnTypeComboBox->addItem("open VPN", OPEN_VPN); + m_vpnTypeComboBox->addItem("PPTP", PPTP); + m_vpnTypeComboBox->addItem("strong-swan", STRONG_SWAN); + + m_keyDirectionCombox->addItem(tr("None"), KEY_DIRECTION_NONE); + m_keyDirectionCombox->addItem("0", KEY_DIRECTION_ZERO); + m_keyDirectionCombox->addItem("1", KEY_DIRECTION_ONE); + + m_pwdOptionCombox->addItem(tr("Save password only for this user"), KYPASSWD_FORTHISUSER); //仅对当前用户保存密码 + m_pwdOptionCombox->addItem(tr("Save password for all users"), KYPASSWD_FORALLUSER); //为所有用户保存密码 + m_pwdOptionCombox->addItem(tr("Ask password every time"), KYPASSWD_ASKEVERYTIME); //每次都询问 + m_pwdOptionCombox->addItem(tr("Don't require a password"), KYPASSWD_ISNOTREQUIRED);//不需要密码 + m_pwdOptionCombox->setCurrentIndex(PWD_OPTION_ASKEVERYTIME_INDEX); + + m_userPwdOptionCombox->addItem(tr("Save password only for this user"), KYPASSWD_FORTHISUSER); + m_userPwdOptionCombox->addItem(tr("Save password for all users"), KYPASSWD_FORALLUSER); + m_userPwdOptionCombox->addItem(tr("Ask password every time"), KYPASSWD_ASKEVERYTIME); + m_userPwdOptionCombox->addItem(tr("Don't require a password"), KYPASSWD_ISNOTREQUIRED); + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_ASKEVERYTIME_INDEX); + + m_vpnNameEdit->setPlaceholderText(tr("Required")); //必填 + m_serverAddressEdit->setPlaceholderText(tr("Required")); + m_privateKeyPwdEdit->setClearButtonEnabled(false); + m_userPwdEdit->setClearButtonEnabled(false); + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_pinEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_pinEdit->setMaxLength(PIN_MAX_LENGTH); + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_serverAddressEdit->setValidator(ipExpVal); + m_localIpEdit->setValidator(ipExpVal); + m_remoteIpEdit->setValidator(ipExpVal); +} + +void VpnConfigPage::initConnect() +{ + connect(m_vpnTypeComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnConfigPage::onVpnTypeComboxIndexChanged); + connect(m_authModeComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnConfigPage::onAuthModeComboxIndexChanged); + + connect(m_vpnNameEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_serverAddressEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_caCertPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_userCertPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_privateKeyEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_staticKeyPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_localIpEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_remoteIpEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_pinEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_usernameEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_ntDomainEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + + connect(m_vpnTypeComboBox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_authModeComboBox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_pwdOptionCombox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_userPwdOptionCombox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + + connect(m_caCertButton, &QPushButton::clicked, this, &VpnConfigPage::onCaCertButtonClicked); + connect(m_userCertButton, &QPushButton::clicked, this, &VpnConfigPage::onUserCertButtonClicked); + connect(m_staticKeyButton, &QPushButton::clicked, this, &VpnConfigPage::onStaticKeyButtonClicked); + connect(m_privateKeyButton, &QPushButton::clicked, this, &VpnConfigPage::onPrivateKeyButtonClicked); +} + +void VpnConfigPage::showL2tpPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + m_ntFrame->setHidden(false); + + m_PrivateKeysFrame->setHidden(true); + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); +} + +void VpnConfigPage::showPptpPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + m_ntFrame->setHidden(false); + + m_authModeFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnTls() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_userCertFrame->setHidden(false); + + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnPwdTls() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_userCertFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnStaticKey() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_staticKeysFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanCertPrivteKey() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_userCertFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanCertSsh() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_userCertFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanSmartCard() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_pinFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanEap() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_usersFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +bool VpnConfigPage::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnConfigPage::checkConfirmBtnIsEnabled() +{ + if (m_vpnNameEdit->text().isEmpty()) { + qDebug() << LOG_FLAG << "VPN name empty or invalid"; + return false; + } + + if (m_serverAddressEdit->text().isEmpty() || !getTextEditState(m_serverAddressEdit->text())) { + qDebug() << LOG_FLAG << "VPN server address empty or invalid"; + return false; + } + + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + switch (currentAuthMethod) { + case KYAUTH_PASSWD: + case KYAUTH_EAP: + if (m_usernameEdit->text().isEmpty() && !m_userPwdEdit->text().isEmpty()) { + return false; + } + if (m_vpnTypeComboBox->currentData().toInt() == OPEN_VPN && m_caCertPathEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_CERTIFICATE: + if (m_caCertPathEdit->text().isEmpty() || m_userCertPathEdit->text().isEmpty() + || m_privateKeyEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_CERTIFICATEANDPASSWD: + if (m_caCertPathEdit->text().isEmpty() || m_userCertPathEdit->text().isEmpty() + || m_privateKeyEdit->text().isEmpty()) { + return false; + } + if (m_usernameEdit->text().isEmpty() && !m_userPwdEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_STATICPASSWD: + if (m_staticKeyPathEdit->text().isEmpty()) { + return false; + } + break; + + default: + break; + } + + return true; +} + +void VpnConfigPage::setPwdAuthInfo(const QString &username, const QString &userPwd, const KyPasswdPolicy &userPwdPolicy) +{ + m_usernameEdit->setText(username); + m_userPwdEdit->setText(userPwd); + if (userPwdPolicy == KYPASSWD_ISNOTREQUIRED) { + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_NOTREQUIRED_INDEX); + } else { + m_userPwdOptionCombox->setCurrentIndex(userPwdPolicy); + } +} + +void VpnConfigPage::setCaCertAuthInfo(const QString &caCertificate) +{ + m_caCertPathEdit->setText(caCertificate); +} + +void VpnConfigPage::setKeyAuthInfo(const QString &userCert, const QString &privateKey, + const QString &privateKeyPwd, const KyPasswdPolicy &privatePwdPolicy) +{ + m_userCertPathEdit->setText(userCert); + m_privateKeyEdit->setText(privateKey); + m_privateKeyPwdEdit->setText(privateKeyPwd); + if (privatePwdPolicy == KYPASSWD_ISNOTREQUIRED) { + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_NOTREQUIRED_INDEX); + } else { + m_userPwdOptionCombox->setCurrentIndex(privatePwdPolicy); + } +} + +void VpnConfigPage::setStaticKeyAuthInfo(const QString &staticKey, const QString &vpnKeyDirection, + const QString &localIp, const QString &remoteIp) +{ + m_staticKeyPathEdit->setText(staticKey); + m_localIpEdit->setText(localIp); + m_remoteIpEdit->setText(remoteIp); + if (vpnKeyDirection == KEY_DIRECTION_ZERO) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ZERO_INDEX); + } else if (vpnKeyDirection == KEY_DIRECTION_ONE) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ONE_INDEX); + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } +} + +void VpnConfigPage::setAgentAuthInfo(const QString &userCert) +{ + m_userCertPathEdit->setText(userCert); +} + +void VpnConfigPage::setSmartCardAuthInfo(const QString &pin) +{ + m_pinEdit->setText(pin); +} + +void VpnConfigPage::setEapAuthInfo(const QString &username, const QString &userPwd) +{ + m_usernameEdit->setText(username); + m_userPwdEdit->setText(userPwd); +} + +void VpnConfigPage::setNtDomain(const QString &ntDomain) +{ + m_ntDomainEdit->setText(ntDomain); +} + +void VpnConfigPage::setL2tpConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_PASSWD) { + m_authModeComboBox->setCurrentIndex(KYAUTH_PASSWD); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + setNtDomain(vpnInfo.m_ntDomain); + } +} + +void VpnConfigPage::setPptpConfigInfo(const KyVpnConfig &vpnInfo) +{ + m_authModeComboBox->clear(); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + setNtDomain(vpnInfo.m_ntDomain); +} + +void VpnConfigPage::setOpenVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_PASSWD) { + m_authModeComboBox->setCurrentIndex(PASSWD_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_CERTIFICATE) { + m_authModeComboBox->setCurrentIndex(CERTIFICATE_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_STATICPASSWD) { + m_authModeComboBox->setCurrentIndex(STATICPASSWD_INDEX); + setStaticKeyAuthInfo(vpnInfo.m_staticKey, vpnInfo.m_vpnKeyDir, + vpnInfo.m_localAddress, vpnInfo.m_remoteAddress); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_CERTIFICATEANDPASSWD) { + m_authModeComboBox->setCurrentIndex(CERTIFICATEANDPASSWD_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + } +} + +void VpnConfigPage::setSSwanVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_KEY) { + m_authModeComboBox->setCurrentIndex(KEY_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_AGENT) { + m_authModeComboBox->setCurrentIndex(AGENT_INDEX); + setAgentAuthInfo(vpnInfo.m_userCertificate); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_SMARTCARD) { + m_authModeComboBox->setCurrentIndex(SMARTCARD_INDEX); + setSmartCardAuthInfo(vpnInfo.m_pinId); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_EAP) { + m_authModeComboBox->setCurrentIndex(EAP_INDEX); + setEapAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd); + } +} + +void VpnConfigPage::updateL2tpConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + vpnInfo.m_ntDomain = m_ntDomainEdit->text(); + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); +} + +void VpnConfigPage::updatePptpConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_ntDomain = m_ntDomainEdit->text(); + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); +} + +void VpnConfigPage::updateOpenVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod == KYAUTH_CERTIFICATE || vpnInfo.m_authMethod == KYAUTH_CERTIFICATEANDPASSWD) { + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + vpnInfo.m_userKey = m_privateKeyEdit->text(); + vpnInfo.m_privatePasswd = m_privateKeyPwdEdit->text(); + vpnInfo.m_privatePasswdPolicy = (KyPasswdPolicy)m_pwdOptionCombox->currentData().toInt(); + } + + if (vpnInfo.m_authMethod == KYAUTH_CERTIFICATEANDPASSWD || vpnInfo.m_authMethod == KYAUTH_PASSWD) { + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + } + + if (vpnInfo.m_authMethod == KYAUTH_STATICPASSWD) { + vpnInfo.m_staticKey = m_staticKeyPathEdit->text(); + vpnInfo.m_vpnKeyDir = m_keyDirectionCombox->currentData().toString(); + vpnInfo.m_localAddress = m_localIpEdit->text(); + vpnInfo.m_remoteAddress = m_remoteIpEdit->text(); + } +} + +void VpnConfigPage::updateSSwanVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod == KYAUTH_KEY) { + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + vpnInfo.m_userKey = m_privateKeyEdit->text(); + vpnInfo.m_privatePasswd = m_privateKeyPwdEdit->text(); + vpnInfo.m_privatePasswdPolicy = (KyPasswdPolicy)m_pwdOptionCombox->currentData().toInt(); + + } else if (vpnInfo.m_authMethod == KYAUTH_AGENT) { + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + + } else if (vpnInfo.m_authMethod == KYAUTH_SMARTCARD) { + vpnInfo.m_pinId = m_pinEdit->text(); + + } else if (vpnInfo.m_authMethod == KYAUTH_EAP) { + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + } +} + +void VpnConfigPage::onVpnTypeComboxIndexChanged() +{ + switch (m_vpnTypeComboBox->currentData().toInt()) { + case L2TP: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Password"), KYAUTH_PASSWD); + onAuthModeComboxIndexChanged(); + break; + case OPEN_VPN: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Certificate(TLS)"), KYAUTH_CERTIFICATE); + m_authModeComboBox->addItem(tr("Static key"), KYAUTH_STATICPASSWD); + m_authModeComboBox->addItem(tr("Password"), KYAUTH_PASSWD); + m_authModeComboBox->addItem(tr("Password and certificate(TLS)"), KYAUTH_CERTIFICATEANDPASSWD); + onAuthModeComboxIndexChanged(); + break; + case PPTP: + m_authModeComboBox->clear(); + showPptpPwd(); + break; + case STRONG_SWAN: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Certificate/Private key"), KYAUTH_KEY); + m_authModeComboBox->addItem(tr("Certificate/ssh-agent"), KYAUTH_AGENT); + m_authModeComboBox->addItem(tr("Smart card"), KYAUTH_SMARTCARD); + m_authModeComboBox->addItem("EAP", KYAUTH_EAP); + onAuthModeComboxIndexChanged(); + break; + default: + break; + } + Q_EMIT vpnTypeChanged(VpnType(m_vpnTypeComboBox->currentData().toInt())); +} + +void VpnConfigPage::onAuthModeComboxIndexChanged() +{ + switch (m_authModeComboBox->currentData().toInt()) { + case KYAUTH_PASSWD: + if (m_vpnTypeComboBox->currentData().toInt() == L2TP) { + showL2tpPwd(); + } else if (m_vpnTypeComboBox->currentData().toInt() == OPEN_VPN) { + showOpenVpnPwd(); + } + break; + case KYAUTH_KEY: + showSswanCertPrivteKey(); + break; + case KYAUTH_AGENT: + showSswanCertSsh(); + break; + case KYAUTH_SMARTCARD: + showSswanSmartCard(); + break; + case KYAUTH_EAP: + showSswanEap(); + break; + case KYAUTH_CERTIFICATE: + showOpenVpnTls(); + break; + case KYAUTH_CERTIFICATEANDPASSWD: + showOpenVpnPwdTls(); + break; + case KYAUTH_STATICPASSWD: + showOpenVpnStaticKey(); + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN auth mothod"; + break; + } +} + +void VpnConfigPage::setEnableOfConfirmBtn() +{ + Q_EMIT setConfigPageState(checkConfirmBtnIsEnabled()); +} + +void VpnConfigPage::onPrivateKeyButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a private key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_privateKeyEdit->blockSignals(true); + m_privateKeyEdit->setText(fileName); + m_privateKeyEdit->blockSignals(false); + } +} + +void VpnConfigPage::onCaCertButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a CA certificate"), + "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + m_caCertPathEdit->blockSignals(true); + m_caCertPathEdit->setText(fileName); + m_caCertPathEdit->blockSignals(false); + } +} + +void VpnConfigPage::onUserCertButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a User certificate"), + "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + m_userCertPathEdit->blockSignals(true); + m_userCertPathEdit->setText(fileName); + m_userCertPathEdit->blockSignals(false); + } +} + +void VpnConfigPage::onStaticKeyButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a Static key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_staticKeyPathEdit->blockSignals(true); + m_staticKeyPathEdit->setText(fileName); + m_staticKeyPathEdit->blockSignals(false); + } +} + + +bool VpnConfigPage::checkL2tpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_ntDomain != m_ntDomainEdit->text() + || vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + return isChanged; +} + +bool VpnConfigPage::checkPptpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_ntDomain != m_ntDomainEdit->text() + || vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + return isChanged; +} + +bool VpnConfigPage::checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod != currentAuthMethod) { + isChanged = true; + } + + if (currentAuthMethod == KYAUTH_PASSWD || currentAuthMethod == KYAUTH_CERTIFICATEANDPASSWD) { + if (vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt() + || vpnInfo.m_caCertificate != m_caCertPathEdit->text()) { + + isChanged = true; + } + } + + if (currentAuthMethod == KYAUTH_CERTIFICATEANDPASSWD || currentAuthMethod == KYAUTH_CERTIFICATE) { + if (vpnInfo.m_caCertificate != m_caCertPathEdit->text() + || vpnInfo.m_userCertificate != m_userCertPathEdit->text() + || vpnInfo.m_userKey != m_privateKeyEdit->text() + || vpnInfo.m_privatePasswd != m_privateKeyPwdEdit->text() + || vpnInfo.m_privatePasswdPolicy != m_pwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + + } + if (currentAuthMethod == KYAUTH_STATICPASSWD) { + if (vpnInfo.m_staticKey != m_staticKeyPathEdit->text() + || vpnInfo.m_vpnKeyDir != m_keyDirectionCombox->currentData().toString() + || vpnInfo.m_localAddress != m_localIpEdit->text() + || vpnInfo.m_remoteAddress != m_localIpEdit->text()) { + + isChanged = true; + } + } + + return isChanged; +} + +bool VpnConfigPage::checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + + if (vpnInfo.m_authMethod != currentAuthMethod) { + isChanged = true; + } + + if (currentAuthMethod == KYAUTH_KEY) { + if (vpnInfo.m_caCertificate != m_caCertPathEdit->text() + || vpnInfo.m_userCertificate != m_userCertPathEdit->text() + || vpnInfo.m_userKey != m_privateKeyEdit->text() + || vpnInfo.m_privatePasswd != m_privateKeyPwdEdit->text() + || vpnInfo.m_privatePasswdPolicy != m_pwdOptionCombox->currentData().toInt()) { + + isChanged = true; + + } + }else if (currentAuthMethod == KYAUTH_AGENT) { + if (vpnInfo.m_userCertificate != m_userCertPathEdit->text()) { + isChanged = true; + } + } else if (currentAuthMethod == KYAUTH_SMARTCARD) { + if (vpnInfo.m_pinId != m_pinEdit->text()) { + isChanged = true; + } + } else if (currentAuthMethod == KYAUTH_EAP) { + if (vpnInfo.m_userName != m_usernameEdit->text() || vpnInfo.m_userPasswd != m_userPwdEdit->text()) { + isChanged = true; + } + } + return isChanged; +} diff --git a/src-vpn/frontend/vpndetails/vpnconfigpage.h b/src-vpn/frontend/vpndetails/vpnconfigpage.h new file mode 100644 index 00000000..e5d60ba5 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnconfigpage.h @@ -0,0 +1,198 @@ +#ifndef VPNCONFIGPAGE_H +#define VPNCONFIGPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kylable.h" +#include "kwidget.h" +#include "kpasswordedit.h" +#include "kyvpnconnectoperation.h" + +using namespace kdk; + +#define KEY_DIRECTION_NONE_INDEX 0 +#define KEY_DIRECTION_ZERO_INDEX 1 +#define KEY_DIRECTION_ONE_INDEX 2 + +#define KEY_DIRECTION_NONE "None" +#define KEY_DIRECTION_ZERO "0" +#define KEY_DIRECTION_ONE "1" + +enum VpnType { + UNKNOW = -1, + L2TP = 0, + OPEN_VPN, + PPTP, + STRONG_SWAN +}; + +enum OpenVpnAuthMethodIndex { + CERTIFICATE_INDEX = 0, + STATICPASSWD_INDEX, + PASSWD_INDEX, + CERTIFICATEANDPASSWD_INDEX, +}; +enum StrongSwanAuthMethodIndex { + KEY_INDEX = 0, + AGENT_INDEX, + SMARTCARD_INDEX, + EAP_INDEX, +}; + +class VpnConfigPage : public QFrame +{ + Q_OBJECT +public: + explicit VpnConfigPage(QWidget *parent = nullptr); + ~VpnConfigPage() = default; + + VpnType getVpnType(); + void setVpnConfigInfo(const KyVpnConfig &vpnInfo); + bool checkIsChanged(const KyVpnConfig &vpnInfo); + + void updateVpnConfigInfo(KyVpnConfig &vpnInfo); + +private: + QFrame *m_vpnCommunalFrame; + QFrame *m_authModeFrame; + QFrame *m_caCertFrame; + QFrame *m_userCertFrame; + QFrame *m_staticKeysFrame; + QFrame *m_pinFrame; + QFrame *m_PrivateKeysFrame; + QFrame *m_usersFrame; + QFrame *m_userPwdOpFrame; + QFrame *m_ntFrame; + + //公有 + QLabel *m_vpnTypeLabel; + QLabel *m_vpnNameLabel; + FixLabel *m_serverAddressLabel; + QComboBox *m_vpnTypeComboBox = nullptr; + QLineEdit *m_vpnNameEdit = nullptr; + QLineEdit *m_serverAddressEdit = nullptr; + + //认证方式 Authentication Mode + FixLabel *m_authModeLabel; + QComboBox *m_authModeComboBox = nullptr; + + //证书 私钥 + FixLabel *m_caCertLabel; + FixLabel *m_userCertLabel; + FixLabel *m_privateKeyLabel; + FixLabel *m_privateKeyPwdLabel; + FixLabel *m_pwdOptionLabel; + + QLineEdit *m_caCertPathEdit; + QLineEdit *m_userCertPathEdit; + QLineEdit *m_privateKeyEdit; + KPasswordEdit *m_privateKeyPwdEdit; + QComboBox *m_pwdOptionCombox; + + QPushButton *m_caCertButton; + QPushButton *m_userCertButton; + QPushButton *m_privateKeyButton; + + //静态密钥 + QLabel *m_staticKeyLabel; + FixLabel *m_keyDirectionLabel; + QLabel *m_noticesLabel; + QLabel *m_localIpLabel; + QLabel *m_remoteIpLabel; + + QLineEdit *m_staticKeyPathEdit; + QPushButton *m_staticKeyButton; + QComboBox *m_keyDirectionCombox; + QLineEdit *m_localIpEdit; + QLineEdit *m_remoteIpEdit; + + //智能卡 PIN码 + QLabel *m_pinLabel; + QLineEdit *m_pinEdit; + + //密码 + FixLabel *m_usernameLabel; + QLabel *m_userPwdLabel; + FixLabel *m_userPwdOptionLabel; + QLineEdit *m_usernameEdit; + KPasswordEdit *m_userPwdEdit; + QComboBox *m_userPwdOptionCombox; + + //L2TP PPTP公有 + QLabel *m_ntDomainLabel; + QLineEdit *m_ntDomainEdit; + + + void initUI(); + void initConnect(); + void showL2tpPwd(); + void showPptpPwd(); + void showOpenVpnTls(); + void showOpenVpnPwd(); + void showOpenVpnPwdTls(); + void showOpenVpnStaticKey(); + void showSswanCertPrivteKey(); + void showSswanCertSsh(); + void showSswanSmartCard(); + void showSswanEap(); + + bool getTextEditState(QString text); + bool checkConfirmBtnIsEnabled(); + + + //填充VPN认证信息 + void setPwdAuthInfo(const QString &username, const QString &userPwd, const KyPasswdPolicy &userPwdPolicy); + void setCaCertAuthInfo(const QString &caCertificate); + + void setKeyAuthInfo(const QString &userCert, const QString &privateKey, + const QString &privateKeyPwd, const KyPasswdPolicy &privatePwdPolicy); + + void setStaticKeyAuthInfo(const QString &staticKey, const QString &vpnKeyDirection, + const QString &localIp, const QString &remoteIp); + + void setAgentAuthInfo(const QString &userCert); + void setSmartCardAuthInfo(const QString &pin); + void setEapAuthInfo(const QString &username, const QString &userPwd); + void setNtDomain(const QString &ntDomain); + + //set info + void setL2tpConfigInfo(const KyVpnConfig &vpnInfo); + void setPptpConfigInfo(const KyVpnConfig &vpnInfo); + void setOpenVpnConfigInfo(const KyVpnConfig &vpnInfo); + void setSSwanVpnConfigInfo(const KyVpnConfig &vpnInfo); + + //check change + bool checkL2tpIsChanged(const KyVpnConfig &vpnInfo); + bool checkPptpIsChanged(const KyVpnConfig &vpnInfo); + bool checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo); + bool checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo); + + //update + void updateL2tpConfigInfo(KyVpnConfig &vpnInfo); + void updatePptpConfigInfo(KyVpnConfig &vpnInfo); + void updateOpenVpnConfigInfo(KyVpnConfig &vpnInfo); + void updateSSwanVpnConfigInfo(KyVpnConfig &vpnInfo); + +private Q_SLOTS: + void onVpnTypeComboxIndexChanged(); + void onAuthModeComboxIndexChanged(); + void setEnableOfConfirmBtn(); + void onCaCertButtonClicked(); + void onUserCertButtonClicked(); + void onStaticKeyButtonClicked(); + void onPrivateKeyButtonClicked(); + +Q_SIGNALS: + void setConfigPageState(bool); + void vpnTypeChanged(VpnType type); +}; + +#endif // VPNCONFIGPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpndetail.cpp b/src-vpn/frontend/vpndetails/vpndetail.cpp new file mode 100644 index 00000000..bc4150ee --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetail.cpp @@ -0,0 +1,439 @@ +#include "vpndetail.h" + +#define WINDOW_WIDTH 520 +#define WINDOW_HEIGHT 562 +#define NO_LAYOUT_MARGINS 0,0,0,0 +#define HLAYOUT_MARGINS 24,0,24,0 +#define CENTER_LAYOUT_MARGINS 24,0,0,0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define BOTTOM_WIDGET_HEIGHT 85 +#define TAB_HEIGHT 36 +#define TAB_WIDTH 80 +#define MAX_TAB_TEXT_LENGTH 44 +#define VPNTAB_WIDTH 240 +#define PAGE_WIDTH 472 +#define SCRO_WIDTH 496 +#define CONFIG_PAGE_NUM 0 +#define IPV4_PAGE_NUM 1 +#define IPV6_PAGE_NUM 2 +#define ADVANCED_PAGE_NUM 3 +#define NORMAL_PAGE_COUNT 3 +#define LOG_FLAG "[VPN Detail]" +#define TAB_HEIGHT_TABLET 48 + +VpnDetail::VpnDetail(QString vpnUuid, QString vpnName, QWidget *parent) : + m_vpnName(vpnName), + m_uuid(vpnUuid), + QWidget(parent) +{ + initWindow(); + centerToScreen(); + getVpnConfig(m_uuid, m_vpnInfo); + + initUI(); + initConnection(); + pagePadding(m_isOpenVpn); + + m_isConfigOk = true; + m_isIpv4Ok = true; + m_isIpv6Ok = true; + m_isAdvancedOk = true; + setConfirmEnable(); +} + +void VpnDetail::paintEvent(QPaintEvent *event) +{ + QPalette pal = qApp->palette(); + QPainter painter(this); + painter.setBrush(pal.color(QPalette::Base)); + painter.drawRect(this->rect()); + painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); + + return QWidget::paintEvent(event); +} + + +void VpnDetail::initWindow() +{ + this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT); + this->setWindowTitle(tr("VPN")); + this->setAttribute(Qt::WA_DeleteOnClose); +} + +void VpnDetail::initTabBar() +{ + //文本长度超出显示区域设置tooltip + int tabCount = m_vpnTabBar->count(); + for (int i = 0; i< tabCount; ++i) { + QFontMetrics fontMetrics(m_vpnTabBar->font()); + int fontSize = fontMetrics.width(m_vpnTabBar->tabText(i)); + if (fontSize > MAX_TAB_TEXT_LENGTH) { + m_vpnTabBar->setTabToolTip(i, m_vpnTabBar->tabText(i)); + } else { + m_vpnTabBar->setTabToolTip(i, ""); + } + } +} + +void VpnDetail::initUI() +{ + //控件 + m_topWidget = new QWidget(this); + m_centerWidget = new QWidget(this); + m_bottomWidget = new QWidget(this); + m_divider = new Divider(this); + m_vpnTabBar = new VpnTabBar(this); + m_autoConnectBox = new QCheckBox(this); + m_autoConnectLabel = new QLabel(this); + m_cancelBtn = new QPushButton(this); + m_confimBtn = new QPushButton(this); + m_stackWidget = new QStackedWidget(m_centerWidget); + + m_configPage = new VpnConfigPage(this); + m_ipv4Page = new VpnIpv4Page(this); + m_ipv6Page = new VpnIpv6Page(this); + m_advancedPage = new VpnAdvancedPage(this); + + m_configScroArea = new QScrollArea(m_centerWidget); + m_configScroArea->setFrameShape(QFrame::NoFrame); + m_configScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_configScroArea->setWidget(m_configPage); + m_configScroArea->setWidgetResizable(true); + + m_ipv4ScroArea = new QScrollArea(m_centerWidget); + m_ipv4ScroArea->setFrameShape(QFrame::NoFrame); + m_ipv4ScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv4ScroArea->setWidget(m_ipv4Page); + m_ipv4ScroArea->setWidgetResizable(true); + + m_ipv6ScroArea = new QScrollArea(m_centerWidget); + m_ipv6ScroArea->setFrameShape(QFrame::NoFrame); + m_ipv6ScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv6ScroArea->setWidget(m_ipv6Page); + m_ipv6ScroArea->setWidgetResizable(true); + + m_advancedScroArea = new QScrollArea(m_centerWidget); + m_advancedScroArea->setFrameShape(QFrame::NoFrame); + m_advancedScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_advancedScroArea->setWidget(m_advancedPage); + m_advancedScroArea->setWidgetResizable(true); + + QPalette pal = m_configScroArea->palette(); + pal.setBrush(QPalette::Window, Qt::transparent); + m_configScroArea->setPalette(pal); + m_ipv4ScroArea->setPalette(pal); + m_ipv6ScroArea->setPalette(pal); + m_advancedScroArea->setPalette(pal); + + m_configPage->setFixedWidth(PAGE_WIDTH); + m_ipv4Page->setFixedWidth(PAGE_WIDTH); + m_ipv6Page->setFixedWidth(PAGE_WIDTH); + m_advancedPage->setFixedWidth(PAGE_WIDTH); + m_configScroArea->setFixedWidth(SCRO_WIDTH); + m_ipv4ScroArea->setFixedWidth(SCRO_WIDTH); + m_ipv6ScroArea->setFixedWidth(SCRO_WIDTH); + m_advancedScroArea->setFixedWidth(SCRO_WIDTH); + + m_stackWidget->addWidget(m_configScroArea); + m_stackWidget->addWidget(m_ipv4ScroArea); + m_stackWidget->addWidget(m_ipv6ScroArea); + m_stackWidget->addWidget(m_advancedScroArea); + + //控件显示文本 + m_vpnTabBar->addTab(tr("VPN")); + m_vpnTabBar->addTab(tr("IPv4")); + if (m_isOpenVpn) { + m_vpnTabBar->addTab(tr("IPv6")); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH + TAB_WIDTH); + } else { + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH); + } + m_vpnTabBar->addTab(tr("Advanced")); + m_vpnTabBar->setFixedHeight(TAB_HEIGHT); + initTabBar(); + + m_autoConnectBox->setChecked(false); + m_autoConnectLabel->setText(tr("Auto Connection")); + m_cancelBtn->setText(tr("Cancel")); + m_confimBtn->setText(tr("Confirm")); + + //布局 + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(NO_SPACE); + mainLayout->addSpacing(HLAYOUT_SPACING); + mainLayout->addWidget(m_topWidget); + mainLayout->addSpacing(VLAYOUT_SPACING); + mainLayout->addWidget(m_centerWidget); + mainLayout->addStretch(); + mainLayout->addWidget(m_divider); + mainLayout->addWidget(m_bottomWidget); + m_bottomWidget->setFixedHeight(BOTTOM_WIDGET_HEIGHT); + + QHBoxLayout *topLayout = new QHBoxLayout(m_topWidget); + topLayout->setContentsMargins(HLAYOUT_MARGINS); + topLayout->addWidget(m_vpnTabBar, Qt::AlignCenter); + + QVBoxLayout *centerlayout = new QVBoxLayout(m_centerWidget); + centerlayout->setContentsMargins(CENTER_LAYOUT_MARGINS); // 右边距为0,为安全页滚动区域留出空间 + centerlayout->addWidget(m_stackWidget); + + QHBoxLayout *bottomLayout = new QHBoxLayout(m_bottomWidget); + bottomLayout->setContentsMargins(HLAYOUT_MARGINS); + bottomLayout->setSpacing(NO_SPACE); + bottomLayout->addWidget(m_autoConnectBox); + bottomLayout->addSpacing(8); + bottomLayout->addWidget(m_autoConnectLabel); + bottomLayout->addStretch(); + bottomLayout->addWidget(m_cancelBtn); + bottomLayout->addSpacing(HLAYOUT_SPACING); + bottomLayout->addWidget(m_confimBtn); + + m_advancedPage->setVpnAdvancedPage(m_configPage->getVpnType()); +} + +void VpnDetail::initConnection() +{ + connect(m_vpnTabBar, &VpnTabBar::currentChanged, this, &VpnDetail::onTabCurrentRowChange); + connect(m_cancelBtn, &QPushButton::clicked, [&] () {this->close();}); + connect(m_confimBtn, &QPushButton::clicked, this, &VpnDetail::onConfimBtnClicked); + + connect(m_configPage, &VpnConfigPage::setConfigPageState, this, [=] (bool state) { + m_isConfigOk = state; + setConfirmEnable(); + }); + connect(m_ipv4Page, &VpnIpv4Page::setIpv4PageState, this, [=] (bool state) { + m_isIpv4Ok = state; + setConfirmEnable(); + }); + connect(m_ipv6Page, &VpnIpv6Page::setIpv6PageState, this, [=] (bool state) { + m_isIpv6Ok = state; + setConfirmEnable(); + }); + connect(m_advancedPage, &VpnAdvancedPage::setAdvancedPageState, this, [=] (bool state) { + m_isAdvancedOk = state; + setConfirmEnable(); + }); + + connect(m_configPage, &VpnConfigPage::vpnTypeChanged, m_advancedPage, &VpnAdvancedPage::setVpnAdvancedPage); + + connect(m_configPage, &VpnConfigPage::vpnTypeChanged, this, [=](VpnType type) { + if (type == OPEN_VPN) { + if (m_vpnTabBar->count() == NORMAL_PAGE_COUNT) { + m_vpnTabBar->insertTab(IPV6_PAGE_NUM, tr("IPv6")); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH + TAB_WIDTH); + } + } else { + if (m_vpnTabBar->count() > NORMAL_PAGE_COUNT) { + m_vpnTabBar->removeTab(IPV6_PAGE_NUM); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH); + } + } + }); +} + +void VpnDetail::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); + this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); +} + +void VpnDetail::setConfirmEnable() +{ + bool isConfirmBtnEnable = false; + if (m_isConfigOk && m_isIpv4Ok && m_isAdvancedOk) { + if (m_isOpenVpn && !m_isIpv6Ok) { + isConfirmBtnEnable = false; + } else { + isConfirmBtnEnable = true; + } + } + m_confimBtn->setEnabled(isConfirmBtnEnable); +} + +void VpnDetail::getVpnConfig(QString connectUuid, KyVpnConfig &vpnInfo) +{ + KyVpnConnectOperation vpnConnect(this); + vpnInfo = vpnConnect.getVpnConfig(connectUuid); + m_isOpenVpn = m_vpnInfo.m_vpnType == KYVPNTYPE_OPENVPN; +} + +void VpnDetail::pagePadding(bool isOpenVpn) +{ + m_autoConnectBox->setChecked(m_vpnInfo.m_isAutoConnect); + + //配置页面填充 + m_configPage->setVpnConfigInfo(m_vpnInfo); + + //IPv4页面填充 + m_ipv4Page->setVpnIpv4Info(m_vpnInfo); + if (!m_vpnInfo.m_ipv4Dns.isEmpty()) { + m_ipv4Page->setDns(m_vpnInfo.m_ipv4Dns.at(0).toString()); + } + if (!m_vpnInfo.m_ipv4DnsSearch.isEmpty()) { + m_ipv4Page->setSearchDomain(m_vpnInfo.m_ipv4DnsSearch.at(0)); + } + m_ipv4Page->setDhcpClientId(m_vpnInfo.m_ipv4DhcpClientId); + //IPv6页面填充 + if (isOpenVpn) { + m_ipv6Page->setVpnIpv6Info(m_vpnInfo); + if (!m_vpnInfo.m_ipv6Dns.isEmpty()) { + m_ipv6Page->setDns(m_vpnInfo.m_ipv6Dns.at(0).toString()); + } + if (!m_vpnInfo.m_ipv6DnsSearch.isEmpty()) { + m_ipv6Page->setSearchDomain(m_vpnInfo.m_ipv6DnsSearch.at(0)); + } + } + + //高级页面填充 + if (m_vpnInfo.m_vpnType == KYVPNTYPE_L2TP || m_vpnInfo.m_vpnType == KYVPNTYPE_PPTP) { + m_advancedPage->setL2tpOrPptpAdiaInfo(m_vpnInfo); + } else if (m_vpnInfo.m_vpnType == KYVPNTYPE_OPENVPN) { + m_advancedPage->setOpenVpnAdiaInfo(m_vpnInfo); + } else if (m_vpnInfo.m_vpnType == KYVPNTYPE_STRONGSWAN) { + m_advancedPage->setStrongSwanAdiaInfo(m_vpnInfo); + } +} + +bool VpnDetail::updateVpnCnofig() +{ + KyVpnConnectOperation vpnConnect(this); + KyVpnConfig vpnConfig = m_vpnInfo; + bool needUpdate = false; + VpnType vpnType = m_configPage->getVpnType(); + + if (m_vpnInfo.m_isAutoConnect != m_autoConnectBox->isChecked()) { + vpnConfig.m_isAutoConnect = m_autoConnectBox->isChecked(); + needUpdate = true; + } + + if (m_configPage->checkIsChanged(m_vpnInfo)) { + m_configPage->updateVpnConfigInfo(vpnConfig); + needUpdate = true; + } + + if (m_ipv4Page->checkIsChanged(m_vpnInfo)) { + m_ipv4Page->updateVpnIpv4Info(vpnConfig); + needUpdate = true; + } + + if (vpnType == OPEN_VPN) { + if (m_ipv6Page->checkIsChanged(m_vpnInfo)) { + m_ipv6Page->updateVpnIpv6Info(vpnConfig); + needUpdate = true; + } + } + + if (m_advancedPage->checkIsChanged(m_vpnInfo, vpnType)) { + if (vpnType == L2TP || vpnType == PPTP) { + m_advancedPage->updateL2tpOrPptpAdiaInfo(vpnConfig); + needUpdate = true; + } else if (vpnType == OPEN_VPN) { + m_advancedPage->updateOpenVpnAdiaInfo(vpnConfig); + needUpdate = true; + } else if (vpnType == STRONG_SWAN) { + m_advancedPage->updateStrongSwanAdiaInfo(vpnConfig); + needUpdate = true; + } + } + + if (needUpdate) { + vpnConnect.setVpnConfig(m_uuid, vpnConfig); + } + + return true; +} + +void VpnDetail::setVpndetailSomeEnable(bool on) +{ + m_configPage->setEnabled(on); + m_ipv4Page->setEnabled(on); + m_ipv6Page->setEnabled(on); + m_advancedPage->setEnabled(on); + m_cancelBtn->setEnabled(on); + m_confimBtn->setEnabled(on); +} + +void VpnDetail::onTabCurrentRowChange(int row) +{ + if (row < 2) { + m_stackWidget->setCurrentIndex(row); + } else { + if (m_configPage->getVpnType() == OPEN_VPN) { + m_stackWidget->setCurrentIndex(row); + } else { + m_stackWidget->setCurrentIndex(ADVANCED_PAGE_NUM); + } + } +} + +void VpnDetail::onConfimBtnClicked() +{ + qDebug() << "onConfimBtnClicked"; + setVpndetailSomeEnable(false); + //更新连接 + qDebug() << "Confirm update connect"; + if (!updateVpnCnofig()) { + setVpndetailSomeEnable(true); + return; + } + close(); +} + + +VpnTabBar::VpnTabBar(QWidget *parent) + :KTabBar(KTabBarStyle::SegmentDark, parent) +{ + //模式切换 + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QString("mode_change_signal"), this, SLOT(onModeChanged(bool))); + //模式获取 + QDBusInterface interface(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QDBusConnection::sessionBus()); + if(!interface.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + QDBusReply reply = interface.call("get_current_tabletmode"); + if (!reply.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + onModeChanged(reply.value()); +} + +QSize VpnTabBar::sizeHint() const +{ + QSize size = KTabBar::sizeHint(); + size.setWidth(TAB_WIDTH); + return size; +} + +QSize VpnTabBar::minimumTabSizeHint(int index) const +{ + Q_UNUSED(index) + QSize size = KTabBar::minimumTabSizeHint(index); + size.setWidth(TAB_WIDTH); + return size; +} + +void VpnTabBar::onModeChanged(bool mode) +{ + if (mode) { + this->setFixedHeight(TAB_HEIGHT_TABLET); // 平板模式 + } else { + this->setFixedHeight(TAB_HEIGHT); // PC模式 + } + +} diff --git a/src-vpn/frontend/vpndetails/vpndetail.h b/src-vpn/frontend/vpndetails/vpndetail.h new file mode 100644 index 00000000..c98585af --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetail.h @@ -0,0 +1,111 @@ +#ifndef VPNDETAIL_H +#define VPNDETAIL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kwidget.h" +#include "ktabbar.h" +#include "../tools/divider.h" +#include "vpnconfigpage.h" +#include "vpnipv4page.h" +#include "vpnipv6page.h" +#include "vpnadvancedpage.h" + +#include "kyvpnconnectoperation.h" + + +using namespace kdk; + +class VpnTabBar : public KTabBar +{ + Q_OBJECT +public: + explicit VpnTabBar(QWidget *parent = nullptr); + ~VpnTabBar() = default; + +protected: + QSize sizeHint() const; + QSize minimumTabSizeHint(int index) const; + +private Q_SLOTS: + void onModeChanged(bool mode); + +}; + +class VpnDetail : public QWidget +{ + Q_OBJECT +public: + explicit VpnDetail(QString vpnUuid, QString vpnName, QWidget *parent = nullptr); + void centerToScreen(); + +protected: + void paintEvent(QPaintEvent *event); + +private: + void initUI(); + void initWindow(); + void initTabBar(); + + void initConnection(); + void setConfirmEnable(); + + void getVpnConfig(QString connectUuid, KyVpnConfig &vpnInfo); + void pagePadding(bool isOpenVpn); + + bool updateVpnCnofig(); + void setVpndetailSomeEnable(bool on); + + bool m_isOpenVpn = false; + QString m_vpnName; + QString m_uuid; + KyVpnConfig m_vpnInfo; + + QStackedWidget * m_stackWidget; + QWidget *m_topWidget; + QWidget *m_centerWidget; + Divider *m_divider = nullptr; + QWidget *m_bottomWidget; + + VpnConfigPage *m_configPage = nullptr; + VpnIpv4Page *m_ipv4Page = nullptr; + VpnIpv6Page *m_ipv6Page = nullptr; + VpnAdvancedPage *m_advancedPage = nullptr; + + QScrollArea *m_configScroArea = nullptr; + QScrollArea *m_ipv4ScroArea = nullptr; + QScrollArea *m_ipv6ScroArea = nullptr; + QScrollArea *m_advancedScroArea = nullptr; + VpnTabBar *m_vpnTabBar = nullptr; + QCheckBox *m_autoConnectBox = nullptr; + QLabel *m_autoConnectLabel; + QPushButton *m_cancelBtn; + QPushButton *m_confimBtn; + + bool m_isConfigOk = false; + bool m_isIpv4Ok = false; + bool m_isIpv6Ok = false; + bool m_isAdvancedOk = false; + +protected Q_SLOTS: + void onTabCurrentRowChange(int row); + void onConfimBtnClicked(); + +Q_SIGNALS: + void currentChanged(int); + +}; + +#endif // VPNDETAIL_H diff --git a/src-vpn/frontend/vpndetails/vpndetails.pri b/src-vpn/frontend/vpndetails/vpndetails.pri new file mode 100644 index 00000000..e80cdfa7 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetails.pri @@ -0,0 +1,17 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/vpnaddpage.h \ + $$PWD/vpnadvancedpage.h \ + $$PWD/vpnconfigpage.h \ + $$PWD/vpndetail.h \ + $$PWD/vpnipv4page.h \ + $$PWD/vpnipv6page.h + +SOURCES += \ + $$PWD/vpnaddpage.cpp \ + $$PWD/vpnadvancedpage.cpp \ + $$PWD/vpnconfigpage.cpp \ + $$PWD/vpndetail.cpp \ + $$PWD/vpnipv4page.cpp \ + $$PWD/vpnipv6page.cpp diff --git a/src-vpn/frontend/vpndetails/vpnipv4page.cpp b/src-vpn/frontend/vpndetails/vpnipv4page.cpp new file mode 100644 index 00000000..fa49a9cd --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv4page.cpp @@ -0,0 +1,284 @@ +#include "vpnipv4page.h" +#include "math.h" +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define AUTO_CONFIG 0 +#define MANUAL_CONFIG 1 +#define LOG_FLAG "[VPN IPv4Page]" + +VpnIpv4Page::VpnIpv4Page(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); +} + +void VpnIpv4Page::setVpnIpv4Info(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_ipv4ConfigIpType == CONFIG_IP_DHCP) { + m_ipv4ConfigCombox->setCurrentIndex(AUTO_CONFIG); + } else { + m_ipv4ConfigCombox->setCurrentIndex(MANUAL_CONFIG); + if (!vpnInfo.m_ipv4Address.isEmpty()) { + m_ipv4addressEdit->setText(vpnInfo.m_ipv4Address.at(0).ip().toString()); + m_netMaskEdit->setText(vpnInfo.m_ipv4Address.at(0).netmask().toString()); + m_gateWayEdit->setText(vpnInfo.m_ipv4Address.at(0).gateway().toString()); + } + } +} + +void VpnIpv4Page::setDns(const QString &firstDns) +{ + m_dnsServerEdit->setText(firstDns); +} + +void VpnIpv4Page::setSearchDomain(const QString &searchDomain) +{ + m_searchDomainEdit->setText(searchDomain); +} + +void VpnIpv4Page::setDhcpClientId(const QString &dhcpId) +{ + m_dhcpClientIdEdit->setText(dhcpId); +} + +bool VpnIpv4Page::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (vpnInfo.m_ipv4ConfigIpType != CONFIG_IP_DHCP) { + qDebug() << LOG_FLAG << "ipv4ConfigType change to Auto"; + isChanged = true; + } + } else { + if (vpnInfo.m_ipv4ConfigIpType != CONFIG_IP_MANUAL) { + qDebug() << LOG_FLAG << "ipv4ConfigType change to Manual"; + isChanged = true; + } + + if (!vpnInfo.m_ipv4Address.isEmpty()) { + if(vpnInfo.m_ipv4Address.at(0).ip().toString() != m_ipv4addressEdit->text() + || vpnInfo.m_ipv4Address.at(0).netmask().toString() != getNetMaskText(m_netMaskEdit->text()) + || vpnInfo.m_ipv4Address.at(0).gateway().toString() != m_gateWayEdit->text()) { + + isChanged = true; + } + } + } + + if (!vpnInfo.m_ipv4Dns.isEmpty() && vpnInfo.m_ipv4Dns.at(0).toString() != m_dnsServerEdit->text()) { + isChanged = true; + } + + if (!vpnInfo.m_ipv4DnsSearch.isEmpty() && vpnInfo.m_ipv4DnsSearch.at(0) != m_searchDomainEdit->text()) { + isChanged = true; + } + if (vpnInfo.m_ipv4DhcpClientId != m_dhcpClientIdEdit->text()){ + isChanged = true; + } + return isChanged; +} + +void VpnIpv4Page::updateVpnIpv4Info(KyVpnConfig &vpnInfo) +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + QString ipv4address(""); + QString netMask(""); + QString gateWay(""); + vpnInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); + vpnInfo.ipv4AddressConstruct(ipv4address, netMask, gateWay); + qDebug() << LOG_FLAG << "IPv4 method" << vpnInfo.m_ipv4ConfigIpType; + qDebug() << LOG_FLAG << "Update IPv4 info finished"; + } else { + QString ipv4address =m_ipv4addressEdit->text(); + QString netMask = getNetMaskText(m_netMaskEdit->text()); + QString gateWay = m_gateWayEdit->text(); + qDebug() << ipv4address << netMask << gateWay; + vpnInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); + vpnInfo.ipv4AddressConstruct(ipv4address, netMask, gateWay); + vpnInfo.dumpInfo(); + qDebug() << LOG_FLAG << "Update IPv4 info finished"; + } + + QList ipv4DnsList; + ipv4DnsList.clear(); + if (!m_dnsServerEdit->text().isEmpty()) { + ipv4DnsList.append(QHostAddress(m_dnsServerEdit->text())); + } + vpnInfo.ipv4DnsConstruct(ipv4DnsList); + + vpnInfo.m_ipv4DnsSearch.clear(); + vpnInfo.m_ipv4DnsSearch.append(m_searchDomainEdit->text()); + vpnInfo.m_ipv4DhcpClientId = m_dhcpClientIdEdit->text(); +} + +void VpnIpv4Page::initUI() +{ + /**********控件**********/ + m_configLabel = new QLabel(this); + m_addressLabel = new QLabel(this); + m_maskLabel = new QLabel(this); + m_gateWayLabel = new QLabel(this); + m_dnsServerLabel = new QLabel(this); + m_searchDomainLabel = new QLabel(this); + m_dhcpClientIdLabel = new QLabel(this); + + m_ipv4ConfigCombox =new QComboBox(this); + m_ipv4addressEdit = new QLineEdit(this); + m_netMaskEdit = new QLineEdit(this); + m_gateWayEdit = new QLineEdit(this); + m_dnsServerEdit = new QLineEdit(this); + m_searchDomainEdit = new QLineEdit(this); + m_dhcpClientIdEdit = new QLineEdit(this); + + + /**********布局**********/ + QFormLayout *mainLayout = new QFormLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setHorizontalSpacing(HLAYOUT_SPACING); + mainLayout->setVerticalSpacing(VLAYOUT_SPACING); + mainLayout->addRow(m_configLabel, m_ipv4ConfigCombox); + mainLayout->addRow(m_addressLabel, m_ipv4addressEdit); + mainLayout->addRow(m_maskLabel, m_netMaskEdit); + mainLayout->addRow(m_gateWayLabel, m_gateWayEdit); + mainLayout->addRow(m_dnsServerLabel, m_dnsServerEdit); + mainLayout->addRow(m_searchDomainLabel, m_searchDomainEdit); + mainLayout->addRow(m_dhcpClientIdLabel, m_dhcpClientIdEdit); + + + /**********控件显示**********/ + m_configLabel->setText(tr("IPv4 Config")); + m_addressLabel->setText(tr("Address")); + m_maskLabel->setText(tr("Netmask")); + m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsServerLabel->setText(tr("DNS Server")); + m_searchDomainLabel->setText(tr("Search Domain")); //搜索域 + m_dhcpClientIdLabel->setText(tr("DHCP Client ID")); //DHCP客户端ID + + m_ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" + m_ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_ipv4addressEdit->setValidator(ipExpVal); + m_netMaskEdit->setValidator(ipExpVal); + m_gateWayEdit->setValidator(ipExpVal); + m_dnsServerEdit->setValidator(ipExpVal); +} + +void VpnIpv4Page::initConnect() +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + setManualEnabled(false); + } else if (m_ipv4ConfigCombox->currentIndex() == MANUAL_CONFIG) { + setManualEnabled(true); + } + connect(m_ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(onConfigChanged(int))); + connect(m_ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_ipv4addressEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_netMaskEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_gateWayEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_dnsServerEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_searchDomainEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_dhcpClientIdEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); +} + +void VpnIpv4Page::setManualEnabled(bool state) +{ + m_addressLabel->setEnabled(state); + m_maskLabel->setEnabled(state); + m_gateWayLabel->setEnabled(state); + m_ipv4addressEdit->setEnabled(state); + m_netMaskEdit->setEnabled(state); + m_gateWayEdit->setEnabled(state); +} + +bool VpnIpv4Page::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnIpv4Page::netMaskIsValide(QString text) +{ + if (getTextEditState(text)) { + return true; + } else { + if (text.length() > 0 && text.length() < 3) { + int num = text.toInt(); + if (num > 0 && num < 33) { + return true; + } + } + } + return false; +} + +QString VpnIpv4Page::getNetMaskText(QString text) +{ + if (text.length() > 2) { + return text; + } + + int num = text.toInt(); + QStringList list; + list << "0" << "0" << "0" << "0"; + int count = 0; + while (num - 8 >= 0) { + list[count] = "255"; + num = num - 8; + count ++; + } + if (num > 0) { + int size = pow(2, 8) - pow(2,(8-num)); + list[count] = QString::number(size); + } + return QString("%1.%2.%3.%4").arg(list[0],list[1],list[2],list[3]); +} + +bool VpnIpv4Page::checkConfirmBtnIsEnabled() +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (m_ipv4addressEdit->text().isEmpty() || !getTextEditState(m_ipv4addressEdit->text())) { + qDebug() << LOG_FLAG << "IPv4 address empty or invalid"; + return false; + } + + if (m_netMaskEdit->text().isEmpty() || !netMaskIsValide(m_netMaskEdit->text())) { + qDebug() << LOG_FLAG << "IPv4 netMask empty or invalid"; + return false; + } + } + return true; +} + +void VpnIpv4Page::setEnableOfConfirmBtn() +{ + Q_EMIT setIpv4PageState(checkConfirmBtnIsEnabled()); +} + +void VpnIpv4Page::onConfigChanged(int index) +{ + if (index == AUTO_CONFIG) { + m_ipv4addressEdit->clear(); + m_netMaskEdit->clear(); + m_gateWayEdit->clear(); + setManualEnabled(false); + } else if (index == MANUAL_CONFIG) { + setManualEnabled(true); + } +} diff --git a/src-vpn/frontend/vpndetails/vpnipv4page.h b/src-vpn/frontend/vpndetails/vpnipv4page.h new file mode 100644 index 00000000..ee73d5fe --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv4page.h @@ -0,0 +1,62 @@ +#ifndef VPNIPV4PAGE_H +#define VPNIPV4PAGE_H + +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +class VpnIpv4Page : public QFrame +{ + Q_OBJECT +public: + VpnIpv4Page(QWidget *parent = nullptr); + ~VpnIpv4Page() = default; + + void setVpnIpv4Info(const KyVpnConfig &vpnInfo); + void setDns(const QString &firstDns); + void setSearchDomain(const QString &searchDomain); + void setDhcpClientId(const QString &dhcpId); + + bool checkIsChanged(const KyVpnConfig &vpnInfo); + void updateVpnIpv4Info(KyVpnConfig &vpnInfo); + +private: + QLabel *m_configLabel; + QLabel *m_addressLabel; + QLabel *m_maskLabel; + QLabel *m_gateWayLabel; + QLabel *m_dnsServerLabel; + QLabel *m_searchDomainLabel; + QLabel *m_dhcpClientIdLabel; + + QComboBox *m_ipv4ConfigCombox; + QLineEdit *m_ipv4addressEdit; + QLineEdit *m_netMaskEdit; + QLineEdit *m_gateWayEdit; + QLineEdit *m_dnsServerEdit; + QLineEdit *m_searchDomainEdit; + QLineEdit *m_dhcpClientIdEdit; + + void initUI(); + void initConnect(); + void setManualEnabled(bool state); + + bool getTextEditState(QString text); + bool netMaskIsValide(QString text); + QString getNetMaskText(QString text); + bool checkConfirmBtnIsEnabled(); + +private Q_SLOTS: + void setEnableOfConfirmBtn(); + void onConfigChanged(int index); + +Q_SIGNALS: + void setIpv4PageState(bool); +}; + +#endif // VPNIPV4PAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnipv6page.cpp b/src-vpn/frontend/vpndetails/vpnipv6page.cpp new file mode 100644 index 00000000..87e921ab --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv6page.cpp @@ -0,0 +1,240 @@ +#include "vpnipv6page.h" +#include "math.h" +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define AUTO_CONFIG 0 +#define MANUAL_CONFIG 1 +#define LOG_FLAG "[VPN IPv6Page]" + +VpnIpv6Page::VpnIpv6Page(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); +} + +void VpnIpv6Page::setVpnIpv6Info(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_ipv6ConfigIpType == CONFIG_IP_DHCP) { + m_ipv6ConfigCombox->setCurrentIndex(AUTO_CONFIG); + } else { + m_ipv6ConfigCombox->setCurrentIndex(MANUAL_CONFIG); + if (!vpnInfo.m_ipv6Address.isEmpty()) { + m_ipv6addressEdit->setText(vpnInfo.m_ipv6Address.at(0).ip().toString()); + m_netMaskEdit->setText(vpnInfo.m_ipv6Address.at(0).netmask().toString()); + m_gateWayEdit->setText(vpnInfo.m_ipv6Address.at(0).gateway().toString()); + } + } +} + +void VpnIpv6Page::setDns(const QString &firstDns) +{ + m_dnsServerEdit->setText(firstDns); +} + +void VpnIpv6Page::setSearchDomain(const QString &searchDomain) +{ + m_searchDomainEdit->setText(searchDomain); +} + +bool VpnIpv6Page::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (vpnInfo.m_ipv6ConfigIpType != CONFIG_IP_DHCP) { + qDebug() << LOG_FLAG << "ipv6ConfigType change to Auto"; + isChanged = true; + } + } else { + if (vpnInfo.m_ipv6ConfigIpType != CONFIG_IP_MANUAL) { + qDebug() << LOG_FLAG << "ipv6ConfigType change to Manual"; + isChanged = true; + } + + if (!vpnInfo.m_ipv6Address.isEmpty()) { + if(vpnInfo.m_ipv6Address.at(0).ip().toString() != m_ipv6addressEdit->text() + || vpnInfo.m_ipv6Address.at(0).netmask().toString() != m_netMaskEdit->text() + || vpnInfo.m_ipv6Address.at(0).gateway().toString() != m_gateWayEdit->text()) { + + isChanged = true; + } + } + } + + if (!vpnInfo.m_ipv6Dns.isEmpty() && vpnInfo.m_ipv6Dns.at(0).toString() != m_dnsServerEdit->text()) { + isChanged = true; + } + + if (!vpnInfo.m_ipv6DnsSearch.isEmpty() && vpnInfo.m_ipv6DnsSearch.at(0) != m_searchDomainEdit->text()) { + isChanged = true; + } + + return isChanged; +} + +void VpnIpv6Page::updateVpnIpv6Info(KyVpnConfig &vpnInfo) +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + QString ipv6address(""); + QString netMask(""); + QString gateWay(""); + vpnInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP); + vpnInfo.ipv6AddressConstruct(ipv6address, netMask, gateWay); + qDebug() << LOG_FLAG << "IPv6 method" << vpnInfo.m_ipv6ConfigIpType; + qDebug() << LOG_FLAG << "Update IPv6 info finished"; + } else { + QString ipv6address =m_ipv6addressEdit->text(); + QString netMask = m_netMaskEdit->text(); + QString gateWay = m_gateWayEdit->text(); + qDebug() << ipv6address << netMask << gateWay; + vpnInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); + vpnInfo.ipv6AddressConstruct(ipv6address, netMask, gateWay); + vpnInfo.dumpInfo(); + qDebug() << LOG_FLAG << "Update IPv6 info finished"; + } + + QList ipv6DnsList; + ipv6DnsList.clear(); + if (!m_dnsServerEdit->text().isEmpty()) { + ipv6DnsList.append(QHostAddress(m_dnsServerEdit->text())); + } + vpnInfo.ipv6DnsConstruct(ipv6DnsList); + + vpnInfo.m_ipv6DnsSearch.clear(); + vpnInfo.m_ipv6DnsSearch.append(m_searchDomainEdit->text()); +} + +void VpnIpv6Page::initUI() +{ + /**********控件**********/ + m_configLabel = new QLabel(this); + m_addressLabel = new QLabel(this); + m_maskLabel = new QLabel(this); + m_gateWayLabel = new QLabel(this); + m_dnsServerLabel = new QLabel(this); + m_searchDomainLabel = new QLabel(this); + + m_ipv6ConfigCombox =new QComboBox(this); + m_ipv6addressEdit = new QLineEdit(this); + m_netMaskEdit = new QLineEdit(this); + m_gateWayEdit = new QLineEdit(this); + m_dnsServerEdit = new QLineEdit(this); + m_searchDomainEdit = new QLineEdit(this); + + + /**********布局**********/ + QFormLayout *mainLayout = new QFormLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setHorizontalSpacing(HLAYOUT_SPACING); + mainLayout->setVerticalSpacing(VLAYOUT_SPACING); + mainLayout->addRow(m_configLabel, m_ipv6ConfigCombox); + mainLayout->addRow(m_addressLabel, m_ipv6addressEdit); + mainLayout->addRow(m_maskLabel, m_netMaskEdit); + mainLayout->addRow(m_gateWayLabel, m_gateWayEdit); + mainLayout->addRow(m_dnsServerLabel, m_dnsServerEdit); + mainLayout->addRow(m_searchDomainLabel, m_searchDomainEdit); + + + /**********控件显示**********/ + m_configLabel->setText(tr("IPv6 Config")); + m_addressLabel->setText(tr("Address")); + m_maskLabel->setText(tr("Netmask")); + m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsServerLabel->setText(tr("DNS Server")); + m_searchDomainLabel->setText(tr("Search Domain")); //搜索域 + + m_ipv6ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" + m_ipv6ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" + + // IP的正则格式限制 + QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + QRegExpValidator *ipv6ExpVal = new QRegExpValidator(ipv6_rx, this); + m_ipv6addressEdit->setValidator(ipv6ExpVal); + m_gateWayEdit->setValidator(ipv6ExpVal); + m_dnsServerEdit->setValidator(ipv6ExpVal); + + QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b"); + m_netMaskEdit->setValidator(new QRegExpValidator(prefix_rx,this)); +} + +void VpnIpv6Page::initConnect() +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + setManualEnabled(false); + } else if (m_ipv6ConfigCombox->currentIndex() == MANUAL_CONFIG) { + setManualEnabled(true); + } + connect(m_ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(onConfigChanged(int))); + connect(m_ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_ipv6addressEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_netMaskEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_gateWayEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_dnsServerEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_searchDomainEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); +} + +void VpnIpv6Page::setManualEnabled(bool state) +{ + m_addressLabel->setEnabled(state); + m_maskLabel->setEnabled(state); + m_gateWayLabel->setEnabled(state); + m_ipv6addressEdit->setEnabled(state); + m_netMaskEdit->setEnabled(state); + m_gateWayEdit->setEnabled(state); +} + +bool VpnIpv6Page::getIpv6EditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnIpv6Page::checkConfirmBtnIsEnabled() +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (m_ipv6addressEdit->text().isEmpty() || !getIpv6EditState(m_ipv6addressEdit->text())) { + qDebug() << "IPv6 address empty or invalid"; + return false; + } + + if (m_netMaskEdit->text().isEmpty()) { + qDebug() << "IPv6 netMask empty or invalid"; + return false; + } + if (m_gateWayEdit->text().isEmpty() || !getIpv6EditState(m_gateWayEdit->text())) { + qDebug() << "IPv6 gateway empty or invalid"; + return false; + } + } + return true; +} + +void VpnIpv6Page::setEnableOfConfirmBtn() +{ + Q_EMIT setIpv6PageState(checkConfirmBtnIsEnabled()); +} + +void VpnIpv6Page::onConfigChanged(int index) +{ + if (index == AUTO_CONFIG) { + m_ipv6addressEdit->clear(); + m_netMaskEdit->clear(); + m_gateWayEdit->clear(); + setManualEnabled(false); + } else if (index == MANUAL_CONFIG) { + setManualEnabled(true); + } +} diff --git a/src-vpn/frontend/vpndetails/vpnipv6page.h b/src-vpn/frontend/vpndetails/vpnipv6page.h new file mode 100644 index 00000000..21debab3 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv6page.h @@ -0,0 +1,57 @@ +#ifndef VPNIPV6PAGE_H +#define VPNIPV6PAGE_H + +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +class VpnIpv6Page : public QFrame +{ + Q_OBJECT +public: + VpnIpv6Page(QWidget *parent = nullptr); + ~VpnIpv6Page() = default; + + void setVpnIpv6Info(const KyVpnConfig &vpnInfo); + void setDns(const QString &firstDns); + void setSearchDomain(const QString &searchDomain); + bool checkIsChanged(const KyVpnConfig &vpnInfo); + + void updateVpnIpv6Info(KyVpnConfig &vpnInfo); + +private: + QLabel *m_configLabel; + QLabel *m_addressLabel; + QLabel *m_maskLabel; + QLabel *m_gateWayLabel; + QLabel *m_dnsServerLabel; + QLabel *m_searchDomainLabel; + + QComboBox *m_ipv6ConfigCombox; + QLineEdit *m_ipv6addressEdit; + QLineEdit *m_netMaskEdit; + QLineEdit *m_gateWayEdit; + QLineEdit *m_dnsServerEdit; + QLineEdit *m_searchDomainEdit; + + void initUI(); + void initConnect(); + void setManualEnabled(bool state); + + bool getIpv6EditState(QString text); + bool checkConfirmBtnIsEnabled(); + +private Q_SLOTS: + void setEnableOfConfirmBtn(); + void onConfigChanged(int index); + +Q_SIGNALS: + void setIpv6PageState(bool); +}; + +#endif // VPNIPV6PAGE_H diff --git a/src-vpn/translations/kylin-vpn_bo_CN.qm b/src-vpn/translations/kylin-vpn_bo_CN.qm new file mode 100644 index 00000000..be651eed --- /dev/null +++ b/src-vpn/translations/kylin-vpn_bo_CN.qm @@ -0,0 +1 @@ +VPN Server + + + VPN + + + + + Auto Connection + + + + + Confirm + + + + + Cancel + + vpnConfigPage @@ -90,7 +110,7 @@ - vpnDetail + VpnDetail @@ -113,29 +133,6 @@ - - vpnDetailPage - - - VPN - - - - - Auto Connection - - - - - Confirm - - - - - Cancel - - - vpnObject diff --git a/src-vpn/translations/kylin-vpn_zh_CN.qm b/src-vpn/translations/kylin-vpn_zh_CN.qm new file mode 100644 index 00000000..75c3ce3e Binary files /dev/null and b/src-vpn/translations/kylin-vpn_zh_CN.qm differ diff --git a/src-vpn/translations/kylin-vpn_zh_CN.ts b/src-vpn/translations/kylin-vpn_zh_CN.ts index d0afe821..29c04c79 100644 --- a/src-vpn/translations/kylin-vpn_zh_CN.ts +++ b/src-vpn/translations/kylin-vpn_zh_CN.ts @@ -756,6 +756,26 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a VPN Server 服务器地址 + + + VPN + + + + + Auto Connection + 自动连接 + + + + Confirm + 确定 + + + + Cancel + 取消 + vpnConfigPage @@ -765,7 +785,7 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a - vpnDetail + VpnDetail @@ -804,29 +824,6 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a 确定 - - vpnDetailPage - - - VPN - - - - - Auto Connection - 自动连接 - - - - Confirm - 确定 - - - - Cancel - 取消 - - vpnObject