summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore 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.cpp33
-rw-r--r--noncore/settings/networksettings/ppp/pppimp.h4
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.cpp48
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.h6
-rw-r--r--noncore/settings/networksettings/ppp/runtests.cpp279
-rw-r--r--noncore/settings/networksettings/ppp/runtests.h47
16 files changed, 3495 insertions, 46 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 @@
+#ifndef _DEVICES_H_
+#define _DEVICES_H_
+
+#include "kpppconfig.h"
+
+static const char *devices[] = {
+#ifdef __FreeBSD__
+ "/dev/cuaa0",
+ "/dev/cuaa1",
+ "/dev/cuaa2",
+ "/dev/cuaa3",
+ "/dev/cuaa4",
+#elif defined(__NetBSD__)
+ "/dev/tty00", /* "normal" modem lines */
+ "/dev/tty01",
+ "/dev/tty02",
+ "/dev/tty03",
+ "/dev/dty00", /* Dial out devices */
+ "/dev/dty01",
+ "/dev/dty02",
+ "/dev/dty03",
+ "/dev/ttyU0", /* USB stuff modems */
+ "/dev/ttyU1",
+ "/dev/ttyU2",
+ "/dev/ttyU3",
+ "/dev/dtyU0", /* USB stuff, too (dial out device) */
+ "/dev/dtyU1",
+ "/dev/dtyU2",
+ "/dev/dtyU3",
+#elif defined (__linux__)
+ "/dev/modem",
+ "/dev/ttyS0",
+ "/dev/ttyS1",
+ "/dev/ttyS2",
+ "/dev/ttyS3",
+#ifdef ISDNSUPPORT
+ "/dev/ttyI0",
+ "/dev/ttyI1",
+ "/dev/ttyI2",
+ "/dev/ttyI3",
+#endif
+ "/dev/usb/ttyACM0", /* USB stuff modems */
+ "/dev/usb/ttyACM1",
+ "/dev/usb/ttyACM2",
+ "/dev/usb/ttyACM3",
+#elif defined(__svr4__)
+ "/dev/cua/a",
+ "/dev/cua/b",
+ "/dev/ttya",
+ "/dev/ttyb",
+#endif
+ 0};
+
+// default device number from the list above
+const int DEV_DEFAULT = 0;
+
+#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 @@
+/* -*- C++ -*-
+ * kPPP: A pppd front end for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#ifndef _KPPPCONFIG_H_
+#define _KPPPCONFIG_H_
+
+#if defined(__svr4__)
+#define STREAMS
+#define _XOPEN_SOURCE 1
+#define _XOPEN_SOURCE_EXTENDED 1
+#define __EXTENSIONS__
+#endif
+
+//#include <config.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+// Warning: If you fiddle with the following directories you have
+// to adjust make_directories() in main.cpp()
+
+// file used for PAP authetication purposes
+#define PAP_AUTH_FILE "/etc/ppp/pap-secrets"
+
+// file used for CHAP authetication purposes
+#define CHAP_AUTH_FILE "/etc/ppp/chap-secrets"
+
+// Define the default modem response timeout
+#define MODEM_TIMEOUT 60
+
+// Define the default modem tone duration (ATS11=)
+#define MODEM_TONEDURATION 70
+
+// Define the default time for pppd to get the interface up
+#define PPPD_TIMEOUT 30
+
+// Define the default time to wait after a busy signal before redialing
+#define BUSY_WAIT 0
+
+
+
+// Every PPP_STATS_INTERVAL milli seconds kppp will read
+// and display the ppp statistics IF the stats window
+// is visible. If the stats window is not visible
+// the stats are not taken.
+// 200 milli secs is 5 times per second and results in
+// 0 load on my machine. Play with this parameter if
+// you feel like it.
+
+#define PPP_STATS_INTERVAL 200
+// comment this out to get some more debugging info
+/*
+#define MY_DEBUG
+*/
+
+// Define the maximum number of accounts
+#define MAX_ACCOUNTS 100
+
+// Define the mamimum number of script entries
+#define MAX_SCRIPT_ENTRIES 20
+
+// Define the maximun number of DNS entries
+#define MAX_DNS_ENTRIES 5
+
+// Maximum size of the command executing pppd
+const unsigned int MAX_CMDLEN = 2024;
+
+// Define the maximum number of arguments passed to the pppd daemon
+#define MAX_PPPD_ARGUMENTS 20
+
+// Define the maximun number of lines of /etc/resolv.conf
+#define MAX_RESOLVCONF_LINES 128
+
+// Directory for modem lock files (Needed by mgetty users)
+#ifdef __linux__
+# define LOCK_DIR "/var/lock"
+#else /* linux */
+# ifdef BSD
+# define LOCK_DIR "/var/spool/lock"
+# else /* BSD */
+# define LOCK_DIR "/var/spool/locks"
+# endif /* BSD */
+#endif /* linux */
+
+#define DEVNULL "/dev/null"
+
+// search path for pppd binary
+#define PPPDSEARCHPATH "/sbin:/usr/sbin:/usr/local/sbin:/usr/bin:/usr/local/bin"
+
+// name of the pppd binary
+#define PPPDNAME "pppd"
+
+// support for internal ISDN cards and modem emulation
+#ifdef __linux__
+#define ISDNSUPPORT
+#endif
+
+#if defined(__linux__) || defined(BSD)
+#define PPP_PID_DIR "/var/run/"
+#else
+#define PPP_PID_DIR "/etc/ppp/"
+#endif
+
+// defined in opener.cpp
+extern const char * const kppp_syslog[];
+
+#ifdef _XPG4_2
+#define __xnet_connect connect
+#endif
+
+#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 @@
+/*
+ * kPPP: A pppd Front End for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * This file was added by Harri Porten <porten@tu-harburg.de>
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <setjmp.h>
+#include <qregexp.h>
+#include <assert.h>
+
+#include "modem.h"
+#include "pppdata.h"
+//#include "requester.h"
+//#include <klocale.h>
+#define i18n QObject::tr
+#define qError qDebug
+//#include <kdebug.h>
+//#include <config.h>
+
+#define MY_ASSERT(x) if (!(x)) { \
+ qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
+ exit(1); }
+
+
+static sigjmp_buf jmp_buffer;
+
+Modem *Modem::modem = 0;
+
+Modem::Modem() :
+ modemfd(-1),
+ sn(0L),
+ data_mode(false),
+ modem_is_locked(false)
+{
+ lockfile[0] = '\0';
+ device = "/dev/modem";
+ assert(modem==0);
+ modem = this;
+}
+
+
+Modem::~Modem() {
+ modem = 0;
+}
+
+
+speed_t Modem::modemspeed() {
+ // convert the string modem speed int the gpppdata object to a t_speed type
+ // to set the modem. The constants here should all be ifdef'd because
+ // other systems may not have them
+ int i = gpppdata.speed().toInt()/100;
+
+ switch(i) {
+ case 24:
+ return B2400;
+ break;
+ case 96:
+ return B9600;
+ break;
+ case 192:
+ return B19200;
+ break;
+ case 384:
+ return B38400;
+ break;
+#ifdef B57600
+ case 576:
+ return B57600;
+ break;
+#endif
+
+#ifdef B115200
+ case 1152:
+ return B115200;
+ break;
+#endif
+
+#ifdef B230400
+ case 2304:
+ return B230400;
+ break;
+#endif
+
+#ifdef B460800
+ case 4608:
+ return B460800;
+ break;
+#endif
+
+ default:
+ return B38400;
+ break;
+ }
+}
+
+bool Modem::opentty() {
+ // int flags;
+
+//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
+ close(modemfd);
+// device = "/dev/modem";//deviceByIndex(request.modem.deviceNum);
+ if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
+ qDebug("error opening modem device !");
+ errmsg = i18n("Unable to open modem.");
+ return false;
+ }
+//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
+//}
+
+#if 0
+ if(gpppdata.UseCDLine()) {
+ if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
+ errmsg = i18n("Unable to detect state of CD line.");
+ ::close(modemfd);
+ modemfd = -1;
+ return false;
+ }
+ if ((flags&TIOCM_CD) == 0) {
+ errmsg = i18n("The modem is not ready.");
+ ::close(modemfd);
+ modemfd = -1;
+ return false;
+ }
+ }
+#endif
+
+ tcdrain (modemfd);
+ tcflush (modemfd, TCIOFLUSH);
+
+ if(tcgetattr(modemfd, &tty) < 0){
+ // this helps in some cases
+ tcsendbreak(modemfd, 0);
+ sleep(1);
+ if(tcgetattr(modemfd, &tty) < 0){
+ errmsg = i18n("The modem is busy.");
+ ::close(modemfd);
+ modemfd = -1;
+ return false;
+ }
+ }
+
+ memset(&initial_tty,'\0',sizeof(initial_tty));
+
+ initial_tty = tty;
+
+ tty.c_cc[VMIN] = 0; // nonblocking
+ tty.c_cc[VTIME] = 0;
+ tty.c_oflag = 0;
+ tty.c_lflag = 0;
+
+ tty.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
+ tty.c_cflag |= CS8 | CREAD;
+ tty.c_cflag |= CLOCAL; // ignore modem status lines
+ tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ;
+ tty.c_lflag &= ~ICANON; // non-canonical mode
+ tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE);
+
+
+ if(gpppdata.flowcontrol() != "None") {
+ if(gpppdata.flowcontrol() == "CRTSCTS") {
+ tty.c_cflag |= CRTSCTS;
+ }
+ else {
+ tty.c_iflag |= IXON | IXOFF;
+ tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
+ tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
+ }
+ }
+ else {
+ tty.c_cflag &= ~CRTSCTS;
+ tty.c_iflag &= ~(IXON | IXOFF);
+ }
+
+ cfsetospeed(&tty, modemspeed());
+ cfsetispeed(&tty, modemspeed());
+
+ tcdrain(modemfd);
+
+ if(tcsetattr(modemfd, TCSANOW, &tty) < 0){
+ errmsg = i18n("The modem is busy.");
+ ::close(modemfd);
+ modemfd=-1;
+ return false;
+ }
+
+ errmsg = i18n("Modem Ready.");
+ return true;
+}
+
+
+bool Modem::closetty() {
+ if(modemfd >=0 ) {
+ stop();
+ /* discard data not read or transmitted */
+ tcflush(modemfd, TCIOFLUSH);
+
+ if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){
+ errmsg = i18n("Can't restore tty settings: tcsetattr()\n");
+ ::close(modemfd);
+ modemfd = -1;
+ return false;
+ }
+ ::close(modemfd);
+ modemfd = -1;
+ }
+
+ return true;
+}
+
+
+void Modem::readtty(int) {
+ char buffer[200];
+ unsigned char c;
+ int len;
+
+ // read data in chunks of up to 200 bytes
+ if((len = ::read(modemfd, buffer, 200)) > 0) {
+ // split buffer into single characters for further processing
+ for(int i = 0; i < len; i++) {
+ c = buffer[i] & 0x7F;
+ emit charWaiting(c);
+ }
+ }
+}
+
+
+void Modem::notify(const QObject *receiver, const char *member) {
+ connect(this, SIGNAL(charWaiting(unsigned char)), receiver, member);
+ startNotifier();
+}
+
+
+void Modem::stop() {
+ disconnect(SIGNAL(charWaiting(unsigned char)));
+ stopNotifier();
+}
+
+
+void Modem::startNotifier() {
+ if(modemfd >= 0) {
+ if(sn == 0) {
+ sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this);
+ connect(sn, SIGNAL(activated(int)), SLOT(readtty(int)));
+ qDebug("QSocketNotifier started!");
+ } else {
+ qDebug("QSocketNotifier re-enabled!");
+ sn->setEnabled(true);
+ }
+ }
+}
+
+
+void Modem::stopNotifier() {
+ if(sn != 0) {
+ sn->setEnabled(false);
+ disconnect(sn);
+ delete sn;
+ sn = 0;
+ qDebug( "QSocketNotifier stopped!" );
+ }
+}
+
+
+void Modem::flush() {
+ char c;
+ while(read(modemfd, &c, 1) == 1);
+}
+
+
+bool Modem::writeChar(unsigned char c) {
+ int s;
+ do {
+ s = write(modemfd, &c, 1);
+ if (s < 0) {
+ qError( "write() in Modem::writeChar failed" );
+ return false;
+ }
+ } while(s == 0);
+
+ return true;
+}
+
+
+bool Modem::writeLine(const char *buf) {
+ int len = strlen(buf);
+ char *b = new char[len+2];
+ memcpy(b, buf, len);
+ // different modems seem to need different line terminations
+ QString term = gpppdata.enter();
+ if(term == "LF")
+ b[len++]='\n';
+ else if(term == "CR")
+ b[len++]='\r';
+ else if(term == "CR/LF") {
+ b[len++]='\r';
+ b[len++]='\n';
+ }
+ int l = len;
+ while(l) {
+ int wr = write(modemfd, &b[len-l], l);
+ if(wr < 0) {
+ // TODO do something meaningful with the error code (or ignore it
+ qError( "write() in Modem::writeLine failed" );
+ delete[] b;
+ return false;
+ }
+ l -= wr;
+ }
+ delete[] b;
+ return true;
+}
+
+
+bool Modem::hangup() {
+ // this should really get the modem to hang up and go into command mode
+ // If anyone sees a fault in the following please let me know, since
+ // this is probably the most imporant snippet of code in the whole of
+ // kppp. If people complain about kppp being stuck, this piece of code
+ // is most likely the reason.
+ struct termios temptty;
+
+ if(modemfd >= 0) {
+
+ // is this Escape & HangupStr stuff really necessary ? (Harri)
+
+ if (data_mode) escape_to_command_mode();
+
+ // Then hangup command
+ writeLine(gpppdata.modemHangupStr().local8Bit());
+
+ usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 sec
+
+#ifndef DEBUG_WO_DIALING
+ if (sigsetjmp(jmp_buffer, 1) == 0) {
+ // set alarm in case tcsendbreak() hangs
+ signal(SIGALRM, alarm_handler);
+ alarm(2);
+
+ tcsendbreak(modemfd, 0);
+
+ alarm(0);
+ signal(SIGALRM, SIG_IGN);
+ } else {
+ // we reach this point if the alarm handler got called
+ closetty();
+ close(modemfd);
+ modemfd = -1;
+ errmsg = i18n("The modem does not respond.");
+ return false;
+ }
+
+#ifndef __svr4__ // drops DTR but doesn't set it afterwards again. not good for init.
+ tcgetattr(modemfd, &temptty);
+ cfsetospeed(&temptty, B0);
+ cfsetispeed(&temptty, B0);
+ tcsetattr(modemfd, TCSAFLUSH, &temptty);
+#else
+ int modemstat;
+ ioctl(modemfd, TIOCMGET, &modemstat);
+ modemstat &= ~TIOCM_DTR;
+ ioctl(modemfd, TIOCMSET, &modemstat);
+ ioctl(modemfd, TIOCMGET, &modemstat);
+ modemstat |= TIOCM_DTR;
+ ioctl(modemfd, TIOCMSET, &modemstat);
+#endif
+
+ usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 secs
+
+ cfsetospeed(&temptty, modemspeed());
+ cfsetispeed(&temptty, modemspeed());
+ tcsetattr(modemfd, TCSAFLUSH, &temptty);
+#endif
+ return true;
+ } else
+ return false;
+}
+
+
+void Modem::escape_to_command_mode() {
+ // Send Properly bracketed escape code to put the modem back into command state.
+ // A modem will accept AT commands only when it is in command state.
+ // When a modem sends the host the CONNECT string, that signals
+ // that the modem is now in the connect state (no long accepts AT commands.)
+ // Need to send properly timed escape sequence to put modem in command state.
+ // Escape codes and guard times are controlled by S2 and S12 values.
+ //
+ tcflush(modemfd, TCIOFLUSH);
+
+ // +3 because quiet time must be greater than guard time.
+ usleep((gpppdata.modemEscapeGuardTime()+3)*20000);
+ QCString tmp = gpppdata.modemEscapeStr().local8Bit();
+ write(modemfd, tmp.data(), tmp.length());
+ tcflush(modemfd, TCIOFLUSH);
+ usleep((gpppdata.modemEscapeGuardTime()+3)*20000);
+
+ data_mode = false;
+}
+
+
+const QString Modem::modemMessage() {
+ return errmsg;
+}
+
+
+QString Modem::parseModemSpeed(const QString &s) {
+ // this is a small (and bad) parser for modem speeds
+ int rx = -1;
+ int tx = -1;
+ int i;
+ QString result;
+
+ qDebug( "Modem reported result string: %s", s.latin1());
+
+ const int RXMAX = 7;
+ const int TXMAX = 2;
+ QRegExp rrx[RXMAX] = {
+ QRegExp("[0-9]+[:/ ]RX", false),
+ QRegExp("[0-9]+RX", false),
+ QRegExp("[/: -][0-9]+[/: ]", false),
+ QRegExp("[/: -][0-9]+$", false),
+ QRegExp("CARRIER [^0-9]*[0-9]+", false),
+ QRegExp("CONNECT [^0-9]*[0-9]+", false),
+ QRegExp("[0-9]+") // panic mode
+ };
+
+ QRegExp trx[TXMAX] = {
+ QRegExp("[0-9]+[:/ ]TX", false),
+ QRegExp("[0-9]+TX", false)
+ };
+
+ for(i = 0; i < RXMAX; i++) {
+ int len, idx, result;
+ if((idx = rrx[i].match(s,0,&len)) > -1) {
+// if((idx = rrx[i].search(s)) > -1) {
+ // len = rrx[i].matchedLength();
+
+ //
+ // rrx[i] has been matched, idx contains the start of the match
+ // and len contains how long the match is. Extract the match.
+ //
+ QString sub = s.mid(idx, len);
+
+ //
+ // Now extract the digits only from the match, which will
+ // then be converted to an int.
+ //
+ if ((idx = rrx[RXMAX-1].match( sub,0,&len )) > -1) {
+// if ((idx = rrx[RXMAX-1].search( sub )) > -1) {
+// len = rrx[RXMAX-1].matchedLength();
+ sub = sub.mid(idx, len);
+ result = sub.toInt();
+ if(result > 0) {
+ rx = result;
+ break;
+ }
+ }
+ }
+ }
+
+ for(i = 0; i < TXMAX; i++) {
+ int len, idx, result;
+ if((idx = trx[i].match(s,0,&len)) > -1) {
+// if((idx = trx[i].search(s)) > -1) {
+// len = trx[i].matchedLength();
+
+ //
+ // trx[i] has been matched, idx contains the start of the match
+ // and len contains how long the match is. Extract the match.
+ //
+ QString sub = s.mid(idx, len);
+
+ //
+ // Now extract the digits only from the match, which will then
+ // be converted to an int.
+ //
+ if((idx = rrx[RXMAX-1].match(sub,0,&len)) > -1) {
+// if((idx = rrx[RXMAX-1].search(sub)) > -1) {
+// len = rrx[RXMAX-1].matchedLength();
+ sub = sub.mid(idx, len);
+ result = sub.toInt();
+ if(result > 0) {
+ tx = result;
+ break;
+ }
+ }
+ }
+ }
+
+ if(rx == -1 && tx == -1)
+ result = i18n("Unknown speed");
+ else if(tx == -1)
+ result.setNum(rx);
+ else if(rx == -1) // should not happen
+ result.setNum(tx);
+ else
+ result.sprintf("%d/%d", rx, tx);
+
+ qDebug( "The parsed result is: %s", result.latin1());
+
+ return result;
+}
+
+
+// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
+// a lock file can't be created ( permission problem )
+int Modem::lockdevice() {
+ int fd;
+ char newlock[80]=""; // safe
+
+ if(!gpppdata.modemLockFile()) {
+ qDebug("The user doesn't want a lockfile.");
+ return 0;
+ }
+
+ if (modem_is_locked)
+ return 1;
+
+ QString lockfile = LOCK_DIR"/LCK..";
+ lockfile += gpppdata.modemDevice().mid(5); // append everything after /dev/
+
+ if(access(QFile::encodeName(lockfile), F_OK) == 0) {
+// if ((fd = Requester::rq->
+if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
+ // Mario: it's not necessary to read more than lets say 32 bytes. If
+ // file has more than 32 bytes, skip the rest
+ char oldlock[33]; // safe
+ int sz = read(fd, &oldlock, 32);
+ close (fd);
+ if (sz <= 0)
+ return 1;
+ oldlock[sz] = '\0';
+
+ qDebug( "Device is locked by: %s", oldlock);
+
+ int oldpid;
+ int match = sscanf(oldlock, "%d", &oldpid);
+
+ // found a pid in lockfile ?
+ if (match < 1 || oldpid <= 0)
+ return 1;
+
+ // check if process exists
+ if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH)
+ return 1;
+
+ qDebug( "lockfile is stale" );
+ }
+ }
+
+ fd = openLockfile(gpppdata.modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
+ if(fd >= 0) {
+ sprintf(newlock,"%010d\n", getpid());
+ qDebug("Locking Device: %s", newlock);
+
+ write(fd, newlock, strlen(newlock));
+ close(fd);
+ modem_is_locked=true;
+
+ return 0;
+ }
+
+ return -1;
+
+}
+
+
+// UnLock modem device
+void Modem::unlockdevice() {
+ if (modem_is_locked) {
+ qDebug( "UnLocking Modem Device" );
+ close(modemfd);
+ modemfd = -1;
+ unlink(lockfile);
+ lockfile[0] = '\0';
+ modem_is_locked=false;
+ }
+}
+
+int Modem::openLockfile( QString lockfile, int flags)
+{
+ int fd;
+ int mode;
+ flags = O_RDONLY;
+ if(flags == O_WRONLY|O_TRUNC|O_CREAT)
+ mode = 0644;
+ else
+ mode = 0;
+
+ lockfile = LOCK_DIR;
+ lockfile += "/LCK..";
+ lockfile += device.right( device.length() - device.findRev("/") -1 );
+ qDebug("lockfile >%s<",lockfile.latin1());
+ // TODO:
+ // struct stat st;
+ // if(stat(lockfile.data(), &st) == -1) {
+ // if(errno == EBADF)
+ // return -1;
+ // } else {
+ // // make sure that this is a regular file
+ // if(!S_ISREG(st.st_mode))
+ // return -1;
+ // }
+ if ((fd = open(lockfile, flags, mode)) == -1) {
+ qDebug("error opening lockfile!");
+ lockfile = QString::null;
+ fd = open(DEVNULL, O_RDONLY);
+ } else
+ fchown(fd, 0, 0);
+ return fd;
+}
+
+
+
+void alarm_handler(int) {
+ // fprintf(stderr, "alarm_handler(): Received SIGALRM\n");
+
+ // jump
+ siglongjmp(jmp_buffer, 1);
+}
+
+
+
+const char* pppdPath() {
+ // wasting a few bytes
+ static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)];
+ static char *pppdPath = 0L;
+ char *p;
+
+ if(pppdPath == 0L) {
+ const char *c = PPPDSEARCHPATH;
+ while(*c != '\0') {
+ while(*c == ':')
+ c++;
+ p = buffer;
+ while(*c != '\0' && *c != ':')
+ *p++ = *c++;
+ *p = '\0';
+ strcat(p, "/");
+ strcat(p, PPPDNAME);
+ if(access(buffer, F_OK) == 0)
+ return (pppdPath = buffer);
+ }
+ }
+
+ return pppdPath;
+}
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 @@
+/*
+ * kPPP: A pppd Front End for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * This file was added by Harri Porten <porten@tu-harburg.de>
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _MODEM_H_
+#define _MODEM_H_
+
+#include <qdir.h>
+
+#include <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <qsocketnotifier.h>
+
+//#include <config.h>
+
+void alarm_handler(int);
+const char *pppdPath();
+
+class Modem : public QObject {
+ Q_OBJECT
+public:
+ Modem();
+ ~Modem();
+
+ const QString getDevice() {return device;};
+ void setDevice(const QString dev) {device = dev;};
+
+ bool opentty();
+ bool closetty();
+ bool hangup();
+ bool writeChar(unsigned char);
+ bool writeLine(const char *);
+ bool dataMode() const { return data_mode; }
+ void setDataMode(bool set) { data_mode = set; }
+ const QString modemMessage();
+ speed_t modemspeed();
+ static QString parseModemSpeed(const QString &);
+ void notify(const QObject *, const char *);
+ void stop();
+ void flush();
+
+ int lockdevice();
+ void unlockdevice();
+
+public:
+ static Modem *modem;
+
+signals:
+ void charWaiting(unsigned char);
+
+private slots:
+ void startNotifier();
+ void stopNotifier();
+ void readtty(int);
+
+private:
+ void escape_to_command_mode();
+ int openLockfile(QString,int);
+
+private:
+ QString device;
+ QString lockfile;
+ int modemfd;
+ QSocketNotifier *sn;
+ bool data_mode;
+ QString errmsg;
+ struct termios initial_tty;
+ struct termios tty;
+ bool modem_is_locked;
+};
+
+#endif
+
+
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 @@
+/*
+ * kPPP: A front end for pppd for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * This file contributed by: Markus Wuebben, mwuebben@fiwi02.wiwi.uni-tuebingen.de
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <unistd.h>
+#include <qregexp.h>
+#include <qlayout.h>
+// #include <kwin.h>
+// #include <kmessagebox.h>
+// #include <kapplication.h>
+#include <qmessagebox.h>
+#include <qapplication.h>
+#include "modeminfo.h"
+#include "modem.h"
+//#include <klocale.h>
+#define i18n QObject::tr
+
+ModemTransfer::ModemTransfer(QWidget *parent, const char *name)
+ : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder)
+{
+ setCaption(i18n("ATI Query"));
+// KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
+
+ QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
+
+ progressBar = new QProgressBar(this, "bar");
+ progressBar->setTotalSteps(8);
+
+ statusBar = new QLabel(this,"sBar");
+ statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken);
+ statusBar->setAlignment(AlignCenter);
+
+ // This is a rather complicated case. Since we do not know which
+ // message is the widest in the national language, we'd to
+ // search all these messages. This is a little overkill, so I take
+ // the longest english message, translate it and give it additional
+ // 20 percent space. Hope this is enough.
+ statusBar->setText(i18n("Unable to create modem lock file."));
+ statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10);
+ statusBar->setFixedHeight(statusBar->sizeHint().height() + 4);
+
+ // set original text
+ statusBar->setText(i18n("Looking for modem..."));
+ progressBar->setFixedHeight(statusBar->minimumSize().height());
+ tl->addWidget(progressBar);
+ tl->addWidget(statusBar);
+
+ cancel = new QPushButton(i18n("Cancel"), this);
+ cancel->setFocus();
+ connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton()));
+
+ QHBoxLayout *l1 = new QHBoxLayout;
+ tl->addLayout(l1);
+ l1->addStretch(1);
+ l1->addWidget(cancel);
+
+ setFixedSize(sizeHint());
+
+ step = 0;
+
+ ////////////////////////////////////////////////
+
+ timeout_timer = new QTimer(this);
+ connect(timeout_timer, SIGNAL(timeout()), SLOT(time_out_slot()));
+
+ scripttimer = new QTimer(this);
+ connect(scripttimer, SIGNAL(timeout()), SLOT(do_script()));
+
+ timeout_timer->start(15000,TRUE); // 15 secs single shot
+ QTimer::singleShot(500, this, SLOT(init()));
+
+}
+
+
+void ModemTransfer::ati_done() {
+ scripttimer->stop();
+ timeout_timer->stop();
+ Modem::modem->closetty();
+ Modem::modem->unlockdevice();
+ hide();
+
+ // open the result window
+ ModemInfo *mi = new ModemInfo(this);
+ for(int i = 0; i < NUM_OF_ATI; i++)
+ mi->setAtiString(i, ati_query_strings[i]);
+ mi->exec();
+ delete mi;
+
+ accept();
+}
+
+
+void ModemTransfer::time_out_slot() {
+ timeout_timer->stop();
+ scripttimer->stop();
+
+ QMessageBox::warning(this, tr("Error"), i18n("Modem Query timed out."));
+ reject();
+}
+
+
+void ModemTransfer::init() {
+
+ qApp->processEvents();
+
+ int lock = Modem::modem->lockdevice();
+ if (lock == 1) {
+
+ statusBar->setText(i18n("Modem device is locked."));
+ return;
+ }
+
+ if (lock == -1) {
+
+ statusBar->setText(i18n("Unable to create modem lock file."));
+ return;
+ }
+
+
+ if(Modem::modem->opentty()) {
+ if(Modem::modem->hangup()) {
+ usleep(100000); // wait 0.1 secs
+ Modem::modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ...
+
+ statusBar->setText(i18n("Modem Ready"));
+ qApp->processEvents();
+ usleep(100000); // wait 0.1 secs
+ qApp->processEvents();
+ scripttimer->start(1000); // this one does the ati query
+
+ // clear modem buffer
+ Modem::modem->flush();
+
+ Modem::modem->notify(this, SLOT(readChar(unsigned char)));
+ return;
+ }
+ }
+
+ // opentty() or hangup() failed
+ statusBar->setText(Modem::modem->modemMessage());
+ step = 99; // wait until cancel is pressed
+ Modem::modem->unlockdevice();
+}
+
+
+void ModemTransfer::do_script() {
+ QString msg;
+ QString query;
+
+ switch(step) {
+ case 0:
+ readtty();
+ statusBar->setText("ATI...");
+ progressBar->setProgress( progressBar->progress() + 1);
+ Modem::modem->writeLine("ATI\n");
+ break;
+
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ readtty();
+ msg.sprintf("ATI %d ...", step);
+ query.sprintf("ATI%d\n", step);
+ statusBar->setText(msg);
+ progressBar->setProgress( progressBar->progress() + 1);
+ Modem::modem->writeLine(query.local8Bit());
+ break;
+
+ default:
+ readtty();
+ ati_done();
+ }
+ step++;
+}
+
+void ModemTransfer::readChar(unsigned char c) {
+ if(readbuffer.length() < 255)
+ readbuffer += c;
+}
+
+void ModemTransfer::readtty() {
+
+ if (step == 0)
+ return;
+
+ readbuffer.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r
+ readbuffer = readbuffer.stripWhiteSpace(); // strip of leading or trailing white
+ // space
+
+ if(step <= NUM_OF_ATI)
+ ati_query_strings[step-1] = readbuffer.copy();
+
+ readbuffer = "";
+}
+
+
+void ModemTransfer::cancelbutton() {
+ scripttimer->stop();
+ Modem::modem->stop();
+ timeout_timer->stop();
+
+ statusBar->setText(i18n("One moment please..."));
+ qApp->processEvents();
+
+ Modem::modem->hangup();
+
+ Modem::modem->closetty();
+ Modem::modem->unlockdevice();
+ reject();
+}
+
+
+void ModemTransfer::closeEvent( QCloseEvent *e ) {
+ cancelbutton();
+ e->accept();
+}
+
+
+ModemInfo::ModemInfo(QWidget *parent, const char* name)
+ : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder)
+{
+ QString label_text;
+
+ setCaption(i18n("Modem Query Results"));
+ // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
+
+ QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
+
+ QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5);
+ tl->addLayout(l1, 1);
+ for(int i = 0 ; i < NUM_OF_ATI ; i++) {
+
+ label_text = "";
+ if ( i == 0)
+ label_text.sprintf("ATI :");
+ else
+ label_text.sprintf("ATI %d:", i );
+
+ ati_label[i] = new QLabel(label_text, this);
+ l1->addWidget(ati_label[i], i, 0);
+
+ ati_label_result[i] = new QLineEdit(this);
+ ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24);
+ l1->addWidget(ati_label_result[i], i, 1);
+ }
+ //tl->addSpacing(1);
+
+ QHBoxLayout *l2 = new QHBoxLayout;
+ QPushButton *ok = new QPushButton(i18n("Close"), this);
+ ok->setDefault(TRUE);
+ ok->setFocus();
+
+ tl->addLayout(l2);
+ l2->addStretch(1);
+
+ connect(ok, SIGNAL(clicked()), SLOT(accept()));
+ l2->addWidget(ok);
+
+ setMinimumSize(sizeHint());
+}
+
+
+void ModemInfo::setAtiString(int i, QString s) {
+ if(i < NUM_OF_ATI)
+ ati_label_result[i]->setText(s);
+}
+
+//#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 @@
+/*
+ *
+ * kPPP: A front end for pppd for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+
+#ifndef _MODEMINFO_H_
+#define _MODEMINFO_H_
+
+#include <qdialog.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qevent.h>
+#include <qtimer.h>
+//#include <kprogress.h>
+#include <qprogressbar.h>
+
+const int NUM_OF_ATI = 8;
+
+
+class ModemTransfer : public QDialog {
+ Q_OBJECT
+public:
+ ModemTransfer(QWidget *parent=0, const char *name=0);
+
+public slots:
+ void init();
+ void readtty();
+ void do_script();
+ void time_out_slot();
+ void cancelbutton();
+ void readChar(unsigned char);
+
+private:
+ void ati_done();
+
+protected:
+ void closeEvent(QCloseEvent *e);
+
+private:
+ int step;
+ QString readbuffer;
+
+ QPushButton *cancel;
+ QProgressBar *progressBar;
+ QLabel *statusBar;
+
+ QTimer *timeout_timer;
+ QTimer *scripttimer;
+ QString ati_query_strings[NUM_OF_ATI];
+};
+
+
+class ModemInfo : public QDialog {
+ Q_OBJECT
+public:
+ ModemInfo(QWidget *parent=0, const char *name=0);
+
+public:
+ void setAtiString(int num, QString s);
+
+private:
+ QLabel *ati_label[NUM_OF_ATI];
+ QLineEdit *ati_label_result[NUM_OF_ATI];
+};
+
+#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,16 +1,17 @@
+#TEMPLATE = app
TEMPLATE = lib
-CONFIG += qt warn_on release
-#CONFIG += qt warn_on debug
+#CONFIG += qt warn_on release
+CONFIG += qt warn_on debug
DESTDIR = $(OPIEDIR)/plugins/networksettings
-HEADERS = pppimp.h pppmodule.h
-SOURCES = pppimp.cpp pppmodule.cpp
+HEADERS = pppimp.h pppmodule.h devices.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h
+SOURCES = pppimp.cpp pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp
INCLUDEPATH += $(OPIEDIR)/include ../ ../interfaces/
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -L../interfaces/ -linterfaces
INTERFACES = ppp.ui
TARGET = pppplugin
VERSION = 1.0.0
include ( $(OPIEDIR)/include.pro )
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
@@ -2,29 +2,36 @@
<class>PPP</class>
<widget>
<class>QDialog</class>
<property stdset="1">
<name>name</name>
<cstring>PPP</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>277</width>
- <height>340</height>
+ <width>355</width>
+ <height>418</height>
</rect>
</property>
<property stdset="1">
+ <name>sizePolicy</name>
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>3</vsizetype>
+ </sizepolicy>
+ </property>
+ <property stdset="1">
<name>caption</name>
<string>Dial-up </string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
@@ -190,76 +197,116 @@
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>tab</cstring>
</property>
<attribute>
<name>title</name>
<string>Modem</string>
</attribute>
<grid>
<property stdset="1">
<name>margin</name>
- <number>6</number>
+ <number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>4</number>
+ <number>6</number>
</property>
+ <widget row="4" column="2" rowspan="1" colspan="3" >
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>PushButtonQuery</cstring>
+ </property>
+ <property stdset="1">
+ <name>sizePolicy</name>
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ </sizepolicy>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Query Modem</string>
+ </property>
+ </widget>
+ <widget row="4" column="1" >
+ <class>QComboBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>ComboBoxDevice</cstring>
+ </property>
+ </widget>
+ <widget row="4" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1_6</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Device</string>
+ </property>
+ </widget>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel3_2_2</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>AT-dial</string>
</property>
</widget>
- <widget row="0" column="1" rowspan="1" colspan="3" >
+ <widget row="0" column="1" rowspan="1" colspan="4" >
<class>QComboBox</class>
<item>
<property>
<name>text</name>
<string>ATDT</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>ATDP</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>atdial</cstring>
</property>
<property stdset="1">
<name>editable</name>
<bool>true</bool>
</property>
+ <property stdset="1">
+ <name>currentItem</name>
+ <number>0</number>
+ </property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1_4</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Speed</string>
</property>
</widget>
- <widget row="1" column="1" rowspan="1" colspan="3" >
+ <widget row="1" column="1" rowspan="1" colspan="4" >
<class>QComboBox</class>
<item>
<property>
<name>text</name>
<string>4800</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>9600</string>
</property>
@@ -288,25 +335,25 @@
<string>115200</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>speed</cstring>
</property>
<property stdset="1">
<name>currentItem</name>
<number>5</number>
</property>
</widget>
- <widget row="3" column="1" >
+ <widget row="3" column="1" rowspan="1" colspan="2" >
<class>QSlider</class>
<property stdset="1">
<name>name</name>
<cstring>connectdelay</cstring>
</property>
<property stdset="1">
<name>minValue</name>
<number>1</number>
</property>
<property stdset="1">
<name>maxValue</name>
<number>180</number>
@@ -322,114 +369,121 @@
</widget>
<widget row="3" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1_3</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Wait time</string>
</property>
</widget>
- <widget row="3" column="2" >
+ <widget row="3" column="3" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>connectdelay_text</cstring>
</property>
<property stdset="1">
<name>minimumSize</name>
<size>
<width>15</width>
<height>0</height>
</size>
</property>
<property stdset="1">
<name>text</name>
<string>6</string>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignVCenter|AlignRight</set>
</property>
<property>
<name>hAlign</name>
</property>
</widget>
- <widget row="3" column="3" >
+ <widget row="3" column="4" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel5</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>sec</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel3</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Flow control</string>
</property>
</widget>
- <widget row="2" column="1" rowspan="1" colspan="3" >
+ <widget row="2" column="1" rowspan="1" colspan="4" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>crtscts</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Hardware flow control</string>
</property>
<property stdset="1">
<name>checked</name>
<bool>true</bool>
</property>
</widget>
- <spacer row="4" column="1" >
+ <spacer row="5" column="1" >
<property>
<name>name</name>
<cstring>Spacer5</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Vertical</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
- <widget row="5" column="0" rowspan="1" colspan="4" >
+ <widget row="6" column="0" rowspan="1" colspan="5" >
<class>QButtonGroup</class>
<property stdset="1">
<name>name</name>
<cstring>dialmode</cstring>
</property>
<property stdset="1">
+ <name>sizePolicy</name>
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>5</vsizetype>
+ </sizepolicy>
+ </property>
+ <property stdset="1">
<name>title</name>
<string>Demand Dialing</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</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 @@
+/*
+ * kPPP: A pppd front end for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * based on EzPPP:
+ * Copyright (C) 1997 Jay Painter
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "pppdata.h"
+#include "runtests.h"
+#include "devices.h"
+//#include <klocale.h>
+#define i18n QObject::tr
+#include <qpe/config.h>
+#include <qmessagebox.h>
+#include <qapplication.h>
+// #include <klocale.h>
+// #include <kconfig.h>
+// #include <kmessagebox.h>
+// #include <kapplication.h>
+#include <assert.h>
+
+PPPData gpppdata;
+
+
+PPPData::PPPData()
+ : config(0L),
+ highcount(-1), // start out with no entries
+ caccount(-1), // set the current account index also
+ suidprocessid(-1), // process ID of setuid child
+ pppdisrunning(false),
+ pppderror(0)
+{
+}
+
+
+//
+// open configuration file
+//
+bool PPPData::open() {
+
+ config = new Config("NetworkSetup");
+ /*
+ config = kapp->config();
+
+ if (config->getConfigState() == KConfig::NoAccess) {
+ KMessageBox::error(0L,
+ i18n("The application-specific config file could not "
+ "be opened in either read-write or read-only mode.\n"
+ "The superuser might have to change its ownership "
+ "by issuing the following command in your home directory:\n"
+ "chown {YourUsername} .kde/share/config/kppprc"),
+ kapp->name());
+ return false;
+ }
+
+ // don't expand shell variables
+ config->setDollarExpansion(false);
+ */
+
+ highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
+
+ if (highcount > MAX_ACCOUNTS)
+ highcount = MAX_ACCOUNTS;
+
+ if(highcount >= 0 && defaultAccount().isEmpty()) {
+ setAccountbyIndex(0);
+ setDefaultAccount(accname());
+ } else if(!setAccount(defaultAccount()))
+ setDefaultAccount(accname());
+
+ // start out with internal debugging disabled
+ // the user is still free to specify `debug' on his own
+ setPPPDebug(false);
+
+ ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
+
+ return true;
+}
+
+
+//
+// save configuration
+//
+void PPPData::save() {
+
+ if (config) {
+ writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
+// config->sync();
+ }
+
+}
+
+
+//
+// cancel changes
+//
+void PPPData::cancel() {
+
+// if (config) {
+// config->rollback();
+// config->reparseConfiguration();
+// }
+
+}
+
+
+// currently differentiates between READWRITE and NONE only
+int PPPData::access() const {
+
+ return 0;//config->getConfigState();
+}
+
+
+// functions to read/write date to configuration file
+QString PPPData::readConfig(const QString &group, const QString &key,
+ const QString &defvalue = "")
+{
+ if (config) {
+ config->setGroup(group);
+ return config->readEntry(key, defvalue);
+ } else
+ return defvalue;
+}
+
+
+int PPPData::readNumConfig(const QString &group, const QString &key,
+ int defvalue) {
+ if (config) {
+ config->setGroup(group);
+ return config->readNumEntry(key, defvalue);
+ } else
+ return defvalue;
+
+}
+
+
+bool PPPData::readListConfig(const QString &group, const QString &key,
+ QStringList &list, char sep) {
+ list.clear();
+ if (config) {
+ config->setGroup(group);
+ list = config->readListEntry(key, sep);
+ return true;
+ } else
+ return false;
+}
+
+
+void PPPData::writeConfig(const QString &group, const QString &key,
+ const QString &value) {
+ if (config) {
+ config->setGroup(group);
+ config->writeEntry(key, value);
+ }
+}
+
+
+void PPPData::writeConfig(const QString &group, const QString &key, int value) {
+ if (config) {
+ config->setGroup(group);
+ config->writeEntry(key, value);
+ }
+}
+
+
+void PPPData::writeListConfig(const QString &group, const QString &key,
+ QStringList &list, char sep) {
+ if (config) {
+ config->setGroup(group);
+ config->writeEntry(key, list, sep);
+ }
+}
+
+
+//
+// functions to set/return general information
+//
+QString PPPData::password() const {
+ return passwd;
+}
+
+
+void PPPData::setPassword(const QString &pw) {
+ passwd = pw;
+}
+
+
+const QString PPPData::defaultAccount() {
+ return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY);
+}
+
+
+void PPPData::setDefaultAccount(const QString &n) {
+ writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n);
+
+ //now set the current account index to the default account
+ setAccount(defaultAccount());
+}
+
+
+bool PPPData::get_show_clock_on_caption() {
+ return (bool) readNumConfig(GENERAL_GRP, SHOWCLOCK_KEY, true);
+}
+
+
+void PPPData::set_show_clock_on_caption(bool set) {
+ writeConfig(GENERAL_GRP, SHOWCLOCK_KEY, (int) set);
+}
+
+
+bool PPPData::get_xserver_exit_disconnect() {
+ return (bool) readNumConfig(GENERAL_GRP, DISCONNECT_KEY, true);
+}
+
+
+void PPPData::setPPPDebug(bool set) {
+ writeConfig(GENERAL_GRP, PPP_DEBUG_OPTION, (int)set);
+}
+
+
+bool PPPData::getPPPDebug() {
+ return (bool)readNumConfig(GENERAL_GRP, PPP_DEBUG_OPTION, false);
+}
+
+
+void PPPData::set_xserver_exit_disconnect(bool set) {
+ writeConfig(GENERAL_GRP, DISCONNECT_KEY, (int) set);
+}
+
+
+bool PPPData::quit_on_disconnect() {
+ return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false);
+}
+
+
+void PPPData::set_quit_on_disconnect(bool set) {
+ writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set);
+}
+
+
+bool PPPData::get_show_log_window() {
+ return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false);
+}
+
+
+void PPPData::set_show_log_window(bool set) {
+ writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set);
+}
+
+
+bool PPPData::automatic_redial() {
+ return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE);
+}
+
+
+void PPPData::set_automatic_redial(bool set) {
+ writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set);
+}
+
+
+bool PPPData::get_iconify_on_connect() {
+ return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE);
+}
+
+
+void PPPData::set_iconify_on_connect(bool set) {
+ writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set);
+}
+
+
+bool PPPData::get_dock_into_panel() {
+ return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false);
+}
+
+
+void PPPData::set_dock_into_panel(bool set) {
+ writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set);
+}
+
+
+QString PPPData::pppdVersion() {
+ return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch);
+}
+
+bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
+ // check if pppd version fulfills minimum requirement
+ return (pppdVer > ver
+ || (pppdVer == ver && pppdMod > mod)
+ || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
+}
+
+int PPPData::pppdTimeout() {
+ return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
+}
+
+
+void PPPData::setpppdTimeout(int n) {
+ writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
+}
+
+
+const QString PPPData::modemDevice() {
+ return readConfig (MODEM_GRP, MODEMDEV_KEY, devices[DEV_DEFAULT]);
+}
+
+
+void PPPData::setModemDevice(const QString &n) {
+ writeConfig(MODEM_GRP, MODEMDEV_KEY, n);
+}
+
+
+const QString PPPData::flowcontrol() {
+ return readConfig(MODEM_GRP, FLOWCONTROL_KEY, "CRTSCTS");
+}
+
+
+void PPPData::setFlowcontrol(const QString &n) {
+ writeConfig(MODEM_GRP, FLOWCONTROL_KEY, n);
+}
+
+
+const QString PPPData::speed() {
+ QString s = readConfig(MODEM_GRP, SPEED_KEY, "57600");
+ // undo the damage of a bug in former versions. It left an empty Speed=
+ // entry in kppprc. kppp did set the serial port to 57600 as default but
+ // pppd wouldn't receive the speed via the command line.
+ if(s.toUInt() == 0)
+ s = "57600";
+ return s;
+}
+
+
+void PPPData::setSpeed(const QString &n) {
+ writeConfig(MODEM_GRP, SPEED_KEY, n);
+}
+
+
+#if 0
+void PPPData::setUseCDLine(const int n) {
+ writeConfig(MODEM_GRP,USECDLINE_KEY,n);
+}
+
+
+int PPPData::UseCDLine() {
+ return readNumConfig(MODEM_GRP,USECDLINE_KEY,0);
+}
+#endif
+
+const QString PPPData::modemEscapeStr() {
+ return readConfig(MODEM_GRP,ESCAPESTR_KEY,"+++");
+}
+
+
+void PPPData::setModemEscapeStr(const QString &n) {
+ writeConfig(MODEM_GRP,ESCAPESTR_KEY,n);
+}
+
+
+const QString PPPData::modemEscapeResp() {
+ return readConfig(MODEM_GRP,ESCAPERESP_KEY,"OK");
+}
+
+
+void PPPData::setModemEscapeResp(const QString &n) {
+ writeConfig(MODEM_GRP,ESCAPERESP_KEY,n);
+}
+
+
+int PPPData::modemEscapeGuardTime() {
+ return readNumConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,50);
+}
+
+
+void PPPData::setModemEscapeGuardTime(int n) {
+ writeConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,n);
+}
+
+
+bool PPPData::modemLockFile() {
+ return readNumConfig(MODEM_GRP, LOCKFILE_KEY, 1);
+}
+
+
+void PPPData::setModemLockFile(bool set) {
+ writeConfig(MODEM_GRP, LOCKFILE_KEY, set);
+}
+
+
+int PPPData::modemTimeout() {
+ return readNumConfig(MODEM_GRP, TIMEOUT_KEY, MODEM_TIMEOUT);
+}
+
+
+void PPPData::setModemTimeout(int n) {
+ writeConfig(MODEM_GRP, TIMEOUT_KEY, n);
+}
+
+
+int PPPData::modemToneDuration() {
+ return readNumConfig(MODEM_GRP, TONEDURATION_KEY,MODEM_TONEDURATION);
+}
+
+
+void PPPData::setModemToneDuration(int n) {
+ writeConfig(MODEM_GRP, TONEDURATION_KEY, n);
+}
+
+
+int PPPData::busyWait() {
+ return readNumConfig(MODEM_GRP, BUSYWAIT_KEY, BUSY_WAIT);
+}
+
+
+void PPPData::setbusyWait(int n) {
+ writeConfig(MODEM_GRP, BUSYWAIT_KEY, n);
+}
+
+
+//
+//Advanced "Modem" dialog
+//
+// defaults: InitString=ATZ, InitString1="" etc.
+const QString PPPData::modemInitStr(int i) {
+ assert(i >= 0 && i < NumInitStrings);
+ if(i == 0)
+ return readConfig(MODEM_GRP, INITSTR_KEY, "ATZ");
+ else
+ return readConfig(MODEM_GRP, INITSTR_KEY + QString::number(i), "");
+}
+
+
+void PPPData::setModemInitStr(int i, const QString &n) {
+ assert(i >= 0 && i < NumInitStrings);
+ QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : "");
+ writeConfig(MODEM_GRP, k, n);
+}
+
+
+const QString PPPData::modemInitResp() {
+ return readConfig(MODEM_GRP, INITRESP_KEY, "OK");
+}
+
+
+void PPPData::setModemInitResp(const QString &n) {
+ writeConfig(MODEM_GRP, INITRESP_KEY, n);
+}
+
+
+int PPPData::modemPreInitDelay() {
+ return readNumConfig(MODEM_GRP, PREINITDELAY_KEY, 50);
+}
+
+
+void PPPData::setModemPreInitDelay(int n) {
+ writeConfig(MODEM_GRP, PREINITDELAY_KEY, n);
+}
+
+
+int PPPData::modemInitDelay() {
+ return readNumConfig(MODEM_GRP, INITDELAY_KEY, 50);
+}
+
+
+void PPPData::setModemInitDelay(int n) {
+ writeConfig(MODEM_GRP, INITDELAY_KEY, n);
+}
+
+QString PPPData::modemNoDialToneDetectionStr() {
+ return readConfig(MODEM_GRP, NODTDETECT_KEY, "ATX3");
+}
+
+void PPPData::setModemNoDialToneDetectionStr(const QString &n) {
+ writeConfig(MODEM_GRP, NODTDETECT_KEY, n);
+}
+
+const QString PPPData::modemDialStr() {
+ return readConfig(MODEM_GRP, DIALSTR_KEY, "ATDT");
+}
+
+
+void PPPData::setModemDialStr(const QString &n) {
+ writeConfig(MODEM_GRP, DIALSTR_KEY, n);
+}
+
+
+const QString PPPData::modemConnectResp() {
+ return readConfig(MODEM_GRP, CONNECTRESP_KEY, "CONNECT");
+}
+
+
+void PPPData::setModemConnectResp(const QString &n) {
+ writeConfig(MODEM_GRP, CONNECTRESP_KEY, n);
+}
+
+
+const QString PPPData::modemBusyResp() {
+ return readConfig(MODEM_GRP, BUSYRESP_KEY, "BUSY");
+}
+
+
+void PPPData::setModemBusyResp(const QString &n) {
+ writeConfig(MODEM_GRP, BUSYRESP_KEY, n);
+}
+
+
+const QString PPPData::modemNoCarrierResp() {
+ return readConfig(MODEM_GRP, NOCARRIERRESP_KEY, "NO CARRIER");
+}
+
+
+void PPPData::setModemNoCarrierResp(const QString &n) {
+ writeConfig(MODEM_GRP, NOCARRIERRESP_KEY, n);
+}
+
+
+const QString PPPData::modemNoDialtoneResp() {
+ return readConfig(MODEM_GRP, NODIALTONERESP_KEY, "NO DIALTONE");
+}
+
+
+void PPPData::setModemNoDialtoneResp(const QString &n) {
+ writeConfig(MODEM_GRP, NODIALTONERESP_KEY, n);
+}
+
+
+const QString PPPData::modemHangupStr() {
+ return readConfig(MODEM_GRP, HANGUPSTR_KEY, "+++ATH");
+}
+
+void PPPData::setModemHangupStr(const QString &n) {
+ writeConfig(MODEM_GRP, HANGUPSTR_KEY, n);
+}
+
+
+const QString PPPData::modemHangupResp() {
+ return readConfig(MODEM_GRP, HANGUPRESP_KEY, "OK");
+}
+
+void PPPData::setModemHangupResp(const QString &n) {
+ writeConfig(MODEM_GRP, HANGUPRESP_KEY, n);
+}
+
+
+const QString PPPData::modemAnswerStr() {
+ return readConfig(MODEM_GRP, ANSWERSTR_KEY, "ATA");
+}
+
+
+QString PPPData::volumeOff() {
+ return readConfig(MODEM_GRP, VOLUME_OFF, "M0L0");
+}
+
+
+void PPPData::setVolumeOff(const QString &s) {
+ writeConfig(MODEM_GRP, VOLUME_OFF, s);
+}
+
+
+QString PPPData::volumeMedium() {
+ return readConfig(MODEM_GRP, VOLUME_MEDIUM, "M1L1");
+}
+
+
+void PPPData::setVolumeMedium(const QString &s) {
+ writeConfig(MODEM_GRP, VOLUME_MEDIUM, s);
+}
+
+
+QString PPPData::volumeHigh() {
+ QString tmp = readConfig(MODEM_GRP, VOLUME_HIGH, "M1L3");
+ if(tmp == "M1L4")
+ tmp = "M1L3";
+ return tmp;
+}
+
+
+void PPPData::setVolumeHigh(const QString &s) {
+ writeConfig(MODEM_GRP, VOLUME_HIGH, s);
+}
+
+
+QString PPPData::volumeInitString() {
+ QString s;
+
+ switch(volume()) {
+ case 0:
+ s = volumeOff();
+ break;
+ case 1:
+ s = volumeMedium();
+ break;
+ case 2:
+ s = volumeHigh();
+ break;
+ default:
+ s = volumeMedium();
+ }
+
+ return s;
+}
+
+
+int PPPData::volume() {
+ return readNumConfig(MODEM_GRP, VOLUME_KEY, 1);
+}
+
+
+void PPPData::setVolume(int i) {
+ writeConfig(MODEM_GRP, VOLUME_KEY, i);
+}
+
+int PPPData::waitForDialTone() {
+ return readNumConfig(MODEM_GRP, DIALTONEWAIT_KEY, 1);
+}
+
+void PPPData::setWaitForDialTone(int i) {
+ writeConfig(MODEM_GRP, DIALTONEWAIT_KEY, i);
+}
+
+void PPPData::setModemAnswerStr(const QString &n) {
+ writeConfig(MODEM_GRP, ANSWERSTR_KEY, n);
+}
+
+
+const QString PPPData::modemRingResp() {
+ return readConfig(MODEM_GRP, RINGRESP_KEY, "RING");
+}
+
+
+void PPPData::setModemRingResp(const QString &n) {
+ writeConfig(MODEM_GRP, RINGRESP_KEY, n);
+}
+
+
+const QString PPPData::modemAnswerResp() {
+ return readConfig(MODEM_GRP, ANSWERRESP_KEY, "CONNECT");
+}
+
+
+void PPPData::setModemAnswerResp(const QString &n) {
+ writeConfig(MODEM_GRP, ANSWERRESP_KEY, n);
+}
+
+
+const QString PPPData::enter() {
+ return readConfig(MODEM_GRP, ENTER_KEY, "CR");
+}
+
+
+void PPPData::setEnter(const QString &n) {
+ writeConfig(MODEM_GRP, ENTER_KEY, n);
+}
+
+
+//
+// functions to set/return account information
+//
+
+//returns number of accounts
+int PPPData::count() const {
+ return highcount + 1;
+}
+
+
+bool PPPData::setAccount(const QString &aname) {
+ for(int i = 0; i <= highcount; i++) {
+ setAccountbyIndex(i);
+ if(accname() == aname) {
+ caccount = i;
+ return true;
+ }
+ }
+ return false;
+}
+
+
+bool PPPData::setAccountbyIndex(int i) {
+ if(i >= 0 && i <= highcount) {
+ caccount = i;
+ cgroup.sprintf("%s%i", ACCOUNT_GRP, i);
+ return true;
+ }
+ return false;
+}
+
+
+bool PPPData::isUniqueAccname(const QString &n) {
+ int current = caccount;
+ for(int i=0; i <= highcount; i++) {
+ setAccountbyIndex(i);
+ if(accname() == n && i != current) {
+ setAccountbyIndex(current);
+ return false;
+ }
+ }
+ setAccountbyIndex(current);
+ return true;
+}
+
+
+bool PPPData::deleteAccount() {
+ if(caccount < 0)
+ return false;
+
+// QMap <QString, QString> map;
+// QMap <QString, QString>::Iterator it;
+
+ // set all entries of the current account to ""
+// tille: do not handle the accounts here... (?)
+// map = config->entryMap(cgroup);
+// it = map.begin();
+// while (it != map.end()) {
+// config->writeEntry(it.key(), "");
+// it++;
+// }
+
+// // shift the succeeding accounts
+// for(int i = caccount+1; i <= highcount; i++) {
+// setAccountbyIndex(i);
+// map = config->entryMap(cgroup);
+// it = map.begin();
+// setAccountbyIndex(i-1);
+// config->setGroup(cgroup);
+// while (it != map.end()) {
+// config->writeEntry(it.key(), *it);
+// it++;
+// }
+// }
+
+// // make sure the top account is cleared
+// setAccountbyIndex(highcount);
+// map = config->entryMap(cgroup);
+// it = map.begin();
+// config->setGroup(cgroup);
+// while (it.key() != QString::null) {
+// config->writeEntry(it.key(), "");
+// it++;
+// }
+
+ highcount--;
+ if(caccount > highcount)
+ caccount = highcount;
+
+ setAccountbyIndex(caccount);
+
+ return true;
+}
+
+
+bool PPPData::deleteAccount(const QString &aname) {
+ if(!setAccount(aname))
+ return false;
+
+ deleteAccount();
+
+ return true;
+}
+
+
+int PPPData::newaccount() {
+
+ if(!config || highcount >= MAX_ACCOUNTS)
+ return -1;
+
+ highcount++;
+ setAccountbyIndex(highcount);
+
+ setpppdArgumentDefaults();
+
+ return caccount;
+}
+
+int PPPData::copyaccount(int i) {
+
+ if(highcount >= MAX_ACCOUNTS)
+ return -1;
+
+ setAccountbyIndex(i);
+
+// QMap <QString, QString> map = config->entryMap(cgroup);
+// QMap <QString, QString>::ConstIterator it = map.begin();
+
+ QString newname = i18n("%1_copy").arg(accname());
+
+ newaccount();
+
+// while (it != map.end()) {
+// config->writeEntry(it.key(), *it);
+// it++;
+// }
+
+ setAccname(newname);
+
+ return caccount;
+}
+
+
+const QString PPPData::accname() {
+ return readConfig(cgroup, NAME_KEY);
+}
+
+void PPPData::setAccname(const QString &n) {
+ if(!cgroup.isNull()) {
+ // are we manipulating the default account's name ? then change it, too.
+ bool def = accname() == defaultAccount();
+ writeConfig(cgroup, NAME_KEY, n);
+ if (def)
+ setDefaultAccount(n);
+ }
+}
+
+
+#define SEPARATOR_CHAR ':'
+QStringList &PPPData::phonenumbers() {
+
+ readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
+ return phonelist;
+
+}
+
+
+const QString PPPData::phonenumber() {
+ return readConfig(cgroup, PHONENUMBER_KEY);
+}
+
+
+void PPPData::setPhonenumber(const QString &n) {
+ writeConfig(cgroup, PHONENUMBER_KEY, n);
+}
+
+
+const QString PPPData::dialPrefix() {
+ return readConfig(cgroup, DIAL_PREFIX_KEY, "");
+}
+
+
+void PPPData::setDialPrefix(const QString &s) {
+ writeConfig(cgroup, DIAL_PREFIX_KEY, s);
+}
+
+
+int PPPData::authMethod() {
+ return readNumConfig(cgroup, AUTH_KEY, 0);
+}
+
+
+void PPPData::setAuthMethod(int value) {
+ writeConfig(cgroup, AUTH_KEY, value);
+}
+
+
+const QString PPPData::storedUsername() {
+ return readConfig(cgroup, STORED_USERNAME_KEY, "");
+}
+
+
+void PPPData::setStoredUsername(const QString &b) {
+ writeConfig(cgroup, STORED_USERNAME_KEY, b);
+}
+
+
+const QString PPPData::storedPassword() {
+ return readConfig(cgroup, STORED_PASSWORD_KEY, "");
+}
+
+
+void PPPData::setStoredPassword(const QString &b) {
+ writeConfig(cgroup, STORED_PASSWORD_KEY, b);
+}
+
+
+bool PPPData::storePassword() {
+ return (bool)readNumConfig(cgroup, STORE_PASSWORD_KEY, 1);
+}
+
+
+const QString PPPData::command_before_connect() {
+ return readConfig(cgroup, BEFORE_CONNECT_KEY);
+}
+
+
+void PPPData::setCommand_before_connect(const QString &n) {
+ writeConfig(cgroup, BEFORE_CONNECT_KEY, n);
+}
+
+
+void PPPData::setStorePassword(bool b) {
+ writeConfig(cgroup, STORE_PASSWORD_KEY, (int)b);
+}
+
+
+const QString PPPData::command_on_connect() {
+ return readConfig(cgroup, COMMAND_KEY);
+}
+
+
+void PPPData::setCommand_on_connect(const QString &n) {
+ writeConfig(cgroup, COMMAND_KEY, n);
+}
+
+
+const QString PPPData::command_on_disconnect() {
+ return readConfig(cgroup, DISCONNECT_COMMAND_KEY);
+}
+
+
+void PPPData::setCommand_on_disconnect(const QString &n) {
+ writeConfig(cgroup, DISCONNECT_COMMAND_KEY, n);
+}
+
+
+const QString PPPData::command_before_disconnect() {
+ return readConfig(cgroup, BEFORE_DISCONNECT_KEY);
+}
+
+
+void PPPData::setCommand_before_disconnect(const QString &n) {
+ writeConfig(cgroup, BEFORE_DISCONNECT_KEY, n);
+}
+
+
+const QString PPPData::ipaddr() {
+ return readConfig(cgroup, IPADDR_KEY);
+}
+
+
+void PPPData::setIpaddr(const QString &n) {
+ writeConfig(cgroup, IPADDR_KEY, n);
+}
+
+
+const QString PPPData::subnetmask() {
+ return readConfig(cgroup, SUBNETMASK_KEY);
+}
+
+
+void PPPData::setSubnetmask(const QString &n) {
+ writeConfig(cgroup, SUBNETMASK_KEY, n);
+}
+
+
+bool PPPData::autoname() {
+ return (bool) readNumConfig(cgroup, AUTONAME_KEY, false);
+}
+
+
+void PPPData::setAutoname(bool set) {
+ writeConfig(cgroup, AUTONAME_KEY, (int) set);
+}
+
+
+bool PPPData::AcctEnabled() {
+ return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false);
+}
+
+
+void PPPData::setAcctEnabled(bool set) {
+ writeConfig(cgroup, ACCTENABLED_KEY, (int) set);
+}
+
+
+int PPPData::VolAcctEnabled() {
+ return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0);
+}
+
+
+void PPPData::setVolAcctEnabled(int set) {
+ writeConfig(cgroup, VOLACCTENABLED_KEY, set);
+}
+
+
+const QString PPPData::gateway() {
+ return readConfig(cgroup, GATEWAY_KEY);
+}
+
+
+void PPPData::setGateway(const QString &n ) {
+ writeConfig(cgroup, GATEWAY_KEY, n);
+}
+
+
+bool PPPData::defaultroute() {
+ // default route is by default 'on'.
+ return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true);
+}
+
+
+void PPPData::setDefaultroute(bool set) {
+ writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set);
+}
+
+
+bool PPPData::autoDNS() {
+ bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true);
+ return (set && gpppdata.pppdVersionMin(2, 3, 7));
+}
+
+
+void PPPData::setAutoDNS(bool set) {
+ writeConfig(cgroup, AUTODNS_KEY, (int) set);
+}
+
+
+void PPPData::setExDNSDisabled(bool set) {
+ writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set);
+}
+
+
+bool PPPData::exDNSDisabled() {
+ return (bool) readNumConfig(cgroup, EXDNSDISABLED_KEY,0);
+}
+
+
+QStringList &PPPData::dns() {
+ static QStringList dnslist;
+
+ readListConfig(cgroup, DNS_KEY, dnslist);
+ while(dnslist.count() > MAX_DNS_ENTRIES)
+ dnslist.remove(dnslist.last());
+
+ return dnslist;
+}
+
+
+void PPPData::setDns(QStringList &list) {
+ writeListConfig(cgroup, DNS_KEY, list);
+}
+
+
+const QString PPPData::domain() {
+ return readConfig(cgroup, DOMAIN_KEY);
+}
+
+
+void PPPData::setDomain(const QString &n ) {
+ writeConfig(cgroup, DOMAIN_KEY, n);
+}
+
+
+QStringList &PPPData::scriptType() {
+ static QStringList typelist;
+
+ readListConfig(cgroup, SCRIPTCOM_KEY, typelist);
+ while(typelist.count() > MAX_SCRIPT_ENTRIES)
+ typelist.remove(typelist.last());
+
+ return typelist;
+}
+
+
+void PPPData::setScriptType(QStringList &list) {
+ writeListConfig(cgroup, SCRIPTCOM_KEY, list);
+}
+
+
+QStringList &PPPData::script() {
+ static QStringList scriptlist;
+
+ readListConfig(cgroup, SCRIPTARG_KEY, scriptlist);
+ while(scriptlist.count() > MAX_SCRIPT_ENTRIES)
+ scriptlist.remove(scriptlist.last());
+
+ return scriptlist;
+}
+
+
+void PPPData::setScript(QStringList &list) {
+ writeListConfig(cgroup, SCRIPTARG_KEY, list);
+}
+
+
+const QString PPPData::accountingFile() {
+ return readConfig(cgroup, ACCTFILE_KEY);
+}
+
+
+void PPPData::setAccountingFile(const QString &n) {
+ writeConfig(cgroup, ACCTFILE_KEY, n);
+}
+
+
+const QString PPPData::totalCosts() {
+ return readConfig(cgroup, TOTALCOSTS_KEY);
+}
+
+
+void PPPData::setTotalCosts(const QString &n) {
+ writeConfig(cgroup, TOTALCOSTS_KEY, n);
+}
+
+
+int PPPData::totalBytes() {
+ return readNumConfig(cgroup, TOTALBYTES_KEY, 0);
+}
+
+void PPPData::setTotalBytes(int n) {
+ writeConfig(cgroup, TOTALBYTES_KEY, n);
+}
+
+
+QStringList &PPPData::pppdArgument() {
+ static QStringList arglist;
+
+ while(arglist.count() > MAX_PPPD_ARGUMENTS)
+ arglist.remove(arglist.last());
+ readListConfig(cgroup, PPPDARG_KEY, arglist);
+
+ return arglist;
+}
+
+
+void PPPData::setpppdArgument(QStringList &args) {
+ writeListConfig(cgroup, PPPDARG_KEY, args);
+}
+
+
+void PPPData::setpppdArgumentDefaults() {
+ QStringList arg;
+ setpppdArgument(arg);
+}
+
+
+// graphing widget
+void PPPData::setGraphingOptions(bool enable,
+ QColor bg,
+ QColor text,
+ QColor in,
+ QColor out)
+{
+ if(config) {
+ config->setGroup(GRAPH_GRP);
+ config->writeEntry(GENABLED, enable);
+// config->writeEntry(GCOLOR_BG, bg);
+// config->writeEntry(GCOLOR_TEXT, text);
+// config->writeEntry(GCOLOR_IN, in);
+// config->writeEntry(GCOLOR_OUT, out);
+ }
+}
+
+void PPPData::graphingOptions(bool &enable,
+ QColor &bg,
+ QColor &text,
+ QColor &in,
+ QColor &out)
+{
+ QColor c;
+
+ if(config) {
+ config->setGroup(GRAPH_GRP);
+ enable = config->readBoolEntry(GENABLED, true);
+ bg = Qt::white;
+ //bg = config->readColorEntry(GCOLOR_BG, &c);
+ text = Qt::black;
+ //text = config->readColorEntry(GCOLOR_TEXT, &c);
+ in = Qt::blue;
+ //in = config->readColorEntry(GCOLOR_IN, &c);
+ out = Qt::red;
+ //out = config->readColorEntry(GCOLOR_OUT, &c);
+ }
+}
+
+
+bool PPPData::graphingEnabled() {
+ return (bool) readNumConfig(GRAPH_GRP, GENABLED, true);
+}
+
+
+
+//
+//functions to change/set the child pppd process info
+//
+bool PPPData::pppdRunning() const {
+ return pppdisrunning;
+}
+
+void PPPData::setpppdRunning(bool set) {
+ pppdisrunning = set;
+}
+
+int PPPData::pppdError() const {
+ return pppderror;
+}
+
+void PPPData::setpppdError(int err) {
+ pppderror = err;
+}
+
+
+//
+// window position
+//
+void PPPData::winPosConWin(int& p_x, int& p_y) {
+ p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160);
+ p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55);
+}
+
+void PPPData::setWinPosConWin(int p_x, int p_y) {
+ writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x);
+ writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y);
+}
+
+void PPPData::winPosStatWin(int& p_x, int& p_y) {
+ p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160);
+ p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55);
+}
+
+void PPPData::setWinPosStatWin(int p_x, int p_y) {
+ writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x);
+ writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y);
+}
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 @@
+/* -*- C++ -*-
+ *
+ * kPPP: A pppd front end for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * based on EzPPP:
+ * Copyright (C) 1997 Jay Painter
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _PPPDATA_H_
+#define _PPPDATA_H_
+
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qcolor.h>
+
+#include "kpppconfig.h"
+
+class Config;
+
+// string lengths
+
+#define PATH_SIZE 120
+#define MODEMSTR_SIZE 80
+#define ACCNAME_SIZE 50
+#define PHONENUMBER_SIZE 60
+#define COMMAND_SIZE 255
+#define IPADDR_SIZE 15
+#define DOMAIN_SIZE 50
+#define TIMEOUT_SIZE 60
+
+//
+// keys for config file
+//
+
+// groups
+#define GENERAL_GRP "General"
+#define MODEM_GRP "Modem"
+#define ACCOUNT_GRP "Account"
+#define GRAPH_GRP "Graph"
+#define WINPOS_GRP "WindowPosition"
+
+// general
+#define DEFAULTACCOUNT_KEY "DefaultAccount"
+#define PPPDVERSION_KEY "pppdVersion"
+#define PPPDTIMEOUT_KEY "pppdTimeout"
+#define SHOWCLOCK_KEY "ShowClock"
+#define SHOWLOGWIN_KEY "ShowLogWindow"
+#define AUTOREDIAL_KEY "AutomaticRedial"
+#define DISCONNECT_KEY "DisconnectOnXServerExit"
+#define QUITONDISCONNECT_KEY "QuitOnDisconnect"
+#define NUMACCOUNTS_KEY "NumberOfAccounts"
+#define ID_KEY "ID"
+
+// modem
+#define MODEMDEV_KEY "Device"
+#define LOCKFILE_KEY "UseLockFile"
+#define FLOWCONTROL_KEY "FlowControl"
+#define SPEED_KEY "Speed"
+#define TIMEOUT_KEY "Timeout"
+#define TONEDURATION_KEY "ToneDuration"
+#define BUSYWAIT_KEY "BusyWait"
+#define INITSTR_KEY "InitString"
+#define INITRESP_KEY "InitResponse"
+#define PREINITDELAY_KEY "PreInitDelay"
+#define INITDELAY_KEY "InitDelay"
+#define NODTDETECT_KEY "NoDialToneDetection"
+#define DIALTONEWAIT_KEY "WaitForDialTone"
+#define DIALSTR_KEY "DialString"
+#define CONNECTRESP_KEY "ConnectResponse"
+#define BUSYRESP_KEY "BusyResponse"
+#define NOCARRIERRESP_KEY "NoCarrierResponse"
+#define NODIALTONERESP_KEY "NoDialToneResp"
+#define HANGUPSTR_KEY "HangupString"
+#define HANGUPRESP_KEY "HangUpResponse"
+#define ANSWERSTR_KEY "AnswerString"
+#define RINGRESP_KEY "RingResponse"
+#define ANSWERRESP_KEY "AnswerResponse"
+#define ENTER_KEY "Enter"
+#define ESCAPESTR_KEY "EscapeString"
+#define ESCAPERESP_KEY "EscapeResponse"
+#define ESCAPEGUARDTIME_KEY "EscapeGuardTime"
+#define USECDLINE_KEY "UseCDLine"
+#define VOLUME_HIGH "VolumeHigh"
+#define VOLUME_MEDIUM "VolumeMedium"
+#define VOLUME_OFF "VolumeOff"
+#define VOLUME_KEY "Volume"
+
+// account
+#define NAME_KEY "Name"
+#define PHONENUMBER_KEY "Phonenumber"
+#define DIAL_PREFIX_KEY "DialPrefix"
+#define AUTH_KEY "Authentication"
+#define STORED_PASSWORD_KEY "Password"
+#define STORED_USERNAME_KEY "Username"
+#define STORE_PASSWORD_KEY "StorePassword"
+#define BEFORE_CONNECT_KEY "BeforeConnect"
+#define COMMAND_KEY "Command"
+#define DISCONNECT_COMMAND_KEY "DisconnectCommand"
+#define BEFORE_DISCONNECT_KEY "BeforeDisconnect"
+#define IPADDR_KEY "IPAddr"
+#define SUBNETMASK_KEY "SubnetMask"
+#define ACCTENABLED_KEY "AccountingEnabled"
+#define VOLACCTENABLED_KEY "VolumeAccountingEnabled"
+#define ACCTFILE_KEY "AccountingFile"
+#define AUTONAME_KEY "AutoName"
+#define GATEWAY_KEY "Gateway"
+#define DEFAULTROUTE_KEY "DefaultRoute"
+#define DOMAIN_KEY "Domain"
+#define DNS_KEY "DNS"
+#define AUTODNS_KEY "AutoDNS"
+#define EXDNSDISABLED_KEY "ExDNSDisabled"
+#define SCRIPTCOM_KEY "ScriptCommands"
+#define SCRIPTARG_KEY "ScriptArguments"
+#define PPPDARG_KEY "pppdArguments"
+#define PPP_DEBUG_OPTION "PPPDebug"
+#define ICONIFY_ON_CONNECT_KEY "iconifyOnConnect"
+#define DOCKING_KEY "DockIntoPanel"
+#define TOTALCOSTS_KEY "TotalCosts"
+#define TOTALBYTES_KEY "TotalBytes"
+
+// graph colors
+#define GENABLED "Enabled"
+#define GCOLOR_BG "Background"
+#define GCOLOR_TEXT "Text"
+#define GCOLOR_IN "InBytes"
+#define GCOLOR_OUT "OutBytes"
+
+// pppd errors
+#define E_IF_TIMEOUT 1
+#define E_PPPD_DIED 2
+
+// window position
+#define WINPOS_CONWIN_X "WindowPositionConWinX"
+#define WINPOS_CONWIN_Y "WindowPositionConWinY"
+#define WINPOS_STATWIN_X "WindowPositionStatWinX"
+#define WINPOS_STATWIN_Y "WindowPositionStatWinY"
+
+class PPPData {
+public:
+ PPPData();
+ ~PPPData() {};
+
+ enum { NumInitStrings = 2 };
+
+ // general functions
+ bool open();
+ void save();
+ void cancel();
+ int access() const; // read/write access
+
+ // function to read/write date to configuration file
+ QString readConfig(const QString &, const QString &, const QString &);
+ int readNumConfig(const QString &, const QString &, int);
+ bool readListConfig(const QString &, const QString &,
+ QStringList &, char sep = ',');
+ void writeConfig(const QString &, const QString &, const QString &);
+ void writeConfig(const QString &, const QString &, int);
+ void writeListConfig(const QString &, const QString &,
+ QStringList &, char sep = ',');
+
+ // return the current account group
+ QString currentGroup() { return cgroup; }
+
+ // functions to set/get general kppp info
+ QString password() const;
+ void setPassword(const QString &);
+
+ const QString defaultAccount();
+ void setDefaultAccount(const QString &);
+
+ void set_xserver_exit_disconnect(bool set);
+ bool get_xserver_exit_disconnect();
+
+ void setPPPDebug(bool set);
+ bool getPPPDebug();
+
+ void set_quit_on_disconnect(bool);
+ bool quit_on_disconnect();
+
+ void set_show_clock_on_caption(bool set);
+ bool get_show_clock_on_caption();
+
+ void set_show_log_window(bool set);
+ bool get_show_log_window();
+
+ void set_automatic_redial(bool set);
+ bool automatic_redial();
+
+ void set_iconify_on_connect(bool set);
+ bool get_iconify_on_connect();
+
+ void set_dock_into_panel(bool set);
+ bool get_dock_into_panel();
+
+ const QString enter();
+ void setEnter(const QString &);
+
+ QString pppdVersion();
+ bool pppdVersionMin(int ver, int mod, int patch);
+
+ int pppdTimeout();
+ void setpppdTimeout(int);
+
+ int busyWait();
+ void setbusyWait(int);
+
+ bool modemLockFile();
+ void setModemLockFile(bool set);
+
+ int modemEscapeGuardTime();
+ void setModemEscapeGuardTime(int i);
+
+ void setModemEscapeStr(const QString &);
+ const QString modemEscapeStr();
+
+ void setModemEscapeResp(const QString &);
+ const QString modemEscapeResp();
+
+ const QString modemDevice();
+ void setModemDevice(const QString &);
+
+ const QString flowcontrol();
+ void setFlowcontrol(const QString &);
+
+ int modemTimeout();
+ void setModemTimeout(int);
+
+ int modemToneDuration();
+ void setModemToneDuration(int);
+
+ QString volumeInitString();
+ int volume();
+ void setVolume(int);
+
+ int waitForDialTone();
+ void setWaitForDialTone(int i);
+
+ // modem command strings/responses
+ const QString modemInitStr(int i);
+ void setModemInitStr(int i, const QString &);
+
+ const QString modemInitResp();
+ void setModemInitResp(const QString &);
+
+ int modemPreInitDelay();
+ void setModemPreInitDelay(int);
+
+ int modemInitDelay();
+ void setModemInitDelay(int);
+
+ QString modemNoDialToneDetectionStr();
+ void setModemNoDialToneDetectionStr(const QString &);
+
+ const QString modemDialStr();
+ void setModemDialStr(const QString &);
+
+ const QString modemConnectResp();
+ void setModemConnectResp(const QString &);
+
+ const QString modemBusyResp();
+ void setModemBusyResp(const QString &);
+
+ const QString modemNoCarrierResp();
+ void setModemNoCarrierResp(const QString &);
+
+ const QString modemNoDialtoneResp();
+ void setModemNoDialtoneResp(const QString &);
+
+ const QString modemHangupStr();
+ void setModemHangupStr(const QString &);
+
+ const QString modemHangupResp();
+ void setModemHangupResp(const QString &);
+
+ const QString modemAnswerStr();
+ void setModemAnswerStr(const QString &);
+
+ const QString modemRingResp();
+ void setModemRingResp(const QString &);
+
+ const QString modemAnswerResp();
+ void setModemAnswerResp(const QString &);
+
+ QString volumeOff();
+ void setVolumeOff(const QString &);
+
+ QString volumeMedium();
+ void setVolumeMedium(const QString &);
+
+ QString volumeHigh();
+ void setVolumeHigh(const QString &);
+
+#if 0
+ void setUseCDLine(const int n);
+ int UseCDLine();
+#endif
+
+ // functions to set/get account information
+ int count() const;
+ bool setAccount(const QString &);
+ bool setAccountbyIndex(int);
+
+ bool isUniqueAccname(const QString &);
+
+ bool deleteAccount();
+ bool deleteAccount(const QString &);
+ int newaccount();
+ int copyaccount(int i);
+
+ const QString accname();
+ void setAccname(const QString &);
+
+ QStringList &phonenumbers();
+ const QString phonenumber();
+ void setPhonenumber(const QString &);
+
+ const QString dialPrefix();
+ void setDialPrefix(const QString &);
+
+ int authMethod();
+ void setAuthMethod(int);
+
+ const QString storedUsername();
+ void setStoredUsername(const QString &);
+
+ const QString storedPassword();
+ void setStoredPassword(const QString &);
+
+ bool storePassword();
+ void setStorePassword(bool);
+
+ const QString speed();
+ void setSpeed(const QString &);
+
+ const QString command_before_connect();
+ void setCommand_before_connect(const QString &);
+
+ const QString command_on_connect();
+ void setCommand_on_connect(const QString &);
+
+ const QString command_on_disconnect();
+ void setCommand_on_disconnect(const QString &);
+
+ const QString command_before_disconnect();
+ void setCommand_before_disconnect(const QString &);
+
+ const QString ipaddr();
+ void setIpaddr(const QString &);
+
+ const QString subnetmask();
+ void setSubnetmask(const QString &);
+
+ bool AcctEnabled();
+ void setAcctEnabled(bool set);
+
+ int VolAcctEnabled();
+ void setVolAcctEnabled(int set);
+
+ bool autoDNS();
+ void setAutoDNS(bool set);
+
+ bool exDNSDisabled();
+ void setExDNSDisabled(bool set);
+
+ bool autoname();
+ void setAutoname(bool set);
+
+ const QString gateway();
+ void setGateway(const QString &);
+
+ bool defaultroute();
+ void setDefaultroute(bool set);
+
+ QStringList &dns();
+ void setDns(QStringList &);
+
+ const QString domain();
+ void setDomain(const QString &);
+
+ QStringList &scriptType();
+ void setScriptType(QStringList &);
+
+ QStringList &script();
+ void setScript(QStringList &);
+
+ QStringList &pppdArgument();
+ void setpppdArgumentDefaults();
+ void setpppdArgument(QStringList &);
+
+ //functions to change/set the child pppd process info
+ bool pppdRunning() const;
+ void setpppdRunning(bool set);
+
+ int pppdError() const;
+ void setpppdError(int err);
+
+ // functions to set/query the accounting info
+ const QString accountingFile();
+ void setAccountingFile(const QString &);
+
+ const QString totalCosts();
+ void setTotalCosts(const QString &);
+
+ int totalBytes();
+ void setTotalBytes(int);
+
+ // graphing widget
+ void setGraphingOptions(bool enabled,
+ QColor bg,
+ QColor text,
+ QColor in,
+ QColor out);
+ void graphingOptions(bool &enabled,
+ QColor &bg,
+ QColor &text,
+ QColor &in,
+ QColor &out);
+ bool graphingEnabled();
+
+ // window positions
+ void winPosConWin(int &, int &);
+ void setWinPosConWin(int, int);
+ void winPosStatWin(int &, int &);
+ void setWinPosStatWin(int, int);
+
+private:
+ QString passwd;
+ Config* config; // configuration object
+ int highcount; // index of highest account
+ int caccount; // index of the current account
+ QString cgroup; // name of current config group
+ pid_t suidprocessid; // process ID of setuid child
+ bool pppdisrunning; // pppd process
+ // daemon
+ int pppderror; // error encounterd running pppd
+ int pppdVer, pppdMod, pppdPatch; // pppd version
+
+ QStringList phonelist;
+};
+
+extern PPPData gpppdata;
+
+#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,39 +1,60 @@
+
+#include <qcombobox.h>
+#include <qpushbutton.h>
+
#include "pppimp.h"
+#include "devices.h"
+#include "modem.h"
+#include "modeminfo.h"
+//#include "pppdata.h"
+
PPPConfigureImp::PPPConfigureImp( QWidget* parent, const char* name, bool modal, WFlags fl) : PPP(parent, name, modal, fl) {
+ for(int i = 0; devices[i]; i++)
+ ComboBoxDevice->insertItem(devices[i]);
+ connect(PushButtonQuery, SIGNAL(clicked()), SLOT(queryModem()));
}
/**
* Open up the peers file and read any set settings
* @param peer the peer file to edit.
- */
+ */
void PPPConfigureImp::setPeer(const QString &newPeer){
peer = newPeer;
}
/**
* Save the settings for the current peer.
- */
+ */
void PPPConfigureImp::accept(){
// Check to make sure that all of the inputs are valid.
// Save settings.
/**
/dev/modem or just modem
<speed> any
defaultroute - automaticly add route
noipdefault - get an ip from the server
usepeerdns - automaticly add dns
crtscts - flow control enabled
name <name> - user name (and do secret file)
-*/
-
+*/
+
// Make sure it is set in interfaces so pon/off can be used.
// Close out the dialog
QDialog::accept();
}
-
-// pppconfigureimp.h
+
+void PPPConfigureImp::queryModem()
+{
+
+ Modem::modem = new Modem();
+ qDebug("setting device");
+// gpppdata.setModemDevice(ComboBoxDevice->currentText());
+ qDebug("open dialog");
+ ModemTransfer mt(this);
+ mt.exec();
+}
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
@@ -1,25 +1,27 @@
#ifndef PPPIMP_H
#define PPPIMP_H
#include "ppp.h"
class PPPConfigureImp : public PPP {
Q_OBJECT
public:
- PPPConfigureImp(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0);
+ PPPConfigureImp(QWidget* parent = 0, const char* name = 0, bool modal = true, WFlags fl = 0);
void setPeer(const QString &peer);
protected:
void accept();
+protected slots:
+ void queryModem();
private:
QString peer;
};
#endif
// pppconfigureimp.h
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,107 +1,115 @@
#include "pppmodule.h"
#include "pppimp.h"
#include "interfaceinformationimp.h"
+//#include "devices.h"
/**
* Constructor, find all of the possible interfaces
- */
+ */
PPPModule::PPPModule() : Module() {
}
/**
* Delete any interfaces that we own.
- */
+ */
PPPModule::~PPPModule(){
Interface *i;
for ( i=list.first(); i != 0; i=list.next() )
delete i;
}
/**
* Change the current profile
- */
+ */
void PPPModule::setProfile(const QString &newProfile){
profile = newProfile;
}
/**
* get the icon name for this device.
* @param Interface* can be used in determining the icon.
- * @return QString the icon name (minus .png, .gif etc)
- */
+ * @return QString the icon name (minus .png, .gif etc)
+ */
QString PPPModule::getPixmapName(Interface* ){
return "ppp";
}
/**
* Check to see if the interface i is owned by this module.
* @param Interface* interface to check against
* @return bool true if i is owned by this module, false otherwise.
- */
+ */
bool PPPModule::isOwner(Interface *i){
if(!i->getInterfaceName().upper().contains("PPP"))
return false;
-
+
i->setHardwareName("PPP");
list.append(i);
return true;
}
/**
* Create, and return the WLANConfigure Module
* @return QWidget* pointer to this modules configure.
- */
+ */
QWidget *PPPModule::configure(Interface *i){
- return NULL;
- //PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", i, false, Qt::WDestructiveClose);
- //pppconfig->setProfile(profile);
- //return wlanconfig;
+ PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", /* i,*/ false, Qt::WDestructiveClose);
+// pppconfig->setProfile(profile);
+ return pppconfig;
}
/**
* Create, and return the Information Module
* @return QWidget* pointer to this modules info.
- */
+ */
QWidget *PPPModule::information(Interface *i){
// We don't have any advanced pppd information widget yet :-D
// TODO ^
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i);
return information;
}
/**
* Get all active (up or down) interfaces
* @return QList<Interface> A list of interfaces that exsist that havn't
* been called by isOwner()
*/
QList<Interface> PPPModule::getInterfaces(){
// List all of the files in the peer directory
return list;
}
/**
* Attempt to add a new interface as defined by name
* @param name the name of the type of interface that should be created given
* by possibleNewInterfaces();
* @return Interface* NULL if it was unable to be created.
- */
+ */
Interface *PPPModule::addNewInterface(const QString &newInterface){
- // If the
+ // If the
+ qDebug("try to add iface %s",newInterface.latin1());
PPPConfigureImp imp(0, "PPPConfigImp");
+ imp.showMaximized();
if(imp.exec() == QDialog::Accepted ){
-
+ qDebug("ACCEPTED");
+ return new Interface( 0, newInterface );
}
- return NULL;
+ return NULL;
}
/**
* Attempts to remove the interface, doesn't delete i
* @return bool true if successfull, false otherwise.
- */
+ */
bool PPPModule::remove(Interface*){
// Can't remove a hardware device, you can stop it though.
- return false;
+ return false;
+}
+
+void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces)
+{
+ qDebug("here");
+ newIfaces.insert(QObject::tr("PPP") ,QObject::tr("generic ppp device"));
}
-// pppmodule.cpp
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
@@ -1,32 +1,32 @@
#ifndef PPP_MODULE_H
#define PPP_MODULE_H
-
+
#include "module.h"
class PPPModule : Module {
signals:
- void updateInterface(Interface *i);
+ void updateInterface(Interface *i);
public:
PPPModule();
~PPPModule();
virtual void setProfile(const QString &newProfile);
virtual bool isOwner(Interface *);
virtual QWidget *configure(Interface *i);
virtual QWidget *information(Interface *i);
virtual QList<Interface> getInterfaces();
- virtual void possibleNewInterfaces(QMap<QString, QString> &){};
+ virtual void possibleNewInterfaces(QMap<QString, QString> &);
virtual Interface *addNewInterface(const QString &name);
virtual bool remove(Interface* i);
virtual QString getPixmapName(Interface* i);
private:
QList<Interface> list;
QString profile;
};
extern "C"
{
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 @@
+/*
+ * kPPP: A pppd front end for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * This file was contributed by Mario Weilguni <mweilguni@sime.com>
+ * Thanks Mario !
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <qdir.h>
+#include "runtests.h"
+#include <ctype.h>
+#include <unistd.h>
+#include <qmessagebox.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <netinet/in.h>
+
+#ifdef HAVE_RESOLV_H
+#include <arpa/nameser.h>
+#include <resolv.h>
+#endif
+
+#ifndef _PATH_RESCONF
+#define _PATH_RESCONF "/etc/resolv.conf"
+#endif
+
+//#include <klocale.h>
+#define i18n QObject::tr
+#include "pppdata.h"
+
+// initial effective uid (main.cpp)
+extern uid_t euid;
+
+// secure pppd location (opener.cpp)
+extern const char* pppdPath();
+
+// shamelessly stolen from pppd-2.3.5
+/********************************************************************
+ *
+ * Internal routine to decode the version.modification.patch level
+ */
+
+static void decode_version (const char *_buf, int *version,
+ int *modification, int *patch)
+ {
+ char *buffer = qstrdup(_buf);
+ char *buf = buffer;
+ *version = (int) strtoul (buf, &buf, 10);
+ *modification = 0;
+ *patch = 0;
+
+ if (*buf == '.')
+ {
+ ++buf;
+ *modification = (int) strtoul (buf, &buf, 10);
+ if (*buf == '.')
+ {
+ ++buf;
+ *patch = (int) strtoul (buf, &buf, 10);
+ }
+ }
+
+ if (*buf != '\0')
+ {
+ *version =
+ *modification =
+ *patch = 0;
+ }
+
+ delete [] buffer;
+ }
+
+
+void pppdVersion(int *version, int *modification, int *patch) {
+ char buffer[30];
+ const char *pppd;
+ char *query;
+
+ *version = *modification = *patch = 0;
+
+ // locate pppd
+ if(!(pppd = pppdPath()))
+ return;
+
+ // call pppd with --version option
+ if(!(query = new char[strlen(pppd)+25]))
+ return;
+ strcpy(query, pppd);
+ // had to add a dummy device to prevent a "no device specified
+ // and stdin is not a tty" error from newer pppd versions.
+ strcat(query, " --version /dev/tty 2>&1");
+ fflush(0L);
+ FILE *output = popen(query, "r");
+ delete [] query;
+ if(!output)
+ return;
+
+ // read output
+ int size = fread(buffer, sizeof(char), 29, output);
+
+ if(ferror(output)) {
+ pclose(output);
+ return;
+ }
+ pclose(output);
+ buffer[size] = '\0';
+
+ // find position of version number x.y.z
+ char *p = buffer;
+ while(*p && !isdigit(*p))
+ p++;
+ if (*p == 0)
+ return;
+ char *p2 = p;
+ while(*p2 == '.' || isdigit(*p2))
+ p2++;
+ *p2 = '\0';
+
+ decode_version(p, version, modification, patch);
+}
+
+
+int uidFromName(const char *uname) {
+ struct passwd *pw;
+
+ setpwent();
+ while((pw = getpwent()) != NULL) {
+ if(strcmp(uname, pw->pw_name) == 0) {
+ int uid = pw->pw_uid;
+ endpwent();
+ return uid;
+ }
+ }
+
+ endpwent();
+ return -1;
+}
+
+
+const char *homedirFromUid(uid_t uid) {
+ struct passwd *pw;
+ char *d = 0;
+
+ setpwent();
+ while((pw = getpwent()) != NULL) {
+ if(pw->pw_uid == uid) {
+ d = strdup(pw->pw_dir);
+ endpwent();
+ return d;
+ }
+ }
+
+ endpwent();
+ return d;
+}
+
+
+const char* getHomeDir() {
+ static const char *hd = 0;
+ static bool ranTest = false;
+ if(!ranTest) {
+ hd = homedirFromUid(getuid());
+ ranTest = true;
+ }
+
+ return hd;
+}
+
+
+int runTests() {
+ int warning = 0;
+
+ // Test pre-1: check if the user is allowed to dial-out
+ if(access("/etc/kppp.allow", R_OK) == 0 && getuid() != 0) {
+ bool access = FALSE;
+ FILE *f;
+ if((f = fopen("/etc/kppp.allow", "r")) != NULL) {
+ char buf[2048]; // safe
+ while(f != NULL && !feof(f)) {
+ if(fgets(buf, sizeof(buf), f) != NULL) {
+ QString s(buf);
+
+ s = s.stripWhiteSpace();
+ if(s[0] == '#' || s.length() == 0)
+ continue;
+
+ if((uid_t)uidFromName(QFile::encodeName(s)) == getuid()) {
+ access = TRUE;
+ fclose(f);
+ f = NULL;
+ }
+ }
+ }
+ if(f)
+ fclose(f);
+ }
+
+ if(!access) {
+ QMessageBox::warning(0,"error",
+ i18n("You're not allowed to dial out with "
+ "kppp.\nContact your system administrator."));
+ return TEST_CRITICAL;
+ }
+ }
+
+ // Test 1: search the pppd binary
+ const char *f = pppdPath();
+
+ if(!f) {
+ QMessageBox::warning(0,"error",
+ i18n("Cannot find the PPP daemon!\n"
+ "Make sure that pppd is installed."));
+ warning++;
+ }
+
+ // Test 2: check access to the pppd binary
+ if(f) {
+#if 0
+ if(access(f, X_OK) != 0 /* && geteuid() != 0 */) {
+ KMessageBox::warning(0,
+ i18n("You do not have the permission "
+ "to start pppd!\n"
+ "Contact your system administrator "
+ "and ask to get access to pppd."));
+ return TEST_CRITICAL;
+ }
+#endif
+
+ if(geteuid() != 0) {
+ struct stat st;
+ stat(f, &st);
+ if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) {
+ QMessageBox::warning(0,"error",
+ i18n("You don't have sufficient permission to run\n"
+ "%1\n"
+ "Please make sure that kppp is owned by root "
+ "and has the SUID bit set.").arg(f));
+ warning++;
+ }
+ }
+ }
+
+ // Test 5: check for existence of /etc/resolv.conf
+ if (access(_PATH_RESCONF, R_OK) != 0) {
+ QString file = _PATH_RESCONF" ";
+ QString msgstr = i18n("%1 is missing or can't be read!\n"
+ "Ask your system administrator to create "
+ "this file (can be empty) with appropriate "
+ "read and write permissions.").arg(file);
+ QMessageBox::warning(0, "errror", msgstr);
+ warning ++;
+ }
+
+ if(warning == 0)
+ return TEST_OK;
+ else
+ return TEST_WARNING;
+}
+
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 @@
+/*
+ * kPPP: A pppd front end for the KDE project
+ *
+ * $Id$
+ *
+ * Copyright (C) 1997 Bernd Johannes Wuebben
+ * wuebben@math.cornell.edu
+ *
+ * This file was contributed by Mario Weilguni <mweilguni@sime.com>
+ * Thanks Mario !
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __RUNTESTS__H__
+#define __RUNTESTS__H__
+
+#define SYSOPTIONS "/etc/ppp/options"
+
+const int TEST_OK = 0;
+const int TEST_WARNING = 1;
+const int TEST_NOCONNECT = 2;
+const int TEST_CRITICAL = 3;
+
+// Various tests to be run at starttime
+int runTests();
+const char* getHomeDir();
+void pppdVersion(int *version, int *modification, int *patch);
+
+#ifdef __linux__
+bool ppp_available(void);
+#endif
+
+#endif
+