[PC-BSD Commits] r8091 - pcbsd/stable/pcbsd-netmanager/src/wificonfig
svn at pcbsd.org
svn at pcbsd.org
Tue Nov 30 09:03:42 PST 2010
Author: kris
Date: 2010-11-30 09:03:42 -0800 (Tue, 30 Nov 2010)
New Revision: 8091
Modified:
pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h
Log:
MFC changes to the wifi tool, which now can be told to not use lagg interface
Modified: pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
===================================================================
--- pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp 2010-11-30 16:56:32 UTC (rev 8090)
+++ pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp 2010-11-30 17:03:42 UTC (rev 8091)
@@ -9,15 +9,18 @@
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
-#include "wificonfigwidgetbase.h"
-#include "ui_wificonfigwidgetbase.h"
#include <QFile>
-#include <qtextstream.h>
-#include <unistd.h>
+#include <QSettings>
+#include <QTextStream>
+
#include <pcbsd-utils.h>
#include <pcbsd-netif.h>
+#include <unistd.h>
+#include "wificonfigwidgetbase.h"
+#include "ui_wificonfigwidgetbase.h"
+
void wificonfigwidgetbase::slotClose()
{
exit(0);
@@ -61,21 +64,15 @@
// If we have a valid wired device, clone the MAC of it to the wireless device
if ( ! wiredDev.isEmpty() )
{
- // Don't need to mark wired device as "up"
- //tmp = getValue( "/etc/rc.conf", "ifconfig_" + wiredDev + "=\"up\"", 1 );
- //if ( ! tmp.isEmpty() ) {
- // saveValue( "/etc/rc.conf", "ifconfig_" + wiredDev, "ifconfig_" + wiredDev + "=\"up\"", -1);
- //}
-
// If we are using wlan device
if ( ! DeviceNameParent.isEmpty() ) {
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
- saveValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
+ Utils::setConfFileValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
} else {
// On 7.x, no wlan0 device needed
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"ether ${ifconfig_" + dev + "##*ether }\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"ether ${ifconfig_" + dev + "##*ether }\"", -1);
}
}
@@ -94,19 +91,19 @@
// Check if we have a WPA setting, and put it in the right device slot
if ( config.indexOf("WPA") != -1 )
{
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
config = config.remove(0, config.indexOf("WPA") + 3);
config = config.simplified();
}
// Enable the lagg0 interface
- saveValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
wiredDev = getFirstWiredDevice();
if ( ! wiredDev.isEmpty() )
- saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
else
- saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
}
void wificonfigwidgetbase::slotApply()
@@ -121,7 +118,7 @@
// If the user disabled the device, do so now
if ( checkDisableWireless->isChecked() )
{
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
runCommand("ifconfig " + DeviceName + " down");
pushApply->setEnabled(FALSE);
return;
@@ -158,10 +155,16 @@
} else {
ifConfigLine="DHCP";
- }
+ }
-
- saveLaggLine(DeviceName, "WPA " + ifConfigLine);
+ // Check if we want to use the lagg interface
+ if ( usingLagg )
+ saveLaggLine(DeviceName, "WPA " + ifConfigLine);
+ else {
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, \
+ "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
+ }
// Now create the wpa_supplicant file based on saved configuration
QFile fileout( "/etc/wpa_supplicant.conf" );
@@ -282,12 +285,15 @@
DeviceName = Device;
// Center the dialog window
- QDesktopWidget *d = QApplication::desktop();
- move(d->width() / 3, d->height() / 4);
+ QDesktopWidget *d = QApplication::desktop();
+ move(d->width() / 3, d->height() / 4);
// Connect the slot to refresh
QTimer::singleShot(100, this, SLOT(slotFinishLoading() ) );
+ // Check if we are using the lagg0 device
+ QSettings settings("PCBSD");
+ usingLagg = settings.value("/pc-netmanager/useLagg", false).toBool();
}
@@ -328,159 +334,6 @@
return TRUE;
}
-
-void wificonfigwidgetbase::saveValue( QString File, QString oldKey, QString newKey, int occur )
-{
- // Lets the dev save a value into a specified config file. The occur value tells which occurance of "oldKey" to replace
- // If occur is set to -1, it will remove any duplicates of "oldKey"
-
-
- QString SavedFile;
-
- int found = 1;
- int wroteKey = 0;
-
- int firstLine = 0;
-
- if ( occur == -1 && newKey.isEmpty() )
- {
-
- }
-
-
- // Load the old file, find the oldKey, remove it and replace with newKey
- QFile file( File );
- if ( file.open( QIODevice::ReadOnly ) ) {
- QTextStream stream( &file );
- QString line;
- while ( !stream.atEnd() ) {
- line = stream.readLine(); // line of text excluding '\n'
-
- // If the KEY is found in the line and this matches the occurance that must be processed
- if ( line.indexOf(oldKey, 0) != -1 && wroteKey == 0 && found == occur && line.indexOf("#", 0) != 0)
- {
- if ( firstLine == 0) {
-
- SavedFile = SavedFile + newKey;
- found++;
- firstLine = 1;
- } else {
- SavedFile = SavedFile + "\n" + newKey;
- found++;
- wroteKey = 1;
- }
-
- // If the KEY is found, and we are just on wrong occurance, save it and continue to search
- } else if (line.indexOf(oldKey, 0) != -1 && occur != -1 && found != occur && line.indexOf("#", 0) != 0 ) {
- if ( firstLine == 0) {
- SavedFile = SavedFile + line ;
- firstLine = 1;
- } else {
- SavedFile = SavedFile + "\n" + line ;
- }
-
- found++;
-
-
- // if we are trying to remove the key, don't save it
- } else if (line.indexOf(oldKey, 0) != -1 && occur == -1 && newKey.isEmpty() && line.indexOf("#", 0) != 0 ) {
-
- // We just want one occurance of the key
- } else if (line.indexOf(oldKey, 0) != -1 && occur == -1 && ! newKey.isEmpty() && line.indexOf("#", 0) != 0 ) {
- if ( firstLine == 0) {
- SavedFile = SavedFile + newKey;
- found++;
- firstLine = 1;
- } else {
- SavedFile = SavedFile + "\n" + newKey;
- found++;
- wroteKey = 1;
- }
-
-
- // String not found at all
- } else {
-
- if ( firstLine == 0) {
- SavedFile = SavedFile + line ;
- firstLine = 1;
- } else {
- SavedFile = SavedFile + "\n" + line ;
- }
- }
-
-
-
- }
- // Didnt find the key? Write it!
- if ( wroteKey == 0 && ! newKey.isEmpty())
- {
- SavedFile = SavedFile + "\n" + newKey;
- }
-
- file.close();
- }
-
-
- // Save the new file
- QFile fileout( File );
- if ( fileout.open( QIODevice::WriteOnly ) ) {
- QTextStream streamout( &fileout );
- streamout << SavedFile;
- fileout.close();
- }
-
-}
-
-
-QString wificonfigwidgetbase::getValue( QString File, QString Key, int occur )
-{
-int found = 1;
-
- QFile file( File );
- if ( file.open( QIODevice::ReadOnly ) ) {
- QTextStream stream( &file );
- QString line;
- while ( !stream.atEnd() ) {
- line = stream.readLine(); // line of text excluding '\n'
-
- // If the KEY is found in the line, continue processing
- if ( line.indexOf(Key, 0) != -1 && line.indexOf("#", 0) != 0)
- {
- if ( found == occur) {
-
- line.remove(line.indexOf(Key, 0), Key.length());
-
-
- // Remove any quotes
- if ( line.indexOf('"') == 0 )
- {
- line = line.remove(0, 1);
- }
-
- if ( line.indexOf('"') != -1 )
- {
- line.truncate(line.lastIndexOf('"'));
- }
-
- return line;
-
- } else {
- found++;
- }
-
-
- }
-
-
-
- }
- file.close();
- }
-
- return "";
-}
-
// Slot which moves a SSID higher in the connection priority
void wificonfigwidgetbase::slotMoveUp()
{
@@ -1074,12 +927,19 @@
}
- textIP->setText(getIpForIdent("lagg0") );
- textNetmask->setText(getNetmaskForIdent( "lagg0" ) );
+ if ( usingLagg ) {
+ textIP->setText(getIpForIdent("lagg0") );
+ textNetmask->setText(getNetmaskForIdent( "lagg0" ) );
+ textGateway->setText(getGatewayForIdent( "lagg0" ) );
+ } else {
+ textIP->setText(getIpForIdent(DeviceName) );
+ textNetmask->setText(getNetmaskForIdent( DeviceName ) );
+ textGateway->setText(getGatewayForIdent( DeviceName ) );
+ }
+
textMac->setText(getMacForIdent( DeviceName ) );
textStatus->setText(getStatusForIdent( DeviceName ) );
textIPv6->setText(getIPv6ForIdent( DeviceName) );
- textGateway->setText(getGatewayForIdent( "lagg0" ) );
tmp = getMediaForIdent(DeviceName);
tmp.truncate(20);
textMedia->setText(tmp);
@@ -1107,7 +967,11 @@
bool ok;
// Get the ifconfig string
- tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+ if ( usingLagg )
+ tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+ else
+ tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
+
if ( ! tmp.isEmpty() ) {
// If the device is setup, start loading the settings
Modified: pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h
===================================================================
--- pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h 2010-11-30 16:56:32 UTC (rev 8090)
+++ pcbsd/stable/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h 2010-11-30 17:03:42 UTC (rev 8091)
@@ -60,8 +60,6 @@
private:
bool checkRange( QString IP );
- void saveValue( QString File, QString oldKey, QString newKey, int occur );
- QString getValue( QString File, QString Key, int occur );
void runCommand( QString Command );
QString getLineFromCommandOutput( QString command );
QString getNetmaskForIdent( QString ident );
@@ -99,6 +97,7 @@
QString WPAEPrivKeyFile[150];
QString WPAEPassword[150];
int WPAEType[150];
+ bool usingLagg;
signals:
More information about the Commits
mailing list