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,35 +1,36 @@
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 ++ ) {
@@ -47,65 +48,77 @@ int main( int argc, char * argv[] ) {
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
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
@@ -80,81 +80,102 @@ void ANetwork::saveSpecificAttribute( QTextStream & TS ) {
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 }
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,36 +1,40 @@
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 );
@@ -46,64 +50,66 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
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()+
@@ -203,32 +209,161 @@ void TheNSResources::addConnection( NodeCollection * NC ) {
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,71 +1,79 @@
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}
@@ -289,32 +297,59 @@ void System::probeInterfaces( void ) {
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
@@ -30,47 +30,52 @@ public :
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,50 +1,52 @@
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 ...
@@ -324,127 +326,129 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
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() );
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