Fix a bug with the list editor, enable modifying IPv4 addresses, don't use QProcess to wipe a cloned MAC address

main
Aaron Rainbolt 1 year ago
parent e8ffda5a29
commit 652ade8704

@ -1,7 +1,6 @@
#include "connectionsettingsengine.h" #include "connectionsettingsengine.h"
#include <QDebug> #include <QDebug>
bool ConnectionSettingsEngine::wipeClonedMacAddress = false;
QString ConnectionSettingsEngine::targetConnUuidStr = QString(); QString ConnectionSettingsEngine::targetConnUuidStr = QString();
/* /*
@ -369,7 +368,8 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings) void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings)
{ {
// Contains adapted code from plasma-nm // Contains adapted code from plasma-nm
wipeClonedMacAddress = false; bool wipeClonedMacAddress = false;
bool wipeManualIpv4Addresses = false;
bool ensure802_1xSettings = false; bool ensure802_1xSettings = false;
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr); NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr);
NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings(); NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings();
@ -466,7 +466,12 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
} }
if (settings["ipv4AddressList"].isValid()) { if (settings["ipv4AddressList"].isValid()) {
connIpv4Setting->setAddresses(settings["ipv4AddressList"].value<QList<NetworkManager::IpAddress>>()); QList<NetworkManager::IpAddress> ipv4AddrList = settings["ipv4AddressList"].value<QList<NetworkManager::IpAddress>>();
if (!ipv4AddrList.isEmpty()) {
connIpv4Setting->setAddresses(ipv4AddrList);
} else {
wipeManualIpv4Addresses = true;
}
} }
if (settings["ipv4Required"].isValid()) { if (settings["ipv4Required"].isValid()) {
@ -683,6 +688,29 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
if (ensure802_1xSettings) { if (ensure802_1xSettings) {
connSettingsMap.insert("802-1x", secSetting.toMap()); connSettingsMap.insert("802-1x", secSetting.toMap());
} }
if (wipeClonedMacAddress) {
QVariantMap ethSettingsMap = connSettingsMap.value("802-3-ethernet");
if (!ethSettingsMap.isEmpty()) {
ethSettingsMap.remove("cloned-mac-address");
ethSettingsMap.remove("assigned-mac-address");
connSettingsMap.remove("802-3-ethernet");
connSettingsMap.insert("802-3-ethernet", ethSettingsMap);
}
// TODO: Handle WiFi here
}
if (wipeManualIpv4Addresses) {
QVariantMap ipv4SettingsMap = connSettingsMap.value("ipv4");
if (!ipv4SettingsMap.isEmpty()) {
qWarning() << "made it";
ipv4SettingsMap.remove("addresses");
ipv4SettingsMap.remove("address-data");
ipv4SettingsMap.remove("gateway");
connSettingsMap.remove("ipv4");
connSettingsMap.insert("ipv4", ipv4SettingsMap);
}
}
qWarning() << connSettingsMap;
// TODO: Do something to surpress app exit here
QDBusPendingReply<> reply = conn->update(connSettingsMap); QDBusPendingReply<> reply = conn->update(connSettingsMap);
auto watcher = new QDBusPendingCallWatcher(reply); auto watcher = new QDBusPendingCallWatcher(reply);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, saveReplyFinished); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, saveReplyFinished);
@ -690,24 +718,7 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
void ConnectionSettingsEngine::saveReplyFinished() void ConnectionSettingsEngine::saveReplyFinished()
{ {
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(targetConnUuidStr); // TODO: Do something to unsupress app exit here
NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings();
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
NetworkManager::WirelessSetting::Ptr connWirelessSetting = connSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
if (wipeClonedMacAddress) {
// Wiping a MAC address with NetworkManagerQt is surprisingly difficult, so we do it with nmcli instead.
QProcess clonedMacWiper;
clonedMacWiper.setProgram("bash");
if (!connWiredSetting.isNull()) {
clonedMacWiper.setArguments(QStringList() << QString("-c") << QString("nmcli connection modify %1 ethernet.cloned-mac-address \"\"").arg(conn->uuid()));
clonedMacWiper.start();
clonedMacWiper.waitForFinished();
} else if (!connWirelessSetting.isNull()) {
clonedMacWiper.setArguments(QStringList() << QString("-c") << QString("nmcli connection modify %1 wifi.cloned-mac-address \"\"").arg(conn->uuid()));
clonedMacWiper.start();
clonedMacWiper.waitForFinished();
}
}
} }
QString ConnectionSettingsEngine::userName() QString ConnectionSettingsEngine::userName()

@ -112,7 +112,6 @@ private slots:
private: private:
static QString userName(); static QString userName();
static QString targetConnUuidStr; static QString targetConnUuidStr;
static bool wipeClonedMacAddress;
}; };
#endif // CONNECTIONSETTINGSENGINE_H #endif // CONNECTIONSETTINGSENGINE_H

@ -9,6 +9,8 @@ Ipv4SettingsTab::Ipv4SettingsTab(QWidget *parent) :
ui->methodComboBox->addItems(QStringList() << tr("Automatic") << tr("Automatic (address-only)") << tr("Link-Local") << tr("Manual") << tr("Shared to other computers") << tr("Disabled")); ui->methodComboBox->addItems(QStringList() << tr("Automatic") << tr("Automatic (address-only)") << tr("Link-Local") << tr("Manual") << tr("Shared to other computers") << tr("Disabled"));
connect(ui->editDnsServersButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onEditDnsServersButtonClicked); connect(ui->editDnsServersButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onEditDnsServersButtonClicked);
connect(ui->editSearchDomainsButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onEditSearchDomainsButtonClicked); connect(ui->editSearchDomainsButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onEditSearchDomainsButtonClicked);
connect(ui->manualIpv4ConfigurationAddButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onManualIpv4ConfigurationAddButtonClicked);
connect(ui->manualIpv4ConfigurationRemoveButton, &QPushButton::clicked, this, &Ipv4SettingsTab::onManualIpv4ConfigurationRemoveButtonClicked);
} }
Ipv4SettingsTab::~Ipv4SettingsTab() Ipv4SettingsTab::~Ipv4SettingsTab()
@ -123,3 +125,14 @@ void Ipv4SettingsTab::onEditSearchDomainsButtonClicked()
led.exec(); led.exec();
ui->searchDomainsLineEdit->setText(led.list()); ui->searchDomainsLineEdit->setText(led.list());
} }
void Ipv4SettingsTab::onManualIpv4ConfigurationAddButtonClicked()
{
int newRow = ui->manualIpv4ConfigurationTable->rowCount();
ui->manualIpv4ConfigurationTable->insertRow(newRow);
}
void Ipv4SettingsTab::onManualIpv4ConfigurationRemoveButtonClicked()
{
ui->manualIpv4ConfigurationTable->removeRow(ui->manualIpv4ConfigurationTable->currentRow());
}

@ -24,6 +24,8 @@ public:
private slots: private slots:
void onEditDnsServersButtonClicked(); void onEditDnsServersButtonClicked();
void onEditSearchDomainsButtonClicked(); void onEditSearchDomainsButtonClicked();
void onManualIpv4ConfigurationAddButtonClicked();
void onManualIpv4ConfigurationRemoveButtonClicked();
private: private:
Ui::Ipv4SettingsTab *ui; Ui::Ipv4SettingsTab *ui;

@ -8,7 +8,10 @@ ListEditorDialog::ListEditorDialog(QWidget *parent, QString listStr, QChar separ
ui->setupUi(this); ui->setupUi(this);
QStringList itemList = listStr.split(separator); QStringList itemList = listStr.split(separator);
for (int i = 0;i < itemList.count();i++) { for (int i = 0;i < itemList.count();i++) {
ui->itemListWidget->addItem(itemList[i]); QString currentStr = itemList[i].trimmed();
if (currentStr.length() != 0) {
ui->itemListWidget->addItem(currentStr);
}
} }
origListStr = listStr; origListStr = listStr;
listModified = false; listModified = false;

Loading…
Cancel
Save