Пример #1
0
void Handler::activateConnection(const QString& connection, const QString& device, const QString& specificObject)
{
    NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection);

    if (!con) {
        qCWarning(NM) << "Not possible to activate this connection";
        return;
    }

    if (con->settings()->connectionType() == NetworkManager::ConnectionSettings::Vpn) {
        NetworkManager::VpnSetting::Ptr vpnSetting = con->settings()->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>();
        if (vpnSetting) {
//            qCDebug(NM) << "Checking VPN" << con->name() << "type:" << vpnSetting->serviceType();
#if 0
            // get the list of supported VPN service types
            const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin",
                                                                              QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(vpnSetting->serviceType()));
            if (services.isEmpty()) {
                qCWarning(NM) << "VPN" << vpnSetting->serviceType() << "not found, skipping";
                KNotification *notification = new KNotification("MissingVpnPlugin", KNotification::CloseOnTimeout, this);
                notification->setComponentName("networkmanagement");
                notification->setTitle(con->name());
                notification->setText(i18n("Missing VPN plugin"));
                notification->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeHuge));
                notification->sendEvent();
                return;
            }
#endif
        }
    }

#if WITH_MODEMMANAGER_SUPPORT
    if (con->settings()->connectionType() == NetworkManager::ConnectionSettings::Gsm) {
        NetworkManager::ModemDevice::Ptr nmModemDevice = NetworkManager::findNetworkInterface(device).objectCast<NetworkManager::ModemDevice>();
        if (nmModemDevice) {
            ModemManager::ModemDevice::Ptr mmModemDevice = ModemManager::findModemDevice(nmModemDevice->udi());
            if (mmModemDevice) {
                ModemManager::Modem::Ptr modem = mmModemDevice->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
                NetworkManager::GsmSetting::Ptr gsmSetting = con->settings()->setting(NetworkManager::Setting::Gsm).staticCast<NetworkManager::GsmSetting>();
                if (gsmSetting && gsmSetting->pinFlags() == NetworkManager::Setting::NotSaved &&
                    modem && modem->unlockRequired() > MM_MODEM_LOCK_NONE) {
                    QDBusInterface managerIface("org.kde.plasmanetworkmanagement", "/org/kde/plasmanetworkmanagement", "org.kde.plasmanetworkmanagement", QDBusConnection::sessionBus(), this);
                    managerIface.call("unlockModem", mmModemDevice->uni());
                    connect(modem.data(), &ModemManager::Modem::unlockRequiredChanged, this, &Handler::unlockRequiredChanged);
                    m_tmpConnectionPath = connection;
                    m_tmpDevicePath = device;
                    m_tmpSpecificPath = specificObject;
                    return;
                }
            }
        }
    }
