summaryrefslogtreecommitdiff
authortille <tille>2003-06-03 14:51:12 (UTC)
committer tille <tille>2003-06-03 14:51:12 (UTC)
commit33cf1711b4d74036fa27dc971c25df236b8d0355 (patch) (side-by-side diff)
tree2a35ce380e40771089e22eed2d41dfc9577ff4cf
parent4e0c9efab5f3c73a1843e96983c9cd1894e44810 (diff)
downloadopie-33cf1711b4d74036fa27dc971c25df236b8d0355.zip
opie-33cf1711b4d74036fa27dc971c25df236b8d0355.tar.gz
opie-33cf1711b4d74036fa27dc971c25df236b8d0355.tar.bz2
should popup for passwd now...
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/authwidget.cpp2
-rw-r--r--noncore/settings/networksettings/ppp/connect.cpp2
-rw-r--r--noncore/settings/networksettings/ppp/interfaceppp.cpp11
3 files changed, 9 insertions, 6 deletions
diff --git a/noncore/settings/networksettings/ppp/authwidget.cpp b/noncore/settings/networksettings/ppp/authwidget.cpp
index 86bea98..fa2b164 100644
--- a/noncore/settings/networksettings/ppp/authwidget.cpp
+++ b/noncore/settings/networksettings/ppp/authwidget.cpp
@@ -1,195 +1,197 @@
#include <qlayout.h>
#include <qmessagebox.h>
#include <qtoolbutton.h>
#include <qwhatsthis.h>
#include "auth.h"
#include "authwidget.h"
#include "edit.h"
#include "pppdata.h"
static const char* const image0_data[] = {
"16 16 2 1",
". c None",
"# c #000000",
"................",
"...#...###...##.",
"..#.#..#..#.##..",
"..###..###.##...",
".#...#.#..##....",
".#...#.#.##.....",
"........##.#..#.",
"..##...##...##..",
".#..#.###...##..",
".#...##..#.#..#.",
".#..##..........",
".#.##.#..#.#..#.",
"..##...##...##..",
".##....##...##..",
".#....#..#.#..#.",
"................"};
AuthWidget::AuthWidget(PPPData *pd, QWidget *parent, bool isnewaccount, const char *name )
: QWidget( parent, name),
scriptWidget(0),
_pppdata(pd),
isNewAccount(isnewaccount)
{
layout = new QGridLayout(this);
auth_l = new QLabel(tr("Authentication: "), this);
layout->addWidget(auth_l, 0, 0);
auth = new QComboBox(this);
auth->insertItem(tr("Script-based"));
auth->insertItem(tr("PAP"));
auth->insertItem(tr("Terminal-based"));
auth->insertItem(tr("CHAP"));
auth->insertItem(tr("PAP/CHAP"));
layout->addWidget(auth, 0, 1);
connect( auth, SIGNAL(activated(const QString&)),
SLOT(authChanged(const QString&)));
QString tmp = tr("<p>Specifies the method used to identify yourself to\n"
"the PPP server. Most universities still use\n"
"<b>Terminal</b>- or <b>Script</b>-based authentication,\n"
"while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n"
"unsure, contact your ISP.\n"
"\n"
"If you can choose between PAP and CHAP,\n"
"choose CHAP, because it's much safer. If you don't know\n"
"whether PAP or CHAP is right, choose PAP/CHAP.");
QWhatsThis::add(auth_l,tmp);
QWhatsThis::add(auth,tmp);
user_l = new QLabel( tr("Username: "), this);
layout->addWidget( user_l, 1, 0 );
userName = new QLineEdit( this, "usernameEdit" );
layout->addWidget( userName, 1, 1 );
tmp = tr("Enter your username here...");
QWhatsThis::add( user_l, tmp );
QWhatsThis::add( userName, tmp );
pw_l = new QLabel( tr("Password: "), this);
layout->addWidget( pw_l, 2, 0 );
passWord = new QLineEdit( this, "pw" );
passWord->setAutoMask( true );
passWord->setEchoMode( QLineEdit::Password );
layout->addWidget( passWord, 2, 1 );
hidePw = new QToolButton( this );
hidePw->setPixmap( QPixmap( ( const char** ) image0_data ) );
hidePw->setToggleButton( true );
layout->addWidget( hidePw, 2, 2 );
connect(hidePw, SIGNAL(toggled(bool)), SLOT(toggleEchoMode(bool)));
tmp = tr("Enter your password here");
QWhatsThis::add( pw_l, tmp );
QWhatsThis::add( passWord, tmp );
store_password = new QCheckBox(tr("Store password"), this);
layout->addMultiCellWidget(store_password, 3, 3, 0, 1, AlignRight);
QWhatsThis::add(store_password,
tr("<p>When this is turned on, your ISP password\n"
"will be saved in <i>kppp</i>'s config file, so\n"
"you do not need to type it in every time.\n"
"\n"
"<b><font color=\"red\">Warning:</font> your password will be stored as\n"
"plain text in the config file, which is\n"
"readable only to you. Make sure nobody\n"
"gains access to this file!"));
if (isNewAccount){
// select PAP/CHAP as default
auth->setCurrentItem(AUTH_PAPCHAP);
store_password->setChecked(true);
}else{
auth->setCurrentItem(_pppdata->authMethod());
authChanged( auth->currentText() );
userName->setText( _pppdata->storedUsername() );
store_password->setChecked(_pppdata->storePassword());
if (store_password->isChecked())
passWord->setText( _pppdata->storedPassword() );
}
}
bool AuthWidget::check()
{
bool ret = true;
if (scriptWidget){
if (!scriptWidget->check()){
QMessageBox::critical(this, tr("error"), tr("<qt>Login script has unbalanced loop Start/End<qt>"));
ret = false;
}
}
return ret;
}
void AuthWidget::save()
{
_pppdata->setAuthMethod(auth->currentItem());
if (scriptWidget) scriptWidget->save();
_pppdata->setStoredUsername( userName->text() );
_pppdata->setStorePassword(store_password->isChecked());
if (store_password->isChecked())
_pppdata->setStoredPassword( passWord->text() );
}
void AuthWidget::authChanged( const QString &authStr )
{
qDebug("AuthWidget::authChanged( %s )", authStr.latin1() );
if ( authStr.contains( tr("Script-based") ) ){
showUsernamePassword( false );
showScriptWindow( true );
} else if ( authStr.contains( tr("PAP") ) ||
authStr.contains( tr("CHAP") ) ){
showUsernamePassword( true );
showScriptWindow( false );
} else {
qDebug("do not really know how to handle");
showUsernamePassword( false );
showScriptWindow( false );
}
}
void AuthWidget::showUsernamePassword( bool show )
{
if (show){
user_l->show();
userName->show();
pw_l->show();
passWord->show();
store_password->show();
+ hidePw->show();
}else{//!show
user_l->hide();
userName->hide();
pw_l->hide();
passWord->hide();
store_password->hide();
+ hidePw->hide();
}
}
void AuthWidget::showScriptWindow( bool show )
{
if (show){
if (!scriptWidget){
scriptWidget = new ScriptWidget( _pppdata, this, isNewAccount, "scriptWid");
layout->addMultiCellWidget( scriptWidget, 1, 4, 0, 1 );
}
scriptWidget->show();
}else{ // !show
if (scriptWidget) scriptWidget->hide();
}
}
void AuthWidget::toggleEchoMode( bool t )
{
passWord->setEchoMode( t ? QLineEdit::Normal : QLineEdit::Password );
}
diff --git a/noncore/settings/networksettings/ppp/connect.cpp b/noncore/settings/networksettings/ppp/connect.cpp
index a93f93d..798431b 100644
--- a/noncore/settings/networksettings/ppp/connect.cpp
+++ b/noncore/settings/networksettings/ppp/connect.cpp
@@ -90,1025 +90,1025 @@ ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *nam
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("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);
debug->setEnabled( false ); // FIXME: disable the log button
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);
l1->addWidget(debug);
l1->addWidget(cancel);
// 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());
qApp->processEvents();
if(_ifaceppp->modem()->hangup()) {
qApp->processEvents();
semaphore = false;
_ifaceppp->modem()->stop();
_ifaceppp->modem()->notify(this, SLOT(readChar(unsigned char)));
// if we are stuck anywhere we will time out
timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
// this timer will run the script etc.
main_timer_ID = startTimer(10);
return;
}
}
// initialization failed
messg->setText(_ifaceppp->modem()->modemMessage());
vmain = 20; // wait until cancel is pressed
_ifaceppp->modem()->unlockdevice();
}
void ConnectWidget::timerEvent(QTimerEvent *) {
if (semaphore || pausing)
return;
if(vmain == 0) {
#ifdef DEBUG_WO_DIALING
vmain = 10;
return;
#endif
assert(PPPData::NumInitStrings > 0);
// first init string ?
if(substate == -1) {
messg->setText(i18n("Initializing modem..."));
emit debugMessage(i18n("Initializing modem..."));
substate = 0;
}
QString initStr = _ifaceppp->data()->modemInitStr(substate);
if (!initStr.isEmpty()) {
// send a carriage return and then wait a bit so that the modem will
// let us issue commands.
if(_ifaceppp->data()->modemPreInitDelay() > 0) {
usleep(_ifaceppp->data()->modemPreInitDelay() * 5000);
writeline("");
usleep(_ifaceppp->data()->modemPreInitDelay() * 5000);
}
setExpect(_ifaceppp->data()->modemInitResp());
writeline(initStr);
usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec
}
substate++;
/*
* FIXME after 3.0: Make it possible to disable ATS11 since it
* seems to be incompatible with some ISDN adapters (e.g. DataBox
* Speed Dragon). Even better would be to detect this when doing
* a "Modem Query"
*/
if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration())
vmain = 5;
else
vmain = 3;
return;
}
if (vmain == 5) {
if(!expecting) {
QString sToneDuration = "ATS11=" + QString::number(_ifaceppp->data()->modemToneDuration());
QString msg = i18n("Setting ") + sToneDuration;
messg->setText(msg);
emit debugMessage(msg);
setExpect(_ifaceppp->data()->modemInitResp());
writeline(sToneDuration);
}
vmain = 3;
return;
}
if(vmain == 3) {
if(!expecting) {
// done with all init strings ?
if(substate < PPPData::NumInitStrings) {
vmain = 0;
return;
}
substate = -1;
// skip setting the volume if command is empty
if(_ifaceppp->data()->volumeInitString().isEmpty()) {
vmain = 4;
return;
}
messg->setText(i18n("Setting speaker volume..."));
emit debugMessage(i18n("Setting speaker volume..."));
setExpect(_ifaceppp->data()->modemInitResp());
QString vol("AT");
vol += _ifaceppp->data()->volumeInitString();
writeline(vol);
usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec
vmain = 4;
return;
}
}
if(vmain == 4) {
if(!expecting) {
if(!_ifaceppp->data()->waitForDialTone()) {
QString msg = i18n("Turning off dial tone waiting...");
messg->setText(msg);
emit debugMessage(msg);
setExpect(_ifaceppp->data()->modemInitResp());
writeline(_ifaceppp->data()->modemNoDialToneDetectionStr());
}
vmain = 1;
return;
}
}
// dial the number and wait to connect
if(vmain == 1) {
if(!expecting) {
timeout_timer->stop();
timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
QStringList &plist = _ifaceppp->data()->phonenumbers();
QString bmarg= _ifaceppp->data()->dialPrefix();
bmarg += *plist.at(dialnumber);
QString bm = i18n("Dialing %1").arg(bmarg);
messg->setText(bm);
emit debugMessage(bm);
QString pn = _ifaceppp->data()->modemDialStr();
pn += _ifaceppp->data()->dialPrefix();
pn += *plist.at(dialnumber);
if(++dialnumber >= plist.count())
dialnumber = 0;
writeline(pn);
setExpect(_ifaceppp->data()->modemConnectResp());
vmain = 100;
return;
}
}
// wait for connect, but redial if BUSY or wait for user cancel
// if NO CARRIER or NO DIALTONE
if(vmain == 100) {
if(!expecting) {
myreadbuffer = _ifaceppp->data()->modemConnectResp();
setExpect("\n");
vmain = 101;
return;
}
if(readbuffer.contains(_ifaceppp->data()->modemBusyResp())) {
timeout_timer->stop();
timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
messg->setText(i18n("Line busy. Hanging up..."));
emit debugPutChar('\n');
_ifaceppp->modem()->hangup();
if(_ifaceppp->data()->busyWait() > 0) {
QString bm = i18n("Line busy. Waiting: %1 seconds").arg(_ifaceppp->data()->busyWait());
messg->setText(bm);
emit debugMessage(bm);
pausing = true;
pausetimer->start(_ifaceppp->data()->busyWait()*1000, true);
timeout_timer->stop();
}
_ifaceppp->modem()->setDataMode(false);
vmain = 0;
substate = -1;
return;
}
if(readbuffer.contains(_ifaceppp->data()->modemNoDialtoneResp())) {
timeout_timer->stop();
messg->setText(i18n("No Dialtone"));
vmain = 20;
_ifaceppp->modem()->unlockdevice();
return;
}
if(readbuffer.contains(_ifaceppp->data()->modemNoCarrierResp())) {
timeout_timer->stop();
messg->setText(i18n("No Carrier"));
vmain = 20;
_ifaceppp->modem()->unlockdevice();
return;
}
}
// wait for newline after CONNECT response (so we get the speed)
if(vmain == 101) {
if(!expecting) {
_ifaceppp->modem()->setDataMode(true); // modem will no longer respond to AT commands
emit startAccounting();
// p_kppp->con_win->startClock();
vmain = 2;
scriptTimeout=_ifaceppp->data()->modemTimeout()*1000;
return;
}
}
// execute the script
if(vmain == 2) {
if(!expecting && !pausing && !scanning) {
timeout_timer->stop();
timeout_timer->start(scriptTimeout);
if((unsigned) scriptindex < comlist->count()) {
scriptCommand = *(comlist->at(scriptindex));
scriptArgument = *(arglist->at(scriptindex));
} else {
qDebug( "End of script" );
vmain = 10;
return;
}
if (scriptCommand == "Scan") {
QString bm = i18n("Scanning %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
setScan(scriptArgument);
scriptindex++;
return;
}
if (scriptCommand == "Save") {
QString bm = i18n("Saving %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
if (scriptArgument.lower() == "password") {
_ifaceppp->data()->setPassword(scanvar);
// p_kppp->setPW_Edit(scanvar);
if(_ifaceppp->data()->storePassword())
_ifaceppp->data()->setStoredPassword(scanvar);
firstrunPW = true;
}
scriptindex++;
return;
}
if (scriptCommand == "Send" || scriptCommand == "SendNoEcho") {
QString bm = i18n("Sending %1");
// replace %USERNAME% and %PASSWORD%
QString arg = scriptArgument;
QRegExp re1("%USERNAME%");
QRegExp re2("%PASSWORD%");
arg = arg.replace(re1, _ifaceppp->data()->storedUsername());
arg = arg.replace(re2, _ifaceppp->data()->storedPassword());
if (scriptCommand == "Send")
bm = bm.arg(scriptArgument);
else {
for(uint i = 0; i < scriptArgument.length(); i++)
bm = bm.arg("*");
}
messg->setText(bm);
emit debugMessage(bm);
writeline(scriptArgument);
scriptindex++;
return;
}
if (scriptCommand == "Expect") {
QString bm = i18n("Expecting %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
// The incrementing of the scriptindex MUST be before the
// call to setExpect otherwise the expect will miss a string that is
// already in the buffer.
scriptindex++;
setExpect(scriptArgument);
return;
}
if (scriptCommand == "Pause") {
QString bm = i18n("Pause %1 seconds").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
pausing = true;
pausetimer->start(scriptArgument.toInt()*1000, true);
timeout_timer->stop();
scriptindex++;
return;
}
if (scriptCommand == "Timeout") {
timeout_timer->stop();
QString bm = i18n("Timeout %1 seconds").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
scriptTimeout=scriptArgument.toInt()*1000;
timeout_timer->start(scriptTimeout);
scriptindex++;
return;
}
if (scriptCommand == "Hangup") {
messg->setText(i18n("Hangup"));
emit debugMessage(i18n("Hangup"));
writeline(_ifaceppp->data()->modemHangupStr());
setExpect(_ifaceppp->data()->modemHangupResp());
scriptindex++;
return;
}
if (scriptCommand == "Answer") {
timeout_timer->stop();
messg->setText(i18n("Answer"));
emit debugMessage(i18n("Answer"));
setExpect(_ifaceppp->data()->modemRingResp());
vmain = 150;
return;
}
if (scriptCommand == "ID") {
QString bm = i18n("ID %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
- QString idstring = _ifaceppp->data()->storedUsername();
+ QString idstring = _ifaceppp->data()->password();
if(!idstring.isEmpty() && firstrunID) {
// the user entered an Id on the main kppp dialog
writeline(idstring);
firstrunID = false;
scriptindex++;
}
else {
// the user didn't enter and Id on the main kppp dialog
// let's query for an ID
/* if not around yet, then post window... */
if (prompt->Consumed()) {
if (!(prompt->isVisible())) {
prompt->setPrompt(scriptArgument);
prompt->setEchoModeNormal();
prompt->show();
}
} else {
/* if prompt withdrawn ... then, */
if(!(prompt->isVisible())) {
writeline(prompt->text());
prompt->setConsumed();
scriptindex++;
return;
}
/* replace timeout value */
}
}
}
if (scriptCommand == "Password") {
QString bm = i18n("Password %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
QString pwstring = _ifaceppp->data()->password();
if(!pwstring.isEmpty() && firstrunPW) {
// the user entered a password on the main kppp dialog
writeline(pwstring);
firstrunPW = false;
scriptindex++;
}
else {
// the user didn't enter a password on the main kppp dialog
// let's query for a password
/* if not around yet, then post window... */
if (prompt->Consumed()) {
if (!(prompt->isVisible())) {
prompt->setPrompt(scriptArgument);
prompt->setEchoModePassword();
prompt->show();
}
} else {
/* if prompt withdrawn ... then, */
if(!(prompt->isVisible())) {
// p_kppp->setPW_Edit(prompt->text());
writeline(prompt->text());
prompt->setConsumed();
scriptindex++;
return;
}
/* replace timeout value */
}
}
}
if (scriptCommand == "Prompt") {
QString bm = i18n("Prompting %1");
// if the scriptindex (aka the prompt text) includes a ## marker
// this marker should get substituted with the contents of our stored
// variable (from the subsequent scan).
QString ts = scriptArgument;
int vstart = ts.find( "##" );
if( vstart != -1 ) {
ts.remove( vstart, 2 );
ts.insert( vstart, scanvar );
}
bm = bm.arg(ts);
messg->setText(bm);
emit debugMessage(bm);
/* if not around yet, then post window... */
if (prompt->Consumed()) {
if (!(prompt->isVisible())) {
prompt->setPrompt( ts );
prompt->setEchoModeNormal();
prompt->show();
}
} else {
/* if prompt withdrawn ... then, */
if (!(prompt->isVisible())) {
writeline(prompt->text());
prompt->setConsumed();
scriptindex++;
return;
}
/* replace timeout value */
}
}
if (scriptCommand == "PWPrompt") {
QString bm = i18n("PW Prompt %1").arg(scriptArgument);
messg->setText(bm);
emit debugMessage(bm);
/* if not around yet, then post window... */
if (prompt->Consumed()) {
if (!(prompt->isVisible())) {
prompt->setPrompt(scriptArgument);
prompt->setEchoModePassword();
prompt->show();
}
} else {
/* if prompt withdrawn ... then, */
if (!(prompt->isVisible())) {
writeline(prompt->text());
prompt->setConsumed();
scriptindex++;
return;
}
/* replace timeout value */
}
}
if (scriptCommand == "LoopStart") {
QString bm = i18n("Loop Start %1").arg(scriptArgument);
// The incrementing of the scriptindex MUST be before the
// call to setExpect otherwise the expect will miss a string that is
// already in the buffer.
scriptindex++;
if ( loopnest > (MAXLOOPNEST-2) ) {
bm += i18n("ERROR: Nested too deep, ignored.");
vmain=20;
cancelbutton();
QMessageBox::critical(0, "error", i18n("Loops nested too deeply!"));
} else {
setExpect(scriptArgument);
loopstartindex[loopnest] = scriptindex;
loopstr[loopnest] = scriptArgument;
loopend = false;
loopnest++;
}
messg->setText(bm);
emit debugMessage(bm);
}
if (scriptCommand == "LoopEnd") {
QString bm = i18n("Loop End %1").arg(scriptArgument);
if ( loopnest <= 0 ) {
bm = i18n("LoopEnd without matching Start! Line: %1").arg(bm);
vmain=20;
cancelbutton();
QMessageBox::critical(0, "error", bm);
return;
} else {
// NB! The incrementing of the scriptindex MUST be before the
// call to setExpect otherwise the expect will miss a string
// that is already in the buffer.
scriptindex++;
setExpect(scriptArgument);
loopnest--;
loopend = true;
}
messg->setText(bm);
emit debugMessage(bm);
}
}
}
// this is a subroutine for the "Answer" script option
if(vmain == 150) {
if(!expecting) {
writeline(_ifaceppp->data()->modemAnswerStr());
setExpect(_ifaceppp->data()->modemAnswerResp());
vmain = 2;
scriptindex++;
return;
}
}
if(vmain == 30) {
// if (termwindow->isVisible())
// return;
// if (termwindow->pressedContinue())
// vmain = 10;
// else
cancelbutton();
}
if(vmain == 10) {
if(!expecting) {
int result;
timeout_timer->stop();
if_timeout_timer->stop(); // better be sure.
// stop reading of data
_ifaceppp->modem()->stop();
if(_ifaceppp->data()->authMethod() == AUTH_TERMINAL) {
// if (termwindow) {
// delete termwindow;
// termwindow = 0L;
// this->show();
// } else {
// termwindow = new LoginTerm(0L, 0L);
// hide();
// termwindow->show();
// vmain = 30;
// return;
// }
}
// Close the tty. This prevents the QTimer::singleShot() in
// Modem::readtty() from re-enabling the socket notifier.
// The port is still held open by the helper process.
_ifaceppp->modem()->closetty();
killTimer( main_timer_ID );
if_timeout_timer->start(_ifaceppp->data()->pppdTimeout()*1000);
qDebug( "started if timeout timer with %i", _ifaceppp->data()->pppdTimeout()*1000);
// find out PPP interface and notify the stats module
// stats->setUnit(pppInterfaceNumber());
qApp->flushX();
semaphore = true;
result = execppp();
emit debugMessage(i18n("Starting pppd..."));
qDebug("execppp() returned with return-code %i", result );
if(result) {
if(!_ifaceppp->data()->autoDNS())
adddns( _ifaceppp );
// O.K we are done here, let's change over to the if_waiting loop
// where we wait for the ppp if (interface) to come up.
emit if_waiting_signal();
} else {
// starting pppd wasn't successful. Error messages were
// handled by execppp();
if_timeout_timer->stop();
this->hide();
messg->setText("");
// p_kppp->quit_b->setFocus();
// p_kppp->show();
qApp->processEvents();
_ifaceppp->modem()->hangup();
emit stopAccounting();
// p_kppp->con_win->stopClock();
_ifaceppp->modem()->closetty();
_ifaceppp->modem()->unlockdevice();
}
return;
}
}
// this is a "wait until cancel" entry
if(vmain == 20) {
}
}
void ConnectWidget::set_con_speed_string() {
// Here we are trying to determine the speed at which we are connected.
// Usually the modem responds after connect with something like
// CONNECT 115200, so all we need to do is find the number after CONNECT
// or whatever the modemConnectResp() is.
// p_kppp->con_speed = _ifaceppp->modem()->parseModemSpeed(myreadbuffer);
}
void ConnectWidget::readChar(unsigned char c) {
if(semaphore)
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();
// p_kppp->quit_b->setFocus();
// p_kppp->show();
// 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();
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())
addpeerdns( _ifaceppp );
// Close the debugging window. If we are connected, we
// are not really interested in debug output
emit closeDebugWindow();
// p_kppp->statdlg->take_stats(); // start taking ppp statistics
auto_hostname(_ifaceppp);
if(!_ifaceppp->data()->command_on_connect().isEmpty()) {
messg->setText(i18n("Running startup command..."));
diff --git a/noncore/settings/networksettings/ppp/interfaceppp.cpp b/noncore/settings/networksettings/ppp/interfaceppp.cpp
index 98bb4da..85ddbee 100644
--- a/noncore/settings/networksettings/ppp/interfaceppp.cpp
+++ b/noncore/settings/networksettings/ppp/interfaceppp.cpp
@@ -1,140 +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),
_modemPtr(0),
_dataPtr(0)
{
qDebug("InterfacePPP::InterfacePPP(");
}
PPPData* InterfacePPP::data()
{
if (!_dataPtr){
qDebug("creating new Data obj");
_dataPtr = new PPPData();
_dataPtr->setModemDevice( getInterfaceName() );
_dataPtr->setAccount( getHardwareName() );
}
return _dataPtr;
}
Modem* InterfacePPP::modem()
{
if (!_modemPtr){
qDebug("creating new modem obj");
_modemPtr = new Modem( data() );
}
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()->password().isEmpty() ){
-//FIXME: ask for password
- qDebug("using dummy password");
- QMessageBox::critical( 0, "no password", "you should be prompted for a password, but you are not! ;-)");
- }
+// should work...
+// if (data()->password().isEmpty() ){
+// //FIXME: ask for password
+// qDebug("using dummy password");
+// QMessageBox::critical( 0, "no password", "you should be prompted for a password, but you are not! ;-)");
+// }
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){ //FIXME: 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;
}
// SEGFAULTS:
// setStatus( true );
// emit updateInterface((Interface*) this);
emit begin_connect();
qDebug("InterfacePPP::start END");
}
void InterfacePPP::stop()
{
qDebug("InterfacePPP::stop");
}
void InterfacePPP::save()
{
data()->save();
emit updateInterface((Interface*) this);
}