From fb07cc161b4adc5bc250569599a7164af2d7caba Mon Sep 17 00:00:00 2001 From: kergoth Date: Mon, 14 Apr 2003 23:31:22 +0000 Subject: Add new wireless parser that uses the wireless-tools if-pre-up.d script to handle wireless configuration, as opposed to pcmcia-cs wireless.opts. This has a number of benefits. In addition to improving clarity, this means one can now configure their wireless non-pcmcia interfaces using networksettings. The only real question is, how to handle the fact that its largely useless without the if-pre-up.d script? I'll adapt the existing wlanimp.(cpp|h) to the new .ui, and leave it as a compiletime selection for now. --- (limited to 'noncore/settings/networksettings') diff --git a/noncore/settings/networksettings/wlan/wlan.pro b/noncore/settings/networksettings/wlan/wlan.pro index f193bcc..9ddc154 100644 --- a/noncore/settings/networksettings/wlan/wlan.pro +++ b/noncore/settings/networksettings/wlan/wlan.pro @@ -2,8 +2,8 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/plugins/networksettings -HEADERS = wlanimp.h infoimp.h wlanmodule.h wextensions.h -SOURCES = wlanimp.cpp infoimp.cpp wlanmodule.cpp wextensions.cpp +HEADERS = infoimp.h wlanmodule.h wextensions.h +SOURCES = infoimp.cpp wlanmodule.cpp wextensions.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../interfaces/ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -L../interfaces/ -linterfaces @@ -11,6 +11,16 @@ INTERFACES = wlan.ui info.ui TARGET = wlanplugin VERSION = 1.0.0 +#CONFIG += wirelessopts +wirelessopts { + HEADERS += wlanimp.h + SOURCES += wlanimp.cpp +} + +! wirelessopts { + HEADERS += wlanimp2.h + SOURCES += wlanimp2.cpp +} include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings/wlan/wlan.ui b/noncore/settings/networksettings/wlan/wlan.ui index 744c559..e7c8dbb 100644 --- a/noncore/settings/networksettings/wlan/wlan.ui +++ b/noncore/settings/networksettings/wlan/wlan.ui @@ -11,13 +11,13 @@ 0 0 - 239 - 277 + 255 + 299 caption - Wireless LAN Setting + Wireless Configuration sizeGripEnabled @@ -55,176 +55,327 @@ title General - + + + name + Spacer31 + - margin - 11 + orientation + Vertical - spacing - 6 + sizeType + Expanding - - QCheckBox - - name - essAny - - + + sizeHint + + 20 + 20 + + + + + QLabel + + name + modeLabel + + + enabled + true + + + geometry + + 11 + 11 + 84 + 29 + + + + sizePolicy + + 1 + 1 + + + + text + Mode + + + + QLabel + + name + essidLabel + + + enabled + true + + + geometry + + 11 + 46 + 84 + 29 + + + + sizePolicy + + 1 + 1 + + + + text + ESS-ID + + + + QSpinBox + + name + networkChannel + + + enabled + false + + + geometry + + 146 + 139 + 58 + 25 + + + + maxValue + 15 + + + minValue + 1 + + + value + 1 + + + + QLineEdit + + name + macEdit + + + enabled + false + + + geometry + + 56 + 108 + 182 + 25 + + + + sizePolicy + + 5 + 1 + + + + + QLabel + + name + macLabel + + + enabled + false + + + geometry + + 11 + 108 + 39 + 25 + + + + text + MAC + + + + QCheckBox + + name + specifyAp + + + geometry + + 11 + 81 + 227 + 21 + + + + text + Specify &Access Point + + + + QCheckBox + + name + specifyChan + + + geometry + + 11 + 141 + 129 + 21 + + + + text + Specify &Channel + + + + + name + Spacer10 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QComboBox + + text - &Specify Access Point + Auto - - - QGroupBox - - name - GroupBox1 - - - enabled - false - - - title - Specific &Access Point Settings - - - - margin - 11 - - - spacing - 6 - - - QLabel - - name - TextLabel1 - - - text - ESS-ID - - - - QLabel - - name - TextLabel2 - - - text - Network Type - - - - QLineEdit - - name - essSpecificLineEdit - - - - QComboBox - - - text - Infrastructure - - - - - text - Ad-Hoc - - - - name - networkType - - - - QLabel - - name - channelLabel - - - text - Channel - - - - QSpinBox - - name - networkChannel - - - enabled - false - - - maxValue - 15 - - - minValue - 1 - - - value - 6 - - - - - name - Spacer4 - - - orientation - Horizontal - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - - + + - name - Spacer31 - - - orientation - Vertical + text + Managed - - sizeType - Expanding + + + + text + Ad-Hoc + + + name + mode + + + enabled + true + + + geometry + + 101 + 11 + 103 + 29 + + + + sizePolicy + + 1 + 0 + + + + + QComboBox + - sizeHint - - 20 - 20 - + text + any - - + + + name + essid + + + geometry + + 101 + 46 + 103 + 29 + + + + sizePolicy + + 7 + 0 + + + + editable + true + + + currentItem + 0 + + + sizeLimit + 5 + + + autoCompletion + true + + + duplicatesEnabled + false + + QWidget @@ -236,7 +387,7 @@ title Encryption - + margin 11 @@ -245,69 +396,39 @@ spacing 6 - - QCheckBox - + + name - wepEnabled + Spacer30 - text - &Enable WEP + orientation + Vertical - - - QButtonGroup - name - ButtonGroup43 + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + QCheckBox - enabled - false + name + wepEnabled - title - &Authentication Type + text + &Enable Encryption - - - margin - 11 - - - spacing - 6 - - - QRadioButton - - name - authOpen - - - text - &Open System - - - checked - true - - - - QRadioButton - - name - authShared - - - text - &Shared Key - - - - + QButtonGroup name @@ -382,7 +503,7 @@ text - Key 1 + Key &1 checked @@ -397,7 +518,7 @@ text - Key 2 + Key &2 @@ -408,7 +529,7 @@ text - Key 3 + Key &3 @@ -419,42 +540,96 @@ text - Key 4 + Key &4 - - + + QButtonGroup + name - Spacer30 + NonEncButtonGroup - orientation - Vertical + enabled + false - sizeType - Expanding + title + Non-encrypted Packets - - sizeHint - - 20 - 20 - + + radioButtonExclusive + true - - + + + margin + 11 + + + spacing + 6 + + + QRadioButton + + name + acceptNonEnc + + + text + &Accept + + + checked + true + + + buttonGroupId + 0 + + + + QRadioButton + + name + rejectNonEnc + + + text + &Reject + + + buttonGroupId + 1 + + + + + - wepEnabled + specifyAp + toggled(bool) + macLabel + setEnabled(bool) + + + specifyAp + toggled(bool) + macEdit + setEnabled(bool) + + + specifyChan toggled(bool) - ButtonGroup43 + networkChannel setEnabled(bool) @@ -464,21 +639,15 @@ setEnabled(bool) - essAny + wepEnabled toggled(bool) - GroupBox1 + NonEncButtonGroup setEnabled(bool) tabWidget - essAny - essSpecificLineEdit - networkType - networkChannel wepEnabled - authOpen - authShared keyRadio0 keyLineEdit0 keyRadio1 @@ -487,5 +656,12 @@ keyLineEdit2 keyRadio3 keyLineEdit3 + acceptNonEnc + mode + essid + specifyAp + macEdit + specifyChan + networkChannel diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp new file mode 100644 index 0000000..01c9668 --- a/dev/null +++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp @@ -0,0 +1,266 @@ +#include "wlanimp2.h" +#include "interfacesetupimp.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef QWS + #include +#else + #define OProcess KProcess + #include +#endif + +#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" +#define PREUP "/etc/netwrok/if-pre-up.d/wireless-tools" + +/** + * Constructor, read in the wireless.opts file for parsing later. + */ +WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), currentProfile("*"), interface(i) { + interfaces = new Interfaces; + interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); + tabWidget->insertTab(interfaceSetup, "TCP/IP"); + + // Check sanity - the existance of the wireless-tools if-pre-up script + QFile file(QString(PREUP)); + if (file.exists()) { + qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); + } +} + +WLANImp::~WLANImp() { + delete interfaces; +} + +/** + * Change the profile for both wireless settings and network settings. + */ +void WLANImp::setProfile(const QString &profile){ + interfaceSetup->setProfile(profile); + parseOpts(); +} + +void WLANImp::parseOpts() { + bool error; + QString opt; + + if (! interfaces->isInterfaceSet()) + return; + + + opt = interfaces->getInterfaceOption("wireless_essid", error); + if(opt == "any" || opt == "off" || opt.isNull()){ + essid->setEditText("any"); + } else { + essid->setEditText(opt); + } + + opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); + if (opt == "Auto") { + mode->setCurrentItem(0); + } else if (opt == "Ad-Hoc") { + mode->setCurrentItem(2); + } else { + // Managed/Infrastructure mode + mode->setCurrentItem(1); + } + + opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); + if (! opt.isNull()) { + specifyAp->setChecked(true); + macEdit->setText(opt); + } + + opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); + if (! opt.isNull()) { + specifyChan->setChecked(true); + networkChannel->setValue(opt.toInt()); + } + + opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); + if (opt.isNull()) + opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); + parseKeyStr(opt); +} + +void WLANImp::parseKeyStr(QString keystr) { + int loc = 0; + int index = 1; + QString key; + QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); + int enc = -1; // encryption state + + for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { + if ((*it).left(3) == "off") { + // encryption disabled + enc = 0; + } else if ((*it).left(2) == "on") { + // encryption enabled + enc = 1; + } else if ((*it).left(4) == "open") { + // open mode, accept non encrypted packets + acceptNonEnc->setChecked(true); + } else if ((*it).left(10) == "restricted") { + // restricted mode, only accept encrypted packets + rejectNonEnc->setChecked(true); + } else if ((*it).left(3) == "key") { + // new set of options + } else if ((*it).left(1) == "[") { + index = (*it).mid(1, 1).toInt(); + // switch current key to index + switch (index) { + case 1: + keyRadio0->setChecked(true); + break; + case 2: + keyRadio1->setChecked(true); + break; + case 3: + keyRadio2->setChecked(true); + break; + case 4: + keyRadio3->setChecked(true); + break; + } + } else { + // key + key = (*it); + } + if (! key.isNull()) { + if (enc == -1) + enc = 1; + QStringList::Iterator next = ++it; + if (it == keys.end()) { + break; + } + if ((*(next)).left(1) == "[") { + // set key at index + index = (*(next)).mid(1, 1).toInt(); + } else { + index = 1; + } + switch (index) { + case 1: + keyLineEdit0->setText(key); + break; + case 2: + keyLineEdit1->setText(key); + break; + case 3: + keyLineEdit2->setText(key); + break; + case 4: + keyLineEdit3->setText(key); + break; + } + key = QString::null; + } + } + if (enc == 1) { + wepEnabled->setChecked(true); + } else { + wepEnabled->setChecked(false); + } +} + +/** + * Check to see if the current config is valid + * Save interfaces + */ +void WLANImp::accept() { + if (wepEnabled->isChecked()) { + if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || + (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || + (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || + (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { + QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); + return; + } + } + + if (essid->currentText().isEmpty()) { + QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); + return; + } + + if (specifyAp->isChecked() && macEdit->text().isEmpty()) { + QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); + return; + } + + // Try to save the interfaces settings. + writeOpts(); + + // Close out the dialog + QDialog::accept(); +} + +void WLANImp::writeOpts() { + bool error = false; + + interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); + interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); + + if (specifyAp->isChecked()) { + interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); + } else { + interfaces->removeInterfaceOption(QString("wireless_ap")); + } + + if (specifyChan->isChecked()) { + interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); + } else { + interfaces->removeInterfaceOption(QString("wireless_channel")); + } + + if (wepEnabled->isChecked()) { + QStringList keyList; + + if (! keyLineEdit0->text().isNull()) { + keyList += keyLineEdit0->text(); + keyList += "[1]"; + } else if (! keyLineEdit1->text().isNull()) { + keyList += keyLineEdit1->text(); + keyList += "[2]"; + } else if (! keyLineEdit2->text().isNull()) { + keyList += keyLineEdit2->text(); + keyList += "[3]"; + } else if (! keyLineEdit3->text().isNull()) { + keyList += keyLineEdit3->text(); + keyList += "[4]"; + } + if (acceptNonEnc->isChecked()) { + keyList += "open"; + } else { + keyList += "restricted"; + } + + keyList += "key"; + if (keyRadio0->isChecked()) { + keyList += "[1]"; + } else if (keyRadio1->isChecked()) { + keyList += "[2]"; + } else if (keyRadio2->isChecked()) { + keyList += "[3]"; + } else if (keyRadio3->isChecked()) { + keyList += "[4]"; + } + interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); + } else { + interfaces->removeInterfaceOption(QString("wireless_key")); + } + interfaces->removeInterfaceOption(QString("wireless_enc")); + + if(!interfaceSetup->saveChanges()) + return; +} diff --git a/noncore/settings/networksettings/wlan/wlanimp2.h b/noncore/settings/networksettings/wlan/wlanimp2.h new file mode 100644 index 0000000..992d09a --- a/dev/null +++ b/noncore/settings/networksettings/wlan/wlanimp2.h @@ -0,0 +1,37 @@ +#ifndef WLANIMP_H +#define WLANIMP_H + +#include "wlan.h" +#include "interfaces.h" +#include + +class InterfaceSetupImp; +class Interface; +class Config; + +class WLANImp : public WLAN { + Q_OBJECT + +public: + WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); + ~WLANImp(); + void setProfile(const QString &profile); + +protected: + void accept(); + +private: + void parseOpts(); + void writeOpts(); + + void parseKeyStr(QString keystr); + + InterfaceSetupImp *interfaceSetup; + Interfaces *interfaces; + Interface *interface; + + QString currentProfile; +}; + +#endif + -- cgit v0.9.0.2