#endif

    QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(connection, device, specificObject);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
    watcher->setProperty("action", Handler::ActivateConnection);
    watcher->setProperty("connection", con->name());
    connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished);
}
Пример #2
0
void L2tpWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting)
{
    NetworkManager::VpnSetting::Ptr vpnSetting = setting.staticCast<NetworkManager::VpnSetting>();

    if (vpnSetting) {
        const NMStringMap secrets = vpnSetting->secrets();
        const QString userPassword = secrets.value(NM_L2TP_KEY_PASSWORD);
        if (!userPassword.isEmpty()) {
            m_ui->password->setText(userPassword);
        }
    }
}
VpnProxySection::VpnProxySection(NetworkManager::VpnSetting::Ptr vpnSetting, QFrame *parent)
    : AbstractSection(tr("VPN Proxy"), parent),
      m_vpnSetting(vpnSetting),
    m_proxyTypeChooser(new ComboBoxWidget(this)),
    m_server(new LineEditWidget(this)),
    m_port(new SpinBoxWidget(this)),
    m_retry(new SwitchWidget(this)),
    m_userName(new LineEditWidget(this)),
    m_password(new PasswdEditWidget(this))
{
    m_dataMap = vpnSetting->data();
    m_secretMap = vpnSetting->secrets();

    initStrMaps();
    initUI();
    initConnection();

    onProxyTypeChanged(m_currentProxyType);
}
Пример #4
0
void PasswordDialog::setupVpnUi(const ConnectionSettings &connectionSettings)
{
    NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings.setting(Setting::Vpn).dynamicCast<VpnSetting>();
    if (!vpnSetting) {
        qCWarning(PLASMA_NM) << "Missing VPN setting!";
        m_hasError = true;
        m_error = SecretAgent::InternalError;
        m_errorMessage = QLatin1String("VPN settings are missing");
    } else {
        VpnUiPlugin *vpnUiPlugin;
        QString error;
        const QString serviceType = vpnSetting->serviceType();
        // qCDebug(PLASMA_NM) << "Agent loading VPN plugin" << serviceType << "from DBUS" << calledFromDBus();
        // vpnSetting->printSetting();
        vpnUiPlugin = KServiceTypeTrader::createInstanceFromQuery<VpnUiPlugin>(QLatin1String("PlasmaNetworkManagement/VpnUiPlugin"),
                                                                               QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType),
                                                                               this, QVariantList(), &error);
        if (vpnUiPlugin && error.isEmpty()) {
            const QString shortName = serviceType.section('.', -1);
            setWindowTitle(i18n("VPN secrets (%1)", shortName));
            vpnWidget = vpnUiPlugin->askUser(vpnSetting, this);
            QDialogButtonBox * box;
            if (shortName != QLatin1String("openconnect")) {
                box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
                connect(box, &QDialogButtonBox::accepted, this, &PasswordDialog::accept);
            } else {
                box = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this);
            }
            connect(box, &QDialogButtonBox::rejected, this, &PasswordDialog::reject);
            QVBoxLayout * layout = new QVBoxLayout(this);
            layout->addWidget(vpnWidget);
            layout->addWidget(box);
            setLayout(layout);
        } else {
            qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType;
            m_hasError = true;
            m_error = SecretAgent::InternalError;
            m_errorMessage = error;
        }
    }
}
Пример #5
0
L2tpWidget::L2tpWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget* parent, Qt::WindowFlags f)
    : SettingWidget(setting, parent, f)
    , m_ui(new Ui::L2tpWidget)
    , m_setting(setting)
{
    qDBusRegisterMetaType<NMStringMap>();

    m_ui->setupUi(this);

    m_ui->password->setPasswordOptionsEnabled(true);

    connect(m_ui->btnIPSecSettings, &QPushButton::clicked, this, &L2tpWidget::showAdvanced);
    connect(m_ui->btnPPPSettings, &QPushButton::clicked, this, &L2tpWidget::showPpp);

    connect(m_ui->gateway, &QLineEdit::textChanged, this, &L2tpWidget::slotWidgetChanged);
    connect(m_ui->cbUseCertificate, &QCheckBox::stateChanged, this, &L2tpWidget::certStateChanged);

    KAcceleratorManager::manage(this);

    if (setting && !setting->isNull()) {
        loadConfig(setting);
    }
}
Пример #6
0
QVariant EditorIdentityModel::data(const QModelIndex& index, int role) const
{
    const QModelIndex sourceIndex = sourceModel()->index(index.row(), 0);
    const QString connectionName = sourceModel()->data(sourceIndex, NetworkModel::NameRole).toString();
    const QString lastUsed = sourceModel()->data(sourceIndex, NetworkModel::LastUsedDateOnlyRole).toString();
    const bool isActivated = (NetworkManager::ActiveConnection::State) sourceModel()->data(sourceIndex, NetworkModel::ConnectionStateRole).toInt()
                             == NetworkManager::ActiveConnection::Activated;
    const bool isActivating = (NetworkManager::ActiveConnection::State) sourceModel()->data(sourceIndex, NetworkModel::ConnectionStateRole).toInt()
                             == NetworkManager::ActiveConnection::Activating;
    NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(sourceModel()->data(sourceIndex, NetworkModel::TypeRole).toInt());

    NetworkManager::ConnectionSettings::Ptr settings;
    NetworkManager::VpnSetting::Ptr vpnSetting ;
    if (type == NetworkManager::ConnectionSettings::Vpn) {
        settings = NetworkManager::findConnection(sourceModel()->data(sourceIndex, NetworkModel::ConnectionPathRole).toString())->settings();
        if (settings) {
            vpnSetting = settings->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>();
        }
    }

    QString tooltip;
    const QString iconName = UiUtils::iconAndTitleForConnectionSettingsType(type, tooltip);
    const int column = index.column();

    if (role == Qt::DisplayRole) {
        switch (column) {
        case 0:
            if (type == NetworkManager::ConnectionSettings::Infiniband ||
                type == NetworkManager::ConnectionSettings::Bond ||
                type == NetworkManager::ConnectionSettings::Bridge ||
#if NM_CHECK_VERSION(0, 9, 10)
                type == NetworkManager::ConnectionSettings::Team ||
#endif
                type == NetworkManager::ConnectionSettings::Vlan) {
                return QString(connectionName + " (" + NetworkManager::ConnectionSettings::typeAsString(type) + ")");
            }
            return connectionName;
        case 1:
            if (type == NetworkManager::ConnectionSettings::Vpn && vpnSetting) {
                return QString("%1 (%2)").arg(tooltip).arg(vpnSetting->serviceType().section('.', -1));
            }
            return tooltip;
        case 2:
            return lastUsed;
        }
    } else if (role == Qt::DecorationRole) {
        if (column == 0) {
            return QIcon::fromTheme(iconName);
        }
    } else if (role == Qt::ToolTipRole) {
        if (column == 0)
            return tooltip;
    } else if (role == Qt::FontRole) {
        if (column == 0 && isActivated) {
            QFont f;
            f.setBold(true);
            return f;
        } else if (column == 0 && isActivating) {
            QFont f;
            f.setItalic(true);
            return f;
        }
    } else {
        return sourceModel()->data(index, role);
    }

    return QVariant();
}
Пример #7
0
void L2tpPPPWidget::loadConfig(const NetworkManager::VpnSetting::Ptr &setting)
{
    // General settings
    const NMStringMap dataMap = setting->data();

    // Authentication options
    const QString yesString = QLatin1String("yes");
    bool refuse_pap = (dataMap[NM_L2TP_KEY_REFUSE_PAP] == yesString);
    bool refuse_chap = (dataMap[NM_L2TP_KEY_REFUSE_CHAP] == yesString);
    bool refuse_mschap = (dataMap[NM_L2TP_KEY_REFUSE_MSCHAP] == yesString);
    bool refuse_mschapv2 = (dataMap[NM_L2TP_KEY_REFUSE_MSCHAPV2] == yesString);
    bool refuse_eap = (dataMap[NM_L2TP_KEY_REFUSE_EAP] == yesString);

    QListWidgetItem * item = 0;
    item = m_ui->listWidget->item(0); // PAP
    item->setCheckState(refuse_pap ? Qt::Unchecked : Qt::Checked);
    item = m_ui->listWidget->item(1); // CHAP
    item->setCheckState(refuse_chap ? Qt::Unchecked : Qt::Checked);
    item = m_ui->listWidget->item(2); // MSCHAP
    item->setCheckState(refuse_mschap ? Qt::Unchecked : Qt::Checked);
    item = m_ui->listWidget->item(3); // MSCHAPv2
    item->setCheckState(refuse_mschapv2 ? Qt::Unchecked : Qt::Checked);
    item = m_ui->listWidget->item(4); // EAP
    item->setCheckState(refuse_eap ? Qt::Unchecked : Qt::Checked);

    // Cryptography and compression
    const bool mppe = (dataMap[NM_L2TP_KEY_REQUIRE_MPPE] == yesString);
    const bool mppe40 = (dataMap[NM_L2TP_KEY_REQUIRE_MPPE_40] == yesString);
    const bool mppe128 = (dataMap[NM_L2TP_KEY_REQUIRE_MPPE_128] == yesString);
    const bool mppe_stateful = (dataMap[NM_L2TP_KEY_MPPE_STATEFUL] == yesString);

    if (mppe || mppe40 || mppe128) { // If MPPE is use
        m_ui->gbMPPE->setChecked(mppe || mppe40 || mppe128);
        if (mppe128) {
            m_ui->cbMPPECrypto->setCurrentIndex(1); // 128 bit
        } else if (mppe40) {
            m_ui->cbMPPECrypto->setCurrentIndex(2); // 40 bit
        } else {
            m_ui->cbMPPECrypto->setCurrentIndex(0); // Any
        }
        m_ui->cbstatefulEncryption->setChecked(mppe_stateful);
    }

    const bool nobsd = (dataMap[NM_L2TP_KEY_NOBSDCOMP] == yesString);
    m_ui->cbBSD->setChecked(!nobsd);

    const bool nodeflate = (dataMap[NM_L2TP_KEY_NODEFLATE] == yesString);
    m_ui->cbdeflate->setChecked(!nodeflate);

    const bool novjcomp = (dataMap[NM_L2TP_KEY_NO_VJ_COMP] == yesString);
    m_ui->cbTCPheaders->setChecked(!novjcomp);

    const bool nopcomp = (dataMap[NM_L2TP_KEY_NO_PCOMP] == yesString);
    m_ui->cbCompressionNegotiation->setChecked(!nopcomp);

    const bool noaccomp = (dataMap[NM_L2TP_KEY_NO_ACCOMP] == yesString);
    m_ui->cbAddressControlCompression->setChecked(!noaccomp);

    // Echo
    const int lcp_echo_interval = QString(dataMap[NM_L2TP_KEY_LCP_ECHO_INTERVAL]).toInt();
    m_ui->cbsendEcho->setChecked(lcp_echo_interval > 0);

    if (dataMap.contains(QLatin1String(NM_L2TP_KEY_MTU))) {
        m_ui->sbMTU->setValue(QString(dataMap[NM_L2TP_KEY_MTU]).toInt());
    }

    if (dataMap.contains(QLatin1String(NM_L2TP_KEY_MTU))) {
        m_ui->sbMRU->setValue(QString(dataMap[NM_L2TP_KEY_MRU]).toInt());
    }
}