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 @@ -105,45 +105,45 @@ ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *nam 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())); @@ -984,33 +984,31 @@ void ConnectWidget::cancelbutton() { _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(); 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 @@ -11,20 +11,23 @@ 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 @@ -24,19 +24,19 @@ * 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: 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 @@ -125,17 +125,17 @@ void PPPData::cancel() { 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); } @@ -342,23 +342,25 @@ void PPPData::setpppdTimeout(int 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"); } @@ -707,23 +709,26 @@ void PPPData::setEnter(const QString &n) { //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); @@ -905,16 +910,19 @@ const QString PPPData::storedUsername() { 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); } @@ -1269,8 +1277,19 @@ void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) 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 @@ -404,16 +404,19 @@ public: //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 |