14 files changed, 174 insertions, 54 deletions
diff --git a/noncore/settings/networksettings2/activateprofileGUI.ui b/noncore/settings/networksettings2/activateprofileGUI.ui index 12ab051..861ce96 100644 --- a/noncore/settings/networksettings2/activateprofileGUI.ui +++ b/noncore/settings/networksettings2/activateprofileGUI.ui @@ -2,25 +2,25 @@ <class>ActivateProfileGUI</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>ActivateProfileGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>231</width> + <width>219</width> <height>121</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Activate Network</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> @@ -31,55 +31,80 @@ <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> + <property> + <name>layoutSpacing</name> + </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>0</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1</cstring> </property> <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> <name>text</name> <string>Select profile to activate for </string> </property> </widget> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>DeviceName_LBL</cstring> </property> <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> <name>text</name> <string>TextLabel2</string> </property> </widget> </hbox> </widget> <widget> <class>QListBox</class> <property stdset="1"> <name>name</name> <cstring>Profiles_LB</cstring> </property> </widget> </vbox> </widget> +<connections> + <connection> + <sender>Profiles_LB</sender> + <signal>doubleClicked(QListBoxItem*)</signal> + <receiver>ActivateProfileGUI</receiver> + <slot>accept()</slot> + </connection> +</connections> </UI> diff --git a/noncore/settings/networksettings2/activatevpn.cpp b/noncore/settings/networksettings2/activatevpn.cpp index b75e623..768a031 100644 --- a/noncore/settings/networksettings2/activatevpn.cpp +++ b/noncore/settings/networksettings2/activatevpn.cpp @@ -9,35 +9,36 @@ public : MyCheckListItem( NodeCollection * N, QListView * V ); NodeCollection * NC; }; MyCheckListItem::MyCheckListItem( NodeCollection * N, QListView * V ): QCheckListItem( V, N->name() ) { NC = N; } -ActivateVPN::ActivateVPN( void ) : +ActivateVPN::ActivateVPN( const QString & I ) : ActivateVPNGUI( 0, 0, TRUE ), NSD() { QCheckListItem * CI; VPN_LV->clear(); VPN_LV->header()->hide(); + // find all connections that want to be triggered by this interface for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { - if( it.current()->triggeredBy( "vpn" ) ) { + if( it.current()->triggeredBy( I ) ) { CI = new MyCheckListItem( it.current(), VPN_LV ); } } } ActivateVPN::~ActivateVPN( void ) { } void ActivateVPN::SLOT_ChangedVPNSetting( QListViewItem * I ) { MyCheckListItem * MI = (MyCheckListItem *)I; diff --git a/noncore/settings/networksettings2/activatevpn.h b/noncore/settings/networksettings2/activatevpn.h index 5794757..49a940b 100644 --- a/noncore/settings/networksettings2/activatevpn.h +++ b/noncore/settings/networksettings2/activatevpn.h @@ -1,20 +1,20 @@ #include "activatevpnGUI.h" #include "nsdata.h" class ActivateVPN : public ActivateVPNGUI { Q_OBJECT public : - ActivateVPN( void ); + ActivateVPN( const QString & Interface ); ~ActivateVPN( void ); public slots : void SLOT_ChangedVPNSetting( QListViewItem * ); private : NetworkSettingsData NSD; }; diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 973b4b7..2243826 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -14,28 +14,30 @@ using namespace Opie::Core; OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) #else // just standard GUI #define ACT_GUI 0 // used by interfaces to request for allow of up/down #define ACT_REQUEST 1 // regenerate config files #define ACT_REGEN 2 // used by interfaces to request user prompt #define ACT_PROMPT 3 -// used by interfaces to trigger VPN -#define ACT_VPN 4 +// used by interfaces to trigger VPN prompting +#define ACT_TRIGGERVPN 4 // activate opietooth #define ACT_OT 5 +// prompt for VPN networks +#define ACT_PROMPTVPN 6 // include Opietooth GUI #include <opietooth2/Opietooth.h> using namespace Opietooth2; #include <qpushbutton.h> #include <qlayout.h> #include <qframe.h> #include <qlabel.h> int main( int argc, char * argv[] ) { int rv = 0; @@ -47,25 +49,29 @@ int main( int argc, char * argv[] ) { for ( int i = 1; i < argc; i ++ ) { int rmv; rmv = 0; if( strcmp( argv[i], "--regen" ) == 0 ) { Action = ACT_REGEN; GuiType = QApplication::Tty; rmv = 1; } else if( strcmp( argv[i], "--prompt" ) == 0 ) { Action = ACT_PROMPT; rmv = 1; } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { - Action = ACT_VPN; + GuiType = QApplication::Tty; + Action = ACT_TRIGGERVPN; + rmv = 1; + } else if( strcmp( argv[i], "--promptvpn" ) == 0 ) { + Action = ACT_PROMPTVPN; rmv = 1; } else if( strcmp( argv[i], "--opietooth" ) == 0 ) { Action = ACT_OT; rmv = 1; } if( rmv ) { memmove( argv+i, argv+i+rmv, sizeof( char * ) * (argc-i-rmv) ); i --; argc -= rmv; } } @@ -86,57 +92,67 @@ int main( int argc, char * argv[] ) { // TheApp anymore ... TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); } else { TheApp = new QPEApplication( argc, argv, GuiType ); } // init qt with app widget switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; if( NS.canStart( argv[1] ) ) { + QStringList SL; + SL << QPEApplication::qpeDir() + "bin/networksettings2" + << "--prompt" + << argv[1]; + // exec synchronous -> blocks + NSResources->system().execAsUser( SL, 1 ); + } + } + break; + case ACT_TRIGGERVPN : + { NetworkSettingsData NS; + if( NS.couldBeTriggered( argv[1] ) ) { + // there are VPNS that can be triggered QStringList S; - S << QPEApplication::qpeDir() + "/bin/networksettings2"; - S << "networksettings2"; - S << "--prompt"; + S << QPEApplication::qpeDir() + "bin/networksettings2"; + S << "--promptvpn"; S << argv[1]; NSResources->system().execAsUser( S ); - Log(("FAILED %s-cNN-allowed\n", argv[1] )); - // if we come here , failed - printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_REGEN : { NetworkSettingsData NS; QString S= NS.generateSettings(); // regen returns 0 if OK rv = ( S.isEmpty() ) ? 0 : 1; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); if( AP.exec() == QDialog::Accepted ) { - Log(("%s-c%ld-allowed\n", - argv[1], AP.selectedProfile() )); - printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); + Log(("allow profile %ld for %s\n", + AP.selectedProfile(), argv[1] )); + printf( "A%ld%s\n", AP.selectedProfile(), argv[1] ); } else { - Log(("%s-c%NN-disallowed\n", argv[1] )); - printf( "%s-cNN-disallowed", argv[1] ); + Log(("disallow %s\n", argv[1] )); + printf( "D-%s\n", argv[1] ); } } break; - case ACT_VPN : - { ActivateVPN AVPN; + case ACT_PROMPTVPN : + { ActivateVPN AVPN( argv[1] ); + Log(("Trigger vpns on interface %s\n", argv[1] )); AVPN.exec(); } break; case ACT_GUI : case ACT_OT : { QWidget * W; if( Action == ACT_OT ) { W = new OTMain( 0 ); } else { W = new NetworkSettings(0); } diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 78e6545..34dac54 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp @@ -107,50 +107,51 @@ short ANetwork::generateFile( SystemFile &SF, long DevNr ) { short rvl, rvd ; QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); rvl = 1; if( SF.name() == "interfaces" ) { Log(("Generate Network for %s\n", SF.name().latin1() )); // we can safely call from here since device item is deeper if( Data.UseDHCP ) { SF << "iface " - << NIC - << "-c" + << "A" << connection()->number() - << "-allowed inet dhcp" + << NIC + << " inet dhcp" << endl; SF << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << endl; if( Data.SendHostname ) { SF << " hostname " << Data.Hostname << endl; } SF << " down rm -f /tmp/profile-" << connection()->number() << ".up" << endl; } else { SF << "iface " - << NIC << "-c" + << "A" << connection()->number() - << "-allowed inet static" + << NIC + << " inet static" << endl; SF << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << endl; SF << " down rm -f /tmp/profile-" << connection()->number() << ".up" << endl; SF << " address " diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 2c93d9d..74467ad 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -1,21 +1,21 @@ #include <system.h> #include <netnode.h> #include <resources.h> #include "networkrun.h" State_t NetworkRun::detectState( void ) { InterfaceInfo * II = nodeCollection()->assignedInterface(); - Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 )); + Log(( "Interface %p %p : %d\n", II, nodeCollection(), (II) ? II->IsUp : 0 )); if( II && II->IsUp ) { // device has assigned interface return IsUp; } // had no interface or interface is no longer up -> release nodeCollection()->assignInterface( 0 ); return Unknown; } QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { @@ -29,22 +29,23 @@ QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { QStringList SL; if( A == Up ) { // we can bring UP if lower level is available SL << "ifup"; } else if( A == Down ) { SL << "ifdown"; } else { return QString(); } - SL << QString().sprintf( "%s=%s-c%d-allowed", - II->Name.latin1(), II->Name.latin1(), - nodeCollection()->number() ); + SL << QString().sprintf( "%s=A%ld%s", + II->Name.latin1(), + nodeCollection()->number(), + II->Name.latin1() ); if( ! NSResources->system().runAsRoot( SL ) ) { return QString("Cannot call %1").arg(SL.join(" ")); } return QString(); } diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 3479abb..b81dcaa 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -238,24 +238,26 @@ QString TheNSResources::tr( const char * 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, bool Dangling ) { ANetNodeInstance * NNI; + Log(( "Add Connection %s, Dangling %d\n", + NC->name().latin1(), Dangling )); if( Dangling ) { DanglingConnectionsMap.insert( NC->name(), NC ); } else { 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 ) { diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index b27cda1..51c4250 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -101,25 +101,25 @@ public : { return AllNodes[S]; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); void addConnection( NodeCollection * NC, bool Dangling ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); NodeCollection * getConnection( int nr ); Name2Connection_t & connections( void ) { return ConnectionsMap; } Name2Connection_t & danglingConnections( void ) - { return ConnectionsMap; } + { return DanglingConnectionsMap; } inline bool userKnown( void ) { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); void findAvailableNetNodes( void ); diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index f027d35..a290f08 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -54,25 +54,25 @@ System::~System( void ) { QDict<InterfaceInfo> & System::interfaces( void ) { if( ProbedInterfaces.count() == 0 ) { probeInterfaces(); } return ProbedInterfaces; } int System::runAsRoot( QStringList & S, MyProcess * Prc ) { char * usr = getenv("USER"); if( S.count() == 0 ) { - // loophole to start shell + // close loophole to start shell return 8888; } if( usr == 0 || strcmp( usr, "root" ) ) { // unknown or non-root user -> use SUDO S.prepend( "sudo" ); } if( getenv( "NS2TESTMODE" ) ) { odebug << "TESTMODE !!! execute " << S.join( " ") << oendl; } else { @@ -110,30 +110,31 @@ int System::runAsRoot( QStringList & S, MyProcess * Prc ) { if( ! Prc ) delete P; // error starting app return 0; } odebug << "Started " << S << oendl; } // all is fine return 1; } -int System::execAsUser( QStringList & SL ) { +int System::execAsUser( QStringList & SL, bool Synchronous ) { MyProcess * P = new MyProcess(); CurrentQPEUser CU = NSResources->currentUser(); char * usr = getenv("USER"); - if( strcmp( usr, "root" ) == 0 ) { + if( usr == 0 || + strcmp( usr, "root" ) == 0 ) { // find user running qpe if( CU.UserName.isEmpty() ) { // if we come here, the exec was not successfull Log(("User not known \n" )); return 0; } } // now we are ready to exec the requested command setuid( CU.Uid ); setgid( CU.Gid ); @@ -144,34 +145,39 @@ int System::execAsUser( QStringList & SL ) { SL = QStringList::split( "=", X ); P->process().setEnvironment( SL[0], SL[1] ); } P->process() << SL; emit processEvent( tr("Command : ") + SL.join( " " ) ); Log(("Executing as user %s : %s\n", CU.UserName.latin1(), SL.join( " " ).latin1() )); - int rv = ( P->process().start( OProcess::DontCare, - OProcess::NoCommunication ) ); + P->setEchoMode( Synchronous ); + + bool rv = P->process().start( + (Synchronous) ? OProcess::Block : + OProcess::DontCare, + (Synchronous) ? OProcess::AllOutput : + OProcess::NoCommunication ); delete P; - if( rv ) { + if( ! rv ) { // if we come here, the exec was not successfull Log(("Could not exec : %d\n", errno )); } - return ! rv; + return rv; } void System::SLOT_ProcessExited( MyProcess * P ) { QString R; for( QValueListConstIterator<QCString> it = P->process().args().begin(); it != P->process().args().end(); ++it ) { R += (*it); R += " "; } @@ -532,45 +538,55 @@ MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() { SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) ); connect( P, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) ); } MyProcess::~MyProcess() { delete P; } void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) { + if( EchoMode ) { + write( 1, Buf, len ); + return; + } + char * LB = (char *)alloca( len + 1 ); memcpy( LB, Buf, len ); LB[len] = '\0'; // now input is zero terminated StdoutBuffer += LB; odebug << "Received " << len << " bytes on stdout" << oendl; // see if we have some lines (allow empty lines) QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE ); for( unsigned int i = 0; i < SL.count()-1; i ++ ) { Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) ); emit stdoutLine( SL[i] ); } // last line is rest StdoutBuffer = SL[ SL.count()-1 ]; } void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) { + if( EchoMode ) { + write( 2, Buf, len ); + return; + } + char * LB = (char *)alloca( len + 1 ); memcpy( LB, Buf, len ); LB[len] = '\0'; // now input is zero terminated StderrBuffer += LB; odebug << "Received " << len << " bytes on stderr" << oendl; // see if we have some lines (allow empty lines) QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE ); for( unsigned int i = 0; i < SL.count()-1; i ++ ) { diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index f7a7274..ebee0d5 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h @@ -20,41 +20,47 @@ class QFile; class MyProcess : public QObject { Q_OBJECT public : MyProcess(); ~MyProcess(); inline OProcess & process() { return *P; } + inline void setEchoMode( bool M ) { + EchoMode = M; + } + public slots : void SLOT_Stdout( Opie::Core::OProcess * P, char *, int ); void SLOT_Stderr( Opie::Core::OProcess * P, char *, int ); void SLOT_ProcessExited( Opie::Core::OProcess * P); signals : void stdoutLine( const QString & ); void stderrLine( const QString & ); void processExited( MyProcess * ); private : QString StdoutBuffer; QString StderrBuffer; OProcess * P; + // output all output to my output + bool EchoMode; }; class InterfaceInfo { public : InterfaceInfo() : Name(), MACAddress(), BCastAddress(), Netmask(), DstAddress() { @@ -95,25 +101,25 @@ public : System( void ); ~System( void ); QDict<InterfaceInfo> & interfaces( void ); InterfaceInfo * interface( const QString& N ) { return interfaces()[N]; } // exec command as root int runAsRoot( QStringList & S, MyProcess * Prc = 0 ); // exec command as user - int execAsUser( QStringList & Cmd ); + int execAsUser( QStringList & Cmd, bool Synchronous = 0 ); // refresh stats for this interface void refreshStatistics( InterfaceInfo & ); // reloads interfaces void probeInterfaces( void ); InterfaceInfo * findInterface( const QString & DevName ); private slots : void SLOT_ProcessExited( MyProcess * ); diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index 1b1988e..0314765 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -127,25 +127,24 @@ bool SystemFile::close( void ) { if( Prefix == "stderr" ) { return 1; } QString OldP = Prefix + Path + "bup"; F->close(); delete F; F = 0; if( ! InAppend ) { - odebug << "Rename " << OldP << " to " << Path << oendl; return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); } return 1; } bool SystemFile::preSection( void ) { if( hasPreSection ) { QFile Fl( TemplDir + Name + "/presection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index d76353a..39031ed 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -52,24 +52,26 @@ NetworkSettingsData::NetworkSettingsData( void ) { if( F->open( IO_ReadOnly ) ) { NodeCollection * NC; interfacename = TS.readLine(); F->close(); Log(( "Assign interface %s to Profile nr %d\n", interfacename.latin1(), profilenr )); NC = NSResources->getConnection( profilenr ); if( NC ) { NC->assignInterface( NSResources->system().findInterface( interfacename ) ); + Log(( "Assign interface %p\n", + NC->assignedInterface() )); } else { Log(( "Profile nr %d no longer defined\n", profilenr )); } } } } } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; @@ -634,110 +636,152 @@ QString NetworkSettingsData::generateSettings( void ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Closure\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } // end of file SF->close(); } return S; } -QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { +QList<NodeCollection> NetworkSettingsData::collectPossible( + const QString & 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() != Disabled && // if enabled NC->state() != IsUp // if already used ) { - Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); + Log( ( "Append %s for %s\n", + NC->name().latin1(), Interface.latin1() )); 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 ) { +bool NetworkSettingsData::canStart( const QString & Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); Log( ( "for %s : Possiblilies %d\n", - Interface, PossibleConnections.count() )); + Interface.latin1(), 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 { QString S= NC->setState( Activate ); if( ! S.isEmpty() ) { // could not bring device Online -> try other alters - Log(( "%s-c%d-disallowed : %s\n", - Interface, NC->number(), S.latin1() )); + Log(( "disallow %ld for %s : %s\n", + NC->number(), Interface.latin1(), S.latin1() )); break; } // interface assigned } // FT case Available : case IsUp : // also called for 'ifdown' // device is ready -> done - Log(( "%s-c%d-allowed\n", Interface, NC->number() )); - printf( "%s-c%d-allowed\n", Interface, NC->number() ); + Log(( "allow %ld for %s\n", NC->number(), Interface.latin1())); + printf( "A%ld%s\n", NC->number(), Interface.latin1() ); return 0; } } // if we come here no alternatives are possible - Log(( "%s-cnn-disallowed\n", Interface )); - printf( "%s-cnn-disallowed\n", Interface ); + Log(( "disallow %s\n", Interface.latin1())); + printf( "D-%s\n", Interface.latin1() ); return 0; } bool NetworkSettingsData::isModified( void ) { if( ForceModified ) return 1; for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { if( it.current()->isModified() ) { return 1; } } return 0; } + +bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { + // load situation + QList<NodeCollection> PossibleTriggered; + + PossibleTriggered = collectTriggered( Interface ); + + Log( ( "for %s : Possiblilies %d\n", + Interface.latin1(), PossibleTriggered.count() )); + + return ( PossibleTriggered.count() ) ? 1 : 0; +} + +QList<NodeCollection> NetworkSettingsData::collectTriggered( + const QString & Interface ) { + + // collect connections that could be triggered by this interface + NodeCollection * NC; + QList<NodeCollection> PossibleTriggered; + + // for all connections + Name2Connection_t & M = NSResources->connections(); + + for( QDictIterator<NodeCollection> it(M); + it.current(); + ++it ) { + NC = it.current(); + // check if this profile handles the requested interface + if( NC->triggeredBy( Interface ) && // if different Intf. + NC->state() != Disabled && // if enabled + NC->state() != IsUp // if already used + ) { + Log( ( "Append %s for %s\n", + NC->name().latin1(), Interface.latin1() )); + PossibleTriggered.append( NC ); + } + } + return PossibleTriggered; +} + diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index a0ae7d1..5791c1e 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h @@ -10,25 +10,29 @@ public : NetworkSettingsData( void ); ~NetworkSettingsData( void ); void loadSettings( void ); QString saveSettings( void ); QString generateSettings( void ); bool isModified( void ); inline void setModified( bool M ) { ForceModified = M; } - QList<NodeCollection> collectPossible( const char * Interface ); + QList<NodeCollection> collectPossible( const QString & Interface ); // return TRUE if we need gui to decide - bool canStart( const char * Interface ); + bool canStart( const QString & Interface ); + // return TRUE if there are vpns that could be triggered + // by this interface + bool couldBeTriggered( const QString & Interface ); private : + QList<NodeCollection> collectTriggered( const QString &Interface ); bool ForceModified; // collect strings in config file nobody wants QStringList LeftOvers; }; #endif diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index a1e1254..fc2d809 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp @@ -1,12 +1,13 @@ +#include <qpe/qpeapplication.h> #include <opie2/odebug.h> #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; @@ -53,24 +54,28 @@ void AProfile::commit( void ) { short AProfile::generateFileEmbedded( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; if( SF.name() == "interfaces" ) { Log(("Generate Profile for %s\n", SF.name().latin1() )); if( Data.TriggerVPN ) { // this profile triggers VPN -> insert trigger - SF << " up networksettings2 --triggervpn" + SF << " up " + << QPEApplication::qpeDir() + << "bin/networksettings2 --triggervpn " + << runtime()->device()->netNode()->nodeClass()->genNic( DevNr ) + << " || true" << endl; rvl = 0; } } rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } |