From e0311ffdf88fc311006351582b959a69d8aad328 Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 1 Mar 2010 19:19:25 +0000 Subject: Added KDE3 version of wlassistant git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/wlassistant@1097621 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/SConscript | 26 + src/main.cpp | 56 ++ src/netlistviewitem.cpp | 239 +++++++++ src/netlistviewitem.h | 176 ++++++ src/netparams.h | 289 ++++++++++ src/ui_NetParamsEdit.ui | 1111 ++++++++++++++++++++++++++++++++++++++ src/ui_NetParamsWizard.ui | 892 +++++++++++++++++++++++++++++++ src/ui_main.ui | 759 ++++++++++++++++++++++++++ src/ui_netparamsedit.cpp | 174 ++++++ src/ui_netparamsedit.h | 53 ++ src/ui_netparamswizard.cpp | 107 ++++ src/ui_netparamswizard.h | 53 ++ src/waconfig.cpp | 29 + src/waconfig.h | 45 ++ src/watools.cpp | 312 +++++++++++ src/watools.h | 76 +++ src/wlassistant.cpp | 1264 ++++++++++++++++++++++++++++++++++++++++++++ src/wlassistant.desktop | 55 ++ src/wlassistant.h | 120 +++++ 19 files changed, 5836 insertions(+) create mode 100644 src/SConscript create mode 100644 src/main.cpp create mode 100644 src/netlistviewitem.cpp create mode 100644 src/netlistviewitem.h create mode 100644 src/netparams.h create mode 100644 src/ui_NetParamsEdit.ui create mode 100644 src/ui_NetParamsWizard.ui create mode 100644 src/ui_main.ui create mode 100644 src/ui_netparamsedit.cpp create mode 100644 src/ui_netparamsedit.h create mode 100644 src/ui_netparamswizard.cpp create mode 100644 src/ui_netparamswizard.h create mode 100644 src/waconfig.cpp create mode 100644 src/waconfig.h create mode 100644 src/watools.cpp create mode 100644 src/watools.h create mode 100644 src/wlassistant.cpp create mode 100644 src/wlassistant.desktop create mode 100644 src/wlassistant.h (limited to 'src') 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 * + * pnawrocki@interia.pl * + * * + * 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 +#include +#include +#include + +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, "pnawrocki@interia.pl"); + about.addAuthor( "Pawel Nawrocki", 0, "pnawrocki@interia.pl" ); + 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 * + * pnawrocki@interia.pl * + * * + * 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 + +#include +#include +#include + +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 * + * pnawrocki@interia.pl * + * * + * 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 + +#include + +#include +#include + +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 * + * pnawrocki@interia.pl * + * * + * 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 +#include +#include +#include + +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("

The network changed its security settings.

Please go to Security tab of the following dialog and configure WEP settings.

") ); + } else + KMessageBox::error(0, i18n("

Your WEP Key is not set properly.

Please go to Security tab of the following dialog and enter the required key.

") ); + r = true; + } + if ( (hiddenEssid) && (!wasHiddenEssid) ) + if ( KMessageBox::questionYesNo(0, i18n("

The network has stopped broadcasting its ESSID since the last time you were connected.

Would you like to use '%1' as an ESSID for this network?

NOTE: If you answer No, a dialog will appear where you will be able to specify a different ESSID.

