29 files changed, 818 insertions, 300 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth.pro b/noncore/settings/networksettings2/bluetooth/bluetooth.pro index 180bda9..2e1e138 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth.pro +++ b/noncore/settings/networksettings2/bluetooth/bluetooth.pro @@ -1,21 +1,22 @@ TEMPLATE = lib CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/plugins/networksettings2 HEADERS = bluetooth_NN.h \ bluetoothBNEP_NNI.h \ bluetoothRFCOMM_NNI.h \ bluetoothBNEPedit.h \ bluetoothRFCOMMedit.h SOURCES = bluetooth_NN.cpp \ bluetoothBNEP_NNI.cpp \ bluetoothRFCOMM_NNI.cpp \ bluetoothBNEPedit.cpp \ + bluetoothBNEPrun.cpp \ bluetoothRFCOMMedit.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 LIBS += -lqpe INTERFACES = bluetoothBNEPGUI.ui bluetoothRFCOMMGUI.ui TARGET = bluetooth VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index 73312c6..d8420b9 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -1,37 +1,50 @@ #include "bluetoothBNEPedit.h" #include "bluetoothBNEP_NNI.h" #include "bluetooth_NN.h" -ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : ANetNodeInstance( PNN ) { +ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : + ANetNodeInstance( PNN ), Data() { GUI = 0; RT = 0; + Data.AllowAll = 1; } -void ABluetoothBNEP::setSpecificAttribute( QString & , QString & ) { +void ABluetoothBNEP::setSpecificAttribute( QString & S, QString & A ) { + if( S == "bdaddress" ) { + Data.BDAddress << A; + } else if ( S == "allowall" ) { + Data.AllowAll = 1; + } } -void ABluetoothBNEP::saveSpecificAttribute( QTextStream & ) { +void ABluetoothBNEP::saveSpecificAttribute( QTextStream & TS ) { + TS << "allowall=" << Data.AllowAll << endl; + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++it ) { + TS << "bdaddress=" << (*it) << endl; + } } QWidget * ABluetoothBNEP::edit( QWidget * parent ) { - GUI = new BluetoothBNEPEdit( parent ); - GUI->showData( Data ); - return GUI; + GUI = new BluetoothBNEPEdit( parent ); + GUI->showData( Data ); + return GUI; } QString ABluetoothBNEP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothBNEP::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool ABluetoothBNEP::hasDataFor( const QString & ) { return 0; } bool ABluetoothBNEP::generateDataForCommonFile( SystemFile & , long ){ return 0; } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h index 037b7b1..03c6903 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h @@ -1,8 +1,11 @@ #ifndef BLUETOOTHBNEP_DATA_H #define BLUETOOTHBNEP_DATA_H +#include <qstringlist.h> + typedef struct BluetoothBNEPData { - long x; + bool AllowAll; + QStringList BDAddress; } BluetoothBNEPData_t; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp index 9a3156b..195dbae 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp @@ -1,26 +1,48 @@ #include <qtopia/qcopenvelope_qws.h> +#include <qlistview.h> +#include <qcheckbox.h> #include <GUIUtils.h> #include "bluetoothBNEPedit.h" BluetoothBNEPEdit::BluetoothBNEPEdit( QWidget * Parent ) : BluetoothBNEPGUI( Parent ){ } QString BluetoothBNEPEdit::acceptable( void ) { + if( ( ! AnyPAN_CB->isChecked() ) && + BTPANServers_LV->firstChild() == 0 ) { + return tr("<p>No bluetooth device addresses specified</p>"); + } + return QString(); } -bool BluetoothBNEPEdit::commit( BluetoothBNEPData & ) { - return 0; +bool BluetoothBNEPEdit::commit( BluetoothBNEPData & Data ) { + QListViewItem * it = BTPANServers_LV->firstChild(); + Data.BDAddress.clear(); + while( it ) { + Data.BDAddress << it->text(0); + it = it->nextSibling(); + } + return 0; } -void BluetoothBNEPEdit::showData( BluetoothBNEPData & ) { +void BluetoothBNEPEdit::showData( BluetoothBNEPData & Data ) { + QListViewItem * lvit; + BTPANServers_LV->clear(); + + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++it ) { + lvit = new QListViewItem(BTPANServers_LV); + lvit->setText( 0, (*it) ); + } } void BluetoothBNEPEdit::SLOT_StartBTMgr( void ) { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( "bluetooth-manager" ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp new file mode 100644 index 0000000..24e4b7b --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp @@ -0,0 +1,249 @@ +#include <qfile.h> +#include <qfileinfo.h> +#include <qtextstream.h> +#include <resources.h> +#include "bluetoothBNEPrun.h" + +QDict<QString> * BluetoothBNEPRun::PANConnections = 0; + +void BluetoothBNEPRun::detectState( NodeCollection * NC ) { + // unavailable : no card found + // available : card found and assigned to us or free + // up : card found and assigned to us and up + QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); + System & Sys = NSResources->system(); + InterfaceInfo * Run; + QFile F( S ); + + Log(("Detecting for %s\n", NC->name().latin1() )); + + if( F.open( IO_ReadOnly ) ) { + // could open file -> read interface and assign + QString X; + bool accepted = 0; + QTextStream TS(&F); + X = TS.readLine(); + Log(("%s exists : %s\n", S.latin1(), X.latin1() )); + // find interface + if( handlesInterface( X ) ) { + + Log(("Handles interface %s, PANC %p\n", X.latin1(), PANConnections )); + if( PANConnections == 0 ) { + // load connections that are active + // format : bnep0 00:60:57:02:71:A2 PANU + FILE * OutputOfCmd = popen( "pand --show", "r" ) ; + + PANConnections = new QDict<QString>; + + if( OutputOfCmd ) { + char ch; + // could fork + // read all data + QString Line = ""; + while( 1 ) { + if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) { + // eof + break; + } + if( ch == '\n' || ch == '\r' ) { + if( ! Line.isEmpty() ) { + if( Line.startsWith( "bnep" ) ) { + QStringList SL = QStringList::split( " ", Line ); + Log(("Detected PAN %s %s\n", + SL[0].latin1(), SL[1].latin1() )); + PANConnections->insert( SL[0], new QString(SL[1])); + } + Line=""; + } + } else { + Line += ch; + } + } + } + + pclose( OutputOfCmd ); + } + + // check if this runtime allows connection to node + if( ! Data.AllowAll ) { + // has addresses + for ( QStringList::Iterator it = Data.BDAddress.begin(); + ! accepted && it != Data.BDAddress.end(); + ++ it ) { + for( QDictIterator<QString> it2( *(PANConnections) ); + it2.current(); + ++ it2 ) { + if( X == it2.currentKey() && + (*it) == *(it2.current()) + ) { + // found + Log(("%s accepts connections to %s\n", + NC->name().latin1(), + it2.current()->latin1() )); + accepted = 1; + break; + } + } + } + } else { + Log(("%s accepts any connection\n", NC->name().latin1() )); + // accept any + accepted = 1; + } + + if( accepted ) { + // matches and is allowed for this node + for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( X == Run->Name ) { + Log(("%s Assigned %p\n", NC->name().latin1(), Run )); + Run->assignNode( netNode() ); + assignInterface( Run ); + NC->setCurrentState( IsUp ); + return; + } + } + } + } + } + + Log(("Assigned %p\n", assignedInterface() )); + if( ( Run = assignedInterface() ) ) { + // we already have an interface assigned -> still present ? + if( ! Run->IsUp ) { + // usb is still free -> keep assignment + NC->setCurrentState( Available ); + return; + } // else interface is up but NOT us -> some other profile + } + + // nothing (valid) assigned to us + assignInterface( 0 ); + + // find possible interface + for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + + Log(("%s %d %d=%d %d\n", + Run->Name.latin1(), + handlesInterface( Run->Name ), + Run->CardType, ARPHRD_ETHER, + ! Run->IsUp )); + + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER && + ! Run->IsUp + ) { + Log(("Released(OFF)\n" )); + // proper type, and Not UP -> free + NC->setCurrentState( Off ); + return; + } + } + // no free found + Log(("None available\n" )); + + NC->setCurrentState( Unavailable ); +} + +bool BluetoothBNEPRun::setState( NodeCollection * NC, Action_t A, bool ) { + + // we only handle activate and deactivate + switch( A ) { + case Activate : + { + if( NC->currentState() != Off ) { + return 0; + } + InterfaceInfo * N = getInterface(); + if( ! N ) { + // no interface available + NC->setCurrentState( Unavailable ); + return 0; + } + // because we were OFF the interface + // we get back is NOT assigned + N->assignNode( netNode() ); + assignInterface( N ); + Log(("Assing %p\n", N )); + NC->setCurrentState( Available ); + return 1; + } + case Deactivate : + if( NC->currentState() == IsUp ) { + // bring down first + if( ! connection()->setState( Down ) ) + // could not ... + return 0; + } else if( NC->currentState() != Available ) { + return 1; + } + assignedInterface()->assignNode( 0 ); // release + assignInterface( 0 ); + NC->setCurrentState( Off ); + return 1; + default : + // FT + break; + } + return 0; +} + +bool BluetoothBNEPRun::canSetState( State_t Curr , Action_t A ) { + // we only handle up down activate and deactivate + switch( A ) { + case Activate : + { // at least available + if( Curr == Available ) { + return 1; + } + // or we can make one available + InterfaceInfo * N = getInterface(); + if( ! N || N->assignedNode() != 0 ) { + // non available or assigned + return 0; + } + return 1; + } + case Deactivate : + return ( Curr >= Available ); + default : + // FT + break; + } + return 0; +} + +// get interface that is free or assigned to us +InterfaceInfo * BluetoothBNEPRun::getInterface( void ) { + + System & S = NSResources->system(); + InterfaceInfo * best = 0, * Run; + + for( QDictIterator<InterfaceInfo> It(S.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER + ) { + // this is a bluetooth card + if( Run->assignedNode() == netNode() ) { + // assigned to us + return Run; + } else if( Run->assignedNode() == 0 ) { + // free + best = Run; + } + } + } + return best; // can be 0 +} + +bool BluetoothBNEPRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; +} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index c168429..ce03cbb 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,31 +1,34 @@ #include <asdevice.h> #include "bluetoothBNEPdata.h" class BluetoothBNEPRun : public AsDevice { public : BluetoothBNEPRun( ANetNodeInstance * NNI, - BluetoothBNEPData & Data ) : AsDevice( NNI ) + BluetoothBNEPData & D ) : + AsDevice( NNI ), + Data( D), + Pat( "bnep[0-6]" ) { } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } virtual AsDevice * device( void ) { return asDevice(); } protected : - void detectState( NodeCollection * ) - { } - - bool setState( NodeCollection * , Action_t, bool ) - { return 0; } + void detectState( NodeCollection * ); + bool setState( NodeCollection * , Action_t, bool ); + bool canSetState( State_t , Action_t ); + bool handlesInterface( const QString & ); - bool canSetState( State_t , Action_t ) - { return 0; } +private : - bool handlesInterface( const QString & ) - { return 0; } + InterfaceInfo * getInterface( void ); + BluetoothBNEPData & Data; + static QDict<QString> * PANConnections; + QRegExp Pat; }; diff --git a/noncore/settings/networksettings2/lancard/lancardedit.cpp b/noncore/settings/networksettings2/lancard/lancardedit.cpp index ffe9bf6..c00d7aa 100644 --- a/noncore/settings/networksettings2/lancard/lancardedit.cpp +++ b/noncore/settings/networksettings2/lancard/lancardedit.cpp @@ -93,51 +93,51 @@ void LanCardEdit::populateList( void ) { NIt.current(); ++NIt ) { if( NIt.current()->MACAddress == (*it) ) { Found = 1; break; } } CLI->setPixmap( 0, NSResources->getPixmap( (Found) ? "add" : "remove" ) ); } } // rescan system for new cards void LanCardEdit::SLOT_ScanCards( void ) { LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass(); // add any NIC that is new and matches our interfacename System & S = NSResources->system(); QRegExp R( "eth[0-9]" ); // populate with all lancards in system for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { - fprintf( stderr, "TEST %s %s\n", + Log(( "TEST %s %s\n", It.current()->Name.latin1(), - It.current()->MACAddress.latin1() ); + It.current()->MACAddress.latin1() )); if( R.match( It.current()->Name ) >= 0 && ( It.current()->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || It.current()->CardType == ARPHRD_IEEE1394 #endif ) ) { // old item ? QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); while( CLI ) { if( CLI->text(0) == It.current()->MACAddress ) { break; } CLI = (QCheckListItem *)CLI->nextSibling(); } if( ! CLI ) { // new item CLI = new QCheckListItem( LanCards_LV, It.current()->MACAddress, QCheckListItem::CheckBox ); } diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 30d1270..6c969fc 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -57,77 +57,84 @@ int main( int argc, char * argv[] ) { // called from system to request something GuiType = QApplication::Tty; Action = ACT_REQUEST; } // Start Qt #ifdef _WS_QWS_ // because QPEApplication does not handle GuiType well if( GuiType == QApplication::Tty ) { // this cast is NOT correct but we do not use // TheApp anymore ... TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); } else { TheApp = new QPEApplication( argc, argv, GuiType ); } #else TheApp = new QApplication( argc, argv, GuiType ); #endif // init qt with app widget switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; + Log(("ACT_REQUEST\n")); if( NS.canStart( argv[1] ) ) { QString S; + Log(("NEED FOR PROMPT\n" )); S.sprintf( QPEApplication::qpeDir()+ "/bin/networksettings2" ); char * MyArgv[4]; MyArgv[0] = "networksettings2"; MyArgv[1] = "--prompt"; MyArgv[2] = argv[1]; MyArgv[3] = NULL; NSResources->system().execAsUser( S, MyArgv ); // if we come here , failed printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_REGEN : { NetworkSettingsData NS; + Log(("REGEN\n" )); // regen returns 0 if OK rv = (NS.regenerate()) ? 1 : 0; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); + Log(("PROMPT\n" )); if( AP.exec() == QDialog::Accepted ) { printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); } else { printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_GUI : { QWidget * W = new NetworkSettings(0); + Log(("GUI\n" )); TheApp->setMainWidget( W ); W->show(); #ifdef _WS_QWS_ W->showMaximized(); #else W->resize( W->sizeHint() ); #endif rv = TheApp->exec(); delete W; } break; } + LogClose(); + return rv; } #endif // main.cpp diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 41e1c53..3e24c5f 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -1,66 +1,78 @@ #include <system.h> #include <asdevice.h> #include "networkrun.h" void NetworkRun::detectState( NodeCollection * NC ) { RuntimeInfo * RI = netNode()->nextNode()->runtime(); AsDevice * Next = RI->asDevice(); InterfaceInfo * II = Next->assignedInterface(); if( II ) { // device has assigned interface NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); return; } + Log(( "%s not ! UP or ava\n", NC->name().latin1() )); // has no interface -> delegate RI->detectState( NC ); } bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { // we handle UP and DOWN RuntimeInfo * RI = netNode()->nextNode()->runtime(); AsDevice * Next = RI->asDevice(); InterfaceInfo * II = Next->assignedInterface(); if( A == Up ) { // we can bring UP if lower level is available if( NC->currentState() == Available || Force ) { QString S; S.sprintf( "ifup %s=%s-c%d-allowed", II->Name.latin1(), II->Name.latin1(), connection()->number() ); NSResources->system().runAsRoot( S ); } return 1; } else if( A == Down ) { - if( NC->currentState() == IsUp || Force ) { - QString S; - S.sprintf( "ifdown %s=%s-c%d-allowed", - II->Name.latin1(), II->Name.latin1(), - connection()->number() ); - NSResources->system().runAsRoot( S ); + QString S; + if( Force ) { + Log(("Force mode %d\n", Force )); + for( int i = 0; + i < RI->netNode()->nodeClass()->instanceCount(); + i ++ ) { + S.sprintf( "ifdown %s", + RI->netNode()->nodeClass()->genNic( i ).latin1() ); + NSResources->system().runAsRoot( S ); + } + } else { + if( NC->currentState() == IsUp ) { + S.sprintf( "ifdown %s=%s-c%d-allowed", + II->Name.latin1(), II->Name.latin1(), + connection()->number() ); + NSResources->system().runAsRoot( S ); + } } return 1; } // delegate - return RI->setState( NC, A ); + return RI->setState( NC, A, Force ); } bool NetworkRun::canSetState( State_t Curr, Action_t A ) { // we handle UP and DOWN RuntimeInfo * RI = netNode()->nextNode()->runtime(); if( A == Up ) { return ( Curr == Available ); } else if( A == Down ) { return ( Curr == IsUp ); } // delegate return RI->canSetState( Curr, A ); } bool NetworkRun::handlesInterface( const QString & S ) { // donno -> pass deeper return netNode()->nextNode()->runtime()->handlesInterface(S); } diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index b36c7a0..6ee4106 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,25 +1,26 @@ #include <stdio.h> +#include <unistd.h> #include <qpe/qpeapplication.h> #include <qlistbox.h> #include <qgroupbox.h> #include <qtimer.h> #include <qlistbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qiconview.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> #include <asdevice.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" NetworkSettings::NetworkSettings( QWidget *parent, const char *name, WFlags fl ) : NetworkSettingsGUI(parent,name,fl), NSD() { UpdateTimer = new QTimer( this ); @@ -40,194 +41,209 @@ NetworkSettings::NetworkSettings( QWidget *parent, // populate main Listbox Profiles_LB->clear(); { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); } } if( Profiles_LB->count() ) { Profiles_LB->setSelected( 0, TRUE ); } // if no profiles -> auto popup editing if( NSResources->connections().count() == 0 ) { QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); } + connect( &(NSResources->system()), + SIGNAL( lineFromCommand(const QString &) ), + this, SLOT( SLOT_CmdMessage(const QString &) ) ); + UpdateTimer->start( 5000 ); connect( UpdateTimer, SIGNAL( timeout() ), this, SLOT( SLOT_RefreshStates() ) ); /* Add QCopChannel */ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } NetworkSettings::~NetworkSettings() { QString S; S = NSD.generateSettings(); if( ! S.isEmpty() ) { QMessageBox::warning( 0, tr( "In System Config" ), S ); } S = NSD.saveSettings(); if( ! S.isEmpty() ) { // problem saving QMessageBox::warning( 0, tr( "Saving setup" ), S ); } } +void NetworkSettings::SLOT_CmdMessage( const QString & S ) { + Messages_LB->insertItem( S ); + Messages_LB->setCurrentItem( Messages_LB->count()-1 ); + Messages_LB->ensureCurrentVisible(); +} + void NetworkSettings::SLOT_RefreshStates( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember if( LBI ) { NodeCollection * NC; NSResources->system().probeInterfaces(); // update current selection only NC = NSResources->findConnection( LBI->text() ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { updateProfileState( LBI ); } } } /* -> LATER !! bool is; NodeCollection * NC; for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { NC = NSResources->findConnection( Profiles_LB->text(i) ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { is = Profiles_LB->isSelected(i); Profiles_LB->changeItem( NC->statePixmap(NewS), NC->name(), i ); if( is ) { Profiles_LB->setSelected( i, TRUE ); } } } } if( ci >= 0 ) Profiles_LB->setCurrentItem( ci ); */ } +void NetworkSettings::SLOT_NoLongerBusy( void ) { + NSResources->busy( FALSE ); +} void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } void NetworkSettings::SLOT_DeleteNode( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; if( QMessageBox::warning( 0, tr( "Removing profile" ), tr( "Remove selected profile ?" ), 1, 0 ) == 1 ) { NSResources->removeConnection( LBI->text() ); delete LBI; setModified( 1 ); NSD.forceGeneration(1); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; EditConnection EC( this ); if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); if( ! NC ) { return; } OldName = NC->name(); EC.setConnection( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); + NSResources->busy( TRUE ); + QTimer::singleShot( 1000, this, SLOT( SLOT_NoLongerBusy() )); // we need to retry while( 1 ) { if( EC.exec() == QDialog::Accepted ) { // toplevel item -> store NodeCollection * NC = EC.connection(); if( NC->isModified() ) { setModified( 1 ); if( LBI ) { if( NC->name() != OldName ) { // find if new name is free NodeCollection * LCN = NSResources->findConnection( NC->name() ); if( LCN ) { QMessageBox::warning( 0, tr( "In System Config" ), tr( "Name %1 already exists" ).arg(NC->name()) ); continue; // restart exec } // else new name // new name -> remove item NSResources->removeConnection( OldName ); NSResources->addConnection( NC ); } // else not changed // must add it here since change will trigger event Profiles_LB->changeItem( NC->devicePixmap(), NC->name(), Profiles_LB->index( LBI ) ); } else { // new item int ci = Profiles_LB->count(); NSResources->addConnection( NC ); - NC->setNumber( NC->maxConnectionNumber()+1 ); + NC->setNumber( NSResources->assignConnectionNumber() ); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); Profiles_LB->setSelected( ci, TRUE ); } updateProfileState( LBI ); } } else { // cancelled : reset connection if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); NC->reassign(); } } break; } // reenable UpdateTimer->start( 5000 ); } void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { if( LBI == 0 ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); @@ -236,73 +252,78 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { // is button On or Off bool DisabledOn, OnOn, ConnectOn; EnabledPossible = OnPossible = ConnectPossible = 1; DisabledOn = 1; OnOn = ConnectOn = 0; switch( NC->state() ) { case Unknown : // cannot occur here break; case Unchecked : case Unavailable : // cannot do anything but recheck EnabledPossible = OnPossible = ConnectPossible = 0; break; case Disabled : OnPossible = ConnectPossible = 0; break; case Off : DisabledOn = 0; break; case Available : OnOn = 1; + Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); DisabledOn = 0; break; case IsUp : OnOn = ConnectOn = 1; + Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); DisabledOn = 0; break; } + if( ! OnOn ) { + Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); + } + // set button state Enable_TB->setEnabled( EnabledPossible ); On_TB->setEnabled( OnPossible ); Connect_TB->setEnabled( ConnectPossible ); Enable_TB->setOn( DisabledOn ); On_TB->setOn( OnOn ); Connect_TB->setOn( ConnectOn ); if( NC->description().isEmpty() ) { - Description_LBL->setText( tr( "No description" ) ); + Description_LBL->setText( tr( "<<No description>>" ) ); } else { Description_LBL->setText( NC->description() ); } - Profile_GB->setTitle( LBI->text() ); - State_LBL->setText( NC->stateName() ); + Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); } void NetworkSettings::SLOT_CheckState( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; updateProfileState( LBI ); } void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { SLOT_ShowNode( LBI ); } } void NetworkSettings::SLOT_GenerateConfig( void ) { QString S = NSD.generateSettings( TRUE ); if( ! S.isEmpty() ) { QMessageBox::warning( 0, tr( "Generating system configuration" ), S ); @@ -393,57 +414,62 @@ void NetworkSettings::SLOT_Connect( void ) { // up interface rv = NC->setState( Up ); break; case Off : // activate and bring up rv = ( NC->setState( Activate ) && NC->setState( Up ) ); break; default : // others no change break; } if( ! rv ) { QMessageBox::warning( 0, tr( "Activating profile" ), tr( "Cannot enable profile" ) ); } // we do not update the GUI but wait for the REAL upping of the device } void NetworkSettings::SLOT_Disconnect( void ) { + QString S; QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); + Log(( "Force interface %s down\n", NC->name().latin1() )); NC->setState( Down, 1 ); + // remove 'up' file to make sure + S.sprintf( "/tmp/Profile-%d.up", NC->number() ); + unlink( S.latin1() ); } void NetworkSettings::SLOT_ToMessages( void ) { Profile_GB->hide(); Messages_GB->show(); } void NetworkSettings::SLOT_ToProfile( void ) { Profile_GB->show(); Messages_GB->hide(); } void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); if( msg == "raise" ) { raise(); return; } /* if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } */ } diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index 97852af..8ffde06 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h @@ -7,46 +7,48 @@ class ANetNodeInstance; class QTimer; class QListBoxItem; class NetworkSettings : public NetworkSettingsGUI { Q_OBJECT public : NetworkSettings( QWidget *parent=0, const char *name=0, WFlags fl = 0 ); ~NetworkSettings( void ); static QString appName( void ) { return QString::fromLatin1("networksettings"); } bool isModified( void ) { return NSD.isModified(); } void setModified( bool m ) { NSD.setModified( m ); } public slots : + void SLOT_NoLongerBusy( void ); void SLOT_AddNode( void ); void SLOT_DeleteNode( void ); void SLOT_ShowNode( QListBoxItem * ); void SLOT_EditNode( QListBoxItem * ); void SLOT_CheckState( void ); void SLOT_Enable( void ); void SLOT_On( void ); void SLOT_Connect( void ); void SLOT_Disconnect( void ); void SLOT_GenerateConfig( void ); void SLOT_RefreshStates( void ); void SLOT_QCopMessage( const QCString&,const QByteArray& ); void SLOT_ToProfile( void ); void SLOT_ToMessages( void ); + void SLOT_CmdMessage( const QString & S ); private : void updateProfileState( QListBoxItem * it ); QTimer * UpdateTimer; NetworkSettingsData NSD; }; diff --git a/noncore/settings/networksettings2/networksettings2/Utils.h b/noncore/settings/networksettings2/networksettings2/Utils.h new file mode 100644 index 0000000..63ef51c --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/Utils.h @@ -0,0 +1,8 @@ +#ifndef __UTILS_H +#define __UTILS_H + +#define Log(x) VLog x +extern void VLog( char * Format, ... ); +extern void LogClose( void ); + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/asfullsetup.h b/noncore/settings/networksettings2/networksettings2/asfullsetup.h index e358a83..072de9a 100644 --- a/noncore/settings/networksettings2/networksettings2/asfullsetup.h +++ b/noncore/settings/networksettings2/networksettings2/asfullsetup.h @@ -1,20 +1,22 @@ #ifndef ASFULLSETUP_H #define ASFULLSETUP_H #include <netnode.h> // pure virtual (component oriented) interface of any // plugin that offers a full setup class AsFullSetup : public RuntimeInfo { public : AsFullSetup( ANetNodeInstance * NNI ) : RuntimeInfo( NNI ) { } virtual const QString & description( void ) = 0; + virtual bool triggersVPN( void ) + { return 0; } }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 1182543..8c80e0b 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -82,91 +82,90 @@ void ANetNodeInstance::initialize( void ) { void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ if( Attr == "name" ) { setName( Value.latin1() ); } else { setSpecificAttribute( Attr, Value ); } } void ANetNodeInstance::saveAttributes( QTextStream & TS ) { TS << "name=" << name() << endl; saveSpecificAttribute( TS ); } ANetNodeInstance * ANetNodeInstance::nextNode( void ) { return connection()->findNext( this ); } // // // NODECOLLECTION // // -long NodeCollection::MaxNr = -1; - NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; CurrentState = Unchecked; } NodeCollection::NodeCollection( QTextStream & TS ) : QList<ANetNodeInstance>() { long idx; bool InError = 0; QString S, A, N; IsModified = 0; Index = -1; Name=""; IsNew = 0; CurrentState = Unchecked; do { S = TS.readLine(); if( S.isEmpty() ) { if( InError ) { // remove all nodes clear(); } // empty line break; } idx = S.find('='); S.stripWhiteSpace(); A = S.left( idx ); A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { + Log(( "read number %s\n", N.latin1() )); setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); if( NNI && ! InError ) { append( NSResources->findNodeInstance( N ) ); } else { // could not find a node type -> collection invalid InError = 1; } } } while( 1 ); } NodeCollection::~NodeCollection( void ) { } const QString & NodeCollection::description( void ) { ANetNodeInstance * NNI = getToplevel(); return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; } void NodeCollection::append( ANetNodeInstance * NNI ) { NNI->setConnection( this ); @@ -274,37 +273,40 @@ QString NodeCollection::stateName( State_t S) { return qApp->translate( "networksettings2", "Unavailable"); case Disabled : return qApp->translate( "networksettings2", "Disabled"); case Off : return qApp->translate( "networksettings2", "Off"); case Available : return qApp->translate( "networksettings2", "Available"); case IsUp : return qApp->translate( "networksettings2", "IsUp"); case Unchecked : /* FT */ default : break; } return QString(""); } void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } +bool NodeCollection::triggersVPN() { + return getToplevel()->runtime()->asFullSetup()->triggersVPN(); +} // // // RUNTIMEINFO // // InterfaceInfo * RuntimeInfo::assignedInterface( void ) { return netNode()->nextNode()->runtime()->assignedInterface(); } AsDevice * RuntimeInfo::device( void ) { return netNode()->nextNode()->runtime()->device(); } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 5e36062..ca35c27 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,34 +1,36 @@ #ifndef NETNODE_H #define NETNODE_H #include <qtextstream.h> #include <qlist.h> #include <qdict.h> #include <qpixmap.h> #include <qobject.h> #include <time.h> +#include <Utils.h> + // difference feature interfaces class AsDevice; class AsLine; class AsConnection; class AsFullSetup; // needed for plugin creation function #include <qlist.h> class ANetNode; class ANetNodeInstance; class NodeCollection; class QTextStream; class RuntimeInfo; class InterfaceInfo; extern QString & deQuote( QString & X ); extern QString quote( QString X ); #include "systemfile.h" typedef enum State { // if we have not yet detected the state of the device Unchecked = 0, @@ -262,121 +264,121 @@ public : virtual bool canSetState( State_t Curr, Action_t A ) = 0; signals : // sent by device if state changes void stateChanged( State_t S, ANetNodeInstance * NNI ); protected : // connection this runtime info belongs to ANetNodeInstance * NNI; }; class NodeCollection : public QList<ANetNodeInstance> { public : NodeCollection( void ); NodeCollection( QTextStream & TS ); ~NodeCollection( void ); int number( void ) { return Number; } void setNumber( int i ) - { Number = i; if( MaxNr < i ) MaxNr = i; } + { Number = i; } bool isNew( void ) { return IsNew; } void setNew( bool N ) { IsNew = N ; } bool isModified( void ) { return IsModified; } void setModified( bool N ) { IsModified = N ; } bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } InterfaceInfo * assignedInterface( void ) { return getToplevel()->runtime()->assignedInterface(); } AsDevice * device() { return getToplevel()->runtime()->device(); } + bool triggersVPN(); + State_t state( bool Update = 0 ) - { if( CurrentState == Unchecked || Update ) { + { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, + Unchecked )); + if( CurrentState == Unchecked || Update ) { + Log(( "TL %p TLR %p\n", + getToplevel(), + getToplevel()->runtime() )); // need to get current state getToplevel()->runtime()->detectState( this ); } return CurrentState; } // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } bool setState( Action_t A, bool Force =0 ) { return getToplevel()->runtime()->setState( this, A, Force ); } bool canSetState( Action_t A ) { return getToplevel()->runtime()->canSetState( CurrentState, A ); } void save( QTextStream & TS ); void append( ANetNodeInstance * NNI ); // makes sure that all items in the connection point to // that connectoin void reassign( void ); ANetNodeInstance * getToplevel( void ); ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); const QString & name() { return Name; } const QString & description( void ); void setName( const QString & N) { Name = N; } State_t currentState( void ) { return CurrentState; } void setCurrentState( State_t S ) { CurrentState = S; } - long maxConnectionNumber( void ) - { return MaxNr; } - - static void resetMaxNr( void ) - { MaxNr = -1; } - private : int compareItems ( QCollection::Item item1, QCollection::Item item2 ); - static long MaxNr; long Number; // state of this connection State_t CurrentState; QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox int Index; bool IsModified; }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/networksettings2.pro b/noncore/settings/networksettings2/networksettings2/networksettings2.pro index f97c93b..16a946b 100644 --- a/noncore/settings/networksettings2/networksettings2/networksettings2.pro +++ b/noncore/settings/networksettings2/networksettings2/networksettings2.pro @@ -1,28 +1,28 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib$(PROJMAK) HEADERS = netnode.h \ resources.h \ system.h \ asline.h \ GUIUtils.h \ asconnection.h \ asfullsetup.h \ systemfile.h \ wextensions.h \ asdevice.h SOURCES = netnode.cpp \ GUIUtils.cpp \ system.cpp \ systemfile.cpp \ wextensions.cpp \ resources.cpp INCLUDEPATH += $(OPIEDIR)/include ../networksettings2 DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 +LIBS += -lqpe -lopiecore2 -lopieui2 INTERFACES = TARGET = networksettings2 VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index c95ac7f..71e84cd 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -2,48 +2,50 @@ #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <qpixmap.h> #include <qdir.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <opie2/odebug.h> #include <qtopia/resource.h> #include "netnode.h" #include "resources.h" #define PLUGINDIR "plugins/networksettings2" #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), ConnectionsMap() { _NSResources = this; + detectCurrentUser(); + // load available netnodes findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); bool Done; for ( ; OuterIt.current(); ++OuterIt ) { // find needs list ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; ANetNode::NetNodeList & NNL = *(NNLP); // must iterate this way to avoid duplication pointers for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); InnerIt.current(); ++InnerIt ) { if( InnerIt.current() == OuterIt.current() ) // avoid recursive continue; const char * Provides = InnerIt.current()->NetNode->provides(); NeedsRun = OuterIt.current()->NetNode->needs(); for( ; *NeedsRun; NeedsRun ++ ) { if( strcmp( Provides, *NeedsRun ) == 0 ) { @@ -59,312 +61,384 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), } } // define Node types to Description map NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); NodeTypeNameMap.insert( "line", tr( "Character device" ) ); NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); NodeTypeDescriptionMap.insert( "device", tr( "<p>Devices that can handle IP packets</p>" ) ); NodeTypeDescriptionMap.insert( "line", tr( "<p>Devices that can handle single bytes</p>" ) ); NodeTypeDescriptionMap.insert( "connection", tr( "<p>Nodes that provide working IP connections</p>" ) ); NodeTypeDescriptionMap.insert( "fullsetup", tr( "<p>Fully configured connection profile</p>" ) ); // define system files addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); // get access to the system TheSystem = new System(); - detectCurrentUser(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } +void TheNSResources::busy( bool B ) { +/* + if( B ) { + ShowWait->show(); + qApp->process + } else { + ShowWait->hide(); + } +*/ +} + /** * Load all modules that are found in the path * @param path a directory that is scaned for any plugins that can be loaded * and attempts to load them */ void TheNSResources::findAvailableNetNodes(const QString &path){ + Log(("Locate plugins in %s\n", path.latin1() )); QDir d(path); if(!d.exists()) return; QString lang = ::getenv("LANG"); // Don't want sym links d.setFilter( QDir::Files | QDir::NoSymLinks ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while ( (fi=it.current()) ) { if( fi->fileName().contains(".so")){ /* if loaded install translation */ if( loadNetNode(path + "/" + fi->fileName()) ) { QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ "/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+ ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } } ++it; } } +// used to find unique connection number +int TheNSResources::assignConnectionNumber( void ) { + bool found = 1; + for( int trial = 0; ; trial ++ ) { + found = 1; + for( QDictIterator<NodeCollection> it(ConnectionsMap); + it.current(); + ++it ) { + if( it.current()->number() == trial ) { + found = 0; + break; + } + } + + if( found ) { + Log(("Assign profile number %d\n", trial )); + return trial; + } + } +} + /** * Attempt to load a function and resolve a function. * @param pluginFileName - the name of the file in which to attempt to load * @param resolveString - function pointer to resolve * @return true of loading is successful */ bool TheNSResources::loadNetNode( const QString &pluginFileName, const QString &resolveString){ QLibrary *lib = new QLibrary(pluginFileName); void * res = lib->resolve(resolveString); if( ! res ){ delete lib; return 0; } GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; // Try to get an object. QList<ANetNode> PNN; getNetNodeList( PNN ); if( PNN.isEmpty() ) { delete lib; return 0; } ANetNode * NNP; for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { NetNode_t * NN; NNP = it.current(); NN = new NetNode_t; NN->NetNode = NNP; NN->TheLibrary = lib; NN->NodeCountInLib = PNN.count(); // store mapping - printf( "Store %s\n", NN->NetNode->name() ); AllNodeTypes.insert( NN->NetNode->name(), NN ); } return 1; } QPixmap TheNSResources::getPixmap( const QString & QS ) { + QPixmap P; QString S("networksettings2/"); S += QS; - fprintf( stderr, "%s\n", S.latin1() ); - return Resource::loadPixmap( S ); + Log(("%s\n", S.latin1() )); + P = Resource::loadPixmap( S ); + return ( P.isNull() ) ? QPixmap() : P; } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } const QString & TheNSResources::netNode2Name( const char * s ) { return NodeTypeNameMap[s]; } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } void TheNSResources::addConnection( NodeCollection * NC ) { ANetNodeInstance * NNI; ConnectionsMap.insert( NC->name(), NC ); // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { // new item addNodeInstance( NNI ); } } } void TheNSResources::removeConnection( const QString & N ) { NodeCollection * NC = findConnection( N ); if( ! NC ) return; // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } ConnectionsMap.remove( N ); } NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } +/* void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } +*/ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { // AnEV( "HOME=" ), -> SPECIAL // AnEV( "LOGNAME=" ), -> SPECIAL AnEV( "USER=" ), AnEV( "LD_LIBRARY_PATH=" ), AnEV( "PATH=" ), AnEV( "QTDIR=" ), AnEV( "OPIEDIR=" ), AnEV( "SHELL=" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; - // open proc dir and find all dirs in it - { QRegExp R("[0-9]+"); - QDir ProcDir( "/proc" ); - QString QPELoc = QPEApplication::qpeDir() + "bin/qpe"; - QFileInfo FI; - QStringList EL = ProcDir.entryList( QDir::Dirs ); - - // print it out - for ( QStringList::Iterator it = EL.begin(); - it != EL.end(); - ++it ) { - if( R.match( (*it) ) >= 0 ) { - QString S = ProcDir.path()+"/"+ (*it); - S.append( "/exe" ); - FI.setFile( S ); - // get the linke - S = FI.readLink(); - if( S == QPELoc ) { - // found running qpe - QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); - break; + if( getenv( "OPIEDIR" ) == 0 ) { + // nothing known + { // open proc dir and find all dirs in it + QRegExp R("[0-9]+"); + QDir ProcDir( "/proc" ); + QFileInfo FI; + QStringList EL = ProcDir.entryList( QDir::Dirs ); + + // print it out + for ( QStringList::Iterator it = EL.begin(); + it != EL.end(); + ++it ) { + if( R.match( (*it) ) >= 0 ) { + QString S = ProcDir.path()+"/"+ (*it); + S.append( "/exe" ); + FI.setFile( S ); + // get the link + S = FI.readLink(); + if( S.right( 8 ) == "/bin/qpe" ) { + // found running qpe + QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); + break; + } } } } - } - if( QPEEnvFile.isEmpty() ) { - // could not find qpe - fprintf( stderr, "Could not find qpe\n" ); - return; - } - - // FI now contains path ProcDir to the cmd dir - { char * Buf = 0; - char TB[1024]; - long BufSize = 0; - int fd; - int rd; - - fd = open( QPEEnvFile.latin1(), O_RDONLY ); - if( fd < 0 ) { - fprintf( stderr, "Could not open %s : %d\n", - QPEEnvFile.latin1(), errno ); + if( QPEEnvFile.isEmpty() ) { + // could not find qpe + Log(("Could not find qpe\n" )); return; } - while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { - Buf = (char *)realloc( Buf, BufSize+rd ); - memcpy( Buf+BufSize, TB, rd ); - BufSize += rd; - } + // FI now contains path ProcDir to the cmd dir + { char * Buf = 0; + char TB[1024]; + long BufSize = 0; + int fd; + int rd; + + fd = open( QPEEnvFile.latin1(), O_RDONLY ); + if( fd < 0 ) { + Log(("Could not open %s : %d\n", + QPEEnvFile.latin1(), errno )); + return; + } - char * Data = Buf; - char * DataEnd = Data+BufSize-1; - - // get env items out of list - while( Data < DataEnd ) { - if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { - CurrentUser.UserName = Data+8; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { - CurrentUser.HomeDir = Data+5; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else { - EnvVar_t * Run = EV; - while( Run->Name ) { - if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - break; + while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { + Buf = (char *)realloc( Buf, BufSize+rd ); + memcpy( Buf+BufSize, TB, rd ); + BufSize += rd; + } + + char * Data = Buf; + char * DataEnd = Data+BufSize-1; + + // get env items out of list + while( Data < DataEnd ) { + if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { + CurrentUser.UserName = Data+8; + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( Data ); + } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { + CurrentUser.HomeDir = Data+5; + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( Data ); + } else { + EnvVar_t * Run = EV; + while( Run->Name ) { + if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( Data ); + // put OPIEDIR in env + if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) { + putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); + + } + break; + } + Run ++; } - Run ++; } - } - Data += strlen( Data )+1; - } + Data += strlen( Data )+1; + } - free( Buf ); + free( Buf ); - if( ! CurrentUser.UserName.isEmpty() ) { - // find user info - struct passwd pwd; - struct passwd * pwdres; + if( ! CurrentUser.UserName.isEmpty() ) { + // find user info + struct passwd pwd; + struct passwd * pwdres; - if( getpwnam_r( CurrentUser.UserName.latin1(), - &pwd, TB, sizeof(TB), &pwdres ) || - pwdres == 0 ) { - fprintf( stderr, "Could not determine user %s : %d\n", - CurrentUser.UserName.latin1(), errno ); - return; + if( getpwnam_r( CurrentUser.UserName.latin1(), + &pwd, TB, sizeof(TB), &pwdres ) || + pwdres == 0 ) { + Log(("Could not determine user %s : %d\n", + CurrentUser.UserName.latin1(), errno )); + return; + } + CurrentUser.Uid = pwd.pw_uid; + CurrentUser.Gid = pwd.pw_gid; + } else{ + CurrentUser.Uid = + CurrentUser.Gid = -1; } - CurrentUser.Uid = pwd.pw_uid; - CurrentUser.Gid = pwd.pw_gid; - } else{ - CurrentUser.Uid = - CurrentUser.Gid = -1; } + + } else { + CurrentUser.UserName = getenv( "LOGNAME" ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( CurrentUser.UserName ); + + CurrentUser.HomeDir = getenv( "HOME" ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( CurrentUser.HomeDir ); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL"); + + CurrentUser.Uid = getuid(); + CurrentUser.Gid = getgid(); } } diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 3d6a44f..55d2f29 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -25,104 +25,107 @@ typedef struct NetNode_S { class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} QString UserName; QString HomeDir; int Uid; int Gid; QArray<char *> EnvList; }; typedef QDict<NetNode_t> Name2NetNode_t; typedef QDict<ANetNodeInstance > Name2Instance_t; typedef QDict<NodeCollection> Name2Connection_t; typedef QDict<SystemFile> Name2SystemFile_t; class TheNSResources { public : TheNSResources( void ); ~TheNSResources( ); + // give busy feedback + void busy( bool B ); + System & system() { return *TheSystem; } + int assignConnectionNumber(void); QPixmap getPixmap( const QString & Name ); Name2NetNode_t & netNodes( void ) { return AllNodeTypes; } bool netNodeExists( const QString & X ) { return AllNodeTypes.find(X)!=0; } ANetNode * findNetNode( const QString & N ) { NetNode_t * NNT = AllNodeTypes.find(N); return (NNT) ? NNT->NetNode : 0; } Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } void addSystemFile( SystemFile * SF ) { SystemFiles.insert( SF->name(), SF ); } ANetNodeInstance * createNodeInstance( const QString & S ) { ANetNodeInstance * NNI = 0; NetNode_t * NNT = AllNodeTypes[S]; if( ! NNT ) { return 0; } NNI = NNT->NetNode->createInstance(); NNI->initialize(); return NNI; } Name2Instance_t & netNodeInstances( void ) { return AllNodes; } void addNodeInstance( ANetNodeInstance * I ) { AllNodes.insert( I->name(), I ); } void removeNodeInstance( const QString & N ) { AllNodes.remove( N );} ANetNodeInstance * findNodeInstance( const QString & S ) { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); - void renumberConnections( void ); void addConnection( NodeCollection * NC ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); Name2Connection_t & connections( void ) { return ConnectionsMap; } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); void findAvailableNetNodes( const QString &path ); bool loadNetNode( const QString &pluginFileName, const QString &resolveString = "create_plugin"); QMap< QString, QString> NodeTypeNameMap; QMap< QString, QString> NodeTypeDescriptionMap; Name2Connection_t ConnectionsMap; System * TheSystem; Name2SystemFile_t SystemFiles; // all node type classes Name2NetNode_t AllNodeTypes; // all nodes Name2Instance_t AllNodes; - CurrentQPEUser CurrentUser; + CurrentQPEUser CurrentUser; }; extern TheNSResources * _NSResources; #define NSResources _NSResources #endif diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 2133d34..a579396 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -1,100 +1,127 @@ #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 <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" 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 ) : ProbedInterfaces() { +System::System( void ) : QObject(), ProbedInterfaces() { probeInterfaces(); } System::~System( void ) { if( ProcDevNet ) delete ProcDevNet; } int System::runAsRoot( const QString & S ) { QString MyS = S; char * usr = getenv("USER"); - int rv; + char ch; if( S.isEmpty() ) { // loophole to start shell return 8888; } if( usr == 0 || strcmp( usr, "root" ) ) { // unknown or non-root user -> use SUDO MyS.prepend( "sudo " ); } - fprintf( stderr, "Executing %s\n", MyS.latin1() ); - - rv = system( MyS.latin1() ) ; - switch( rv ) { - case -1 : - // cannot fork - return 1; - case 127 : - // cannot start shell - return 2; - default : - if( WEXITSTATUS(rv) != 0 ) { - // error in command - return 3; + Log(("Executing %s\n", MyS.latin1() )); + + emit lineFromCommand( tr("Command : ") + MyS ); + emit lineFromCommand( "---------------" ); + Log(( "Command : %s\n", MyS.latin1() ) ); + MyS += " 2>&1 "; + OutputOfCmd = popen( MyS.latin1(), "r" ) ; + if( ! OutputOfCmd ) { + // cannot fork + return 1; + } + + // read all data + QString Line = ""; + while( 1 ) { + if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) + // eof + break; + if( ch == '\n' || ch == '\r' ) { + if( ! Line.isEmpty() ) { + Log(( "read cmd output : **%s**\n", Line.latin1() ) ); + emit lineFromCommand( Line ); + Line = ""; + qApp->processEvents(); } + } else { + Line += ch; + } + } + + if( ! Line.isEmpty() ) { + emit lineFromCommand( Line ); + Log(( "read cmd output : **%s**\n", Line.latin1() ) ); + } + Log(( "End of command\n", Line.latin1() ) ); + + if( pclose( OutputOfCmd ) < 0 ) { + // error in command + return 3; } + // all is fine return 0; } 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" ) ) @@ -177,77 +204,77 @@ void System::probeInterfaces( void ) { delete ProcDevNet; ProcDevNet =0; return; } QString line; QString NicName; QTextStream procTs(ProcDevNet); int loc = -1; procTs.readLine(); // eat a line procTs.readLine(); // eat a line while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if((loc = line.find(":")) == -1) { continue; } NicName = line.left(loc); // set name for ioctl strcpy( ifrs.ifr_name, NicName.latin1() ); if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { // new nic - fprintf( stderr, "NEWNIC %s\n", NicName.latin1()); + Log(("NEWNIC %s\n", NicName.latin1())); IFI = new InterfaceInfo; IFI->Name = line.left(loc); IFI->NetNode = 0; ProbedInterfaces.insert( IFI->Name, IFI ); // get dynamic info if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); } else { IFI->IsPointToPoint = 0; } // settings that never change IFI->DstAddress = ""; if( IFI->IsPointToPoint ) { if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { IFI->DstAddress = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); } } IFI->CardType = 999999; IFI->MACAddress = ""; if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { - fprintf( stderr, "%s = %d\n", IFI->Name.latin1(), - ifrs.ifr_hwaddr.sa_family ); + Log(("%s = %d\n", IFI->Name.latin1(), + ifrs.ifr_hwaddr.sa_family )); IFI->CardType = ifrs.ifr_hwaddr.sa_family; switch( ifrs.ifr_hwaddr.sa_family ) { case ARPHRD_ETHER : // regular MAC address // valid address -> convert to regular ::: format // length = 6 bytes = 12 DIGITS -> 6 : IFI->MACAddress.sprintf( "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", HN( ifrs.ifr_hwaddr.sa_data[0] ), LN( ifrs.ifr_hwaddr.sa_data[0] ), HN( ifrs.ifr_hwaddr.sa_data[1] ), LN( ifrs.ifr_hwaddr.sa_data[1] ), HN( ifrs.ifr_hwaddr.sa_data[2] ), LN( ifrs.ifr_hwaddr.sa_data[2] ), HN( ifrs.ifr_hwaddr.sa_data[3] ), LN( ifrs.ifr_hwaddr.sa_data[3] ), HN( ifrs.ifr_hwaddr.sa_data[4] ), LN( ifrs.ifr_hwaddr.sa_data[4] ), HN( ifrs.ifr_hwaddr.sa_data[5] ), LN( ifrs.ifr_hwaddr.sa_data[5] ) ); break; #ifdef ARPHRD_IEEE1394 case ARPHRD_IEEE1394 : // Firewire Eth address @@ -272,84 +299,119 @@ void System::probeInterfaces( void ) { HN( ifrs.ifr_hwaddr.sa_data[8] ), LN( ifrs.ifr_hwaddr.sa_data[8] ), HN( ifrs.ifr_hwaddr.sa_data[9] ), LN( ifrs.ifr_hwaddr.sa_data[9] ), HN( ifrs.ifr_hwaddr.sa_data[10] ), LN( ifrs.ifr_hwaddr.sa_data[10] ), HN( ifrs.ifr_hwaddr.sa_data[11] ), LN( ifrs.ifr_hwaddr.sa_data[11] ), HN( ifrs.ifr_hwaddr.sa_data[12] ), LN( ifrs.ifr_hwaddr.sa_data[12] ), HN( ifrs.ifr_hwaddr.sa_data[13] ), LN( ifrs.ifr_hwaddr.sa_data[13] ) ); break; #endif case ARPHRD_PPP : // PPP break; case ARPHRD_IEEE80211 : // WLAN break; case ARPHRD_IRDA : // IRDA break; } } } else // else already probed before -> just update - fprintf( stderr, "OLDNIC %s\n", NicName.latin1()); + Log(("OLDNIC %s\n", NicName.latin1())); // get dynamic info if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); } else { IFI->IsUp = 0; IFI->HasMulticast = 0; } if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { IFI->Address = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); } else { IFI->Address = ""; IFI->IsUp = 0; } if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { IFI->BCastAddress = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); } else { IFI->BCastAddress = ""; } if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { IFI->Netmask = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); } else { IFI->Netmask = ""; } - fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ); + Log(("NIC %s UP %d\n", NicName.latin1(), IFI->IsUp )); } } void System::execAsUser( QString & Cmd, char * argv[] ) { CurrentQPEUser CU = NSResources->currentUser(); if( CU.UserName.isEmpty() ) { // if we come here, the exec was not successfull - fprintf( stderr, "User not known \n" ); + Log(("User not known \n" )); return; } // now we are ready to exec the requested command setuid( CU.Uid ); setgid( CU.Gid ); char ** envp = (char **)alloca( sizeof( char *) * (CU.EnvList.count()+1) ); for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { *(envp+i) = CU.EnvList[i]; } envp[CU.EnvList.count()]=NULL; execve( Cmd.latin1(), argv, envp ); // if we come here, the exec was not successfull - fprintf( stderr, "Could not exec : %d\n", errno ); + Log(("Could not exec : %d\n", errno )); +} + +#include <stdarg.h> +static FILE * logf = 0; + +void VLog( char * Format, ... ) { + va_list l; + + va_start(l, Format ); + + if( logf == (FILE *)0 ) { + // logf = fopen( "/tmp/ns2log", "a" ); + logf = stderr; + if( ! logf ) { + fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n", + errno ); + logf = (FILE *)1; + } else { + fprintf( logf, "____ OPEN LOGFILE ____\n"); + } + } + + if( (long)logf > 1 ) { + vfprintf( logf, Format, l ); + } + va_end( l ); + +} + +void LogClose( void ) { + if( (long)logf > 1 ) { + fprintf( logf, "____ CLOSE LOGFILE ____\n"); + fclose( logf ); + logf = 0; + } } diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index 96ee9bd..33af391 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h @@ -1,81 +1,90 @@ #ifndef __SYSTEM__H #define __SYSTEM__H // for hardware types #include <net/if_arp.h> #include <qdict.h> +#include <qobject.h> +#include <stdio.h> class ANetNodeInstance; class QFile; class InterfaceInfo { public : InterfaceInfo() : Name(), MACAddress(), BCastAddress(), Netmask(), DstAddress() { } ANetNodeInstance * assignedNode() { return NetNode; } void assignNode( ANetNodeInstance * NNI ) { NetNode = NNI; } ANetNodeInstance * NetNode; // netnode taking care of me QString Name; // name of interface int CardType; // type of card QString MACAddress; // MAC address QString Address; // IP Address QString BCastAddress; // Broadcast Address QString Netmask; // Netmask QString DstAddress; // Peer address (if P-t-P) bool IsUp; // interface is UP bool HasMulticast; // Supports Multicast bool IsPointToPoint; // IsPointToPoint card QString RcvBytes; QString SndBytes; QString RcvErrors; QString SndErrors; QString RcvDropped; QString SndDropped; QString Collisions; }; -class System { +class System : public QObject { + + Q_OBJECT public : System( void ); ~System( void ); QDict<InterfaceInfo> & interfaces( void ) { return ProbedInterfaces; } InterfaceInfo * interface( const QString& N ) { return ProbedInterfaces[N]; } // exec command as root int runAsRoot( const QString & S ); // exec command as user void execAsUser( QString & Cmd, char * argv[] ); // refresh stats for this interface void refreshStatistics( InterfaceInfo & ); // reloads interfaces void probeInterfaces( void ); +signals : + + void lineFromCommand( const QString & S ); + private : QDict<InterfaceInfo> ProbedInterfaces; + FILE * OutputOfCmd; QFile * ProcDevNet; }; #endif diff --git a/noncore/settings/networksettings2/networksettingsGUI.ui b/noncore/settings/networksettings2/networksettingsGUI.ui index 7ef2f64..6ed29f3 100644 --- a/noncore/settings/networksettings2/networksettingsGUI.ui +++ b/noncore/settings/networksettings2/networksettingsGUI.ui @@ -1,55 +1,55 @@ <!DOCTYPE UI><UI> <class>NetworkSettingsGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>NetworkSettingsGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>160</width> + <width>144</width> <height>260</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Network Settings</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>0</number> + <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QFrame</class> <property stdset="1"> <name>name</name> <cstring>Frame4</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> @@ -281,112 +281,48 @@ <property stdset="1"> <name>name</name> <cstring>Profile_GB</cstring> </property> <property stdset="1"> <name>title</name> <string>Profile</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> <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>TextLabel2_2</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>State</string> - </property> - </widget> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>State_LBL</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>State</string> - </property> - <property stdset="1"> - <name>indent</name> - <number>0</number> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer6_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> - </hbox> - </widget> - <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>Description_LBL</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>5</hsizetype> <vsizetype>7</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property stdset="1"> <name>text</name> <string></string> </property> @@ -464,49 +400,49 @@ </property> <property stdset="1"> <name>title</name> <string>Messages</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QListBox</class> <property stdset="1"> <name>name</name> - <cstring>Mesages_LB</cstring> + <cstring>Messages_LB</cstring> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer3</cstring> </property> <property stdset="1"> <name>orientation</name> @@ -593,38 +529,44 @@ <connection> <sender>Profiles_LB</sender> <signal>currentChanged(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ShowNode( QListBoxItem*)</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>doubleClicked(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_EditNode( QListBoxItem *)</slot> </connection> <connection> <sender>ToProfile_BUT</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ToProfile()</slot> </connection> <connection> <sender>ToMessages_BUT</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ToMessages()</slot> </connection> + <connection> + <sender>Disconnect_TB</sender> + <signal>clicked()</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_Disconnect()</slot> + </connection> <slot access="public">SLOT_AddNode()</slot> <slot access="public">SLOT_CheckState()</slot> <slot access="public">SLOT_Connect()</slot> <slot access="public">SLOT_DeleteNode()</slot> <slot access="public">SLOT_EditNode( QListBoxItem *)</slot> <slot access="public">SLOT_Enable()</slot> <slot access="public">SLOT_GenerateConfig()</slot> <slot access="public">SLOT_On()</slot> <slot access="public">SLOT_ShowNode( QListBoxItem*)</slot> <slot access="public">SLOT_ToMessages()</slot> <slot access="public">SLOT_ToProfile()</slot> <slot access="public">SLOT_Disconnect()</slot> </connections> </UI> diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index bb37f10..3b17548 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -1,44 +1,44 @@ #include <stdlib.h> #include <qpe/qpeapplication.h> #include <qtextstream.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include "nsdata.h" #include <asdevice.h> #include <resources.h> static QString CfgFile; NetworkSettingsData::NetworkSettingsData( void ) { // init global resources structure new TheNSResources(); CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); - fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() ); + Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings Force = 0; IsModified = 0; loadSettings(); } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; } void NetworkSettingsData::loadSettings( void ) { QString Line, S; QString Attr, Value; long idx; QFile F( CfgFile ); QTextStream TS( &F ); do { if( ! F.open(IO_ReadOnly) ) break; @@ -58,53 +58,53 @@ void NetworkSettingsData::loadSettings( void ) { while( ! TS.atEnd() ) { S = Line = TS.readLine(); if ( S.isEmpty() || S[0] != '[' ) continue; S = S.mid( 1, S.length()-2 ); if( ! NSResources ) { continue; } if( S == "connection" ) { // load connections -> collections of nodes NodeCollection * NC = new NodeCollection( TS ); NSResources->addConnection( NC ); } else { ANetNode * NN = 0; ANetNodeInstance* NNI = 0; if( S.startsWith( "nodetype " ) ) { S = S.mid( 9, S.length()-9 ); S = deQuote(S); // try to find netnode NN = NSResources->findNetNode( S ); - fprintf( stderr, "Node %s : %p\n", S.latin1(), NN ); + Log( ( "Node %s : %p\n", S.latin1(), NN ) ); } else { // try to find instance NNI = NSResources->createNodeInstance( S ); - fprintf( stderr, "NodeInstance %s : %p\n", S.latin1(), NNI ); + Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); } if( NN == 0 && NNI == 0 ) { LeftOvers.append( Line ); } do { S = Line = TS.readLine(); if( NN || NNI ) { if( S.isEmpty() ) { // empty line break; } idx = S.find( '=' ); if( idx > 0 ) { Attr = S.left( idx ); Value = S.mid( idx+1, S.length() ); } else { Value=""; Attr = S; } Value.stripWhiteSpace(); @@ -130,49 +130,49 @@ void NetworkSettingsData::loadSettings( void ) { } } while( 1 ); if( NNI ) { // loading from file -> exists NNI->setNew( FALSE ); NSResources->addNodeInstance( NNI ); } } } } while( 0 ); } QString NetworkSettingsData::saveSettings( void ) { QString ErrS = ""; if( ! isModified() ) return ErrS; QString S; QFile F( CfgFile + ".bup" ); - printf( "Saving settings to %s\n", CfgFile.latin1() ); + Log( ( "Saving settings to %s\n", CfgFile.latin1() )); if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { ErrS = qApp->translate( "NetworkSettings", "<p>Could not save setup to \"%1\" !</p>" ). arg(CfgFile); // problem return ErrS; } QTextStream TS( &F ); // save leftovers for ( QStringList::Iterator it = LeftOvers.begin(); it != LeftOvers.end(); ++it ) { TS << (*it) << endl; } // save global configs for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); it.current(); ++it ) { TS << "[nodetype " << quote( QString( it.current()->NetNode->name() ) ) << "]" << endl; @@ -208,49 +208,49 @@ QString NetworkSettingsData::saveSettings( void ) { } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // setModified( 0 ); return ErrS; } QString NetworkSettingsData::generateSettings( bool ForceReq ) { bool ForceIt; QString S = ""; // include own force flag ForceIt = (Force) ? 1 : ForceReq; if( ! ForceIt && ! isModified() ) return S; // regenerate system files - fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() ); + Log( ( "Generating settings from %s\n", CfgFile.latin1() )); { Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; SystemFile * SF; AsDevice * CurDev; ANetNode * CurDevNN; bool needToRegenerate = ForceIt; // // check if we need to generate at least one of the system files // if( ! ForceIt ) { for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SF = sfit.current(); // check if there are nodes that are modified and require // data for this system file // for all connections for( QDictIterator<NodeCollection> ncit(M); @@ -260,89 +260,81 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { if( NC->isModified() ) { // does this connection 'touch' this system file ? for( QListIterator<ANetNodeInstance> cncit(*NC); cncit.current(); ++cncit ) { NNI = cncit.current(); if( ( NNI->nodeClass()->hasDataFor( SF->name() ) || NNI->hasDataFor( SF->name() ) ) && NNI->isModified() ) { needToRegenerate = 1; break; } } } if( needToRegenerate ) break; } if( needToRegenerate ) break; } } - // we cannot renumber with a FORCE request since - // we probably are NOT going to save the config - // e.g. when using --regen option - if( ! ForceReq && needToRegenerate ) { - NSResources->renumberConnections(); - setModified(1); - } - // // generate files proper to each netnodeinstance // { Name2Instance_t & NNIs = NSResources->netNodeInstances(); for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); NNIIt.current(); ++NNIIt ){ // for all nodes find those that are modified NNI = NNIIt.current(); if( ForceIt || NNI->isModified() ) { if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) { // problem generating S = qApp->translate( "NetworkSettings", "<p>Cannot generate files proper to \"%1\"</p>" ). arg(NNI->nodeClass()->name()) ; return S; } } } } // // generate all system files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SF = sfit.current(); - fprintf( stderr, "Generating %s\n", SF->name().latin1() ); + Log( ( "Generating %s\n", SF->name().latin1() )); SF->open(); do { // so we can break; // global presection for this system file if( SF->preSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in preSection for file \"%1\"</p>" ). arg( SF->name() ); return S; } // find all netnodes and figure out if // for that node there are instances for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { CurDevNN = nnit.current()->NetNode; // are there instances for this netnode ? NNI = 0; for( QDictIterator<ANetNodeInstance> nniit( @@ -384,71 +376,70 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { } while( 0 ); SF->close(); } } Force = 0; return S; } QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { // collect connections that can work on top of this interface NodeCollection * NC; QList<NodeCollection> PossibleConnections; Name2Connection_t & M = NSResources->connections(); // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->handlesInterface( Interface ) && // if different Intf. NC->state() != Disabled && // if not enabled NC->state() != IsUp // if already used ) { - fprintf( stderr, "Append %s for %s\n", NC->name().latin1(), Interface); + Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); PossibleConnections.append( NC ); } } return PossibleConnections; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ bool NetworkSettingsData::canStart( const char * Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); - fprintf( stderr, "Possiblilies %d\n", - PossibleConnections.count() ); + Log( ( "Possiblilies %d\n", PossibleConnections.count() )); switch( PossibleConnections.count() ) { case 0 : // no connections break; case 1 : // one connection NC = PossibleConnections.first(); break; default : // need to ask user ? return 1; } if( NC ) { switch( NC->state() ) { case Unchecked : case Unknown : case Unavailable : case Disabled : // this profile does not allow interface to be UP // -> try others break; case Off : // try to UP the device if( ! NC->setState( Activate ) ) { // cannot bring device Online -> try other alters break; diff --git a/noncore/settings/networksettings2/profile/profileGUI.ui b/noncore/settings/networksettings2/profile/profileGUI.ui index 365704b..5bf9a9c 100644 --- a/noncore/settings/networksettings2/profile/profileGUI.ui +++ b/noncore/settings/networksettings2/profile/profileGUI.ui @@ -1,137 +1,207 @@ <!DOCTYPE UI><UI> <class>ProfileGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>Profile_FRM</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>225</width> - <height>301</height> + <width>276</width> + <height>231</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Profile</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>0</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>TabWidget6</cstring> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>tab</cstring> </property> <attribute> <name>title</name> <string>Setup</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>1</number> </property> <property stdset="1"> <name>spacing</name> - <number>0</number> + <number>2</number> </property> <widget> - <class>QCheckBox</class> - <property stdset="1"> - <name>name</name> - <cstring>Automatic_CB</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Start automatically</string> - </property> - </widget> - <widget> - <class>QCheckBox</class> - <property stdset="1"> - <name>name</name> - <cstring>Confirm_CB</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>true</bool> - </property> - <property stdset="1"> - <name>text</name> - <string>Confirm before start</string> - </property> - <property> - <name>layoutMargin</name> - </property> - </widget> - <widget> - <class>QCheckBox</class> + <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Disabled_CB</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>true</bool> - </property> - <property stdset="1"> - <name>text</name> - <string>Disabled</string> - </property> - <property> - <name>layoutMargin</name> + <cstring>Layout8</cstring> </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" rowspan="2" colspan="1" > + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox1</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Start</string> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Automatic_CB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Automatically</string> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Confirm_CB</cstring> + </property> + <property stdset="1"> + <name>enabled</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>text</name> + <string>Ask</string> + </property> + <property> + <name>layoutMargin</name> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Disabled_CB</cstring> + </property> + <property stdset="1"> + <name>enabled</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>text</name> + <string>Disabled</string> + </property> + <property> + <name>layoutMargin</name> + </property> + </widget> + </vbox> + </widget> + <widget row="0" column="1" > + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>TriggersVPN_CB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Trigger VPN</string> + </property> + </widget> + <spacer row="1" column="1" > + <property> + <name>name</name> + <cstring>Spacer8</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</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> + </grid> </widget> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel3</cstring> </property> <property stdset="1"> <name>text</name> <string>Description</string> </property> </widget> <widget> <class>QMultiLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Description_LE</cstring> </property> </widget> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index 5b54aa4..cb52b2a 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp @@ -1,54 +1,58 @@ #include "profileedit.h" #include "profile_NNI.h" #include "profile_NN.h" AProfile::AProfile( ProfileNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.Automatic = 1; Data.Confirm = 0; Data.Description = ""; Data.Disabled = 0; + Data.TriggerVPN = 0; GUI = 0; RT = 0; } void AProfile::setSpecificAttribute( QString & Attr, QString & Value ) { if ( Attr == "automatic" ) { Data.Automatic = (Value=="yes"); } else if ( Attr == "preconfirm" ) { Data.Confirm = (Value=="yes"); } else if ( Attr == "disabled" ) { Data.Disabled = (Value=="yes"); + } else if ( Attr == "triggervpn" ) { + Data.TriggerVPN = (Value=="yes"); } else if ( Attr == "description" ) { Data.Description = Value; } } void AProfile::saveSpecificAttribute( QTextStream & TS ) { TS << "automatic=" << ((Data.Automatic) ? "yes" : "no") << endl; TS << "preconfirm=" << ((Data.Confirm) ? "yes" : "no") << endl; TS << "disabled=" << ((Data.Disabled) ? "yes" : "no") << endl; + TS << "triggervpn=" << ((Data.TriggerVPN) ? "yes" : "no") << endl; TS << "description=" << Data.Description << endl; } QWidget * AProfile::edit( QWidget * parent ) { GUI = new ProfileEdit( parent, this ); GUI->showData( Data ); return GUI; } QString AProfile::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AProfile::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool AProfile::generateDataForCommonFile( SystemFile & , long) { return 1; } diff --git a/noncore/settings/networksettings2/profile/profiledata.h b/noncore/settings/networksettings2/profile/profiledata.h index b4168e2..246d50c 100644 --- a/noncore/settings/networksettings2/profile/profiledata.h +++ b/noncore/settings/networksettings2/profile/profiledata.h @@ -1,15 +1,16 @@ #ifndef PROFILE_DATA_H #define PROFILE_DATA_H #include <qstring.h> typedef struct ProfileData { QString Description; // start up automatically bool Automatic; // if started up automatically, ask user for confirmation bool Confirm; // Do not bring this connection up bool Disabled; + bool TriggerVPN; } ProfileData_t; #endif diff --git a/noncore/settings/networksettings2/profile/profileedit.cpp b/noncore/settings/networksettings2/profile/profileedit.cpp index c9fb650..87e503e 100644 --- a/noncore/settings/networksettings2/profile/profileedit.cpp +++ b/noncore/settings/networksettings2/profile/profileedit.cpp @@ -37,58 +37,60 @@ ProfileEdit::ProfileEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : } QString S; InterfaceName_LBL->setText( II->Name ); if( II->HasMulticast ) { S += "Multicast"; } if( ! S.isEmpty() ) { S.prepend( " : " ); } InterfaceOptions_LBL->setText( S ); connect( &RefreshTimer, SIGNAL( timeout() ), this, SLOT( SLOT_Refresh() ) ); } } QString ProfileEdit::acceptable( void ) { return QString(); } void ProfileEdit::showData( ProfileData_t & Data ) { Description_LE->setText( Data.Description ); Automatic_CB->setChecked( Data.Automatic ); + TriggersVPN_CB->setChecked( Data.TriggerVPN ); Confirm_CB->setChecked( Data.Confirm ); Disabled_CB->setChecked( Data.Disabled ); } bool ProfileEdit::commit( ProfileData_t & Data ) { bool SM = 0; TXTM( Data.Description, Description_LE, SM ); CBM( Data.Automatic, Automatic_CB, SM ); + CBM( Data.TriggerVPN, TriggersVPN_CB, SM ); CBM( Data.Disabled, Disabled_CB, SM ); CBM( Data.Confirm, Confirm_CB, SM ); return SM; } void ProfileEdit::SLOT_Refresh( void ) { InterfaceInfo * II = Dev->assignedInterface(); NSResources->system().refreshStatistics( *II ); RcvBytes_LBL->setText( II->RcvBytes ); SndBytes_LBL->setText( II->SndBytes ); RcvErrors_LBL->setText( II->RcvErrors ); SndErrors_LBL->setText( II->SndErrors ); RcvDropped_LBL->setText( II->RcvDropped ); SndDropped_LBL->setText( II->SndDropped ); Collisions_LBL->setText( II->Collisions ); } void ProfileEdit::SLOT_AutoRefresh( bool ar ) { if( ar ) { RefreshTimer.start( 1000 ); SLOT_Refresh(); } else { RefreshTimer.stop(); diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp index 79bb93e..1a5b15b 100644 --- a/noncore/settings/networksettings2/profile/profilerun.cpp +++ b/noncore/settings/networksettings2/profile/profilerun.cpp @@ -1,65 +1,67 @@ #include <resources.h> #include "profilerun.h" void ProfileRun::detectState( NodeCollection * NC ) { if( Data->Disabled ) { + Log(( "%s disabled\n", NC->name().latin1() )); NC->setCurrentState( Disabled ); } else { + Log(( "%s not disabled\n", NC->name().latin1() )); // find next item in connection // convert to runtime and ask to detect the state netNode()->nextNode()->runtime()->detectState( NC ); } } -bool ProfileRun::setState( NodeCollection * NC, Action_t A, bool ) { +bool ProfileRun::setState( NodeCollection * NC, Action_t A, bool F ) { ANetNodeInstance * NNNI; NNNI = netNode()->nextNode(); switch ( A ) { case Enable : if( NC->currentState() == Disabled ) { Data->Disabled = 0; NC->setCurrentState( Off ); // at least // ... but request deeper NNNI->runtime()->detectState(NC); } return 1; case Disable : switch( NC->currentState() ) { case IsUp : case Available : // bring Deactivate (will bring down) if( ! NNNI->runtime()->setState(NC, Deactivate) ) return 0; default : break; } Data->Disabled = 1; NC->setCurrentState( Disabled ); return 1; default : break; } - return NNNI->runtime()->setState(NC, A); + return NNNI->runtime()->setState(NC, A, F ); } bool ProfileRun::canSetState( State_t Curr, Action_t A ) { RuntimeInfo * RI; switch ( A ) { case Enable : case Disable : // always possible return 1; default : break; } RI = netNode()->nextNode()->runtime(); return ( Curr != Disabled ) ? RI->canSetState(Curr, A) : 0; } bool ProfileRun::handlesInterface( const QString & S ) { // donno -> pass deeper return netNode()->nextNode()->runtime()->handlesInterface(S); } diff --git a/noncore/settings/networksettings2/profile/profilerun.h b/noncore/settings/networksettings2/profile/profilerun.h index c8ea063..400b56c 100644 --- a/noncore/settings/networksettings2/profile/profilerun.h +++ b/noncore/settings/networksettings2/profile/profilerun.h @@ -2,30 +2,34 @@ #define PROFILERUN_H #include <asfullsetup.h> #include "profiledata.h" class ProfileRun : public AsFullSetup { public : ProfileRun( ANetNodeInstance * NNI, ProfileData & D ) : AsFullSetup( NNI ) { Data = &D; } void detectState( NodeCollection * NC ); bool setState( NodeCollection * NC, Action_t A, bool ); bool canSetState( State_t Curr, Action_t A ); bool handlesInterface( const QString & I ); virtual const QString & description( void ) { return Data->Description; } virtual AsFullSetup * asFullSetup( void ) { return (AsFullSetup *)this; } + + virtual bool triggersVPN( void ) + { return Data->TriggerVPN; } + private : ProfileData * Data; }; #endif diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index beacd7b..b8ac8a8 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,121 +1,123 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "usbrun.h" void USBRun::detectState( NodeCollection * NC ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); + Log(("Detecting for %s\n", NC->name().latin1() )); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); + Log(("%s exists\n", S.latin1() )); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { Run->assignNode( netNode() ); assignInterface( Run ); NC->setCurrentState( IsUp ); return; } } } } - fprintf( stderr, "Assigned %p\n", assignedInterface() ); + Log(("Assigned %p\n", assignedInterface() )); if( ( Run = assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment NC->setCurrentState( Available ); return; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); - fprintf( stderr, "%s %d %d=%d %d\n", + Log(("%s %d %d=%d %d\n", Run->Name.latin1(), handlesInterface( Run->Name ), Run->CardType, ARPHRD_ETHER, - ! Run->IsUp ); + ! Run->IsUp )); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER && ! Run->IsUp ) { - fprintf( stderr, "Released(OFF)\n" ); + Log(("Released(OFF)\n" )); // proper type, and Not UP -> free NC->setCurrentState( Off ); return; } } // no free found - fprintf( stderr, "UNA\n" ); + Log(("UNA\n" )); NC->setCurrentState( Unavailable ); } bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) { // we only handle activate and deactivate switch( A ) { case Activate : { if( NC->currentState() != Off ) { return 0; } InterfaceInfo * N = getInterface(); if( ! N ) { // no interface available NC->setCurrentState( Unavailable ); return 0; } // because we were OFF the interface // we get back is NOT assigned N->assignNode( netNode() ); assignInterface( N ); - fprintf( stderr, "Assing %p\n", N ); + Log(("Assing %p\n", N )); NC->setCurrentState( Available ); return 1; } case Deactivate : if( NC->currentState() == IsUp ) { // bring down first if( ! connection()->setState( Down ) ) // could not ... return 0; } else if( NC->currentState() != Available ) { return 1; } assignedInterface()->assignNode( 0 ); // release assignInterface( 0 ); NC->setCurrentState( Off ); return 1; default : // FT break; } return 0; } bool USBRun::canSetState( State_t Curr, Action_t A ) { |