diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:19:25 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:19:25 +0000 |
commit | e0311ffdf88fc311006351582b959a69d8aad328 (patch) | |
tree | dccf6212f21ef7e3824b54837be7b1d14139d2e1 /src | |
download | wlassistant-e0311ffdf88fc311006351582b959a69d8aad328.tar.gz wlassistant-e0311ffdf88fc311006351582b959a69d8aad328.zip |
Added KDE3 version of wlassistant
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/wlassistant@1097621 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src')
-rw-r--r-- | src/SConscript | 26 | ||||
-rw-r--r-- | src/main.cpp | 56 | ||||
-rw-r--r-- | src/netlistviewitem.cpp | 239 | ||||
-rw-r--r-- | src/netlistviewitem.h | 176 | ||||
-rw-r--r-- | src/netparams.h | 289 | ||||
-rw-r--r-- | src/ui_NetParamsEdit.ui | 1111 | ||||
-rw-r--r-- | src/ui_NetParamsWizard.ui | 892 | ||||
-rw-r--r-- | src/ui_main.ui | 759 | ||||
-rw-r--r-- | src/ui_netparamsedit.cpp | 174 | ||||
-rw-r--r-- | src/ui_netparamsedit.h | 53 | ||||
-rw-r--r-- | src/ui_netparamswizard.cpp | 107 | ||||
-rw-r--r-- | src/ui_netparamswizard.h | 53 | ||||
-rw-r--r-- | src/waconfig.cpp | 29 | ||||
-rw-r--r-- | src/waconfig.h | 45 | ||||
-rw-r--r-- | src/watools.cpp | 312 | ||||
-rw-r--r-- | src/watools.h | 76 | ||||
-rw-r--r-- | src/wlassistant.cpp | 1264 | ||||
-rw-r--r-- | src/wlassistant.desktop | 55 | ||||
-rw-r--r-- | src/wlassistant.h | 120 |
19 files changed, 5836 insertions, 0 deletions
diff --git a/src/SConscript b/src/SConscript new file mode 100644 index 0000000..85a3fee --- /dev/null +++ b/src/SConscript @@ -0,0 +1,26 @@ +#! /usr/bin/env python +## Thomas Nagy, 2005 +## This file can be reused freely for any project (see COPYING) + +Import( 'env' ) + +obj=env.kobject('program') +obj.target='wlassistant' +obj.source=""" +main.cpp +netlistviewitem.cpp +ui_NetParamsEdit.ui +ui_netparamsedit.cpp +ui_NetParamsWizard.ui +ui_netparamswizard.cpp +ui_main.ui +waconfig.cpp +watools.cpp +wlassistant.cpp +""" + +obj.cxxflags='-DQT_THREAD_SUPPORT' +obj.libs='qt-mt kdecore kdeui iw' +obj.execute() + +#env.KDEinstall( 'KDEMENU', 'Utilities', 'wlassistant.desktop' )
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a06f95e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include "wlassistant.h" + +#include <kapplication.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> +#include <klocale.h> + +static const char description[] = + I18N_NOOP("Wireless Assistant"); + +static const char version[] = "0.5.7"; + +static KCmdLineOptions options[] = + { + // { "+[URL]", I18N_NOOP( "Document to open" ), 0 }, + KCmdLineLastOption + }; + +int main(int argc, char **argv) +{ + KAboutData about("wlassistant", I18N_NOOP("Wireless Assistant"), version, description, + KAboutData::License_GPL, "(C) %{YEAR} Pawel Nawrocki", 0, 0, "[email protected]"); + about.addAuthor( "Pawel Nawrocki", 0, "[email protected]" ); + KCmdLineArgs::init(argc, argv, &about); + KCmdLineArgs::addCmdLineOptions( options ); + KApplication app; + WirelessAssistant *mainWin = 0; + mainWin = new WirelessAssistant(); + mainWin->setCaption( QString("%1 %2").arg(description).arg(version) ); + app.setMainWidget( mainWin ); + mainWin->show(); + + // mainWin has WDestructiveClose flag by default, so it will delete itself. + return app.exec(); +} diff --git a/src/netlistviewitem.cpp b/src/netlistviewitem.cpp new file mode 100644 index 0000000..a607eee --- /dev/null +++ b/src/netlistviewitem.cpp @@ -0,0 +1,239 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "netlistviewitem.h" + +#include <iostream> + +#include <kiconloader.h> +#include <kiconeffect.h> +#include <kdeversion.h> + +void NetListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) +{ + /// HACK fixes: higher item (connected) is drawn using regular height upon widget change (widgetStack); + if ( height()!=mHeight ) + setHeight( mHeight ); + + /// PREPARE COLORS /// + QColor bgColor, fgColor; + /// colors of selected item + if ( listView()->isSelected(this) ) { + bgColor = cg.color( QColorGroup::Highlight ); /// settings for selected item; + fgColor = cg.color( QColorGroup::HighlightedText ); + /// colors of deselected item` + } else { + if (mConnected) + bgColor = cg.color( QColorGroup::Background); + else { +#if KDE_IS_VERSION(3,4,0) + bgColor = ((KListViewItem*)this)->backgroundColor(column); +#else + + bgColor = ((KListViewItem*)this)->backgroundColor(); +#endif + + } + fgColor = cg.color( QColorGroup::Text); + if (mQuality<8) + fgColor = fgColor.light(); + } + + /// DRAW BACKGROUND /// + p->fillRect(0,0,width,height(),bgColor); + if (mConnected) { + /// draw a line separating connectedItem from the rest of the list. + p->setPen( bgColor.dark(130) ); + p->drawLine(0, height()-1, width, height()-1); + } + + switch (column) { + + /// DRAW QUALITY /// + case mQualityColumn: { + QPixmap qualityIcon = SmallIcon("knewstuff"); + QPixmap qualityIconGray = KIconEffect().apply( qualityIcon, KIconEffect::ToGray, 1, Qt::black, true ); + int barWidth = int(mQuality/8)*8; + if (mQuality>0) + barWidth+=8; //add 8 (half a star) b/c int rounds down. + if (barWidth>96) + barWidth=96; + int icoTop = int( ( this->height()-16 )/2 ); + p->drawTiledPixmap(listView()->itemMargin(),icoTop,6*16, 16, qualityIconGray ); + p->drawTiledPixmap(listView()->itemMargin(),icoTop,barWidth, 16, qualityIcon ); + break; + } + + /// DRAW ENCRYPTION /// + case mEncColumn: { + if (mEnc) { + int icoTop = int( ( this->height()-16 )/2 ); + int icoLeft = int( ( width-listView()->itemMargin()-16 )/2 ); + QPixmap encIcon = SmallIcon("encrypted"); + p->drawPixmap(icoLeft,icoTop, encIcon ); + } + break; + } + + /// DRAW ESSID /// + case mEssidColumn: { + /// draw icon and its shadow. + if (mConnected) { + QPixmap connectedIcon; + connectedIcon = SmallIcon("forward"); + int icoTop = int( ( this->height()-16 )/2 ); + p->drawPixmap(listView()->itemMargin(),icoTop, connectedIcon ); + } + + QFont mFont = listView()->font(); + if (mConnected) + mFont.setBold( true ); + if (mHidden) + mFont.setItalic( true ); + p->setFont( mFont ); + /// draw shadow + essid name(not connected) + if (mConnected) { + p->setPen( bgColor.dark(130) ); + p->drawText(16+(listView()->itemMargin()*2),0,width, height(), AlignVCenter, mEssid); + p->setPen( bgColor.dark(220) ); + p->drawText(16+(listView()->itemMargin()*2)-1,-1,width, height(), AlignVCenter, mEssid); + p->setPen( fgColor ); + p->drawText(16+(listView()->itemMargin()*2)-2,-2,width, height(), AlignVCenter, mEssid); + + } else { + /// draw essid name (not connected) + p->setPen( fgColor ); + p->drawText(listView()->itemMargin(),0,width, height(), AlignVCenter, mEssid); + } + break; + } + + /// DRAW CHANNEL /// + case mChanColumn: { + QFont mFont = listView()->font(); + mFont.setItalic(true); + if (mConnected) + mFont.setBold( true ); + p->setFont( mFont ); + if (mConnected) { + p->setPen( bgColor.dark(130) ); + p->drawText(listView()->itemMargin(),0,width, height(), AlignCenter, mChannel); + p->setPen( bgColor.dark(220) ); + p->drawText(listView()->itemMargin()-1,-1,width, height(), AlignCenter, mChannel); + } else { + p->setPen( bgColor.dark(220) ); + p->drawText(listView()->itemMargin(),0,width, height(), AlignCenter, mChannel); + } + break; + } + /// DRAW ACCESS POINT /// + case mAPColumn: { + QFont mFont = listView()->font(); + if (mHidden) + mFont.setItalic( true ); + if (mConnected) + mFont.setBold( true ); + p->setFont( mFont ); + if (mConnected) { + p->setPen( bgColor.dark(130) ); + p->drawText(listView()->itemMargin(),0,width, height(), AlignVCenter, mAP); + p->setPen( bgColor.dark(220) ); + p->drawText(listView()->itemMargin()-1,-1,width, height(), AlignVCenter, mAP); + + } else { + p->setPen( bgColor.dark(220) ); + p->drawText(listView()->itemMargin(),0,width, height(), AlignVCenter, mAP); + } + break; + } + + default: + KListViewItem::paintCell(p, cg, column, width, alignment); + + } //switch +} + +int NetListViewItem::width(const QFontMetrics &fm, const QListView *lv, int column) const +{ + int w; + QFont mFont = listView()->font(); + if (mConnected) + mFont.setBold(true); + if (mHidden) + mFont.setItalic(true); + QFontMetrics mFm( mFont ); + + if (column == mQualityColumn) + w = 6*16 + (lv->itemMargin()*2); + else if (column == mEncColumn) + w = 16 + (lv->itemMargin()*2); + else if (column == mChanColumn) + w = mFm.width( mChannel ) + (lv->itemMargin()*2); + else if (column == mEssidColumn) + w = mFm.width( mEssid ) + (lv->itemMargin()*2); + else if (column == mAPColumn) + w = mFm.width( mAP ) + (lv->itemMargin()*2); + /*else if (column == mModeColumn) + w = fm.width( mMode ) + (lv->itemMargin()*2);*/ + + else + w = 0; + + int headerw = fm.width( listView()->columnText(column) ) + (lv->itemMargin()*2); + if (w < headerw) + w = headerw; + + return w; +} + +QString NetListViewItem::key( int column, bool ascending ) const +{ + if (mConnected) { // make sure that connected item is always 1st. + if (ascending) + return "0"; + else + return "ZZZ"; + } + QString t = QString::null; + if (column == mQualityColumn) { + t = QString::number( mQuality ); + if (mQuality < 10) + t.prepend("0"); + } else if (column == mEncColumn) { + if (mEnc) + t = "1"; + else + t="0"; + } else if (column == mEssidColumn) { + t = mEssid.upper(); // add .upper() to make it case-insensitive; + } else if (column == mChanColumn) { + t = mChannel; + if ( mChannel.length() == 1 ) + t.prepend("0"); + } else if (column == mAPColumn) { + t = mAP.upper(); + /*} else if (column == mModeColumn) { + t = mMode.upper();*/ + + } + + + return t; +} diff --git a/src/netlistviewitem.h b/src/netlistviewitem.h new file mode 100644 index 0000000..6410c86 --- /dev/null +++ b/src/netlistviewitem.h @@ -0,0 +1,176 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WA_NETLISTVIEWITEM_H +#define WA_NETLISTVIEWITEM_H + +#include <iostream> + +#include <qpainter.h> + +#include <klistview.h> +#include <kmessagebox.h> + +class NetListViewItem : public KListViewItem +{ +public: + //NetListViewItem(KListView *parent) : KListViewItem(parent) {} + //NetListViewItem(KListView *parent, KListViewItem *after) : KListViewItem(parent, after) {} + //NetListViewItem(KListView *parent, KListViewItem *after, QString essid, QString mode) : KListViewItem(parent, after, essid, mode) {} + NetListViewItem(KListView *parent, QString essid, QString chan, int quality, bool enc, QString ap, bool hidden, bool connected = 0 ) + : KListViewItem(parent, QString::null, QString::null, QString::null, QString::null, QString::null) + { + mEssid = essid; + mChannel = chan; + //mMode = mode; + mQuality = quality; + mEnc = enc; + mAP = ap; + mHidden = hidden; + mConnected = connected; + mHeight = height(); + mWpaSettings = QStringList(); + } + + ~NetListViewItem() + {} + + void setEssid(const QString& theValue) + { + mEssid = theValue; + setText(mEssidColumn, mEssid); + //update(); + } + QString essid() const + { + return mEssid; + } + + void setChannel(const QString& theValue) + { + if ( mChannel != theValue ) { //repaint only if difference visible in quality stars + mChannel = theValue; + repaint(); + } + } + + + QString channel() const + { + return mChannel; + } + + /*QString mode() const + { + return mMode; + }*/ + + bool enc() const + { + return mEnc; + } + + QString ap() const + { + return mAP; + } + + void setAp(const QString& ap) { + mAP = ap; + setText(mAPColumn, mAP); + } + + bool hidden() const + { + return mHidden; + } + + void setConnected(bool theValue) + { + mConnected = theValue; + if (mConnected) + mHeight+=10; + else { + mHeight-=10; + } + setHeight( mHeight ); + repaint(); + } + + + bool isConnected() const + { + return mConnected; + } + + void setQuality(const int& theValue) + { + if ( int(mQuality/8) != int(theValue/8) ) { //repaint only if difference visible in quality stars + mQuality = theValue; + repaint(); + } else + mQuality = theValue; + } + + int quality() const + { + return mQuality; + } + + void setWpaSettings(const QStringList& theValue) + { + mWpaSettings = theValue; + } + + + QStringList wpaSettings() const + { + return mWpaSettings; + } + + + + + +private: + virtual void paintCell (QPainter *p, const QColorGroup &cg, int column, int width, int alignment); + virtual int width(const QFontMetrics &fm, const QListView *lv, int column) const; + virtual QString key( int column, bool ascending ) const; + + QString mEssid; + QString mChannel; + //QString mMode; + int mQuality; + bool mEnc; + QString mAP; + bool mHidden; + bool mConnected; + int mHeight; + QStringList mWpaSettings; + + static const int mEssidColumn = 0; + static const int mChanColumn = 1; + static const int mQualityColumn = 2; + static const int mEncColumn = 3; + static const int mAPColumn = 4; + +}; + +#endif // WA_NETLISTVIEWITEM_H diff --git a/src/netparams.h b/src/netparams.h new file mode 100644 index 0000000..3ec8352 --- /dev/null +++ b/src/netparams.h @@ -0,0 +1,289 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WA_NETPARAMS_H +#define WA_NETPARAMS_H + +#include <iostream> +#include <qfile.h> +#include <kmessagebox.h> +#include <klocale.h> + +class WANetParams +{ +public: + QString iface; + QString essid; + //QString mode; + QString channel; + QString ap; + bool wep; + QString wepMode; + QString wepKey; + bool wpa; + QStringList wpaSettings; + QString wpaKey; + + bool dhcp; + QString ip; + QString netmask; + QString broadcast; + QString gateway; + QString domain; + QString dns1; + QString dns2; + + bool hiddenEssid; + bool wasHiddenEssid; + bool wasWep; + + QString preConnectionCommand; + QString postConnectionCommand; + QString preDisconnectionCommand; + QString postDisconnectionCommand; + int preConnectionTimeout; + int postConnectionTimeout; + int preDisconnectionTimeout; + int postDisconnectionTimeout; + bool preConnectionDetached; + bool postConnectionDetached; + bool preDisconnectionDetached; + bool postDisconnectionDetached; + + bool review() + { + bool r = false; //DEFAULTS TO 'no review needed' + if (wep) + if ( (wepMode.isEmpty()) || (wepKey.isEmpty()) ) { + if (!wasWep) { + KMessageBox::information(0, i18n("<qt><p>The network changed its security settings.</p><p>Please go to <i>Security</i> tab of the following dialog and configure WEP settings.</p></qt>") ); + } else + KMessageBox::error(0, i18n("<qt><p>Your WEP Key is not set properly.</p><p>Please go to <i>Security</i> tab of the following dialog and enter the required key.</p></qt>") ); + r = true; + } + if ( (hiddenEssid) && (!wasHiddenEssid) ) + if ( KMessageBox::questionYesNo(0, i18n("<qt><p>The network has stopped broadcasting its ESSID since the last time you were connected.</p><p>Would you like to use '<b>%1</b>' as an ESSID for this network?</p><p><i>NOTE: If you answer No, a dialog will appear where you will be able to specify a different ESSID.</i></p></qt>").arg(essid) ) != 3 ) // !=YES + r = true; + + wasHiddenEssid = hiddenEssid; + wasWep = wep; + return r; + } + + QString netParamsString() + { + QStringList mNPS; + mNPS << boolToString(hiddenEssid) << essid << ap << channel << boolToString(wep) << wepMode << wepKey << boolToString(dhcp) << ip << netmask << broadcast << gateway << domain << dns1 << dns2 << boolToString(wasHiddenEssid) << boolToString(wasWep) << \ + preConnectionCommand << QString::number(preConnectionTimeout) << boolToString(preConnectionDetached) << \ + postConnectionCommand << QString::number(postConnectionTimeout) << boolToString(postConnectionDetached) << \ + preDisconnectionCommand << QString::number(preDisconnectionTimeout) << boolToString(preDisconnectionDetached) << \ + postDisconnectionCommand << QString::number(postDisconnectionTimeout) << boolToString(postDisconnectionDetached) << \ + wpaSettings.join(",") << wpaKey; + return mNPS.join(","); + } + + void loadNetParamsString( const QString & nps ) + { + /*if (nps.section(",",0,0)=="true") + hiddenEssid=true; + else + hiddenEssid=false;*/ // COMMENTED OUT because hiddenEssid boolean is set from the list item + essid = nps.section(",",1,1); + ap = nps.section(",",2,2); + //channel = nps.section(",",3,3); COMMENTED OUT because channel is set from the list item + /*if (nps.section(",",4,4)=="true") + wep=true; + else + wep=false;*/ // COMMENTED OUT because wep boolean is set from the list item + wepMode = nps.section(",",5,5); + wepKey = nps.section(",",6,6); + dhcp = ( nps.section(",",7,7) == "true" ); + ip = nps.section(",",8,8); + netmask = nps.section(",",9,9); + broadcast = nps.section(",",10,10); + gateway = nps.section(",",11,11); + domain = nps.section(",",12,12); + dns1 = nps.section(",",13,13); + dns2 = nps.section(",",14,14); + wasHiddenEssid = ( nps.section(",",15,15)=="true" ); + wasWep = ( nps.section(",",16,16)=="true" ); + + preConnectionCommand = nps.section(",",17,17); + preConnectionTimeout = nps.section(",",18,18).toInt(); + preConnectionDetached = ( nps.section(",",19,19) == "true" ); + + postConnectionCommand = nps.section(",",20,20); + postConnectionTimeout = nps.section(",",21,21).toInt(); + postConnectionDetached = ( nps.section(",",22,22) == "true" ); + + preDisconnectionCommand = nps.section(",",23,23); + preDisconnectionTimeout = nps.section(",",24,24).toInt(); + preDisconnectionDetached = ( nps.section(",",25,25) == "true" ); + + postDisconnectionCommand = nps.section(",",26,26); + postDisconnectionTimeout = nps.section(",",27,27).toInt(); + postDisconnectionDetached = ( nps.section(",",28,28) == "true" ); + wpaSettings = QStringList::split( ",", nps.section(",",29,32) ); // 4 fields + wpaKey = nps.section(",",33,33); + + } +private: + QString boolToString( bool b ) + { + QString result; + b ? result = "true" : result = "false"; + return result; + } +}; + +class WACommands +{ +public: + bool allFound; + QStringList notFound; + + void init() + { + QStringList binDirs; + binDirs << "/sbin" << "/usr/sbin" << "/usr/local/sbin" << "/bin" << "/usr/bin" << "/usr/local/bin"; + + wpa_supplicant = getPath("wpa_supplicant", binDirs); + wpa_cli = getPath("wpa_cli", binDirs); + dhcp = getPath("dhcpcd", binDirs); //these 2 checks have to be first, so allFound flag is properly set. + if (dhcp.isEmpty()) + dhcp = getPath("dhclient", binDirs); + if (!dhcp.isEmpty()) { + allFound=1; + dhcpClient = dhcp.section("/",-1,-1); + std::cout << "DHCP Client: " << dhcpClient << std::endl; + } + + ifconfig = getPath("ifconfig", binDirs); + iwconfig = getPath("iwconfig", binDirs); + iwlist = getPath("iwlist", binDirs); + route = getPath("route", binDirs); + pidof = getPath("pidof", binDirs); + + if (!allFound) + std::cout << "Executable(s) not found:" << notFound.join(", ") << std::endl; + else + std::cout << "All executables found." << std::endl; + } + + QStringList cmd( const QString & action, const WANetParams & np, const bool & quiet = false ) + { + QStringList mCmd; + + /*if (action=="ifup") + mCmd << ifconfig << np.iface << "up"; + + else if (action=="ifdown") + mCmd << ifconfig << np.iface << "down"; + + else*/ if (action=="radio_on") + mCmd << iwconfig << np.iface << "txpower" << "auto"; + + else if (action=="scan") + mCmd << iwlist << np.iface << "scan"; + + else if (action=="disconnect") + mCmd << iwconfig << np.iface << "mode" << "managed" << "key" << "off" << "ap" << "off" << "essid" << "off"; + + else if (action=="iwconfig_set") { + mCmd << iwconfig << np.iface << "mode" << "managed"; + if (np.channel.toInt()>0) + mCmd << "channel" << np.channel; + mCmd << "key"; + if (np.wep && !np.wepKey.isEmpty()) + mCmd << np.wepMode << np.wepKey; + else + mCmd << "off"; + mCmd << "essid" << np.essid; + + } else if (action=="iwconfig_ap") { + mCmd << iwconfig << np.iface << "ap" << np.ap; + + } else if (action=="ifconfig_dhcp") { + if (dhcpClient=="dhcpcd") + mCmd << dhcp << "-nd" << np.iface; + else if (dhcpClient=="dhclient") + mCmd << dhcp << np.iface; // << "-1" << "-q" + + } else if (action=="kill_dhcp") { + if ( dhcpClient=="dhcpcd") //dhcpcd + mCmd << dhcp << "-k" << np.iface; + else //dhclient + mCmd << dhcp << "-r" << np.iface; + + } else if (action=="ifconfig_manual") { + mCmd << ifconfig << np.iface << np.ip; + if (!np.netmask.isEmpty()) + mCmd << "netmask" << np.netmask; + if (!np.broadcast.isEmpty()) + mCmd << "broadcast" << np.broadcast; + + } else if (action=="route_add") { + if (!np.gateway.isEmpty()) + mCmd << route << "add" << "default" << "gw" << np.gateway; + + } else if (action=="route_del") { + if (!np.gateway.isEmpty()) + mCmd << route << "del" << "default" << "gw" << np.gateway; + + } else + std::cout << "Unknown action: " << action << std::endl; + + if ( (!mCmd.isEmpty()) && (!quiet) ) {//mCmd = QStringList(); + QString mCmdString = mCmd.join(" "); + if (!np.wepKey.isEmpty()) mCmdString.replace(np.wepKey, "xxxxxxxxxx"); + std::cout << action << ": " << mCmdString << std::endl; + } + return mCmd; + } + + QString route; + QString dhcpClient; + QString wpa_supplicant; + QString wpa_cli; +private: + QString ifconfig; + QString iwconfig; + QString iwlist; + QString dhcp; + QString pidof; + + QString getPath(QString file, QStringList dirs) + { + QString s; + for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { + if (QFile( QString(*it+"/"+file) ).exists()) { + s = QString(*it+"/"+file); + break; + } + } + if (s.isEmpty()) { + allFound = 0; + notFound << file; + } + return s; + } +}; + +#endif //WA_NETPARAMS_H diff --git a/src/ui_NetParamsEdit.ui b/src/ui_NetParamsEdit.ui new file mode 100644 index 0000000..b10b5f3 --- /dev/null +++ b/src/ui_NetParamsEdit.ui @@ -0,0 +1,1111 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>netProperties</class> +<widget class="QDialog"> +<property name="name"> +<cstring>netProperties</cstring> +</property> +<property name="geometry"> +<rect> +<x>0</x> +<y>0</y> +<width>420</width> +<height>504</height> +</rect> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>5</hsizetype> +<vsizetype>1</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="caption"> +<string>Properties</string> +</property> +<property name="sizeGripEnabled"> +<bool>false</bool> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="margin"> +<number>11</number> +</property> +<property name="spacing"> +<number>6</number> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>Layout1</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="margin"> +<number>0</number> +</property> +<property name="spacing"> +<number>6</number> +</property> +<widget class="QPushButton"> +<property name="name"> +<cstring>buttonHelp</cstring> +</property> +<property name="text"> +<string>&Help</string> +</property> +<property name="accel"> +<string>F1</string> +</property> +<property name="autoDefault"> +<bool>true</bool> +</property> +</widget> +<spacer> +<property name="name"> +<cstring>Horizontal Spacing2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>20</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QPushButton"> +<property name="name"> +<cstring>buttonOk</cstring> +</property> +<property name="text"> +<string>&OK</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="autoDefault"> +<bool>true</bool> +</property> +<property name="default"> +<bool>true</bool> +</property> +</widget> +<widget class="QPushButton"> +<property name="name"> +<cstring>buttonCancel</cstring> +</property> +<property name="text"> +<string>&Cancel</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="autoDefault"> +<bool>true</bool> +</property> +</widget> +</hbox> +</widget> +<widget class="QTabWidget" row="0" column="0"> +<property name="name"> +<cstring>tabNetParams</cstring> +</property> +<widget class="QWidget"> +<property name="name"> +<cstring>tabInterface</cstring> +</property> +<attribute name="title"> +<string>I&nterface</string> +</attribute> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QGroupBox"> +<property name="name"> +<cstring>boxEssid</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>5</hsizetype> +<vsizetype>1</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="title"> +<string>ESSID</string> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1</cstring> +</property> +<property name="text"> +<string>ESSID:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>essid</cstring> +</property> +</widget> +</hbox> +</widget> +<widget class="QButtonGroup"> +<property name="name"> +<cstring>buttonGroup1</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>5</hsizetype> +<vsizetype>3</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="title"> +<string>Configuration</string> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout3</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioDhcp</cstring> +</property> +<property name="text"> +<string>Automatic (DHCP)</string> +</property> +</widget> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioManualConfig</cstring> +</property> +<property name="text"> +<string>&Manual</string> +</property> +</widget> +</vbox> +</widget> +<widget class="QFrame"> +<property name="name"> +<cstring>boxManualConfig</cstring> +</property> +<property name="frameShape"> +<enum>NoFrame</enum> +</property> +<property name="frameShadow"> +<enum>Raised</enum> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLineEdit" row="2" column="1"> +<property name="name"> +<cstring>netmask</cstring> +</property> +</widget> +<widget class="QLabel" row="2" column="0"> +<property name="name"> +<cstring>textLabel4</cstring> +</property> +<property name="text"> +<string>Netmask:</string> +</property> +</widget> +<widget class="QLineEdit" row="0" column="1"> +<property name="name"> +<cstring>ip</cstring> +</property> +</widget> +<widget class="QLineEdit" row="4" column="1"> +<property name="name"> +<cstring>domain</cstring> +</property> +</widget> +<widget class="QLabel" row="0" column="0"> +<property name="name"> +<cstring>textLabel2</cstring> +</property> +<property name="text"> +<string>IP:</string> +</property> +</widget> +<widget class="QLabel" row="1" column="0"> +<property name="name"> +<cstring>textLabel3</cstring> +</property> +<property name="text"> +<string>Broadcast:</string> +</property> +</widget> +<widget class="QLabel" row="3" column="0"> +<property name="name"> +<cstring>textLabel5</cstring> +</property> +<property name="text"> +<string>Gateway:</string> +</property> +</widget> +<widget class="QLineEdit" row="5" column="1"> +<property name="name"> +<cstring>dns1</cstring> +</property> +</widget> +<widget class="QLabel" row="4" column="0"> +<property name="name"> +<cstring>textLabel6</cstring> +</property> +<property name="text"> +<string>Domain:</string> +</property> +</widget> +<widget class="QLineEdit" row="1" column="1"> +<property name="name"> +<cstring>broadcast</cstring> +</property> +</widget> +<widget class="QLineEdit" row="3" column="1"> +<property name="name"> +<cstring>gateway</cstring> +</property> +</widget> +<widget class="QLineEdit" row="6" column="1"> +<property name="name"> +<cstring>dns2</cstring> +</property> +</widget> +<widget class="QLabel" row="6" column="0"> +<property name="name"> +<cstring>textLabel8</cstring> +</property> +<property name="text"> +<string>Secondary DNS:</string> +</property> +</widget> +<widget class="QLabel" row="5" column="0"> +<property name="name"> +<cstring>textLabel7</cstring> +</property> +<property name="text"> +<string>Primary DNS:</string> +</property> +</widget> +</grid> +</widget> +</vbox> +</widget> +<spacer> +<property name="name"> +<cstring>spacer2</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>20</width> +<height>21</height> +</size> +</property> +</spacer> +</vbox> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>tabSecurity</cstring> +</property> +<attribute name="title"> +<string>Securit&y</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer row="2" column="0"> +<property name="name"> +<cstring>spacer3</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>40</height> +</size> +</property> +</spacer> +<widget class="QButtonGroup" row="1" column="0"> +<property name="name"> +<cstring>groupWpa</cstring> +</property> +<property name="title"> +<string>WPA Settings</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>layout33</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_2_2</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>1</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string>Key:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>wpaKey</cstring> +</property> +<property name="echoMode"> +<enum>Password</enum> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkWpaAscii</cstring> +</property> +<property name="text"> +<string>ASCII</string> +</property> +</widget> +</hbox> +</widget> +<widget class="QLayoutWidget" row="0" column="0"> +<property name="name"> +<cstring>layout34</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_5</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>3</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string>WPA Version:<br>Group Cipher:<br>Pairwise Cipher:<br>Authentication Suite:</string> +</property> +</widget> +<widget class="QLabel"> +<property name="name"> +<cstring>labelWpaSettings</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>1</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string><b>?<br>?<br>?<br>?</b></string> +</property> +</widget> +<spacer> +<property name="name"> +<cstring>spacer71</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>131</width> +<height>21</height> +</size> +</property> +</spacer> +</hbox> +</widget> +</grid> +</widget> +<widget class="QButtonGroup" row="0" column="0"> +<property name="name"> +<cstring>groupWep</cstring> +</property> +<property name="title"> +<string>WEP Settings</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QRadioButton" row="0" column="0"> +<property name="name"> +<cstring>radioWepOpen</cstring> +</property> +<property name="text"> +<string>Open Syste&m</string> +</property> +<property name="accel"> +<string>Alt+M</string> +</property> +</widget> +<widget class="QLayoutWidget" row="2" column="0"> +<property name="name"> +<cstring>layout35</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_2</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>1</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string>Key:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>wepKey</cstring> +</property> +<property name="echoMode"> +<enum>Password</enum> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkWepAscii</cstring> +</property> +<property name="text"> +<string>ASCII</string> +</property> +</widget> +</hbox> +</widget> +<widget class="QRadioButton" row="1" column="0"> +<property name="name"> +<cstring>radioWepRestricted</cstring> +</property> +<property name="text"> +<string>Shared &Key</string> +</property> +<property name="accel"> +<string>Alt+K</string> +</property> +</widget> +</grid> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>tabAdvanced</cstring> +</property> +<attribute name="title"> +<string>Advanced</string> +</attribute> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_4</cstring> +</property> +<property name="text"> +<string><b>Security Warning:</b> the commands specified below will be ran with the same privileges as Wireless Assistant has.</string> +</property> +</widget> +<widget class="QGroupBox"> +<property name="name"> +<cstring>groupBox3</cstring> +</property> +<property name="title"> +<string>Pre-Connection Command</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>layout6</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer7</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>130</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3</cstring> +</property> +<property name="text"> +<string>Timeout:</string> +</property> +</widget> +<widget class="QSpinBox"> +<property name="name"> +<cstring>preConnectionTimeout</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>60</number> +</property> +<property name="minValue"> +<number>1</number> +</property> +<property name="value"> +<number>20</number> +</property> +<property name="toolTip" stdset="0"> +<string>Amount of time after which the process will be killed.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Timeout</b></p> +<p>This option specifies how long should Wireless Assistant wait for the process to finish, before it will be killed.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>preConnectionDetached</cstring> +</property> +<property name="text"> +<string>Run detached</string> +</property> +<property name="toolTip" stdset="0"> +<string>Don't wait for the process to finish.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p></string> +</property> +</widget> +</hbox> +</widget> +<widget class="QLayoutWidget" row="0" column="0"> +<property name="name"> +<cstring>layout7</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_2</cstring> +</property> +<property name="text"> +<string>Command:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>preConnectionCommand</cstring> +</property> +</widget> +</hbox> +</widget> +</grid> +</widget> +<widget class="QGroupBox"> +<property name="name"> +<cstring>groupBox3_2</cstring> +</property> +<property name="title"> +<string>Post-Connection Command</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>layout6_2</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer7_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>130</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_3</cstring> +</property> +<property name="text"> +<string>Timeout:</string> +</property> +</widget> +<widget class="QSpinBox"> +<property name="name"> +<cstring>postConnectionTimeout</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>60</number> +</property> +<property name="minValue"> +<number>1</number> +</property> +<property name="value"> +<number>20</number> +</property> +<property name="toolTip" stdset="0"> +<string>Amount of time after which the process will be killed.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Timeout</b></p> +<p>This option specifies how long should Wireless Assistant wait for the process to finish, before it will be killed.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>postConnectionDetached</cstring> +</property> +<property name="text"> +<string>Run detached</string> +</property> +<property name="toolTip" stdset="0"> +<string>Don't wait for the process to finish.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p></string> +</property> +</widget> +</hbox> +</widget> +<widget class="QLayoutWidget" row="0" column="0"> +<property name="name"> +<cstring>layout7_2</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_2_2</cstring> +</property> +<property name="text"> +<string>Command:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>postConnectionCommand</cstring> +</property> +</widget> +</hbox> +</widget> +</grid> +</widget> +<widget class="QGroupBox"> +<property name="name"> +<cstring>groupBox3_3</cstring> +</property> +<property name="title"> +<string>Pre-Disconnection Command</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>layout6_3</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer7_3</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>130</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_4</cstring> +</property> +<property name="text"> +<string>Timeout:</string> +</property> +</widget> +<widget class="QSpinBox"> +<property name="name"> +<cstring>preDisconnectionTimeout</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>60</number> +</property> +<property name="minValue"> +<number>1</number> +</property> +<property name="value"> +<number>20</number> +</property> +<property name="toolTip" stdset="0"> +<string>Amount of time after which the process will be killed.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Timeout</b></p> +<p>This option specifies how long should Wireless Assistant wait for the process to finish, before it will be killed.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>preDisconnectionDetached</cstring> +</property> +<property name="text"> +<string>Run detached</string> +</property> +<property name="toolTip" stdset="0"> +<string>Don't wait for the process to finish.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p></string> +</property> +</widget> +</hbox> +</widget> +<widget class="QLayoutWidget" row="0" column="0"> +<property name="name"> +<cstring>layout7_3</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_2_3</cstring> +</property> +<property name="text"> +<string>Command:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>preDisconnectionCommand</cstring> +</property> +</widget> +</hbox> +</widget> +</grid> +</widget> +<widget class="QGroupBox"> +<property name="name"> +<cstring>groupBox3_3_2</cstring> +</property> +<property name="title"> +<string>Post-Disconnection Command</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget" row="1" column="0"> +<property name="name"> +<cstring>layout6_3_2</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer7_3_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>130</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_4_2</cstring> +</property> +<property name="text"> +<string>Timeout:</string> +</property> +</widget> +<widget class="QSpinBox"> +<property name="name"> +<cstring>postDisconnectionTimeout</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>60</number> +</property> +<property name="minValue"> +<number>1</number> +</property> +<property name="value"> +<number>20</number> +</property> +<property name="toolTip" stdset="0"> +<string>Amount of time after which the process will be killed.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Timeout</b></p> +<p>This option specifies how long should Wireless Assistant wait for the process to finish, before it will be killed.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>postDisconnectionDetached</cstring> +</property> +<property name="text"> +<string>Run detached</string> +</property> +<property name="toolTip" stdset="0"> +<string>Don't wait for the process to finish.</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p></string> +</property> +</widget> +</hbox> +</widget> +<widget class="QLayoutWidget" row="0" column="0"> +<property name="name"> +<cstring>layout7_3_2</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1_3_2_3_2</cstring> +</property> +<property name="text"> +<string>Command:</string> +</property> +</widget> +<widget class="QLineEdit"> +<property name="name"> +<cstring>postDisconnectionCommand</cstring> +</property> +</widget> +</hbox> +</widget> +</grid> +</widget> +<spacer> +<property name="name"> +<cstring>spacer4</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>31</width> +<height>20</height> +</size> +</property> +</spacer> +</vbox> +</widget> +</widget> +</grid> +</widget> +<connections> +<connection> +<sender>buttonOk</sender> +<signal>clicked()</signal> +<receiver>netProperties</receiver> +<slot>accept()</slot> +</connection> +<connection> +<sender>buttonCancel</sender> +<signal>clicked()</signal> +<receiver>netProperties</receiver> +<slot>reject()</slot> +</connection> +<connection> +<sender>radioManualConfig</sender> +<signal>toggled(bool)</signal> +<receiver>boxManualConfig</receiver> +<slot>setEnabled(bool)</slot> +</connection> +<connection> +<sender>radioDhcp</sender> +<signal>toggled(bool)</signal> +<receiver>boxManualConfig</receiver> +<slot>setDisabled(bool)</slot> +</connection> +<connection> +<sender>preConnectionDetached</sender> +<signal>toggled(bool)</signal> +<receiver>preConnectionTimeout</receiver> +<slot>setDisabled(bool)</slot> +</connection> +<connection> +<sender>postConnectionDetached</sender> +<signal>toggled(bool)</signal> +<receiver>postConnectionTimeout</receiver> +<slot>setDisabled(bool)</slot> +</connection> +<connection> +<sender>preDisconnectionDetached</sender> +<signal>toggled(bool)</signal> +<receiver>preDisconnectionTimeout</receiver> +<slot>setDisabled(bool)</slot> +</connection> +<connection> +<sender>postDisconnectionDetached</sender> +<signal>toggled(bool)</signal> +<receiver>postDisconnectionTimeout</receiver> +<slot>setDisabled(bool)</slot> +</connection> +</connections> +<tabstops> +<tabstop>essid</tabstop> +<tabstop>radioDhcp</tabstop> +<tabstop>radioManualConfig</tabstop> +<tabstop>ip</tabstop> +<tabstop>broadcast</tabstop> +<tabstop>netmask</tabstop> +<tabstop>gateway</tabstop> +<tabstop>domain</tabstop> +<tabstop>dns1</tabstop> +<tabstop>dns2</tabstop> +<tabstop>tabNetParams</tabstop> +<tabstop>radioWepOpen</tabstop> +<tabstop>radioWepRestricted</tabstop> +<tabstop>wepKey</tabstop> +<tabstop>buttonHelp</tabstop> +<tabstop>buttonOk</tabstop> +<tabstop>buttonCancel</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/ui_NetParamsWizard.ui b/src/ui_NetParamsWizard.ui new file mode 100644 index 0000000..14e8a46 --- /dev/null +++ b/src/ui_NetParamsWizard.ui @@ -0,0 +1,892 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>NetParamsWizard</class> +<widget class="QWizard"> +<property name="name"> +<cstring>NetParamsWizard</cstring> +</property> +<property name="geometry"> +<rect> +<x>0</x> +<y>0</y> +<width>427</width> +<height>356</height> +</rect> +</property> +<property name="caption"> +<string>First Connection Wizard</string> +</property> +<property name="sizeGripEnabled"> +<bool>false</bool> +</property> +<property name="modal"> +<bool>true</bool> +</property> +<property name="titleFont"> +<font> +<bold>1</bold> +</font> +</property> +<widget class="QWidget"> +<property name="name"> +<cstring>welcome</cstring> +</property> +<attribute name="title"> +<string>Welcome to First Connection Wizard</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel" row="0" column="0"> +<property name="name"> +<cstring>textLabel1_2</cstring> +</property> +<property name="text"> +<string><b><p>This is the first time you are trying to connect to the selected network.</p></b> +<p>You will be asked a few questions necessary to configure this connection.</p> +<p><i>Press Next to continue.</i></p></string> +</property> +<property name="alignment"> +<set>WordBreak|AlignTop</set> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>WizardPage</cstring> +</property> +<attribute name="title"> +<string>ESSID</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="spacing"> +<number>15</number> +</property> +<widget class="QLabel" row="0" column="0" rowspan="1" colspan="4"> +<property name="name"> +<cstring>textLabel8_2</cstring> +</property> +<property name="text"> +<string><p><b>You are trying to connect to a network that does not broadcast its ESSID.</b></p> +<p>Please specify ESSID that you would like to use when connecting to this access point.</p></string> +</property> +</widget> +<spacer row="2" column="2"> +<property name="name"> +<cstring>spacer54</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>100</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="1" column="1"> +<property name="name"> +<cstring>textLabel9</cstring> +</property> +<property name="text"> +<string>ESSID:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="1" column="2"> +<property name="name"> +<cstring>essid</cstring> +</property> +</widget> +<spacer row="1" column="3"> +<property name="name"> +<cstring>spacer55</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>101</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="1" column="0"> +<property name="name"> +<cstring>spacer56</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>61</width> +<height>21</height> +</size> +</property> +</spacer> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>ConfigMode</cstring> +</property> +<attribute name="title"> +<string>Interface Configuration</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="spacing"> +<number>15</number> +</property> +<spacer row="1" column="2"> +<property name="name"> +<cstring>spacer5</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>80</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="1" column="0"> +<property name="name"> +<cstring>spacer4</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>60</width> +<height>31</height> +</size> +</property> +</spacer> +<spacer row="2" column="1"> +<property name="name"> +<cstring>spacer6</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>20</height> +</size> +</property> +</spacer> +<widget class="QButtonGroup" row="1" column="1"> +<property name="name"> +<cstring>buttonGroup3</cstring> +</property> +<property name="focusPolicy"> +<enum>TabFocus</enum> +</property> +<property name="lineWidth"> +<number>0</number> +</property> +<property name="title"> +<string></string> +</property> +<property name="flat"> +<bool>true</bool> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioDhcp</cstring> +</property> +<property name="text"> +<string>Automatic (DHCP)</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="checked"> +<bool>true</bool> +</property> +</widget> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioManualConfig</cstring> +</property> +<property name="text"> +<string>Manual</string> +</property> +<property name="accel"> +<string></string> +</property> +</widget> +</vbox> +</widget> +<widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> +<property name="name"> +<cstring>textLabel2_2</cstring> +</property> +<property name="text"> +<string><p><b>Your IP and other parameters need to be configured to connect to any network.</b></p> +<p>Which configuration option would you like to use when connecting to this network?</p></string> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>ManualConfig</cstring> +</property> +<attribute name="title"> +<string>Interface Parameters</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="spacing"> +<number>15</number> +</property> +<widget class="QLayoutWidget" row="1" column="1"> +<property name="name"> +<cstring>layout12</cstring> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLineEdit" row="5" column="1"> +<property name="name"> +<cstring>dns1</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLineEdit" row="3" column="1"> +<property name="name"> +<cstring>gateway</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLabel" row="6" column="0"> +<property name="name"> +<cstring>textLabel6</cstring> +</property> +<property name="text"> +<string>Secondary DNS:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="0" column="1"> +<property name="name"> +<cstring>ip</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLineEdit" row="1" column="1"> +<property name="name"> +<cstring>broadcast</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLabel" row="0" column="0"> +<property name="name"> +<cstring>textLabel1</cstring> +</property> +<property name="text"> +<string>IP:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLabel" row="2" column="0"> +<property name="name"> +<cstring>textLabel3</cstring> +</property> +<property name="text"> +<string>Netmask:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="6" column="1"> +<property name="name"> +<cstring>dns2</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLabel" row="5" column="0"> +<property name="name"> +<cstring>textLabel5</cstring> +</property> +<property name="text"> +<string>Primary DNS:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLabel" row="3" column="0"> +<property name="name"> +<cstring>textLabel7</cstring> +</property> +<property name="text"> +<string>Gateway:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="4" column="1"> +<property name="name"> +<cstring>domain</cstring> +</property> +</widget> +<widget class="QLineEdit" row="2" column="1"> +<property name="name"> +<cstring>netmask</cstring> +</property> +<property name="maxLength"> +<number>32767</number> +</property> +</widget> +<widget class="QLabel" row="4" column="0"> +<property name="name"> +<cstring>textLabel4</cstring> +</property> +<property name="text"> +<string>Domain:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLabel" row="1" column="0"> +<property name="name"> +<cstring>textLabel2</cstring> +</property> +<property name="text"> +<string>Broadcast:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +</grid> +</widget> +<spacer row="1" column="2"> +<property name="name"> +<cstring>spacer7</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>60</width> +<height>31</height> +</size> +</property> +</spacer> +<spacer row="1" column="0"> +<property name="name"> +<cstring>spacer8</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>50</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="2" column="1"> +<property name="name"> +<cstring>spacer9</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>16</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> +<property name="name"> +<cstring>textLabel3_2</cstring> +</property> +<property name="text"> +<string><p><b>Please specify interface parameters to be used to connect to this network.</b></p> +<p>You may leave some fields blank.</p></string> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>WepConfig</cstring> +</property> +<attribute name="title"> +<string>WEP Configuration</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel" row="0" column="0" rowspan="1" colspan="6"> +<property name="name"> +<cstring>textLabel5_2</cstring> +</property> +<property name="text"> +<string><p><b>The network you are trying to connect to requires WEP authentication.</b></p> +<p>Which WEP mode would you like to use?</p></string> +</property> +</widget> +<widget class="QButtonGroup" row="1" column="3"> +<property name="name"> +<cstring>buttonGroup3_2_2</cstring> +</property> +<property name="lineWidth"> +<number>0</number> +</property> +<property name="title"> +<string></string> +</property> +<property name="flat"> +<bool>true</bool> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioWepOpen</cstring> +</property> +<property name="text"> +<string>Open S&ystem</string> +</property> +<property name="checked"> +<bool>true</bool> +</property> +</widget> +<widget class="QRadioButton"> +<property name="name"> +<cstring>radioButton2_2_2</cstring> +</property> +<property name="text"> +<string>Shared Key</string> +</property> +</widget> +</vbox> +</widget> +<spacer row="1" column="0" rowspan="1" colspan="3"> +<property name="name"> +<cstring>spacer4_2_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>122</width> +<height>31</height> +</size> +</property> +</spacer> +<spacer row="1" column="4" rowspan="1" colspan="2"> +<property name="name"> +<cstring>spacer5_2_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>150</width> +<height>21</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="2" column="0" rowspan="1" colspan="6"> +<property name="name"> +<cstring>textLabel6_2</cstring> +</property> +<property name="text"> +<string><p><b>Please provide a key to be used with this network.</b></p></string> +</property> +</widget> +<spacer row="4" column="3"> +<property name="name"> +<cstring>spacer17</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>31</width> +<height>16</height> +</size> +</property> +</spacer> +<spacer row="3" column="5"> +<property name="name"> +<cstring>spacer15</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>50</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="3" column="0"> +<property name="name"> +<cstring>spacer16</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>30</width> +<height>21</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="3" column="1"> +<property name="name"> +<cstring>textLabel8</cstring> +</property> +<property name="text"> +<string>WEP key:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="3" column="2" rowspan="1" colspan="2"> +<property name="name"> +<cstring>wepKey</cstring> +</property> +<property name="minimumSize"> +<size> +<width>140</width> +<height>0</height> +</size> +</property> +<property name="echoMode"> +<enum>Password</enum> +</property> +</widget> +<widget class="QCheckBox" row="3" column="4"> +<property name="name"> +<cstring>checkWepAscii</cstring> +</property> +<property name="text"> +<string>ASCII</string> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>WizardPage</cstring> +</property> +<attribute name="title"> +<string>WPA Configuration</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer row="4" column="3"> +<property name="name"> +<cstring>spacer17_2</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>31</width> +<height>54</height> +</size> +</property> +</spacer> +<spacer row="3" column="6"> +<property name="name"> +<cstring>spacer15_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>80</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="3" column="0"> +<property name="name"> +<cstring>spacer16_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>49</width> +<height>21</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="0" column="0" rowspan="1" colspan="7"> +<property name="name"> +<cstring>textLabel5_2_2</cstring> +</property> +<property name="text"> +<string><p><b>The network you are trying to connect to requires WPA authentication.</b></p></string> +</property> +</widget> +<widget class="QLabel" row="3" column="1" rowspan="1" colspan="2"> +<property name="name"> +<cstring>textLabel8_3</cstring> +</property> +<property name="text"> +<string>WPA Key:</string> +</property> +<property name="alignment"> +<set>AlignVCenter|AlignRight</set> +</property> +</widget> +<widget class="QLineEdit" row="3" column="3" rowspan="1" colspan="2"> +<property name="name"> +<cstring>wpaKey</cstring> +</property> +<property name="minimumSize"> +<size> +<width>140</width> +<height>0</height> +</size> +</property> +<property name="echoMode"> +<enum>Password</enum> +</property> +</widget> +<widget class="QCheckBox" row="3" column="5"> +<property name="name"> +<cstring>checkWpaAscii</cstring> +</property> +<property name="text"> +<string>ASCII</string> +</property> +</widget> +<widget class="QLabel" row="2" column="0" rowspan="1" colspan="7"> +<property name="name"> +<cstring>textLabel6_2_2</cstring> +</property> +<property name="text"> +<string><p><b>Please provide a key to be used with this network.</b></p></string> +</property> +</widget> +<spacer row="1" column="0" rowspan="1" colspan="2"> +<property name="name"> +<cstring>spacer43</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>80</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer row="1" column="6"> +<property name="name"> +<cstring>spacer42</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>60</width> +<height>31</height> +</size> +</property> +</spacer> +<widget class="QLabel" row="1" column="4" rowspan="1" colspan="2"> +<property name="name"> +<cstring>labelWpaSettings</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>1</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string><b>?<br>?<br>?<br>?</b></string> +</property> +</widget> +<widget class="QLabel" row="1" column="2" rowspan="1" colspan="2"> +<property name="name"> +<cstring>textLabel1_3</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>3</hsizetype> +<vsizetype>5</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="text"> +<string>WPA Version:<br>Group Cipher:<br>Pairwise Cipher:<br>Authentication Suite:</string> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>done</cstring> +</property> +<attribute name="title"> +<string>Done!</string> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel" row="0" column="0"> +<property name="name"> +<cstring>textLabel7_2</cstring> +</property> +<property name="text"> +<string><p><b>Congratulations!</b></p> +<p>You have successfully finished configuring this connection.</p> +<p><b>Press Finish to connect!</b></p></string> +</property> +<property name="alignment"> +<set>WordBreak|AlignTop</set> +</property> +</widget> +</grid> +</widget> +</widget> +<tabstops> +<tabstop>buttonGroup3</tabstop> +<tabstop>ip</tabstop> +<tabstop>broadcast</tabstop> +<tabstop>netmask</tabstop> +<tabstop>gateway</tabstop> +<tabstop>domain</tabstop> +<tabstop>dns1</tabstop> +<tabstop>dns2</tabstop> +<tabstop>radioWepOpen</tabstop> +<tabstop>wepKey</tabstop> +<tabstop>radioDhcp</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/ui_main.ui b/src/ui_main.ui new file mode 100644 index 0000000..eca55a9 --- /dev/null +++ b/src/ui_main.ui @@ -0,0 +1,759 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>mainWindow</class> +<widget class="QDialog"> +<property name="name"> +<cstring>mainWindow</cstring> +</property> +<property name="geometry"> +<rect> +<x>0</x> +<y>0</y> +<width>588</width> +<height>324</height> +</rect> +</property> +<property name="caption"> +<string>Wireless Assistant</string> +</property> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="KPushButton" row="2" column="1"> +<property name="name"> +<cstring>buttonOptions</cstring> +</property> +<property name="minimumSize"> +<size> +<width>0</width> +<height>0</height> +</size> +</property> +<property name="text"> +<string>&Options</string> +</property> +<property name="accel"> +<string>Alt+O</string> +</property> +<property name="toggleButton"> +<bool>true</bool> +</property> +<property name="toolTip" stdset="0"> +<string>Toggle network list/options</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Options Button</b></p> +<p>Pressing this toggle button will show the available application options.</p> +<p><i>HINT: Press this button again to return to the network list.</i></p></string> +</property> +</widget> +<widget class="KPushButton" row="4" column="1"> +<property name="name"> +<cstring>buttonClose</cstring> +</property> +<property name="text"> +<string>&Quit</string> +</property> +<property name="accel"> +<string>Alt+Q</string> +</property> +<property name="default"> +<bool>true</bool> +</property> +<property name="toolTip" stdset="0"> +<string>Quit the application</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Quit Button</b></p> +<p>Pressing this button will quit the application.</p></string> +</property> +</widget> +<widget class="KPushButton" row="1" column="1"> +<property name="name"> +<cstring>buttonConnect</cstring> +</property> +<property name="enabled"> +<bool>false</bool> +</property> +<property name="minimumSize"> +<size> +<width>120</width> +<height>0</height> +</size> +</property> +<property name="text"> +<string>Co&nnect</string> +</property> +<property name="accel"> +<string>Alt+N</string> +</property> +<property name="toolTip" stdset="0"> +<string>Connect to the selected network</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Connect/Disconnect Button</b></p> +<p>Pressing this button will connect to/disconnect from the network currently selected in the network list.</p></string> +</property> +</widget> +<widget class="KPushButton" row="0" column="1"> +<property name="name"> +<cstring>buttonScan</cstring> +</property> +<property name="enabled"> +<bool>false</bool> +</property> +<property name="text"> +<string>Refresh</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="flat"> +<bool>false</bool> +</property> +<property name="toolTip" stdset="0"> +<string>Refresh network list</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Scan Button</b></p> +<p>Pressing this button will scan for wireless networks and refresh the network list.</p></string> +</property> +</widget> +<spacer row="3" column="1"> +<property name="name"> +<cstring>spacer14</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>120</height> +</size> +</property> +</spacer> +<widget class="QLayoutWidget" row="0" column="0" rowspan="5" colspan="1"> +<property name="name"> +<cstring>layout16</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="margin"> +<number>0</number> +</property> +<widget class="QFrame"> +<property name="name"> +<cstring>frameDevice</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>5</hsizetype> +<vsizetype>1</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="frameShape"> +<enum>NoFrame</enum> +</property> +<property name="frameShadow"> +<enum>Plain</enum> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="margin"> +<number>0</number> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>devLabel</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>1</hsizetype> +<vsizetype>0</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="minimumSize"> +<size> +<width>0</width> +<height>20</height> +</size> +</property> +<property name="text"> +<string>Device:</string> +</property> +</widget> +<widget class="KComboBox"> +<property name="name"> +<cstring>devCombo</cstring> +</property> +<property name="enabled"> +<bool>false</bool> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>3</hsizetype> +<vsizetype>0</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="minimumSize"> +<size> +<width>60</width> +<height>0</height> +</size> +</property> +<property name="toolTip" stdset="0"> +<string>Pick a network device to use</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Device Selection</b></p> +<p>This combo box allows you to select which wireless card to use.</p> +<p><i>NOTE: Selecting a different card will refresh the network list.</i></p></string> +</property> +</widget> +</hbox> +</widget> +<widget class="QWidgetStack"> +<property name="name"> +<cstring>widgetStack</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>7</hsizetype> +<vsizetype>7</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="frameShape"> +<enum>PopupPanel</enum> +</property> +<property name="frameShadow"> +<enum>Sunken</enum> +</property> +<property name="lineWidth"> +<number>2</number> +</property> +<widget class="QWidget"> +<property name="name"> +<cstring>netPage</cstring> +</property> +<attribute name="id"> +<number>0</number> +</attribute> +<grid> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<property name="margin"> +<number>0</number> +</property> +<property name="spacing"> +<number>0</number> +</property> +<widget class="KListView" row="0" column="0"> +<column> +<property name="text"> +<string>ESSID</string> +</property> +<property name="clickable"> +<bool>true</bool> +</property> +<property name="resizable"> +<bool>true</bool> +</property> +</column> +<column> +<property name="text"> +<string>Channel</string> +</property> +<property name="clickable"> +<bool>true</bool> +</property> +<property name="resizable"> +<bool>true</bool> +</property> +</column> +<column> +<property name="text"> +<string>Link Quality</string> +</property> +<property name="clickable"> +<bool>true</bool> +</property> +<property name="resizable"> +<bool>false</bool> +</property> +</column> +<column> +<property name="text"> +<string>WEP/WPA</string> +</property> +<property name="clickable"> +<bool>true</bool> +</property> +<property name="resizable"> +<bool>false</bool> +</property> +</column> +<column> +<property name="text"> +<string>AP</string> +</property> +<property name="clickable"> +<bool>true</bool> +</property> +<property name="resizable"> +<bool>true</bool> +</property> +</column> +<property name="name"> +<cstring>netList</cstring> +</property> +<property name="frameShape"> +<enum>NoFrame</enum> +</property> +<property name="frameShadow"> +<enum>Plain</enum> +</property> +<property name="lineWidth"> +<number>1</number> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Network List</b></p> +<p>This list shows all the wireless networks that have been found.</p> +<p><i>HINT: Click the Refresh button to update this list.</i></p></string> +</property> +</widget> +<widget class="QLabel" row="1" column="0"> +<property name="name"> +<cstring>statusLabel</cstring> +</property> +<property name="sizePolicy"> +<sizepolicy> +<hsizetype>7</hsizetype> +<vsizetype>0</vsizetype> +<horstretch>0</horstretch> +<verstretch>0</verstretch> +</sizepolicy> +</property> +<property name="minimumSize"> +<size> +<width>0</width> +<height>20</height> +</size> +</property> +<property name="margin"> +<number>5</number> +</property> +<property name="text"> +<string>Ready</string> +</property> +<property name="alignment"> +<set>WordBreak|AlignVCenter</set> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Status Bar</b></p> +<p>Messages describing current process are shown in this area.</p></string> +</property> +</widget> +</grid> +</widget> +<widget class="QWidget"> +<property name="name"> +<cstring>optionsPage</cstring> +</property> +<attribute name="id"> +<number>1</number> +</attribute> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout20</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkAutoConnect</cstring> +</property> +<property name="text"> +<string>Automatically connect on startup</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>AutomaticallyConnect on Startup</b></p> +<p>Checking this box will make the application try to connect to the best available network. Only networks that have been previously configured will be taken into account.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkAutoReconnect</cstring> +</property> +<property name="text"> +<string>Automaticall&y reconnect if connection is lost</string> +</property> +<property name="accel"> +<string>Alt+Y</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Automatically Reconnect if Connection is Lost</b></p> +<p>Checking this box will make the application try to reconnect after the connection is lost.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkAutoQuit</cstring> +</property> +<property name="text"> +<string>Quit upon successful connection</string> +</property> +<property name="accel"> +<string></string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Quit Upon Successful Connection</b></p> +<p>Checking this box will make the application close after successfully establishing a connection to a wireless network.</p></string> +</property> +</widget> +<widget class="QCheckBox"> +<property name="name"> +<cstring>checkGroupAPs</cstring> +</property> +<property name="text"> +<string>&Group access points with the same ESSID</string> +</property> +<property name="accel"> +<string>Alt+G</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Group Access Points with the Same ESSID</b></p> +<p>Checking this box will make all access points with the same ESSID appear as one item in the network list.</p></string> +</property> +</widget> +</vbox> +</widget> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout17</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout12</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel2_2</cstring> +</property> +<property name="text"> +<string>Delay before scanning:</string> +</property> +<property name="toolTip" stdset="0"> +<string>Specify how long to wait for an IP</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>DHCP Client Timeout</b></p> +<p>This option specifies the amount of time after which the application should stop waiting for an IP address and assume that the connection has failed.</p> +<p><i>HINT: Increasing this number can help if you have problems connecting to some networks.</i></p></string> +</property> +</widget> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel2</cstring> +</property> +<property name="text"> +<string>DHCP client timeout:</string> +</property> +<property name="toolTip" stdset="0"> +<string>Specify how long to wait for an IP</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>DHCP Client Timeout</b></p> +<p>This option specifies the amount of time after which the application should stop waiting for an IP address and assume that the connection has failed.</p> +<p><i>HINT: Increasing this number can help if you have problems connecting to some networks.</i></p></string> +</property> +</widget> +</vbox> +</widget> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout13</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer24_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Fixed</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>20</height> +</size> +</property> +</spacer> +<spacer> +<property name="name"> +<cstring>spacer24</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Fixed</enum> +</property> +<property name="sizeHint"> +<size> +<width>21</width> +<height>20</height> +</size> +</property> +</spacer> +</vbox> +</widget> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout14</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<widget class="QSpinBox"> +<property name="name"> +<cstring>spinDelayBeforeScanning</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>20</number> +</property> +<property name="minValue"> +<number>0</number> +</property> +<property name="value"> +<number>0</number> +</property> +<property name="toolTip" stdset="0"> +<string>Specify how long to wait before scanning</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Delay Before Scanning</b></p> +<p>This option specifies the amount of time to wait between bringing the interface up and performing a scan.</p> +<p><i>HINT: Increasing this number can help if you have to refresh the list manually to see all the available networks.</i></p></string> +</property> +</widget> +<widget class="QSpinBox"> +<property name="name"> +<cstring>spinDhcpTimeout</cstring> +</property> +<property name="suffix"> +<string>s</string> +</property> +<property name="maxValue"> +<number>60</number> +</property> +<property name="minValue"> +<number>5</number> +</property> +<property name="value"> +<number>15</number> +</property> +<property name="toolTip" stdset="0"> +<string>Specify how long to wait for an IP</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>DHCP Client Timeout</b></p> +<p>This option specifies the amount of time after which the application should stop waiting for an IP address and assume that the connection has failed.</p> +<p><i>HINT: Increasing this number can help if you have problems connecting to some networks.</i></p></string> +</property> +</widget> +</vbox> +</widget> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout15</cstring> +</property> +<vbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer25_2</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>101</width> +<height>21</height> +</size> +</property> +</spacer> +<spacer> +<property name="name"> +<cstring>spacer25</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>118</width> +<height>21</height> +</size> +</property> +</spacer> +</vbox> +</widget> +</hbox> +</widget> +<widget class="QLabel"> +<property name="name"> +<cstring>textLabel1</cstring> +</property> +<property name="text"> +<string><i>Press the button below to enable all messages which have been turned off with the 'Don't Show Again' feature.</i></string> +</property> +</widget> +<widget class="QLayoutWidget"> +<property name="name"> +<cstring>layout19</cstring> +</property> +<hbox> +<property name="name"> +<cstring>unnamed</cstring> +</property> +<spacer> +<property name="name"> +<cstring>spacer22</cstring> +</property> +<property name="orientation"> +<enum>Horizontal</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>201</width> +<height>21</height> +</size> +</property> +</spacer> +<widget class="QPushButton"> +<property name="name"> +<cstring>buttonEnableAllMessages</cstring> +</property> +<property name="text"> +<string>E&nable All Messages</string> +</property> +<property name="accel"> +<string>Alt+N</string> +</property> +<property name="whatsThis" stdset="0"> +<string><p><b>Enable All Messages</b></p> +<p>Pressing this button will enable all messages which have been turned off with the 'Don't Show Again' feature.</p></string> +</property> +</widget> +</hbox> +</widget> +<spacer> +<property name="name"> +<cstring>spacer16</cstring> +</property> +<property name="orientation"> +<enum>Vertical</enum> +</property> +<property name="sizeType"> +<enum>Expanding</enum> +</property> +<property name="sizeHint"> +<size> +<width>20</width> +<height>31</height> +</size> +</property> +</spacer> +</vbox> +</widget> +</widget> +</vbox> +</widget> +</grid> +</widget> +<tabstops> +<tabstop>devCombo</tabstop> +<tabstop>netList</tabstop> +<tabstop>buttonScan</tabstop> +<tabstop>buttonConnect</tabstop> +<tabstop>buttonOptions</tabstop> +<tabstop>buttonClose</tabstop> +<tabstop>checkAutoQuit</tabstop> +<tabstop>spinDhcpTimeout</tabstop> +<tabstop>buttonEnableAllMessages</tabstop> +</tabstops> +<slots> +<slot>netScan()</slot> +<slot>netConnect()</slot> +<slot>showCfgDlg()</slot> +<slot>setDeviceList()</slot> +</slots> +<functions> +<function>updateStatus(char sts)</function> +</functions> +<layoutdefaults spacing="6" margin="11"/> +<includehints> +<includehint>kpushbutton.h</includehint> +<includehint>kpushbutton.h</includehint> +<includehint>kpushbutton.h</includehint> +<includehint>kpushbutton.h</includehint> +<includehint>kcombobox.h</includehint> +<includehint>klistview.h</includehint> +</includehints> +</UI> diff --git a/src/ui_netparamsedit.cpp b/src/ui_netparamsedit.cpp new file mode 100644 index 0000000..0e994d6 --- /dev/null +++ b/src/ui_netparamsedit.cpp @@ -0,0 +1,174 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include "ui_netparamsedit.h" +#include "netparams.h" + +#include <qgroupbox.h> +#include <qlineedit.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qtabwidget.h> +#include <qpushbutton.h> +#include <qspinbox.h> +#include <qbuttongroup.h> +#include <qlabel.h> + +#include <kiconloader.h> + +ui_NetParamsEdit::ui_NetParamsEdit(QWidget* parent, const char* name, bool modal, WFlags fl) + : netProperties(parent,name, modal,fl) +{ + buttonHelp->hide(); + buttonOk->setIconSet( SmallIconSet("ok") ); + buttonCancel->setIconSet( SmallIconSet("cancel") ); +} + +ui_NetParamsEdit::~ui_NetParamsEdit() +{} + +/*$SPECIALIZATION$*/ + +/*void ui_NetParamsEdit::setWepEnabled( bool w ) +{ + tabSecurity->setShown(w); +}*/ + +/*void ui_NetParamsEdit::setEssidEnabled( bool e ) +{ + boxEssid->setShown(e); +}*/ + +void ui_NetParamsEdit::setValues( const WANetParams & np ) +{ + boxEssid->setShown(np.hiddenEssid); + essid->setText(np.essid); + + tabNetParams->setTabEnabled( tabSecurity, (np.wep || np.wpa) ); + + if ( tabSecurity->isEnabled() ) { + groupWep->setEnabled( np.wep ); + groupWpa->setEnabled( np.wpa ); + if (np.wep) { + if (np.wepMode=="open") + radioWepOpen->setChecked(1); + else + radioWepRestricted->setChecked(1); + if ( np.wepKey.left(2)=="s:" ) { //ASCII key + checkWepAscii->setChecked(true); + wepKey->setText( np.wepKey.right(np.wepKey.length()-2) ); + } else { //HEX key + checkWepAscii->setChecked(false); + wepKey->setText( np.wepKey ); + } + } + if (np.wpa) { + labelWpaSettings->setText( QString("<i>%1</i>").arg( np.wpaSettings.join("<br>") ) ); + if ( np.wpaKey.left(2)=="s:" ) { //ASCII key + checkWpaAscii->setChecked(true); + wpaKey->setText( np.wpaKey.right(np.wpaKey.length()-2) ); + } else { //HEX key + checkWpaAscii->setChecked(false); + wpaKey->setText( np.wpaKey ); + } + } + } + + radioDhcp->setChecked( np.dhcp ); + radioManualConfig->setChecked( !np.dhcp ); + + ip->setText(np.ip); + broadcast->setText( np.broadcast ); + netmask->setText( np.netmask ); + gateway->setText( np.gateway ); + domain->setText( np.domain ); + dns1->setText( np.dns1 ); + dns2->setText( np.dns2 ); + + preConnectionCommand->setText( np.preConnectionCommand ); + preConnectionDetached->setChecked( np.preConnectionDetached ); + preConnectionTimeout->setValue( np.preConnectionTimeout ); + + postConnectionCommand->setText( np.postConnectionCommand ); + postConnectionDetached->setChecked( np.postConnectionDetached ); + postConnectionTimeout->setValue( np.postConnectionTimeout ); + + preDisconnectionCommand->setText( np.preDisconnectionCommand ); + preDisconnectionDetached->setChecked( np.preDisconnectionDetached ); + preDisconnectionTimeout->setValue( np.preDisconnectionTimeout ); + + postDisconnectionCommand->setText( np.postDisconnectionCommand ); + postDisconnectionDetached->setChecked( np.postDisconnectionDetached ); + postDisconnectionTimeout->setValue( np.postDisconnectionTimeout ); +} + +WANetParams ui_NetParamsEdit::readNetParams( WANetParams & np ) +{ + if (np.hiddenEssid) { + np.wasHiddenEssid = true; + np.essid = essid->text(); + } + np.dhcp = radioDhcp->isChecked(); + np.ip = ip->text(); + np.broadcast = broadcast->text(); + np.netmask = netmask->text(); + np.gateway = gateway->text(); + np.domain = domain->text(); + np.dns1 = dns1->text(); + np.dns2 = dns2->text(); + if (np.wep) { // WEP authentication needed + np.wasWep = true; + if (radioWepOpen->isChecked()) + np.wepMode = "open"; + else + np.wepMode = "restricted"; + np.wepKey = wepKey->text(); + if (checkWepAscii->isChecked()) + np.wepKey.prepend("s:"); + } + if (np.wpa) { // WPA authentication needed + np.wpaKey = wpaKey->text(); + if (checkWpaAscii->isChecked()) + np.wpaKey.prepend("s:"); + } + + + np.preConnectionCommand = preConnectionCommand->text(); + np.preConnectionTimeout = preConnectionTimeout->value(); + np.preConnectionDetached = preConnectionDetached->isChecked(); + + np.postConnectionCommand = postConnectionCommand->text(); + np.postConnectionTimeout = postConnectionTimeout->value(); + np.postConnectionDetached = postConnectionDetached->isChecked(); + + np.preDisconnectionCommand = preDisconnectionCommand->text(); + np.preDisconnectionTimeout = preDisconnectionTimeout->value(); + np.preDisconnectionDetached = preDisconnectionDetached->isChecked(); + + np.postDisconnectionCommand = postDisconnectionCommand->text(); + np.postDisconnectionTimeout = postDisconnectionTimeout->value(); + np.postDisconnectionDetached = postDisconnectionDetached->isChecked(); + + return np; +} + +#include "ui_netparamsedit.moc" + diff --git a/src/ui_netparamsedit.h b/src/ui_netparamsedit.h new file mode 100644 index 0000000..4c3b8b0 --- /dev/null +++ b/src/ui_netparamsedit.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef UI_NETPARAMSEDIT_H +#define UI_NETPARAMSEDIT_H + +#include "ui_NetParamsEdit.h" + +class WANetParams; + +class ui_NetParamsEdit : public netProperties +{ + Q_OBJECT + +public: + ui_NetParamsEdit(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~ui_NetParamsEdit(); + /*$PUBLIC_FUNCTIONS$*/ + //void setWepEnabled( bool w ); + //void setEssidEnabled( bool e ); + void setValues( const WANetParams & np ); + WANetParams readNetParams( WANetParams & np ); + +public slots: + /*$PUBLIC_SLOTS$*/ + +protected: + /*$PROTECTED_FUNCTIONS$*/ + +protected slots: + /*$PROTECTED_SLOTS$*/ + +}; + +#endif + diff --git a/src/ui_netparamswizard.cpp b/src/ui_netparamswizard.cpp new file mode 100644 index 0000000..9945eea --- /dev/null +++ b/src/ui_netparamswizard.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include "ui_netparamswizard.h" +#include "netparams.h" + +#include <qpushbutton.h> +#include <qradiobutton.h> +#include <qlineedit.h> +#include <qcheckbox.h> +#include <qlabel.h> + +#include <kiconloader.h> + +ui_NetParamsWizard::ui_NetParamsWizard(QWidget* parent, const char* name, bool modal, WFlags fl) + : NetParamsWizard(parent,name, modal,fl) +{ + backButton()->setIconSet( SmallIconSet("back") ); + nextButton()->setIconSet( SmallIconSet("forward") ); + cancelButton()->setIconSet( SmallIconSet("cancel") ); + finishButton()->setIconSet( SmallIconSet("ok") ); + //helpButton()->setIconSet( SmallIconSet("help") ); + helpButton()->hide(); + setFinishEnabled( page( pageCount()-1 ), true ); +} + +ui_NetParamsWizard::~ui_NetParamsWizard() +{} + +/*$SPECIALIZATION$*/ + +void ui_NetParamsWizard::setWepEnabled( bool w ) +{ + setAppropriate( page(4), w ); +} + +void ui_NetParamsWizard::setWpaEnabled( bool w, QStringList settings ) +{ + setAppropriate( page(5), w ); + if (w) labelWpaSettings->setText( QString("<i>%1</i>").arg( settings.join("<br>") ) ); +} + + +void ui_NetParamsWizard::setEssidEnabled( bool e ) +{ + setAppropriate( page(1), e ); +} + +void ui_NetParamsWizard::next() +{ + if (indexOf(currentPage())==2) + setAppropriate( page(3), radioManualConfig->isChecked() ); + QWizard::next(); +} + +WANetParams ui_NetParamsWizard::readNetParams( WANetParams & np ) +{ + if (appropriate(page(1))) + np.essid = essid->text(); + np.dhcp = radioDhcp->isChecked(); + if (!np.dhcp) { // manual configuration option selected + np.ip = ip->text(); + np.broadcast = broadcast->text(); + np.netmask = netmask->text(); + np.gateway = gateway->text(); + np.domain = domain->text(); + np.dns1 = dns1->text(); + np.dns2 = dns2->text(); + } + if (np.wep) { // WEP authentication needed + if (radioWepOpen->isChecked()) + np.wepMode = "open"; + else + np.wepMode = "restricted"; + np.wepKey = wepKey->text(); + if (checkWepAscii->isChecked()) + np.wepKey.prepend("s:"); + } + if (np.wpa) { // WPA authentication needed + np.wpaKey = wpaKey->text(); + if (checkWpaAscii->isChecked()) + np.wpaKey.prepend("s:"); + } + + return np; +} + +#include "ui_netparamswizard.moc" + diff --git a/src/ui_netparamswizard.h b/src/ui_netparamswizard.h new file mode 100644 index 0000000..fc3dfcb --- /dev/null +++ b/src/ui_netparamswizard.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef UI_NETPARAMSWIZARD_H +#define UI_NETPARAMSWIZARD_H + +#include "ui_NetParamsWizard.h" + + +class WANetParams; +class ui_NetParamsWizard : public NetParamsWizard +{ + Q_OBJECT + +public: + ui_NetParamsWizard(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~ui_NetParamsWizard(); + /*$PUBLIC_FUNCTIONS$*/ + void setWepEnabled( bool w ); + void setWpaEnabled( bool w, QStringList settings = QStringList() ); + void setEssidEnabled( bool e ); + WANetParams readNetParams( WANetParams & np ); + +public slots: + /*$PUBLIC_SLOTS$*/ + +protected: + /*$PROTECTED_FUNCTIONS$*/ + +protected slots: + /*$PROTECTED_SLOTS$*/ + virtual void next(); +}; + +#endif + diff --git a/src/waconfig.cpp b/src/waconfig.cpp new file mode 100644 index 0000000..aadad38 --- /dev/null +++ b/src/waconfig.cpp @@ -0,0 +1,29 @@ +#include "waconfig.h" + +#include <kstaticdeleter.h> + +WAConfig *WAConfig::mSelf = 0; +static KStaticDeleter<WAConfig> staticWAConfigDeleter; + +WAConfig *WAConfig::self() +{ + if ( !mSelf ) { + staticWAConfigDeleter.setObject( mSelf, new WAConfig() ); + mSelf->readConfig(); + } + + return mSelf; +} + +WAConfig::WAConfig( ) + : KConfigSkeleton( QString::fromLatin1( "wlassistantrc" ) ) +{ + mSelf = this; +} + +WAConfig::~WAConfig() +{ + if ( mSelf == this ) + staticWAConfigDeleter.setObject( mSelf, 0, false ); +} + diff --git a/src/waconfig.h b/src/waconfig.h new file mode 100644 index 0000000..bedcaf1 --- /dev/null +++ b/src/waconfig.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WACONFIG_H +#define WACONFIG_H + +#include <kconfigskeleton.h> + +class WAConfig : public KConfigSkeleton +{ + public: + + static WAConfig *self(); + ~WAConfig(); + + static + void writeConfig() + { + static_cast<KConfigSkeleton*>(self())->writeConfig(); + } + protected: + + WAConfig(); + static WAConfig *mSelf; +}; + +#endif + diff --git a/src/watools.cpp b/src/watools.cpp new file mode 100644 index 0000000..5814274 --- /dev/null +++ b/src/watools.cpp @@ -0,0 +1,312 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "watools.h" + +#include <unistd.h> //provides readlink +#include <dirent.h> +#include <stdio.h> //to get values from /sys +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> //inet_ntoa +#include <iostream> //debugging + +char* WATools::ifname = 0; +int WATools::iw_socket = -1; +int WATools::prev_tx_packets = 0; +int WATools::prev_rx_packets = 0; + +////////////////////// +///// GENERAL INTERFACE CALLS +bool WATools::isUp( const char* _ifname ) ///returns true if specified interface is up. Uses request SIOCGIFFLAGS +{ + if (_ifname==0) + _ifname = ifname; + + struct ifreq req; + if ( doRequest( SIOCGIFFLAGS, &req, _ifname ) < 0) // get interface flags + return 0; +// ( req.ifr_flags & IFF_UP ) ? std::cout << "* UP: YES" << std::endl : std::cout << "* UP: NO" << std::endl; + return ( req.ifr_flags & IFF_UP ); +} + +bool WATools::setUp( bool u, const char* _ifname ) /// brings interface up or down. Requests SIOCGIFFLAGS and SIOCSIFFLAGS +{ + if (_ifname==0) + _ifname = ifname; + + struct ifreq req; + if ( doRequest( SIOCGIFFLAGS, &req, _ifname ) < 0 ) //get current flags, so they're not reset + return 0; + + if ( u != (req.ifr_flags & IFF_UP) ) + req.ifr_flags ^= IFF_UP; //change value of IFF_UP flag (XOR) + + return ( doRequest( SIOCSIFFLAGS, &req, _ifname ) > -1 ); //set up/down flag, > -1 if succeeded +} + +char* WATools::ip( const char* _ifname ) ///returns current IP. Request SIOCGIFADDR +{ + if (_ifname==0) + _ifname = ifname; + + struct ifreq req; + static char buffer[16]; + if ( doRequest( SIOCGIFADDR, &req, _ifname ) < 0 ) + strcpy( buffer, "0.0.0.0" ); + else + strcpy( buffer, inet_ntoa( ((sockaddr_in*)&req.ifr_addr)->sin_addr ) ); +// std::cout << "* IP ADDRESS: " << buffer << std::endl; + return buffer; +} + +int WATools::txpackets( const char* _ifname ) ///returns number of packets send via _iface +{ + if (_ifname==0) + _ifname = ifname; + + return getStatistic( "tx_packets", _ifname ); +} + +int WATools::rxpackets( const char* _ifname ) ///returns number of packets received via _iface +{ + if (_ifname==0) + _ifname = ifname; + + return getStatistic( "rx_packets", _ifname ); +} + + +////////////////////// +///// WIRELESS EXTENSIONS CALLS + +bool WATools::isWireless( const char* _ifname ) /// returns TRUE if the specified interface supports Wireless Extensions +{ + static iwreq req; + memset( &req, 0, sizeof(req) ); + return ( doWirelessRequest(SIOCGIWNAME, &req, _ifname ) > -1 ); +} + +char* WATools::essid( const char* _ifname ) ///returns current ESSID (for the specified interface). Request SIOCGIWESSID +{ + static iwreq req; + static char buffer[IW_ESSID_MAX_SIZE + 1]; + + memset( buffer, 0, sizeof(buffer) ); + req.u.essid.pointer = buffer; //set pointer of essid string resulting from request to buffer + req.u.essid.length = IW_ESSID_MAX_SIZE; + if( doWirelessRequest(SIOCGIWESSID, &req, _ifname) < 0 ) // try to get ap address. + return 0; // no ap address + return buffer; +} + +char* WATools::ap( const char* _ifname ) ///returns current AP (for the specified interface). Request SIOCGIWAP +{ + static iwreq req; + if( doWirelessRequest(SIOCGIWAP, &req, _ifname) < 0 ) // try to get ap address. + return 0; // no ap address + static char buffer[32]; + iw_ether_ntop( (const struct ether_addr *)req.u.ap_addr.sa_data, buffer ); + +// std::cout << "* AP ADDRESS: " << buffer << std::endl; + return buffer; +} + +int WATools::quality( const char* _ifname ) ///returns active link quality in range 0-100 (for the specified interface) +{ + static iw_statistics stats; + if ( doWirelessStatisticsRequest( &stats, _ifname ) < 0 ) + return 0; + unsigned int std_qual = (100*stats.qual.qual)/50; //calculate normalized quality (0-100). 50 is the best noise/signal difference + if (std_qual > 100) std_qual = 100; + +// std::cout << "* QUALITY: " << std_qual << std::endl; + return std_qual; +} + +int WATools::txpower( const char* _ifname ) ///returns current txpower in mW (for the specified interface). Request SIOCGIWTXPOW +{ + static iwreq req; + if( doWirelessRequest(SIOCGIWTXPOW, &req, _ifname) < 0 ) // try to get txpower. + return 0; // no txpower + else { + if (req.u.txpower.disabled) + return -1; + else + return req.u.txpower.value; + } +} + +bool WATools::hasKey( const char* _ifname ) ///returns true if WEP key for the specified interface is set. Request SIOCGIWENCODE +{ + static iwreq req; + static char buffer[IW_ENCODING_TOKEN_MAX + 1]; + + memset( buffer, 0, sizeof(buffer) ); + req.u.encoding.pointer = buffer; //set pointer of encoding string resulting from request to buffer + req.u.encoding.length = IW_ENCODING_TOKEN_MAX; + + if( doWirelessRequest(SIOCGIWENCODE, &req, _ifname) < 0 ) // try to get current key flags. + return 0; +// ( strlen(buffer)!=0 ) ? std::cout << "* KEY: YES" << std::endl : std::cout << "*KEY: NO" << std::endl; + return ( strlen(buffer)!=0 ); // not encoding token empty +} + +int WATools::availableNetworks( const char* _ifname ) //returns a list of available networks +{ + static struct wireless_scan_head context; + static struct wireless_scan* scan; + + if (_ifname==0) + _ifname = ifname; + if (iw_socket<0) + iw_socket = iw_sockets_open(); //get kernel socket + if (iw_socket<0) + return 0; + + iw_scan( iw_socket, (char*)_ifname, iw_get_kernel_we_version(), &context ); + scan = context.result; + + int i = 0; + if ( scan = context.result ) do { + char buffer[32]; + //iw_ether_ntop( (const struct ether_addr *)scan->ap_addr.sa_data, buffer ); + //printf( "ESSID: %s, quality: %i\n", scan->b.essid, scan->stats.qual.qual ); + i++; + } while (scan = scan->next); + printf( "WATools: Networks found: %i\n", i ); +} + + +////////////////////// +///// MISC FUNCTIONS + +bool WATools::isConnected( const char* _ifname ) ///returns true if interface is properly configured and associated +{ + bool ret; + if ( WATools::isUp( _ifname ) && \ + (strcmp( WATools::ip( _ifname ), "0.0.0.0" ) != 0) && \ + (strcmp( WATools::ap( _ifname ), "00:00:00:00:00:00" ) != 0) && \ + (WATools::quality( _ifname ) > 0) ) { + int tx = txpackets( _ifname); + if ( tx > prev_tx_packets + WA_TX_THRESHOLD ) { + prev_tx_packets = tx; + int rx = rxpackets( _ifname ); + if ( rx > prev_rx_packets ) { + prev_rx_packets = rx; + ret = 1; + } else { // no packets received since last change + std::cout << "Connection lost (TX threshold exceeded)" << std::endl; + ret = 0; + } + } else ret = 1; // no packets sent since last check + } else ret = 0; + return ret; +} + +char* WATools::kernelModule( const char* _ifname ) ///returns KERNEL MODULE name for the given interface +{ + /// DOES SOMEONE KNOW A BETTER WAY TO RETRIEVE IT? + char origPath[64], symPath[64]; + static char module[32]; + char* p; + sprintf( origPath, "/sys/class/net/%s/device/driver", _ifname ); + memset( &symPath, 0, sizeof(symPath) ); + readlink( (const char*)origPath, symPath, sizeof(symPath) ); + p = strtok( symPath, "/" ); + do { + strcpy( module, p ); + p = strtok( NULL, "/" ); + } while ( p != NULL ); //last part of the symlinked directory is the module name used for the interface. + return module; +} + + +////////////////////// +///// PRIVATE CONVENIENCE FUNCTIONS + +int WATools::getStatistic( const char* statName, const char* _ifname ) +{ + if (_ifname==0) + _ifname = ifname; + + char path[64]; + sprintf( path, "/sys/class/net/%s/statistics/%s", _ifname, statName ); + + FILE* f = fopen( path, "r" ); + void* ptr; + static char buffer[16]; + fgets(buffer, sizeof(buffer), f); + fclose(f); + return atoi( buffer ); //convert string to integer +} + +int WATools::doRequest( int request, struct ifreq* reqStruct, const char* _ifname ) +{ + if (_ifname==0) + _ifname = ifname; + if (iw_socket<0) + iw_socket = iw_sockets_open(); //get kernel socket + if (iw_socket<0) + return 0; + + memset( reqStruct, 0, sizeof(reqStruct) ); + strncpy(reqStruct->ifr_name, _ifname, IFNAMSIZ); + return ioctl(iw_socket, request, reqStruct); +} + +int WATools::doWirelessRequest( int request, struct iwreq* reqStruct, const char* _ifname ) +{ + if (_ifname==0) + _ifname = ifname; + if (iw_socket<0) + iw_socket = iw_sockets_open(); //get kernel socket + if (iw_socket<0) + return 0; + + memset( reqStruct, 0, sizeof(reqStruct) ); + strncpy(reqStruct->ifr_name, _ifname, IFNAMSIZ); + return ioctl(iw_socket, request, reqStruct); +} + +int WATools::doWirelessStatisticsRequest( iw_statistics* iwStats, const char* _ifname ) +{ + if (_ifname==0) + _ifname = ifname; + if (iw_socket<0) + iw_socket = iw_sockets_open();//get kernel socket + if (iw_socket<0) + return 0; + + unsigned int has_range; + iw_range range; + + if ( iw_get_range_info(iw_socket, _ifname, &range) < 0 ) + has_range = 0; + else + has_range = 1; + return iw_get_stats(iw_socket, _ifname, iwStats, &range, has_range); +} + +void WATools::cleanup() +{ + if (!iw_socket<0) + iw_sockets_close(iw_socket); +} diff --git a/src/watools.h b/src/watools.h new file mode 100644 index 0000000..e2088e5 --- /dev/null +++ b/src/watools.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WATOOLS_H +#define WATOOLS_H + +//maximum number of packets send without any received. When it's exceeded, the connection is considered lost. +#define WA_TX_THRESHOLD 14 + +#include <iwlib.h> +#include <time.h> +class QStringList; + +class WATools +{ +public: + static inline void setInterface( const char* new_ifname ) //sets default (fallback) interface + { + ifname = (char*)new_ifname; + } + static inline char* interface() //returns default (fallback) interface + { + return ifname; + } + // general interface functions + static bool isUp( const char* _ifname = 0 ); //returns current STATUS + static bool setUp( bool u, const char* _ifname = 0 ); //bring interface up/down + static char* ip( const char* _ifname = 0 ); //returns current IP + static int txpackets( const char* _ifname = 0 ); //returns number of packets send via _iface + static int rxpackets( const char* _ifname = 0 ); //returns number of packets received via _iface + + // wireless extensions calls + static bool isWireless( const char* _ifname ); //returns true if iface is a valid wireless interface + static char* essid( const char* _ifname = 0 ); //returns current ESSID + static char* ap( const char* _ifname = 0 ); //returns current AP + static int quality( const char* _ifname = 0 ); //returns current QUALITY + static int txpower( const char* _ifname = 0 ); //returns current TXPOWER + + static bool hasKey( const char* _ifname = 0 ); //returns true if WEP key for the specified interface is set + + static int availableNetworks( const char* _ifname = 0 ); //returns a list of available networks + + // misc functions + static bool isConnected( const char* _ifname = 0 ); //returns true if the interface is properly CONFIGURED AND ASSOCIATED + static char* kernelModule( const char* _ifname = 0 ); //returns KERNEL MODULE name for the given interface + static void cleanup(); //closes open socket etc. + +private: + static char* ifname; + static int iw_socket; + static int prev_tx_packets, prev_rx_packets; + + static int getStatistic( const char* statName, const char* _ifname = 0 ); + static int doRequest( int request, struct ifreq* reqStruct, const char* _ifname = 0 ); + static int doWirelessRequest( int request, struct iwreq* reqStruct, const char* _ifname = 0 ); + static int doWirelessStatisticsRequest( iw_statistics* iwStats, const char* _ifname = 0 ); +}; + +#endif //WATOOLS_H diff --git a/src/wlassistant.cpp b/src/wlassistant.cpp new file mode 100644 index 0000000..bf58914 --- /dev/null +++ b/src/wlassistant.cpp @@ -0,0 +1,1264 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "wlassistant.h" +#include "netlistviewitem.h" +#include "waconfig.h" +#include "watools.h" +#include "ui_netparamswizard.h" +#include "ui_netparamsedit.h" + +#include <iostream> +#include <linux/version.h> //provides LINUX_VERSION* macros + +#include <qregexp.h> +#include <qlabel.h> +#include <qprocess.h> +#include <qcursor.h> +#include <qeventloop.h> +#include <qtimer.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <qwidgetstack.h> +#include <qtooltip.h> + +#include <kpushbutton.h> +#include <kcombobox.h> +#include <klistview.h> +#include <kapplication.h> +#include <kiconloader.h> +#include <kmessagebox.h> +#include <kpopupmenu.h> +#include <klocale.h> +#include <kstandarddirs.h> + +WirelessAssistant::WirelessAssistant(QWidget* parent, const char* name, bool modal, WFlags fl) + : mainWindow(parent,name, modal,fl) +{ + buttonScan->setIconSet( SmallIconSet("reload") ); + buttonConnect->setIconSet( SmallIconSet("connect_creating") ); + buttonOptions->setIconSet( SmallIconSet("configure") ); + buttonClose->setIconSet( SmallIconSet("fileclose") ); + + netList->setAllColumnsShowFocus(1); + netList->setItemMargin(8); + frameDevice->hide(); + + /// Network List Widget + connect( buttonScan, SIGNAL(clicked()), + this, SLOT(netScan()) ); + + connect( buttonConnect, SIGNAL(clicked()), + this, SLOT(itemAction()) ); + + connect( buttonClose, SIGNAL(clicked()), + this, SLOT(close()) ); + + connect( devCombo, SIGNAL(activated( const QString & )), + this, SLOT(setDev( const QString & )) ); + + connect( netList, SIGNAL(rightButtonPressed( QListViewItem*, const QPoint&, int )), + SLOT(showItemContextMenu( QListViewItem*, const QPoint&, int )) ); + + /// Settings Widget + connect( buttonOptions, SIGNAL(toggled(bool)), + this, SLOT(togglePage(bool)) ); + + connect( buttonEnableAllMessages, SIGNAL(clicked()), + this, SLOT(enableAllMessages()) ); + + /// Global KDE Options + connect( KApplication::kApplication(), SIGNAL(settingsChanged(int)), + this, SLOT(updateConfiguration(int)) ); + + setMouseBehaviour(); + + QTimer::singleShot(10, this, SLOT(init()) ); //WAIT FOR THE UI TO BE READY BEFORE FURTHER SETUP (msec) +} + +WirelessAssistant::~WirelessAssistant() +{} + +/*$SPECIALIZATION$*/ + + +void WirelessAssistant::init() +{ + statusLabel->setText(i18n("Initializing...")); + statusLabel->repaint(); + + //////////////////////////////////////// + ///// CHECK FOR SYSFS (KERNEL 2.6) ///// + if ( !QFile::exists("/sys") ) { + std::cout << "Sysfs not present. Exiting." << std::endl; + KMessageBox::error( 0, i18n("Kernel 2.6 or later not present.\nWireless Assistant will now quit.") ); + close(); + return; + } + + ///////////////////////////////////////////////////// + ///// LOAD CONFIG FILE INCL. ALL NET PARAMETERS ///// + WAConfig::self()->setCurrentGroup("Global Options"); + WAConfig::self()->addItemBool("Auto Quit", autoQuit); + WAConfig::self()->addItemBool("Auto Reconnect", autoReconnect); + WAConfig::self()->addItemBool("Auto Connect", autoConnect); + WAConfig::self()->addItemInt("Delay Before Scanning", DelayBeforeScanning); + WAConfig::self()->addItemBool("Group APs", groupAPs); + WAConfig::self()->addItemInt("DHCP Client Timeout", DhcpTimeout); + WAConfig::self()->addItemString("Interface", NetParams.iface); + + WAConfig::self()->setCurrentGroup("Paths"); + // Commented out cos no longer needed. Paths are detected when necessary. + /*WAConfig::self()->addItemString("DHCP Info (dhcpcd)", dhcpcdInfoPath); + WAConfig::self()->addItemString("DHCP PID File (dhcpcd)", dhcpcdPidPath); + WAConfig::self()->addItemString("DHCP Info (dhclient)", dhclientInfoPath); + WAConfig::self()->addItemString("DHCP PID File (dhclient)", dhclientPidPath);*/ + + WAConfig::self()->setCurrentGroup("Network Parameters"); + WAConfig::self()->addItemStringList("NetParamsList", NetParamsList ); + WAConfig::self()->readConfig(); + checkAutoQuit->setChecked(autoQuit); + checkAutoReconnect->setChecked(autoReconnect); + checkAutoConnect->setChecked(autoConnect); + checkGroupAPs->setChecked(groupAPs); + if (!DelayBeforeScanning) + DelayBeforeScanning = spinDelayBeforeScanning->value(); + else + spinDelayBeforeScanning->setValue(DelayBeforeScanning); + if (!DhcpTimeout) + DhcpTimeout = spinDhcpTimeout->value(); + else + spinDhcpTimeout->setValue(DhcpTimeout); + + std::cout << "Loaded application options." << std::endl; + + /////////////////////////////////// + ///// DETECT WIRELESS DEVICES ///// + QStringList devList = interfaceList(); + if ( devList.count()==0 ) { + std::cout << "No wireless interfaces found. Exiting." << std::endl; + KMessageBox::error(0, i18n("No usable wireless devices found.\nWireless Assistant will now quit.")); + close(); + return; + } + std::cout << "Wireless interface(s): " << devList.join(", ") << std::endl; + devCombo->insertStringList(devList); + + if (devCombo->count() > 1) { //check if last used (saved) interface is available (only if more that 1 interface present). + for (int i=0; i<devCombo->count(); i++) { + if ( devCombo->text(i)==NetParams.iface ) { //select matching interface. + devCombo->setCurrentItem( i ); + break; + } + } + frameDevice->show(); //only if more than 1 wireless device. + } + NetParams.iface = devCombo->currentText(); // set interface name + WATools::setInterface( NetParams.iface ); // set fallback interface for WATools + + ////////////////////////////////// + ///// CHECK FILE PERMISSIONS ///// + if (!QFileInfo("/etc/resolv.conf").isWritable()) { + std::cout << "warning: /etc/resolv.conf not writable" << std::endl; + KMessageBox::information(0, i18n("<qt><p>You might have insufficient permissions for Wireless Assistant to function properly.</p><p>Did you run it using '<tt>sudo</tt>'?</p></qt>") ); + } + std::cout << "Permissions checked." << std::endl; + + ////////////////////////////////// + ///// INITIALIZE COMMANDS + Commands.init(); + + /////////////////////////////////////// + ///// INITIALIZE GLOBAL VARIABLES ///// + wpaAvailable = ( !( Commands.wpa_supplicant.isEmpty() || Commands.wpa_cli.isEmpty() ) ); + connectedItem = 0; + timerGui = new QTimer(); + timerConnectionCheck = new QTimer(); + connect( timerGui, SIGNAL(timeout()), SLOT(updateConnectedItem()) ); + connect( timerConnectionCheck, SIGNAL(timeout()), SLOT(checkConnectionStatus()) ); + + //////////////////////// + ///// DETECT & SET PATHS ///// + if (!Commands.allFound) { //all ok or ONLY dhcpcd not found (i.e. dhclient present). + std::cout << "Missing executables (" << Commands.notFound.join("', '") << "). Exiting." << std::endl; + KMessageBox::error(0, i18n("Executable(s) '%1' could not be found.\nWireless Assistant will now quit.").arg(Commands.notFound.join("', '")) ); + close(); + return; + } + + KStandardDirs standardDirs; + wpaConfigFile = standardDirs.saveLocation("config").append("wlassistantwpa"); + + /////////////////////////////////////// + ///// SCAN FOR AVAILABLE NETWORKS ///// + if ( autoConnect ) + QTimer::singleShot( 0, this, SLOT(netAutoConnect()) ); + else + QTimer::singleShot( 0, this, SLOT(netScan()) ); +} + +void WirelessAssistant::checkConnectionStatus() +{ + QListViewItem* lvi; + if (groupAPs) lvi = getItemByEssid( WATools::essid(NetParams.iface)); + else lvi = getItemByAp( WATools::ap(NetParams.iface )); + bool needsKey; + lvi ? needsKey = static_cast<NetListViewItem*>(lvi)->enc() : needsKey = 0; + if ( WATools::isConnected(NetParams.iface) && WATools::hasKey(NetParams.iface)==needsKey ) { //connection OK + if (!connectedItem) { + std::cout << "Now connected to '" << WATools::essid(NetParams.iface) << "'" << std::endl; + if (groupAPs && NetParams.ap=="any") { + setConnectedItem( WATools::essid( NetParams.iface ) ); + setNetParamsFromConfig( WATools::essid( NetParams.iface ) ); + } else { + setConnectedItem( WATools::ap( NetParams.iface ) ); + setNetParamsFromConfig( WATools::ap( NetParams.iface ) ); + } + setNetParamsFromList( connectedItem ); + } + } else if (connectedItem) { //connection LOST + setConnectedItem(0); + timerConnectionCheck->stop(); + if ( autoReconnect || KMessageBox::questionYesNo(0, i18n("Connection to '%1' has been lost!\nWould you like to reconnect?").arg(NetParams.essid), i18n("Connection Lost") , KStdGuiItem::yes(), KStdGuiItem::no() ) == KMessageBox::Yes ) { + netDisconnect( true ); + netConnect(); + } + timerConnectionCheck->start( WA_CONNECTION_CHECK_INTERVAL ); + } +} + +void WirelessAssistant::removeNetParams() +{ + NetListViewItem *nvi = static_cast<NetListViewItem*>(netList->selectedItem()); + QString ap = nvi->ap(); QString essid = nvi->essid(); + for (QStringList::Iterator nps = NetParamsList.begin(); nps != NetParamsList.end(); nps++) { + if ( (*nps).section(",",2,2)==ap && (*nps).section(",",1,1)==essid) { + if ( KMessageBox::warningContinueCancel(0, i18n("<qt><p>Settings for network '<b>%1</b>' are about to be deleted.</p><p>Would you like to continue?</p></qt>").arg(essid)) == KMessageBox::Continue ) { + if (nvi->hidden()) // hiddenEssid = 1 + nvi->setEssid("<hidden>"); + NetParamsList.remove(nps); + WAConfig::self()->writeConfig(); + statusLabel->setText( i18n("Settings deleted.") ); + } + break; + } + } +} + + +void WirelessAssistant::setDNS( const WANetParams & np ) +{ + QFile f("/etc/resolv.conf"); + if (f.open( IO_WriteOnly | IO_Truncate )) { + QTextStream s( &f ); + if (!np.domain.isEmpty()) { + s << QString("domain " + np.domain + "\n"); + std::cout << "resolv.conf: domain " << np.domain << std::endl; + } + if (!np.dns1.isEmpty()) { + s << QString("nameserver " + np.dns1 + "\n"); + std::cout << "resolv.conf: nameserver " << np.dns1 << std::endl; + } + if (!np.dns2.isEmpty()) { + s << QString("nameserver " + np.dns2 + "\n"); + std::cout << "resolv.conf: nameserver " << np.dns2 << std::endl; + } + f.close(); + } else { + std::cout << "dns setup error: " << f.name() << " is not writeable." << std::endl; + KMessageBox::error(0, i18n("<qt><p>File '<i>%1</i>' could not be opened for writing.</p><p>Nameserver(s) and/or domain are not set.</p></qt>").arg(f.name()) ); + } +} + +void WirelessAssistant::netScan() +{ + timerConnectionCheck->stop(); //stop while scanning. + netScan( NetParams ); + if (netList->childCount() > 0) { + QTimer::singleShot( 0, this, SLOT(checkConnectionStatus()) ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); + } +} + +void WirelessAssistant::netScan( const WANetParams & np ) +{ + if (!radioEnabled()) { + statusLabel->setText("Radio off. Scanning aborted."); + std::cout << "Radio is off!" << std::endl; + setUi(1); + return; + } + + setUi(0); + + bool wasConnected = false; + if (connectedItem) { + wasConnected = true; + setConnectedItem( 0 ); + } + + if ( !WATools::isUp(np.iface) ) { + statusLabel->setText(i18n("Bringing interface %1 up...").arg(np.iface)); + //runCommand( Commands.cmd("ifup",np) ); + WATools::setUp(true, np.iface); + if (DelayBeforeScanning>0) { + statusLabel->setText(i18n("Waiting before scanning...")); + statusLabel->repaint(); + KApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput ); + usleep(DelayBeforeScanning * 1000000); // delay * 1000ms + } + } + + statusLabel->setText(i18n("Scanning...")); + statusLabel->repaint(); + + netList->clear(); + + QString result; + statusLabel->setText(i18n("Scanning...")); + result = runCommand( Commands.cmd("scan",np) ); + + parseScan( result ); + + if (netList->childCount() > 0) { + std::cout << "Networks found: " << QString::number( netList->childCount() ) << std::endl; + if (wasConnected) + groupAPs ? setConnectedItem( WATools::essid() ) : setConnectedItem( WATools::ap() ); //mark item as connected. + statusLabel->setText( i18n("Done.") ); + } else { + //Workaround for cards overusing cache - bringing if down seems to solve it. + //runCommand( Commands.cmd("ifdown", NetParams) ); //Commented out b/c it seems to cause more problems than it solves. (like no scan results) + std::cout << "No networks found!" << std::endl; + statusLabel->setText( i18n("No networks found.") ); + if ( result.find("Resource temporarily unavailable")>-1 ) { + std::cout << "Radio switch seems to be off." << std::endl; + KMessageBox::information(0, i18n("Radio of your wireless card seems to be turned off using an external switch on your computer.\nYou need turn it on to be able to use wireless networks.") ); + } + } + setNetListColumns(); +} + +void WirelessAssistant::parseScan( const QString & output ) +{ + QString essid; + QStringList essidList; + QString channel; + QString mode; + int qualInt; + bool enc; //default to false + bool hidden; //default to false + QString ap; + + // security parameters + bool wpa; + QStringList wpaSettings; + //QString wpaVersion, wpaGroupCipher, wpaPairwiseCipher, wpaAuthenticationSuite; + + + bool ok_channel = true; //does iwlist return channel? + QString section; + + netList->setUpdatesEnabled( false ); //do not redraw while adding items to avoid flicker. + + for (int i=1; (!output.section("Cell ",i,i).isEmpty()); i++ ) { + section = output.section("Cell ",i,i); + + // GET ESSID VALUE + essid = getVal(section, "ESSID\\W+\"(.+)\""); + + // GET CHANNEL NUMBER + channel = getVal(section, "Channel\\D+(\\d+)" ); + if (channel.isEmpty()) { + channel = getVal(section, "Frequency\\D+(\\d.+)Hz"); + ok_channel = false; + } + + // GET MODE VALUE + mode = getVal(section, "Mode:(\\w)"); //get 1st letter of mode. + if (mode.upper()!="M") //this covers both Managed and Master. Other are unsupported. + continue; + + // GET AP + ap = getVal(section, "Address\\W+(\\S+)"); + + if (essid.isEmpty()) { + if (!ap.isEmpty()) //older wireless-tools report "", not "<hidden>" + essid = "<hidden>"; + else + continue; //some cards report one '' essid even when no network's present. Workaround. + } + + if (essid=="<hidden>") { + hidden = true; + essid = matchEssidForAp( ap ); + } else + hidden=false; + + // GET QUALITY + int wsignal; + //check if driver reports quality directly + qualInt = getVal(section, "Quality\\D+(\\d+)").toInt(); + + if (qualInt == 0) { //noise not reported? estimate. + wsignal = getVal(section, "Signal level\\D+(\\d+)" ).toInt(); + qualInt = 100-wsignal; + } + qualInt = (100*qualInt)/50; //adjust and normalize quality (0-100). 50 is the best (6 stars) noise/signal difference + if (qualInt > 100) qualInt = 100; + + // GET ENCRYPTION + if (getVal(section, "Encryption key\\W+(\\w+)" ).upper()=="OFF") + enc = false; + else { + enc = true; + + wpaSettings.clear(); + if ( section.contains("WPA2 Version") ) wpaSettings << "WPA2"; //prefer WPA2 over WPA + else if ( section.contains("WPA Version") ) wpaSettings << "WPA"; + + wpa = ( !wpaSettings.isEmpty() ); + if (wpa) { + wpaSettings << getVal(section, "Group Cipher : (\\w+)") \ + << getVal(section, "Pairwise Ciphers \\(\\d+\\) : ([\\w ]+)[\n\r]") \ + << getVal(section, "Authentication Suites \\(\\d+\\) : ([\\w ]+)[\n\r]"); + } + } + + // CHECK IF SAME ESSID ALREADY FOUND, if necessary + if (groupAPs) { + if ( !hidden && essidList.contains(essid) ) { + NetListViewItem* sameEssid = static_cast<NetListViewItem*>(getItemByEssid(essid)); + sameEssid->setAp("any"); + if (sameEssid->quality() < qualInt) { + sameEssid->setQuality(qualInt); + sameEssid->setChannel(channel); + } + continue; + } + essidList << essid; + } + + NetListViewItem* nvi = new NetListViewItem( netList, essid, channel, qualInt, enc, ap, hidden ); + if (wpa) nvi->setWpaSettings( wpaSettings ); + } + + if (!ok_channel) + netList->setColumnText( 1, i18n("Freq (Hz)") ); + + /// @fixme HACK: Test item for the network list. + /// new NetListViewItem( netList, "Test Net", "9", 76, 1, "00:00:00:00:00:11", 0 ); + + + netList->setUpdatesEnabled( true ); + setUi(1); +} + +bool WirelessAssistant::radioEnabled() +{ + bool r; + if ( WATools::txpower()==-1 ) { + if (KMessageBox::questionYesNo(0, i18n("Radio of your wireless card is off.\nWould you like to turn it on?") )== KMessageBox::Yes) { + runCommand( Commands.cmd("radio_on", NetParams) ); + r = true; + } else { + r = false; + } + } else + r = true; + + return r; +} + +void WirelessAssistant::setNetParamsFromList( QListViewItem* lvi ) +{ + NetListViewItem *nvi = static_cast<NetListViewItem*>(lvi); + NetParams.essid = nvi->essid(); + NetParams.hiddenEssid = nvi->hidden(); + //NetParams.mode = nvi->mode(); + NetParams.channel = nvi->channel(); + NetParams.ap = nvi->ap(); + NetParams.wpaSettings = nvi->wpaSettings(); + NetParams.wep = ( nvi->enc() && NetParams.wpaSettings.isEmpty() ); + NetParams.wpa = ( nvi->enc() && !NetParams.wpaSettings.isEmpty() ); +} + +bool WirelessAssistant::setNetParamsFromConfig( const QString & s ) +{ + for (QStringList::Iterator nps = NetParamsList.begin(); nps != NetParamsList.end(); nps++) { + if ( (*nps).section(",",2,2)==s || ( (*nps).section(",",1,1)==s && (*nps).section(",",2,2)=="any") ) { + NetParams.loadNetParamsString( *nps ); + if (!s.contains(":")) NetParams.ap = "any"; //if searched by essid + return 1; + } + } + return 0; +} + +void WirelessAssistant::itemAction() +{ + QListViewItem* lvi = netList->selectedItem(); + if (!lvi) + return; + + NetListViewItem* nvi = static_cast<NetListViewItem*>(lvi); + /////////////////// + ///// ACTIONS ///// + if (nvi->isConnected()) { + std::cout << "ACTION: DISCONNECT." << std::endl; + netDisconnect(); + return; + } else { + std::cout << "ACTION: CONNECT." << std::endl; + netConnect(); + return; + } +} + +void WirelessAssistant::netAutoConnect() +{ + netScan(); + if ( WATools::isConnected(NetParams.iface) ) return; + + int bestItem = -1; + int bestQuality = 0; + for ( int i = 0; i < netList->childCount(); i++ ) { + NetListViewItem* nvi = static_cast<NetListViewItem*>( netList->itemAtIndex(i) ); + QString search = nvi->ap(); + if (search == "any") search = nvi->essid(); + if ( setNetParamsFromConfig(search) ) { + if ( nvi->quality() > bestQuality ) { + bestQuality = nvi->quality(); + bestItem = i; + } + } + } + + if ( bestItem != -1 ) { + NetListViewItem* nvi = static_cast<NetListViewItem*>( netList->itemAtIndex( bestItem ) ); + setNetParamsFromList( nvi ); + QString search = nvi->ap(); + if (search == "any") search = nvi->essid(); + setNetParamsFromConfig( search ); + timerConnectionCheck->stop(); + netConnect( NetParams ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); + } else { + statusLabel->setText( i18n("Auto connection failed.") ); + std::cout << "Auto connection failed: no available configured networks found." << std::endl; + } +} + +void WirelessAssistant::netConnect() +{ + timerConnectionCheck->stop(); + setNetParamsFromList( netList->selectedItem() ); + //can't connect if WPA needed, and wpa_supplicant and wpa_cli not available + if ( NetParams.wpa && !wpaAvailable ) { + KMessageBox::error(0, i18n("<qt><p><b>Can not connect to network '%1'.<b></p><p>The network you are trying to connect to requires WPA authentication. The necessary executables <i>wpa_supplicant</i> and <i>wpa_cli</i> could not be found. Install <i>wpa_supplicant</i> and restart Wireless Assistant to connect.</p></qt>").arg(NetParams.essid) ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); //resume connection checking + return; + } + QString search = NetParams.ap; + if (search == "any") search = NetParams.essid; + if ( (NetParams.essid=="<hidden>") || (!setNetParamsFromConfig( search )) ) { + ui_NetParamsWizard *netwiz = new ui_NetParamsWizard; + if (!NetParams.hiddenEssid) + netwiz->setCaption( i18n("%1 - First Connection Wizard").arg(NetParams.essid) ); + netwiz->setEssidEnabled( NetParams.hiddenEssid ); + netwiz->setWepEnabled( NetParams.wep ); + netwiz->setWpaEnabled( NetParams.wpa, NetParams.wpaSettings ); + netwiz->exec(); + if (netwiz->result()==QDialog::Rejected) { + delete netwiz; + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); //resume connection checking + return; + } else { + NetParams = netwiz->readNetParams( NetParams ); + NetParams.wasHiddenEssid = NetParams.hiddenEssid; //first time values. + NetParams.wasWep = NetParams.wep; + NetParamsList << NetParams.netParamsString(); + if (NetParams.hiddenEssid) + static_cast<NetListViewItem*>(netList->selectedItem())->setEssid( NetParams.essid ); + WAConfig::self()->writeConfig(); + delete netwiz; + } + } + + if (NetParams.review()) + editNetParams(); + updateNetParams(); + netConnect( NetParams ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); +} + +void WirelessAssistant::updateNetParams() +{ + for (QStringList::Iterator nps = NetParamsList.begin(); nps != NetParamsList.end(); nps++) { + if ( (*nps).section(",",2,2)==NetParams.ap ) { + QString newNps = NetParams.netParamsString(); + if ( newNps!=(*nps) ) { + (*nps) = newNps; + WAConfig::self()->writeConfig(); + std::cout << "Network settings updated." << std::endl; + statusLabel->setText( i18n("Network settings updated.") ); + break; + } + } + } +} + +QString WirelessAssistant::matchEssidForAp( const QString & ap ) +{ + for (QStringList::Iterator nps = NetParamsList.begin(); nps != NetParamsList.end(); nps++) { + if ( (*nps).section(",",2,2)==ap ) { + return (*nps).section(",",1,1); //essid + } + } + return "<hidden>"; +} + +void WirelessAssistant::netConnect( const WANetParams & np ) +{ + setUi(0); + + if (connectedItem) + netDisconnect( true ); + else if ( dhcpClientRunning() ) + runCommand( Commands.cmd("kill_dhcp", np) ); //kill any stale DHCP client running + + if ( !np.preConnectionCommand.isEmpty() ) { + std::cout << "Running pre-connection command: " << np.preConnectionCommand << std::endl; + statusLabel->setText( i18n("Running pre-connection command...") ); + runCommand( QStringList::split( " ", np.preConnectionCommand ), np.preConnectionTimeout, np.preConnectionDetached ); + } else + std::cout << "No pre-connection command specified." << std::endl; + + + statusLabel->setText( i18n("Connecting to '%1'...").arg(np.essid) ); + statusLabel->repaint(); + if (!WATools::isUp(np.iface) ) WATools::setUp( true, np.iface ); + //runCommand( Commands.cmd("ifup", np) ); + if ( runCommand( Commands.cmd("iwconfig_set", np) ).find("8B04") > -1 ) { // error 8B04 - Request 'Set Frequency' not supported. + WANetParams np2 = np; + np2.channel = "0"; + runCommand( Commands.cmd("iwconfig_set", np2) ); + } + + runCommand( Commands.cmd("iwconfig_ap", np) ); + + /////////////////////// + ///// RUN WPA CLIENT IF NEEDED + if (np.wpa) { + if ( generateWpaConfigFile( np.essid, np.wpaSettings, np.wpaKey ) ) { + if ( !setWpaClientEnabled( true, np.iface ) ) { + setUi(1); + std::cout << "CONNECTION FAILED." << std::endl; + statusLabel->setText( i18n("Connection failed.") ); + runCommand( Commands.cmd("disconnect", np ) ); + return; + } + } + } + + //////////////////////// + ///// CONFIGURE IP ADDRESS etc. + if (np.dhcp) { //DHCP config + QString dhcp_out = runCommand( Commands.cmd("ifconfig_dhcp", np), DhcpTimeout ); + if ( dhcp_out.contains("::ERR::") && !dhcp_out.contains("bound to ") ) { // 'bound to' is a check for dhclient, which gives some output to stderr even when succeeded + if ( dhcpClientRunning() ) + runCommand( Commands.cmd("kill_dhcp", np) ); //kill any stale DHCP client running (seems it's dhclient only) + setUi(1); + std::cout << "CONNECTION FAILED." << std::endl; + statusLabel->setText( i18n("Connection failed.") ); + runCommand( Commands.cmd("disconnect", np ) ); + return; + } + } else { //manual config + runCommand( Commands.cmd("ifconfig_manual", np) ); + setDNS( np ); + runCommand( Commands.cmd("route_add", np) ); + } + + if ( !np.postConnectionCommand.isEmpty() ) { + std::cout << "Running post-connection command: " << np.postConnectionCommand << std::endl; + statusLabel->setText( i18n("Running post-connection command...") ); + runCommand( QStringList::split( " ", np.postConnectionCommand ), np.postConnectionTimeout, np.postConnectionDetached ); + } else + std::cout << "No post-connection command specified." << std::endl; + + ////////////////////// + ///// CHECK CONNECTION + statusLabel->setText(i18n("Testing connection...")); + usleep(200*1000); //sleep 200ms to make sure all parameters are set. + if ( WATools::isConnected(np.iface)) { + if (autoQuit) + this->close(); + groupAPs ? setConnectedItem( np.essid ) : setConnectedItem( np.ap ); + statusLabel->setText( i18n("Successfully connected to '%1'.").arg(np.essid) ); + setUi(1); + } else { + std::cout << "CONNECTION FAILED." << std::endl; + statusLabel->setText(i18n("Connection failed.")); + runCommand( Commands.cmd("disconnect", np ) ); + setConnectedItem( 0 ); + setUi(1); + if (KMessageBox::questionYesNo(0, i18n("Connection failed.\nWould you like to review settings for this network?"), i18n("Review Settings?") , KStdGuiItem::yes(), KStdGuiItem::no(), "ReviewSettings" ) == KMessageBox::Yes) + editNetParams(); + } +} + +void WirelessAssistant::updateConnectedItem() +{ + connectedItem->setQuality( WATools::quality() ); +} + +void WirelessAssistant::setConnectedItem( const QString & netid ) +{ + timerConnectionCheck->stop(); //stop timer while changing currentItem + if (connectedItem) { + timerGui->stop(); + connectedItem->setConnected( false ); + connectedItem = 0; + } + if (!netid.isEmpty()) { + QListViewItem* lvi; + if (netid.contains(":")) lvi = getItemByAp( netid ); //netid is an AP address + else lvi = getItemByEssid( netid ); + if (lvi) { + NetListViewItem* nvi = static_cast<NetListViewItem*>(lvi); + nvi->setConnected( true ); + connectedItem = nvi; + netList->sort(); // sort to make sure new connectedItem is 1st. + } + } + + if (connectedItem) { + timerGui->start(2500); //update quality indicator every 2.5seconds + } + updateConnectButton( netList->selectedItem() ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); +} + +void WirelessAssistant::netDisconnect( const bool & quiet ) +{ + if ( (quiet) || (KMessageBox::warningContinueCancel(0, i18n("<qt><p>You are about to disconnect from '<b>%1</b>'.</p><p>Would you like to continue?<p></qt>").arg(connectedItem->essid()) )== KMessageBox::Continue ) ) { + timerConnectionCheck->stop(); //stop while disconnecting. + + if ( !NetParams.preDisconnectionCommand.isEmpty() ) { + std::cout << "Running pre-disconnection command: " << NetParams.preDisconnectionCommand << std::endl; + statusLabel->setText( i18n("Running pre-disconnection command...") ); + runCommand( QStringList::split( " ", NetParams.preDisconnectionCommand ), NetParams.preDisconnectionTimeout, NetParams.preDisconnectionDetached ); + } else + std::cout << "No pre-disconnection command specified." << std::endl; + + + statusLabel->setText( i18n("Disconnecting...") ); + statusLabel->repaint(); + setConnectedItem( 0 ); + if ( NetParams.dhcp ) { + if ( dhcpClientRunning() ) { + runCommand( Commands.cmd( "kill_dhcp", NetParams ) ); + statusLabel->setText( i18n("Waiting for DHCP client to shut down...") ); + statusLabel->repaint(); + QTimer* tmr = new QTimer(); + tmr->start(1500, true); //wait 1.5sec for dhcp client to really shutdown, single shot. + while ( tmr->isActive() ) { + KApplication::eventLoop()->processEvents( QEventLoop::AllEvents ); + usleep(75*1000); //75msec on Linux + } + delete tmr; + } + } else { + runCommand( Commands.cmd( "route_del", NetParams ) ); + } + runCommand( Commands.cmd( "disconnect", NetParams ) ); + WATools::setUp( false, NetParams.iface ); + + if ( NetParams.wpa ) + setWpaClientEnabled( false ); + + std::cout << "DISCONNECTED." << std::endl; + + if ( !NetParams.postDisconnectionCommand.isEmpty() ) { + std::cout << "Running post-disconnection command: " << NetParams.postDisconnectionCommand << std::endl; + statusLabel->setText( i18n("Running post-disconnection command...") ); + runCommand( QStringList::split( " ", NetParams.postDisconnectionCommand ), NetParams.postDisconnectionTimeout, NetParams.postDisconnectionDetached ); + } else + std::cout << "No post-disconnection command specified." << std::endl; + + + statusLabel->setText( i18n("Done.") ); + timerConnectionCheck->start(WA_CONNECTION_CHECK_INTERVAL); + } else { + statusLabel->setText( i18n("Cancelled.") ); + } +} + +QListViewItem* WirelessAssistant::getItemByAp( const QString & ap ) +{ + QListViewItem* lvi = netList->firstChild(); + while (lvi) { + if ( static_cast<NetListViewItem*>(lvi)-> + ap() == ap ) { + break; + } + lvi = lvi->nextSibling(); + } + return lvi; +} + +QListViewItem* WirelessAssistant::getItemByEssid( const QString & essid ) +{ + QListViewItem* lvi = netList->firstChild(); + while (lvi) { + if ( static_cast<NetListViewItem*>(lvi)-> + essid() == essid ) { + break; + } + lvi = lvi->nextSibling(); + } + return lvi; +} + + +void WirelessAssistant::updateConfiguration(int category) +{ + if (category == KApplication::SETTINGS_MOUSE) { + setMouseBehaviour(); + return; + } + if (category == -1) { + autoQuit = checkAutoQuit->isChecked(); + autoReconnect = checkAutoReconnect->isChecked(); + autoConnect = checkAutoConnect->isChecked(); + groupAPs = checkGroupAPs->isChecked(); + DelayBeforeScanning = spinDelayBeforeScanning->value(); + DhcpTimeout = spinDhcpTimeout->value(); + } +} + +void WirelessAssistant::togglePage(bool options) +{ + buttonScan->setDisabled(options); + buttonConnect->setDisabled(options); + if (options) { + if (WAConfig::self()->config()->groupList().contains("Notification Messages")>0) + buttonEnableAllMessages->setEnabled(true); + else + buttonEnableAllMessages->setEnabled(false); + widgetStack->raiseWidget(optionsPage); + } else { + widgetStack->raiseWidget(netPage); + updateConfiguration(-1); + } +} + +void WirelessAssistant::enableAllMessages() +{ + KMessageBox::enableAllMessages(); + buttonEnableAllMessages->setEnabled( false ); +} + +void WirelessAssistant::setMouseBehaviour() +{ + if ( KGlobalSettings::singleClick() ) { + disconnect( netList, SIGNAL(selectionChanged(QListViewItem*)), + this, SLOT(updateConnectButton(QListViewItem*)) ); + disconnect( netList, SIGNAL(doubleClicked(QListViewItem*, const QPoint &, int)), + this, SLOT(itemAction()) ); + connect( netList, SIGNAL(clicked(QListViewItem*, const QPoint &, int)), + this, SLOT(itemAction()) ); + buttonConnect->hide(); + } else { + disconnect( netList, SIGNAL(clicked(QListViewItem*, const QPoint &, int)), + this, SLOT(itemAction()) ); + + connect( netList, SIGNAL(selectionChanged(QListViewItem*)), + this, SLOT(updateConnectButton(QListViewItem*)) ); + connect( netList, SIGNAL(doubleClicked(QListViewItem*, const QPoint &, int)), + this, SLOT(itemAction()) ); + buttonConnect->show(); + } +} + +void WirelessAssistant::updateConnectButton(QListViewItem* lvi) +{ + QToolTip::remove + (buttonConnect); + if ( lvi == connectedItem ) { + buttonConnect->setText( i18n("&Disconnect") ); + QToolTip::add + ( buttonConnect, i18n("Disconnect from the selected network") ); + + } else { + buttonConnect->setText( i18n("&Connect") ); + QToolTip::add + ( buttonConnect, i18n("Connect to the selected network") ); + + } +} + +void WirelessAssistant::setDev( const QString & ifname) +{ + NetParams.iface = ifname; + WATools::setInterface( ifname ); + std::cout << "Selected interface: " << ifname << std::endl; + netScan(); +} + +QString WirelessAssistant::runCommand( const QStringList & cmd, int timeout, bool detached ) +{ + if (cmd.isEmpty()) + return QString::null; + + // a very basic and easy-to-workaround attepmt to restrict using dangerous commands via custom commands setting. This *REALLY* needs a working solution. + if ( cmd[0] == "rm" || cmd[0] == "mv" || cmd[0] == "cp" || cmd[0] == "ln" ) return QString::null; + + QProcess* p = new QProcess( this ); + p->setArguments( cmd ); + + p->start(); + if (detached) { + p = 0; + return QString::null; + } + + QTimer* timerProc = new QTimer(); //timeout timer + if ( timeout>0 && !detached ) { + connect( timerProc, SIGNAL(timeout()), p, SLOT(kill()) ); + timerProc->start(timeout*1000); //convert sec to msec + } + + connect(buttonClose, SIGNAL(clicked()), + p, SLOT(kill()) ); + int i = 0; + + while ( p->isRunning() ) { // PROCESS USER EVENTS + KApplication::eventLoop()->processEvents( QEventLoop::AllEvents ); + usleep(75*1000); //75msec on Linux (75000msec on Windows...) + if (i==27) { // ca 2sec have passed and the process is still running. Replace the 'Close' button with 'Stop'. + disconnect(buttonClose, SIGNAL(clicked()), + this, SLOT(close()) ); + buttonClose->setIconSet( SmallIconSet("stop") ); + buttonClose->setText( i18n("&Stop") ); + QToolTip::remove + (buttonClose); + QToolTip::add + ( buttonClose, i18n("Terminate current process\n(%1)").arg( p->arguments().join(" ") ) ); + } + i++; + } + + disconnect(buttonClose, SIGNAL(clicked()), + p, SLOT(kill()) ); + if (i>27) {//set 'stop' back to 'close' if needed + connect(buttonClose, SIGNAL(clicked()), + this, SLOT(close()) ); + buttonClose->setIconSet( SmallIconSet("fileclose") ); + buttonClose->setText( i18n("&Quit") ); + QToolTip::remove + (buttonClose); + QToolTip::add + ( buttonClose, i18n("Quit the application") ); + } + + if (timerProc->isActive()) + timerProc->stop(); + delete timerProc; + QString e = QString( p->readStderr() ); + QString o = QString( p->readStdout() ); + if (!p->normalExit()) { + o.append("::ERR::killed"); + //std::cout << "Process terminated (timed out)." << std::endl; //too much output when checking for internet when it's not available. + } + delete p; + + if (!e.isEmpty()) { + std::cout << "==>stderr: " << e;// << std::endl; + o.append("::ERR::"); + o.append(e); + } + + return o; +} + +void WirelessAssistant::setUi(int uiState) +{ + + if (uiState==0) { + devCombo->setEnabled( false ); + buttonScan->setEnabled( false ); + buttonConnect->setEnabled( false ); + buttonOptions->setEnabled( false ); + KApplication::setOverrideCursor( QCursor(Qt::BusyCursor) ); + } else { + if (devCombo->count() > 0) { + devCombo->setEnabled( true ); + buttonScan->setEnabled( true ); + } + if (netList->childCount() > 0) + buttonConnect->setEnabled( true ); + buttonOptions->setEnabled( true ); + KApplication::restoreOverrideCursor(); + } +} + +void WirelessAssistant::showItemContextMenu( QListViewItem* i, const QPoint& p, int c ) +{ + if (!i) + return; + + NetListViewItem *nvi = static_cast<NetListViewItem*>(i); + + QString search = nvi->ap(); + if (search == "any") search = nvi->essid(); + bool isConfigured = setNetParamsFromConfig(search); + + KPopupMenu *icm = new KPopupMenu(); + icm->insertTitle(nvi->essid()); + if (isConfigured) { + if (nvi->isConnected()) { + icm->insertItem( SmallIcon("connect_no"), i18n("Disconnect..."), this, SLOT(netDisconnect()) ); + //icm->insertItem( SmallIcon("reload"), i18n("Reconnect"), this, SLOT(netConnect()) ); + } else + icm->insertItem( SmallIcon("connect_creating"), i18n("Connect"), this, SLOT(netConnect()) ); + icm->insertSeparator(); + icm->insertItem(i18n("Forget Settings..."), this, SLOT(removeNetParams()) ); + icm->insertItem(i18n("Edit Settings..."), this, SLOT(editNetParams()) ); + } else { + if (nvi->isConnected()) { + icm->insertItem( SmallIcon("connect_no"), i18n("Disconnect..."), this, SLOT(netDisconnect()) ); + //icm->insertItem( SmallIcon("reload"), i18n("Configure and Reconnect..."), this, SLOT(netConnect()) ); + } else + icm->insertItem( SmallIcon("connect_creating"), i18n("Configure and Connect..."), this, SLOT(netConnect()) ); + } + icm->exec( QCursor::pos() ); +} + +void WirelessAssistant::editNetParams() +{ + setNetParamsFromList( netList->selectedItem() ); //prepare NetParams + if (NetParams.ap!="any") setNetParamsFromConfig( NetParams.ap ); //prepare NetParams + else setNetParamsFromConfig( NetParams.essid ); + + ui_NetParamsEdit *netedit = new ui_NetParamsEdit(); + netedit->setValues( NetParams ); + netedit->setCaption( i18n("%1 Settings").arg(NetParams.essid) ); + netedit->exec(); + if (netedit->result() == QDialog::Rejected) { + delete netedit; + return; + } else { //accepted + NetParams = netedit->readNetParams( NetParams ); + updateNetParams(); + } +} + +void WirelessAssistant::setNetListColumns() +{ + int realWidth = netList->viewportSize( netList->contentsWidth(), netList->contentsHeight() ).width(); //calculate actual width taking scrollbars into account + int essidWidth = realWidth - netList->columnWidth(1) - netList->columnWidth(2) - netList->columnWidth(3); + + netList->setColumnWidth(0, essidWidth); + netList->triggerUpdate(); +} + +bool WirelessAssistant::dhcpClientRunning() +{ + QStringList pidPaths; + QString pidFile; + pidPaths << "/etc/" << "/etc/dhcpc/" << "/var/run/"; + if ( Commands.dhcpClient=="dhcpcd" ) + pidFile = QString("dhcpcd-%1.pid").arg(NetParams.iface); + else + pidFile = QString("dhclient.pid"); + + for ( QStringList::Iterator it = pidPaths.begin(); it != pidPaths.end(); ++it ) { + if ( QFile( QString(*it).append(pidFile) ).exists() ) { + std::cout << "Running DHCP client found." << std::endl; + return true; + } + } + std::cout << "No DHCP client running." << std::endl; + return false; +} + +QStringList WirelessAssistant::interfaceList() +{ + QDir d("/sys/class/net"); + QStringList ifList = d.entryList( QDir::Dirs ); + ifList.remove("."); ifList.remove(".."); ifList.remove("lo"); + std::cout << "All interfaces: " << ifList.join(", ") << std::endl; + for (QStringList::Iterator nps = ifList.begin(); nps != ifList.end(); nps++) { + const char* i = *nps; + bool w = WATools::isWireless( i ); + if ( !WATools::isWireless( (const char*)*nps ) ) { + nps = ifList.remove( nps ); nps--; + } + } + return ifList; +} + +QString WirelessAssistant::getVal(const QString & str, const QString & rxs) +{ + QRegExp rx(rxs); + rx.search(str); + return rx.cap(1).stripWhiteSpace(); +} + +bool WirelessAssistant::generateWpaConfigFile( const QString& essid, const QStringList& wpaSettings, const QString& wpaKey ) +{ + // 0 WPA version (1 or 2), 1 group, 2 pairwise, 3 suite + if ( wpaSettings.isEmpty() ) return QString(); + QString c = "ctrl_interface=/var/run/wpa_supplicant\nnetwork={\nscan_ssid=0\nssid=\""; //fast_reauth=1\n + c.append(essid).append("\"\n"); + + // WPA version + c.append("proto=").append(wpaSettings[0]).append("\n"); + + //WPA authentication suite + c.append("key_mgmt="); + if ( wpaSettings[3].contains("PSK") ) c.append("WPA-PSK\n"); + else return QString(); // not supported + + //WPA pairwise cipher + c.append("pairwise="); + c.append( wpaSettings[2] ).append("\n"); + + //WPA group cipher + c.append("group="); + c.append( wpaSettings[1] ).append("\n"); + + //WPA key + QString k = QString(); + if (wpaKey.left(2)=="s:") { // PASSPHRASE + k.append("\""); + k.append( wpaKey.right( wpaKey.length() - 2 ) ); + k.append("\"\n"); + } else + k.append( wpaKey ).append("\n"); // HEX KEY + + c.append("psk=").append(k); + + c.append("}\n"); + //std::cout << "WPA Config:\n" << c << std::endl; + +// # WPA protected network, supply your own ESSID and WPAPSK here: +// network={ +// scan_ssid=0 +// ssid="your_essid_here" +// proto=WPA +// key_mgmt=WPA-PSK +// pairwise=CCMP TKIP +// group=CCMP TKIP WEP104 WEP40 +// psk=your_psk_here +// } + + QFile file( wpaConfigFile ); + if (file.exists()) file.remove(); + if ( file.open( IO_WriteOnly ) ) { + QTextStream stream( &file ); + stream << c; + file.close(); + //std::cout << "Wrote WPA config: " << wpaConfigFile << std::endl; + return 1; + } else + return 0; +} + +bool WirelessAssistant::setWpaClientEnabled( bool e, const QString& iface, QString driver ) +{ + if (!e) { + if ( runCommand( QStringList(Commands.wpa_cli) << QString("-i%1").arg(NetParams.iface) << "terminate" ).contains("OK") ) { + QFile( wpaConfigFile ).remove(); + return 1; + } else + return 0; // wpa client was not running. + } + + if ( !runCommand( QStringList(Commands.wpa_cli) << QString("-i%1").arg(NetParams.iface) << "status" ).contains("Failed to connect") ) { + std::cout << "WPA client already running. Reconfiguring..." << std::endl; + runCommand( QStringList(Commands.wpa_cli) << "reconfigure" ); + } else { + if ( driver.isEmpty() ) { //detect needed driver + QString k = WATools::kernelModule( iface ); + if ( k.contains("hermes") ) driver = "hermes"; + else if ( k.contains("atmel") ) driver = "atmel"; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 13) + else if ( k.contains("ipw") ) driver = "ipw"; //wext should be used for kernels newer than 2.6.12 +#endif + //Commented out, because ndiswrapper newer than 1.13 works with wext driver. + //else if ( k.contains("ndiswrapper") ) driver = "ndiswrapper"; + //Commented out, because madwifi-ng works with wext driver. + //else if ( k.contains("ath") ) driver = "madwifi"; + else driver = "wext"; + std::cout << "Using wpa_supplicant driver: " << driver << std::endl; + } + + QProcess* wp = new QProcess( this ); + wp->clearArguments(); + wp->addArgument( Commands.wpa_supplicant ); + wp->addArgument( "-W" ); //wait for control interface + wp->addArgument( QString("-D%1").arg(driver) ); + wp->addArgument( QString("-i%1").arg(iface) ); + wp->addArgument( QString("-c%1").arg(wpaConfigFile) ); + //std::cout << "Starting WPA client: " << wp->arguments().join(" ") << std::endl; + if ( !wp->start() ) { + std::cout << "Failed to start WPA client." << std::endl; + return 0; + } + wp = 0; + std::cout << "WPA client started. Waiting for status..." << std::endl; + } + + usleep(200*1000); //200msec for wpa_supplicant to initiate + + QString o; + int i = 0; + while ( !(o =runCommand( QStringList(Commands.wpa_cli) << QString("-i%1").arg(NetParams.iface) << "status" )).contains("Failed to connect") ) { + for (int c = 0; c < 15; c++) { + usleep(75*1000); //75msec + KApplication::eventLoop()->processEvents( QEventLoop::AllEvents ); + i++; + } + if (i>400) { //more than 30sec have passed + runCommand( QStringList(Commands.wpa_cli) << QString("-i%1").arg(NetParams.iface) << "terminate" ); + return 0; + } + if ( o.contains("wpa_state=COMPLETED") ) { + std::cout << "WPA Authorisation successful." << std::endl; + return 1; + } + } + return 0; +} + + +bool WirelessAssistant::close() +{ + updateConfiguration(-1); //read values from setingsPage; + WAConfig::self()->writeConfig(); + std::cout << "Application options saved." << std::endl; + WATools::cleanup(); + std::cout << "Kernel socket closed." << std::endl; + return QWidget::close(); +} + + +#include "wlassistant.moc" diff --git a/src/wlassistant.desktop b/src/wlassistant.desktop new file mode 100644 index 0000000..b119871 --- /dev/null +++ b/src/wlassistant.desktop @@ -0,0 +1,55 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Wireless Assistant +Comment[pl]=Program do obsługi sieci bezprzewodowych +Comment[es]=Aplicación para buscar redes inalámbricas +Exec=ksystraycmd kdesu wlassistant +Icon=wlassistant +Type=Application +Categories=Qt;KDE;Network; + +Name[de]=Funknetzassistent +GenericName=Wireless LAN Manager +GenericName[ar]=إدارة الشبكة المحلية اللاسلكية +GenericName[bg]=Безжична мрежа +GenericName[br]=Merour ar rouedad hep neud +GenericName[bs]=Upravitelj bežčnim LANom +GenericName[ca]=Gestor LAN sense fils +GenericName[cs]=Správce bezdrátové LAN +GenericName[cy]=Rheolydd LAN Di-Wifr +GenericName[da]=Håndtering af trådløst netværk +GenericName[de]=Verwaltung für drahtlose LAN-Verbindungen +GenericName[el]=Διαχειριστής ασύρματου LAN +GenericName[es]=Gestor de red inalámbrica +GenericName[et]=Traadita võrgu haldur +GenericName[eu]=Kablerik gabeko LAN kudeatzailea +GenericName[fi]=Langattoman lähiverkon hallinta +GenericName[fr]=Gestionnaire de réseau sans fil +GenericName[ga]=Bainisteoir Ghréasáin gan sreang +GenericName[hi]= बतार लन मनजर +GenericName[hr]=Upravitelj bežičnog LAN-a +GenericName[hu]=WiFi-kezelő +GenericName[is]=Fylgist með staðarneti +GenericName[it]=Gestione LAN senza fili +GenericName[ja]=ワイヤレスLANマネージャ +GenericName[lt]=Bevielio ryšio kontrolės centras +GenericName[mk]=Менаџер на безжичната локална мрежа +GenericName[nb]=Trådløst nettverksbehandler +GenericName[nl]=Draadloos netwerkbeheer +GenericName[nn]=Handsamar for trådlaust nettverk +GenericName[pl]=Nadzorca sieci bezprzewodowej +GenericName[pt]=Gestor de Rede Sem Fios +GenericName[pt_BR]=Gerenciador de Wireless na LAN +GenericName[ru]=Менеджер локальной радиосети +GenericName[sk]=Správca bezdrôtovej siete LAN +GenericName[sl]=Upravljalec brezžičnega LAN-a +GenericName[sr]=Управник бежичног LAN-а +GenericName[sr@Latn]=Upravnik bežičnog LAN-a +GenericName[sv]=Trådlöst nätverkshantering +GenericName[ta]=கமபியிலலா LAN மேளாளர +GenericName[tg]=Мудири Беноқили Шабакаи Маҳаллӣ +GenericName[tr]=Kablosuz Yerel Ağ Yöneticisi +GenericName[uk]=Менеджер локальної радіомережі +GenericName[uz]=Симсиз тармоқ бошқарувчиси +GenericName[xx]=xxWireless LAN Managerxx +GenericName[zh_CN]=无线局域网管理器 diff --git a/src/wlassistant.h b/src/wlassistant.h new file mode 100644 index 0000000..64cd048 --- /dev/null +++ b/src/wlassistant.h @@ -0,0 +1,120 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pawel Nawrocki * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WLASSISTANT_H +#define WLASSISTANT_H + +//connection check interval in msec +#define WA_CONNECTION_CHECK_INTERVAL 5000 + +#include "ui_main.h" +#include "waconfig.h" + +#include "netparams.h" + +class QTimer; +class QProcess; +class NetListViewItem; + +class WirelessAssistant : public mainWindow +{ + Q_OBJECT + +public: + /*$PUBLIC_FUNCTIONS$*/ + WirelessAssistant(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~WirelessAssistant(); + + static QString getVal(const QString & str, const QString & rxs); + +public slots: + /*$PUBLIC_SLOTS$*/ + virtual void netConnect(); + virtual void netScan(); + virtual void netDisconnect( const bool & quiet = false); + +private: + void netScan( const WANetParams & np ); + void netConnect( const WANetParams & np ); + void setDNS( const WANetParams & np ); + void readConfig(); + void saveSettings(); + void setUi(int uiState); + void setSingleClick(bool i); + QString runCommand( const QStringList & cmd, int timeout = 0, bool detached = 0 ); + void setNetParamsFromList( QListViewItem* lvi ); + bool setNetParamsFromConfig( const QString & s ); + QString matchEssidForAp( const QString & ap ); + bool radioEnabled(); + QListViewItem* getItemByAp( const QString & ap ); + QListViewItem* getItemByEssid( const QString & essid ); + void setConnectedItem( const QString & netid ); + QString getGateway(); + bool dhcpClientRunning(); + QStringList interfaceList(); + bool generateWpaConfigFile( const QString& essid, const QStringList& wpaSettings, const QString& wpaKey ); + bool setWpaClientEnabled( bool e, const QString& iface = 0, QString driver = 0 ); + + QStringList NetParamsList; + QStringList execsNotFound; + NetListViewItem* connectedItem; + QString wpaConfigFile; + /// settings saved in wlassistantrc + bool autoQuit; + bool autoReconnect; + bool autoConnect; + bool groupAPs; + bool wpaAvailable; + int DelayBeforeScanning; + int DhcpTimeout; + /*QString dhcpcdInfoPath; + QString dhclientInfoPath; + QString dhcpcdPidPath; + QString dhclientPidPath;*/ + /// end settings. + + WACommands Commands; + WANetParams NetParams; + QTimer* timerGui; + QTimer* timerConnectionCheck; + +protected slots: + /*$PROTECTED_SLOTS$*/ + virtual void init(); + virtual void netAutoConnect(); + virtual void parseScan( const QString & output ); + virtual void setDev( const QString & ifname); + virtual void setNetListColumns(); + virtual void updateConfiguration(int category = -1); + virtual void updateConnectedItem(); + virtual void showItemContextMenu( QListViewItem* i, const QPoint& p, int c); + virtual void editNetParams(); + virtual void removeNetParams(); + virtual void updateNetParams(); + virtual void itemAction(); + virtual void checkConnectionStatus(); + virtual void updateConnectButton(QListViewItem* lvi); + virtual void setMouseBehaviour(); + virtual void togglePage(bool options ); + virtual void enableAllMessages(); + virtual bool close(); +}; + +#endif |