").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 @@ + +netProperties + + +netProperties + + + +0 +0 +420 +504 + + + + +5 +1 +0 +0 + + + +Properties + + +false + + + +unnamed + + +11 + + +6 + + + +Layout1 + + + +unnamed + + +0 + + +6 + + + +buttonHelp + + +&Help + + +F1 + + +true + + + + +Horizontal Spacing2 + + +Horizontal + + +Expanding + + + +20 +20 + + + + + +buttonOk + + +&OK + + + + + +true + + +true + + + + +buttonCancel + + +&Cancel + + + + + +true + + + + + + +tabNetParams + + + +tabInterface + + +I&nterface + + + +unnamed + + + +boxEssid + + + +5 +1 +0 +0 + + + +ESSID + + + +unnamed + + + +textLabel1 + + +ESSID: + + + + +essid + + + + + + +buttonGroup1 + + + +5 +3 +0 +0 + + + +Configuration + + + +unnamed + + + +layout3 + + + +unnamed + + + +radioDhcp + + +Automatic (DHCP) + + + + +radioManualConfig + + +&Manual + + + + + + +boxManualConfig + + +NoFrame + + +Raised + + + +unnamed + + + +netmask + + + + +textLabel4 + + +Netmask: + + + + +ip + + + + +domain + + + + +textLabel2 + + +IP: + + + + +textLabel3 + + +Broadcast: + + + + +textLabel5 + + +Gateway: + + + + +dns1 + + + + +textLabel6 + + +Domain: + + + + +broadcast + + + + +gateway + + + + +dns2 + + + + +textLabel8 + + +Secondary DNS: + + + + +textLabel7 + + +Primary DNS: + + + + + + + + +spacer2 + + +Vertical + + +Expanding + + + +20 +21 + + + + + + + +tabSecurity + + +Securit&y + + + +unnamed + + + +spacer3 + + +Vertical + + +Expanding + + + +21 +40 + + + + + +groupWpa + + +WPA Settings + + + +unnamed + + + +layout33 + + + +unnamed + + + +textLabel1_2_2 + + + +1 +5 +0 +0 + + + +Key: + + + + +wpaKey + + +Password + + + + +checkWpaAscii + + +ASCII + + + + + + +layout34 + + + +unnamed + + + +textLabel1_3_5 + + + +3 +5 +0 +0 + + + +WPA Version:<br>Group Cipher:<br>Pairwise Cipher:<br>Authentication Suite: + + + + +labelWpaSettings + + + +1 +5 +0 +0 + + + +<b>?<br>?<br>?<br>?</b> + + + + +spacer71 + + +Horizontal + + +Expanding + + + +131 +21 + + + + + + + + + +groupWep + + +WEP Settings + + + +unnamed + + + +radioWepOpen + + +Open Syste&m + + +Alt+M + + + + +layout35 + + + +unnamed + + + +textLabel1_2 + + + +1 +5 +0 +0 + + + +Key: + + + + +wepKey + + +Password + + + + +checkWepAscii + + +ASCII + + + + + + +radioWepRestricted + + +Shared &Key + + +Alt+K + + + + + + + + +tabAdvanced + + +Advanced + + + +unnamed + + + +textLabel1_4 + + +<b>Security Warning:</b> the commands specified below will be ran with the same privileges as Wireless Assistant has. + + + + +groupBox3 + + +Pre-Connection Command + + + +unnamed + + + +layout6 + + + +unnamed + + + +spacer7 + + +Horizontal + + +Expanding + + + +130 +20 + + + + + +textLabel1_3 + + +Timeout: + + + + +preConnectionTimeout + + +s + + +60 + + +1 + + +20 + + +Amount of time after which the process will be killed. + + +<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> + + + + +preConnectionDetached + + +Run detached + + +Don't wait for the process to finish. + + +<p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p> + + + + + + +layout7 + + + +unnamed + + + +textLabel1_3_2 + + +Command: + + + + +preConnectionCommand + + + + + + + + +groupBox3_2 + + +Post-Connection Command + + + +unnamed + + + +layout6_2 + + + +unnamed + + + +spacer7_2 + + +Horizontal + + +Expanding + + + +130 +20 + + + + + +textLabel1_3_3 + + +Timeout: + + + + +postConnectionTimeout + + +s + + +60 + + +1 + + +20 + + +Amount of time after which the process will be killed. + + +<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> + + + + +postConnectionDetached + + +Run detached + + +Don't wait for the process to finish. + + +<p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p> + + + + + + +layout7_2 + + + +unnamed + + + +textLabel1_3_2_2 + + +Command: + + + + +postConnectionCommand + + + + + + + + +groupBox3_3 + + +Pre-Disconnection Command + + + +unnamed + + + +layout6_3 + + + +unnamed + + + +spacer7_3 + + +Horizontal + + +Expanding + + + +130 +20 + + + + + +textLabel1_3_4 + + +Timeout: + + + + +preDisconnectionTimeout + + +s + + +60 + + +1 + + +20 + + +Amount of time after which the process will be killed. + + +<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> + + + + +preDisconnectionDetached + + +Run detached + + +Don't wait for the process to finish. + + +<p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p> + + + + + + +layout7_3 + + + +unnamed + + + +textLabel1_3_2_3 + + +Command: + + + + +preDisconnectionCommand + + + + + + + + +groupBox3_3_2 + + +Post-Disconnection Command + + + +unnamed + + + +layout6_3_2 + + + +unnamed + + + +spacer7_3_2 + + +Horizontal + + +Expanding + + + +130 +20 + + + + + +textLabel1_3_4_2 + + +Timeout: + + + + +postDisconnectionTimeout + + +s + + +60 + + +1 + + +20 + + +Amount of time after which the process will be killed. + + +<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> + + + + +postDisconnectionDetached + + +Run detached + + +Don't wait for the process to finish. + + +<p><b>Run Detached</b></p> +<p>If this checkbox is selected Wireless Assistant will not wait for the process to finish.</p> + + + + + + +layout7_3_2 + + + +unnamed + + + +textLabel1_3_2_3_2 + + +Command: + + + + +postDisconnectionCommand + + + + + + + + +spacer4 + + +Vertical + + +Expanding + + + +31 +20 + + + + + + + + + + +buttonOk +clicked() +netProperties +accept() + + +buttonCancel +clicked() +netProperties +reject() + + +radioManualConfig +toggled(bool) +boxManualConfig +setEnabled(bool) + + +radioDhcp +toggled(bool) +boxManualConfig +setDisabled(bool) + + +preConnectionDetached +toggled(bool) +preConnectionTimeout +setDisabled(bool) + + +postConnectionDetached +toggled(bool) +postConnectionTimeout +setDisabled(bool) + + +preDisconnectionDetached +toggled(bool) +preDisconnectionTimeout +setDisabled(bool) + + +postDisconnectionDetached +toggled(bool) +postDisconnectionTimeout +setDisabled(bool) + + + +essid +radioDhcp +radioManualConfig +ip +broadcast +netmask +gateway +domain +dns1 +dns2 +tabNetParams +radioWepOpen +radioWepRestricted +wepKey +buttonHelp +buttonOk +buttonCancel + + + 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 @@ + +NetParamsWizard + + +NetParamsWizard + + + +0 +0 +427 +356 + + + +First Connection Wizard + + +false + + +true + + + +1 + + + + +welcome + + +Welcome to First Connection Wizard + + + +unnamed + + + +textLabel1_2 + + +<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> + + +WordBreak|AlignTop + + + + + + +WizardPage + + +ESSID + + + +unnamed + + +15 + + + +textLabel8_2 + + +<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> + + + + +spacer54 + + +Vertical + + +Expanding + + + +21 +100 + + + + + +textLabel9 + + +ESSID: + + +AlignVCenter|AlignRight + + + + +essid + + + + +spacer55 + + +Horizontal + + +Expanding + + + +101 +21 + + + + + +spacer56 + + +Horizontal + + +Expanding + + + +61 +21 + + + + + + + +ConfigMode + + +Interface Configuration + + + +unnamed + + +15 + + + +spacer5 + + +Horizontal + + +Expanding + + + +80 +21 + + + + + +spacer4 + + +Horizontal + + +Expanding + + + +60 +31 + + + + + +spacer6 + + +Vertical + + +Expanding + + + +21 +20 + + + + + +buttonGroup3 + + +TabFocus + + +0 + + + + + +true + + + +unnamed + + + +radioDhcp + + +Automatic (DHCP) + + + + + +true + + + + +radioManualConfig + + +Manual + + + + + + + + + +textLabel2_2 + + +<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> + + + + + + +ManualConfig + + +Interface Parameters + + + +unnamed + + +15 + + + +layout12 + + + +unnamed + + + +dns1 + + +32767 + + + + +gateway + + +32767 + + + + +textLabel6 + + +Secondary DNS: + + +AlignVCenter|AlignRight + + + + +ip + + +32767 + + + + +broadcast + + +32767 + + + + +textLabel1 + + +IP: + + +AlignVCenter|AlignRight + + + + +textLabel3 + + +Netmask: + + +AlignVCenter|AlignRight + + + + +dns2 + + +32767 + + + + +textLabel5 + + +Primary DNS: + + +AlignVCenter|AlignRight + + + + +textLabel7 + + +Gateway: + + +AlignVCenter|AlignRight + + + + +domain + + + + +netmask + + +32767 + + + + +textLabel4 + + +Domain: + + +AlignVCenter|AlignRight + + + + +textLabel2 + + +Broadcast: + + +AlignVCenter|AlignRight + + + + + + +spacer7 + + +Horizontal + + +Expanding + + + +60 +31 + + + + + +spacer8 + + +Horizontal + + +Expanding + + + +50 +21 + + + + + +spacer9 + + +Vertical + + +Expanding + + + +21 +16 + + + + + +textLabel3_2 + + +<p><b>Please specify interface parameters to be used to connect to this network.</b></p> +<p>You may leave some fields blank.</p> + + + + + + +WepConfig + + +WEP Configuration + + + +unnamed + + + +textLabel5_2 + + +<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> + + + + +buttonGroup3_2_2 + + +0 + + + + + +true + + + +unnamed + + + +radioWepOpen + + +Open S&ystem + + +true + + + + +radioButton2_2_2 + + +Shared Key + + + + + + +spacer4_2_2 + + +Horizontal + + +Expanding + + + +122 +31 + + + + + +spacer5_2_2 + + +Horizontal + + +Expanding + + + +150 +21 + + + + + +textLabel6_2 + + +<p><b>Please provide a key to be used with this network.</b></p> + + + + +spacer17 + + +Vertical + + +Expanding + + + +31 +16 + + + + + +spacer15 + + +Horizontal + + +Expanding + + + +50 +21 + + + + + +spacer16 + + +Horizontal + + +Expanding + + + +30 +21 + + + + + +textLabel8 + + +WEP key: + + +AlignVCenter|AlignRight + + + + +wepKey + + + +140 +0 + + + +Password + + + + +checkWepAscii + + +ASCII + + + + + + +WizardPage + + +WPA Configuration + + + +unnamed + + + +spacer17_2 + + +Vertical + + +Expanding + + + +31 +54 + + + + + +spacer15_2 + + +Horizontal + + +Expanding + + + +80 +21 + + + + + +spacer16_2 + + +Horizontal + + +Expanding + + + +49 +21 + + + + + +textLabel5_2_2 + + +<p><b>The network you are trying to connect to requires WPA authentication.</b></p> + + + + +textLabel8_3 + + +WPA Key: + + +AlignVCenter|AlignRight + + + + +wpaKey + + + +140 +0 + + + +Password + + + + +checkWpaAscii + + +ASCII + + + + +textLabel6_2_2 + + +<p><b>Please provide a key to be used with this network.</b></p> + + + + +spacer43 + + +Horizontal + + +Expanding + + + +80 +21 + + + + + +spacer42 + + +Horizontal + + +Expanding + + + +60 +31 + + + + + +labelWpaSettings + + + +1 +5 +0 +0 + + + +<b>?<br>?<br>?<br>?</b> + + + + +textLabel1_3 + + + +3 +5 +0 +0 + + + +WPA Version:<br>Group Cipher:<br>Pairwise Cipher:<br>Authentication Suite: + + + + + + +done + + +Done! + + + +unnamed + + + +textLabel7_2 + + +<p><b>Congratulations!</b></p> +<p>You have successfully finished configuring this connection.</p> +<p><b>Press Finish to connect!</b></p> + + +WordBreak|AlignTop + + + + + + +buttonGroup3 +ip +broadcast +netmask +gateway +domain +dns1 +dns2 +radioWepOpen +wepKey +radioDhcp + + + 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 @@ + +mainWindow + + +mainWindow + + + +0 +0 +588 +324 + + + +Wireless Assistant + + + +unnamed + + + +buttonOptions + + + +0 +0 + + + +&Options + + +Alt+O + + +true + + +Toggle network list/options + + +<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> + + + + +buttonClose + + +&Quit + + +Alt+Q + + +true + + +Quit the application + + +<p><b>Quit Button</b></p> +<p>Pressing this button will quit the application.</p> + + + + +buttonConnect + + +false + + + +120 +0 + + + +Co&nnect + + +Alt+N + + +Connect to the selected network + + +<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> + + + + +buttonScan + + +false + + +Refresh + + + + + +false + + +Refresh network list + + +<p><b>Scan Button</b></p> +<p>Pressing this button will scan for wireless networks and refresh the network list.</p> + + + + +spacer14 + + +Vertical + + +Expanding + + + +21 +120 + + + + + +layout16 + + + +unnamed + + +0 + + + +frameDevice + + + +5 +1 +0 +0 + + + +NoFrame + + +Plain + + + +unnamed + + +0 + + + +devLabel + + + +1 +0 +0 +0 + + + + +0 +20 + + + +Device: + + + + +devCombo + + +false + + + +3 +0 +0 +0 + + + + +60 +0 + + + +Pick a network device to use + + +<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> + + + + + + +widgetStack + + + +7 +7 +0 +0 + + + +PopupPanel + + +Sunken + + +2 + + + +netPage + + +0 + + + +unnamed + + +0 + + +0 + + + + +ESSID + + +true + + +true + + + + +Channel + + +true + + +true + + + + +Link Quality + + +true + + +false + + + + +WEP/WPA + + +true + + +false + + + + +AP + + +true + + +true + + + +netList + + +NoFrame + + +Plain + + +1 + + +<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> + + + + +statusLabel + + + +7 +0 +0 +0 + + + + +0 +20 + + + +5 + + +Ready + + +WordBreak|AlignVCenter + + +<p><b>Status Bar</b></p> +<p>Messages describing current process are shown in this area.</p> + + + + + + +optionsPage + + +1 + + + +unnamed + + + +layout20 + + + +unnamed + + + +checkAutoConnect + + +Automatically connect on startup + + + + + +<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> + + + + +checkAutoReconnect + + +Automaticall&y reconnect if connection is lost + + +Alt+Y + + +<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> + + + + +checkAutoQuit + + +Quit upon successful connection + + + + + +<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> + + + + +checkGroupAPs + + +&Group access points with the same ESSID + + +Alt+G + + +<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> + + + + + + +layout17 + + + +unnamed + + + +layout12 + + + +unnamed + + + +textLabel2_2 + + +Delay before scanning: + + +Specify how long to wait for an IP + + +<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> + + + + +textLabel2 + + +DHCP client timeout: + + +Specify how long to wait for an IP + + +<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> + + + + + + +layout13 + + + +unnamed + + + +spacer24_2 + + +Horizontal + + +Fixed + + + +21 +20 + + + + + +spacer24 + + +Horizontal + + +Fixed + + + +21 +20 + + + + + + + +layout14 + + + +unnamed + + + +spinDelayBeforeScanning + + +s + + +20 + + +0 + + +0 + + +Specify how long to wait before scanning + + +<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> + + + + +spinDhcpTimeout + + +s + + +60 + + +5 + + +15 + + +Specify how long to wait for an IP + + +<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> + + + + + + +layout15 + + + +unnamed + + + +spacer25_2 + + +Horizontal + + +Expanding + + + +101 +21 + + + + + +spacer25 + + +Horizontal + + +Expanding + + + +118 +21 + + + + + + + + + +textLabel1 + + +<i>Press the button below to enable all messages which have been turned off with the 'Don't Show Again' feature.</i> + + + + +layout19 + + + +unnamed + + + +spacer22 + + +Horizontal + + +Expanding + + + +201 +21 + + + + + +buttonEnableAllMessages + + +E&nable All Messages + + +Alt+N + + +<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> + + + + + + +spacer16 + + +Vertical + + +Expanding + + + +20 +31 + + + + + + + + + + + +devCombo +netList +buttonScan +buttonConnect +buttonOptions +buttonClose +checkAutoQuit +spinDhcpTimeout +buttonEnableAllMessages + + +netScan() +netConnect() +showCfgDlg() +setDeviceList() + + +updateStatus(char sts) + + + +kpushbutton.h +kpushbutton.h +kpushbutton.h +kpushbutton.h +kcombobox.h +klistview.h + + 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 * + * pnawrocki@interia.pl * + * * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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("%1").arg( np.wpaSettings.join("
") ) ); + 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 * + * pnawrocki@interia.pl * + * * + * 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 * + * pnawrocki@interia.pl * + * * + * 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 +#include +#include +#include +#include + +#include + +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("%1").arg( settings.join("
") ) ); +} + + +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 * + * pnawrocki@interia.pl * + * * + * 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 + +WAConfig *WAConfig::mSelf = 0; +static KStaticDeleter 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 * + * pnawrocki@interia.pl * + * * + * 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 + +class WAConfig : public KConfigSkeleton +{ + public: + + static WAConfig *self(); + ~WAConfig(); + + static + void writeConfig() + { + static_cast(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 * + * pnawrocki@interia.pl * + * * + * 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 //provides readlink +#include +#include //to get values from /sys +#include +#include +#include //inet_ntoa +#include //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 * + * pnawrocki@interia.pl * + * * + * 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 +#include +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 * + * pnawrocki@interia.pl * + * * + * 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 +#include //provides LINUX_VERSION* macros + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; icount(); 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("

