summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2003-01-21 16:17:11 (UTC)
committer benmeyer <benmeyer>2003-01-21 16:17:11 (UTC)
commitf31a6c629738a813f53a61656c88a4c5062db195 (patch) (unidiff)
tree9fefcb1ad61888162a6704d04da7ca5aed7fb1f5
parentf1530bc4a34aa1ae4963029536e435deeae67d33 (diff)
downloadopie-f31a6c629738a813f53a61656c88a4c5062db195.zip
opie-f31a6c629738a813f53a61656c88a4c5062db195.tar.gz
opie-f31a6c629738a813f53a61656c88a4c5062db195.tar.bz2
Added replaces
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp2
-rw-r--r--noncore/settings/networksettings/opie-networksettings.control3
2 files changed, 2 insertions, 3 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index 032819b..cc45525 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,304 +1,302 @@
1/** 1/**
2 * $Author$ 2 * $Author$
3 * $Date$ 3 * $Date$
4 * $Id$
5 * $Source$
6 */ 4 */
7 5
8#include "interface.h" 6#include "interface.h"
9#include <qdatetime.h> 7#include <qdatetime.h>
10#include <qfile.h> 8#include <qfile.h>
11#include <qdir.h> 9#include <qdir.h>
12#include <qfileinfo.h> 10#include <qfileinfo.h>
13#include <qtextstream.h> 11#include <qtextstream.h>
14 12
15#define IFCONFIG "/sbin/ifconfig" 13#define IFCONFIG "/sbin/ifconfig"
16#define DHCP_INFO_DIR "/etc/dhcpc" 14#define DHCP_INFO_DIR "/etc/dhcpc"
17 15
18#include <stdio.h> 16#include <stdio.h>
19#include <stdlib.h> 17#include <stdlib.h>
20 18
21Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ 19Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){
22 refresh(); 20 refresh();
23} 21}
24 22
25/** 23/**
26 * Set status 24 * Set status
27 * @param newStatus - the new status 25 * @param newStatus - the new status
28 * emit updateInterface 26 * emit updateInterface
29 */ 27 */
30void Interface::setStatus(bool newStatus){ 28void Interface::setStatus(bool newStatus){
31 if(status != newStatus){ 29 if(status != newStatus){
32 status = newStatus; 30 status = newStatus;
33 refresh(); 31 refresh();
34 } 32 }
35}; 33};
36 34
37/** 35/**
38 * Set if attached or not (802.11 card pulled out for example) 36 * Set if attached or not (802.11 card pulled out for example)
39 * @param isAttached - if attached 37 * @param isAttached - if attached
40 * emit updateInterface 38 * emit updateInterface
41 */ 39 */
42void Interface::setAttached(bool isAttached){ 40void Interface::setAttached(bool isAttached){
43 attached = isAttached; 41 attached = isAttached;
44 emit(updateInterface(this)); 42 emit(updateInterface(this));
45}; 43};
46 44
47/** 45/**
48 * Set Hardware name 46 * Set Hardware name
49 * @param name - the new name 47 * @param name - the new name
50 * emit updateInterface 48 * emit updateInterface
51 */ 49 */
52void Interface::setHardwareName(const QString &name){ 50void Interface::setHardwareName(const QString &name){
53 hardwareName = name; 51 hardwareName = name;
54 emit(updateInterface(this)); 52 emit(updateInterface(this));
55}; 53};
56 54
57/** 55/**
58 * Set Module owner 56 * Set Module owner
59 * @param owner - the new owner 57 * @param owner - the new owner
60 * emit updateInterface 58 * emit updateInterface
61 */ 59 */
62void Interface::setModuleOwner(Module *owner){ 60void Interface::setModuleOwner(Module *owner){
63 moduleOwner = owner; 61 moduleOwner = owner;
64 emit(updateInterface(this)); 62 emit(updateInterface(this));
65}; 63};
66 64
67 65
68/** 66/**
69 * Try to start the interface. 67 * Try to start the interface.
70 */ 68 */
71void Interface::start(){ 69void Interface::start(){
72 // check to see if we are already running. 70 // check to see if we are already running.
73 if(true == status){ 71 if(true == status){
74 emit (updateMessage("Unable to start interface,\n already started")); 72 emit (updateMessage("Unable to start interface,\n already started"));
75 return; 73 return;
76 } 74 }
77 75
78 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 76 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
79 // See if it was successfull... 77 // See if it was successfull...
80 if(ret != 0){ 78 if(ret != 0){
81 emit (updateMessage("Starting interface failed")); 79 emit (updateMessage("Starting interface failed"));
82 return; 80 return;
83 } 81 }
84 82
85 status = true; 83 status = true;
86 refresh(); 84 refresh();
87 emit (updateMessage("Start successfull")); 85 emit (updateMessage("Start successfull"));
88} 86}
89 87
90/** 88/**
91 * Try to stop the interface. 89 * Try to stop the interface.
92 */ 90 */
93void Interface::stop(){ 91void Interface::stop(){
94 // check to see if we are already stopped. 92 // check to see if we are already stopped.
95 if(false == status){ 93 if(false == status){
96 emit (updateMessage("Unable to stop interface,\n already stopped")); 94 emit (updateMessage("Unable to stop interface,\n already stopped"));
97 return; 95 return;
98 } 96 }
99 97
100 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 98 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
101 if(ret != 0){ 99 if(ret != 0){
102 emit (updateMessage("Stopping interface failed")); 100 emit (updateMessage("Stopping interface failed"));
103 return; 101 return;
104 } 102 }
105 103
106 status = false; 104 status = false;
107 refresh(); 105 refresh();
108 emit (updateMessage("Stop successfull")); 106 emit (updateMessage("Stop successfull"));
109} 107}
110 108
111/** 109/**
112 * Try to restart the interface. 110 * Try to restart the interface.
113 */ 111 */
114void Interface::restart(){ 112void Interface::restart(){
115 stop(); 113 stop();
116 start(); 114 start();
117} 115}
118 116
119/** 117/**
120 * Try to refresh the information about the interface. 118 * Try to refresh the information about the interface.
121 * First call ifconfig, then check the dhcp-info file 119 * First call ifconfig, then check the dhcp-info file
122 * @return bool true if successfull. 120 * @return bool true if successfull.
123 */ 121 */
124bool Interface::refresh(){ 122bool Interface::refresh(){
125 // See if we are up. 123 // See if we are up.
126 if(status == false){ 124 if(status == false){
127 macAddress = ""; 125 macAddress = "";
128 ip = "0.0.0.0"; 126 ip = "0.0.0.0";
129 subnetMask = "0.0.0.0"; 127 subnetMask = "0.0.0.0";
130 broadcast = ""; 128 broadcast = "";
131 dhcp = false; 129 dhcp = false;
132 dhcpServerIp = ""; 130 dhcpServerIp = "";
133 leaseObtained = ""; 131 leaseObtained = "";
134 leaseExpires = ""; 132 leaseExpires = "";
135 emit(updateInterface(this)); 133 emit(updateInterface(this));
136 return true; 134 return true;
137 } 135 }
138 136
139 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 137 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
140 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 138 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
141 if(ret != 0){ 139 if(ret != 0){
142 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 140 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
143 return false; 141 return false;
144 } 142 }
145 143
146 QFile file(fileName); 144 QFile file(fileName);
147 if (!file.open(IO_ReadOnly)){ 145 if (!file.open(IO_ReadOnly)){
148 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 146 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
149 return false; 147 return false;
150 } 148 }
151 149
152 // Set to the defaults 150 // Set to the defaults
153 macAddress = ""; 151 macAddress = "";
154 ip = "0.0.0.0"; 152 ip = "0.0.0.0";
155 subnetMask = "0.0.0.0"; 153 subnetMask = "0.0.0.0";
156 broadcast = ""; 154 broadcast = "";
157 155
158 QTextStream stream( &file ); 156 QTextStream stream( &file );
159 QString line; 157 QString line;
160 while ( !stream.eof() ) { 158 while ( !stream.eof() ) {
161 line = stream.readLine(); 159 line = stream.readLine();
162 if(line.contains("HWaddr")){ 160 if(line.contains("HWaddr")){
163 int mac = line.find("HWaddr"); 161 int mac = line.find("HWaddr");
164 macAddress = line.mid(mac+7, line.length()); 162 macAddress = line.mid(mac+7, line.length());
165 } 163 }
166 if(line.contains("inet addr")){ 164 if(line.contains("inet addr")){
167 int ipl = line.find("inet addr"); 165 int ipl = line.find("inet addr");
168 int space = line.find(" ", ipl+10); 166 int space = line.find(" ", ipl+10);
169 ip = line.mid(ipl+10, space-ipl-10); 167 ip = line.mid(ipl+10, space-ipl-10);
170 } 168 }
171 if(line.contains("Mask")){ 169 if(line.contains("Mask")){
172 int mask = line.find("Mask"); 170 int mask = line.find("Mask");
173 subnetMask = line.mid(mask+5, line.length()); 171 subnetMask = line.mid(mask+5, line.length());
174 } 172 }
175 if(line.contains("Bcast")){ 173 if(line.contains("Bcast")){
176 int mask = line.find("Bcast"); 174 int mask = line.find("Bcast");
177 int space = line.find(" ", mask+6); 175 int space = line.find(" ", mask+6);
178 broadcast = line.mid(mask+6, space-mask-6); 176 broadcast = line.mid(mask+6, space-mask-6);
179 } 177 }
180 } 178 }
181 file.close(); 179 file.close();
182 QFile::remove(fileName); 180 QFile::remove(fileName);
183 181
184 // DHCP TESTING 182 // DHCP TESTING
185 // reset DHCP info 183 // reset DHCP info
186 dhcpServerIp = ""; 184 dhcpServerIp = "";
187 leaseObtained = ""; 185 leaseObtained = "";
188 leaseExpires = ""; 186 leaseExpires = "";
189 dhcp = false; 187 dhcp = false;
190 188
191 QString dhcpDirectory(DHCP_INFO_DIR); 189 QString dhcpDirectory(DHCP_INFO_DIR);
192 QDir d(dhcpDirectory); 190 QDir d(dhcpDirectory);
193 if(!d.exists(dhcpDirectory)) 191 if(!d.exists(dhcpDirectory))
194 dhcpDirectory = "/var/run"; 192 dhcpDirectory = "/var/run";
195 193
196 // See if we have 194 // See if we have
197 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 195 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
198 // If there is no DHCP information then exit now with no errors. 196 // If there is no DHCP information then exit now with no errors.
199 if(!QFile::exists(dhcpFile)){ 197 if(!QFile::exists(dhcpFile)){
200 emit(updateInterface(this)); 198 emit(updateInterface(this));
201 return true; 199 return true;
202 } 200 }
203 201
204 file.setName(dhcpFile); 202 file.setName(dhcpFile);
205 if (!file.open(IO_ReadOnly)){ 203 if (!file.open(IO_ReadOnly)){
206 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 204 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
207 return false; 205 return false;
208 } 206 }
209 207
210 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 208 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
211 int leaseTime = 0; 209 int leaseTime = 0;
212 int renewalTime = 0; 210 int renewalTime = 0;
213 211
214 stream.setDevice( &file ); 212 stream.setDevice( &file );
215 while ( !stream.eof() ) { 213 while ( !stream.eof() ) {
216 line = stream.readLine(); 214 line = stream.readLine();
217 if(line.contains("DHCPSIADDR=")) 215 if(line.contains("DHCPSIADDR="))
218 dhcpServerIp = line.mid(11, line.length()); 216 dhcpServerIp = line.mid(11, line.length());
219 if(line.contains("LEASETIME=")) 217 if(line.contains("LEASETIME="))
220 leaseTime = line.mid(10, line.length()).toInt(); 218 leaseTime = line.mid(10, line.length()).toInt();
221 if(line.contains("RENEWALTIME=")) 219 if(line.contains("RENEWALTIME="))
222 renewalTime = line.mid(12, line.length()).toInt(); 220 renewalTime = line.mid(12, line.length()).toInt();
223 } 221 }
224 file.close(); 222 file.close();
225 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 223 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
226 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 224 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
227 225
228 // Get the pid of the deamond 226 // Get the pid of the deamond
229 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 227 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
230 file.setName(dhcpFile); 228 file.setName(dhcpFile);
231 if (!file.open(IO_ReadOnly)){ 229 if (!file.open(IO_ReadOnly)){
232 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 230 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
233 return false; 231 return false;
234 } 232 }
235 233
236 int pid = -1; 234 int pid = -1;
237 stream.setDevice( &file ); 235 stream.setDevice( &file );
238 while ( !stream.eof() ) { 236 while ( !stream.eof() ) {
239 line = stream.readLine(); 237 line = stream.readLine();
240 pid = line.toInt(); 238 pid = line.toInt();
241 } 239 }
242 file.close(); 240 file.close();
243 241
244 if( pid == -1){ 242 if( pid == -1){
245 qDebug("Interface: Could not get pid of dhcpc deamon."); 243 qDebug("Interface: Could not get pid of dhcpc deamon.");
246 return false; 244 return false;
247 } 245 }
248 246
249 // Get the start running time of the deamon 247 // Get the start running time of the deamon
250 fileName = (QString("/proc/%1/stat").arg(pid)); 248 fileName = (QString("/proc/%1/stat").arg(pid));
251 file.setName(fileName); 249 file.setName(fileName);
252 stream.setDevice( &file ); 250 stream.setDevice( &file );
253 if (!file.open(IO_ReadOnly)){ 251 if (!file.open(IO_ReadOnly)){
254 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 252 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
255 return false; 253 return false;
256 } 254 }
257 while ( !stream.eof() ) { 255 while ( !stream.eof() ) {
258 line = stream.readLine(); 256 line = stream.readLine();
259 } 257 }
260 file.close(); 258 file.close();
261 long time = 0; 259 long time = 0;
262 // Grab the start time 260 // Grab the start time
263 // pid com state ppid pgrp session tty_nr tpgid flags 261 // pid com state ppid pgrp session tty_nr tpgid flags
264 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 262 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
265 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 263 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
266 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 264 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
267 // nice 0 itrealvalue starttime 265 // nice 0 itrealvalue starttime
268 "%*d %*d %*d %lu", (long*) &time); 266 "%*d %*d %*d %lu", (long*) &time);
269 time = time/100; 267 time = time/100;
270 268
271 QDateTime datetime(QDateTime::currentDateTime()); 269 QDateTime datetime(QDateTime::currentDateTime());
272 270
273 // Get the uptime of the computer. 271 // Get the uptime of the computer.
274 QFile f("/proc/uptime"); 272 QFile f("/proc/uptime");
275 if ( f.open(IO_ReadOnly) ) { // file opened successfully 273 if ( f.open(IO_ReadOnly) ) { // file opened successfully
276 QTextStream t( &f ); // use a text stream 274 QTextStream t( &f ); // use a text stream
277 int sec = 0; 275 int sec = 0;
278 t >> sec; 276 t >> sec;
279 datetime = datetime.addSecs((-1*sec)); 277 datetime = datetime.addSecs((-1*sec));
280 f.close(); 278 f.close();
281 } 279 }
282 else{ 280 else{
283 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 281 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
284 return false; 282 return false;
285 } 283 }
286 284
287 datetime = datetime.addSecs(time); 285 datetime = datetime.addSecs(time);
288 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 286 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
289 287
290 // Calculate the start and renew times 288 // Calculate the start and renew times
291 leaseObtained= datetime.toString(); 289 leaseObtained= datetime.toString();
292 290
293 // Calculate the start and renew times 291 // Calculate the start and renew times
294 datetime = datetime.addSecs(leaseTime); 292 datetime = datetime.addSecs(leaseTime);
295 leaseExpires = datetime.toString(); 293 leaseExpires = datetime.toString();
296 294
297 dhcp = true; 295 dhcp = true;
298 296
299 emit(updateInterface(this)); 297 emit(updateInterface(this));
300 return true; 298 return true;
301} 299}
302 300
303// interface.cpp 301// interface.cpp
304 302
diff --git a/noncore/settings/networksettings/opie-networksettings.control b/noncore/settings/networksettings/opie-networksettings.control
index 8fa40c7..7635cd1 100644
--- a/noncore/settings/networksettings/opie-networksettings.control
+++ b/noncore/settings/networksettings/opie-networksettings.control
@@ -1,8 +1,9 @@
1Files: bin/networksettings apps/Settings/networksettings.desktop plugins/networksettings/* pics/networksettings/* pics/Network/PPPConnect.png $QTDIR/lib/libinterfaces.so.1.0.0 $QTDIR/lib/libinterfaces.so.1.0 $QTDIR/lib/libinterfaces.so.1 root/usr/bin/changedns bin/getprofile 1Files: bin/networksettings apps/Settings/networksettings.desktop plugins/networksettings/* pics/networksettings/* pics/Network/PPPConnect.png $QTDIR/lib/libinterfaces.so.1.0.0 $QTDIR/lib/libinterfaces.so.1.0 $QTDIR/lib/libinterfaces.so.1 root/usr/bin/changedns bin/getprofile
2Priority: optional 2Priority: optional
3Section: opie/settings 3Section: opie/settings
4Maintainer: Ben Meyer <meyerb@sharpsec.com> 4Maintainer: Ben Meyer <meyerb@sharpsec.com>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION)
8Description: Network settings 8Description: Network settings.
9Replaces: opie-networksetup