5 files changed, 43 insertions, 29 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 9512579..e642c08 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -1,260 +1,261 @@ #include <sys/types.h> #include <sys/wait.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <opie2/oprocess.h> #include <qdir.h> #include <qregexp.h> #include <qstringlist.h> #include <qfile.h> #include <qtextstream.h> #include <qapplication.h> #include "resources.h" #include "system.h" #define PROCNETDEV "/proc/net/dev" #ifndef ARPHRD_IEEE80211 #define ARPHRD_IEEE80211 801 #endif static char Dig2Hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // get HIGH nibble of byte #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] // get LOW nibble of byte #define LN(x) Dig2Hex[((x)&0x0f)] System::System( void ) : QObject(), ProbedInterfaces() { + ProcDevNet = 0; } System::~System( void ) { if( ProcDevNet ) delete ProcDevNet; } QDict<InterfaceInfo> & System::interfaces( void ) { if( ProbedInterfaces.count() == 0 ) { probeInterfaces(); } return ProbedInterfaces; } int System::runAsRoot( QStringList & S, MyProcess * Prc ) { char * usr = getenv("USER"); if( S.count() == 0 ) { // loophole to start shell return 8888; } if( usr == 0 || strcmp( usr, "root" ) ) { // unknown or non-root user -> use SUDO S.prepend( "sudo" ); } if( getenv( "NS2TESTMODE" ) ) { owarn << "TESTMODE !!! execute " << S.join( " ") << oendl; } else { MyProcess * P; if( Prc ) { P = Prc; } else { P = new MyProcess(); emit processEvent( tr("Command : ") + S.join( " " ) ); connect( P, SIGNAL( stdoutLine( const QString & ) ), this, SIGNAL( stdoutLine( const QString & ) ) ); connect( P, SIGNAL( stderrLine( const QString & ) ), this, SIGNAL( stderrLine( const QString & ) ) ); connect( P, SIGNAL(processExited(MyProcess*) ), this, SLOT (SLOT_ProcessExited(MyProcess*) ) ); } P->process() << S; Log(("Executing %s\n", S.join( " " ).latin1() )); if( ! P->process().start( OProcess::DontCare, OProcess::AllOutput ) ) { owarn << "Error starting " << S << oendl; if( ! Prc ) delete P; // error starting app - return 1; + return 0; } owarn << "Started " << S << oendl; } // all is fine - return 0; + return 1; } int System::execAsUser( QStringList & SL ) { MyProcess * P = new MyProcess(); CurrentQPEUser CU = NSResources->currentUser(); char * usr = getenv("USER"); if( strcmp( usr, "root" ) == 0 ) { // find user running qpe if( CU.UserName.isEmpty() ) { // if we come here, the exec was not successfull Log(("User not known \n" )); return 0; } } // now we are ready to exec the requested command setuid( CU.Uid ); setgid( CU.Gid ); for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { QString X; QStringList SL; X = CU.EnvList[i]; SL = QStringList::split( "=", X ); P->process().setEnvironment( SL[0], SL[1] ); } P->process() << SL; emit processEvent( tr("Command : ") + SL.join( " " ) ); Log(("Executing as user %s : %s\n", CU.UserName.latin1(), SL.join( " " ).latin1() )); int rv = ( P->process().start( OProcess::DontCare, OProcess::NoCommunication ) ); delete P; if( rv ) { // if we come here, the exec was not successfull Log(("Could not exec : %d\n", errno )); } - return rv; + return ! rv; } void System::SLOT_ProcessExited( MyProcess * P ) { QString R; for( QValueListConstIterator<QCString> it = P->process().args().begin(); it != P->process().args().end(); ++it ) { R += (*it); R += " "; } R += "Returned with " + QString().setNum( P->process().exitStatus() ); emit processEvent( R ); delete P; } void System::refreshStatistics( InterfaceInfo & I ) { if( ! ProcDevNet ) { return; } // cannot seek on dev ProcDevNet->close(); ProcDevNet->open( IO_ReadOnly ); QString line; QTextStream procTs(ProcDevNet); QStringList SL; int loc = -1; int version; procTs.readLine(); line = procTs.readLine(); // get version if( line.find("compressed") ) version = 3; else if( line.find( "bytes" ) ) version = 2; else version = 1; while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if( (loc = line.find(":") ) == -1) { continue; } if( I.Name != line.left(loc) ) continue; // tokenize SL = QStringList::split( ' ', line, FALSE ); // update data switch( version ) { case 1 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[6]; I.SndErrors = SL[8]; I.SndDropped = SL[9]; I.Collisions = SL[11]; break; case 2 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[7]; I.SndErrors = SL[9]; I.SndDropped = SL[10]; I.Collisions = SL[12]; break; case 3 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[9]; I.SndErrors = SL[11]; I.SndDropped = SL[12]; I.Collisions = SL[14]; break; } break; } } // // THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT // FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT // void System::probeInterfaces( void ) { // probe interfaces int sockfd; // get list of all interfaces struct ifreq ifrs; diff --git a/noncore/settings/networksettings2/opie-networksettings2.control b/noncore/settings/networksettings2/opie-networksettings2.control index e4bd29c..874833c 100644 --- a/noncore/settings/networksettings2/opie-networksettings2.control +++ b/noncore/settings/networksettings2/opie-networksettings2.control @@ -1,10 +1,10 @@ Package: opie-networksettings2 -Files: bin/networksettings2 apps/Settings/networksettings2.desktop pics/networksettings2/*.png lib/libnetworksettings2.so* pics/networksettings2/Devices/*.png +Files: bin/networksettings2 apps/Settings/networksettings2.desktop pics/networksettings2/*.png lib/libnetworksettings2.so* pics/networksettings2/Devices/*.png etc/NS2templates/* etc/NS2templates/*/* Priority: optional Section: opie/settings Maintainer: wim delvaux <wimpie@handhelds.org> Architecture: arm Depends: task-opie-minimal, libopietooth2 Description: Network settings. Replaces: opie-networksetup Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/opietooth2/OTSniffGUI.ui b/noncore/settings/networksettings2/opietooth2/OTSniffGUI.ui index 9ef540e..ec0b387 100644 --- a/noncore/settings/networksettings2/opietooth2/OTSniffGUI.ui +++ b/noncore/settings/networksettings2/opietooth2/OTSniffGUI.ui @@ -1,230 +1,229 @@ <!DOCTYPE UI><UI> <class>OTSniffGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>OTSniffGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>274</width> - <height>160</height> + <height>173</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Bluetooth Sniffing</string> </property> <property> <name>layoutMargin</name> </property> + <property> + <name>layoutSpacing</name> + </property> <vbox> <property stdset="1"> <name>margin</name> <number>3</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>2</number> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout3</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>Display data</string> </property> </widget> <widget> <class>QComboBox</class> <item> <property> <name>text</name> <string>Hex</string> </property> </item> <item> <property> <name>text</name> <string>Ascii</string> </property> </item> <item> <property> <name>text</name> <string>Both</string> </property> </item> <property stdset="1"> <name>name</name> <cstring>DataFormat_CB</cstring> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> <cstring>EnableTrace_CB</cstring> </property> <property stdset="1"> <name>text</name> <string>Trace</string> </property> </widget> </hbox> </widget> <widget> - <class>QListBox</class> + <class>QTextView</class> <property stdset="1"> <name>name</name> - <cstring>Output_LB</cstring> - </property> - <property stdset="1"> - <name>selectionMode</name> - <enum>NoSelection</enum> + <cstring>Output_TV</cstring> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout3</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>Save_But</cstring> </property> <property stdset="1"> <name>text</name> <string>Save</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer2_2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>Load_But</cstring> </property> <property stdset="1"> <name>text</name> <string>Load</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>ClearLog_But</cstring> </property> <property stdset="1"> <name>text</name> <string>Clear log</string> </property> </widget> </hbox> </widget> </vbox> </widget> diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp index 5a890da..b14cc2f 100644 --- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp @@ -1,332 +1,348 @@ #include <opie2/odebug.h> #include <opie2/oledbox.h> #include <opie2/ofiledialog.h> using namespace Opie::Core; using namespace Opie::Ui; #include <qpe/resource.h> #include <qapplication.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qdialog.h> #include <qdir.h> #include <qfile.h> #include <qgroupbox.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qlistbox.h> #include <qlistview.h> #include <qmessagebox.h> #include <qprogressbar.h> #include <qpushbutton.h> +#include <qscrollbar.h> #include <qtextstream.h> +#include <qtextview.h> #include <Opietooth.h> #include <OTDriver.h> #include <OTPeer.h> #include <OTGateway.h> #include <OTSDPAttribute.h> #include <OTSDPService.h> #include <OTInquiry.h> #include <system.h> using namespace Opietooth2; namespace Opietooth2 { class PeerLVI : public QListViewItem { public : PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { Peer = P; } ~PeerLVI( void ) { } inline OTPeer * peer( void ) { return Peer; } private : OTPeer * Peer; }; class ChannelLVI : public QListViewItem { public : ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { Channel = Ch; } ~ChannelLVI( void ) { } inline int channel( void ) { return Channel; } private : int Channel; }; class DriverLVI : public QListViewItem { public : DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) { Driver = P; } ~DriverLVI( void ) { } inline OTDriver * driver( void ) { return Driver; } private : OTDriver * Driver; }; class LinkKeyLVI : public QListViewItem { public : LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { LinkKey = Ch; } ~LinkKeyLVI( void ) { } inline int index( void ) { return LinkKey; } private : int LinkKey; }; }; // // // // // OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) { OT = OTGateway::getOTGateway(); HciDump = 0; - Sys = new System(); } OTSniffing::~OTSniffing() { - printf( "CLOSE \n" ); - if ( HciDump ) { - HciDump->process().kill(); - delete HciDump; - } - delete Sys; + SLOT_Trace( 0 ); } -void OTSniffing::SLOT_Trace( bool ) { +void OTSniffing::SLOT_Trace( bool Run ) { + + if( ! Run ) { + if ( HciDump ) { + HciDump->process().kill(); + delete HciDump; + } + HciDump = 0; + return; + } + HciDump = new MyProcess(); QStringList SL; - SL << "hcidump"; + SL << "/usr/sbin/hcidump"; switch( DataFormat_CB->currentItem() ) { case 0 : // Hex SL << "-x"; break; case 1 : // Ascii SL << "-a"; break; case 2 : // both SL << "-X"; break; } SL << "-i"; SL << OT->scanWith()->devname(); connect( HciDump, SIGNAL( stdoutLine( const QString & ) ), this, SLOT( SLOT_Show( const QString & ) ) ); connect( HciDump, SIGNAL(processExited(MyProcess*) ), this, SLOT( SLOT_ProcessExited(MyProcess*) ) ); - if( ! Sys->runAsRoot( SL, HciDump ) ) { + HciDump->process() << SL; + + if( ! HciDump->process().start( OProcess::DontCare, + OProcess::AllOutput ) + ) { QMessageBox::warning(0, tr("Run hcidump"), tr("Cannot start %1").arg(SL.join(" ")) ); delete HciDump; HciDump = 0; } } void OTSniffing::SLOT_Show( const QString & S ) { printf( "%s\n", S.latin1() ); - Output_LB->insertItem( S ); - Output_LB->setCurrentItem( Output_LB->count()-1 ); - Output_LB->ensureCurrentVisible(); + Output_TV->setText( Output_TV->text() + S + "\n" ); + + QScrollBar *scroll = Output_TV->verticalScrollBar(); + scroll->setValue(scroll->maxValue()); + //Output_LB->insertItem( S ); + //Output_LB->setCurrentItem( Output_LB->count()-1 ); + //Output_LB->ensureCurrentVisible(); } void OTSniffing::SLOT_ProcessExited( MyProcess * ) { printf( "Exited\n" ); delete HciDump; HciDump = 0; } void OTSniffing::SLOT_Save( void ) { QString S = OFileDialog::getSaveFileName( OFileSelector::Extended, QDir::home().path(), QString::null, MimeTypes(), this ); if( ! S.isEmpty() ) { QFile F( S ); if( ! F.open( IO_WriteOnly ) ) { QMessageBox::warning(0, tr("Save log"), tr("Cannot open %1").arg(S) ); return; } QTextStream TS( &F ); TS << S << endl; } } void OTSniffing::SLOT_Load( void ) { QString S = OFileDialog::getOpenFileName( OFileSelector::Extended, QDir::home().path(), QString::null, MimeTypes(), this ); if( ! S.isEmpty() ) { QFile F( S ); if( ! F.open( IO_ReadOnly ) ) { QMessageBox::warning(0, tr("Save log"), tr("Cannot open %1").arg(S) ); return; } QTextStream TS ( &F ); SLOT_ClearLog(); S = TS.read(); - Output_LB->insertStringList( QStringList::split( "\n", S ) ); + // Output_LB->insertStringList( QStringList::split( "\n", S ) ); + Output_TV->setText( S ); } } void OTSniffing::SLOT_ClearLog( void ) { - Output_LB->clear(); + // Output_LB->clear(); + Output_TV->setText( "" ); } // // // // // OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : OTPairingGUI( parent ) { OT = OTGateway::getOTGateway(); Icons = (_IC ) ? _IC : new OTIcons(); MyIcons = (_IC == 0 ); // unpairing can only be done if bluetooth is disabled Unpair_But->setEnabled( ! OT->isEnabled() ); if( ! OT->isEnabled() ) { Unpair_LBL->hide(); } else { Unpair_LBL->show(); } // open linkkey file and load pairs LinkKeyArray Keys = OT->getLinkKeys(); LinkKeyLVI * it; OTPeer * P; OTDriver * D; for( unsigned int i = 0 ; i < Keys.count(); i ++ ) { it = new LinkKeyLVI( i, Pairs_LV ); P = 0; D = OT->findDriver( Keys[i].from() ); if( D ) { it->setText( 0, D->devname() ); // we are source P = OT->findPeer( Keys[i].to() ); if( P ) { // put name it->setText( 1, P->name() ); } else { // unknown it->setText( 1, Keys[i].to().toString() ); } // and put address as sub QListViewItem * Sub = new QListViewItem( it ); Sub->setText( 0, D->address().toString() ); Sub->setText( 1, Keys[i].to().toString() ); } else { // perhaps we are destination D = OT->findDriver( Keys[i].to() ); if( D ) { it->setText( 1, D->devname() ); // we are source P = OT->findPeer( Keys[i].from() ); if( P ) { // put name it->setText( 0, P->name() ); } else { // unknown it->setText( 0, Keys[i].from().toString() ); } // and put address as sub QListViewItem * Sub = new QListViewItem( it ); Sub->setText( 0, Keys[i].from().toString() ); Sub->setText( 1, D->address().toString() ); } else { // nor source nor destination -> unknown it->setText( 0, Keys[i].from().toString() ); it->setText( 1, Keys[i].to().toString() ); } } } } OTPairing::~OTPairing() { if( MyIcons ) delete Icons; OTGateway::releaseOTGateway(); } void OTPairing::SLOT_Unpair( ) { // find selected pair diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.h b/noncore/settings/networksettings2/opietooth2/Opietooth.h index 2b20975..e66787f 100644 --- a/noncore/settings/networksettings2/opietooth2/Opietooth.h +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.h @@ -1,150 +1,148 @@ #ifndef OPIETOOTH_H #define OPIETOOTH_H #include <OTIcons.h> class MyProcess; -class System; namespace Opie { namespace Ui { class OLedBox; }; }; #include <OTSniffGUI.h> namespace Opietooth2 { class OTGateway; class OTDriver; class OTInquiry; class OTPeer; class PeerLVI; class OTSniffing : public OTSniffGUI { Q_OBJECT public : OTSniffing( QWidget * parent ); ~OTSniffing(); private slots : void SLOT_Trace( bool ); void SLOT_ClearLog( void ); void SLOT_Load( void ); void SLOT_Save( void ); void SLOT_ProcessExited( MyProcess * ); void SLOT_Show( const QString & ); signals : protected : private : OTGateway * OT; MyProcess * HciDump; - System * Sys; }; }; #include <OTPairingGUI.h> namespace Opietooth2 { class OTPairing : public OTPairingGUI { Q_OBJECT public : OTPairing( QWidget * parent, OTIcons * _Ic = 0 ); ~OTPairing(); private slots : void SLOT_Unpair( void ); signals : protected : private : bool MyIcons; OTIcons * Icons; OTGateway * OT; }; }; #include <OTScanGUI.h> namespace Opietooth2 { class OTGateway; class OTDriver; class OTInquiry; class OTPeer; class OTScan : public OTScanGUI { Q_OBJECT public : OTScan( QWidget * parent, OTIcons * _Ic = 0 ); ~OTScan(); // static function to return a device and a channel static int getDevice( OTPeer *& Peer, int & Channel, OTGateway * OT, const UUIDVector & Filter = 0, QWidget* Parent = 0); // show only services that match any of the filter void setScanFilter( const UUIDVector & Filter ); void resetScanFilter( void ); inline OTPeer * selectedPeer( void ) { return SelectedPeer; } inline int selectedChannel( void ) { return SelectedChannel; } public slots : private slots : void SLOT_DoScan( bool ); void SLOT_NewPeer( OTPeer *, bool ); void SLOT_FinishedDetecting(); void SLOT_Show( QListViewItem *); void SLOT_RefreshServices( void ); void SLOT_RefreshState( void ); void SLOT_CleanupOld( void ); void SLOT_UpdateStrength( void ); void SLOT_PeerState( OTPeer * ); void SLOT_Selected( QListViewItem * ); signals : void selected( void ); protected : private : void refreshState( PeerLVI *, bool ); void scanMode( bool ); // load scanned devices bool MyIcons; |