summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/activateprofile.cpp2
-rw-r--r--noncore/settings/networksettings2/activateprofileGUI.ui4
-rw-r--r--noncore/settings/networksettings2/main.cpp15
-rw-r--r--noncore/settings/networksettings2/network/network_NNI.cpp47
-rw-r--r--noncore/settings/networksettings2/network/networkrun.cpp4
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp137
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h18
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp43
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.h7
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp26
-rw-r--r--noncore/settings/networksettings2/nsdata.h3
11 files changed, 270 insertions, 36 deletions
diff --git a/noncore/settings/networksettings2/activateprofile.cpp b/noncore/settings/networksettings2/activateprofile.cpp
index ba726bb..e4064e3 100644
--- a/noncore/settings/networksettings2/activateprofile.cpp
+++ b/noncore/settings/networksettings2/activateprofile.cpp
@@ -1,29 +1,31 @@
1#include <qlistbox.h> 1#include <qlistbox.h>
2#include <qlabel.h>
2#include "activateprofile.h" 3#include "activateprofile.h"
3 4
4ActivateProfile::ActivateProfile( const char * Interface ) : 5ActivateProfile::ActivateProfile( const char * Interface ) :
5 ActivateProfileGUI( 0, 0, TRUE ), NSD() { 6 ActivateProfileGUI( 0, 0, TRUE ), NSD() {
6 7
7 Possible = NSD.collectPossible( Interface ); 8 Possible = NSD.collectPossible( Interface );
8 9
10 DeviceName_LBL->setText( Interface );
9 Profiles_LB->clear(); 11 Profiles_LB->clear();
10 for( NodeCollection * NC = Possible.first(); 12 for( NodeCollection * NC = Possible.first();
11 NC; 13 NC;
12 NC = Possible.next() ) { 14 NC = Possible.next() ) {
13 Profiles_LB->insertItem( NC->devicePixmap(), 15 Profiles_LB->insertItem( NC->devicePixmap(),
14 NC->name() ); 16 NC->name() );
15 } 17 }
16} 18}
17 19
18ActivateProfile::~ActivateProfile( void ) { 20ActivateProfile::~ActivateProfile( void ) {
19} 21}
20 22
21long ActivateProfile::selectedProfile( void ) { 23long ActivateProfile::selectedProfile( void ) {
22 for( unsigned int i = 0 ; i < Profiles_LB->count(); i ++ ) { 24 for( unsigned int i = 0 ; i < Profiles_LB->count(); i ++ ) {
23 if( Profiles_LB->isSelected(i) ) { 25 if( Profiles_LB->isSelected(i) ) {
24 return Possible.at(i)->number(); 26 return Possible.at(i)->number();
25 27
26 } 28 }
27 } 29 }
28 return -1; 30 return -1;
29} 31}
diff --git a/noncore/settings/networksettings2/activateprofileGUI.ui b/noncore/settings/networksettings2/activateprofileGUI.ui
index 296e044..12ab051 100644
--- a/noncore/settings/networksettings2/activateprofileGUI.ui
+++ b/noncore/settings/networksettings2/activateprofileGUI.ui
@@ -1,85 +1,85 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>ActivateProfileGUI</class> 2<class>ActivateProfileGUI</class>
3<widget> 3<widget>
4 <class>QDialog</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>ActivateProfileGUI</cstring> 7 <cstring>ActivateProfileGUI</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>231</width> 14 <width>231</width>
15 <height>121</height> 15 <height>121</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Activate Profile</string> 20 <string>Activate Network</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <vbox> 28 <vbox>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>2</number> 31 <number>2</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QLayoutWidget</class> 38 <class>QLayoutWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>Layout2</cstring> 41 <cstring>Layout2</cstring>
42 </property> 42 </property>
43 <hbox> 43 <hbox>
44 <property stdset="1"> 44 <property stdset="1">
45 <name>margin</name> 45 <name>margin</name>
46 <number>0</number> 46 <number>0</number>
47 </property> 47 </property>
48 <property stdset="1"> 48 <property stdset="1">
49 <name>spacing</name> 49 <name>spacing</name>
50 <number>6</number> 50 <number>6</number>
51 </property> 51 </property>
52 <widget> 52 <widget>
53 <class>QLabel</class> 53 <class>QLabel</class>
54 <property stdset="1"> 54 <property stdset="1">
55 <name>name</name> 55 <name>name</name>
56 <cstring>TextLabel1</cstring> 56 <cstring>TextLabel1</cstring>
57 </property> 57 </property>
58 <property stdset="1"> 58 <property stdset="1">
59 <name>text</name> 59 <name>text</name>
60 <string>Select profile for device :</string> 60 <string>Select profile to activate for </string>
61 </property> 61 </property>
62 </widget> 62 </widget>
63 <widget> 63 <widget>
64 <class>QLabel</class> 64 <class>QLabel</class>
65 <property stdset="1"> 65 <property stdset="1">
66 <name>name</name> 66 <name>name</name>
67 <cstring>DeviceName_LBL</cstring> 67 <cstring>DeviceName_LBL</cstring>
68 </property> 68 </property>
69 <property stdset="1"> 69 <property stdset="1">
70 <name>text</name> 70 <name>text</name>
71 <string>TextLabel2</string> 71 <string>TextLabel2</string>
72 </property> 72 </property>
73 </widget> 73 </widget>
74 </hbox> 74 </hbox>
75 </widget> 75 </widget>
76 <widget> 76 <widget>
77 <class>QListBox</class> 77 <class>QListBox</class>
78 <property stdset="1"> 78 <property stdset="1">
79 <name>name</name> 79 <name>name</name>
80 <cstring>Profiles_LB</cstring> 80 <cstring>Profiles_LB</cstring>
81 </property> 81 </property>
82 </widget> 82 </widget>
83 </vbox> 83 </vbox>
84</widget> 84</widget>
85</UI> 85</UI>
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp
index 7ec26a7..e2c00f6 100644
--- a/noncore/settings/networksettings2/main.cpp
+++ b/noncore/settings/networksettings2/main.cpp
@@ -1,119 +1,132 @@
1#include "nsdata.h" 1#include "nsdata.h"
2#include "activateprofile.h" 2#include "activateprofile.h"
3#include "networksettings.h" 3#include "networksettings.h"
4
4#include <qpe/qpeapplication.h> 5#include <qpe/qpeapplication.h>
5 6
6#include <opie/oapplicationfactory.h> 7#include <opie/oapplicationfactory.h>
7 8
8#ifdef GONE 9#ifdef GONE
9 10
10OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) 11OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> )
11 12
12#else 13#else
13 14
14// just standard GUI 15// just standard GUI
15#define ACT_GUI 0 16#define ACT_GUI 0
16// used by interfaces to request for allow of up/down 17// used by interfaces to request for allow of up/down
17#define ACT_REQUEST 1 18#define ACT_REQUEST 1
18// regenerate config files 19// regenerate config files
19#define ACT_REGEN 2 20#define ACT_REGEN 2
20// used by interfaces to request user prompt 21// used by interfaces to request user prompt
21#define ACT_PROMPT 3 22#define ACT_PROMPT 3
22 23
23int main( int argc, char * argv[] ) { 24int main( int argc, char * argv[] ) {
24 int rv = 0; 25 int rv = 0;
25 int Action = ACT_GUI; 26 int Action = ACT_GUI;
26 // could be overruled by -qws 27 // could be overruled by -qws
27 QApplication::Type GuiType = QApplication::GuiClient; 28 QApplication::Type GuiType = QApplication::GuiClient;
28 29
29#ifdef _WS_QWS_ 30#ifdef _WS_QWS_
30 QPEApplication * TheApp; 31 QPEApplication * TheApp;
31#else 32#else
32 QApplication * TheApp; 33 QApplication * TheApp;
33#endif 34#endif
34 35
35 for ( int i = 1; i < argc; i ++ ) { 36 for ( int i = 1; i < argc; i ++ ) {
36 int rmv; 37 int rmv;
37 rmv = 0; 38 rmv = 0;
38 if( strcmp( argv[i], "--regen" ) == 0 ) { 39 if( strcmp( argv[i], "--regen" ) == 0 ) {
39 Action = ACT_REGEN; 40 Action = ACT_REGEN;
40 GuiType = QApplication::Tty; 41 GuiType = QApplication::Tty;
41 rmv = 1; 42 rmv = 1;
42 } else if( strcmp( argv[i], "--prompt" ) == 0 ) { 43 } else if( strcmp( argv[i], "--prompt" ) == 0 ) {
43 Action = ACT_PROMPT; 44 Action = ACT_PROMPT;
44 rmv = 1; 45 rmv = 1;
45 } 46 }
46 if( rmv ) { 47 if( rmv ) {
47 memmove( argv+i, argv+i+rmv, 48 memmove( argv+i, argv+i+rmv,
48 sizeof( char * ) * (argc-i-rmv) ); 49 sizeof( char * ) * (argc-i-rmv) );
49 i --; 50 i --;
50 argc -= rmv; 51 argc -= rmv;
51 } 52 }
52 } 53 }
53 54
54 if( strstr( argv[0], "-request" ) ) { 55 if( strstr( argv[0], "-request" ) ) {
55 // called from system to request something 56 // called from system to request something
56 GuiType = QApplication::Tty; 57 GuiType = QApplication::Tty;
57 Action = ACT_REQUEST; 58 Action = ACT_REQUEST;
58 } 59 }
59 60
60 // Start Qt 61 // Start Qt
61#ifdef _WS_QWS_ 62#ifdef _WS_QWS_
62 // because QPEApplication does not handle GuiType well 63 // because QPEApplication does not handle GuiType well
63 if( GuiType == QApplication::Tty ) { 64 if( GuiType == QApplication::Tty ) {
64 // this cast is NOT correct but we do not use 65 // this cast is NOT correct but we do not use
65 // TheApp anymore ... 66 // TheApp anymore ...
66 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); 67 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
67 } else { 68 } else {
68 TheApp = new QPEApplication( argc, argv, GuiType ); 69 TheApp = new QPEApplication( argc, argv, GuiType );
69 } 70 }
70#else 71#else
71 TheApp = new QApplication( argc, argv, GuiType ); 72 TheApp = new QApplication( argc, argv, GuiType );
72#endif 73#endif
73 74
74 // init qt with app widget 75 // init qt with app widget
75 76
76 switch( Action ) { 77 switch( Action ) {
77 case ACT_REQUEST : 78 case ACT_REQUEST :
78 { NetworkSettingsData NS; 79 { NetworkSettingsData NS;
79 NS.canStart( argv[1] ); 80 if( NS.canStart( argv[1] ) ) {
81 QString S;
82 S.sprintf( QPEApplication::qpeDir()+
83 "/bin/networksettings2" );
84 char * MyArgv[4];
85 MyArgv[0] = "networksettings2";
86 MyArgv[1] = "--prompt";
87 MyArgv[2] = argv[1];
88 MyArgv[3] = NULL;
89 NSResources->system().execAsUser( S, MyArgv );
90 // if we come here , failed
91 printf( "%s-cNN-disallowed", argv[1] );
92 }
80 } 93 }
81 break; 94 break;
82 case ACT_REGEN : 95 case ACT_REGEN :
83 { NetworkSettingsData NS; 96 { NetworkSettingsData NS;
84 // regen returns 0 if OK 97 // regen returns 0 if OK
85 rv = (NS.regenerate()) ? 1 : 0; 98 rv = (NS.regenerate()) ? 1 : 0;
86 } 99 }
87 break; 100 break;
88 case ACT_PROMPT : 101 case ACT_PROMPT :
89 { ActivateProfile AP(argv[1]); 102 { ActivateProfile AP(argv[1]);
90 if( AP.exec() == QDialog::Accepted ) { 103 if( AP.exec() == QDialog::Accepted ) {
91 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); 104 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() );
92 } else { 105 } else {
93 printf( "%s-cNN-disallowed", argv[1] ); 106 printf( "%s-cNN-disallowed", argv[1] );
94 } 107 }
95 } 108 }
96 break; 109 break;
97 case ACT_GUI : 110 case ACT_GUI :
98 { QWidget * W = new NetworkSettings(0); 111 { QWidget * W = new NetworkSettings(0);
99 TheApp->setMainWidget( W ); 112 TheApp->setMainWidget( W );
100 W->show(); 113 W->show();
101#ifdef _WS_QWS_ 114#ifdef _WS_QWS_
102 W->showMaximized(); 115 W->showMaximized();
103#else 116#else
104 W->resize( W->sizeHint() ); 117 W->resize( W->sizeHint() );
105#endif 118#endif
106 rv = TheApp->exec(); 119 rv = TheApp->exec();
107 delete W; 120 delete W;
108 } 121 }
109 break; 122 break;
110 } 123 }
111 124
112 return rv; 125 return rv;
113} 126}
114 127
115#endif 128#endif
116 129
117 130
118// main.cpp 131// main.cpp
119 132
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp
index 054385a..3e368a2 100644
--- a/noncore/settings/networksettings2/network/network_NNI.cpp
+++ b/noncore/settings/networksettings2/network/network_NNI.cpp
@@ -1,168 +1,189 @@
1#include <system.h> 1#include <system.h>
2#include <asdevice.h> 2#include <asdevice.h>
3#include "networkedit.h" 3#include "networkedit.h"
4#include "network_NNI.h" 4#include "network_NNI.h"
5#include "network_NN.h" 5#include "network_NN.h"
6 6
7ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) { 7ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) {
8 Data.UseDHCP = 1; 8 Data.UseDHCP = 1;
9 Data.IPAddress = ""; 9 Data.IPAddress = "";
10 Data.NetMask = ""; 10 Data.NetMask = "";
11 Data.Broadcast = ""; 11 Data.Broadcast = "";
12 Data.Gateway = ""; 12 Data.Gateway = "";
13 Data.DNS1 = ""; 13 Data.DNS1 = "";
14 Data.DNS2 = ""; 14 Data.DNS2 = "";
15 Data.SendHostname = 0; 15 Data.SendHostname = 0;
16 Data.Hostname = ""; 16 Data.Hostname = "";
17 Data.PreUp_SL.clear(); 17 Data.PreUp_SL.clear();
18 Data.PreDown_SL.clear(); 18 Data.PreDown_SL.clear();
19 Data.PostUp_SL.clear(); 19 Data.PostUp_SL.clear();
20 Data.PostDown_SL.clear(); 20 Data.PostDown_SL.clear();
21 GUI = 0; 21 GUI = 0;
22 RT = 0; 22 RT = 0;
23} 23}
24 24
25void ANetwork::setSpecificAttribute( QString & A, QString & V ) { 25void ANetwork::setSpecificAttribute( QString & A, QString & V ) {
26 if( A == "usedhcp" ) { 26 if( A == "usedhcp" ) {
27 Data.UseDHCP = (V == "yes"); 27 Data.UseDHCP = (V == "yes");
28 } else if( A == "sendhostname" ) { 28 } else if( A == "sendhostname" ) {
29 Data.SendHostname = (V=="yes"); 29 Data.SendHostname = (V=="yes");
30 } else if( A == "hostname" ) { 30 } else if( A == "hostname" ) {
31 Data.Hostname = V; 31 Data.Hostname = V;
32 } else if( A == "ipaddress" ) { 32 } else if( A == "ipaddress" ) {
33 Data.IPAddress = V; 33 Data.IPAddress = V;
34 } else if( A == "netmask" ) { 34 } else if( A == "netmask" ) {
35 Data.NetMask = V; 35 Data.NetMask = V;
36 } else if( A == "broadcast" ) { 36 } else if( A == "broadcast" ) {
37 Data.Broadcast = V; 37 Data.Broadcast = V;
38 } else if( A == "gateway" ) { 38 } else if( A == "gateway" ) {
39 Data.Gateway = V; 39 Data.Gateway = V;
40 } else if( A == "dns1" ) { 40 } else if( A == "dns1" ) {
41 Data.DNS1 = V; 41 Data.DNS1 = V;
42 } else if( A == "dns2" ) { 42 } else if( A == "dns2" ) {
43 Data.DNS2 = V; 43 Data.DNS2 = V;
44 } else if( A == "preup" ) { 44 } else if( A == "preup" ) {
45 Data.PreUp_SL.append( V ); 45 Data.PreUp_SL.append( V );
46 } else if( A == "predown" ) { 46 } else if( A == "predown" ) {
47 Data.PreDown_SL.append( V ); 47 Data.PreDown_SL.append( V );
48 } else if( A == "postup" ) { 48 } else if( A == "postup" ) {
49 Data.PostUp_SL.append( V ); 49 Data.PostUp_SL.append( V );
50 } else if( A == "postdown" ) { 50 } else if( A == "postdown" ) {
51 Data.PostDown_SL.append( V ); 51 Data.PostDown_SL.append( V );
52 } 52 }
53} 53}
54 54
55void ANetwork::saveSpecificAttribute( QTextStream & TS ) { 55void ANetwork::saveSpecificAttribute( QTextStream & TS ) {
56 TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl; 56 TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl;
57 TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl; 57 TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl;
58 TS << "hostname=" << Data.Hostname << endl; 58 TS << "hostname=" << Data.Hostname << endl;
59 TS << "ipaddress=" << Data.IPAddress << endl; 59 TS << "ipaddress=" << Data.IPAddress << endl;
60 TS << "netmask=" << Data.NetMask << endl; 60 TS << "netmask=" << Data.NetMask << endl;
61 TS << "broadcast=" << Data.Broadcast << endl; 61 TS << "broadcast=" << Data.Broadcast << endl;
62 TS << "gateway=" << Data.Gateway << endl; 62 TS << "gateway=" << Data.Gateway << endl;
63 TS << "dns1=" << Data.DNS1 << endl; 63 TS << "dns1=" << Data.DNS1 << endl;
64 TS << "dns2=" << Data.DNS2 << endl; 64 TS << "dns2=" << Data.DNS2 << endl;
65 for ( QStringList::Iterator it = Data.PreUp_SL.begin(); 65 for ( QStringList::Iterator it = Data.PreUp_SL.begin();
66 it != Data.PreUp_SL.end(); 66 it != Data.PreUp_SL.end();
67 ++it ) { 67 ++it ) {
68 TS << "preup=" << quote(*it) << endl; 68 TS << "preup=" << quote(*it) << endl;
69 } 69 }
70 for ( QStringList::Iterator it = Data.PreDown_SL.begin(); 70 for ( QStringList::Iterator it = Data.PreDown_SL.begin();
71 it != Data.PreDown_SL.end(); 71 it != Data.PreDown_SL.end();
72 ++it ) { 72 ++it ) {
73 TS << "predown=" << quote(*it) << endl; 73 TS << "predown=" << quote(*it) << endl;
74 } 74 }
75 for ( QStringList::Iterator it = Data.PostUp_SL.begin(); 75 for ( QStringList::Iterator it = Data.PostUp_SL.begin();
76 it != Data.PostUp_SL.end(); 76 it != Data.PostUp_SL.end();
77 ++it ) { 77 ++it ) {
78 TS << "postup=" << quote(*it) << endl; 78 TS << "postup=" << quote(*it) << endl;
79 } 79 }
80 for ( QStringList::Iterator it = Data.PostDown_SL.begin(); 80 for ( QStringList::Iterator it = Data.PostDown_SL.begin();
81 it != Data.PostDown_SL.end(); 81 it != Data.PostDown_SL.end();
82 ++it ) { 82 ++it ) {
83 TS << "postdown=" << quote(*it) << endl; 83 TS << "postdown=" << quote(*it) << endl;
84 } 84 }
85} 85}
86 86
87QWidget * ANetwork::edit( QWidget * parent ) { 87QWidget * ANetwork::edit( QWidget * parent ) {
88 GUI = new NetworkEdit( parent ); 88 GUI = new NetworkEdit( parent );
89 GUI->showData( Data ); 89 GUI->showData( Data );
90 return GUI; 90 return GUI;
91} 91}
92 92
93QString ANetwork::acceptable( void ) { 93QString ANetwork::acceptable( void ) {
94 return ( GUI ) ? GUI->acceptable( ) : QString(); 94 return ( GUI ) ? GUI->acceptable( ) : QString();
95} 95}
96 96
97void ANetwork::commit( void ) { 97void ANetwork::commit( void ) {
98 if( GUI && GUI->commit( Data ) ) 98 if( GUI && GUI->commit( Data ) )
99 setModified( 1 ); 99 setModified( 1 );
100} 100}
101 101
102bool ANetwork::hasDataFor( const QString & S ) { 102bool ANetwork::hasDataFor( const QString & S ) {
103 return S == "interfaces"; 103 return S == "interfaces";
104} 104}
105 105
106bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { 106bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) {
107 QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); 107 QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr );
108 108
109 if( S.name() == "interfaces" ) { 109 if( S.name() == "interfaces" ) {
110 // we can safely call from here since device item is deeper 110 // we can safely call from here since device item is deeper
111 if( Data.UseDHCP ) { 111 if( Data.UseDHCP ) {
112 S << "iface " << NIC << "-c" << connection()->number() << 112 S << "iface "
113 "-allowed inet dhcp" << endl; 113 << NIC
114 S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << 114 << "-c"
115 ".up" << Data.IPAddress << endl; 115 << connection()->number()
116 << "-allowed inet dhcp"
117 << endl;
118 S << " up echo \""
119 << NIC
120 << "\" > /tmp/profile-"
121 << connection()->number()
122 << ".up"
123 << endl;
116 if( Data.SendHostname ) { 124 if( Data.SendHostname ) {
117 S << " hostname "<< Data.Hostname << endl; 125 S << " hostname "
126 << Data.Hostname
127 << endl;
118 } 128 }
119 129
120 S << " down rm -f /tmp/profile-" << connection()->number() << 130 S << " down rm -f /tmp/profile-"
121 ".up" << Data.IPAddress << endl; 131 << connection()->number()
132 << ".up"
133 << endl;
122 } else { 134 } else {
123 S << "iface " << NIC << "-c" << connection()->number() << 135 S << "iface "
124 "-allowed inet static" << endl; 136 << NIC << "-c"
125 S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << 137 << connection()->number()
126 ".up" << Data.IPAddress << endl; 138 << "-allowed inet static"
127 S << " down rm -f /tmp/profile-" << connection()->number() << 139 << endl;
128 ".up" << Data.IPAddress << endl; 140 S << " up echo \""
141 << NIC
142 << "\" > /tmp/profile-"
143 << connection()->number()
144 << ".up"
145 << endl;
146 S << " down rm -f /tmp/profile-"
147 << connection()->number()
148 << ".up"
149 << endl;
129 S << " address " << Data.IPAddress << endl; 150 S << " address " << Data.IPAddress << endl;
130 S << " broadcast " << Data.Broadcast << endl; 151 S << " broadcast " << Data.Broadcast << endl;
131 S << " netmask " << Data.NetMask << endl; 152 S << " netmask " << Data.NetMask << endl;
132 153
133 // derive network address = IPAddress & netmask 154 // derive network address = IPAddress & netmask
134 { QString NW; 155 { QString NW;
135 QStringList ipal = QStringList::split( '.', Data.IPAddress ); 156 QStringList ipal = QStringList::split( '.', Data.IPAddress );
136 QStringList nmal = QStringList::split( '.', Data.NetMask ); 157 QStringList nmal = QStringList::split( '.', Data.NetMask );
137 158
138 NW = QString( "%1.%2.%3.%4" ). 159 NW = QString( "%1.%2.%3.%4" ).
139 arg( ipal[0].toShort() & nmal[0].toShort() ). 160 arg( ipal[0].toShort() & nmal[0].toShort() ).
140 arg( ipal[1].toShort() & nmal[1].toShort() ). 161 arg( ipal[1].toShort() & nmal[1].toShort() ).
141 arg( ipal[2].toShort() & nmal[2].toShort() ). 162 arg( ipal[2].toShort() & nmal[2].toShort() ).
142 arg( ipal[3].toShort() & nmal[3].toShort() ); 163 arg( ipal[3].toShort() & nmal[3].toShort() );
143 S << " network " << NW << endl; 164 S << " network " << NW << endl;
144 } 165 }
145 } 166 }
146 for ( QStringList::Iterator it = Data.PreUp_SL.begin(); 167 for ( QStringList::Iterator it = Data.PreUp_SL.begin();
147 it != Data.PreUp_SL.end(); 168 it != Data.PreUp_SL.end();
148 ++it ) { 169 ++it ) {
149 S << " pre-up " << (*it) << endl; 170 S << " pre-up " << (*it) << endl;
150 } 171 }
151 for ( QStringList::Iterator it = Data.PostUp_SL.begin(); 172 for ( QStringList::Iterator it = Data.PostUp_SL.begin();
152 it != Data.PostUp_SL.end(); 173 it != Data.PostUp_SL.end();
153 ++it ) { 174 ++it ) {
154 S << " up " << (*it) << endl; 175 S << " up " << (*it) << endl;
155 } 176 }
156 for ( QStringList::Iterator it = Data.PreDown_SL.begin(); 177 for ( QStringList::Iterator it = Data.PreDown_SL.begin();
157 it != Data.PreDown_SL.end(); 178 it != Data.PreDown_SL.end();
158 ++it ) { 179 ++it ) {
159 S << " down " << (*it) << endl; 180 S << " down " << (*it) << endl;
160 } 181 }
161 for ( QStringList::Iterator it = Data.PostDown_SL.begin(); 182 for ( QStringList::Iterator it = Data.PostDown_SL.begin();
162 it != Data.PostDown_SL.end(); 183 it != Data.PostDown_SL.end();
163 ++it ) { 184 ++it ) {
164 S << " post-down " << (*it) << endl; 185 S << " post-down " << (*it) << endl;
165 } 186 }
166 } 187 }
167 return 0; 188 return 0;
168} 189}
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp
index ddb9a5f..c19235a 100644
--- a/noncore/settings/networksettings2/network/networkrun.cpp
+++ b/noncore/settings/networksettings2/network/networkrun.cpp
@@ -1,66 +1,66 @@
1#include <system.h> 1#include <system.h>
2#include <asdevice.h> 2#include <asdevice.h>
3#include "networkrun.h" 3#include "networkrun.h"
4 4
5void NetworkRun::detectState( NodeCollection * NC ) { 5void NetworkRun::detectState( NodeCollection * NC ) {
6 RuntimeInfo * RI = netNode()->nextNode()->runtime(); 6 RuntimeInfo * RI = netNode()->nextNode()->runtime();
7 AsDevice * Next = RI->asDevice(); 7 AsDevice * Next = RI->asDevice();
8 InterfaceInfo * II = Next->assignedInterface(); 8 InterfaceInfo * II = Next->assignedInterface();
9 9
10 if( II ) { 10 if( II ) {
11 // device has assigned interface 11 // device has assigned interface
12 NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); 12 NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) );
13 return; 13 return;
14 } 14 }
15 15
16 // has no interface -> delegate 16 // has no interface -> delegate
17 RI->detectState( NC ); 17 RI->detectState( NC );
18} 18}
19 19
20bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { 20bool NetworkRun::setState( NodeCollection * NC, Action_t A ) {
21 // we handle UP and DOWN 21 // we handle UP and DOWN
22 RuntimeInfo * RI = netNode()->nextNode()->runtime(); 22 RuntimeInfo * RI = netNode()->nextNode()->runtime();
23 AsDevice * Next = RI->asDevice(); 23 AsDevice * Next = RI->asDevice();
24 InterfaceInfo * II = Next->assignedInterface(); 24 InterfaceInfo * II = Next->assignedInterface();
25 25
26 if( A == Up ) { 26 if( A == Up ) {
27 // we can bring UP if lower level is available 27 // we can bring UP if lower level is available
28 if( NC->currentState() == Available ) { 28 if( NC->currentState() == Available ) {
29 QString S; 29 QString S;
30 S.sprintf( "ifup %s=%s-c%d-allowed", 30 S.sprintf( "ifup %s=%s-c%d-allowed",
31 II->Name.latin1(), II->Name.latin1(), 31 II->Name.latin1(), II->Name.latin1(),
32 connection()->number() ); 32 connection()->number() );
33 NSResources->system().execute( S ); 33 NSResources->system().runAsRoot( S );
34 } 34 }
35 return 1; 35 return 1;
36 } else if( A == Down ) { 36 } else if( A == Down ) {
37 if( NC->currentState() == IsUp ) { 37 if( NC->currentState() == IsUp ) {
38 QString S; 38 QString S;
39 S.sprintf( "ifdown %s=%s-c%d-allowed", 39 S.sprintf( "ifdown %s=%s-c%d-allowed",
40 II->Name.latin1(), II->Name.latin1(), 40 II->Name.latin1(), II->Name.latin1(),
41 connection()->number() ); 41 connection()->number() );
42 NSResources->system().execute( S ); 42 NSResources->system().runAsRoot( S );
43 } 43 }
44 return 1; 44 return 1;
45 } 45 }
46 // delegate 46 // delegate
47 return RI->setState( NC, A ); 47 return RI->setState( NC, A );
48} 48}
49 49
50bool NetworkRun::canSetState( State_t Curr, Action_t A ) { 50bool NetworkRun::canSetState( State_t Curr, Action_t A ) {
51 // we handle UP and DOWN 51 // we handle UP and DOWN
52 RuntimeInfo * RI = netNode()->nextNode()->runtime(); 52 RuntimeInfo * RI = netNode()->nextNode()->runtime();
53 53
54 if( A == Up ) { 54 if( A == Up ) {
55 return ( Curr == Available ); 55 return ( Curr == Available );
56 } else if( A == Down ) { 56 } else if( A == Down ) {
57 return ( Curr == IsUp ); 57 return ( Curr == IsUp );
58 } 58 }
59 // delegate 59 // delegate
60 return RI->canSetState( Curr, A ); 60 return RI->canSetState( Curr, A );
61} 61}
62 62
63bool NetworkRun::handlesInterface( const QString & S ) { 63bool NetworkRun::handlesInterface( const QString & S ) {
64 // donno -> pass deeper 64 // donno -> pass deeper
65 return netNode()->nextNode()->runtime()->handlesInterface(S); 65 return netNode()->nextNode()->runtime()->handlesInterface(S);
66} 66}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 0301361..e6ce2b7 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -1,234 +1,369 @@
1#include <unistd.h>
2#include <errno.h>
3#include <fcntl.h>
4#include <pwd.h>
1#include <qpixmap.h> 5#include <qpixmap.h>
6#include <qdir.h>
2#include <qpe/qlibrary.h> 7#include <qpe/qlibrary.h>
3#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
4#include <qdir.h>
5#include <opie2/odebug.h> 9#include <opie2/odebug.h>
6#include <qtopia/resource.h> 10#include <qtopia/resource.h>
7 11
8#include "netnode.h" 12#include "netnode.h"
9#include "resources.h" 13#include "resources.h"
10 14
11#define PLUGINDIR "plugins/networksettings2" 15#define PLUGINDIR "plugins/networksettings2"
12#define ICONDIR "/pics/networksettings2/" 16#define ICONDIR "/pics/networksettings2/"
13 17
14// single resources instance 18// single resources instance
15TheNSResources * _NSResources = 0; 19TheNSResources * _NSResources = 0;
16 20
17TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), 21TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
18 ConnectionsMap() { 22 ConnectionsMap() {
19 23
20 _NSResources = this; 24 _NSResources = this;
21 25
22 // load available netnodes 26 // load available netnodes
23 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); 27 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
24 28
25 // compile provides and needs lists 29 // compile provides and needs lists
26 { const char ** NeedsRun; 30 { const char ** NeedsRun;
27 QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); 31 QDictIterator<NetNode_t> OuterIt( AllNodeTypes );
28 bool Done; 32 bool Done;
29 33
30 for ( ; OuterIt.current(); ++OuterIt ) { 34 for ( ; OuterIt.current(); ++OuterIt ) {
31 // find needs list 35 // find needs list
32 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; 36 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList;
33 ANetNode::NetNodeList & NNL = *(NNLP); 37 ANetNode::NetNodeList & NNL = *(NNLP);
34 38
35 // must iterate this way to avoid duplication pointers 39 // must iterate this way to avoid duplication pointers
36 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); 40 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes );
37 InnerIt.current(); ++InnerIt ) { 41 InnerIt.current(); ++InnerIt ) {
38 if( InnerIt.current() == OuterIt.current() ) 42 if( InnerIt.current() == OuterIt.current() )
39 // avoid recursive 43 // avoid recursive
40 continue; 44 continue;
41 45
42 const char * Provides = InnerIt.current()->NetNode->provides(); 46 const char * Provides = InnerIt.current()->NetNode->provides();
43 NeedsRun = OuterIt.current()->NetNode->needs(); 47 NeedsRun = OuterIt.current()->NetNode->needs();
44 for( ; *NeedsRun; NeedsRun ++ ) { 48 for( ; *NeedsRun; NeedsRun ++ ) {
45 if( strcmp( Provides, *NeedsRun ) == 0 ) { 49 if( strcmp( Provides, *NeedsRun ) == 0 ) {
46 // inner provides what outer needs 50 // inner provides what outer needs
47 NNL.resize( NNL.size() + 1 ); 51 NNL.resize( NNL.size() + 1 );
48 NNL[NNL.size()-1] = InnerIt.current()->NetNode; 52 NNL[NNL.size()-1] = InnerIt.current()->NetNode;
49 Done = 1; // break from 2 loops 53 Done = 1; // break from 2 loops
50 break; 54 break;
51 } 55 }
52 } 56 }
53 } 57 }
54 OuterIt.current()->NetNode->setAlternatives( NNLP ); 58 OuterIt.current()->NetNode->setAlternatives( NNLP );
55 } 59 }
56 } 60 }
57 61
58 // define Node types to Description map 62 // define Node types to Description map
59 NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); 63 NodeTypeNameMap.insert( "device", tr( "Network Device" ) );
60 NodeTypeNameMap.insert( "line", tr( "Character device" ) ); 64 NodeTypeNameMap.insert( "line", tr( "Character device" ) );
61 NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); 65 NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) );
62 NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); 66 NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) );
63 67
64 NodeTypeDescriptionMap.insert( "device", 68 NodeTypeDescriptionMap.insert( "device",
65 tr( "<p>Devices that can handle IP packets</p>" ) ); 69 tr( "<p>Devices that can handle IP packets</p>" ) );
66 NodeTypeDescriptionMap.insert( "line", 70 NodeTypeDescriptionMap.insert( "line",
67 tr( "<p>Devices that can handle single bytes</p>" ) ); 71 tr( "<p>Devices that can handle single bytes</p>" ) );
68 NodeTypeDescriptionMap.insert( "connection", 72 NodeTypeDescriptionMap.insert( "connection",
69 tr( "<p>Nodes that provide working IP connections</p>" ) ); 73 tr( "<p>Nodes that provide working IP connections</p>" ) );
70 NodeTypeDescriptionMap.insert( "fullsetup", 74 NodeTypeDescriptionMap.insert( "fullsetup",
71 tr( "<p>Fully configured connection profile</p>" ) ); 75 tr( "<p>Fully configured connection profile</p>" ) );
72 76
73 // define system files 77 // define system files
74 addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); 78 addSystemFile( new SystemFile( "interfaces", "./interfaces" ) );
75 79
76 // get access to the system 80 // get access to the system
77 TheSystem = new System(); 81 TheSystem = new System();
82
83 detectCurrentUser();
78} 84}
79 85
80TheNSResources::~TheNSResources( void ) { 86TheNSResources::~TheNSResources( void ) {
81 delete TheSystem; 87 delete TheSystem;
82} 88}
83 89
84/** 90/**
85 * Load all modules that are found in the path 91 * Load all modules that are found in the path
86 * @param path a directory that is scaned for any plugins that can be loaded 92 * @param path a directory that is scaned for any plugins that can be loaded
87 * and attempts to load them 93 * and attempts to load them
88 */ 94 */
89void TheNSResources::findAvailableNetNodes(const QString &path){ 95void TheNSResources::findAvailableNetNodes(const QString &path){
90 96
91 QDir d(path); 97 QDir d(path);
92 if(!d.exists()) 98 if(!d.exists())
93 return; 99 return;
94 100
95 QString lang = ::getenv("LANG"); 101 QString lang = ::getenv("LANG");
96 102
97 // Don't want sym links 103 // Don't want sym links
98 d.setFilter( QDir::Files | QDir::NoSymLinks ); 104 d.setFilter( QDir::Files | QDir::NoSymLinks );
99 const QFileInfoList *list = d.entryInfoList(); 105 const QFileInfoList *list = d.entryInfoList();
100 QFileInfoListIterator it( *list ); 106 QFileInfoListIterator it( *list );
101 QFileInfo *fi; 107 QFileInfo *fi;
102 108
103 while ( (fi=it.current()) ) { 109 while ( (fi=it.current()) ) {
104 110
105 if( fi->fileName().contains(".so")){ 111 if( fi->fileName().contains(".so")){
106 /* if loaded install translation */ 112 /* if loaded install translation */
107 if( loadNetNode(path + "/" + fi->fileName()) ) { 113 if( loadNetNode(path + "/" + fi->fileName()) ) {
108 QTranslator *trans = new QTranslator(qApp); 114 QTranslator *trans = new QTranslator(qApp);
109 QString fn = QPEApplication::qpeDir()+ 115 QString fn = QPEApplication::qpeDir()+
110 "/i18n/"+lang+"/"+ 116 "/i18n/"+lang+"/"+
111 fi->fileName().left( fi->fileName().find(".") )+ 117 fi->fileName().left( fi->fileName().find(".") )+
112 ".qm"; 118 ".qm";
113 119
114 if( trans->load( fn ) ) 120 if( trans->load( fn ) )
115 qApp->installTranslator( trans ); 121 qApp->installTranslator( trans );
116 else 122 else
117 delete trans; 123 delete trans;
118 } 124 }
119 } 125 }
120 ++it; 126 ++it;
121 } 127 }
122} 128}
123 129
124/** 130/**
125 * Attempt to load a function and resolve a function. 131 * Attempt to load a function and resolve a function.
126 * @param pluginFileName - the name of the file in which to attempt to load 132 * @param pluginFileName - the name of the file in which to attempt to load
127 * @param resolveString - function pointer to resolve 133 * @param resolveString - function pointer to resolve
128 * @return true of loading is successful 134 * @return true of loading is successful
129 */ 135 */
130bool TheNSResources::loadNetNode( 136bool TheNSResources::loadNetNode(
131 const QString &pluginFileName, const QString &resolveString){ 137 const QString &pluginFileName, const QString &resolveString){
132 138
133 QLibrary *lib = new QLibrary(pluginFileName); 139 QLibrary *lib = new QLibrary(pluginFileName);
134 void * res = lib->resolve(resolveString); 140 void * res = lib->resolve(resolveString);
135 if( ! res ){ 141 if( ! res ){
136 delete lib; 142 delete lib;
137 return 0; 143 return 0;
138 } 144 }
139 145
140 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; 146 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res;
141 147
142 // Try to get an object. 148 // Try to get an object.
143 QList<ANetNode> PNN; 149 QList<ANetNode> PNN;
144 150
145 getNetNodeList( PNN ); 151 getNetNodeList( PNN );
146 if( PNN.isEmpty() ) { 152 if( PNN.isEmpty() ) {
147 delete lib; 153 delete lib;
148 return 0; 154 return 0;
149 } 155 }
150 156
151 ANetNode * NNP; 157 ANetNode * NNP;
152 for( QListIterator<ANetNode> it(PNN); 158 for( QListIterator<ANetNode> it(PNN);
153 it.current(); 159 it.current();
154 ++it ) { 160 ++it ) {
155 NetNode_t * NN; 161 NetNode_t * NN;
156 162
157 NNP = it.current(); 163 NNP = it.current();
158 NN = new NetNode_t; 164 NN = new NetNode_t;
159 NN->NetNode = NNP; 165 NN->NetNode = NNP;
160 NN->TheLibrary = lib; 166 NN->TheLibrary = lib;
161 NN->NodeCountInLib = PNN.count(); 167 NN->NodeCountInLib = PNN.count();
162 168
163 // store mapping 169 // store mapping
164 AllNodeTypes.insert( NN->NetNode->nodeName(), NN ); 170 AllNodeTypes.insert( NN->NetNode->nodeName(), NN );
165 } 171 }
166 172
167 return 1; 173 return 1;
168} 174}
169 175
170QPixmap TheNSResources::getPixmap( const QString & QS ) { 176QPixmap TheNSResources::getPixmap( const QString & QS ) {
171 QString S("networksettings2/"); 177 QString S("networksettings2/");
172 S += QS; 178 S += QS;
173 printf( " pixmap %s\n", S.latin1() ); 179 printf( " pixmap %s\n", S.latin1() );
174 return Resource::loadPixmap( QString("networksettings2/")+QS ); 180 return Resource::loadPixmap( QString("networksettings2/")+QS );
175} 181}
176 182
177QString TheNSResources::tr( const char * s ) { 183QString TheNSResources::tr( const char * s ) {
178 return qApp->translate( "resource", s ); 184 return qApp->translate( "resource", s );
179} 185}
180 186
181const QString & TheNSResources::netNode2Name( const char * s ) { 187const QString & TheNSResources::netNode2Name( const char * s ) {
182 return NodeTypeNameMap[s]; 188 return NodeTypeNameMap[s];
183} 189}
184 190
185const QString & TheNSResources::netNode2Description( const char * s ) { 191const QString & TheNSResources::netNode2Description( const char * s ) {
186 return NodeTypeDescriptionMap[s]; 192 return NodeTypeDescriptionMap[s];
187} 193}
188 194
189void TheNSResources::addConnection( NodeCollection * NC ) { 195void TheNSResources::addConnection( NodeCollection * NC ) {
190 ANetNodeInstance * NNI; 196 ANetNodeInstance * NNI;
191 ConnectionsMap.insert( NC->name(), NC ); 197 ConnectionsMap.insert( NC->name(), NC );
192 // add (new) nodes to NodeList 198 // add (new) nodes to NodeList
193 for( QListIterator<ANetNodeInstance> it(*NC); 199 for( QListIterator<ANetNodeInstance> it(*NC);
194 it.current(); 200 it.current();
195 ++it ) { 201 ++it ) {
196 NNI = it.current(); 202 NNI = it.current();
197 if( findNodeInstance( NNI->nodeName() ) == 0 ) { 203 if( findNodeInstance( NNI->nodeName() ) == 0 ) {
198 // new item 204 // new item
199 addNodeInstance( NNI ); 205 addNodeInstance( NNI );
200 } 206 }
201 } 207 }
202} 208}
203 209
204void TheNSResources::removeConnection( const QString & N ) { 210void TheNSResources::removeConnection( const QString & N ) {
205 NodeCollection * NC = findConnection( N ); 211 NodeCollection * NC = findConnection( N );
206 if( ! NC ) 212 if( ! NC )
207 return; 213 return;
208 214
209 // delete netnodes in this connection 215 // delete netnodes in this connection
210 ANetNodeInstance * NNI; 216 ANetNodeInstance * NNI;
211 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { 217 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) {
212 removeNodeInstance( NNI->nodeName() ); 218 removeNodeInstance( NNI->nodeName() );
213 } 219 }
214 ConnectionsMap.remove( N ); 220 ConnectionsMap.remove( N );
215} 221}
216 222
217NodeCollection * TheNSResources::findConnection( const QString & S ) { 223NodeCollection * TheNSResources::findConnection( const QString & S ) {
218 return ConnectionsMap[ S ]; 224 return ConnectionsMap[ S ];
219} 225}
220 226
221void TheNSResources::renumberConnections( void ) { 227void TheNSResources::renumberConnections( void ) {
222 Name2Connection_t & M = NSResources->connections(); 228 Name2Connection_t & M = NSResources->connections();
223 NodeCollection * NC; 229 NodeCollection * NC;
224 230
225 // for all connections 231 // for all connections
226 NodeCollection::resetMaxNr(); 232 NodeCollection::resetMaxNr();
227 for( QDictIterator<NodeCollection> it(M); 233 for( QDictIterator<NodeCollection> it(M);
228 it.current(); 234 it.current();
229 ++it ) { 235 ++it ) {
230 NC = it.current(); 236 NC = it.current();
231 NC->setNumber( NC->maxConnectionNumber()+1 ); 237 NC->setNumber( NC->maxConnectionNumber()+1 );
232 NC->setModified( 1 ); 238 NC->setModified( 1 );
233 } 239 }
234} 240}
241
242typedef struct EnvVars {
243 char * Name;
244 int Len;
245} EnvVar_t;
246
247#define AnEV(x) x, sizeof(x)-1
248
249static EnvVar_t EV[] = {
250 // AnEV( "HOME=" ), -> SPECIAL
251 // AnEV( "LOGNAME=" ), -> SPECIAL
252 AnEV( "USER=" ),
253 AnEV( "LD_LIBRARY_PATH=" ),
254 AnEV( "PATH=" ),
255 AnEV( "QTDIR=" ),
256 AnEV( "OPIEDIR=" ),
257 AnEV( "SHELL=" ),
258 { NULL, 0 }
259};
260
261void TheNSResources::detectCurrentUser( void ) {
262 // find current running qpe
263 QString QPEEnvFile = "";
264
265 // open proc dir and find all dirs in it
266 { QRegExp R("[0-9]+");
267 QDir ProcDir( "/proc" );
268 QString QPELoc = QPEApplication::qpeDir() + "bin/qpe";
269 QFileInfo FI;
270 QStringList EL = ProcDir.entryList( QDir::Dirs );
271
272 // print it out
273 for ( QStringList::Iterator it = EL.begin();
274 it != EL.end();
275 ++it ) {
276 if( R.match( (*it) ) >= 0 ) {
277 QString S = ProcDir.path()+"/"+ (*it);
278 S.append( "/exe" );
279 FI.setFile( S );
280 // get the linke
281 S = FI.readLink();
282 if( S == QPELoc ) {
283 // found running qpe
284 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
285 break;
286 }
287 }
288 }
289 }
290
291 if( QPEEnvFile.isEmpty() ) {
292 // could not find qpe
293 fprintf( stderr, "Could not find qpe\n" );
294 return;
295 }
296
297 // FI now contains path ProcDir to the cmd dir
298 { char * Buf = 0;
299 char TB[1024];
300 long BufSize = 0;
301 int fd;
302 int rd;
303
304 fd = open( QPEEnvFile.latin1(), O_RDONLY );
305 if( fd < 0 ) {
306 fprintf( stderr, "Could not open %s : %d\n",
307 QPEEnvFile.latin1(), errno );
308 return;
309 }
310
311 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) {
312 Buf = (char *)realloc( Buf, BufSize+rd );
313 memcpy( Buf+BufSize, TB, rd );
314 BufSize += rd;
315 }
316
317 char * Data = Buf;
318 char * DataEnd = Data+BufSize-1;
319
320 // get env items out of list
321 while( Data < DataEnd ) {
322 if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) {
323 CurrentUser.UserName = Data+8;
324 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
325 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
326 strdup( Data );
327 } else if( strncmp( Data, "HOME=", 5 ) == 0 ) {
328 CurrentUser.HomeDir = Data+5;
329 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
330 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
331 strdup( Data );
332 } else {
333 EnvVar_t * Run = EV;
334 while( Run->Name ) {
335 if( strncmp( Data, Run->Name, Run->Len ) == 0 ) {
336 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
337 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
338 strdup( Data );
339 break;
340 }
341 Run ++;
342 }
343 }
344
345 Data += strlen( Data )+1;
346 }
347
348 free( Buf );
349
350 if( ! CurrentUser.UserName.isEmpty() ) {
351 // find user info
352 struct passwd pwd;
353 struct passwd * pwdres;
354
355 if( getpwnam_r( CurrentUser.UserName.latin1(),
356 &pwd, TB, sizeof(TB), &pwdres ) ||
357 pwdres == 0 ) {
358 fprintf( stderr, "Could not determine user %s : %d\n",
359 CurrentUser.UserName.latin1(), errno );
360 return;
361 }
362 CurrentUser.Uid = pwd.pw_uid;
363 CurrentUser.Gid = pwd.pw_gid;
364 } else{
365 CurrentUser.Uid =
366 CurrentUser.Gid = -1;
367 }
368 }
369}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h
index 4df3ce3..3048fb3 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.h
+++ b/noncore/settings/networksettings2/networksettings2/resources.h
@@ -1,110 +1,128 @@
1#ifndef __RESOURCES__H 1#ifndef __RESOURCES__H
2#define __RESOURCES__H 2#define __RESOURCES__H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qdict.h> 5#include <qdict.h>
6#include <qmap.h> 6#include <qmap.h>
7#include <qlist.h> 7#include <qlist.h>
8#include "netnode.h" 8#include "netnode.h"
9#include "systemfile.h" 9#include "systemfile.h"
10#include "system.h" 10#include "system.h"
11 11
12class QLibrary; 12class QLibrary;
13class QPixmap; 13class QPixmap;
14class ANetNode; 14class ANetNode;
15class ANetNodeInstance; 15class ANetNodeInstance;
16 16
17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); 17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );
18 18
19typedef struct NetNode_S { 19typedef struct NetNode_S {
20 ANetNode * NetNode; 20 ANetNode * NetNode;
21 QLibrary * TheLibrary; 21 QLibrary * TheLibrary;
22 long NodeCountInLib; 22 long NodeCountInLib;
23} NetNode_t; 23} NetNode_t;
24 24
25class CurrentQPEUser {
26
27public :
28 CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}
29
30 QString UserName;
31 QString HomeDir;
32 int Uid;
33 int Gid;
34 QArray<char *> EnvList;
35};
36
25typedef QDict<NetNode_t> Name2NetNode_t; 37typedef QDict<NetNode_t> Name2NetNode_t;
26typedef QDict<ANetNodeInstance > Name2Instance_t; 38typedef QDict<ANetNodeInstance > Name2Instance_t;
27typedef QDict<NodeCollection> Name2Connection_t; 39typedef QDict<NodeCollection> Name2Connection_t;
28typedef QDict<SystemFile> Name2SystemFile_t; 40typedef QDict<SystemFile> Name2SystemFile_t;
29 41
30class TheNSResources { 42class TheNSResources {
31 43
32public : 44public :
33 45
34 TheNSResources( void ); 46 TheNSResources( void );
35 ~TheNSResources( ); 47 ~TheNSResources( );
36 48
37 System & system() 49 System & system()
38 { return *TheSystem; } 50 { return *TheSystem; }
39 51
40 QPixmap getPixmap( const QString & Name ); 52 QPixmap getPixmap( const QString & Name );
41 53
42 Name2NetNode_t & netNodes( void ) 54 Name2NetNode_t & netNodes( void )
43 { return AllNodeTypes; } 55 { return AllNodeTypes; }
44 bool netNodeExists( const QString & X ) 56 bool netNodeExists( const QString & X )
45 { return AllNodeTypes.find(X)!=0; } 57 { return AllNodeTypes.find(X)!=0; }
46 58
47 Name2SystemFile_t & systemFiles( void ) 59 Name2SystemFile_t & systemFiles( void )
48 { return SystemFiles; } 60 { return SystemFiles; }
49 void addSystemFile( SystemFile * SF ) 61 void addSystemFile( SystemFile * SF )
50 { SystemFiles.insert( SF->name(), SF ); } 62 { SystemFiles.insert( SF->name(), SF ); }
51 63
52 ANetNodeInstance * createNodeInstance( const QString & S ) 64 ANetNodeInstance * createNodeInstance( const QString & S )
53 { ANetNodeInstance * NNI = 0; 65 { ANetNodeInstance * NNI = 0;
54 NetNode_t * NNT = AllNodeTypes[S]; 66 NetNode_t * NNT = AllNodeTypes[S];
55 ANetNode * NN; 67 ANetNode * NN;
56 if( ! NNT ) { 68 if( ! NNT ) {
57 NN = FakeNode = 69 NN = FakeNode =
58 ( FakeNode ) ? FakeNode : new FakeNetNode(); 70 ( FakeNode ) ? FakeNode : new FakeNetNode();
59 } else { 71 } else {
60 NN = NNT->NetNode; 72 NN = NNT->NetNode;
61 } 73 }
62 NNI = NN->createInstance(); 74 NNI = NN->createInstance();
63 NNI->initialize(); 75 NNI->initialize();
64 return NNI; 76 return NNI;
65 } 77 }
66 78
67 Name2Instance_t & netNodeInstances( void ) 79 Name2Instance_t & netNodeInstances( void )
68 { return AllNodes; } 80 { return AllNodes; }
69 void addNodeInstance( ANetNodeInstance * I ) 81 void addNodeInstance( ANetNodeInstance * I )
70 { AllNodes.insert( I->nodeName(), I ); } 82 { AllNodes.insert( I->nodeName(), I ); }
71 void removeNodeInstance( const QString & N ) 83 void removeNodeInstance( const QString & N )
72 { AllNodes.remove( N );} 84 { AllNodes.remove( N );}
73 ANetNodeInstance * findNodeInstance( const QString & S ) 85 ANetNodeInstance * findNodeInstance( const QString & S )
74 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } 86 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }
75 87
76 const QString & netNode2Name( const char * Type ); 88 const QString & netNode2Name( const char * Type );
77 const QString & netNode2Description( const char * Type ); 89 const QString & netNode2Description( const char * Type );
78 90
79 void renumberConnections( void ); 91 void renumberConnections( void );
80 void addConnection( NodeCollection * NC ); 92 void addConnection( NodeCollection * NC );
81 void removeConnection( const QString & N ); 93 void removeConnection( const QString & N );
82 NodeCollection * findConnection( const QString & N ); 94 NodeCollection * findConnection( const QString & N );
83 Name2Connection_t & connections( void ) 95 Name2Connection_t & connections( void )
84 { return ConnectionsMap; } 96 { return ConnectionsMap; }
85 97
98 CurrentQPEUser & currentUser( void )
99 { return CurrentUser; }
100
86private : 101private :
87 102
103 void detectCurrentUser( void );
88 QString tr( const char * path ); 104 QString tr( const char * path );
89 void findAvailableNetNodes( const QString &path ); 105 void findAvailableNetNodes( const QString &path );
90 bool loadNetNode( 106 bool loadNetNode(
91 const QString &pluginFileName, 107 const QString &pluginFileName,
92 const QString &resolveString = "create_plugin"); 108 const QString &resolveString = "create_plugin");
93 109
94 QMap< QString, QString> NodeTypeNameMap; 110 QMap< QString, QString> NodeTypeNameMap;
95 QMap< QString, QString> NodeTypeDescriptionMap; 111 QMap< QString, QString> NodeTypeDescriptionMap;
96 Name2Connection_t ConnectionsMap; 112 Name2Connection_t ConnectionsMap;
97 System * TheSystem; 113 System * TheSystem;
98 Name2SystemFile_t SystemFiles; 114 Name2SystemFile_t SystemFiles;
99 115
100 // all node type classes 116 // all node type classes
101 Name2NetNode_t AllNodeTypes; 117 Name2NetNode_t AllNodeTypes;
102 118
103 // all nodes 119 // all nodes
104 Name2Instance_t AllNodes; 120 Name2Instance_t AllNodes;
121
122 CurrentQPEUser CurrentUser;
105}; 123};
106 124
107extern TheNSResources * _NSResources; 125extern TheNSResources * _NSResources;
108#define NSResources _NSResources 126#define NSResources _NSResources
109 127
110#endif 128#endif
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp
index a68f3c0..2133d34 100644
--- a/noncore/settings/networksettings2/networksettings2/system.cpp
+++ b/noncore/settings/networksettings2/networksettings2/system.cpp
@@ -1,320 +1,355 @@
1#include <stdlib.h>
2#include <sys/types.h> 1#include <sys/types.h>
3#include <sys/wait.h> 2#include <sys/wait.h>
4#include <qfile.h> 3
5#include <qtextstream.h>
6#include <net/if.h> 4#include <net/if.h>
7#include <net/if_arp.h> 5#include <net/if_arp.h>
8#include <netinet/in.h> 6#include <netinet/in.h>
9#include <arpa/inet.h> 7#include <arpa/inet.h>
10#include <sys/ioctl.h> 8#include <sys/ioctl.h>
11#include <sys/socket.h> 9#include <sys/socket.h>
10#include <stdlib.h>
11#include <fcntl.h>
12#include <errno.h>
13#include <unistd.h>
14
15#include <qdir.h>
16#include <qregexp.h>
17#include <qstringlist.h>
18#include <qfile.h>
19#include <qtextstream.h>
12 20
13#include "resources.h" 21#include "resources.h"
14#include "system.h" 22#include "system.h"
15 23
16#define PROCNETDEV "/proc/net/dev" 24#define PROCNETDEV "/proc/net/dev"
17 25
18static char Dig2Hex[] = { 26static char Dig2Hex[] = {
19 '0', '1', '2', '3', 27 '0', '1', '2', '3',
20 '4', '5', '6', '7', 28 '4', '5', '6', '7',
21 '8', '9', 'A', 'B', 29 '8', '9', 'A', 'B',
22 'C', 'D', 'E', 'F' 30 'C', 'D', 'E', 'F'
23}; 31};
24 32
25// get HIGH nibble of byte 33// get HIGH nibble of byte
26#define HN(x) Dig2Hex[(((x)&0xf0)>>4)] 34#define HN(x) Dig2Hex[(((x)&0xf0)>>4)]
27// get LOW nibble of byte 35// get LOW nibble of byte
28#define LN(x) Dig2Hex[((x)&0x0f)] 36#define LN(x) Dig2Hex[((x)&0x0f)]
29 37
30System::System( void ) : ProbedInterfaces() { 38System::System( void ) : ProbedInterfaces() {
31 probeInterfaces(); 39 probeInterfaces();
32} 40}
33 41
34System::~System( void ) { 42System::~System( void ) {
35 if( ProcDevNet ) 43 if( ProcDevNet )
36 delete ProcDevNet; 44 delete ProcDevNet;
37} 45}
38 46
39int System::execute( const QString & S ) { 47int System::runAsRoot( const QString & S ) {
40 QString MyS = S; 48 QString MyS = S;
41 char * usr = getenv("USER"); 49 char * usr = getenv("USER");
42 int rv; 50 int rv;
43 51
44 if( S.isEmpty() ) { 52 if( S.isEmpty() ) {
45 // loophole to start shell 53 // loophole to start shell
46 return 8888; 54 return 8888;
47 } 55 }
48 if( usr == 0 || strcmp( usr, "root" ) ) { 56 if( usr == 0 || strcmp( usr, "root" ) ) {
49 // unknown or non-root user -> use SUDO 57 // unknown or non-root user -> use SUDO
50 MyS.prepend( "sudo " ); 58 MyS.prepend( "sudo " );
51 } 59 }
52 60
53 fprintf( stderr, "Executing %s\n", MyS.latin1() ); 61 fprintf( stderr, "Executing %s\n", MyS.latin1() );
54 62
55 rv = system( MyS.latin1() ) ; 63 rv = system( MyS.latin1() ) ;
56 switch( rv ) { 64 switch( rv ) {
57 case -1 : 65 case -1 :
58 // cannot fork 66 // cannot fork
59 return 1; 67 return 1;
60 case 127 : 68 case 127 :
61 // cannot start shell 69 // cannot start shell
62 return 2; 70 return 2;
63 default : 71 default :
64 if( WEXITSTATUS(rv) != 0 ) { 72 if( WEXITSTATUS(rv) != 0 ) {
65 // error in command 73 // error in command
66 return 3; 74 return 3;
67 } 75 }
68 } 76 }
69 // all is fine 77 // all is fine
70 return 0; 78 return 0;
71} 79}
72 80
73void System::refreshStatistics( InterfaceInfo & I ) { 81void System::refreshStatistics( InterfaceInfo & I ) {
74 if( ! ProcDevNet ) { 82 if( ! ProcDevNet ) {
75 return; 83 return;
76 } 84 }
77 // cannot seek on dev 85 // cannot seek on dev
78 ProcDevNet->close(); 86 ProcDevNet->close();
79 ProcDevNet->open( IO_ReadOnly ); 87 ProcDevNet->open( IO_ReadOnly );
80 88
81 QString line; 89 QString line;
82 QTextStream procTs(ProcDevNet); 90 QTextStream procTs(ProcDevNet);
83 QStringList SL; 91 QStringList SL;
84 int loc = -1; 92 int loc = -1;
85 int version; 93 int version;
86 94
87 procTs.readLine(); 95 procTs.readLine();
88 line = procTs.readLine(); 96 line = procTs.readLine();
89 // get version 97 // get version
90 if( line.find("compressed") ) 98 if( line.find("compressed") )
91 version = 3; 99 version = 3;
92 else if( line.find( "bytes" ) ) 100 else if( line.find( "bytes" ) )
93 version = 2; 101 version = 2;
94 else 102 else
95 version = 1; 103 version = 1;
96 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { 104 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
97 if( (loc = line.find(":") ) == -1) { 105 if( (loc = line.find(":") ) == -1) {
98 continue; 106 continue;
99 } 107 }
100 108
101 if( I.Name != line.left(loc) ) 109 if( I.Name != line.left(loc) )
102 continue; 110 continue;
103 111
104 // tokenize 112 // tokenize
105 SL = QStringList::split( ' ', line, FALSE ); 113 SL = QStringList::split( ' ', line, FALSE );
106 114
107 // update data 115 // update data
108 switch( version ) { 116 switch( version ) {
109 case 1 : 117 case 1 :
110 I.RcvBytes = SL[1]; 118 I.RcvBytes = SL[1];
111 I.RcvErrors = SL[3]; 119 I.RcvErrors = SL[3];
112 I.RcvDropped = SL[4]; 120 I.RcvDropped = SL[4];
113 I.SndBytes = SL[6]; 121 I.SndBytes = SL[6];
114 I.SndErrors = SL[8]; 122 I.SndErrors = SL[8];
115 I.SndDropped = SL[9]; 123 I.SndDropped = SL[9];
116 I.Collisions = SL[11]; 124 I.Collisions = SL[11];
117 break; 125 break;
118 case 2 : 126 case 2 :
119 I.RcvBytes = SL[1]; 127 I.RcvBytes = SL[1];
120 I.RcvErrors = SL[3]; 128 I.RcvErrors = SL[3];
121 I.RcvDropped = SL[4]; 129 I.RcvDropped = SL[4];
122 I.SndBytes = SL[7]; 130 I.SndBytes = SL[7];
123 I.SndErrors = SL[9]; 131 I.SndErrors = SL[9];
124 I.SndDropped = SL[10]; 132 I.SndDropped = SL[10];
125 I.Collisions = SL[12]; 133 I.Collisions = SL[12];
126 break; 134 break;
127 case 3 : 135 case 3 :
128 I.RcvBytes = SL[1]; 136 I.RcvBytes = SL[1];
129 I.RcvErrors = SL[3]; 137 I.RcvErrors = SL[3];
130 I.RcvDropped = SL[4]; 138 I.RcvDropped = SL[4];
131 I.SndBytes = SL[9]; 139 I.SndBytes = SL[9];
132 I.SndErrors = SL[11]; 140 I.SndErrors = SL[11];
133 I.SndDropped = SL[12]; 141 I.SndDropped = SL[12];
134 I.Collisions = SL[14]; 142 I.Collisions = SL[14];
135 break; 143 break;
136 } 144 }
137 break; 145 break;
138 } 146 }
139} 147}
140 148
141// 149//
142// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT 150// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT
143// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT 151// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT
144// 152//
145 153
146void System::probeInterfaces( void ) { 154void System::probeInterfaces( void ) {
147 155
148 // probe interfaces 156 // probe interfaces
149 int sockfd; 157 int sockfd;
150 // get list of all interfaces 158 // get list of all interfaces
151 struct ifreq ifrs; 159 struct ifreq ifrs;
152 InterfaceInfo * IFI; 160 InterfaceInfo * IFI;
153 161
154 // flag all as 'down' 162 // flag all as 'down'
155 for( QDictIterator<InterfaceInfo> it( ProbedInterfaces ); 163 for( QDictIterator<InterfaceInfo> it( ProbedInterfaces );
156 it.current(); 164 it.current();
157 ++it ) { 165 ++it ) {
158 it.current()->IsUp = 0; 166 it.current()->IsUp = 0;
159 } 167 }
160 168
161 sockfd = socket(PF_INET, SOCK_DGRAM, 0); 169 sockfd = socket(PF_INET, SOCK_DGRAM, 0);
162 if(sockfd == -1) 170 if(sockfd == -1)
163 return; 171 return;
164 172
165 // read interfaces from /proc/dev/net 173 // read interfaces from /proc/dev/net
166 // SIOCGIFCONF does not return ALL interfaces ???!? 174 // SIOCGIFCONF does not return ALL interfaces ???!?
167 ProcDevNet = new QFile(PROCNETDEV); 175 ProcDevNet = new QFile(PROCNETDEV);
168 if( ! ProcDevNet->open(IO_ReadOnly) ) { 176 if( ! ProcDevNet->open(IO_ReadOnly) ) {
169 delete ProcDevNet; 177 delete ProcDevNet;
170 ProcDevNet =0; 178 ProcDevNet =0;
171 return; 179 return;
172 } 180 }
173 181
174 QString line; 182 QString line;
175 QString NicName; 183 QString NicName;
176 QTextStream procTs(ProcDevNet); 184 QTextStream procTs(ProcDevNet);
177 int loc = -1; 185 int loc = -1;
178 186
179 procTs.readLine(); // eat a line 187 procTs.readLine(); // eat a line
180 procTs.readLine(); // eat a line 188 procTs.readLine(); // eat a line
181 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { 189 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
182 if((loc = line.find(":")) == -1) { 190 if((loc = line.find(":")) == -1) {
183 continue; 191 continue;
184 } 192 }
185 193
186 NicName = line.left(loc); 194 NicName = line.left(loc);
187 195
188 // set name for ioctl 196 // set name for ioctl
189 strcpy( ifrs.ifr_name, NicName.latin1() ); 197 strcpy( ifrs.ifr_name, NicName.latin1() );
190 198
191 if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { 199 if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) {
192 // new nic 200 // new nic
193 fprintf( stderr, "NEWNIC %s\n", NicName.latin1()); 201 fprintf( stderr, "NEWNIC %s\n", NicName.latin1());
194 IFI = new InterfaceInfo; 202 IFI = new InterfaceInfo;
195 IFI->Name = line.left(loc); 203 IFI->Name = line.left(loc);
196 IFI->NetNode = 0; 204 IFI->NetNode = 0;
197 ProbedInterfaces.insert( IFI->Name, IFI ); 205 ProbedInterfaces.insert( IFI->Name, IFI );
198 206
199 // get dynamic info 207 // get dynamic info
200 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { 208 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
201 IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); 209 IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT);
202 } else { 210 } else {
203 IFI->IsPointToPoint = 0; 211 IFI->IsPointToPoint = 0;
204 } 212 }
205 213
206 // settings that never change 214 // settings that never change
207 IFI->DstAddress = ""; 215 IFI->DstAddress = "";
208 216
209 if( IFI->IsPointToPoint ) { 217 if( IFI->IsPointToPoint ) {
210 if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { 218 if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) {
211 IFI->DstAddress = 219 IFI->DstAddress =
212 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); 220 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr);
213 } 221 }
214 } 222 }
215 223
216 IFI->CardType = 999999; 224 IFI->CardType = 999999;
217 IFI->MACAddress = ""; 225 IFI->MACAddress = "";
218 226
219 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { 227 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
220 fprintf( stderr, "%s = %d\n", IFI->Name.latin1(), 228 fprintf( stderr, "%s = %d\n", IFI->Name.latin1(),
221 ifrs.ifr_hwaddr.sa_family ); 229 ifrs.ifr_hwaddr.sa_family );
222 230
223 IFI->CardType = ifrs.ifr_hwaddr.sa_family; 231 IFI->CardType = ifrs.ifr_hwaddr.sa_family;
224 switch( ifrs.ifr_hwaddr.sa_family ) { 232 switch( ifrs.ifr_hwaddr.sa_family ) {
225 case ARPHRD_ETHER : // regular MAC address 233 case ARPHRD_ETHER : // regular MAC address
226 // valid address -> convert to regular ::: format 234 // valid address -> convert to regular ::: format
227 // length = 6 bytes = 12 DIGITS -> 6 : 235 // length = 6 bytes = 12 DIGITS -> 6 :
228 IFI->MACAddress.sprintf( 236 IFI->MACAddress.sprintf(
229 "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", 237 "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
230 HN( ifrs.ifr_hwaddr.sa_data[0] ), 238 HN( ifrs.ifr_hwaddr.sa_data[0] ),
231 LN( ifrs.ifr_hwaddr.sa_data[0] ), 239 LN( ifrs.ifr_hwaddr.sa_data[0] ),
232 HN( ifrs.ifr_hwaddr.sa_data[1] ), 240 HN( ifrs.ifr_hwaddr.sa_data[1] ),
233 LN( ifrs.ifr_hwaddr.sa_data[1] ), 241 LN( ifrs.ifr_hwaddr.sa_data[1] ),
234 HN( ifrs.ifr_hwaddr.sa_data[2] ), 242 HN( ifrs.ifr_hwaddr.sa_data[2] ),
235 LN( ifrs.ifr_hwaddr.sa_data[2] ), 243 LN( ifrs.ifr_hwaddr.sa_data[2] ),
236 HN( ifrs.ifr_hwaddr.sa_data[3] ), 244 HN( ifrs.ifr_hwaddr.sa_data[3] ),
237 LN( ifrs.ifr_hwaddr.sa_data[3] ), 245 LN( ifrs.ifr_hwaddr.sa_data[3] ),
238 HN( ifrs.ifr_hwaddr.sa_data[4] ), 246 HN( ifrs.ifr_hwaddr.sa_data[4] ),
239 LN( ifrs.ifr_hwaddr.sa_data[4] ), 247 LN( ifrs.ifr_hwaddr.sa_data[4] ),
240 HN( ifrs.ifr_hwaddr.sa_data[5] ), 248 HN( ifrs.ifr_hwaddr.sa_data[5] ),
241 LN( ifrs.ifr_hwaddr.sa_data[5] ) 249 LN( ifrs.ifr_hwaddr.sa_data[5] )
242 ); 250 );
243 break; 251 break;
244#ifdef ARPHRD_IEEE1394 252#ifdef ARPHRD_IEEE1394
245 case ARPHRD_IEEE1394 : // Firewire Eth address 253 case ARPHRD_IEEE1394 : // Firewire Eth address
246 IFI->MACAddress.sprintf( 254 IFI->MACAddress.sprintf(
247 "%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00", 255 "%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00",
248 HN( ifrs.ifr_hwaddr.sa_data[0] ), 256 HN( ifrs.ifr_hwaddr.sa_data[0] ),
249 LN( ifrs.ifr_hwaddr.sa_data[0] ), 257 LN( ifrs.ifr_hwaddr.sa_data[0] ),
250 HN( ifrs.ifr_hwaddr.sa_data[1] ), 258 HN( ifrs.ifr_hwaddr.sa_data[1] ),
251 LN( ifrs.ifr_hwaddr.sa_data[1] ), 259 LN( ifrs.ifr_hwaddr.sa_data[1] ),
252 HN( ifrs.ifr_hwaddr.sa_data[2] ), 260 HN( ifrs.ifr_hwaddr.sa_data[2] ),
253 LN( ifrs.ifr_hwaddr.sa_data[2] ), 261 LN( ifrs.ifr_hwaddr.sa_data[2] ),
254 HN( ifrs.ifr_hwaddr.sa_data[3] ), 262 HN( ifrs.ifr_hwaddr.sa_data[3] ),
255 LN( ifrs.ifr_hwaddr.sa_data[3] ), 263 LN( ifrs.ifr_hwaddr.sa_data[3] ),
256 HN( ifrs.ifr_hwaddr.sa_data[4] ), 264 HN( ifrs.ifr_hwaddr.sa_data[4] ),
257 LN( ifrs.ifr_hwaddr.sa_data[4] ), 265 LN( ifrs.ifr_hwaddr.sa_data[4] ),
258 HN( ifrs.ifr_hwaddr.sa_data[5] ), 266 HN( ifrs.ifr_hwaddr.sa_data[5] ),
259 LN( ifrs.ifr_hwaddr.sa_data[5] ), 267 LN( ifrs.ifr_hwaddr.sa_data[5] ),
260 HN( ifrs.ifr_hwaddr.sa_data[6] ), 268 HN( ifrs.ifr_hwaddr.sa_data[6] ),
261 LN( ifrs.ifr_hwaddr.sa_data[6] ), 269 LN( ifrs.ifr_hwaddr.sa_data[6] ),
262 HN( ifrs.ifr_hwaddr.sa_data[7] ), 270 HN( ifrs.ifr_hwaddr.sa_data[7] ),
263 LN( ifrs.ifr_hwaddr.sa_data[7] ), 271 LN( ifrs.ifr_hwaddr.sa_data[7] ),
264 HN( ifrs.ifr_hwaddr.sa_data[8] ), 272 HN( ifrs.ifr_hwaddr.sa_data[8] ),
265 LN( ifrs.ifr_hwaddr.sa_data[8] ), 273 LN( ifrs.ifr_hwaddr.sa_data[8] ),
266 HN( ifrs.ifr_hwaddr.sa_data[9] ), 274 HN( ifrs.ifr_hwaddr.sa_data[9] ),
267 LN( ifrs.ifr_hwaddr.sa_data[9] ), 275 LN( ifrs.ifr_hwaddr.sa_data[9] ),
268 HN( ifrs.ifr_hwaddr.sa_data[10] ), 276 HN( ifrs.ifr_hwaddr.sa_data[10] ),
269 LN( ifrs.ifr_hwaddr.sa_data[10] ), 277 LN( ifrs.ifr_hwaddr.sa_data[10] ),
270 HN( ifrs.ifr_hwaddr.sa_data[11] ), 278 HN( ifrs.ifr_hwaddr.sa_data[11] ),
271 LN( ifrs.ifr_hwaddr.sa_data[11] ), 279 LN( ifrs.ifr_hwaddr.sa_data[11] ),
272 HN( ifrs.ifr_hwaddr.sa_data[12] ), 280 HN( ifrs.ifr_hwaddr.sa_data[12] ),
273 LN( ifrs.ifr_hwaddr.sa_data[12] ), 281 LN( ifrs.ifr_hwaddr.sa_data[12] ),
274 HN( ifrs.ifr_hwaddr.sa_data[13] ), 282 HN( ifrs.ifr_hwaddr.sa_data[13] ),
275 LN( ifrs.ifr_hwaddr.sa_data[13] ) 283 LN( ifrs.ifr_hwaddr.sa_data[13] )
276 ); 284 );
277 break; 285 break;
278#endif 286#endif
279 case ARPHRD_PPP : // PPP 287 case ARPHRD_PPP : // PPP
280 break; 288 break;
281 case ARPHRD_IEEE80211 : // WLAN 289 case ARPHRD_IEEE80211 : // WLAN
282 break; 290 break;
283 case ARPHRD_IRDA : // IRDA 291 case ARPHRD_IRDA : // IRDA
284 break; 292 break;
285 } 293 }
286 } 294 }
287 } else // else already probed before -> just update 295 } else // else already probed before -> just update
288 fprintf( stderr, "OLDNIC %s\n", NicName.latin1()); 296 fprintf( stderr, "OLDNIC %s\n", NicName.latin1());
289 297
290 // get dynamic info 298 // get dynamic info
291 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { 299 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
292 IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); 300 IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP);
293 IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); 301 IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST);
294 } else { 302 } else {
295 IFI->IsUp = 0; 303 IFI->IsUp = 0;
296 IFI->HasMulticast = 0; 304 IFI->HasMulticast = 0;
297 } 305 }
298 306
299 if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { 307 if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) {
300 IFI->Address = 308 IFI->Address =
301 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); 309 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr);
302 } else { 310 } else {
303 IFI->Address = ""; 311 IFI->Address = "";
304 IFI->IsUp = 0; 312 IFI->IsUp = 0;
305 } 313 }
306 if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { 314 if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) {
307 IFI->BCastAddress = 315 IFI->BCastAddress =
308 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); 316 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr);
309 } else { 317 } else {
310 IFI->BCastAddress = ""; 318 IFI->BCastAddress = "";
311 } 319 }
312 if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { 320 if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) {
313 IFI->Netmask = 321 IFI->Netmask =
314 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); 322 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr);
315 } else { 323 } else {
316 IFI->Netmask = ""; 324 IFI->Netmask = "";
317 } 325 }
318 fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ); 326 fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp );
319 } 327 }
320} 328}
329
330void System::execAsUser( QString & Cmd, char * argv[] ) {
331 CurrentQPEUser CU = NSResources->currentUser();
332
333 if( CU.UserName.isEmpty() ) {
334 // if we come here, the exec was not successfull
335 fprintf( stderr, "User not known \n" );
336 return;
337 }
338
339 // now we are ready to exec the requested command
340 setuid( CU.Uid );
341 setgid( CU.Gid );
342
343 char ** envp = (char **)alloca( sizeof( char *) *
344 (CU.EnvList.count()+1) );
345
346 for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
347 *(envp+i) = CU.EnvList[i];
348 }
349 envp[CU.EnvList.count()]=NULL;
350
351 execve( Cmd.latin1(), argv, envp );
352
353 // if we come here, the exec was not successfull
354 fprintf( stderr, "Could not exec : %d\n", errno );
355}
diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h
index f89fe5d..96ee9bd 100644
--- a/noncore/settings/networksettings2/networksettings2/system.h
+++ b/noncore/settings/networksettings2/networksettings2/system.h
@@ -1,76 +1,81 @@
1#ifndef __SYSTEM__H 1#ifndef __SYSTEM__H
2#define __SYSTEM__H 2#define __SYSTEM__H
3 3
4// for hardware types 4// for hardware types
5#include <net/if_arp.h> 5#include <net/if_arp.h>
6#include <qdict.h> 6#include <qdict.h>
7 7
8class ANetNodeInstance; 8class ANetNodeInstance;
9class QFile; 9class QFile;
10 10
11class InterfaceInfo { 11class InterfaceInfo {
12 12
13public : 13public :
14 14
15 InterfaceInfo() : 15 InterfaceInfo() :
16 Name(), 16 Name(),
17 MACAddress(), 17 MACAddress(),
18 BCastAddress(), 18 BCastAddress(),
19 Netmask(), 19 Netmask(),
20 DstAddress() { 20 DstAddress() {
21 } 21 }
22 22
23 ANetNodeInstance * assignedNode() 23 ANetNodeInstance * assignedNode()
24 { return NetNode; } 24 { return NetNode; }
25 25
26 void assignNode( ANetNodeInstance * NNI ) 26 void assignNode( ANetNodeInstance * NNI )
27 { NetNode = NNI; } 27 { NetNode = NNI; }
28 28
29 ANetNodeInstance * NetNode; // netnode taking care of me 29 ANetNodeInstance * NetNode; // netnode taking care of me
30 QString Name; // name of interface 30 QString Name; // name of interface
31 int CardType; // type of card 31 int CardType; // type of card
32 QString MACAddress; // MAC address 32 QString MACAddress; // MAC address
33 QString Address; // IP Address 33 QString Address; // IP Address
34 QString BCastAddress; // Broadcast Address 34 QString BCastAddress; // Broadcast Address
35 QString Netmask; // Netmask 35 QString Netmask; // Netmask
36 QString DstAddress; // Peer address (if P-t-P) 36 QString DstAddress; // Peer address (if P-t-P)
37 bool IsUp; // interface is UP 37 bool IsUp; // interface is UP
38 bool HasMulticast; // Supports Multicast 38 bool HasMulticast; // Supports Multicast
39 bool IsPointToPoint; // IsPointToPoint card 39 bool IsPointToPoint; // IsPointToPoint card
40 40
41 QString RcvBytes; 41 QString RcvBytes;
42 QString SndBytes; 42 QString SndBytes;
43 QString RcvErrors; 43 QString RcvErrors;
44 QString SndErrors; 44 QString SndErrors;
45 QString RcvDropped; 45 QString RcvDropped;
46 QString SndDropped; 46 QString SndDropped;
47 QString Collisions; 47 QString Collisions;
48}; 48};
49 49
50class System { 50class System {
51 51
52public : 52public :
53 53
54 System( void ); 54 System( void );
55 ~System( void ); 55 ~System( void );
56 56
57 QDict<InterfaceInfo> & interfaces( void ) 57 QDict<InterfaceInfo> & interfaces( void )
58 { return ProbedInterfaces; } 58 { return ProbedInterfaces; }
59 InterfaceInfo * interface( const QString& N ) 59 InterfaceInfo * interface( const QString& N )
60 { return ProbedInterfaces[N]; } 60 { return ProbedInterfaces[N]; }
61 61
62 int execute( const QString & S ); 62 // exec command as root
63 int runAsRoot( const QString & S );
64
65 // exec command as user
66 void execAsUser( QString & Cmd, char * argv[] );
67
63 // refresh stats for this interface 68 // refresh stats for this interface
64 void refreshStatistics( InterfaceInfo & ); 69 void refreshStatistics( InterfaceInfo & );
65 70
66 // reloads interfaces 71 // reloads interfaces
67 void probeInterfaces( void ); 72 void probeInterfaces( void );
68 73
69private : 74private :
70 75
71 QDict<InterfaceInfo> ProbedInterfaces; 76 QDict<InterfaceInfo> ProbedInterfaces;
72 QFile * ProcDevNet; 77 QFile * ProcDevNet;
73 78
74}; 79};
75 80
76#endif 81#endif
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index eb63e02..b4d9aaa 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -1,540 +1,544 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfile.h> 5#include <qfile.h>
6#include <qfileinfo.h> 6#include <qfileinfo.h>
7 7
8#include "nsdata.h" 8#include "nsdata.h"
9#include <asdevice.h> 9#include <asdevice.h>
10#include <resources.h> 10#include <resources.h>
11 11
12static QString CfgFile; 12static QString CfgFile;
13 13
14NetworkSettingsData::NetworkSettingsData( void ) { 14NetworkSettingsData::NetworkSettingsData( void ) {
15 // init global resources structure 15 // init global resources structure
16 new TheNSResources(); 16 new TheNSResources();
17 17
18 CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") ); 18 CfgFile.sprintf( "%s/NETCONFIG",
19 NSResources->currentUser().HomeDir.latin1() );
20 fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() );
19 21
20 // load settings 22 // load settings
21 Force = 0; 23 Force = 0;
22 IsModified = 0; 24 IsModified = 0;
23 loadSettings(); 25 loadSettings();
24} 26}
25 27
26// saving is done by caller 28// saving is done by caller
27NetworkSettingsData::~NetworkSettingsData( void ) { 29NetworkSettingsData::~NetworkSettingsData( void ) {
28 delete NSResources; 30 delete NSResources;
29} 31}
30 32
31void NetworkSettingsData::loadSettings( void ) { 33void NetworkSettingsData::loadSettings( void ) {
32 QString S; 34 QString S;
33 ANetNodeInstance* NNI; 35 ANetNodeInstance* NNI;
34 QString Attr, Value; 36 QString Attr, Value;
35 long idx; 37 long idx;
36 38
37 QFile F( CfgFile ); 39 QFile F( CfgFile );
38 QTextStream TS( &F ); 40 QTextStream TS( &F );
39 41
40 do { 42 do {
41 43
42 if( ! F.open(IO_ReadOnly) ) 44 if( ! F.open(IO_ReadOnly) )
43 break; 45 break;
44 46
45 /* load the file -> 47 /* load the file ->
46 48
47 FORMAT : 49 FORMAT :
48 50
49 [NETNODETYPE] 51 [NETNODETYPE]
50 Entries ... 52 Entries ...
51 <EMPTYLINE> 53 <EMPTYLINE>
52 [connection] 54 [connection]
53 Name=Name 55 Name=Name
54 Node=Name 56 Node=Name
55 <EMPTYLINE> 57 <EMPTYLINE>
56 */ 58 */
57 while( ! TS.atEnd() ) { 59 while( ! TS.atEnd() ) {
58 S = TS.readLine(); 60 S = TS.readLine();
59 61
60 if ( S.isEmpty() || S[0] != '[' ) 62 if ( S.isEmpty() || S[0] != '[' )
61 continue; 63 continue;
62 64
63 S = S.mid( 1, S.length()-2 ); 65 S = S.mid( 1, S.length()-2 );
64 66
65 if( ! NSResources ) { 67 if( ! NSResources ) {
66 continue; 68 continue;
67 } 69 }
68 70
69 if( S == "connection" ) { 71 if( S == "connection" ) {
70 // load connections -> collections of nodes 72 // load connections -> collections of nodes
71 NodeCollection * NC = new NodeCollection( TS ); 73 NodeCollection * NC = new NodeCollection( TS );
72 NSResources->addConnection( NC ); 74 NSResources->addConnection( NC );
73 } else { 75 } else {
74 // load nodes 76 // load nodes
75 NNI = NSResources->createNodeInstance( S ); 77 NNI = NSResources->createNodeInstance( S );
76 if( ! NNI ) { 78 if( ! NNI ) {
77 printf( "SKIPPING %s\n", S.latin1() ); 79 printf( "SKIPPING %s\n", S.latin1() );
78 } 80 }
79 81
80 do { 82 do {
81 S = TS.readLine(); 83 S = TS.readLine();
82 if( S.isEmpty() ) { 84 if( S.isEmpty() ) {
83 // empty line 85 // empty line
84 break; 86 break;
85 } 87 }
86 // node found ? 88 // node found ?
87 if( NNI ) { 89 if( NNI ) {
88 idx = S.find( '=' ); 90 idx = S.find( '=' );
89 if( idx > 0 ) { 91 if( idx > 0 ) {
90 Attr = S.left( idx ); 92 Attr = S.left( idx );
91 Value = S.mid( idx+1, S.length() ); 93 Value = S.mid( idx+1, S.length() );
92 } else { 94 } else {
93 Value=""; 95 Value="";
94 Attr = S; 96 Attr = S;
95 } 97 }
96 98
97 Value.stripWhiteSpace(); 99 Value.stripWhiteSpace();
98 Attr.stripWhiteSpace(); 100 Attr.stripWhiteSpace();
99 Attr.lower(); 101 Attr.lower();
100 // dequote Attr 102 // dequote Attr
101 Value = deQuote(Value); 103 Value = deQuote(Value);
102 104
103 // set the attribute 105 // set the attribute
104 NNI->setAttribute( Attr, Value ); 106 NNI->setAttribute( Attr, Value );
105 } 107 }
106 108
107 } while( 1 ); 109 } while( 1 );
108 if( NNI ) { 110 if( NNI ) {
109 // loading from file -> exists 111 // loading from file -> exists
110 NNI->setNew( FALSE ); 112 NNI->setNew( FALSE );
111 NSResources->addNodeInstance( NNI ); 113 NSResources->addNodeInstance( NNI );
112 } 114 }
113 } 115 }
114 } 116 }
115 117
116 } while( 0 ); 118 } while( 0 );
117 119
118} 120}
119 121
120QString NetworkSettingsData::saveSettings( void ) { 122QString NetworkSettingsData::saveSettings( void ) {
121 QString ErrS = ""; 123 QString ErrS = "";
122 124
123 if( ! isModified() ) 125 if( ! isModified() )
124 return ErrS; 126 return ErrS;
125 127
126 QString S; 128 QString S;
127 QFile F( CfgFile + ".bup" ); 129 QFile F( CfgFile + ".bup" );
128 130
129 printf( "Saving settings to %s\n", CfgFile.latin1() ); 131 printf( "Saving settings to %s\n", CfgFile.latin1() );
130 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { 132 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
131 ErrS = qApp->translate( "NetworkSettings", 133 ErrS = qApp->translate( "NetworkSettings",
132 "<p>Could not save setup to \"%1\" !</p>" ). 134 "<p>Could not save setup to \"%1\" !</p>" ).
133 arg(CfgFile); 135 arg(CfgFile);
134 // problem 136 // problem
135 return ErrS; 137 return ErrS;
136 } 138 }
137 139
138 QTextStream TS( &F ); 140 QTextStream TS( &F );
139 { Name2Connection_t & M = NSResources->connections(); 141 { Name2Connection_t & M = NSResources->connections();
140 ANetNodeInstance * NNI; 142 ANetNodeInstance * NNI;
141 143
142 // for all connections 144 // for all connections
143 for( QDictIterator<NodeCollection> it(M); 145 for( QDictIterator<NodeCollection> it(M);
144 it.current(); 146 it.current();
145 ++it ) { 147 ++it ) {
146 // all nodes in those connections 148 // all nodes in those connections
147 for( QListIterator<ANetNodeInstance> nit(*(it.current())); 149 for( QListIterator<ANetNodeInstance> nit(*(it.current()));
148 nit.current(); 150 nit.current();
149 ++nit ) { 151 ++nit ) {
150 // header 152 // header
151 NNI = nit.current(); 153 NNI = nit.current();
152 TS << '[' <<NNI->nodeClass()->nodeName() << ']' << endl; 154 TS << '[' <<NNI->nodeClass()->nodeName() << ']' << endl;
153 NNI->saveAttributes( TS ); 155 NNI->saveAttributes( TS );
154 TS << endl; 156 TS << endl;
155 } 157 }
156 158
157 TS << "[connection]" << endl; 159 TS << "[connection]" << endl;
158 it.current()->save(TS); 160 it.current()->save(TS);
159 } 161 }
160 } 162 }
161 163
162 QDir D("."); 164 QDir D(".");
163 D.rename( CfgFile + ".bup", CfgFile ); 165 D.rename( CfgFile + ".bup", CfgFile );
164 166
165 // 167 //
166 // proper files AND system files regenerated 168 // proper files AND system files regenerated
167 // 169 //
168 170
169 setModified( 0 ); 171 setModified( 0 );
170 return ErrS; 172 return ErrS;
171} 173}
172 174
173QString NetworkSettingsData::generateSettings( bool ForceReq ) { 175QString NetworkSettingsData::generateSettings( bool ForceReq ) {
174 bool ForceIt; 176 bool ForceIt;
175 QString S = ""; 177 QString S = "";
176 178
177 // include own force flag 179 // include own force flag
178 ForceIt = (Force) ? 1 : ForceReq; 180 ForceIt = (Force) ? 1 : ForceReq;
179 181
180 if( ! ForceIt && ! isModified() ) 182 if( ! ForceIt && ! isModified() )
181 return S; 183 return S;
182 184
183 // regenerate system files 185 // regenerate system files
184 fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() ); 186 fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() );
185 187
186 { Name2SystemFile_t & SFM = NSResources->systemFiles(); 188 { Name2SystemFile_t & SFM = NSResources->systemFiles();
187 Name2Connection_t & M = NSResources->connections(); 189 Name2Connection_t & M = NSResources->connections();
188 NodeCollection * NC; 190 NodeCollection * NC;
189 ANetNodeInstance * NNI; 191 ANetNodeInstance * NNI;
190 SystemFile * SF; 192 SystemFile * SF;
191 AsDevice * CurDev; 193 AsDevice * CurDev;
192 ANetNode * CurDevNN; 194 ANetNode * CurDevNN;
193 bool needToRegenerate = ForceIt; 195 bool needToRegenerate = ForceIt;
194 196
195 // 197 //
196 // check if we need to generate at least one of the system files 198 // check if we need to generate at least one of the system files
197 // 199 //
198 if( ! ForceIt ) { 200 if( ! ForceIt ) {
199 for( QDictIterator<SystemFile> sfit(SFM); 201 for( QDictIterator<SystemFile> sfit(SFM);
200 sfit.current(); 202 sfit.current();
201 ++sfit ) { 203 ++sfit ) {
202 SF = sfit.current(); 204 SF = sfit.current();
203 205
204 // check if there are nodes that are modified and require 206 // check if there are nodes that are modified and require
205 // data for this system file 207 // data for this system file
206 208
207 // for all connections 209 // for all connections
208 for( QDictIterator<NodeCollection> ncit(M); 210 for( QDictIterator<NodeCollection> ncit(M);
209 ncit.current(); 211 ncit.current();
210 ++ncit ) { 212 ++ncit ) {
211 NC = ncit.current(); 213 NC = ncit.current();
212 214
213 if( NC->isModified() ) { 215 if( NC->isModified() ) {
214 // does this connection 'touch' this system file ? 216 // does this connection 'touch' this system file ?
215 for( QListIterator<ANetNodeInstance> cncit(*NC); 217 for( QListIterator<ANetNodeInstance> cncit(*NC);
216 cncit.current(); 218 cncit.current();
217 ++cncit ) { 219 ++cncit ) {
218 NNI = cncit.current(); 220 NNI = cncit.current();
219 if( ( NNI->nodeClass()->hasDataFor( SF->name() ) || 221 if( ( NNI->nodeClass()->hasDataFor( SF->name() ) ||
220 NNI->hasDataFor( SF->name() ) 222 NNI->hasDataFor( SF->name() )
221 ) && 223 ) &&
222 NNI->isModified() ) { 224 NNI->isModified() ) {
223 needToRegenerate = 1; 225 needToRegenerate = 1;
224 break; 226 break;
225 } 227 }
226 } 228 }
227 } 229 }
228 if( needToRegenerate ) 230 if( needToRegenerate )
229 break; 231 break;
230 } 232 }
231 if( needToRegenerate ) 233 if( needToRegenerate )
232 break; 234 break;
233 } 235 }
234 } 236 }
235 237
236 // we cannot renumber with a FORCE request since 238 // we cannot renumber with a FORCE request since
237 // we probably are NOT going to save the config 239 // we probably are NOT going to save the config
238 // e.g. when using --regen option 240 // e.g. when using --regen option
239 if( ! ForceReq && needToRegenerate ) { 241 if( ! ForceReq && needToRegenerate ) {
240 NSResources->renumberConnections(); 242 NSResources->renumberConnections();
241 setModified(1); 243 setModified(1);
242 } 244 }
243 245
244 // 246 //
245 // generate files proper to each netnodeinstance 247 // generate files proper to each netnodeinstance
246 // 248 //
247 { Name2Instance_t & NNIs = NSResources->netNodeInstances(); 249 { Name2Instance_t & NNIs = NSResources->netNodeInstances();
248 250
249 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); 251 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs);
250 NNIIt.current(); 252 NNIIt.current();
251 ++NNIIt 253 ++NNIIt
252 ){ 254 ){
253 // for all nodes find those that are modified 255 // for all nodes find those that are modified
254 NNI = NNIIt.current(); 256 NNI = NNIIt.current();
255 257
256 if( ForceIt || NNI->isModified() ) { 258 if( ForceIt || NNI->isModified() ) {
257 if( ! NNI->nodeClass()->generateProperFilesFor( NNI ) ) { 259 if( ! NNI->nodeClass()->generateProperFilesFor( NNI ) ) {
258 // problem generating 260 // problem generating
259 S = qApp->translate( "NetworkSettings", 261 S = qApp->translate( "NetworkSettings",
260 "<p>Cannot generate files proper to \"%1\"</p>" ). 262 "<p>Cannot generate files proper to \"%1\"</p>" ).
261 arg(NNI->nodeClass()->nodeName()) ; 263 arg(NNI->nodeClass()->nodeName()) ;
262 return S; 264 return S;
263 } 265 }
264 } 266 }
265 } 267 }
266 } 268 }
267 269
268 // 270 //
269 // generate all system files 271 // generate all system files
270 // 272 //
271 for( QDictIterator<SystemFile> sfit(SFM); 273 for( QDictIterator<SystemFile> sfit(SFM);
272 sfit.current(); 274 sfit.current();
273 ++sfit ) { 275 ++sfit ) {
274 SF = sfit.current(); 276 SF = sfit.current();
275 277
276 fprintf( stderr, "Generating %s\n", SF->name().latin1() ); 278 fprintf( stderr, "Generating %s\n", SF->name().latin1() );
277 SF->open(); 279 SF->open();
278 280
279 do { // so we can break; 281 do { // so we can break;
280 282
281 // global presection for this system file 283 // global presection for this system file
282 if( SF->preSection() ) { 284 if( SF->preSection() ) {
283 S = qApp->translate( "NetworkSettings", 285 S = qApp->translate( "NetworkSettings",
284 "<p>Error in preSection for file \"%1\"</p>" ). 286 "<p>Error in preSection for file \"%1\"</p>" ).
285 arg( SF->name() ); 287 arg( SF->name() );
286 return S; 288 return S;
287 } 289 }
288 290
289 // find all netnodes and figure out if 291 // find all netnodes and figure out if
290 // for that node there are instances 292 // for that node there are instances
291 for( QDictIterator<NetNode_t> nnit( 293 for( QDictIterator<NetNode_t> nnit(
292 NSResources->netNodes() ); 294 NSResources->netNodes() );
293 nnit.current(); 295 nnit.current();
294 ++nnit ) { 296 ++nnit ) {
295 297
296 CurDevNN = nnit.current()->NetNode; 298 CurDevNN = nnit.current()->NetNode;
297 299
298 // are there instances for this netnode ? 300 // are there instances for this netnode ?
299 NNI = 0; 301 NNI = 0;
300 for( QDictIterator<ANetNodeInstance> nniit( 302 for( QDictIterator<ANetNodeInstance> nniit(
301 NSResources->netNodeInstances() ); 303 NSResources->netNodeInstances() );
302 nniit.current(); 304 nniit.current();
303 ++nniit ) { 305 ++nniit ) {
304 if( nniit.current()->nodeClass() == CurDevNN ) { 306 if( nniit.current()->nodeClass() == CurDevNN ) {
305 NNI = nniit.current(); 307 NNI = nniit.current();
306 break; 308 break;
307 } 309 }
308 } 310 }
309 311
310 if( ! NNI ) 312 if( ! NNI )
311 // no instances -> next netnode type 313 // no instances -> next netnode type
312 continue; 314 continue;
313 315
314 // has this node data for this system file ? 316 // has this node data for this system file ?
315 if( (CurDev = NNI->runtime()->asDevice() ) ) { 317 if( (CurDev = NNI->runtime()->asDevice() ) ) {
316 // generate start for this nodetype for all possible devices of this type 318 // generate start for this nodetype for all possible devices of this type
317 for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) { 319 for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) {
318 S = generateSystemFileNode( *SF, CurDev, NNI, i ); 320 S = generateSystemFileNode( *SF, CurDev, NNI, i );
319 if( ! S.isEmpty() ) 321 if( ! S.isEmpty() )
320 return S; 322 return S;
321 } 323 }
322 } else { 324 } else {
323 S = generateSystemFileNode( *SF, 0, NNI, -1 ); 325 S = generateSystemFileNode( *SF, 0, NNI, -1 );
324 if( ! S.isEmpty() ) 326 if( ! S.isEmpty() )
325 return S; 327 return S;
326 } 328 }
327 } 329 }
328 330
329 if( SF->postSection() ) { 331 if( SF->postSection() ) {
330 S = qApp->translate( "NetworkSettings", 332 S = qApp->translate( "NetworkSettings",
331 "<p>Error in postSection for file \"%1\"</p>" ). 333 "<p>Error in postSection for file \"%1\"</p>" ).
332 arg( SF->name() ); 334 arg( SF->name() );
333 return S; 335 return S;
334 } 336 }
335 337
336 } while( 0 ); 338 } while( 0 );
337 SF->close(); 339 SF->close();
338 } 340 }
339 } 341 }
340 Force = 0; 342 Force = 0;
341 return S; 343 return S;
342} 344}
343 345
344QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { 346QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) {
345 // collect connections that can work on top of this interface 347 // collect connections that can work on top of this interface
346 NodeCollection * NC; 348 NodeCollection * NC;
347 QList<NodeCollection> PossibleConnections; 349 QList<NodeCollection> PossibleConnections;
348 Name2Connection_t & M = NSResources->connections(); 350 Name2Connection_t & M = NSResources->connections();
349 351
350 // for all connections 352 // for all connections
351 for( QDictIterator<NodeCollection> it(M); 353 for( QDictIterator<NodeCollection> it(M);
352 it.current(); 354 it.current();
353 ++it ) { 355 ++it ) {
354 NC = it.current(); 356 NC = it.current();
355 // check if this profile handles the requested interface 357 // check if this profile handles the requested interface
358 fprintf( stderr, "check %s\n", NC->name().latin1() );
356 if( NC->handlesInterface( Interface ) && // if different Intf. 359 if( NC->handlesInterface( Interface ) && // if different Intf.
357 NC->state() != Disabled && // if not enabled 360 NC->state() != Disabled && // if not enabled
358 NC->state() != IsUp // if already used 361 NC->state() != IsUp // if already used
359 ) { 362 ) {
363 fprintf( stderr, "Append %s\n", NC->name().latin1() );
360 PossibleConnections.append( NC ); 364 PossibleConnections.append( NC );
361 } 365 }
362 } 366 }
363 return PossibleConnections; 367 return PossibleConnections;
364} 368}
365 369
366 370
367/* 371/*
368 Called by the system to see if interface can be brought UP 372 Called by the system to see if interface can be brought UP
369 373
370 if allowed, echo Interface-allowed else Interface-disallowed 374 if allowed, echo Interface-allowed else Interface-disallowed
371*/ 375*/
372 376
373void NetworkSettingsData::canStart( const char * Interface ) { 377bool NetworkSettingsData::canStart( const char * Interface ) {
374 // load situation 378 // load situation
375 NodeCollection * NC = 0; 379 NodeCollection * NC = 0;
376 QList<NodeCollection> PossibleConnections; 380 QList<NodeCollection> PossibleConnections;
377 381
378 PossibleConnections = collectPossible( Interface ); 382 PossibleConnections = collectPossible( Interface );
379 383
384 fprintf( stderr, "Possiblilies %d\n",
385 PossibleConnections.count() );
380 switch( PossibleConnections.count() ) { 386 switch( PossibleConnections.count() ) {
381 case 0 : // no connections 387 case 0 : // no connections
382 break; 388 break;
383 case 1 : // one connection 389 case 1 : // one connection
384 NC = PossibleConnections.first(); 390 NC = PossibleConnections.first();
385 break; 391 break;
386 default : // need to ask user ? 392 default : // need to ask user ?
387 // are we connected to a server 393 return 1;
388 // system( "su %d networksettings2 --prompt %s\n",
389 // "", Interface );
390 break;
391 } 394 }
392 395
393 if( NC ) { 396 if( NC ) {
394 switch( NC->state() ) { 397 switch( NC->state() ) {
395 case Unchecked : 398 case Unchecked :
396 case Unknown : 399 case Unknown :
397 case Unavailable : 400 case Unavailable :
398 case Disabled : 401 case Disabled :
399 // this profile does not allow interface to be UP 402 // this profile does not allow interface to be UP
400 // -> try others 403 // -> try others
401 break; 404 break;
402 case Off : 405 case Off :
403 // try to UP the device 406 // try to UP the device
404 if( ! NC->setState( Activate ) ) { 407 if( ! NC->setState( Activate ) ) {
405 // cannot bring device Online -> try other alters 408 // cannot bring device Online -> try other alters
406 break; 409 break;
407 } 410 }
408 // FT 411 // FT
409 case Available : 412 case Available :
410 case IsUp : // also called for 'ifdown' 413 case IsUp : // also called for 'ifdown'
411 // device is ready -> done 414 // device is ready -> done
412 printf( "%s-c%d-allowed\n", Interface, NC->number() ); 415 printf( "%s-c%d-allowed\n", Interface, NC->number() );
413 return; 416 return 0;
414 } 417 }
415 } else { 418 }
416 // if we come here no alternatives are possible 419
417 printf( "%s-cnn-disallowed\n", Interface ); 420 // if we come here no alternatives are possible
418 } 421 printf( "%s-cnn-disallowed\n", Interface );
422 return 0;
419} 423}
420 424
421/* 425/*
422 Called by the system to regenerate config files 426 Called by the system to regenerate config files
423*/ 427*/
424 428
425bool NetworkSettingsData::regenerate( void ) { 429bool NetworkSettingsData::regenerate( void ) {
426 QString S; 430 QString S;
427 // load situation 431 // load situation
428 S = generateSettings( TRUE ); 432 S = generateSettings( TRUE );
429 if( ! S.isEmpty() ) { 433 if( ! S.isEmpty() ) {
430 fprintf( stdout, "%s\n", S.latin1() ); 434 fprintf( stdout, "%s\n", S.latin1() );
431 return 1; 435 return 1;
432 } 436 }
433 return 0; 437 return 0;
434} 438}
435 439
436QString NetworkSettingsData::generateSystemFileNode( 440QString NetworkSettingsData::generateSystemFileNode(
437 SystemFile &SF, 441 SystemFile &SF,
438 AsDevice * CurDev, 442 AsDevice * CurDev,
439 ANetNodeInstance * DevNNI, 443 ANetNodeInstance * DevNNI,
440 long DevInstNr ) { 444 long DevInstNr ) {
441 445
442 QString S=""; 446 QString S="";
443 ANetNode * CurDevNN = DevNNI->nodeClass(); 447 ANetNode * CurDevNN = DevNNI->nodeClass();
444 Name2Connection_t & M = NSResources->connections(); 448 Name2Connection_t & M = NSResources->connections();
445 449
446 if( SF.preDeviceSection( CurDevNN ) ) { 450 if( SF.preDeviceSection( CurDevNN ) ) {
447 S = qApp->translate( "NetworkSettings", 451 S = qApp->translate( "NetworkSettings",
448 "<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ). 452 "<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ).
449 arg( SF.name() ). 453 arg( SF.name() ).
450 arg( CurDevNN->nodeName() ); 454 arg( CurDevNN->nodeName() );
451 return S; 455 return S;
452 } 456 }
453 457
454 if( CurDevNN->hasDataFor( SF.name() ) ) { 458 if( CurDevNN->hasDataFor( SF.name() ) ) {
455 if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { 459 if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) {
456 S = qApp->translate( "NetworkSettings", 460 S = qApp->translate( "NetworkSettings",
457 "<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ). 461 "<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ).
458 arg( SF.name() ). 462 arg( SF.name() ).
459 arg( CurDevNN->nodeName() ); 463 arg( CurDevNN->nodeName() );
460 return S; 464 return S;
461 } 465 }
462 } 466 }
463 467
464 if( CurDev ) 468 if( CurDev )
465 fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() ); 469 fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() );
466 else 470 else
467 fprintf( stderr, "Cur NO\n" ); 471 fprintf( stderr, "Cur NO\n" );
468 472
469 // now generate profile specific data for all 473 // now generate profile specific data for all
470 // connections working on a device of the current 474 // connections working on a device of the current
471 // netnode type 475 // netnode type
472 for( QDictIterator<NodeCollection> ncit(M); 476 for( QDictIterator<NodeCollection> ncit(M);
473 ncit.current(); 477 ncit.current();
474 ++ncit ) { 478 ++ncit ) {
475 NodeCollection * NC = ncit.current(); 479 NodeCollection * NC = ncit.current();
476 480
477 // currenly only those connections that work on 481 // currenly only those connections that work on
478 // the current device (or on no device if no current) 482 // the current device (or on no device if no current)
479 AsDevice * Dev = NC->device(); 483 AsDevice * Dev = NC->device();
480 484
481 fprintf( stderr, "%s\n", Dev->netNode()->nodeName().latin1() ); 485 fprintf( stderr, "%s\n", Dev->netNode()->nodeName().latin1() );
482 if( CurDev ) { 486 if( CurDev ) {
483 if( CurDevNN != Dev->netNode()->nodeClass() ) { 487 if( CurDevNN != Dev->netNode()->nodeClass() ) {
484 // other device type -> later 488 // other device type -> later
485 fprintf( stderr, "Other Dev type\n" ); 489 fprintf( stderr, "Other Dev type\n" );
486 continue; 490 continue;
487 } 491 }
488 } else { 492 } else {
489 if( Dev ) { 493 if( Dev ) {
490 // other 494 // other
491 continue; 495 continue;
492 } 496 }
493 } 497 }
494 498
495 // generate 'entry' 499 // generate 'entry'
496 if( SF.preNodeSection( DevNNI, DevInstNr ) ) { 500 if( SF.preNodeSection( DevNNI, DevInstNr ) ) {
497 S = qApp->translate( "NetworkSettings", 501 S = qApp->translate( "NetworkSettings",
498 "<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ). 502 "<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ).
499 arg( SF.name() ). 503 arg( SF.name() ).
500 arg( CurDevNN->nodeName() ); 504 arg( CurDevNN->nodeName() );
501 return S; 505 return S;
502 } 506 }
503 507
504 // ask all nodes in connection 508 // ask all nodes in connection
505 for( QListIterator<ANetNodeInstance> cncit(*NC); 509 for( QListIterator<ANetNodeInstance> cncit(*NC);
506 cncit.current(); 510 cncit.current();
507 ++cncit ) { 511 ++cncit ) {
508 ANetNodeInstance * NNI = cncit.current(); 512 ANetNodeInstance * NNI = cncit.current();
509 513
510 if( NNI->hasDataFor( SF.name() ) ) { 514 if( NNI->hasDataFor( SF.name() ) ) {
511 if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { 515 if( NNI->generateDataForCommonFile(SF,DevInstNr) ) {
512 S = qApp->translate( "NetworkSettings", 516 S = qApp->translate( "NetworkSettings",
513 "<p>Error in node part for file \"%1\" and node \"%2\"</p>" ). 517 "<p>Error in node part for file \"%1\" and node \"%2\"</p>" ).
514 arg( SF.name() ). 518 arg( SF.name() ).
515 arg( NNI->nodeClass()->nodeName() ); 519 arg( NNI->nodeClass()->nodeName() );
516 return S; 520 return S;
517 } 521 }
518 } 522 }
519 } 523 }
520 524
521 if( SF.postNodeSection( DevNNI, DevInstNr ) ) { 525 if( SF.postNodeSection( DevNNI, DevInstNr ) ) {
522 S = qApp->translate( "NetworkSettings", 526 S = qApp->translate( "NetworkSettings",
523 "<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ). 527 "<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ).
524 arg( SF.name() ). 528 arg( SF.name() ).
525 arg( CurDevNN->nodeName() ); 529 arg( CurDevNN->nodeName() );
526 return S; 530 return S;
527 } 531 }
528 SF << endl; 532 SF << endl;
529 } 533 }
530 534
531 if( SF.postDeviceSection( CurDevNN ) ) { 535 if( SF.postDeviceSection( CurDevNN ) ) {
532 S = qApp->translate( "NetworkSettings", 536 S = qApp->translate( "NetworkSettings",
533 "<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ). 537 "<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ).
534 arg( SF.name() ). 538 arg( SF.name() ).
535 arg( CurDevNN->nodeName() ); 539 arg( CurDevNN->nodeName() );
536 return S; 540 return S;
537 } 541 }
538 542
539 return S; 543 return S;
540} 544}
diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h
index b54df24..eb96930 100644
--- a/noncore/settings/networksettings2/nsdata.h
+++ b/noncore/settings/networksettings2/nsdata.h
@@ -1,42 +1,43 @@
1#ifndef __NSDATA_H 1#ifndef __NSDATA_H
2#define __NSDATA_H 2#define __NSDATA_H
3 3
4#include "netnode.h" 4#include "netnode.h"
5 5
6class NetworkSettingsData { 6class NetworkSettingsData {
7 7
8public : 8public :
9 9
10 NetworkSettingsData( void ); 10 NetworkSettingsData( void );
11 ~NetworkSettingsData( void ); 11 ~NetworkSettingsData( void );
12 12
13 void loadSettings( void ); 13 void loadSettings( void );
14 QString saveSettings( void ); 14 QString saveSettings( void );
15 15
16 QString generateSettings( bool Force = FALSE ); 16 QString generateSettings( bool Force = FALSE );
17 17
18 bool isModified( void ) 18 bool isModified( void )
19 { return IsModified; } 19 { return IsModified; }
20 void setModified( bool m ) 20 void setModified( bool m )
21 { IsModified = m; } 21 { IsModified = m; }
22 22
23 QList<NodeCollection> collectPossible( const char * Interface ); 23 QList<NodeCollection> collectPossible( const char * Interface );
24 void canStart( const char * Interface ); 24 // return TRUE if we need gui to decide
25 bool canStart( const char * Interface );
25 bool regenerate( void ); 26 bool regenerate( void );
26 27
27 void forceGeneration( bool m ) 28 void forceGeneration( bool m )
28 { Force = m; } 29 { Force = m; }
29 30
30private : 31private :
31 32
32 QString NetworkSettingsData::generateSystemFileNode( 33 QString NetworkSettingsData::generateSystemFileNode(
33 SystemFile & SF, 34 SystemFile & SF,
34 AsDevice * CurDev, 35 AsDevice * CurDev,
35 ANetNodeInstance * DevNNI, 36 ANetNodeInstance * DevNNI,
36 long DevInstNr ); 37 long DevInstNr );
37 bool IsModified; 38 bool IsModified;
38 bool Force; 39 bool Force;
39 40
40}; 41};
41 42
42#endif 43#endif