author | mickeyl <mickeyl> | 2004-01-08 10:37:42 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-08 10:37:42 (UTC) |
commit | c1fe58cfdfdb42f75a040442c29defa15c81f626 (patch) (side-by-side diff) | |
tree | 69c3e3c441af1ef933b73984e0c1a6778f8dc672 /noncore | |
parent | 05d47b2603adfab0e16f7395e34b7aa56ce6d8de (diff) | |
download | opie-c1fe58cfdfdb42f75a040442c29defa15c81f626.zip opie-c1fe58cfdfdb42f75a040442c29defa15c81f626.tar.gz opie-c1fe58cfdfdb42f75a040442c29defa15c81f626.tar.bz2 |
Calling scripts on new {Network, Client, Station} works now. Possible substitution
values are $SSID, $MAC, $WEP, $CHAN.
-rw-r--r-- | noncore/net/wellenreiter/gui/configwindow.cpp | 52 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/configwindow.h | 5 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/main.cpp | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 6 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 12 |
5 files changed, 56 insertions, 21 deletions
diff --git a/noncore/net/wellenreiter/gui/configwindow.cpp b/noncore/net/wellenreiter/gui/configwindow.cpp index 1341d03..7f39230 100644 --- a/noncore/net/wellenreiter/gui/configwindow.cpp +++ b/noncore/net/wellenreiter/gui/configwindow.cpp @@ -1,88 +1,92 @@ /********************************************************************** ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ /* LOCAL */ #include "configwindow.h" #include "mainwindow.h" /* OPIE */ #include <opie2/onetwork.h> #ifdef QWS #include <opie2/oapplication.h> #include <opie2/oconfig.h> +#include <opie/odevice.h> +using namespace Opie; #endif /* QT */ #include <qapplication.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qfile.h> #include <qlineedit.h> #include <qlayout.h> #include <qmap.h> #include <qpushbutton.h> #include <qtabwidget.h> #include <qtoolbutton.h> #include <qspinbox.h> #include <qtextstream.h> +/* POSIX */ +#include <assert.h> WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0; WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f ) :WellenreiterConfigBase( parent, name, true, f ) { _devicetype[ "cisco" ] = DEVTYPE_CISCO; _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG; _devicetype[ "hostap" ] = DEVTYPE_HOSTAP; _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO; _devicetype[ "<manual>" ] = DEVTYPE_MANUAL; _devicetype[ "<file>" ] = DEVTYPE_FILE; // gather possible interface names from ONetwork ONetwork* net = ONetwork::instance(); ONetwork::InterfaceIterator it = net->iterator(); while ( it.current() ) { if ( it.current()->isWireless() ) interfaceName->insertItem( it.current()->name() ); ++it; } load(); #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here QPushButton* okButton = new QPushButton( "ok", this ); okButton->show(); WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); #endif WellenreiterConfigWindow::_instance = this; connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) ); connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) ); connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) ); connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) ); connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) ); // make the checkbox 'channelAll' control all other channels connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) ); connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) ); // hide tab4 (parse) until Wellenreiter 1.2 tab->removePage( tab_4 ); }; @@ -227,132 +231,160 @@ void WellenreiterConfigWindow::getCaptureFileNameClicked() QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true); qDebug( "name = %s", (const char*) name ); if ( !name.isEmpty() ) { captureFileName->setText( name ); } } void WellenreiterConfigWindow::channelAllClicked(int state) { bool b = state; channel1->setChecked( b ); channel2->setChecked( b ); channel3->setChecked( b ); channel4->setChecked( b ); channel5->setChecked( b ); channel6->setChecked( b ); channel7->setChecked( b ); channel8->setChecked( b ); channel9->setChecked( b ); channel10->setChecked( b ); channel11->setChecked( b ); channel12->setChecked( b ); channel13->setChecked( b ); channel14->setChecked( b ); } bool WellenreiterConfigWindow::useGPS() const { return enableGPS->isChecked(); } const QString WellenreiterConfigWindow::gpsHost() const { return useGPS() ? gpsdHost->currentText() : QString::null; } int WellenreiterConfigWindow::gpsPort() const { bool ok; return useGPS() ? gpsdPort->value() : -1; } -void WellenreiterConfigWindow::performAction( const QString& type ) +void WellenreiterConfigWindow::performAction( const QString& type, + const QString& essid, + const QString& mac, + bool wep, + int channel, + int signal + /* , const GpsLocation& loc */ ) { int action; QString script; if ( type == "network" ) { action = newNetworkAction->currentItem(); script = newNetworkScript->text(); } else if ( type == "managed" || type == "adhoc" ) { action = newClientAction->currentItem(); script = newClientScript->text(); } else if ( type == "station" ) { action = newStationAction->currentItem(); script = newStationScript->text(); } else { - qWarning( "WellenreiterConfigWindow::performAction(): unknown type '%s'", (const char*) type ); + qWarning( "WellenreiterConfigWindow::performAction(): unknown type '%s'", (const char*) type ); return; } qDebug( "going to perform action %d (script='%s')", action, (const char*) script ); - /* - - if ( sound == "Ignore" ) return; - else if ( sound == "Touch" ) ODevice::inst()->touchSound(); - else if ( sound == "Key" ) ODevice::inst()->keySound(); - else if ( sound == "Alarm" ) ODevice::inst()->alarmSound(); - - */ + switch( action ) + { + case 0: /* Ignore */ return; + case 1: /* Play Alarm */ ODevice::inst()->alarmSound(); return; + case 2: /* Play Click */ ODevice::inst()->touchSound(); return; + case 3: /* Blink LED */ break; //FIXME: Implement this + case 4: /* Run Script */ + { + /** + * + * Script Substitution Information: + * + * $SSID = SSID + * $MAC = MAC + * $WEP = Wep + * $CHAN = Channel + * + **/ + script = script.replace( QRegExp( "$SSID" ), essid ); + script = script.replace( QRegExp( "$MAC" ), mac ); + script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) ); + script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) ); + + qDebug( "going to call script '%s'", (const char*) script ); + ::system( script ); + qDebug( "script returned." ); + return; + } + default: assert( false ); + } } void WellenreiterConfigWindow::load() { #ifdef Q_WS_X11 #warning Persistent Configuration not yet implemented for standalone X11 build performAutodetection(); #else qDebug( "loading configuration settings..." ); /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ OConfig* c = oApp->config(); c->setGroup( "Interface" ); QString interface = c->readEntry( "name", "<none>" ); if ( interface != "<none>" ) { #if QT_VERSION < 300 interfaceName->insertItem( interface, 0 ); interfaceName->setCurrentItem( 0 ); #else interfaceName->setCurrentText( interface ); #endif QString device = c->readEntry( "type", "<select>" ); #if QT_VERSION < 300 for ( int i = 0; i < deviceType->count(); ++i ) { if ( deviceType->text( i ) == device ) { deviceType->setCurrentItem( i ); break; } } #else deviceType->setCurrentText( device ); #endif } else { performAutodetection(); } prismHeader->setChecked( c->readBoolEntry( "prism", false ) ); hopChannels->setChecked( c->readBoolEntry( "hop", true ) ); diff --git a/noncore/net/wellenreiter/gui/configwindow.h b/noncore/net/wellenreiter/gui/configwindow.h index b082331..5c998cb 100644 --- a/noncore/net/wellenreiter/gui/configwindow.h +++ b/noncore/net/wellenreiter/gui/configwindow.h @@ -1,78 +1,81 @@ /********************************************************************** ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef WELLENREITERCONFIGWINDOW_H #define WELLENREITERCONFIGWINDOW_H #include "configbase.h" +#include "gps.h" + +/* QT */ #include <qmap.h> #include <qcombobox.h> #include <qstring.h> const int DEVTYPE_SELECT = 0; const int DEVTYPE_CISCO = 1; const int DEVTYPE_WLAN_NG = 2; const int DEVTYPE_HOSTAP = 3; const int DEVTYPE_ORINOCO = 4; const int DEVTYPE_MANUAL = 5; const int DEVTYPE_FILE = 6; class WellenreiterConfigWindow; class WellenreiterConfigWindow : public WellenreiterConfigBase { Q_OBJECT public: WellenreiterConfigWindow( QWidget * parent = 0, const char * name = "WellenreiterConfigWindow", WFlags f = 0 ); ~WellenreiterConfigWindow(); int driverType() const; const QString soundOnNetwork() const { return "";/*netSound->currentText();*/ }; const QString soundOnBeacon() const { return "";/*beaconSound->currentText();*/ }; static WellenreiterConfigWindow* instance() { return _instance; }; int hoppingInterval() const; bool usePrismHeader() const; bool isChannelChecked( int ) const; bool useGPS() const; const QString gpsHost() const; int gpsPort() const; void save(); void load(); public slots: void changedDeviceType(int); void changedNetworkAction(int t); void changedClientAction(int t); void changedStationAction(int t); void getCaptureFileNameClicked(); void performAutodetection(); void channelAllClicked(int); - void performAction( const QString& ); + void performAction( const QString&, const QString&, const QString&, bool, int, int /* , const GpsLocation& */ ); protected: void synchronizeActionsAndScripts(); protected: QMap<QString, int> _devicetype; static WellenreiterConfigWindow* _instance; int _guess; }; #endif diff --git a/noncore/net/wellenreiter/gui/main.cpp b/noncore/net/wellenreiter/gui/main.cpp index dd757b5..702a7cc 100644 --- a/noncore/net/wellenreiter/gui/main.cpp +++ b/noncore/net/wellenreiter/gui/main.cpp @@ -76,56 +76,56 @@ int main( int argc, char **argv ) QMessageBox::Yes, QMessageBox::No ); if ( result == QMessageBox::No ) return -1; } // dhcp check - NOT HERE! This really belongs as a static member to OProcess // and I want to call it like that: if ( OProcess::isRunning( QString& ) ) ... QString line; QDir d = QDir( "/proc" ); QStringList dirs = d.entryList( QDir::Dirs ); QStringList::Iterator it; for ( it = dirs.begin(); it != dirs.end(); ++it ) { //qDebug( "next entry: %s", (const char*) *it ); QFile file( "/proc/"+*it+"/cmdline" ); file.open( IO_ReadOnly ); if ( !file.isOpen() ) continue; QTextStream t( &file ); line = t.readLine(); //qDebug( "cmdline = %s", (const char*) line ); if ( line.contains( "dhcp" ) ) break; } if ( line.contains( "dhcp" ) ) { qWarning( "Wellenreiter: found dhcp process #%d", (*it).toInt() ); result = QMessageBox::warning( w, " - Wellenreiter II - (dhcp)", QObject::tr( "You have a dhcp client running.\n" "This can severly limit scanning!\nShould I kill it for you?" ), QMessageBox::Yes, QMessageBox::No ); if ( result == QMessageBox::Yes ) { if ( -1 == ::kill( (*it).toInt(), SIGTERM ) ) qWarning( "Wellenreiter: can't kill process #%d (%s)", result, strerror( errno ) ); else killed = true; } } } a.exec(); if ( check ) { if ( killed ) { result = QMessageBox::warning( w, " - Wellenreiter II - (dhcp)", QObject::tr( "Restart your dhcp client?" ), QMessageBox::Yes, QMessageBox::No ); if ( result == QMessageBox::Yes ) { - system( QString().sprintf( "dhclient &; udhcpcd &; dhcpcd &" ) ); + ::system( QString().sprintf( "dhclient &; udhcpcd &; dhcpcd &" ) ); } } delete w; } return 0; } diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index 470646d..aea7eb6 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -364,113 +364,113 @@ void MScanListView::addService( const QString& name, const OMacAddress& macaddr, { // we have already seen this item, it's a dupe #ifdef DEBUG qDebug( "%s is a dupe - ignoring...", (const char*) name ); #endif subitem->receivedBeacon(); //FIXME: sent data bit return; } // never seen that - add new item MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", " ", false, -1, -1 ); item->setText( col_essid, name ); return; } } qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" ); MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!", (const char*) macaddr.toString(), (const char*) ip ) ); } void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col ) { if ( !item ) return; MScanListItem* itm = static_cast<MScanListItem*>( item ); qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'", (const char*) itm->text(0), (const char*) itm->type, col ); if ( itm->type == "adhoc" || itm->type == "managed" ) { QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() ); QPopupMenu m( this ); m.insertItem( entry, 37773, 0 ); int result = m.exec( QCursor::pos() ); if ( result == 37773 ) emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() ); } } //============================================================ // MScanListItem //============================================================ -MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, +MScanListItem::MScanListItem( QListView* parent, const QString& type, const QString& essid, const QString& macaddr, bool wep, int channel, int signal ) :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), _channel( channel ), _signal( signal ), _beacons( 1 ) { #ifdef DEBUG qDebug( "creating scanlist item" ); #endif if ( WellenreiterConfigWindow::instance() ) - WellenreiterConfigWindow::instance()->performAction( type ); // better use signal/slot combination here + WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here decorateItem( type, essid, macaddr, wep, channel, signal ); } -MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, +MScanListItem::MScanListItem( QListViewItem* parent, const QString& type, const QString& essid, const QString& macaddr, bool wep, int channel, int signal ) :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) { #ifdef DEBUG qDebug( "creating scanlist item" ); #endif decorateItem( type, essid, macaddr, wep, channel, signal ); } const QString& MScanListItem::essid() const { if ( type == "network" ) return _essid; else return ( (MScanListItem*) parent() )->essid(); } OListViewItem* MScanListItem::childFactory() { return new MScanListItem( this ); } void MScanListItem::serializeTo( QDataStream& s ) const { #ifdef DEBUG qDebug( "serializing MScanListItem" ); #endif OListViewItem::serializeTo( s ); s << _type; s << (Q_UINT8) ( _wep ? 'y' : 'n' ); } void MScanListItem::serializeFrom( QDataStream& s ) { #ifdef DEBUG qDebug( "serializing MScanListItem" ); #endif OListViewItem::serializeFrom( s ); char wep; s >> _type; s >> (Q_UINT8) wep; _wep = (wep == 'y'); QString name; name.sprintf( "wellenreiter/%s", (const char*) _type ); setPixmap( col_type, Resource::loadPixmap( name ) ); diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index 42f35c2..e8d48c3 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -23,107 +23,107 @@ #include <opie2/onetutils.h> /* QT */ #include <qtextstream.h> class QString; class MScanListItem; class MScanListView: public OListView { Q_OBJECT public: MScanListView( QWidget* parent = 0, const char* name = 0 ); virtual ~MScanListView(); virtual OListViewItem* childFactory(); virtual void serializeTo( QDataStream& s ) const; virtual void serializeFrom( QDataStream& s ); public slots: void addNewItem( const QString& type, const QString& essid, const OMacAddress& macaddr, bool wep, int channel, int signal, const GpsLocation& location ); void addService( const QString& name, const OMacAddress& macaddr, const QString& ip ); void fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); void toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); void WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo ); void IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); void identify( const OMacAddress&, const QString& ipaddr ); void contextMenuRequested( QListViewItem* item, const QPoint&, int ); signals: void rightButtonClicked(QListViewItem*,const QPoint&,int); void joinNetwork( const QString&, const QString&, int, const QString& ); protected: void addIfNotExisting( MScanListItem* parent, const OMacAddress& addr, const QString& type = "station" ); }; //****************************** MScanListItem **************************************************************** class MScanListItem: public OListViewItem { public: MScanListItem::MScanListItem( QListView* parent, - QString type = "unknown", - QString essid = "unknown", - QString macaddr = "unknown", + const QString& type = "unknown", + const QString& essid = "unknown", + const QString& macaddr = "unknown", bool wep = false, int channel = 0, int signal = 0 ); MScanListItem::MScanListItem( QListViewItem* parent, - QString type = "unknown", - QString essid = "unknown", - QString macaddr = "unknown", + const QString& type = "unknown", + const QString& essid = "unknown", + const QString& macaddr = "unknown", bool wep = false, int channel = 0, int signal = 0 ); protected: virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); public: QString type; public: //const QString& type() { return _type; }; const QString& essid() const; const QString& macaddr() { return _macaddr; }; bool wep() { return _wep; }; int channel() { return _channel; }; int signal() { return _signal; }; int beacons() { return _beacons; }; void setSignal( int signal ) { /* TODO */ }; void receivedBeacon(); void setManufacturer( const QString& manufacturer ); void setLocation( const QString& location ); virtual OListViewItem* childFactory(); virtual void serializeTo( QDataStream& s ) const; virtual void serializeFrom( QDataStream& s ); private: QString _type; QString _essid; QString _macaddr; bool _wep; int _channel; int _signal; int _beacons; }; //****************************** MScanListViewFactory **************************************************************** /* class MScanListViewFactory : public OListViewFactory { public: |