summaryrefslogtreecommitdiff
authortille <tille>2003-05-22 15:08:21 (UTC)
committer tille <tille>2003-05-22 15:08:21 (UTC)
commit273857932d4d4af9bf78bfca92f2986163e5f4f6 (patch) (unidiff)
treefd809cda2eefdbb3d39567f956513511cb43dd3d
parent4364269ddceef65bf06f475e2dcface882d37ed4 (diff)
downloadopie-273857932d4d4af9bf78bfca92f2986163e5f4f6.zip
opie-273857932d4d4af9bf78bfca92f2986163e5f4f6.tar.gz
opie-273857932d4d4af9bf78bfca92f2986163e5f4f6.tar.bz2
finds the modem of my laptop now,
thanks to the kppp team
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/devices.h57
-rw-r--r--noncore/settings/networksettings/ppp/kpppconfig.h134
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp671
-rw-r--r--noncore/settings/networksettings/ppp/modem.h98
-rw-r--r--noncore/settings/networksettings/ppp/modeminfo.cpp294
-rw-r--r--noncore/settings/networksettings/ppp/modeminfo.h89
-rw-r--r--noncore/settings/networksettings/ppp/ppp.pro9
-rw-r--r--noncore/settings/networksettings/ppp/ppp.ui78
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp1229
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.h465
-rw-r--r--noncore/settings/networksettings/ppp/pppimp.cpp23
-rw-r--r--noncore/settings/networksettings/ppp/pppimp.h4
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.cpp18
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.h2
-rw-r--r--noncore/settings/networksettings/ppp/runtests.cpp279
-rw-r--r--noncore/settings/networksettings/ppp/runtests.h47
16 files changed, 3473 insertions, 24 deletions
diff --git a/noncore/settings/networksettings/ppp/devices.h b/noncore/settings/networksettings/ppp/devices.h
new file mode 100644
index 0000000..fb57128
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/devices.h
@@ -0,0 +1,57 @@
1#ifndef _DEVICES_H_
2#define _DEVICES_H_
3
4#include "kpppconfig.h"
5
6static const char *devices[] = {
7#ifdef __FreeBSD__
8 "/dev/cuaa0",
9 "/dev/cuaa1",
10 "/dev/cuaa2",
11 "/dev/cuaa3",
12 "/dev/cuaa4",
13#elif defined(__NetBSD__)
14 "/dev/tty00", /* "normal" modem lines */
15 "/dev/tty01",
16 "/dev/tty02",
17 "/dev/tty03",
18 "/dev/dty00", /* Dial out devices */
19 "/dev/dty01",
20 "/dev/dty02",
21 "/dev/dty03",
22 "/dev/ttyU0", /* USB stuff modems */
23 "/dev/ttyU1",
24 "/dev/ttyU2",
25 "/dev/ttyU3",
26 "/dev/dtyU0", /* USB stuff, too (dial out device) */
27 "/dev/dtyU1",
28 "/dev/dtyU2",
29 "/dev/dtyU3",
30#elif defined (__linux__)
31 "/dev/modem",
32 "/dev/ttyS0",
33 "/dev/ttyS1",
34 "/dev/ttyS2",
35 "/dev/ttyS3",
36#ifdef ISDNSUPPORT
37 "/dev/ttyI0",
38 "/dev/ttyI1",
39 "/dev/ttyI2",
40 "/dev/ttyI3",
41#endif
42 "/dev/usb/ttyACM0", /* USB stuff modems */
43 "/dev/usb/ttyACM1",
44 "/dev/usb/ttyACM2",
45 "/dev/usb/ttyACM3",
46#elif defined(__svr4__)
47 "/dev/cua/a",
48 "/dev/cua/b",
49 "/dev/ttya",
50 "/dev/ttyb",
51#endif
52 0};
53
54// default device number from the list above
55const int DEV_DEFAULT = 0;
56
57#endif
diff --git a/noncore/settings/networksettings/ppp/kpppconfig.h b/noncore/settings/networksettings/ppp/kpppconfig.h
new file mode 100644
index 0000000..cff2aac
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/kpppconfig.h
@@ -0,0 +1,134 @@
1/* -*- C++ -*-
2 * kPPP: A pppd front end for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25
26#ifndef _KPPPCONFIG_H_
27#define _KPPPCONFIG_H_
28
29#if defined(__svr4__)
30#define STREAMS
31#define _XOPEN_SOURCE 1
32#define _XOPEN_SOURCE_EXTENDED 1
33#define __EXTENSIONS__
34#endif
35
36//#include <config.h>
37
38#ifdef HAVE_SYS_PARAM_H
39#include <sys/param.h>
40#endif
41
42// Warning: If you fiddle with the following directories you have
43// to adjust make_directories() in main.cpp()
44
45// file used for PAP authetication purposes
46#define PAP_AUTH_FILE "/etc/ppp/pap-secrets"
47
48// file used for CHAP authetication purposes
49#define CHAP_AUTH_FILE "/etc/ppp/chap-secrets"
50
51// Define the default modem response timeout
52#define MODEM_TIMEOUT 60
53
54// Define the default modem tone duration (ATS11=)
55#define MODEM_TONEDURATION 70
56
57// Define the default time for pppd to get the interface up
58#define PPPD_TIMEOUT 30
59
60// Define the default time to wait after a busy signal before redialing
61#define BUSY_WAIT 0
62
63
64
65// Every PPP_STATS_INTERVAL milli seconds kppp will read
66// and display the ppp statistics IF the stats window
67// is visible. If the stats window is not visible
68// the stats are not taken.
69// 200 milli secs is 5 times per second and results in
70// 0 load on my machine. Play with this parameter if
71// you feel like it.
72
73#define PPP_STATS_INTERVAL 200
74// comment this out to get some more debugging info
75/*
76#define MY_DEBUG
77*/
78
79// Define the maximum number of accounts
80#define MAX_ACCOUNTS 100
81
82// Define the mamimum number of script entries
83#define MAX_SCRIPT_ENTRIES 20
84
85// Define the maximun number of DNS entries
86#define MAX_DNS_ENTRIES 5
87
88// Maximum size of the command executing pppd
89const unsigned int MAX_CMDLEN = 2024;
90
91// Define the maximum number of arguments passed to the pppd daemon
92#define MAX_PPPD_ARGUMENTS 20
93
94// Define the maximun number of lines of /etc/resolv.conf
95#define MAX_RESOLVCONF_LINES 128
96
97// Directory for modem lock files (Needed by mgetty users)
98#ifdef __linux__
99# define LOCK_DIR "/var/lock"
100#else /* linux */
101# ifdef BSD
102 # defineLOCK_DIR "/var/spool/lock"
103# else /* BSD */
104 # defineLOCK_DIR "/var/spool/locks"
105# endif /* BSD */
106#endif /* linux */
107
108#define DEVNULL "/dev/null"
109
110// search path for pppd binary
111#define PPPDSEARCHPATH "/sbin:/usr/sbin:/usr/local/sbin:/usr/bin:/usr/local/bin"
112
113// name of the pppd binary
114#define PPPDNAME "pppd"
115
116// support for internal ISDN cards and modem emulation
117#ifdef __linux__
118#define ISDNSUPPORT
119#endif
120
121#if defined(__linux__) || defined(BSD)
122#define PPP_PID_DIR "/var/run/"
123#else
124#define PPP_PID_DIR "/etc/ppp/"
125#endif
126
127// defined in opener.cpp
128extern const char * const kppp_syslog[];
129
130#ifdef _XPG4_2
131#define __xnet_connect connect
132#endif
133
134#endif
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
new file mode 100644
index 0000000..e9e3f06
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -0,0 +1,671 @@
1/*
2 * kPPP: A pppd Front End for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * This file was added by Harri Porten <porten@tu-harburg.de>
10 *
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <errno.h>
28#include <stdlib.h>
29#include <fcntl.h>
30#include <signal.h>
31#include <sys/ioctl.h>
32#include <setjmp.h>
33#include <qregexp.h>
34#include <assert.h>
35
36#include "modem.h"
37#include "pppdata.h"
38//#include "requester.h"
39//#include <klocale.h>
40#define i18n QObject::tr
41#define qError qDebug
42//#include <kdebug.h>
43//#include <config.h>
44
45#define MY_ASSERT(x) if (!(x)) { \
46 qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
47 exit(1); }
48
49
50static sigjmp_buf jmp_buffer;
51
52Modem *Modem::modem = 0;
53
54Modem::Modem() :
55 modemfd(-1),
56 sn(0L),
57 data_mode(false),
58 modem_is_locked(false)
59{
60 lockfile[0] = '\0';
61 device = "/dev/modem";
62 assert(modem==0);
63 modem = this;
64}
65
66
67Modem::~Modem() {
68 modem = 0;
69}
70
71
72speed_t Modem::modemspeed() {
73 // convert the string modem speed int the gpppdata object to a t_speed type
74 // to set the modem. The constants here should all be ifdef'd because
75 // other systems may not have them
76 int i = gpppdata.speed().toInt()/100;
77
78 switch(i) {
79 case 24:
80 return B2400;
81 break;
82 case 96:
83 return B9600;
84 break;
85 case 192:
86 return B19200;
87 break;
88 case 384:
89 return B38400;
90 break;
91#ifdef B57600
92 case 576:
93 return B57600;
94 break;
95#endif
96
97#ifdef B115200
98 case 1152:
99 return B115200;
100 break;
101#endif
102
103#ifdef B230400
104 case 2304:
105 return B230400;
106 break;
107#endif
108
109#ifdef B460800
110 case 4608:
111 return B460800;
112 break;
113#endif
114
115 default:
116 return B38400;
117 break;
118 }
119}
120
121bool Modem::opentty() {
122 // int flags;
123
124//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
125 close(modemfd);
126// device = "/dev/modem";//deviceByIndex(request.modem.deviceNum);
127 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
128 qDebug("error opening modem device !");
129 errmsg = i18n("Unable to open modem.");
130 return false;
131 }
132//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
133//}
134
135#if 0
136 if(gpppdata.UseCDLine()) {
137 if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
138 errmsg = i18n("Unable to detect state of CD line.");
139 ::close(modemfd);
140 modemfd = -1;
141 return false;
142 }
143 if ((flags&TIOCM_CD) == 0) {
144 errmsg = i18n("The modem is not ready.");
145 ::close(modemfd);
146 modemfd = -1;
147 return false;
148 }
149 }
150#endif
151
152 tcdrain (modemfd);
153 tcflush (modemfd, TCIOFLUSH);
154
155 if(tcgetattr(modemfd, &tty) < 0){
156 // this helps in some cases
157 tcsendbreak(modemfd, 0);
158 sleep(1);
159 if(tcgetattr(modemfd, &tty) < 0){
160 errmsg = i18n("The modem is busy.");
161 ::close(modemfd);
162 modemfd = -1;
163 return false;
164 }
165 }
166
167 memset(&initial_tty,'\0',sizeof(initial_tty));
168
169 initial_tty = tty;
170
171 tty.c_cc[VMIN] = 0; // nonblocking
172 tty.c_cc[VTIME] = 0;
173 tty.c_oflag = 0;
174 tty.c_lflag = 0;
175
176 tty.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
177 tty.c_cflag |= CS8 | CREAD;
178 tty.c_cflag |= CLOCAL; // ignore modem status lines
179 tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ;
180 tty.c_lflag &= ~ICANON; // non-canonical mode
181 tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE);
182
183
184 if(gpppdata.flowcontrol() != "None") {
185 if(gpppdata.flowcontrol() == "CRTSCTS") {
186 tty.c_cflag |= CRTSCTS;
187 }
188 else {
189 tty.c_iflag |= IXON | IXOFF;
190 tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
191 tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
192 }
193 }
194 else {
195 tty.c_cflag &= ~CRTSCTS;
196 tty.c_iflag &= ~(IXON | IXOFF);
197 }
198
199 cfsetospeed(&tty, modemspeed());
200 cfsetispeed(&tty, modemspeed());
201
202 tcdrain(modemfd);
203
204 if(tcsetattr(modemfd, TCSANOW, &tty) < 0){
205 errmsg = i18n("The modem is busy.");
206 ::close(modemfd);
207 modemfd=-1;
208 return false;
209 }
210
211 errmsg = i18n("Modem Ready.");
212 return true;
213}
214
215
216bool Modem::closetty() {
217 if(modemfd >=0 ) {
218 stop();
219 /* discard data not read or transmitted */
220 tcflush(modemfd, TCIOFLUSH);
221
222 if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){
223 errmsg = i18n("Can't restore tty settings: tcsetattr()\n");
224 ::close(modemfd);
225 modemfd = -1;
226 return false;
227 }
228 ::close(modemfd);
229 modemfd = -1;
230 }
231
232 return true;
233}
234
235
236void Modem::readtty(int) {
237 char buffer[200];
238 unsigned char c;
239 int len;
240
241 // read data in chunks of up to 200 bytes
242 if((len = ::read(modemfd, buffer, 200)) > 0) {
243 // split buffer into single characters for further processing
244 for(int i = 0; i < len; i++) {
245 c = buffer[i] & 0x7F;
246 emit charWaiting(c);
247 }
248 }
249}
250
251
252void Modem::notify(const QObject *receiver, const char *member) {
253 connect(this, SIGNAL(charWaiting(unsigned char)), receiver, member);
254 startNotifier();
255}
256
257
258void Modem::stop() {
259 disconnect(SIGNAL(charWaiting(unsigned char)));
260 stopNotifier();
261}
262
263
264void Modem::startNotifier() {
265 if(modemfd >= 0) {
266 if(sn == 0) {
267 sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this);
268 connect(sn, SIGNAL(activated(int)), SLOT(readtty(int)));
269 qDebug("QSocketNotifier started!");
270 } else {
271 qDebug("QSocketNotifier re-enabled!");
272 sn->setEnabled(true);
273 }
274 }
275}
276
277
278void Modem::stopNotifier() {
279 if(sn != 0) {
280 sn->setEnabled(false);
281 disconnect(sn);
282 delete sn;
283 sn = 0;
284 qDebug( "QSocketNotifier stopped!" );
285 }
286}
287
288
289void Modem::flush() {
290 char c;
291 while(read(modemfd, &c, 1) == 1);
292}
293
294
295bool Modem::writeChar(unsigned char c) {
296 int s;
297 do {
298 s = write(modemfd, &c, 1);
299 if (s < 0) {
300 qError( "write() in Modem::writeChar failed" );
301 return false;
302 }
303 } while(s == 0);
304
305 return true;
306}
307
308
309bool Modem::writeLine(const char *buf) {
310 int len = strlen(buf);
311 char *b = new char[len+2];
312 memcpy(b, buf, len);
313 // different modems seem to need different line terminations
314 QString term = gpppdata.enter();
315 if(term == "LF")
316 b[len++]='\n';
317 else if(term == "CR")
318 b[len++]='\r';
319 else if(term == "CR/LF") {
320 b[len++]='\r';
321 b[len++]='\n';
322 }
323 int l = len;
324 while(l) {
325 int wr = write(modemfd, &b[len-l], l);
326 if(wr < 0) {
327 // TODO do something meaningful with the error code (or ignore it
328 qError( "write() in Modem::writeLine failed" );
329 delete[] b;
330 return false;
331 }
332 l -= wr;
333 }
334 delete[] b;
335 return true;
336}
337
338
339bool Modem::hangup() {
340 // this should really get the modem to hang up and go into command mode
341 // If anyone sees a fault in the following please let me know, since
342 // this is probably the most imporant snippet of code in the whole of
343 // kppp. If people complain about kppp being stuck, this piece of code
344 // is most likely the reason.
345 struct termios temptty;
346
347 if(modemfd >= 0) {
348
349 // is this Escape & HangupStr stuff really necessary ? (Harri)
350
351 if (data_mode) escape_to_command_mode();
352
353 // Then hangup command
354 writeLine(gpppdata.modemHangupStr().local8Bit());
355
356 usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 sec
357
358#ifndef DEBUG_WO_DIALING
359 if (sigsetjmp(jmp_buffer, 1) == 0) {
360 // set alarm in case tcsendbreak() hangs
361 signal(SIGALRM, alarm_handler);
362 alarm(2);
363
364 tcsendbreak(modemfd, 0);
365
366 alarm(0);
367 signal(SIGALRM, SIG_IGN);
368 } else {
369 // we reach this point if the alarm handler got called
370 closetty();
371 close(modemfd);
372 modemfd = -1;
373 errmsg = i18n("The modem does not respond.");
374 return false;
375 }
376
377#ifndef __svr4__ // drops DTR but doesn't set it afterwards again. not good for init.
378 tcgetattr(modemfd, &temptty);
379 cfsetospeed(&temptty, B0);
380 cfsetispeed(&temptty, B0);
381 tcsetattr(modemfd, TCSAFLUSH, &temptty);
382#else
383 int modemstat;
384 ioctl(modemfd, TIOCMGET, &modemstat);
385 modemstat &= ~TIOCM_DTR;
386 ioctl(modemfd, TIOCMSET, &modemstat);
387 ioctl(modemfd, TIOCMGET, &modemstat);
388 modemstat |= TIOCM_DTR;
389 ioctl(modemfd, TIOCMSET, &modemstat);
390#endif
391
392 usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 secs
393
394 cfsetospeed(&temptty, modemspeed());
395 cfsetispeed(&temptty, modemspeed());
396 tcsetattr(modemfd, TCSAFLUSH, &temptty);
397#endif
398 return true;
399 } else
400 return false;
401}
402
403
404void Modem::escape_to_command_mode() {
405 // Send Properly bracketed escape code to put the modem back into command state.
406 // A modem will accept AT commands only when it is in command state.
407 // When a modem sends the host the CONNECT string, that signals
408 // that the modem is now in the connect state (no long accepts AT commands.)
409 // Need to send properly timed escape sequence to put modem in command state.
410 // Escape codes and guard times are controlled by S2 and S12 values.
411 //
412 tcflush(modemfd, TCIOFLUSH);
413
414 // +3 because quiet time must be greater than guard time.
415 usleep((gpppdata.modemEscapeGuardTime()+3)*20000);
416 QCString tmp = gpppdata.modemEscapeStr().local8Bit();
417 write(modemfd, tmp.data(), tmp.length());
418 tcflush(modemfd, TCIOFLUSH);
419 usleep((gpppdata.modemEscapeGuardTime()+3)*20000);
420
421 data_mode = false;
422}
423
424
425const QString Modem::modemMessage() {
426 return errmsg;
427}
428
429
430QString Modem::parseModemSpeed(const QString &s) {
431 // this is a small (and bad) parser for modem speeds
432 int rx = -1;
433 int tx = -1;
434 int i;
435 QString result;
436
437 qDebug( "Modem reported result string: %s", s.latin1());
438
439 const int RXMAX = 7;
440 const int TXMAX = 2;
441 QRegExp rrx[RXMAX] = {
442 QRegExp("[0-9]+[:/ ]RX", false),
443 QRegExp("[0-9]+RX", false),
444 QRegExp("[/: -][0-9]+[/: ]", false),
445 QRegExp("[/: -][0-9]+$", false),
446 QRegExp("CARRIER [^0-9]*[0-9]+", false),
447 QRegExp("CONNECT [^0-9]*[0-9]+", false),
448 QRegExp("[0-9]+") // panic mode
449 };
450
451 QRegExp trx[TXMAX] = {
452 QRegExp("[0-9]+[:/ ]TX", false),
453 QRegExp("[0-9]+TX", false)
454 };
455
456 for(i = 0; i < RXMAX; i++) {
457 int len, idx, result;
458 if((idx = rrx[i].match(s,0,&len)) > -1) {
459// if((idx = rrx[i].search(s)) > -1) {
460 // len = rrx[i].matchedLength();
461
462 //
463 // rrx[i] has been matched, idx contains the start of the match
464 // and len contains how long the match is. Extract the match.
465 //
466 QString sub = s.mid(idx, len);
467
468 //
469 // Now extract the digits only from the match, which will
470 // then be converted to an int.
471 //
472 if ((idx = rrx[RXMAX-1].match( sub,0,&len )) > -1) {
473// if ((idx = rrx[RXMAX-1].search( sub )) > -1) {
474// len = rrx[RXMAX-1].matchedLength();
475 sub = sub.mid(idx, len);
476 result = sub.toInt();
477 if(result > 0) {
478 rx = result;
479 break;
480 }
481 }
482 }
483 }
484
485 for(i = 0; i < TXMAX; i++) {
486 int len, idx, result;
487 if((idx = trx[i].match(s,0,&len)) > -1) {
488// if((idx = trx[i].search(s)) > -1) {
489// len = trx[i].matchedLength();
490
491 //
492 // trx[i] has been matched, idx contains the start of the match
493 // and len contains how long the match is. Extract the match.
494 //
495 QString sub = s.mid(idx, len);
496
497 //
498 // Now extract the digits only from the match, which will then
499 // be converted to an int.
500 //
501 if((idx = rrx[RXMAX-1].match(sub,0,&len)) > -1) {
502// if((idx = rrx[RXMAX-1].search(sub)) > -1) {
503// len = rrx[RXMAX-1].matchedLength();
504 sub = sub.mid(idx, len);
505 result = sub.toInt();
506 if(result > 0) {
507 tx = result;
508 break;
509 }
510 }
511 }
512 }
513
514 if(rx == -1 && tx == -1)
515 result = i18n("Unknown speed");
516 else if(tx == -1)
517 result.setNum(rx);
518 else if(rx == -1) // should not happen
519 result.setNum(tx);
520 else
521 result.sprintf("%d/%d", rx, tx);
522
523 qDebug( "The parsed result is: %s", result.latin1());
524
525 return result;
526}
527
528
529// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
530// a lock file can't be created ( permission problem )
531int Modem::lockdevice() {
532 int fd;
533 char newlock[80]=""; // safe
534
535 if(!gpppdata.modemLockFile()) {
536 qDebug("The user doesn't want a lockfile.");
537 return 0;
538 }
539
540 if (modem_is_locked)
541 return 1;
542
543 QString lockfile = LOCK_DIR"/LCK..";
544 lockfile += gpppdata.modemDevice().mid(5); // append everything after /dev/
545
546 if(access(QFile::encodeName(lockfile), F_OK) == 0) {
547// if ((fd = Requester::rq->
548if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
549 // Mario: it's not necessary to read more than lets say 32 bytes. If
550 // file has more than 32 bytes, skip the rest
551 char oldlock[33]; // safe
552 int sz = read(fd, &oldlock, 32);
553 close (fd);
554 if (sz <= 0)
555 return 1;
556 oldlock[sz] = '\0';
557
558 qDebug( "Device is locked by: %s", oldlock);
559
560 int oldpid;
561 int match = sscanf(oldlock, "%d", &oldpid);
562
563 // found a pid in lockfile ?
564 if (match < 1 || oldpid <= 0)
565 return 1;
566
567 // check if process exists
568 if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH)
569 return 1;
570
571 qDebug( "lockfile is stale" );
572 }
573 }
574
575 fd = openLockfile(gpppdata.modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
576 if(fd >= 0) {
577 sprintf(newlock,"%010d\n", getpid());
578 qDebug("Locking Device: %s", newlock);
579
580 write(fd, newlock, strlen(newlock));
581 close(fd);
582 modem_is_locked=true;
583
584 return 0;
585 }
586
587 return -1;
588
589}
590
591
592// UnLock modem device
593void Modem::unlockdevice() {
594 if (modem_is_locked) {
595 qDebug( "UnLocking Modem Device" );
596 close(modemfd);
597 modemfd = -1;
598 unlink(lockfile);
599 lockfile[0] = '\0';
600 modem_is_locked=false;
601 }
602}
603
604int Modem::openLockfile( QString lockfile, int flags)
605{
606 int fd;
607 int mode;
608 flags = O_RDONLY;
609 if(flags == O_WRONLY|O_TRUNC|O_CREAT)
610 mode = 0644;
611 else
612 mode = 0;
613
614 lockfile = LOCK_DIR;
615 lockfile += "/LCK..";
616 lockfile += device.right( device.length() - device.findRev("/") -1 );
617 qDebug("lockfile >%s<",lockfile.latin1());
618 // TODO:
619 // struct stat st;
620 // if(stat(lockfile.data(), &st) == -1) {
621 // if(errno == EBADF)
622 // return -1;
623 // } else {
624 // // make sure that this is a regular file
625 // if(!S_ISREG(st.st_mode))
626 // return -1;
627 // }
628 if ((fd = open(lockfile, flags, mode)) == -1) {
629 qDebug("error opening lockfile!");
630 lockfile = QString::null;
631 fd = open(DEVNULL, O_RDONLY);
632 } else
633 fchown(fd, 0, 0);
634 return fd;
635}
636
637
638
639void alarm_handler(int) {
640 // fprintf(stderr, "alarm_handler(): Received SIGALRM\n");
641
642 // jump
643 siglongjmp(jmp_buffer, 1);
644}
645
646
647
648const char* pppdPath() {
649 // wasting a few bytes
650 static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)];
651 static char *pppdPath = 0L;
652 char *p;
653
654 if(pppdPath == 0L) {
655 const char *c = PPPDSEARCHPATH;
656 while(*c != '\0') {
657 while(*c == ':')
658 c++;
659 p = buffer;
660 while(*c != '\0' && *c != ':')
661 *p++ = *c++;
662 *p = '\0';
663 strcat(p, "/");
664 strcat(p, PPPDNAME);
665 if(access(buffer, F_OK) == 0)
666 return (pppdPath = buffer);
667 }
668 }
669
670 return pppdPath;
671}
diff --git a/noncore/settings/networksettings/ppp/modem.h b/noncore/settings/networksettings/ppp/modem.h
new file mode 100644
index 0000000..c23524a
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/modem.h
@@ -0,0 +1,98 @@
1/*
2 * kPPP: A pppd Front End for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * This file was added by Harri Porten <porten@tu-harburg.de>
10 *
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#ifndef _MODEM_H_
28#define _MODEM_H_
29
30#include <qdir.h>
31
32#include <sys/types.h>
33#include <termios.h>
34#include <unistd.h>
35
36#include <qsocketnotifier.h>
37
38//#include <config.h>
39
40void alarm_handler(int);
41const char *pppdPath();
42
43class Modem : public QObject {
44 Q_OBJECT
45public:
46 Modem();
47 ~Modem();
48
49 const QString getDevice() {return device;};
50 void setDevice(const QString dev) {device = dev;};
51
52 bool opentty();
53 bool closetty();
54 bool hangup();
55 bool writeChar(unsigned char);
56 bool writeLine(const char *);
57 bool dataMode() const { return data_mode; }
58 void setDataMode(bool set) { data_mode = set; }
59 const QString modemMessage();
60 speed_t modemspeed();
61 static QString parseModemSpeed(const QString &);
62 void notify(const QObject *, const char *);
63 void stop();
64 void flush();
65
66 int lockdevice();
67 void unlockdevice();
68
69public:
70 static Modem *modem;
71
72signals:
73 void charWaiting(unsigned char);
74
75private slots:
76 void startNotifier();
77 void stopNotifier();
78 void readtty(int);
79
80private:
81 void escape_to_command_mode();
82 int openLockfile(QString,int);
83
84private:
85 QString device;
86 QString lockfile;
87 int modemfd;
88 QSocketNotifier *sn;
89 bool data_mode;
90 QString errmsg;
91 struct termios initial_tty;
92 struct termios tty;
93 bool modem_is_locked;
94};
95
96#endif
97
98
diff --git a/noncore/settings/networksettings/ppp/modeminfo.cpp b/noncore/settings/networksettings/ppp/modeminfo.cpp
new file mode 100644
index 0000000..8c81e67
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/modeminfo.cpp
@@ -0,0 +1,294 @@
1/*
2 * kPPP: A front end for pppd for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * This file contributed by: Markus Wuebben, mwuebben@fiwi02.wiwi.uni-tuebingen.de
10 *
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <unistd.h>
28#include <qregexp.h>
29#include <qlayout.h>
30// #include <kwin.h>
31// #include <kmessagebox.h>
32// #include <kapplication.h>
33#include <qmessagebox.h>
34#include <qapplication.h>
35#include "modeminfo.h"
36#include "modem.h"
37//#include <klocale.h>
38#define i18n QObject::tr
39
40ModemTransfer::ModemTransfer(QWidget *parent, const char *name)
41 : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder)
42{
43 setCaption(i18n("ATI Query"));
44// KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
45
46 QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
47
48 progressBar = new QProgressBar(this, "bar");
49 progressBar->setTotalSteps(8);
50
51 statusBar = new QLabel(this,"sBar");
52 statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken);
53 statusBar->setAlignment(AlignCenter);
54
55 // This is a rather complicated case. Since we do not know which
56 // message is the widest in the national language, we'd to
57 // search all these messages. This is a little overkill, so I take
58 // the longest english message, translate it and give it additional
59 // 20 percent space. Hope this is enough.
60 statusBar->setText(i18n("Unable to create modem lock file."));
61 statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10);
62 statusBar->setFixedHeight(statusBar->sizeHint().height() + 4);
63
64 // set original text
65 statusBar->setText(i18n("Looking for modem..."));
66 progressBar->setFixedHeight(statusBar->minimumSize().height());
67 tl->addWidget(progressBar);
68 tl->addWidget(statusBar);
69
70 cancel = new QPushButton(i18n("Cancel"), this);
71 cancel->setFocus();
72 connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton()));
73
74 QHBoxLayout *l1 = new QHBoxLayout;
75 tl->addLayout(l1);
76 l1->addStretch(1);
77 l1->addWidget(cancel);
78
79 setFixedSize(sizeHint());
80
81 step = 0;
82
83 ////////////////////////////////////////////////
84
85 timeout_timer = new QTimer(this);
86 connect(timeout_timer, SIGNAL(timeout()), SLOT(time_out_slot()));
87
88 scripttimer = new QTimer(this);
89 connect(scripttimer, SIGNAL(timeout()), SLOT(do_script()));
90
91 timeout_timer->start(15000,TRUE); // 15 secs single shot
92 QTimer::singleShot(500, this, SLOT(init()));
93
94}
95
96
97void ModemTransfer::ati_done() {
98 scripttimer->stop();
99 timeout_timer->stop();
100 Modem::modem->closetty();
101 Modem::modem->unlockdevice();
102 hide();
103
104 // open the result window
105 ModemInfo *mi = new ModemInfo(this);
106 for(int i = 0; i < NUM_OF_ATI; i++)
107 mi->setAtiString(i, ati_query_strings[i]);
108 mi->exec();
109 delete mi;
110
111 accept();
112}
113
114
115void ModemTransfer::time_out_slot() {
116 timeout_timer->stop();
117 scripttimer->stop();
118
119 QMessageBox::warning(this, tr("Error"), i18n("Modem Query timed out."));
120 reject();
121}
122
123
124void ModemTransfer::init() {
125
126 qApp->processEvents();
127
128 int lock = Modem::modem->lockdevice();
129 if (lock == 1) {
130
131 statusBar->setText(i18n("Modem device is locked."));
132 return;
133 }
134
135 if (lock == -1) {
136
137 statusBar->setText(i18n("Unable to create modem lock file."));
138 return;
139 }
140
141
142 if(Modem::modem->opentty()) {
143 if(Modem::modem->hangup()) {
144 usleep(100000); // wait 0.1 secs
145 Modem::modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ...
146
147 statusBar->setText(i18n("Modem Ready"));
148 qApp->processEvents();
149 usleep(100000); // wait 0.1 secs
150 qApp->processEvents();
151 scripttimer->start(1000); // this one does the ati query
152
153 // clear modem buffer
154 Modem::modem->flush();
155
156 Modem::modem->notify(this, SLOT(readChar(unsigned char)));
157 return;
158 }
159 }
160
161 // opentty() or hangup() failed
162 statusBar->setText(Modem::modem->modemMessage());
163 step = 99; // wait until cancel is pressed
164 Modem::modem->unlockdevice();
165}
166
167
168void ModemTransfer::do_script() {
169 QString msg;
170 QString query;
171
172 switch(step) {
173 case 0:
174 readtty();
175 statusBar->setText("ATI...");
176 progressBar->setProgress( progressBar->progress() + 1);
177 Modem::modem->writeLine("ATI\n");
178 break;
179
180 case 1:
181 case 2:
182 case 3:
183 case 4:
184 case 5:
185 case 6:
186 case 7:
187 readtty();
188 msg.sprintf("ATI %d ...", step);
189 query.sprintf("ATI%d\n", step);
190 statusBar->setText(msg);
191 progressBar->setProgress( progressBar->progress() + 1);
192 Modem::modem->writeLine(query.local8Bit());
193 break;
194
195 default:
196 readtty();
197 ati_done();
198 }
199 step++;
200}
201
202void ModemTransfer::readChar(unsigned char c) {
203 if(readbuffer.length() < 255)
204 readbuffer += c;
205}
206
207void ModemTransfer::readtty() {
208
209 if (step == 0)
210 return;
211
212 readbuffer.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r
213 readbuffer = readbuffer.stripWhiteSpace(); // strip of leading or trailing white
214 // space
215
216 if(step <= NUM_OF_ATI)
217 ati_query_strings[step-1] = readbuffer.copy();
218
219 readbuffer = "";
220}
221
222
223void ModemTransfer::cancelbutton() {
224 scripttimer->stop();
225 Modem::modem->stop();
226 timeout_timer->stop();
227
228 statusBar->setText(i18n("One moment please..."));
229 qApp->processEvents();
230
231 Modem::modem->hangup();
232
233 Modem::modem->closetty();
234 Modem::modem->unlockdevice();
235 reject();
236}
237
238
239void ModemTransfer::closeEvent( QCloseEvent *e ) {
240 cancelbutton();
241 e->accept();
242}
243
244
245ModemInfo::ModemInfo(QWidget *parent, const char* name)
246 : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder)
247{
248 QString label_text;
249
250 setCaption(i18n("Modem Query Results"));
251 // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
252
253 QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
254
255 QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5);
256 tl->addLayout(l1, 1);
257 for(int i = 0 ; i < NUM_OF_ATI ; i++) {
258
259 label_text = "";
260 if ( i == 0)
261 label_text.sprintf("ATI :");
262 else
263 label_text.sprintf("ATI %d:", i );
264
265 ati_label[i] = new QLabel(label_text, this);
266 l1->addWidget(ati_label[i], i, 0);
267
268 ati_label_result[i] = new QLineEdit(this);
269 ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24);
270 l1->addWidget(ati_label_result[i], i, 1);
271 }
272 //tl->addSpacing(1);
273
274 QHBoxLayout *l2 = new QHBoxLayout;
275 QPushButton *ok = new QPushButton(i18n("Close"), this);
276 ok->setDefault(TRUE);
277 ok->setFocus();
278
279 tl->addLayout(l2);
280 l2->addStretch(1);
281
282 connect(ok, SIGNAL(clicked()), SLOT(accept()));
283 l2->addWidget(ok);
284
285 setMinimumSize(sizeHint());
286}
287
288
289void ModemInfo::setAtiString(int i, QString s) {
290 if(i < NUM_OF_ATI)
291 ati_label_result[i]->setText(s);
292}
293
294//#include "modeminfo.moc"
diff --git a/noncore/settings/networksettings/ppp/modeminfo.h b/noncore/settings/networksettings/ppp/modeminfo.h
new file mode 100644
index 0000000..7aa2cc0
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/modeminfo.h
@@ -0,0 +1,89 @@
1/*
2 *
3 * kPPP: A front end for pppd for the KDE project
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997 Bernd Johannes Wuebben
8 * wuebben@math.cornell.edu
9 *
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 */
26
27
28#ifndef _MODEMINFO_H_
29#define _MODEMINFO_H_
30
31#include <qdialog.h>
32#include <qlineedit.h>
33#include <qpushbutton.h>
34#include <qlabel.h>
35#include <qevent.h>
36#include <qtimer.h>
37//#include <kprogress.h>
38#include <qprogressbar.h>
39
40const int NUM_OF_ATI = 8;
41
42
43class ModemTransfer : public QDialog {
44 Q_OBJECT
45public:
46 ModemTransfer(QWidget *parent=0, const char *name=0);
47
48public slots:
49 void init();
50 void readtty();
51 void do_script();
52 void time_out_slot();
53 void cancelbutton();
54 void readChar(unsigned char);
55
56private:
57 void ati_done();
58
59protected:
60 void closeEvent(QCloseEvent *e);
61
62private:
63 int step;
64 QString readbuffer;
65
66 QPushButton *cancel;
67 QProgressBar *progressBar;
68 QLabel *statusBar;
69
70 QTimer *timeout_timer;
71 QTimer *scripttimer;
72 QString ati_query_strings[NUM_OF_ATI];
73};
74
75
76class ModemInfo : public QDialog {
77 Q_OBJECT
78public:
79 ModemInfo(QWidget *parent=0, const char *name=0);
80
81public:
82 void setAtiString(int num, QString s);
83
84private:
85 QLabel *ati_label[NUM_OF_ATI];
86 QLineEdit *ati_label_result[NUM_OF_ATI];
87};
88
89#endif
diff --git a/noncore/settings/networksettings/ppp/ppp.pro b/noncore/settings/networksettings/ppp/ppp.pro
index 0e9e5b8..da32395 100644
--- a/noncore/settings/networksettings/ppp/ppp.pro
+++ b/noncore/settings/networksettings/ppp/ppp.pro
@@ -1,9 +1,10 @@
1#TEMPLATE = app
1TEMPLATE = lib 2TEMPLATE = lib
2CONFIG += qt warn_on release 3#CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 4 CONFIG += qt warn_on debug
4DESTDIR = $(OPIEDIR)/plugins/networksettings 5DESTDIR = $(OPIEDIR)/plugins/networksettings
5 HEADERS = pppimp.h pppmodule.h 6 HEADERS = pppimp.h pppmodule.h devices.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h
6 SOURCES = pppimp.cpp pppmodule.cpp 7 SOURCES = pppimp.cpp pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/ 8 INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/
8 DEPENDPATH+= $(OPIEDIR)/include 9 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe -L../interfaces/ -linterfaces 10LIBS += -lqpe -L../interfaces/ -linterfaces
diff --git a/noncore/settings/networksettings/ppp/ppp.ui b/noncore/settings/networksettings/ppp/ppp.ui
index 56e1621..2fcb419 100644
--- a/noncore/settings/networksettings/ppp/ppp.ui
+++ b/noncore/settings/networksettings/ppp/ppp.ui
@@ -11,11 +11,18 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>277</width> 14 <width>355</width>
15 <height>340</height> 15 <height>418</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>sizePolicy</name>
20 <sizepolicy>
21 <hsizetype>3</hsizetype>
22 <vsizetype>3</vsizetype>
23 </sizepolicy>
24 </property>
25 <property stdset="1">
19 <name>caption</name> 26 <name>caption</name>
20 <string>Dial-up </string> 27 <string>Dial-up </string>
21 </property> 28 </property>
@@ -199,12 +206,48 @@
199 <grid> 206 <grid>
200 <property stdset="1"> 207 <property stdset="1">
201 <name>margin</name> 208 <name>margin</name>
202 <number>6</number> 209 <number>11</number>
203 </property> 210 </property>
204 <property stdset="1"> 211 <property stdset="1">
205 <name>spacing</name> 212 <name>spacing</name>
206 <number>4</number> 213 <number>6</number>
214 </property>
215 <widget row="4" column="2" rowspan="1" colspan="3" >
216 <class>QPushButton</class>
217 <property stdset="1">
218 <name>name</name>
219 <cstring>PushButtonQuery</cstring>
207 </property> 220 </property>
221 <property stdset="1">
222 <name>sizePolicy</name>
223 <sizepolicy>
224 <hsizetype>3</hsizetype>
225 <vsizetype>0</vsizetype>
226 </sizepolicy>
227 </property>
228 <property stdset="1">
229 <name>text</name>
230 <string>Query Modem</string>
231 </property>
232 </widget>
233 <widget row="4" column="1" >
234 <class>QComboBox</class>
235 <property stdset="1">
236 <name>name</name>
237 <cstring>ComboBoxDevice</cstring>
238 </property>
239 </widget>
240 <widget row="4" column="0" >
241 <class>QLabel</class>
242 <property stdset="1">
243 <name>name</name>
244 <cstring>TextLabel1_6</cstring>
245 </property>
246 <property stdset="1">
247 <name>text</name>
248 <string>Device</string>
249 </property>
250 </widget>
208 <widget row="0" column="0" > 251 <widget row="0" column="0" >
209 <class>QLabel</class> 252 <class>QLabel</class>
210 <property stdset="1"> 253 <property stdset="1">
@@ -216,7 +259,7 @@
216 <string>AT-dial</string> 259 <string>AT-dial</string>
217 </property> 260 </property>
218 </widget> 261 </widget>
219 <widget row="0" column="1" rowspan="1" colspan="3" > 262 <widget row="0" column="1" rowspan="1" colspan="4" >
220 <class>QComboBox</class> 263 <class>QComboBox</class>
221 <item> 264 <item>
222 <property> 265 <property>
@@ -238,6 +281,10 @@
238 <name>editable</name> 281 <name>editable</name>
239 <bool>true</bool> 282 <bool>true</bool>
240 </property> 283 </property>
284 <property stdset="1">
285 <name>currentItem</name>
286 <number>0</number>
287 </property>
241 </widget> 288 </widget>
242 <widget row="1" column="0" > 289 <widget row="1" column="0" >
243 <class>QLabel</class> 290 <class>QLabel</class>
@@ -250,7 +297,7 @@
250 <string>Speed</string> 297 <string>Speed</string>
251 </property> 298 </property>
252 </widget> 299 </widget>
253 <widget row="1" column="1" rowspan="1" colspan="3" > 300 <widget row="1" column="1" rowspan="1" colspan="4" >
254 <class>QComboBox</class> 301 <class>QComboBox</class>
255 <item> 302 <item>
256 <property> 303 <property>
@@ -297,7 +344,7 @@
297 <number>5</number> 344 <number>5</number>
298 </property> 345 </property>
299 </widget> 346 </widget>
300 <widget row="3" column="1" > 347 <widget row="3" column="1" rowspan="1" colspan="2" >
301 <class>QSlider</class> 348 <class>QSlider</class>
302 <property stdset="1"> 349 <property stdset="1">
303 <name>name</name> 350 <name>name</name>
@@ -331,7 +378,7 @@
331 <string>Wait time</string> 378 <string>Wait time</string>
332 </property> 379 </property>
333 </widget> 380 </widget>
334 <widget row="3" column="2" > 381 <widget row="3" column="3" >
335 <class>QLabel</class> 382 <class>QLabel</class>
336 <property stdset="1"> 383 <property stdset="1">
337 <name>name</name> 384 <name>name</name>
@@ -356,7 +403,7 @@
356 <name>hAlign</name> 403 <name>hAlign</name>
357 </property> 404 </property>
358 </widget> 405 </widget>
359 <widget row="3" column="3" > 406 <widget row="3" column="4" >
360 <class>QLabel</class> 407 <class>QLabel</class>
361 <property stdset="1"> 408 <property stdset="1">
362 <name>name</name> 409 <name>name</name>
@@ -378,7 +425,7 @@
378 <string>Flow control</string> 425 <string>Flow control</string>
379 </property> 426 </property>
380 </widget> 427 </widget>
381 <widget row="2" column="1" rowspan="1" colspan="3" > 428 <widget row="2" column="1" rowspan="1" colspan="4" >
382 <class>QCheckBox</class> 429 <class>QCheckBox</class>
383 <property stdset="1"> 430 <property stdset="1">
384 <name>name</name> 431 <name>name</name>
@@ -393,7 +440,7 @@
393 <bool>true</bool> 440 <bool>true</bool>
394 </property> 441 </property>
395 </widget> 442 </widget>
396 <spacer row="4" column="1" > 443 <spacer row="5" column="1" >
397 <property> 444 <property>
398 <name>name</name> 445 <name>name</name>
399 <cstring>Spacer5</cstring> 446 <cstring>Spacer5</cstring>
@@ -414,13 +461,20 @@
414 </size> 461 </size>
415 </property> 462 </property>
416 </spacer> 463 </spacer>
417 <widget row="5" column="0" rowspan="1" colspan="4" > 464 <widget row="6" column="0" rowspan="1" colspan="5" >
418 <class>QButtonGroup</class> 465 <class>QButtonGroup</class>
419 <property stdset="1"> 466 <property stdset="1">
420 <name>name</name> 467 <name>name</name>
421 <cstring>dialmode</cstring> 468 <cstring>dialmode</cstring>
422 </property> 469 </property>
423 <property stdset="1"> 470 <property stdset="1">
471 <name>sizePolicy</name>
472 <sizepolicy>
473 <hsizetype>3</hsizetype>
474 <vsizetype>5</vsizetype>
475 </sizepolicy>
476 </property>
477 <property stdset="1">
424 <name>title</name> 478 <name>title</name>
425 <string>Demand Dialing</string> 479 <string>Demand Dialing</string>
426 </property> 480 </property>
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp
new file mode 100644
index 0000000..f2386fc
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/pppdata.cpp
@@ -0,0 +1,1229 @@
1/*
2 * kPPP: A pppd front end for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * based on EzPPP:
10 * Copyright (C) 1997 Jay Painter
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include "pppdata.h"
28#include "runtests.h"
29#include "devices.h"
30//#include <klocale.h>
31#define i18n QObject::tr
32#include <qpe/config.h>
33#include <qmessagebox.h>
34#include <qapplication.h>
35// #include <klocale.h>
36// #include <kconfig.h>
37// #include <kmessagebox.h>
38// #include <kapplication.h>
39#include <assert.h>
40
41PPPData gpppdata;
42
43
44PPPData::PPPData()
45 : config(0L),
46 highcount(-1), // start out with no entries
47 caccount(-1), // set the current account index also
48 suidprocessid(-1), // process ID of setuid child
49 pppdisrunning(false),
50 pppderror(0)
51{
52}
53
54
55//
56// open configuration file
57//
58bool PPPData::open() {
59
60 config = new Config("NetworkSetup");
61 /*
62 config = kapp->config();
63
64 if (config->getConfigState() == KConfig::NoAccess) {
65 KMessageBox::error(0L,
66 i18n("The application-specific config file could not "
67 "be opened in either read-write or read-only mode.\n"
68 "The superuser might have to change its ownership "
69 "by issuing the following command in your home directory:\n"
70 "chown {YourUsername} .kde/share/config/kppprc"),
71 kapp->name());
72 return false;
73 }
74
75 // don't expand shell variables
76 config->setDollarExpansion(false);
77 */
78
79 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
80
81 if (highcount > MAX_ACCOUNTS)
82 highcount = MAX_ACCOUNTS;
83
84 if(highcount >= 0 && defaultAccount().isEmpty()) {
85 setAccountbyIndex(0);
86 setDefaultAccount(accname());
87 } else if(!setAccount(defaultAccount()))
88 setDefaultAccount(accname());
89
90 // start out with internal debugging disabled
91 // the user is still free to specify `debug' on his own
92 setPPPDebug(false);
93
94 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
95
96 return true;
97}
98
99
100//
101// save configuration
102//
103void PPPData::save() {
104
105 if (config) {
106 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
107// config->sync();
108 }
109
110}
111
112
113//
114// cancel changes
115//
116void PPPData::cancel() {
117
118// if (config) {
119// config->rollback();
120// config->reparseConfiguration();
121// }
122
123}
124
125
126// currently differentiates between READWRITE and NONE only
127int PPPData::access() const {
128
129 return 0;//config->getConfigState();
130}
131
132
133// functions to read/write date to configuration file
134QString PPPData::readConfig(const QString &group, const QString &key,
135 const QString &defvalue = "")
136{
137 if (config) {
138 config->setGroup(group);
139 return config->readEntry(key, defvalue);
140 } else
141 return defvalue;
142}
143
144
145int PPPData::readNumConfig(const QString &group, const QString &key,
146 int defvalue) {
147 if (config) {
148 config->setGroup(group);
149 return config->readNumEntry(key, defvalue);
150 } else
151 return defvalue;
152
153}
154
155
156bool PPPData::readListConfig(const QString &group, const QString &key,
157 QStringList &list, char sep) {
158 list.clear();
159 if (config) {
160 config->setGroup(group);
161 list = config->readListEntry(key, sep);
162 return true;
163 } else
164 return false;
165}
166
167
168void PPPData::writeConfig(const QString &group, const QString &key,
169 const QString &value) {
170 if (config) {
171 config->setGroup(group);
172 config->writeEntry(key, value);
173 }
174}
175
176
177void PPPData::writeConfig(const QString &group, const QString &key, int value) {
178 if (config) {
179 config->setGroup(group);
180 config->writeEntry(key, value);
181 }
182}
183
184
185void PPPData::writeListConfig(const QString &group, const QString &key,
186 QStringList &list, char sep) {
187 if (config) {
188 config->setGroup(group);
189 config->writeEntry(key, list, sep);
190 }
191}
192
193
194//
195// functions to set/return general information
196//
197QString PPPData::password() const {
198 return passwd;
199}
200
201
202void PPPData::setPassword(const QString &pw) {
203 passwd = pw;
204}
205
206
207const QString PPPData::defaultAccount() {
208 return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY);
209}
210
211
212void PPPData::setDefaultAccount(const QString &n) {
213 writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n);
214
215 //now set the current account index to the default account
216 setAccount(defaultAccount());
217}
218
219
220bool PPPData::get_show_clock_on_caption() {
221 return (bool) readNumConfig(GENERAL_GRP, SHOWCLOCK_KEY, true);
222}
223
224
225void PPPData::set_show_clock_on_caption(bool set) {
226 writeConfig(GENERAL_GRP, SHOWCLOCK_KEY, (int) set);
227}
228
229
230bool PPPData::get_xserver_exit_disconnect() {
231 return (bool) readNumConfig(GENERAL_GRP, DISCONNECT_KEY, true);
232}
233
234
235void PPPData::setPPPDebug(bool set) {
236 writeConfig(GENERAL_GRP, PPP_DEBUG_OPTION, (int)set);
237}
238
239
240bool PPPData::getPPPDebug() {
241 return (bool)readNumConfig(GENERAL_GRP, PPP_DEBUG_OPTION, false);
242}
243
244
245void PPPData::set_xserver_exit_disconnect(bool set) {
246 writeConfig(GENERAL_GRP, DISCONNECT_KEY, (int) set);
247}
248
249
250bool PPPData::quit_on_disconnect() {
251 return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false);
252}
253
254
255void PPPData::set_quit_on_disconnect(bool set) {
256 writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set);
257}
258
259
260bool PPPData::get_show_log_window() {
261 return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false);
262}
263
264
265void PPPData::set_show_log_window(bool set) {
266 writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set);
267}
268
269
270bool PPPData::automatic_redial() {
271 return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE);
272}
273
274
275void PPPData::set_automatic_redial(bool set) {
276 writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set);
277}
278
279
280bool PPPData::get_iconify_on_connect() {
281 return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE);
282}
283
284
285void PPPData::set_iconify_on_connect(bool set) {
286 writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set);
287}
288
289
290bool PPPData::get_dock_into_panel() {
291 return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false);
292}
293
294
295void PPPData::set_dock_into_panel(bool set) {
296 writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set);
297}
298
299
300QString PPPData::pppdVersion() {
301 return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch);
302}
303
304bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
305 // check if pppd version fulfills minimum requirement
306 return (pppdVer > ver
307 || (pppdVer == ver && pppdMod > mod)
308 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
309}
310
311int PPPData::pppdTimeout() {
312 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
313}
314
315
316void PPPData::setpppdTimeout(int n) {
317 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
318}
319
320
321const QString PPPData::modemDevice() {
322 return readConfig (MODEM_GRP, MODEMDEV_KEY, devices[DEV_DEFAULT]);
323}
324
325
326void PPPData::setModemDevice(const QString &n) {
327 writeConfig(MODEM_GRP, MODEMDEV_KEY, n);
328}
329
330
331const QString PPPData::flowcontrol() {
332 return readConfig(MODEM_GRP, FLOWCONTROL_KEY, "CRTSCTS");
333}
334
335
336void PPPData::setFlowcontrol(const QString &n) {
337 writeConfig(MODEM_GRP, FLOWCONTROL_KEY, n);
338}
339
340
341const QString PPPData::speed() {
342 QString s = readConfig(MODEM_GRP, SPEED_KEY, "57600");
343 // undo the damage of a bug in former versions. It left an empty Speed=
344 // entry in kppprc. kppp did set the serial port to 57600 as default but
345 // pppd wouldn't receive the speed via the command line.
346 if(s.toUInt() == 0)
347 s = "57600";
348 return s;
349}
350
351
352void PPPData::setSpeed(const QString &n) {
353 writeConfig(MODEM_GRP, SPEED_KEY, n);
354}
355
356
357#if 0
358void PPPData::setUseCDLine(const int n) {
359 writeConfig(MODEM_GRP,USECDLINE_KEY,n);
360}
361
362
363int PPPData::UseCDLine() {
364 return readNumConfig(MODEM_GRP,USECDLINE_KEY,0);
365}
366#endif
367
368const QString PPPData::modemEscapeStr() {
369 return readConfig(MODEM_GRP,ESCAPESTR_KEY,"+++");
370}
371
372
373void PPPData::setModemEscapeStr(const QString &n) {
374 writeConfig(MODEM_GRP,ESCAPESTR_KEY,n);
375}
376
377
378const QString PPPData::modemEscapeResp() {
379 return readConfig(MODEM_GRP,ESCAPERESP_KEY,"OK");
380}
381
382
383void PPPData::setModemEscapeResp(const QString &n) {
384 writeConfig(MODEM_GRP,ESCAPERESP_KEY,n);
385}
386
387
388int PPPData::modemEscapeGuardTime() {
389 return readNumConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,50);
390}
391
392
393void PPPData::setModemEscapeGuardTime(int n) {
394 writeConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,n);
395}
396
397
398bool PPPData::modemLockFile() {
399 return readNumConfig(MODEM_GRP, LOCKFILE_KEY, 1);
400}
401
402
403void PPPData::setModemLockFile(bool set) {
404 writeConfig(MODEM_GRP, LOCKFILE_KEY, set);
405}
406
407
408int PPPData::modemTimeout() {
409 return readNumConfig(MODEM_GRP, TIMEOUT_KEY, MODEM_TIMEOUT);
410}
411
412
413void PPPData::setModemTimeout(int n) {
414 writeConfig(MODEM_GRP, TIMEOUT_KEY, n);
415}
416
417
418int PPPData::modemToneDuration() {
419 return readNumConfig(MODEM_GRP, TONEDURATION_KEY,MODEM_TONEDURATION);
420}
421
422
423void PPPData::setModemToneDuration(int n) {
424 writeConfig(MODEM_GRP, TONEDURATION_KEY, n);
425}
426
427
428int PPPData::busyWait() {
429 return readNumConfig(MODEM_GRP, BUSYWAIT_KEY, BUSY_WAIT);
430}
431
432
433void PPPData::setbusyWait(int n) {
434 writeConfig(MODEM_GRP, BUSYWAIT_KEY, n);
435}
436
437
438//
439//Advanced "Modem" dialog
440//
441// defaults: InitString=ATZ, InitString1="" etc.
442const QString PPPData::modemInitStr(int i) {
443 assert(i >= 0 && i < NumInitStrings);
444 if(i == 0)
445 return readConfig(MODEM_GRP, INITSTR_KEY, "ATZ");
446 else
447 return readConfig(MODEM_GRP, INITSTR_KEY + QString::number(i), "");
448}
449
450
451void PPPData::setModemInitStr(int i, const QString &n) {
452 assert(i >= 0 && i < NumInitStrings);
453 QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : "");
454 writeConfig(MODEM_GRP, k, n);
455}
456
457
458const QString PPPData::modemInitResp() {
459 return readConfig(MODEM_GRP, INITRESP_KEY, "OK");
460}
461
462
463void PPPData::setModemInitResp(const QString &n) {
464 writeConfig(MODEM_GRP, INITRESP_KEY, n);
465}
466
467
468int PPPData::modemPreInitDelay() {
469 return readNumConfig(MODEM_GRP, PREINITDELAY_KEY, 50);
470}
471
472
473void PPPData::setModemPreInitDelay(int n) {
474 writeConfig(MODEM_GRP, PREINITDELAY_KEY, n);
475}
476
477
478int PPPData::modemInitDelay() {
479 return readNumConfig(MODEM_GRP, INITDELAY_KEY, 50);
480}
481
482
483void PPPData::setModemInitDelay(int n) {
484 writeConfig(MODEM_GRP, INITDELAY_KEY, n);
485}
486
487QString PPPData::modemNoDialToneDetectionStr() {
488 return readConfig(MODEM_GRP, NODTDETECT_KEY, "ATX3");
489}
490
491void PPPData::setModemNoDialToneDetectionStr(const QString &n) {
492 writeConfig(MODEM_GRP, NODTDETECT_KEY, n);
493}
494
495const QString PPPData::modemDialStr() {
496 return readConfig(MODEM_GRP, DIALSTR_KEY, "ATDT");
497}
498
499
500void PPPData::setModemDialStr(const QString &n) {
501 writeConfig(MODEM_GRP, DIALSTR_KEY, n);
502}
503
504
505const QString PPPData::modemConnectResp() {
506 return readConfig(MODEM_GRP, CONNECTRESP_KEY, "CONNECT");
507}
508
509
510void PPPData::setModemConnectResp(const QString &n) {
511 writeConfig(MODEM_GRP, CONNECTRESP_KEY, n);
512}
513
514
515const QString PPPData::modemBusyResp() {
516 return readConfig(MODEM_GRP, BUSYRESP_KEY, "BUSY");
517}
518
519
520void PPPData::setModemBusyResp(const QString &n) {
521 writeConfig(MODEM_GRP, BUSYRESP_KEY, n);
522}
523
524
525const QString PPPData::modemNoCarrierResp() {
526 return readConfig(MODEM_GRP, NOCARRIERRESP_KEY, "NO CARRIER");
527}
528
529
530void PPPData::setModemNoCarrierResp(const QString &n) {
531 writeConfig(MODEM_GRP, NOCARRIERRESP_KEY, n);
532}
533
534
535const QString PPPData::modemNoDialtoneResp() {
536 return readConfig(MODEM_GRP, NODIALTONERESP_KEY, "NO DIALTONE");
537}
538
539
540void PPPData::setModemNoDialtoneResp(const QString &n) {
541 writeConfig(MODEM_GRP, NODIALTONERESP_KEY, n);
542}
543
544
545const QString PPPData::modemHangupStr() {
546 return readConfig(MODEM_GRP, HANGUPSTR_KEY, "+++ATH");
547}
548
549void PPPData::setModemHangupStr(const QString &n) {
550 writeConfig(MODEM_GRP, HANGUPSTR_KEY, n);
551}
552
553
554const QString PPPData::modemHangupResp() {
555 return readConfig(MODEM_GRP, HANGUPRESP_KEY, "OK");
556}
557
558void PPPData::setModemHangupResp(const QString &n) {
559 writeConfig(MODEM_GRP, HANGUPRESP_KEY, n);
560}
561
562
563const QString PPPData::modemAnswerStr() {
564 return readConfig(MODEM_GRP, ANSWERSTR_KEY, "ATA");
565}
566
567
568QString PPPData::volumeOff() {
569 return readConfig(MODEM_GRP, VOLUME_OFF, "M0L0");
570}
571
572
573void PPPData::setVolumeOff(const QString &s) {
574 writeConfig(MODEM_GRP, VOLUME_OFF, s);
575}
576
577
578QString PPPData::volumeMedium() {
579 return readConfig(MODEM_GRP, VOLUME_MEDIUM, "M1L1");
580}
581
582
583void PPPData::setVolumeMedium(const QString &s) {
584 writeConfig(MODEM_GRP, VOLUME_MEDIUM, s);
585}
586
587
588QString PPPData::volumeHigh() {
589 QString tmp = readConfig(MODEM_GRP, VOLUME_HIGH, "M1L3");
590 if(tmp == "M1L4")
591 tmp = "M1L3";
592 return tmp;
593}
594
595
596void PPPData::setVolumeHigh(const QString &s) {
597 writeConfig(MODEM_GRP, VOLUME_HIGH, s);
598}
599
600
601QString PPPData::volumeInitString() {
602 QString s;
603
604 switch(volume()) {
605 case 0:
606 s = volumeOff();
607 break;
608 case 1:
609 s = volumeMedium();
610 break;
611 case 2:
612 s = volumeHigh();
613 break;
614 default:
615 s = volumeMedium();
616 }
617
618 return s;
619}
620
621
622int PPPData::volume() {
623 return readNumConfig(MODEM_GRP, VOLUME_KEY, 1);
624}
625
626
627void PPPData::setVolume(int i) {
628 writeConfig(MODEM_GRP, VOLUME_KEY, i);
629}
630
631int PPPData::waitForDialTone() {
632 return readNumConfig(MODEM_GRP, DIALTONEWAIT_KEY, 1);
633}
634
635void PPPData::setWaitForDialTone(int i) {
636 writeConfig(MODEM_GRP, DIALTONEWAIT_KEY, i);
637}
638
639void PPPData::setModemAnswerStr(const QString &n) {
640 writeConfig(MODEM_GRP, ANSWERSTR_KEY, n);
641}
642
643
644const QString PPPData::modemRingResp() {
645 return readConfig(MODEM_GRP, RINGRESP_KEY, "RING");
646}
647
648
649void PPPData::setModemRingResp(const QString &n) {
650 writeConfig(MODEM_GRP, RINGRESP_KEY, n);
651}
652
653
654const QString PPPData::modemAnswerResp() {
655 return readConfig(MODEM_GRP, ANSWERRESP_KEY, "CONNECT");
656}
657
658
659void PPPData::setModemAnswerResp(const QString &n) {
660 writeConfig(MODEM_GRP, ANSWERRESP_KEY, n);
661}
662
663
664const QString PPPData::enter() {
665 return readConfig(MODEM_GRP, ENTER_KEY, "CR");
666}
667
668
669void PPPData::setEnter(const QString &n) {
670 writeConfig(MODEM_GRP, ENTER_KEY, n);
671}
672
673
674//
675// functions to set/return account information
676//
677
678//returns number of accounts
679int PPPData::count() const {
680 return highcount + 1;
681}
682
683
684bool PPPData::setAccount(const QString &aname) {
685 for(int i = 0; i <= highcount; i++) {
686 setAccountbyIndex(i);
687 if(accname() == aname) {
688 caccount = i;
689 return true;
690 }
691 }
692 return false;
693}
694
695
696bool PPPData::setAccountbyIndex(int i) {
697 if(i >= 0 && i <= highcount) {
698 caccount = i;
699 cgroup.sprintf("%s%i", ACCOUNT_GRP, i);
700 return true;
701 }
702 return false;
703}
704
705
706bool PPPData::isUniqueAccname(const QString &n) {
707 int current = caccount;
708 for(int i=0; i <= highcount; i++) {
709 setAccountbyIndex(i);
710 if(accname() == n && i != current) {
711 setAccountbyIndex(current);
712 return false;
713 }
714 }
715 setAccountbyIndex(current);
716 return true;
717}
718
719
720bool PPPData::deleteAccount() {
721 if(caccount < 0)
722 return false;
723
724// QMap <QString, QString> map;
725// QMap <QString, QString>::Iterator it;
726
727 // set all entries of the current account to ""
728// tille: do not handle the accounts here... (?)
729// map = config->entryMap(cgroup);
730// it = map.begin();
731// while (it != map.end()) {
732// config->writeEntry(it.key(), "");
733// it++;
734// }
735
736// // shift the succeeding accounts
737// for(int i = caccount+1; i <= highcount; i++) {
738// setAccountbyIndex(i);
739// map = config->entryMap(cgroup);
740// it = map.begin();
741// setAccountbyIndex(i-1);
742// config->setGroup(cgroup);
743// while (it != map.end()) {
744// config->writeEntry(it.key(), *it);
745// it++;
746// }
747// }
748
749// // make sure the top account is cleared
750// setAccountbyIndex(highcount);
751// map = config->entryMap(cgroup);
752// it = map.begin();
753// config->setGroup(cgroup);
754// while (it.key() != QString::null) {
755// config->writeEntry(it.key(), "");
756// it++;
757// }
758
759 highcount--;
760 if(caccount > highcount)
761 caccount = highcount;
762
763 setAccountbyIndex(caccount);
764
765 return true;
766}
767
768
769bool PPPData::deleteAccount(const QString &aname) {
770 if(!setAccount(aname))
771 return false;
772
773 deleteAccount();
774
775 return true;
776}
777
778
779int PPPData::newaccount() {
780
781 if(!config || highcount >= MAX_ACCOUNTS)
782 return -1;
783
784 highcount++;
785 setAccountbyIndex(highcount);
786
787 setpppdArgumentDefaults();
788
789 return caccount;
790}
791
792int PPPData::copyaccount(int i) {
793
794 if(highcount >= MAX_ACCOUNTS)
795 return -1;
796
797 setAccountbyIndex(i);
798
799// QMap <QString, QString> map = config->entryMap(cgroup);
800// QMap <QString, QString>::ConstIterator it = map.begin();
801
802 QString newname = i18n("%1_copy").arg(accname());
803
804 newaccount();
805
806// while (it != map.end()) {
807// config->writeEntry(it.key(), *it);
808// it++;
809// }
810
811 setAccname(newname);
812
813 return caccount;
814}
815
816
817const QString PPPData::accname() {
818 return readConfig(cgroup, NAME_KEY);
819}
820
821void PPPData::setAccname(const QString &n) {
822 if(!cgroup.isNull()) {
823 // are we manipulating the default account's name ? then change it, too.
824 bool def = accname() == defaultAccount();
825 writeConfig(cgroup, NAME_KEY, n);
826 if (def)
827 setDefaultAccount(n);
828 }
829}
830
831
832#define SEPARATOR_CHAR ':'
833QStringList &PPPData::phonenumbers() {
834
835 readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
836 return phonelist;
837
838}
839
840
841const QString PPPData::phonenumber() {
842 return readConfig(cgroup, PHONENUMBER_KEY);
843}
844
845
846void PPPData::setPhonenumber(const QString &n) {
847 writeConfig(cgroup, PHONENUMBER_KEY, n);
848}
849
850
851const QString PPPData::dialPrefix() {
852 return readConfig(cgroup, DIAL_PREFIX_KEY, "");
853}
854
855
856void PPPData::setDialPrefix(const QString &s) {
857 writeConfig(cgroup, DIAL_PREFIX_KEY, s);
858}
859
860
861int PPPData::authMethod() {
862 return readNumConfig(cgroup, AUTH_KEY, 0);
863}
864
865
866void PPPData::setAuthMethod(int value) {
867 writeConfig(cgroup, AUTH_KEY, value);
868}
869
870
871const QString PPPData::storedUsername() {
872 return readConfig(cgroup, STORED_USERNAME_KEY, "");
873}
874
875
876void PPPData::setStoredUsername(const QString &b) {
877 writeConfig(cgroup, STORED_USERNAME_KEY, b);
878}
879
880
881const QString PPPData::storedPassword() {
882 return readConfig(cgroup, STORED_PASSWORD_KEY, "");
883}
884
885
886void PPPData::setStoredPassword(const QString &b) {
887 writeConfig(cgroup, STORED_PASSWORD_KEY, b);
888}
889
890
891bool PPPData::storePassword() {
892 return (bool)readNumConfig(cgroup, STORE_PASSWORD_KEY, 1);
893}
894
895
896const QString PPPData::command_before_connect() {
897 return readConfig(cgroup, BEFORE_CONNECT_KEY);
898}
899
900
901void PPPData::setCommand_before_connect(const QString &n) {
902 writeConfig(cgroup, BEFORE_CONNECT_KEY, n);
903}
904
905
906void PPPData::setStorePassword(bool b) {
907 writeConfig(cgroup, STORE_PASSWORD_KEY, (int)b);
908}
909
910
911const QString PPPData::command_on_connect() {
912 return readConfig(cgroup, COMMAND_KEY);
913}
914
915
916void PPPData::setCommand_on_connect(const QString &n) {
917 writeConfig(cgroup, COMMAND_KEY, n);
918}
919
920
921const QString PPPData::command_on_disconnect() {
922 return readConfig(cgroup, DISCONNECT_COMMAND_KEY);
923}
924
925
926void PPPData::setCommand_on_disconnect(const QString &n) {
927 writeConfig(cgroup, DISCONNECT_COMMAND_KEY, n);
928}
929
930
931const QString PPPData::command_before_disconnect() {
932 return readConfig(cgroup, BEFORE_DISCONNECT_KEY);
933}
934
935
936void PPPData::setCommand_before_disconnect(const QString &n) {
937 writeConfig(cgroup, BEFORE_DISCONNECT_KEY, n);
938}
939
940
941const QString PPPData::ipaddr() {
942 return readConfig(cgroup, IPADDR_KEY);
943}
944
945
946void PPPData::setIpaddr(const QString &n) {
947 writeConfig(cgroup, IPADDR_KEY, n);
948}
949
950
951const QString PPPData::subnetmask() {
952 return readConfig(cgroup, SUBNETMASK_KEY);
953}
954
955
956void PPPData::setSubnetmask(const QString &n) {
957 writeConfig(cgroup, SUBNETMASK_KEY, n);
958}
959
960
961bool PPPData::autoname() {
962 return (bool) readNumConfig(cgroup, AUTONAME_KEY, false);
963}
964
965
966void PPPData::setAutoname(bool set) {
967 writeConfig(cgroup, AUTONAME_KEY, (int) set);
968}
969
970
971bool PPPData::AcctEnabled() {
972 return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false);
973}
974
975
976void PPPData::setAcctEnabled(bool set) {
977 writeConfig(cgroup, ACCTENABLED_KEY, (int) set);
978}
979
980
981int PPPData::VolAcctEnabled() {
982 return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0);
983}
984
985
986void PPPData::setVolAcctEnabled(int set) {
987 writeConfig(cgroup, VOLACCTENABLED_KEY, set);
988}
989
990
991const QString PPPData::gateway() {
992 return readConfig(cgroup, GATEWAY_KEY);
993}
994
995
996void PPPData::setGateway(const QString &n ) {
997 writeConfig(cgroup, GATEWAY_KEY, n);
998}
999
1000
1001bool PPPData::defaultroute() {
1002 // default route is by default 'on'.
1003 return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true);
1004}
1005
1006
1007void PPPData::setDefaultroute(bool set) {
1008 writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set);
1009}
1010
1011
1012bool PPPData::autoDNS() {
1013 bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true);
1014 return (set && gpppdata.pppdVersionMin(2, 3, 7));
1015}
1016
1017
1018void PPPData::setAutoDNS(bool set) {
1019 writeConfig(cgroup, AUTODNS_KEY, (int) set);
1020}
1021
1022
1023void PPPData::setExDNSDisabled(bool set) {
1024 writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set);
1025}
1026
1027
1028bool PPPData::exDNSDisabled() {
1029 return (bool) readNumConfig(cgroup, EXDNSDISABLED_KEY,0);
1030}
1031
1032
1033QStringList &PPPData::dns() {
1034 static QStringList dnslist;
1035
1036 readListConfig(cgroup, DNS_KEY, dnslist);
1037 while(dnslist.count() > MAX_DNS_ENTRIES)
1038 dnslist.remove(dnslist.last());
1039
1040 return dnslist;
1041}
1042
1043
1044void PPPData::setDns(QStringList &list) {
1045 writeListConfig(cgroup, DNS_KEY, list);
1046}
1047
1048
1049const QString PPPData::domain() {
1050 return readConfig(cgroup, DOMAIN_KEY);
1051}
1052
1053
1054void PPPData::setDomain(const QString &n ) {
1055 writeConfig(cgroup, DOMAIN_KEY, n);
1056}
1057
1058
1059QStringList &PPPData::scriptType() {
1060 static QStringList typelist;
1061
1062 readListConfig(cgroup, SCRIPTCOM_KEY, typelist);
1063 while(typelist.count() > MAX_SCRIPT_ENTRIES)
1064 typelist.remove(typelist.last());
1065
1066 return typelist;
1067}
1068
1069
1070void PPPData::setScriptType(QStringList &list) {
1071 writeListConfig(cgroup, SCRIPTCOM_KEY, list);
1072}
1073
1074
1075QStringList &PPPData::script() {
1076 static QStringList scriptlist;
1077
1078 readListConfig(cgroup, SCRIPTARG_KEY, scriptlist);
1079 while(scriptlist.count() > MAX_SCRIPT_ENTRIES)
1080 scriptlist.remove(scriptlist.last());
1081
1082 return scriptlist;
1083}
1084
1085
1086void PPPData::setScript(QStringList &list) {
1087 writeListConfig(cgroup, SCRIPTARG_KEY, list);
1088}
1089
1090
1091const QString PPPData::accountingFile() {
1092 return readConfig(cgroup, ACCTFILE_KEY);
1093}
1094
1095
1096void PPPData::setAccountingFile(const QString &n) {
1097 writeConfig(cgroup, ACCTFILE_KEY, n);
1098}
1099
1100
1101const QString PPPData::totalCosts() {
1102 return readConfig(cgroup, TOTALCOSTS_KEY);
1103}
1104
1105
1106void PPPData::setTotalCosts(const QString &n) {
1107 writeConfig(cgroup, TOTALCOSTS_KEY, n);
1108}
1109
1110
1111int PPPData::totalBytes() {
1112 return readNumConfig(cgroup, TOTALBYTES_KEY, 0);
1113}
1114
1115void PPPData::setTotalBytes(int n) {
1116 writeConfig(cgroup, TOTALBYTES_KEY, n);
1117}
1118
1119
1120QStringList &PPPData::pppdArgument() {
1121 static QStringList arglist;
1122
1123 while(arglist.count() > MAX_PPPD_ARGUMENTS)
1124 arglist.remove(arglist.last());
1125 readListConfig(cgroup, PPPDARG_KEY, arglist);
1126
1127 return arglist;
1128}
1129
1130
1131void PPPData::setpppdArgument(QStringList &args) {
1132 writeListConfig(cgroup, PPPDARG_KEY, args);
1133}
1134
1135
1136void PPPData::setpppdArgumentDefaults() {
1137 QStringList arg;
1138 setpppdArgument(arg);
1139}
1140
1141
1142// graphing widget
1143void PPPData::setGraphingOptions(bool enable,
1144 QColor bg,
1145 QColor text,
1146 QColor in,
1147 QColor out)
1148{
1149 if(config) {
1150 config->setGroup(GRAPH_GRP);
1151 config->writeEntry(GENABLED, enable);
1152// config->writeEntry(GCOLOR_BG, bg);
1153// config->writeEntry(GCOLOR_TEXT, text);
1154// config->writeEntry(GCOLOR_IN, in);
1155// config->writeEntry(GCOLOR_OUT, out);
1156 }
1157}
1158
1159void PPPData::graphingOptions(bool &enable,
1160 QColor &bg,
1161 QColor &text,
1162 QColor &in,
1163 QColor &out)
1164{
1165 QColor c;
1166
1167 if(config) {
1168 config->setGroup(GRAPH_GRP);
1169 enable = config->readBoolEntry(GENABLED, true);
1170 bg = Qt::white;
1171 //bg = config->readColorEntry(GCOLOR_BG, &c);
1172 text = Qt::black;
1173 //text = config->readColorEntry(GCOLOR_TEXT, &c);
1174 in = Qt::blue;
1175 //in = config->readColorEntry(GCOLOR_IN, &c);
1176 out = Qt::red;
1177 //out = config->readColorEntry(GCOLOR_OUT, &c);
1178 }
1179}
1180
1181
1182bool PPPData::graphingEnabled() {
1183 return (bool) readNumConfig(GRAPH_GRP, GENABLED, true);
1184}
1185
1186
1187
1188//
1189//functions to change/set the child pppd process info
1190//
1191bool PPPData::pppdRunning() const {
1192 return pppdisrunning;
1193}
1194
1195void PPPData::setpppdRunning(bool set) {
1196 pppdisrunning = set;
1197}
1198
1199int PPPData::pppdError() const {
1200 return pppderror;
1201}
1202
1203void PPPData::setpppdError(int err) {
1204 pppderror = err;
1205}
1206
1207
1208//
1209// window position
1210//
1211void PPPData::winPosConWin(int& p_x, int& p_y) {
1212 p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160);
1213 p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55);
1214}
1215
1216void PPPData::setWinPosConWin(int p_x, int p_y) {
1217 writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x);
1218 writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y);
1219}
1220
1221void PPPData::winPosStatWin(int& p_x, int& p_y) {
1222 p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160);
1223 p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55);
1224}
1225
1226void PPPData::setWinPosStatWin(int p_x, int p_y) {
1227 writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x);
1228 writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y);
1229}
diff --git a/noncore/settings/networksettings/ppp/pppdata.h b/noncore/settings/networksettings/ppp/pppdata.h
new file mode 100644
index 0000000..e286b70
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/pppdata.h
@@ -0,0 +1,465 @@
1/* -*- C++ -*-
2 *
3 * kPPP: A pppd front end for the KDE project
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997 Bernd Johannes Wuebben
8 * wuebben@math.cornell.edu
9 *
10 * based on EzPPP:
11 * Copyright (C) 1997 Jay Painter
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
22 *
23 * You should have received a copy of the GNU Library General Public
24 * License along with this program; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#ifndef _PPPDATA_H_
29#define _PPPDATA_H_
30
31#include <unistd.h>
32#include <sys/types.h>
33
34#include <qstring.h>
35#include <qstringlist.h>
36#include <qcolor.h>
37
38#include "kpppconfig.h"
39
40class Config;
41
42// string lengths
43
44#define PATH_SIZE 120
45#define MODEMSTR_SIZE 80
46#define ACCNAME_SIZE 50
47#define PHONENUMBER_SIZE 60
48#define COMMAND_SIZE 255
49#define IPADDR_SIZE 15
50#define DOMAIN_SIZE 50
51#define TIMEOUT_SIZE 60
52
53//
54// keys for config file
55//
56
57// groups
58#define GENERAL_GRP "General"
59#define MODEM_GRP "Modem"
60#define ACCOUNT_GRP "Account"
61#define GRAPH_GRP "Graph"
62#define WINPOS_GRP "WindowPosition"
63
64// general
65#define DEFAULTACCOUNT_KEY "DefaultAccount"
66#define PPPDVERSION_KEY "pppdVersion"
67#define PPPDTIMEOUT_KEY "pppdTimeout"
68#define SHOWCLOCK_KEY "ShowClock"
69#define SHOWLOGWIN_KEY "ShowLogWindow"
70#define AUTOREDIAL_KEY "AutomaticRedial"
71#define DISCONNECT_KEY "DisconnectOnXServerExit"
72#define QUITONDISCONNECT_KEY "QuitOnDisconnect"
73#define NUMACCOUNTS_KEY "NumberOfAccounts"
74 #define ID_KEY "ID"
75
76// modem
77#define MODEMDEV_KEY "Device"
78#define LOCKFILE_KEY "UseLockFile"
79#define FLOWCONTROL_KEY "FlowControl"
80#define SPEED_KEY "Speed"
81#define TIMEOUT_KEY "Timeout"
82#define TONEDURATION_KEY "ToneDuration"
83#define BUSYWAIT_KEY "BusyWait"
84#define INITSTR_KEY "InitString"
85#define INITRESP_KEY "InitResponse"
86#define PREINITDELAY_KEY "PreInitDelay"
87#define INITDELAY_KEY "InitDelay"
88#define NODTDETECT_KEY "NoDialToneDetection"
89#define DIALTONEWAIT_KEY "WaitForDialTone"
90#define DIALSTR_KEY "DialString"
91#define CONNECTRESP_KEY "ConnectResponse"
92#define BUSYRESP_KEY "BusyResponse"
93#define NOCARRIERRESP_KEY "NoCarrierResponse"
94#define NODIALTONERESP_KEY "NoDialToneResp"
95#define HANGUPSTR_KEY "HangupString"
96#define HANGUPRESP_KEY "HangUpResponse"
97#define ANSWERSTR_KEY "AnswerString"
98#define RINGRESP_KEY "RingResponse"
99#define ANSWERRESP_KEY "AnswerResponse"
100#define ENTER_KEY "Enter"
101#define ESCAPESTR_KEY "EscapeString"
102#define ESCAPERESP_KEY "EscapeResponse"
103#define ESCAPEGUARDTIME_KEY "EscapeGuardTime"
104#define USECDLINE_KEY "UseCDLine"
105#define VOLUME_HIGH "VolumeHigh"
106#define VOLUME_MEDIUM "VolumeMedium"
107#define VOLUME_OFF "VolumeOff"
108#define VOLUME_KEY "Volume"
109
110// account
111#define NAME_KEY "Name"
112#define PHONENUMBER_KEY "Phonenumber"
113#define DIAL_PREFIX_KEY "DialPrefix"
114#define AUTH_KEY "Authentication"
115#define STORED_PASSWORD_KEY "Password"
116#define STORED_USERNAME_KEY "Username"
117#define STORE_PASSWORD_KEY "StorePassword"
118#define BEFORE_CONNECT_KEY "BeforeConnect"
119#define COMMAND_KEY "Command"
120#define DISCONNECT_COMMAND_KEY "DisconnectCommand"
121#define BEFORE_DISCONNECT_KEY "BeforeDisconnect"
122#define IPADDR_KEY "IPAddr"
123#define SUBNETMASK_KEY "SubnetMask"
124#define ACCTENABLED_KEY "AccountingEnabled"
125#define VOLACCTENABLED_KEY "VolumeAccountingEnabled"
126#define ACCTFILE_KEY "AccountingFile"
127#define AUTONAME_KEY "AutoName"
128#define GATEWAY_KEY "Gateway"
129#define DEFAULTROUTE_KEY "DefaultRoute"
130#define DOMAIN_KEY "Domain"
131#define DNS_KEY "DNS"
132#define AUTODNS_KEY "AutoDNS"
133#define EXDNSDISABLED_KEY "ExDNSDisabled"
134#define SCRIPTCOM_KEY "ScriptCommands"
135#define SCRIPTARG_KEY "ScriptArguments"
136#define PPPDARG_KEY "pppdArguments"
137#define PPP_DEBUG_OPTION "PPPDebug"
138#define ICONIFY_ON_CONNECT_KEY "iconifyOnConnect"
139#define DOCKING_KEY "DockIntoPanel"
140#define TOTALCOSTS_KEY "TotalCosts"
141#define TOTALBYTES_KEY "TotalBytes"
142
143// graph colors
144#define GENABLED "Enabled"
145#define GCOLOR_BG "Background"
146#define GCOLOR_TEXT "Text"
147#define GCOLOR_IN "InBytes"
148#define GCOLOR_OUT "OutBytes"
149
150// pppd errors
151#define E_IF_TIMEOUT 1
152#define E_PPPD_DIED 2
153
154// window position
155#define WINPOS_CONWIN_X "WindowPositionConWinX"
156#define WINPOS_CONWIN_Y "WindowPositionConWinY"
157#define WINPOS_STATWIN_X "WindowPositionStatWinX"
158#define WINPOS_STATWIN_Y "WindowPositionStatWinY"
159
160class PPPData {
161public:
162 PPPData();
163 ~PPPData() {};
164
165 enum { NumInitStrings = 2 };
166
167 // general functions
168 bool open();
169 void save();
170 void cancel();
171 int access() const; // read/write access
172
173 // function to read/write date to configuration file
174 QString readConfig(const QString &, const QString &, const QString &);
175 int readNumConfig(const QString &, const QString &, int);
176 bool readListConfig(const QString &, const QString &,
177 QStringList &, char sep = ',');
178 void writeConfig(const QString &, const QString &, const QString &);
179 void writeConfig(const QString &, const QString &, int);
180 void writeListConfig(const QString &, const QString &,
181 QStringList &, char sep = ',');
182
183 // return the current account group
184 QString currentGroup() { return cgroup; }
185
186 // functions to set/get general kppp info
187 QString password() const;
188 void setPassword(const QString &);
189
190 const QString defaultAccount();
191 void setDefaultAccount(const QString &);
192
193 void set_xserver_exit_disconnect(bool set);
194 bool get_xserver_exit_disconnect();
195
196 void setPPPDebug(bool set);
197 bool getPPPDebug();
198
199 void set_quit_on_disconnect(bool);
200 bool quit_on_disconnect();
201
202 void set_show_clock_on_caption(bool set);
203 bool get_show_clock_on_caption();
204
205 void set_show_log_window(bool set);
206 bool get_show_log_window();
207
208 void set_automatic_redial(bool set);
209 bool automatic_redial();
210
211 void set_iconify_on_connect(bool set);
212 bool get_iconify_on_connect();
213
214 void set_dock_into_panel(bool set);
215 bool get_dock_into_panel();
216
217 const QString enter();
218 void setEnter(const QString &);
219
220 QString pppdVersion();
221 bool pppdVersionMin(int ver, int mod, int patch);
222
223 int pppdTimeout();
224 void setpppdTimeout(int);
225
226 int busyWait();
227 void setbusyWait(int);
228
229 bool modemLockFile();
230 void setModemLockFile(bool set);
231
232 int modemEscapeGuardTime();
233 void setModemEscapeGuardTime(int i);
234
235 void setModemEscapeStr(const QString &);
236 const QString modemEscapeStr();
237
238 void setModemEscapeResp(const QString &);
239 const QString modemEscapeResp();
240
241 const QString modemDevice();
242 void setModemDevice(const QString &);
243
244 const QString flowcontrol();
245 void setFlowcontrol(const QString &);
246
247 int modemTimeout();
248 void setModemTimeout(int);
249
250 int modemToneDuration();
251 void setModemToneDuration(int);
252
253 QString volumeInitString();
254 int volume();
255 void setVolume(int);
256
257 int waitForDialTone();
258 void setWaitForDialTone(int i);
259
260 // modem command strings/responses
261 const QString modemInitStr(int i);
262 void setModemInitStr(int i, const QString &);
263
264 const QString modemInitResp();
265 void setModemInitResp(const QString &);
266
267 int modemPreInitDelay();
268 void setModemPreInitDelay(int);
269
270 int modemInitDelay();
271 void setModemInitDelay(int);
272
273 QString modemNoDialToneDetectionStr();
274 void setModemNoDialToneDetectionStr(const QString &);
275
276 const QString modemDialStr();
277 void setModemDialStr(const QString &);
278
279 const QString modemConnectResp();
280 void setModemConnectResp(const QString &);
281
282 const QString modemBusyResp();
283 void setModemBusyResp(const QString &);
284
285 const QString modemNoCarrierResp();
286 void setModemNoCarrierResp(const QString &);
287
288 const QString modemNoDialtoneResp();
289 void setModemNoDialtoneResp(const QString &);
290
291 const QString modemHangupStr();
292 void setModemHangupStr(const QString &);
293
294 const QString modemHangupResp();
295 void setModemHangupResp(const QString &);
296
297 const QString modemAnswerStr();
298 void setModemAnswerStr(const QString &);
299
300 const QString modemRingResp();
301 void setModemRingResp(const QString &);
302
303 const QString modemAnswerResp();
304 void setModemAnswerResp(const QString &);
305
306 QString volumeOff();
307 void setVolumeOff(const QString &);
308
309 QString volumeMedium();
310 void setVolumeMedium(const QString &);
311
312 QString volumeHigh();
313 void setVolumeHigh(const QString &);
314
315#if 0
316 void setUseCDLine(const int n);
317 int UseCDLine();
318#endif
319
320 // functions to set/get account information
321 int count() const;
322 bool setAccount(const QString &);
323 bool setAccountbyIndex(int);
324
325 bool isUniqueAccname(const QString &);
326
327 bool deleteAccount();
328 bool deleteAccount(const QString &);
329 int newaccount();
330 int copyaccount(int i);
331
332 const QString accname();
333 void setAccname(const QString &);
334
335 QStringList &phonenumbers();
336 const QString phonenumber();
337 void setPhonenumber(const QString &);
338
339 const QString dialPrefix();
340 void setDialPrefix(const QString &);
341
342 int authMethod();
343 void setAuthMethod(int);
344
345 const QString storedUsername();
346 void setStoredUsername(const QString &);
347
348 const QString storedPassword();
349 void setStoredPassword(const QString &);
350
351 bool storePassword();
352 void setStorePassword(bool);
353
354 const QString speed();
355 void setSpeed(const QString &);
356
357 const QString command_before_connect();
358 void setCommand_before_connect(const QString &);
359
360 const QString command_on_connect();
361 void setCommand_on_connect(const QString &);
362
363 const QString command_on_disconnect();
364 void setCommand_on_disconnect(const QString &);
365
366 const QString command_before_disconnect();
367 void setCommand_before_disconnect(const QString &);
368
369 const QString ipaddr();
370 void setIpaddr(const QString &);
371
372 const QString subnetmask();
373 void setSubnetmask(const QString &);
374
375 bool AcctEnabled();
376 void setAcctEnabled(bool set);
377
378 int VolAcctEnabled();
379 void setVolAcctEnabled(int set);
380
381 bool autoDNS();
382 void setAutoDNS(bool set);
383
384 bool exDNSDisabled();
385 void setExDNSDisabled(bool set);
386
387 bool autoname();
388 void setAutoname(bool set);
389
390 const QString gateway();
391 void setGateway(const QString &);
392
393 bool defaultroute();
394 void setDefaultroute(bool set);
395
396 QStringList &dns();
397 void setDns(QStringList &);
398
399 const QString domain();
400 void setDomain(const QString &);
401
402 QStringList &scriptType();
403 void setScriptType(QStringList &);
404
405 QStringList &script();
406 void setScript(QStringList &);
407
408 QStringList &pppdArgument();
409 void setpppdArgumentDefaults();
410 void setpppdArgument(QStringList &);
411
412 //functions to change/set the child pppd process info
413 bool pppdRunning() const;
414 void setpppdRunning(bool set);
415
416 int pppdError() const;
417 void setpppdError(int err);
418
419 // functions to set/query the accounting info
420 const QString accountingFile();
421 void setAccountingFile(const QString &);
422
423 const QString totalCosts();
424 void setTotalCosts(const QString &);
425
426 int totalBytes();
427 void setTotalBytes(int);
428
429 // graphing widget
430 void setGraphingOptions(bool enabled,
431 QColor bg,
432 QColor text,
433 QColor in,
434 QColor out);
435 void graphingOptions(bool &enabled,
436 QColor &bg,
437 QColor &text,
438 QColor &in,
439 QColor &out);
440 bool graphingEnabled();
441
442 // window positions
443 void winPosConWin(int &, int &);
444 void setWinPosConWin(int, int);
445 void winPosStatWin(int &, int &);
446 void setWinPosStatWin(int, int);
447
448private:
449 QString passwd;
450 Config* config; // configuration object
451 int highcount; // index of highest account
452 int caccount; // index of the current account
453 QString cgroup; // name of current config group
454 pid_t suidprocessid; // process ID of setuid child
455 bool pppdisrunning; // pppd process
456 // daemon
457 int pppderror; // error encounterd running pppd
458 int pppdVer, pppdMod, pppdPatch; // pppd version
459
460 QStringList phonelist;
461};
462
463extern PPPData gpppdata;
464
465#endif
diff --git a/noncore/settings/networksettings/ppp/pppimp.cpp b/noncore/settings/networksettings/ppp/pppimp.cpp
index d3094fc..6588bbc 100644
--- a/noncore/settings/networksettings/ppp/pppimp.cpp
+++ b/noncore/settings/networksettings/ppp/pppimp.cpp
@@ -1,7 +1,19 @@
1
2#include <qcombobox.h>
3#include <qpushbutton.h>
4
1#include "pppimp.h" 5#include "pppimp.h"
6#include "devices.h"
7#include "modem.h"
8#include "modeminfo.h"
9//#include "pppdata.h"
10
2 11
3PPPConfigureImp::PPPConfigureImp( QWidget* parent, const char* name, bool modal, WFlags fl) : PPP(parent, name, modal, fl) { 12PPPConfigureImp::PPPConfigureImp( QWidget* parent, const char* name, bool modal, WFlags fl) : PPP(parent, name, modal, fl) {
4 13
14 for(int i = 0; devices[i]; i++)
15 ComboBoxDevice->insertItem(devices[i]);
16 connect(PushButtonQuery, SIGNAL(clicked()), SLOT(queryModem()));
5} 17}
6 18
7/** 19/**
@@ -35,5 +47,14 @@ name <name> - user name (and do secret file)
35 QDialog::accept(); 47 QDialog::accept();
36} 48}
37 49
38// pppconfigureimp.h 50void PPPConfigureImp::queryModem()
51{
52
53 Modem::modem = new Modem();
54 qDebug("setting device");
55// gpppdata.setModemDevice(ComboBoxDevice->currentText());
56 qDebug("open dialog");
57 ModemTransfer mt(this);
58 mt.exec();
59}
39 60
diff --git a/noncore/settings/networksettings/ppp/pppimp.h b/noncore/settings/networksettings/ppp/pppimp.h
index 1bc1fad..a94139e 100644
--- a/noncore/settings/networksettings/ppp/pppimp.h
+++ b/noncore/settings/networksettings/ppp/pppimp.h
@@ -8,12 +8,14 @@ class PPPConfigureImp : public PPP {
8Q_OBJECT 8Q_OBJECT
9 9
10public: 10public:
11 PPPConfigureImp(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0); 11 PPPConfigureImp(QWidget* parent = 0, const char* name = 0, bool modal = true, WFlags fl = 0);
12 void setPeer(const QString &peer); 12 void setPeer(const QString &peer);
13 13
14protected: 14protected:
15 void accept(); 15 void accept();
16 16
17protected slots:
18 void queryModem();
17private: 19private:
18 QString peer; 20 QString peer;
19 21
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp
index 72cd45e..40d2455 100644
--- a/noncore/settings/networksettings/ppp/pppmodule.cpp
+++ b/noncore/settings/networksettings/ppp/pppmodule.cpp
@@ -1,6 +1,7 @@
1#include "pppmodule.h" 1#include "pppmodule.h"
2#include "pppimp.h" 2#include "pppimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4//#include "devices.h"
4 5
5/** 6/**
6 * Constructor, find all of the possible interfaces 7 * Constructor, find all of the possible interfaces
@@ -52,10 +53,9 @@ bool PPPModule::isOwner(Interface *i){
52 * @return QWidget* pointer to this modules configure. 53 * @return QWidget* pointer to this modules configure.
53 */ 54 */
54QWidget *PPPModule::configure(Interface *i){ 55QWidget *PPPModule::configure(Interface *i){
55 return NULL; 56 PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", /* i,*/ false, Qt::WDestructiveClose);
56 //PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", i, false, Qt::WDestructiveClose);
57 //pppconfig->setProfile(profile); 57 //pppconfig->setProfile(profile);
58 //return wlanconfig; 58 return pppconfig;
59} 59}
60 60
61/** 61/**
@@ -87,9 +87,12 @@ QList<Interface> PPPModule::getInterfaces(){
87 */ 87 */
88Interface *PPPModule::addNewInterface(const QString &newInterface){ 88Interface *PPPModule::addNewInterface(const QString &newInterface){
89 // If the 89 // If the
90 qDebug("try to add iface %s",newInterface.latin1());
90 PPPConfigureImp imp(0, "PPPConfigImp"); 91 PPPConfigureImp imp(0, "PPPConfigImp");
92 imp.showMaximized();
91 if(imp.exec() == QDialog::Accepted ){ 93 if(imp.exec() == QDialog::Accepted ){
92 94 qDebug("ACCEPTED");
95 return new Interface( 0, newInterface );
93 } 96 }
94 return NULL; 97 return NULL;
95} 98}
@@ -103,5 +106,10 @@ bool PPPModule::remove(Interface*){
103 return false; 106 return false;
104} 107}
105 108
106// pppmodule.cpp 109void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces)
110{
111 qDebug("here");
112 newIfaces.insert(QObject::tr("PPP") ,QObject::tr("generic ppp device"));
113}
114
107 115
diff --git a/noncore/settings/networksettings/ppp/pppmodule.h b/noncore/settings/networksettings/ppp/pppmodule.h
index c8e77e2..6464f87 100644
--- a/noncore/settings/networksettings/ppp/pppmodule.h
+++ b/noncore/settings/networksettings/ppp/pppmodule.h
@@ -17,7 +17,7 @@ public:
17 virtual QWidget *configure(Interface *i); 17 virtual QWidget *configure(Interface *i);
18 virtual QWidget *information(Interface *i); 18 virtual QWidget *information(Interface *i);
19 virtual QList<Interface> getInterfaces(); 19 virtual QList<Interface> getInterfaces();
20 virtual void possibleNewInterfaces(QMap<QString, QString> &){}; 20 virtual void possibleNewInterfaces(QMap<QString, QString> &);
21 virtual Interface *addNewInterface(const QString &name); 21 virtual Interface *addNewInterface(const QString &name);
22 virtual bool remove(Interface* i); 22 virtual bool remove(Interface* i);
23 virtual QString getPixmapName(Interface* i); 23 virtual QString getPixmapName(Interface* i);
diff --git a/noncore/settings/networksettings/ppp/runtests.cpp b/noncore/settings/networksettings/ppp/runtests.cpp
new file mode 100644
index 0000000..83ef2ea
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/runtests.cpp
@@ -0,0 +1,279 @@
1/*
2 * kPPP: A pppd front end for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * This file was contributed by Mario Weilguni <mweilguni@sime.com>
10 * Thanks Mario !
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <qdir.h>
28#include "runtests.h"
29#include <ctype.h>
30#include <unistd.h>
31#include <qmessagebox.h>
32#include <sys/stat.h>
33#include <stdlib.h>
34#include <sys/types.h>
35#include <pwd.h>
36#include <netinet/in.h>
37
38#ifdef HAVE_RESOLV_H
39#include <arpa/nameser.h>
40#include <resolv.h>
41#endif
42
43#ifndef _PATH_RESCONF
44#define _PATH_RESCONF "/etc/resolv.conf"
45#endif
46
47//#include <klocale.h>
48#define i18n QObject::tr
49#include "pppdata.h"
50
51// initial effective uid (main.cpp)
52extern uid_t euid;
53
54// secure pppd location (opener.cpp)
55extern const char* pppdPath();
56
57// shamelessly stolen from pppd-2.3.5
58/********************************************************************
59 *
60 * Internal routine to decode the version.modification.patch level
61 */
62
63static void decode_version (const char *_buf, int *version,
64 int *modification, int *patch)
65 {
66 char *buffer = qstrdup(_buf);
67 char *buf = buffer;
68 *version = (int) strtoul (buf, &buf, 10);
69 *modification = 0;
70 *patch = 0;
71
72 if (*buf == '.')
73 {
74 ++buf;
75 *modification = (int) strtoul (buf, &buf, 10);
76 if (*buf == '.')
77 {
78 ++buf;
79 *patch = (int) strtoul (buf, &buf, 10);
80 }
81 }
82
83 if (*buf != '\0')
84 {
85 *version =
86 *modification =
87 *patch = 0;
88 }
89
90 delete [] buffer;
91 }
92
93
94void pppdVersion(int *version, int *modification, int *patch) {
95 char buffer[30];
96 const char *pppd;
97 char *query;
98
99 *version = *modification = *patch = 0;
100
101 // locate pppd
102 if(!(pppd = pppdPath()))
103 return;
104
105 // call pppd with --version option
106 if(!(query = new char[strlen(pppd)+25]))
107 return;
108 strcpy(query, pppd);
109 // had to add a dummy device to prevent a "no device specified
110 // and stdin is not a tty" error from newer pppd versions.
111 strcat(query, " --version /dev/tty 2>&1");
112 fflush(0L);
113 FILE *output = popen(query, "r");
114 delete [] query;
115 if(!output)
116 return;
117
118 // read output
119 int size = fread(buffer, sizeof(char), 29, output);
120
121 if(ferror(output)) {
122 pclose(output);
123 return;
124 }
125 pclose(output);
126 buffer[size] = '\0';
127
128 // find position of version number x.y.z
129 char *p = buffer;
130 while(*p && !isdigit(*p))
131 p++;
132 if (*p == 0)
133 return;
134 char *p2 = p;
135 while(*p2 == '.' || isdigit(*p2))
136 p2++;
137 *p2 = '\0';
138
139 decode_version(p, version, modification, patch);
140}
141
142
143int uidFromName(const char *uname) {
144 struct passwd *pw;
145
146 setpwent();
147 while((pw = getpwent()) != NULL) {
148 if(strcmp(uname, pw->pw_name) == 0) {
149 int uid = pw->pw_uid;
150 endpwent();
151 return uid;
152 }
153 }
154
155 endpwent();
156 return -1;
157}
158
159
160const char *homedirFromUid(uid_t uid) {
161 struct passwd *pw;
162 char *d = 0;
163
164 setpwent();
165 while((pw = getpwent()) != NULL) {
166 if(pw->pw_uid == uid) {
167 d = strdup(pw->pw_dir);
168 endpwent();
169 return d;
170 }
171 }
172
173 endpwent();
174 return d;
175}
176
177
178const char* getHomeDir() {
179 static const char *hd = 0;
180 static bool ranTest = false;
181 if(!ranTest) {
182 hd = homedirFromUid(getuid());
183 ranTest = true;
184 }
185
186 return hd;
187}
188
189
190int runTests() {
191 int warning = 0;
192
193 // Test pre-1: check if the user is allowed to dial-out
194 if(access("/etc/kppp.allow", R_OK) == 0 && getuid() != 0) {
195 bool access = FALSE;
196 FILE *f;
197 if((f = fopen("/etc/kppp.allow", "r")) != NULL) {
198 char buf[2048]; // safe
199 while(f != NULL && !feof(f)) {
200 if(fgets(buf, sizeof(buf), f) != NULL) {
201 QString s(buf);
202
203 s = s.stripWhiteSpace();
204 if(s[0] == '#' || s.length() == 0)
205 continue;
206
207 if((uid_t)uidFromName(QFile::encodeName(s)) == getuid()) {
208 access = TRUE;
209 fclose(f);
210 f = NULL;
211 }
212 }
213 }
214 if(f)
215 fclose(f);
216 }
217
218 if(!access) {
219 QMessageBox::warning(0,"error",
220 i18n("You're not allowed to dial out with "
221 "kppp.\nContact your system administrator."));
222 return TEST_CRITICAL;
223 }
224 }
225
226 // Test 1: search the pppd binary
227 const char *f = pppdPath();
228
229 if(!f) {
230 QMessageBox::warning(0,"error",
231 i18n("Cannot find the PPP daemon!\n"
232 "Make sure that pppd is installed."));
233 warning++;
234 }
235
236 // Test 2: check access to the pppd binary
237 if(f) {
238#if 0
239 if(access(f, X_OK) != 0 /* && geteuid() != 0 */) {
240 KMessageBox::warning(0,
241 i18n("You do not have the permission "
242 "to start pppd!\n"
243 "Contact your system administrator "
244 "and ask to get access to pppd."));
245 return TEST_CRITICAL;
246 }
247#endif
248
249 if(geteuid() != 0) {
250 struct stat st;
251 stat(f, &st);
252 if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) {
253 QMessageBox::warning(0,"error",
254 i18n("You don't have sufficient permission to run\n"
255 "%1\n"
256 "Please make sure that kppp is owned by root "
257 "and has the SUID bit set.").arg(f));
258 warning++;
259 }
260 }
261 }
262
263 // Test 5: check for existence of /etc/resolv.conf
264 if (access(_PATH_RESCONF, R_OK) != 0) {
265 QString file = _PATH_RESCONF" ";
266 QString msgstr = i18n("%1 is missing or can't be read!\n"
267 "Ask your system administrator to create "
268 "this file (can be empty) with appropriate "
269 "read and write permissions.").arg(file);
270 QMessageBox::warning(0, "errror", msgstr);
271 warning ++;
272 }
273
274 if(warning == 0)
275 return TEST_OK;
276 else
277 return TEST_WARNING;
278}
279
diff --git a/noncore/settings/networksettings/ppp/runtests.h b/noncore/settings/networksettings/ppp/runtests.h
new file mode 100644
index 0000000..efb1197
--- a/dev/null
+++ b/noncore/settings/networksettings/ppp/runtests.h
@@ -0,0 +1,47 @@
1/*
2 * kPPP: A pppd front end for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * This file was contributed by Mario Weilguni <mweilguni@sime.com>
10 * Thanks Mario !
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#ifndef __RUNTESTS__H__
28#define __RUNTESTS__H__
29
30#define SYSOPTIONS "/etc/ppp/options"
31
32const int TEST_OK = 0;
33const int TEST_WARNING = 1;
34const int TEST_NOCONNECT = 2;
35const int TEST_CRITICAL = 3;
36
37// Various tests to be run at starttime
38int runTests();
39const char* getHomeDir();
40void pppdVersion(int *version, int *modification, int *patch);
41
42#ifdef __linux__
43bool ppp_available(void);
44#endif
45
46#endif
47