9 files changed, 160 insertions, 30 deletions
diff --git a/noncore/settings/networksettings/ppp/TODO b/noncore/settings/networksettings/ppp/TODO index 2410880..1136c2d 100644 --- a/noncore/settings/networksettings/ppp/TODO +++ b/noncore/settings/networksettings/ppp/TODO @@ -1,6 +1,7 @@ +- add possibility to input username and password ;) - impl. PPPData::copyaccount & PPPData::deleteAccount - update modem attribute inputs when modem has changed - fix layout of edit account - save pppd arguments in edit account - popup configure modem with the correct account prselected not quite shure why it does not work... IMHO it should work diff --git a/noncore/settings/networksettings/ppp/connect.cpp b/noncore/settings/networksettings/ppp/connect.cpp index 2615b60..89d9930 100644 --- a/noncore/settings/networksettings/ppp/connect.cpp +++ b/noncore/settings/networksettings/ppp/connect.cpp @@ -17,221 +17,221 @@ * 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 <config.h> #include <qlayout.h> #include <qregexp.h> #include <qapplication.h> //#include <kdebug.h> //#include <klocale.h> #define i18n QObject::tr #include <qmessagebox.h> #include <qpushbutton.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <sys/ioctl.h> #include <assert.h> #ifdef _XPG4_2 #define __xnet_connect connect #endif #include <errno.h> #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif #ifdef __linux__ #include "runtests.h" #endif #include "auth.h" #include "connect.h" //#include "docking.h" #include "interfaceppp.h" #include "modem.h" #include "kpppconfig.h" #include "pppdata.h" #include "kpppwidget.h" //#include "requester.h" //#include "utils.h" #define execute_command system QString old_hostname; bool modified_hostname; ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *name) : QWidget(parent, name), myreadbuffer(""), main_timer_ID(0), vmain(0), substate(-1), scriptindex(0), loopnest(0), loopend(false), semaphore(false), expecting(false), readbuffer(""), scanvar(""), scanning(false), pausing(false), dialnumber(0), _ifaceppp(ifp) { modified_hostname = false; QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); QString tit = i18n("Connecting to: "); setCaption(tit); QHBoxLayout *l0 = new QHBoxLayout(10); tl->addLayout(l0); l0->addSpacing(10); messg = new QLabel(this, "messg"); messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); messg->setAlignment(AlignCenter); messg->setText(i18n("Unable to create modem lock file.")); messg->setMinimumHeight(messg->sizeHint().height() + 5); - int messw = (messg->sizeHint().width() * 12) / 10; - messw = QMAX(messw,280); - messg->setMinimumWidth(messw); - messg->setText(i18n("Looking for modem...")); +// int messw = (messg->sizeHint().width() * 12) / 10; +// messw = QMAX(messw,280); +// messg->setMinimumWidth(messw); + messg->setText(i18n("Offline")); l0->addSpacing(10); l0->addWidget(messg); l0->addSpacing(10); QHBoxLayout *l1 = new QHBoxLayout(10); tl->addLayout(l1); l1->addStretch(1); debug = new QPushButton(i18n("Log"), this); debug->setToggleButton(true); connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); cancel = new QPushButton(i18n("Cancel"), this); cancel->setFocus(); connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); - int maxw = QMAX(cancel->sizeHint().width(), - debug->sizeHint().width()); - maxw = QMAX(maxw,65); - debug->setFixedWidth(maxw); - cancel->setFixedWidth(maxw); +// int maxw = QMAX(cancel->sizeHint().width(), +// debug->sizeHint().width()); +// maxw = QMAX(maxw,65); +// debug->setFixedWidth(maxw); +// cancel->setFixedWidth(maxw); l1->addWidget(debug); l1->addWidget(cancel); - setFixedSize(sizeHint()); +// setFixedSize(sizeHint()); pausetimer = new QTimer(this); connect(pausetimer, SIGNAL(timeout()), SLOT(pause())); qApp->processEvents(); timeout_timer = new QTimer(this); connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out())); inittimer = new QTimer(this); connect(inittimer, SIGNAL(timeout()), SLOT(init())); if_timeout_timer = new QTimer(this); connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out())); connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot())); prompt = new PWEntry( this, "pw" ); if_timer = new QTimer(this); connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); } ConnectWidget::~ConnectWidget() { } void ConnectWidget::preinit() { // this is all just to keep the GUI nice and snappy .... // you have to see to believe ... messg->setText(i18n("Looking for modem...")); inittimer->start(100); } void ConnectWidget::init() { _ifaceppp->data()->setpppdError(0); inittimer->stop(); vmain = 0; substate = -1; expecting = false; pausing = false; scriptindex = 0; myreadbuffer = ""; scanning = false; scanvar = ""; firstrunID = true; firstrunPW = true; // stats->totalbytes = 0; dialnumber = 0; // p_kppp->con_speed = ""; // p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect()); comlist = &_ifaceppp->data()->scriptType(); arglist = &_ifaceppp->data()->script(); QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname()); setCaption(tit); qApp->processEvents(); // run the "before-connect" command if (!_ifaceppp->data()->command_before_connect().isEmpty()) { messg->setText(i18n("Running pre-startup command...")); emit debugMessage(i18n("Running pre-startup command...")); qApp->processEvents(); QApplication::flushX(); pid_t id = execute_command(_ifaceppp->data()->command_before_connect()); // int i, status; // do { // qApp->processEvents(); // i = waitpid(id, &status, WNOHANG); // usleep(100000); // } while (i == 0 && errno == 0); } int lock = _ifaceppp->modem()->lockdevice(); if (lock == 1) { messg->setText(i18n("Modem device is locked.")); vmain = 20; // wait until cancel is pressed return; } if (lock == -1) { messg->setText(i18n("Unable to create modem lock file.")); vmain = 20; // wait until cancel is pressed return; } if(_ifaceppp->modem()->opentty()) { messg->setText(_ifaceppp->modem()->modemMessage()); @@ -896,209 +896,207 @@ void ConnectWidget::readChar(unsigned char c) { return; readbuffer += c; myreadbuffer += c; // While in scanning mode store each char to the scan buffer // for use in the prompt command if( scanning ) scanbuffer += c; // add to debug window emit debugPutChar(c); checkBuffers(); } void ConnectWidget::checkBuffers() { // Let's check if we are finished with scanning: // The scanstring have to be in the buffer and the latest character // was a carriage return or an linefeed (depending on modem setup) if( scanning && scanbuffer.contains(scanstr) && ( scanbuffer.right(1) == "\n" || scanbuffer.right(1) == "\r") ) { scanning = false; int vstart = scanbuffer.find( scanstr ) + scanstr.length(); scanvar = scanbuffer.mid( vstart, scanbuffer.length() - vstart); scanvar = scanvar.stripWhiteSpace(); // Show the Variabel content in the debug window QString sv = i18n("Scan Var: %1").arg(scanvar); emit debugMessage(sv); } if(expecting) { if(readbuffer.contains(expectstr)) { expecting = false; // keep everything after the expected string readbuffer.remove(0, readbuffer.find(expectstr) + expectstr.length()); QString ts = i18n("Found: %1").arg(expectstr); emit debugMessage(ts); if (loopend) { loopend=false; } } if (loopend && readbuffer.contains(loopstr[loopnest])) { expecting = false; readbuffer = ""; QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); emit debugMessage(ts); scriptindex = loopstartindex[loopnest]; loopend = false; loopnest++; } // notify event loop if expected string was found if(!expecting) timerEvent((QTimerEvent *) 0); } } void ConnectWidget::pause() { pausing = false; pausetimer->stop(); } void ConnectWidget::cancelbutton() { _ifaceppp->modem()->stop(); killTimer(main_timer_ID); timeout_timer->stop(); if_timer->stop(); if_timeout_timer->stop(); // if (termwindow) { // delete termwindow; // termwindow = 0L; // this->show(); // } messg->setText(i18n("One moment please...")); // just to be sure _ifaceppp->modem()->removeSecret(AUTH_PAP); _ifaceppp->modem()->removeSecret(AUTH_CHAP); removedns(_ifaceppp); qApp->processEvents(); _ifaceppp->modem()->killPPPDaemon(); _ifaceppp->modem()->hangup(); - this->hide(); - messg->setText(""); + // p_kppp->quit_b->setFocus(); // p_kppp->show(); - emit stopAccounting(); // just to be sure +// emit stopAccounting(); // just to be sure // p_kppp->con_win->stopClock(); _ifaceppp->modem()->closetty(); _ifaceppp->modem()->unlockdevice(); //abort prompt window... if (prompt->isVisible()) { prompt->hide(); } prompt->setConsumed(); -// if(p_kppp->quitOnDisconnect()) -// qApp->exit(0); + messg->setText(tr("offline")); } void ConnectWidget::script_timed_out() { if(vmain == 20) { // we are in the 'wait for the user to cancel' state timeout_timer->stop(); emit stopAccounting(); // p_kppp->con_win->stopClock(); return; } if (prompt->isVisible()) prompt->hide(); prompt->setConsumed(); messg->setText(i18n("Script timed out!")); _ifaceppp->modem()->hangup(); emit stopAccounting(); // p_kppp->con_win->stopClock(); vmain = 0; // let's try again. substate = -1; } void ConnectWidget::setScan(const QString &n) { scanning = true; scanstr = n; scanbuffer = ""; QString ts = i18n("Scanning: %1").arg(n); emit debugMessage(ts); } void ConnectWidget::setExpect(const QString &n) { expecting = true; expectstr = n; QString ts = i18n("Expecting: %1").arg(n); ts.replace(QRegExp("\n"), "<LF>"); emit debugMessage(ts); // check if the expected string is in the read buffer already. checkBuffers(); } void ConnectWidget::if_waiting_timed_out() { if_timer->stop(); if_timeout_timer->stop(); qDebug("if_waiting_timed_out()"); _ifaceppp->data()->setpppdError(E_IF_TIMEOUT); // let's kill the stuck pppd _ifaceppp->modem()->killPPPDaemon(); emit stopAccounting(); // p_kppp->con_win->stopClock(); // killing ppp will generate a SIGCHLD which will be caught in pppdie() // in main.cpp what happens next will depend on the boolean // reconnect_on_disconnect which is set in ConnectWidget::init(); } void ConnectWidget::pppdDied() { if_timer->stop(); if_timeout_timer->stop(); } void ConnectWidget::if_waiting_slot() { messg->setText(i18n("Logging on to network...")); // if(!stats->ifIsUp()) { // if(_ifaceppp->data()->pppdError() != 0) { // // we are here if pppd died immediately after starting it. // pppdDied(); // // error message handled in main.cpp: sigPPPDDied() // return; // } // if_timer->start(100, TRUE); // single shot // return; // } // O.K the ppp interface is up and running // give it a few time to come up completly (0.2 seconds) if_timeout_timer->stop(); if_timer->stop(); usleep(200000); if(_ifaceppp->data()->autoDNS()) diff --git a/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp b/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp index a58858c..3cf1167 100644 --- a/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp +++ b/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp @@ -1,24 +1,32 @@ #include "interfaceinformationppp.h" #include <qpushbutton.h> #include <qlabel.h> //#include <qgroupbox.h> #include <qmessagebox.h> +#include "connect.h" +#include "conwindow.h" + #ifdef QWS #else #define showMaximized show #endif /** * Constructor for the InterfaceInformationImp class. This class pretty much * just display's information about the interface that is passed to it. */ InterfaceInformationPPP::InterfaceInformationPPP(QWidget *parent, const char *name, Interface *i, WFlags f) :InterfaceInformationImp(parent, name, i, f) { + qDebug("InterfaceInformationPPP::InterfaceInformationPPP"); + con = new ConnectWidget( (InterfacePPP*)i, this, "con" ); + // InterfaceInformationLayout->addMultiCellWidget( con, 7, 7, 0, 1 ); + InterfaceInformationLayout->addWidget( con, 7, 0 ); + connect(i, SIGNAL(begin_connect()),con, SLOT(preinit())); } diff --git a/noncore/settings/networksettings/ppp/interfaceinformationppp.h b/noncore/settings/networksettings/ppp/interfaceinformationppp.h index 8c6fc0b..68b58ea 100644 --- a/noncore/settings/networksettings/ppp/interfaceinformationppp.h +++ b/noncore/settings/networksettings/ppp/interfaceinformationppp.h @@ -1,25 +1,30 @@ #ifndef INTERFACEINFORMATIONPPP_H #define INTERFACEINFORMATIONPPP_H #include "interfaceinformationimp.h" -//#include "interface.h" + class QWidget; class Interface; +class ConnectWidget; +class ConnectWindow; class InterfaceInformationPPP : public InterfaceInformationImp { Q_OBJECT public: InterfaceInformationPPP(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); ~InterfaceInformationPPP(){}; + private: + ConnectWidget *con; + ConnectWindow *con_win; }; #endif // addserviceimp.h diff --git a/noncore/settings/networksettings/ppp/interfaceppp.cpp b/noncore/settings/networksettings/ppp/interfaceppp.cpp index d9ee3ff..dc24824 100644 --- a/noncore/settings/networksettings/ppp/interfaceppp.cpp +++ b/noncore/settings/networksettings/ppp/interfaceppp.cpp @@ -1,48 +1,141 @@ + +#include <qmessagebox.h> +#define i18n QObject::tr + +#include "auth.h" #include "interfaceppp.h" #include "modem.h" #include "pppdata.h" InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status) : Interface(parent, name, status), - _modem(0), - _pppdata(0) + _modemPtr(0), + _dataPtr(0) { qDebug("InterfacePPP::InterfacePPP("); } PPPData* InterfacePPP::data() { - if (!_pppdata){ - _pppdata = new PPPData(); - _pppdata->setModemDevice( getInterfaceName() ); - _pppdata->setAccount( getHardwareName() ); + if (!_dataPtr){ + qDebug("creating new Data obj"); + _dataPtr = new PPPData(); + _dataPtr->setModemDevice( getInterfaceName() ); + _dataPtr->setAccount( getHardwareName() ); } - return _pppdata; + return _dataPtr; } Modem* InterfacePPP::modem() { - if (!_modem){ - _modem = new Modem( data() ); + if (!_modemPtr){ + qDebug("creating new modem obj"); + _modemPtr = new Modem( data() ); } - return _modem; + return _modemPtr; } bool InterfacePPP::refresh() { qDebug("InterfacePPP::refresh()"); + QMessageBox::information(0,"Not Implemented","This feature is not yet implemneted... ;-("); return false; } void InterfacePPP::start() { qDebug("InterfacePPP::start"); + if (data()->storedPassword() != "" ){ + data()->setPassword(data()->storedPassword()); + }else{ + //FIXME: + qDebug("using dummy password"); + data()->setPassword( "dummy" ); + } + + + QFileInfo info(pppdPath()); + + if(!info.exists()){ + QMessageBox::warning(0, tr("Error"), + i18n("<qt>Cannot find the PPP daemon!<br>" + "Make sure that pppd is installed and " + "that you have entered the correct path.</qt>")); + return; + } +//#if 0 + if(!info.isExecutable()){ + + QString string; + string = i18n( "<qt>Cannot execute:<br> %1<br>" + "Please make sure that you have given " + "setuid permission and that " + "pppd is executable.<br>").arg(pppdPath()); + QMessageBox::warning(0, tr("Error"), string); + return; + + } +//#endif + + QFileInfo info2(data()->modemDevice()); + + if(!info2.exists()){ + QString string; + string = i18n( "<qt>Cannot find:<br> %1<br>" + "Please make sure you have setup " + "your modem device properly " + "and/or adjust the location of the modem device on " + "the modem tab of " + "the setup dialog.</qt>").arg(data()->modemDevice()); + QMessageBox::warning(0, tr("Error"), string); + return; + } + + // if this is a PAP or CHAP account, ensure that username is + // supplied + if(data()->authMethod() == AUTH_PAP || + data()->authMethod() == AUTH_CHAP || + data()->authMethod() == AUTH_PAPCHAP ) { + if(false){ //ID_Edit->text().isEmpty()) { + QMessageBox::warning(0,tr("Error"), + i18n("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>")); +// FIXME: return; + } else { + if(!modem()->setSecret(data()->authMethod(), + PPPData::encodeWord(data()->storedUsername()), + PPPData::encodeWord(data()->password())) + ) { + QString s; + s = i18n("<qt>Cannot create PAP/CHAP authentication<br>" + "file \"%1\"</qt>").arg(PAP_AUTH_FILE); + QMessageBox::warning(0, tr("Error"), s); + return; + } + } + } + + if (data()->phonenumber().isEmpty()) { + QString s = i18n("You must specify a telephone number!"); + QMessageBox::warning(0, tr("Error"), s); + return; + } + +// this->hide(); + + QString tit = i18n("Connecting to: %1").arg(data()->accname()); +// con->setCaption(tit); + +// con->show(); + + + emit begin_connect(); + qDebug("InterfacePPP::start END"); } void InterfacePPP::stop() { qDebug("InterfacePPP::stop"); } diff --git a/noncore/settings/networksettings/ppp/interfaceppp.h b/noncore/settings/networksettings/ppp/interfaceppp.h index b7477c9..06a4dbf 100644 --- a/noncore/settings/networksettings/ppp/interfaceppp.h +++ b/noncore/settings/networksettings/ppp/interfaceppp.h @@ -1,30 +1,33 @@ #ifndef INTERFACEPPP_H #define INTERFACEPPP_H #include "interface.h" class PPPData; class Modem; class InterfacePPP : public Interface { Q_OBJECT public: InterfacePPP(QObject *parent=0, const char *name="PPP", bool status=false); PPPData* data(); Modem* modem(); +signals: + void begin_connect(); + public slots: virtual bool refresh(); virtual void start(); virtual void stop(); private: - Modem *_modem; - PPPData *_pppdata; + Modem *_modemPtr; + PPPData *_dataPtr; }; #endif diff --git a/noncore/settings/networksettings/ppp/kpppwidget.h b/noncore/settings/networksettings/ppp/kpppwidget.h index b958862..e0f5237 100644 --- a/noncore/settings/networksettings/ppp/kpppwidget.h +++ b/noncore/settings/networksettings/ppp/kpppwidget.h @@ -1,115 +1,115 @@ /* * * kPPP: A pppd front end for the KDE project * * $Id$ * * Copyright (C) 1997 Bernd Johannes Wuebben * wuebben@math.cornell.edu * * Copyright (C) 1998-2002 Harri Porten <porten@kde.org> * * 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 __KPPPWIDGET_H__ #define __KPPPWIDGET_H__ #include <qstring.h> -#include "conwindow.h" #include "accounts.h" #include "connect.h" +#include "conwindow.h" class QPushButton; class Interface; class PPPData; class KPPPWidget : public QDialog { Q_OBJECT public: KPPPWidget(PPPData*, Interface*, QWidget *parent=0, const char *name=0, bool modal = false, WFlags fl = 0 ); ~KPPPWidget(); void setPW_Edit(const QString &); private slots: void newdefaultaccount(int); void beginConnect(); void quitbutton(); void usernameChanged(const QString &); void passwordChanged(const QString &); void enterPressedInID(); void enterPressedInPW(); void saveMyself(); void shutDown(); public slots: void disconnect(); void log_window_toggled(bool on); signals: void begin_connect(); void cmdl_start(); public: QCheckBox *log; bool connected; QString con_speed; ConnectWidget *con; ConWindow *con_win; // PPPStatsDlg *statdlg; // AccountingBase *acct; QPushButton *quit_b; //PPPStats *stats; private: // void prepareSetupDialog(); void interruptConnection(); void sigChld(); void sigPPPDDied(); QString encodeWord(const QString &s); void showNews (); QString ruleset_load_errmsg; PPPData *_pppdata; QPushButton *setup_b; QFrame *fline; QFrame *fline1; QPushButton *connect_b; QComboBox *connectto_c; QLabel *ID_Label; QLabel *PW_Label; QLineEdit *ID_Edit; QLineEdit *PW_Edit; QLabel *label1; QLabel *label2; QLabel *label3; QLabel *label4; QLabel *label5; QLabel *label6; QLabel *radio_label; /* QString m_strCmdlAccount; */ /* bool m_bQuitOnDisconnect; */ /* bool m_bCmdlAccount; */ }; #endif diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp index 59d68c9..7a6524f 100644 --- a/noncore/settings/networksettings/ppp/pppdata.cpp +++ b/noncore/settings/networksettings/ppp/pppdata.cpp @@ -37,193 +37,193 @@ // #include <kmessagebox.h> // #include <kapplication.h> #include <assert.h> #define SEPARATOR -sseepp- #define SEP QString("%1SEPARATOR%1") PPPData::PPPData() : modemDeviceGroup(-1), 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) { 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); } Config PPPData::config() { return Config("NetworkSetupPPP"); } // // save configuration // void PPPData::save() { qDebug("PPPData saving data"); writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); QString key; QStringList keys; Config cfg = config(); for( QMap<QString,QString>::Iterator it = stringEntries.begin(); it != stringEntries.end(); ++it ){ QString val = it.data(); key = it.key(); // qDebug("saving %s -> %s", key.latin1(), val.latin1() ); keys = QStringList::split( "SEPARATOR", key ); qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val); } for( QMap<QString,int>::Iterator it = intEntries.begin(); it != intEntries.end(); ++it ){ int val = it.data(); key = it.key(); // qDebug("saving %s -> %i", key.latin1(), val ); keys = QStringList::split( "SEPARATOR", key ); qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val); } for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); it != listEntries.end(); ++it ){ QStringList val = it.data(); key = it.key(); QChar sep = sepEntries[key]; // qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() ); keys = QStringList::split( "SEPARATOR", key ); qDebug("group >%s< key >%s<values >%s<", keys[0].latin1(), keys[1].latin1(), val.join(sep).latin1() ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val, sep); } } // // cancel changes // void PPPData::cancel() { stringEntries.clear(); intEntries.clear(); listEntries.clear(); } // functions to read/write date to configuration file QString PPPData::readConfig(const QString &group, const QString &key, const QString &defvalue = "") { -// qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); + qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); QString idx = SEP.arg(group).arg(key); if (stringEntries.find(idx) != stringEntries.end()) return stringEntries[idx]; Config cfg = config(); cfg.setGroup(group); return cfg.readEntry(key, defvalue); } int PPPData::readNumConfig(const QString &group, const QString &key, int defvalue) { QString idx = SEP.arg(group).arg(key); if (intEntries.find(idx) != intEntries.end()) return intEntries[idx]; Config cfg = config(); cfg.setGroup(group); return cfg.readNumEntry(key, 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(); QString idx = SEP.arg(group).arg(key); if (listEntries.find(idx) != listEntries.end()){ list = listEntries[idx]; return true; } Config cfg = config(); cfg.setGroup(group); list = cfg.readListEntry(key, sep); if (list.count() > 0) return true; return false; // 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) { stringEntries.insert( SEP.arg(group).arg(key), value ); // if (config) { // config->setGroup(group); // config->writeEntry(key, value); // } } void PPPData::writeConfig(const QString &group, const QString &key, int value) { intEntries.insert( SEP.arg(group).arg(key), value ); // if (config) { // config->setGroup(group); // config->writeEntry(key, value); // } } void PPPData::writeListConfig(const QString &group, const QString &key, QStringList &list, char sep) { listEntries.insert( SEP.arg(group).arg(key), list ); sepEntries.insert( SEP.arg(group).arg(key), 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; } @@ -254,199 +254,201 @@ 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 (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]); } bool PPPData::setModemDevice(const QString &n) { + qDebug("Setting modem dev to >%s<", n.latin1()); bool ret = false; for (int i = 0; devices[i]; i++) if (devices[i] == n){ modemDeviceGroup = i; writeConfig(modemGroup(), MODEMDEV_KEY, n); ret = true; } + qDebug(ret?"SUCCESS":"FAILURE"); return ret; } const QString PPPData::flowcontrol() { return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); } void PPPData::setFlowcontrol(const QString &n) { writeConfig(modemGroup(), FLOWCONTROL_KEY, n); } const QString PPPData::speed() { QString s = readConfig(modemGroup(), 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(modemGroup(), SPEED_KEY, n); } #if 0 void PPPData::setUseCDLine(const int n) { writeConfig(modemGroup(),USECDLINE_KEY,n); } int PPPData::UseCDLine() { return readNumConfig(modemGroup(),USECDLINE_KEY,0); } #endif const QString PPPData::modemEscapeStr() { return readConfig(modemGroup(),ESCAPESTR_KEY,"+++"); } void PPPData::setModemEscapeStr(const QString &n) { writeConfig(modemGroup(),ESCAPESTR_KEY,n); } const QString PPPData::modemEscapeResp() { return readConfig(modemGroup(),ESCAPERESP_KEY,"OK"); } void PPPData::setModemEscapeResp(const QString &n) { writeConfig(modemGroup(),ESCAPERESP_KEY,n); } int PPPData::modemEscapeGuardTime() { return readNumConfig(modemGroup(),ESCAPEGUARDTIME_KEY,50); } void PPPData::setModemEscapeGuardTime(int n) { writeConfig(modemGroup(),ESCAPEGUARDTIME_KEY,n); } bool PPPData::modemLockFile() { return readNumConfig(modemGroup(), LOCKFILE_KEY, 1); } void PPPData::setModemLockFile(bool set) { writeConfig(modemGroup(), LOCKFILE_KEY, set); } int PPPData::modemTimeout() { return readNumConfig(modemGroup(), TIMEOUT_KEY, MODEM_TIMEOUT); } void PPPData::setModemTimeout(int n) { writeConfig(modemGroup(), TIMEOUT_KEY, n); } int PPPData::modemToneDuration() { return readNumConfig(modemGroup(), TONEDURATION_KEY,MODEM_TONEDURATION); } @@ -619,390 +621,396 @@ QString PPPData::volumeHigh() { QString tmp = readConfig(modemGroup(), VOLUME_HIGH, "M1L3"); if(tmp == "M1L4") tmp = "M1L3"; return tmp; } void PPPData::setVolumeHigh(const QString &s) { writeConfig(modemGroup(), 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(modemGroup(), VOLUME_KEY, 1); } void PPPData::setVolume(int i) { writeConfig(modemGroup(), VOLUME_KEY, i); } int PPPData::waitForDialTone() { return readNumConfig(modemGroup(), DIALTONEWAIT_KEY, 1); } void PPPData::setWaitForDialTone(int i) { writeConfig(modemGroup(), DIALTONEWAIT_KEY, i); } void PPPData::setModemAnswerStr(const QString &n) { writeConfig(modemGroup(), ANSWERSTR_KEY, n); } const QString PPPData::modemRingResp() { return readConfig(modemGroup(), RINGRESP_KEY, "RING"); } void PPPData::setModemRingResp(const QString &n) { writeConfig(modemGroup(), RINGRESP_KEY, n); } const QString PPPData::modemAnswerResp() { return readConfig(modemGroup(), ANSWERRESP_KEY, "CONNECT"); } void PPPData::setModemAnswerResp(const QString &n) { writeConfig(modemGroup(), ANSWERRESP_KEY, n); } const QString PPPData::enter() { return readConfig(modemGroup(), ENTER_KEY, "CR"); } void PPPData::setEnter(const QString &n) { writeConfig(modemGroup(), 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) { + qDebug("setting account to >%s<", aname.latin1()); for(int i = 0; i <= highcount; i++) { setAccountbyIndex(i); if(accname() == aname) { caccount = i; + qDebug("SUCCESS"); return true; } } + qDebug("FAILURE"); 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() { //FIXME: // if(caccount < 0) return false; // QMap <QString, QString> map; // QMap <QString, QString>::Iterator it; // // set all entries of the current account to "" // 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() { qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); // if(!config) open(); if (highcount >= MAX_ACCOUNTS) return -1; highcount++; setAccountbyIndex(highcount); setpppdArgumentDefaults(); qDebug("PPPData::newaccount -> %i",caccount); return caccount; } int PPPData::copyaccount(int i) { // FIXME // 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() { + qDebug("getting stored pw"); + qDebug("g %s", cgroup.latin1() ); + qDebug("k %s", STORED_PASSWORD_KEY); 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); @@ -1181,96 +1189,107 @@ void PPPData::setpppdArgumentDefaults() { // 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; } QString PPPData::modemGroup() { if (modemDeviceGroup<0)qFatal("wrong modem %i",modemDeviceGroup); return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup); } QMap<QString,QString> PPPData::getConfiguredInterfaces() { QMap<QString,QString> ifaces; Config config = PPPData::config(); config.setGroup(ACCLIST_GRP); int count = config.readNumEntry( ACCOUNTS_COUNT, -1 ); QString accGrp, dev, acc; for (int i = 0; i < count; i++){ accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); config.setGroup(accGrp); dev = config.readEntry( ACOUNTS_DEV, "error" ); acc = config.readEntry( ACOUNTS_ACC, "error" ); ifaces.insert( dev, acc ); } return ifaces; } void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) { QMap<QString,QString>::Iterator it; int i = 0; Config cfg = config(); for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){ cfg.setGroup(QString("%1_%1").arg(ACCLIST_GRP).arg(i)); cfg.writeEntry( ACOUNTS_DEV, it.key() ); cfg.writeEntry( ACOUNTS_ACC, it.data() ); } cfg.setGroup( ACCLIST_GRP ); cfg.writeEntry( ACCOUNTS_COUNT, i ); } + +/** + * pppd's getword() function knows about escape characters. + * If we write the username and password to the secrets file + * we'll therefore have to escape back slashes. + */ +QString PPPData::encodeWord(const QString &s) { + QString r = s; + r.replace(QRegExp("\\"), "\\\\"); + return r; +} diff --git a/noncore/settings/networksettings/ppp/pppdata.h b/noncore/settings/networksettings/ppp/pppdata.h index af960c6..c9cd482 100644 --- a/noncore/settings/networksettings/ppp/pppdata.h +++ b/noncore/settings/networksettings/ppp/pppdata.h @@ -316,120 +316,123 @@ public: 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); + + static QString encodeWord(const QString &s); + private: //static PPPData *_data; int modemDeviceGroup; QString passwd; // static 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; QMap<QString,QString> stringEntries; QMap<QString,int> intEntries; QMap<QString,QStringList> listEntries; QMap<QString,QChar> sepEntries; }; #endif |