You might have insufficient permissions for Wireless Assistant to function properly.

Did you run it using 'sudo'?

") ); + } + 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(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(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("

Settings for network '%1' are about to be deleted.

Would you like to continue?

").arg(essid)) == KMessageBox::Continue ) { + if (nvi->hidden()) // hiddenEssid = 1 + nvi->setEssid(""); + 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("

File '%1' could not be opened for writing.

Nameserver(s) and/or domain are not set.

").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 "" + essid = ""; + else + continue; //some cards report one '' essid even when no network's present. Workaround. + } + + if (essid=="") { + 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(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(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(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( 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( 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("

Can not connect to network '%1'.

The network you are trying to connect to requires WPA authentication. The necessary executables wpa_supplicant and wpa_cli could not be found. Install wpa_supplicant and restart Wireless Assistant to connect.

").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=="") || (!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(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 ""; +} + +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(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("

You are about to disconnect from '%1'.

Would you like to continue?

").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(lvi)-> + ap() == ap ) { + break; + } + lvi = lvi->nextSibling(); + } + return lvi; +} + +QListViewItem* WirelessAssistant::getItemByEssid( const QString & essid ) +{ + QListViewItem* lvi = netList->firstChild(); + while (lvi) { + if ( static_cast(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(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 * + * pnawrocki@interia.pl * + * * + * 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 -- cgit v1.2.3