summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/network_NNI.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/network/network_NNI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/network/network_NNI.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp
index 324c6e2..78e6545 100644
--- a/noncore/settings/networksettings2/network/network_NNI.cpp
+++ b/noncore/settings/networksettings2/network/network_NNI.cpp
@@ -1,50 +1,50 @@
1#include <system.h> 1#include <system.h>
2#include <asdevice.h> 2#include <netnode.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" ) {
@@ -54,166 +54,164 @@ void ANetwork::setSpecificAttribute( QString & A, QString & V ) {
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::hasDataForFile( const QString & S ) { 102bool ANetwork::hasDataForFile( SystemFile & S ) {
103 return S == "interfaces"; 103 return S.name() == "interfaces";
104} 104}
105 105
106short ANetwork::generateFile( const QString & ID, 106short ANetwork::generateFile( SystemFile &SF,
107 const QString & Path, 107 long DevNr
108 QTextStream &TS, 108 ) {
109 long DevNr
110 ) {
111 109
112 short rvl, rvd ; 110 short rvl, rvd ;
113 QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); 111 QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr );
114 112
115 rvl = 1; 113 rvl = 1;
116 if( ID == "interfaces" ) { 114 if( SF.name() == "interfaces" ) {
117 Log(("Generate Network for %s\n", ID.latin1() )); 115 Log(("Generate Network for %s\n", SF.name().latin1() ));
118 // we can safely call from here since device item is deeper 116 // we can safely call from here since device item is deeper
119 if( Data.UseDHCP ) { 117 if( Data.UseDHCP ) {
120 TS << "iface " 118 SF << "iface "
121 << NIC 119 << NIC
122 << "-c" 120 << "-c"
123 << connection()->number() 121 << connection()->number()
124 << "-allowed inet dhcp" 122 << "-allowed inet dhcp"
125 << endl; 123 << endl;
126 TS << " up echo \"" 124 SF << " up echo \""
127 << NIC 125 << NIC
128 << "\" > /tmp/profile-" 126 << "\" > /tmp/profile-"
129 << connection()->number() 127 << connection()->number()
130 << ".up" 128 << ".up"
131 << endl; 129 << endl;
132 if( Data.SendHostname ) { 130 if( Data.SendHostname ) {
133 TS << " hostname " 131 SF << " hostname "
134 << Data.Hostname 132 << Data.Hostname
135 << endl; 133 << endl;
136 } 134 }
137 135
138 TS << " down rm -f /tmp/profile-" 136 SF << " down rm -f /tmp/profile-"
139 << connection()->number() 137 << connection()->number()
140 << ".up" 138 << ".up"
141 << endl; 139 << endl;
142 } else { 140 } else {
143 TS << "iface " 141 SF << "iface "
144 << NIC << "-c" 142 << NIC << "-c"
145 << connection()->number() 143 << connection()->number()
146 << "-allowed inet static" 144 << "-allowed inet static"
147 << endl; 145 << endl;
148 TS << " up echo \"" 146 SF << " up echo \""
149 << NIC 147 << NIC
150 << "\" > /tmp/profile-" 148 << "\" > /tmp/profile-"
151 << connection()->number() 149 << connection()->number()
152 << ".up" 150 << ".up"
153 << endl; 151 << endl;
154 TS << " down rm -f /tmp/profile-" 152 SF << " down rm -f /tmp/profile-"
155 << connection()->number() 153 << connection()->number()
156 << ".up" 154 << ".up"
157 << endl; 155 << endl;
158 TS << " address " 156 SF << " address "
159 << Data.IPAddress 157 << Data.IPAddress
160 << endl; 158 << endl;
161 TS << " broadcast " 159 SF << " broadcast "
162 << Data.Broadcast 160 << Data.Broadcast
163 << endl; 161 << endl;
164 TS << " netmask " 162 SF << " netmask "
165 << Data.NetMask 163 << Data.NetMask
166 << endl; 164 << endl;
167 165
168 // derive network address = IPAddress & netmask 166 // derive network address = IPAddress & netmask
169 { QString NW; 167 { QString NW;
170 QStringList ipal = QStringList::split( '.', Data.IPAddress ); 168 QStringList ipal = QStringList::split( '.', Data.IPAddress );
171 QStringList nmal = QStringList::split( '.', Data.NetMask ); 169 QStringList nmal = QStringList::split( '.', Data.NetMask );
172 170
173 NW = QString( "%1.%2.%3.%4" ). 171 NW = QString( "%1.%2.%3.%4" ).
174 arg( ipal[0].toShort() & nmal[0].toShort() ). 172 arg( ipal[0].toShort() & nmal[0].toShort() ).
175 arg( ipal[1].toShort() & nmal[1].toShort() ). 173 arg( ipal[1].toShort() & nmal[1].toShort() ).
176 arg( ipal[2].toShort() & nmal[2].toShort() ). 174 arg( ipal[2].toShort() & nmal[2].toShort() ).
177 arg( ipal[3].toShort() & nmal[3].toShort() ); 175 arg( ipal[3].toShort() & nmal[3].toShort() );
178 TS << " network " 176 SF << " network "
179 << NW 177 << NW
180 << endl; 178 << endl;
181 } 179 }
182 } 180 }
183 for ( QStringList::Iterator it = Data.PreUp_SL.begin(); 181 for ( QStringList::Iterator it = Data.PreUp_SL.begin();
184 it != Data.PreUp_SL.end(); 182 it != Data.PreUp_SL.end();
185 ++it ) { 183 ++it ) {
186 TS << " pre-up " 184 SF << " pre-up "
187 << (*it) 185 << (*it)
188 << endl; 186 << endl;
189 } 187 }
190 for ( QStringList::Iterator it = Data.PostUp_SL.begin(); 188 for ( QStringList::Iterator it = Data.PostUp_SL.begin();
191 it != Data.PostUp_SL.end(); 189 it != Data.PostUp_SL.end();
192 ++it ) { 190 ++it ) {
193 TS << " up " 191 SF << " up "
194 << (*it) 192 << (*it)
195 << endl; 193 << endl;
196 } 194 }
197 for ( QStringList::Iterator it = Data.PreDown_SL.begin(); 195 for ( QStringList::Iterator it = Data.PreDown_SL.begin();
198 it != Data.PreDown_SL.end(); 196 it != Data.PreDown_SL.end();
199 ++it ) { 197 ++it ) {
200 TS << " down " 198 SF << " down "
201 << (*it) 199 << (*it)
202 << endl; 200 << endl;
203 } 201 }
204 for ( QStringList::Iterator it = Data.PostDown_SL.begin(); 202 for ( QStringList::Iterator it = Data.PostDown_SL.begin();
205 it != Data.PostDown_SL.end(); 203 it != Data.PostDown_SL.end();
206 ++it ) { 204 ++it ) {
207 TS << " post-down " 205 SF << " post-down "
208 << (*it) 206 << (*it)
209 << endl; 207 << endl;
210 } 208 }
211 rvl = 0; 209 rvl = 0;
212 } 210 }
213 211
214 // embed other info in it 212 // embed other info in it
215 rvd = connection()->getToplevel()->generateFileEmbedded( ID, Path, TS, DevNr ); 213 rvd = connection()->getToplevel()->generateFileEmbedded( SF, DevNr );
216 214
217 return (rvd == 2 || rvl == 2 ) ? 2 : 215 return (rvd == 2 || rvl == 2 ) ? 2 :
218 (rvd == 0 || rvl == 0 ) ? 0 : 1; 216 (rvd == 0 || rvl == 0 ) ? 0 : 1;
219} 217}