summaryrefslogtreecommitdiff
authortille <tille>2003-06-03 14:51:12 (UTC)
committer tille <tille>2003-06-03 14:51:12 (UTC)
commit33cf1711b4d74036fa27dc971c25df236b8d0355 (patch) (unidiff)
tree2a35ce380e40771089e22eed2d41dfc9577ff4cf
parent4e0c9efab5f3c73a1843e96983c9cd1894e44810 (diff)
downloadopie-33cf1711b4d74036fa27dc971c25df236b8d0355.zip
opie-33cf1711b4d74036fa27dc971c25df236b8d0355.tar.gz
opie-33cf1711b4d74036fa27dc971c25df236b8d0355.tar.bz2
should popup for passwd now...
Diffstat (more/less context) (ignore 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 @@
1 1
2#include <qlayout.h> 2#include <qlayout.h>
3#include <qmessagebox.h> 3#include <qmessagebox.h>
4#include <qtoolbutton.h> 4#include <qtoolbutton.h>
5#include <qwhatsthis.h> 5#include <qwhatsthis.h>
6 6
7#include "auth.h" 7#include "auth.h"
8#include "authwidget.h" 8#include "authwidget.h"
9#include "edit.h" 9#include "edit.h"
10#include "pppdata.h" 10#include "pppdata.h"
11 11
12 12
13static const char* const image0_data[] = { 13static const char* const image0_data[] = {
14"16 16 2 1", 14"16 16 2 1",
15". c None", 15". c None",
16"# c #000000", 16"# c #000000",
17"................", 17"................",
18"...#...###...##.", 18"...#...###...##.",
19"..#.#..#..#.##..", 19"..#.#..#..#.##..",
20"..###..###.##...", 20"..###..###.##...",
21".#...#.#..##....", 21".#...#.#..##....",
22".#...#.#.##.....", 22".#...#.#.##.....",
23"........##.#..#.", 23"........##.#..#.",
24"..##...##...##..", 24"..##...##...##..",
25".#..#.###...##..", 25".#..#.###...##..",
26".#...##..#.#..#.", 26".#...##..#.#..#.",
27".#..##..........", 27".#..##..........",
28".#.##.#..#.#..#.", 28".#.##.#..#.#..#.",
29"..##...##...##..", 29"..##...##...##..",
30".##....##...##..", 30".##....##...##..",
31".#....#..#.#..#.", 31".#....#..#.#..#.",
32"................"}; 32"................"};
33 33
34 34
35AuthWidget::AuthWidget(PPPData *pd, QWidget *parent, bool isnewaccount, const char *name ) 35AuthWidget::AuthWidget(PPPData *pd, QWidget *parent, bool isnewaccount, const char *name )
36 : QWidget( parent, name), 36 : QWidget( parent, name),
37 scriptWidget(0), 37 scriptWidget(0),
38 _pppdata(pd), 38 _pppdata(pd),
39 isNewAccount(isnewaccount) 39 isNewAccount(isnewaccount)
40{ 40{
41 layout = new QGridLayout(this); 41 layout = new QGridLayout(this);
42 42
43 auth_l = new QLabel(tr("Authentication: "), this); 43 auth_l = new QLabel(tr("Authentication: "), this);
44 layout->addWidget(auth_l, 0, 0); 44 layout->addWidget(auth_l, 0, 0);
45 45
46 auth = new QComboBox(this); 46 auth = new QComboBox(this);
47 auth->insertItem(tr("Script-based")); 47 auth->insertItem(tr("Script-based"));
48 auth->insertItem(tr("PAP")); 48 auth->insertItem(tr("PAP"));
49 auth->insertItem(tr("Terminal-based")); 49 auth->insertItem(tr("Terminal-based"));
50 auth->insertItem(tr("CHAP")); 50 auth->insertItem(tr("CHAP"));
51 auth->insertItem(tr("PAP/CHAP")); 51 auth->insertItem(tr("PAP/CHAP"));
52 layout->addWidget(auth, 0, 1); 52 layout->addWidget(auth, 0, 1);
53 53
54 connect( auth, SIGNAL(activated(const QString&)), 54 connect( auth, SIGNAL(activated(const QString&)),
55 SLOT(authChanged(const QString&))); 55 SLOT(authChanged(const QString&)));
56 56
57 QString tmp = tr("<p>Specifies the method used to identify yourself to\n" 57 QString tmp = tr("<p>Specifies the method used to identify yourself to\n"
58 "the PPP server. Most universities still use\n" 58 "the PPP server. Most universities still use\n"
59 "<b>Terminal</b>- or <b>Script</b>-based authentication,\n" 59 "<b>Terminal</b>- or <b>Script</b>-based authentication,\n"
60 "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n" 60 "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n"
61 "unsure, contact your ISP.\n" 61 "unsure, contact your ISP.\n"
62 "\n" 62 "\n"
63 "If you can choose between PAP and CHAP,\n" 63 "If you can choose between PAP and CHAP,\n"
64 "choose CHAP, because it's much safer. If you don't know\n" 64 "choose CHAP, because it's much safer. If you don't know\n"
65 "whether PAP or CHAP is right, choose PAP/CHAP."); 65 "whether PAP or CHAP is right, choose PAP/CHAP.");
66 66
67 QWhatsThis::add(auth_l,tmp); 67 QWhatsThis::add(auth_l,tmp);
68 QWhatsThis::add(auth,tmp); 68 QWhatsThis::add(auth,tmp);
69 69
70 user_l = new QLabel( tr("Username: "), this); 70 user_l = new QLabel( tr("Username: "), this);
71 layout->addWidget( user_l, 1, 0 ); 71 layout->addWidget( user_l, 1, 0 );
72 userName = new QLineEdit( this, "usernameEdit" ); 72 userName = new QLineEdit( this, "usernameEdit" );
73 layout->addWidget( userName, 1, 1 ); 73 layout->addWidget( userName, 1, 1 );
74 tmp = tr("Enter your username here..."); 74 tmp = tr("Enter your username here...");
75 QWhatsThis::add( user_l, tmp ); 75 QWhatsThis::add( user_l, tmp );
76 QWhatsThis::add( userName, tmp ); 76 QWhatsThis::add( userName, tmp );
77 77
78 pw_l = new QLabel( tr("Password: "), this); 78 pw_l = new QLabel( tr("Password: "), this);
79 layout->addWidget( pw_l, 2, 0 ); 79 layout->addWidget( pw_l, 2, 0 );
80 passWord = new QLineEdit( this, "pw" ); 80 passWord = new QLineEdit( this, "pw" );
81 passWord->setAutoMask( true ); 81 passWord->setAutoMask( true );
82 passWord->setEchoMode( QLineEdit::Password ); 82 passWord->setEchoMode( QLineEdit::Password );
83 layout->addWidget( passWord, 2, 1 ); 83 layout->addWidget( passWord, 2, 1 );
84 hidePw = new QToolButton( this ); 84 hidePw = new QToolButton( this );
85 hidePw->setPixmap( QPixmap( ( const char** ) image0_data ) ); 85 hidePw->setPixmap( QPixmap( ( const char** ) image0_data ) );
86 hidePw->setToggleButton( true ); 86 hidePw->setToggleButton( true );
87 layout->addWidget( hidePw, 2, 2 ); 87 layout->addWidget( hidePw, 2, 2 );
88 88
89 connect(hidePw, SIGNAL(toggled(bool)), SLOT(toggleEchoMode(bool))); 89 connect(hidePw, SIGNAL(toggled(bool)), SLOT(toggleEchoMode(bool)));
90 90
91 tmp = tr("Enter your password here"); 91 tmp = tr("Enter your password here");
92 QWhatsThis::add( pw_l, tmp ); 92 QWhatsThis::add( pw_l, tmp );
93 QWhatsThis::add( passWord, tmp ); 93 QWhatsThis::add( passWord, tmp );
94 94
95 store_password = new QCheckBox(tr("Store password"), this); 95 store_password = new QCheckBox(tr("Store password"), this);
96 layout->addMultiCellWidget(store_password, 3, 3, 0, 1, AlignRight); 96 layout->addMultiCellWidget(store_password, 3, 3, 0, 1, AlignRight);
97 QWhatsThis::add(store_password, 97 QWhatsThis::add(store_password,
98 tr("<p>When this is turned on, your ISP password\n" 98 tr("<p>When this is turned on, your ISP password\n"
99 "will be saved in <i>kppp</i>'s config file, so\n" 99 "will be saved in <i>kppp</i>'s config file, so\n"
100 "you do not need to type it in every time.\n" 100 "you do not need to type it in every time.\n"
101 "\n" 101 "\n"
102 "<b><font color=\"red\">Warning:</font> your password will be stored as\n" 102 "<b><font color=\"red\">Warning:</font> your password will be stored as\n"
103 "plain text in the config file, which is\n" 103 "plain text in the config file, which is\n"
104 "readable only to you. Make sure nobody\n" 104 "readable only to you. Make sure nobody\n"
105 "gains access to this file!")); 105 "gains access to this file!"));
106 106
107 if (isNewAccount){ 107 if (isNewAccount){
108 // select PAP/CHAP as default 108 // select PAP/CHAP as default
109 auth->setCurrentItem(AUTH_PAPCHAP); 109 auth->setCurrentItem(AUTH_PAPCHAP);
110 store_password->setChecked(true); 110 store_password->setChecked(true);
111 }else{ 111 }else{
112 auth->setCurrentItem(_pppdata->authMethod()); 112 auth->setCurrentItem(_pppdata->authMethod());
113 authChanged( auth->currentText() ); 113 authChanged( auth->currentText() );
114 userName->setText( _pppdata->storedUsername() ); 114 userName->setText( _pppdata->storedUsername() );
115 store_password->setChecked(_pppdata->storePassword()); 115 store_password->setChecked(_pppdata->storePassword());
116 if (store_password->isChecked()) 116 if (store_password->isChecked())
117 passWord->setText( _pppdata->storedPassword() ); 117 passWord->setText( _pppdata->storedPassword() );
118 } 118 }
119} 119}
120 120
121bool AuthWidget::check() 121bool AuthWidget::check()
122{ 122{
123 bool ret = true; 123 bool ret = true;
124 if (scriptWidget){ 124 if (scriptWidget){
125 if (!scriptWidget->check()){ 125 if (!scriptWidget->check()){
126 QMessageBox::critical(this, tr("error"), tr("<qt>Login script has unbalanced loop Start/End<qt>")); 126 QMessageBox::critical(this, tr("error"), tr("<qt>Login script has unbalanced loop Start/End<qt>"));
127 ret = false; 127 ret = false;
128 } 128 }
129 } 129 }
130 return ret; 130 return ret;
131} 131}
132 132
133void AuthWidget::save() 133void AuthWidget::save()
134{ 134{
135 _pppdata->setAuthMethod(auth->currentItem()); 135 _pppdata->setAuthMethod(auth->currentItem());
136 if (scriptWidget) scriptWidget->save(); 136 if (scriptWidget) scriptWidget->save();
137 _pppdata->setStoredUsername( userName->text() ); 137 _pppdata->setStoredUsername( userName->text() );
138 _pppdata->setStorePassword(store_password->isChecked()); 138 _pppdata->setStorePassword(store_password->isChecked());
139 if (store_password->isChecked()) 139 if (store_password->isChecked())
140 _pppdata->setStoredPassword( passWord->text() ); 140 _pppdata->setStoredPassword( passWord->text() );
141} 141}
142 142
143void AuthWidget::authChanged( const QString &authStr ) 143void AuthWidget::authChanged( const QString &authStr )
144{ 144{
145 qDebug("AuthWidget::authChanged( %s )", authStr.latin1() ); 145 qDebug("AuthWidget::authChanged( %s )", authStr.latin1() );
146 if ( authStr.contains( tr("Script-based") ) ){ 146 if ( authStr.contains( tr("Script-based") ) ){
147 showUsernamePassword( false ); 147 showUsernamePassword( false );
148 showScriptWindow( true ); 148 showScriptWindow( true );
149 } else if ( authStr.contains( tr("PAP") ) || 149 } else if ( authStr.contains( tr("PAP") ) ||
150 authStr.contains( tr("CHAP") ) ){ 150 authStr.contains( tr("CHAP") ) ){
151 showUsernamePassword( true ); 151 showUsernamePassword( true );
152 showScriptWindow( false ); 152 showScriptWindow( false );
153 } else { 153 } else {
154 qDebug("do not really know how to handle"); 154 qDebug("do not really know how to handle");
155 showUsernamePassword( false ); 155 showUsernamePassword( false );
156 showScriptWindow( false ); 156 showScriptWindow( false );
157 } 157 }
158} 158}
159 159
160 160
161void AuthWidget::showUsernamePassword( bool show ) 161void AuthWidget::showUsernamePassword( bool show )
162{ 162{
163 if (show){ 163 if (show){
164 user_l->show(); 164 user_l->show();
165 userName->show(); 165 userName->show();
166 pw_l->show(); 166 pw_l->show();
167 passWord->show(); 167 passWord->show();
168 store_password->show(); 168 store_password->show();
169 hidePw->show();
169 }else{//!show 170 }else{//!show
170 user_l->hide(); 171 user_l->hide();
171 userName->hide(); 172 userName->hide();
172 pw_l->hide(); 173 pw_l->hide();
173 passWord->hide(); 174 passWord->hide();
174 store_password->hide(); 175 store_password->hide();
176 hidePw->hide();
175 } 177 }
176} 178}
177 179
178void AuthWidget::showScriptWindow( bool show ) 180void AuthWidget::showScriptWindow( bool show )
179{ 181{
180 if (show){ 182 if (show){
181 if (!scriptWidget){ 183 if (!scriptWidget){
182 scriptWidget = new ScriptWidget( _pppdata, this, isNewAccount, "scriptWid"); 184 scriptWidget = new ScriptWidget( _pppdata, this, isNewAccount, "scriptWid");
183 layout->addMultiCellWidget( scriptWidget, 1, 4, 0, 1 ); 185 layout->addMultiCellWidget( scriptWidget, 1, 4, 0, 1 );
184 } 186 }
185 scriptWidget->show(); 187 scriptWidget->show();
186 }else{ // !show 188 }else{ // !show
187 if (scriptWidget) scriptWidget->hide(); 189 if (scriptWidget) scriptWidget->hide();
188 } 190 }
189} 191}
190 192
191void AuthWidget::toggleEchoMode( bool t ) 193void AuthWidget::toggleEchoMode( bool t )
192{ 194{
193 passWord->setEchoMode( t ? QLineEdit::Normal : QLineEdit::Password ); 195 passWord->setEchoMode( t ? QLineEdit::Normal : QLineEdit::Password );
194} 196}
195 197
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
@@ -1,1433 +1,1433 @@
1/* 1/*
2 * kPPP: A pppd front end for the KDE project 2 * kPPP: A pppd front end for the KDE project
3 * 3 *
4 * 4 *
5 * Copyright (C) 1997 Bernd Johannes Wuebben 5 * Copyright (C) 1997 Bernd Johannes Wuebben
6 * wuebben@math.cornell.edu 6 * wuebben@math.cornell.edu
7 * Copyright (C) 1998-2001 Harri Porten <porten@kde.org> 7 * Copyright (C) 1998-2001 Harri Porten <porten@kde.org>
8 * 8 *
9 * based on EzPPP: 9 * based on EzPPP:
10 * Copyright (C) 1997 Jay Painter 10 * Copyright (C) 1997 Jay Painter
11 * 11 *
12 * This program is free software; you can redistribute it and/or 12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public 13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either 14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version. 15 * version 2 of the License, or (at your option) any later version.
16 * 16 *
17 * This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details. 20 * Library General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU Library General Public 22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free 23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27//#include <config.h> 27//#include <config.h>
28 28
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qregexp.h> 30#include <qregexp.h>
31 31
32#include <qapplication.h> 32#include <qapplication.h>
33//#include <kdebug.h> 33//#include <kdebug.h>
34//#include <klocale.h> 34//#include <klocale.h>
35#define i18n QObject::tr 35#define i18n QObject::tr
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38 38
39#include <unistd.h> 39#include <unistd.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <string.h> 41#include <string.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <netdb.h> 43#include <netdb.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/socket.h> 45#include <sys/socket.h>
46#include <arpa/inet.h> 46#include <arpa/inet.h>
47#include <netinet/in.h> 47#include <netinet/in.h>
48#include <sys/ioctl.h> 48#include <sys/ioctl.h>
49#include <assert.h> 49#include <assert.h>
50 50
51#ifdef _XPG4_2 51#ifdef _XPG4_2
52 #define __xnet_connectconnect 52 #define __xnet_connectconnect
53#endif 53#endif
54 54
55#include <errno.h> 55#include <errno.h>
56 56
57#ifdef HAVE_SYS_PARAM_H 57#ifdef HAVE_SYS_PARAM_H
58#include <sys/param.h> 58#include <sys/param.h>
59#endif 59#endif
60 60
61#ifdef __linux__ 61#ifdef __linux__
62#include "runtests.h" 62#include "runtests.h"
63#endif 63#endif
64 64
65#include "auth.h" 65#include "auth.h"
66#include "connect.h" 66#include "connect.h"
67//#include "docking.h" 67//#include "docking.h"
68#include "interfaceppp.h" 68#include "interfaceppp.h"
69#include "modem.h" 69#include "modem.h"
70#include "kpppconfig.h" 70#include "kpppconfig.h"
71#include "pppdata.h" 71#include "pppdata.h"
72#include "kpppwidget.h" 72#include "kpppwidget.h"
73//#include "requester.h" 73//#include "requester.h"
74//#include "utils.h" 74//#include "utils.h"
75#define execute_command system 75#define execute_command system
76 76
77QString old_hostname; 77QString old_hostname;
78bool modified_hostname; 78bool modified_hostname;
79 79
80 80
81ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *name) 81ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *name)
82 : QWidget(parent, name), 82 : QWidget(parent, name),
83 myreadbuffer(""), 83 myreadbuffer(""),
84 main_timer_ID(0), 84 main_timer_ID(0),
85 vmain(0), 85 vmain(0),
86 substate(-1), 86 substate(-1),
87 scriptindex(0), 87 scriptindex(0),
88 loopnest(0), 88 loopnest(0),
89 loopend(false), 89 loopend(false),
90 semaphore(false), 90 semaphore(false),
91 expecting(false), 91 expecting(false),
92 readbuffer(""), 92 readbuffer(""),
93 scanvar(""), 93 scanvar(""),
94 scanning(false), 94 scanning(false),
95 pausing(false), 95 pausing(false),
96 dialnumber(0), 96 dialnumber(0),
97 _ifaceppp(ifp) 97 _ifaceppp(ifp)
98{ 98{
99 modified_hostname = false; 99 modified_hostname = false;
100 100
101 QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); 101 QVBoxLayout *tl = new QVBoxLayout(this, 8, 10);
102 QString tit = i18n("Connecting to: "); 102 QString tit = i18n("Connecting to: ");
103 setCaption(tit); 103 setCaption(tit);
104 104
105 QHBoxLayout *l0 = new QHBoxLayout(10); 105 QHBoxLayout *l0 = new QHBoxLayout(10);
106 tl->addLayout(l0); 106 tl->addLayout(l0);
107 l0->addSpacing(10); 107 l0->addSpacing(10);
108 messg = new QLabel(this, "messg"); 108 messg = new QLabel(this, "messg");
109 messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); 109 messg->setFrameStyle(QFrame::Panel|QFrame::Sunken);
110 messg->setAlignment(AlignCenter); 110 messg->setAlignment(AlignCenter);
111 messg->setText(i18n("Unable to create modem lock file.")); 111 messg->setText(i18n("Unable to create modem lock file."));
112 messg->setMinimumHeight(messg->sizeHint().height() + 5); 112 messg->setMinimumHeight(messg->sizeHint().height() + 5);
113// int messw = (messg->sizeHint().width() * 12) / 10; 113// int messw = (messg->sizeHint().width() * 12) / 10;
114// messw = QMAX(messw,280); 114// messw = QMAX(messw,280);
115// messg->setMinimumWidth(messw); 115// messg->setMinimumWidth(messw);
116 messg->setText(i18n("Offline")); 116 messg->setText(i18n("Offline"));
117 l0->addSpacing(10); 117 l0->addSpacing(10);
118 l0->addWidget(messg); 118 l0->addWidget(messg);
119 l0->addSpacing(10); 119 l0->addSpacing(10);
120 120
121 QHBoxLayout *l1 = new QHBoxLayout(10); 121 QHBoxLayout *l1 = new QHBoxLayout(10);
122 tl->addLayout(l1); 122 tl->addLayout(l1);
123 l1->addStretch(1); 123 l1->addStretch(1);
124 124
125 debug = new QPushButton(i18n("Log"), this); 125 debug = new QPushButton(i18n("Log"), this);
126 debug->setToggleButton(true); 126 debug->setToggleButton(true);
127 debug->setEnabled( false ); // FIXME: disable the log button 127 debug->setEnabled( false ); // FIXME: disable the log button
128 connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); 128 connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow()));
129 129
130 cancel = new QPushButton(i18n("Cancel"), this); 130 cancel = new QPushButton(i18n("Cancel"), this);
131 cancel->setFocus(); 131 cancel->setFocus();
132 connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); 132 connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton()));
133 133
134// int maxw = QMAX(cancel->sizeHint().width(), 134// int maxw = QMAX(cancel->sizeHint().width(),
135 // debug->sizeHint().width()); 135 // debug->sizeHint().width());
136// maxw = QMAX(maxw,65); 136// maxw = QMAX(maxw,65);
137// debug->setFixedWidth(maxw); 137// debug->setFixedWidth(maxw);
138// cancel->setFixedWidth(maxw); 138// cancel->setFixedWidth(maxw);
139 l1->addWidget(debug); 139 l1->addWidget(debug);
140 l1->addWidget(cancel); 140 l1->addWidget(cancel);
141 141
142// setFixedSize(sizeHint()); 142// setFixedSize(sizeHint());
143 143
144 pausetimer = new QTimer(this); 144 pausetimer = new QTimer(this);
145 connect(pausetimer, SIGNAL(timeout()), SLOT(pause())); 145 connect(pausetimer, SIGNAL(timeout()), SLOT(pause()));
146 146
147 qApp->processEvents(); 147 qApp->processEvents();
148 148
149 timeout_timer = new QTimer(this); 149 timeout_timer = new QTimer(this);
150 connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out())); 150 connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out()));
151 151
152 inittimer = new QTimer(this); 152 inittimer = new QTimer(this);
153 connect(inittimer, SIGNAL(timeout()), SLOT(init())); 153 connect(inittimer, SIGNAL(timeout()), SLOT(init()));
154 154
155 if_timeout_timer = new QTimer(this); 155 if_timeout_timer = new QTimer(this);
156 connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out())); 156 connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out()));
157 157
158 connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot())); 158 connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot()));
159 159
160 prompt = new PWEntry( this, "pw" ); 160 prompt = new PWEntry( this, "pw" );
161 if_timer = new QTimer(this); 161 if_timer = new QTimer(this);
162 connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); 162 connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot()));
163} 163}
164 164
165 165
166ConnectWidget::~ConnectWidget() { 166ConnectWidget::~ConnectWidget() {
167} 167}
168 168
169 169
170void ConnectWidget::preinit() { 170void ConnectWidget::preinit() {
171 // this is all just to keep the GUI nice and snappy .... 171 // this is all just to keep the GUI nice and snappy ....
172 // you have to see to believe ... 172 // you have to see to believe ...
173 messg->setText(i18n("Looking for modem...")); 173 messg->setText(i18n("Looking for modem..."));
174 inittimer->start(100); 174 inittimer->start(100);
175} 175}
176 176
177 177
178void ConnectWidget::init() { 178void ConnectWidget::init() {
179 _ifaceppp->data()->setpppdError(0); 179 _ifaceppp->data()->setpppdError(0);
180 inittimer->stop(); 180 inittimer->stop();
181 vmain = 0; 181 vmain = 0;
182 substate = -1; 182 substate = -1;
183 expecting = false; 183 expecting = false;
184 pausing = false; 184 pausing = false;
185 scriptindex = 0; 185 scriptindex = 0;
186 myreadbuffer = ""; 186 myreadbuffer = "";
187 scanning = false; 187 scanning = false;
188 scanvar = ""; 188 scanvar = "";
189 firstrunID = true; 189 firstrunID = true;
190 firstrunPW = true; 190 firstrunPW = true;
191// stats->totalbytes = 0; 191// stats->totalbytes = 0;
192 dialnumber = 0; 192 dialnumber = 0;
193 193
194// p_kppp->con_speed = ""; 194// p_kppp->con_speed = "";
195 195
196// p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect()); 196// p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect());
197 197
198 comlist = &_ifaceppp->data()->scriptType(); 198 comlist = &_ifaceppp->data()->scriptType();
199 arglist = &_ifaceppp->data()->script(); 199 arglist = &_ifaceppp->data()->script();
200 200
201 QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname()); 201 QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname());
202 setCaption(tit); 202 setCaption(tit);
203 203
204 qApp->processEvents(); 204 qApp->processEvents();
205 205
206 // run the "before-connect" command 206 // run the "before-connect" command
207 if (!_ifaceppp->data()->command_before_connect().isEmpty()) { 207 if (!_ifaceppp->data()->command_before_connect().isEmpty()) {
208 messg->setText(i18n("Running pre-startup command...")); 208 messg->setText(i18n("Running pre-startup command..."));
209 emit debugMessage(i18n("Running pre-startup command...")); 209 emit debugMessage(i18n("Running pre-startup command..."));
210 210
211 qApp->processEvents(); 211 qApp->processEvents();
212 QApplication::flushX(); 212 QApplication::flushX();
213 pid_t id = execute_command(_ifaceppp->data()->command_before_connect()); 213 pid_t id = execute_command(_ifaceppp->data()->command_before_connect());
214// int i, status; 214// int i, status;
215 215
216// do { 216// do {
217// qApp->processEvents(); 217// qApp->processEvents();
218// i = waitpid(id, &status, WNOHANG); 218// i = waitpid(id, &status, WNOHANG);
219// usleep(100000); 219// usleep(100000);
220// } while (i == 0 && errno == 0); 220// } while (i == 0 && errno == 0);
221 } 221 }
222 222
223 int lock = _ifaceppp->modem()->lockdevice(); 223 int lock = _ifaceppp->modem()->lockdevice();
224 224
225 if (lock == 1) { 225 if (lock == 1) {
226 messg->setText(i18n("Modem device is locked.")); 226 messg->setText(i18n("Modem device is locked."));
227 vmain = 20; // wait until cancel is pressed 227 vmain = 20; // wait until cancel is pressed
228 return; 228 return;
229 } 229 }
230 230
231 if (lock == -1) { 231 if (lock == -1) {
232 messg->setText(i18n("Unable to create modem lock file.")); 232 messg->setText(i18n("Unable to create modem lock file."));
233 vmain = 20; // wait until cancel is pressed 233 vmain = 20; // wait until cancel is pressed
234 return; 234 return;
235 } 235 }
236 236
237 if(_ifaceppp->modem()->opentty()) { 237 if(_ifaceppp->modem()->opentty()) {
238 messg->setText(_ifaceppp->modem()->modemMessage()); 238 messg->setText(_ifaceppp->modem()->modemMessage());
239 qApp->processEvents(); 239 qApp->processEvents();
240 if(_ifaceppp->modem()->hangup()) { 240 if(_ifaceppp->modem()->hangup()) {
241 241
242 qApp->processEvents(); 242 qApp->processEvents();
243 243
244 semaphore = false; 244 semaphore = false;
245 245
246 _ifaceppp->modem()->stop(); 246 _ifaceppp->modem()->stop();
247 _ifaceppp->modem()->notify(this, SLOT(readChar(unsigned char))); 247 _ifaceppp->modem()->notify(this, SLOT(readChar(unsigned char)));
248 248
249 // if we are stuck anywhere we will time out 249 // if we are stuck anywhere we will time out
250 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); 250 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
251 251
252 // this timer will run the script etc. 252 // this timer will run the script etc.
253 main_timer_ID = startTimer(10); 253 main_timer_ID = startTimer(10);
254 254
255 return; 255 return;
256 } 256 }
257 } 257 }
258 258
259 // initialization failed 259 // initialization failed
260 messg->setText(_ifaceppp->modem()->modemMessage()); 260 messg->setText(_ifaceppp->modem()->modemMessage());
261 vmain = 20; // wait until cancel is pressed 261 vmain = 20; // wait until cancel is pressed
262 _ifaceppp->modem()->unlockdevice(); 262 _ifaceppp->modem()->unlockdevice();
263} 263}
264 264
265 265
266void ConnectWidget::timerEvent(QTimerEvent *) { 266void ConnectWidget::timerEvent(QTimerEvent *) {
267 if (semaphore || pausing) 267 if (semaphore || pausing)
268 return; 268 return;
269 269
270 if(vmain == 0) { 270 if(vmain == 0) {
271#ifdef DEBUG_WO_DIALING 271#ifdef DEBUG_WO_DIALING
272 vmain = 10; 272 vmain = 10;
273 return; 273 return;
274#endif 274#endif
275 275
276 assert(PPPData::NumInitStrings > 0); 276 assert(PPPData::NumInitStrings > 0);
277 // first init string ? 277 // first init string ?
278 if(substate == -1) { 278 if(substate == -1) {
279 messg->setText(i18n("Initializing modem...")); 279 messg->setText(i18n("Initializing modem..."));
280 emit debugMessage(i18n("Initializing modem...")); 280 emit debugMessage(i18n("Initializing modem..."));
281 substate = 0; 281 substate = 0;
282 } 282 }
283 283
284 QString initStr = _ifaceppp->data()->modemInitStr(substate); 284 QString initStr = _ifaceppp->data()->modemInitStr(substate);
285 if (!initStr.isEmpty()) { 285 if (!initStr.isEmpty()) {
286 // send a carriage return and then wait a bit so that the modem will 286 // send a carriage return and then wait a bit so that the modem will
287 // let us issue commands. 287 // let us issue commands.
288 if(_ifaceppp->data()->modemPreInitDelay() > 0) { 288 if(_ifaceppp->data()->modemPreInitDelay() > 0) {
289 usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); 289 usleep(_ifaceppp->data()->modemPreInitDelay() * 5000);
290 writeline(""); 290 writeline("");
291 usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); 291 usleep(_ifaceppp->data()->modemPreInitDelay() * 5000);
292 } 292 }
293 setExpect(_ifaceppp->data()->modemInitResp()); 293 setExpect(_ifaceppp->data()->modemInitResp());
294 writeline(initStr); 294 writeline(initStr);
295 usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec 295 usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec
296 } 296 }
297 297
298 substate++; 298 substate++;
299 299
300 /* 300 /*
301 * FIXME after 3.0: Make it possible to disable ATS11 since it 301 * FIXME after 3.0: Make it possible to disable ATS11 since it
302 * seems to be incompatible with some ISDN adapters (e.g. DataBox 302 * seems to be incompatible with some ISDN adapters (e.g. DataBox
303 * Speed Dragon). Even better would be to detect this when doing 303 * Speed Dragon). Even better would be to detect this when doing
304 * a "Modem Query" 304 * a "Modem Query"
305 */ 305 */
306 if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration()) 306 if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration())
307 vmain = 5; 307 vmain = 5;
308 else 308 else
309 vmain = 3; 309 vmain = 3;
310 310
311 return; 311 return;
312 } 312 }
313 313
314 if (vmain == 5) { 314 if (vmain == 5) {
315 if(!expecting) { 315 if(!expecting) {
316 QString sToneDuration = "ATS11=" + QString::number(_ifaceppp->data()->modemToneDuration()); 316 QString sToneDuration = "ATS11=" + QString::number(_ifaceppp->data()->modemToneDuration());
317 QString msg = i18n("Setting ") + sToneDuration; 317 QString msg = i18n("Setting ") + sToneDuration;
318 messg->setText(msg); 318 messg->setText(msg);
319 emit debugMessage(msg); 319 emit debugMessage(msg);
320 setExpect(_ifaceppp->data()->modemInitResp()); 320 setExpect(_ifaceppp->data()->modemInitResp());
321 writeline(sToneDuration); 321 writeline(sToneDuration);
322 } 322 }
323 vmain = 3; 323 vmain = 3;
324 return; 324 return;
325 } 325 }
326 326
327 if(vmain == 3) { 327 if(vmain == 3) {
328 if(!expecting) { 328 if(!expecting) {
329 // done with all init strings ? 329 // done with all init strings ?
330 if(substate < PPPData::NumInitStrings) { 330 if(substate < PPPData::NumInitStrings) {
331 vmain = 0; 331 vmain = 0;
332 return; 332 return;
333 } 333 }
334 substate = -1; 334 substate = -1;
335 // skip setting the volume if command is empty 335 // skip setting the volume if command is empty
336 if(_ifaceppp->data()->volumeInitString().isEmpty()) { 336 if(_ifaceppp->data()->volumeInitString().isEmpty()) {
337 vmain = 4; 337 vmain = 4;
338 return; 338 return;
339 } 339 }
340 messg->setText(i18n("Setting speaker volume...")); 340 messg->setText(i18n("Setting speaker volume..."));
341 emit debugMessage(i18n("Setting speaker volume...")); 341 emit debugMessage(i18n("Setting speaker volume..."));
342 342
343 setExpect(_ifaceppp->data()->modemInitResp()); 343 setExpect(_ifaceppp->data()->modemInitResp());
344 QString vol("AT"); 344 QString vol("AT");
345 vol += _ifaceppp->data()->volumeInitString(); 345 vol += _ifaceppp->data()->volumeInitString();
346 writeline(vol); 346 writeline(vol);
347 usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec 347 usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec
348 vmain = 4; 348 vmain = 4;
349 return; 349 return;
350 } 350 }
351 } 351 }
352 352
353 if(vmain == 4) { 353 if(vmain == 4) {
354 if(!expecting) { 354 if(!expecting) {
355 if(!_ifaceppp->data()->waitForDialTone()) { 355 if(!_ifaceppp->data()->waitForDialTone()) {
356 QString msg = i18n("Turning off dial tone waiting..."); 356 QString msg = i18n("Turning off dial tone waiting...");
357 messg->setText(msg); 357 messg->setText(msg);
358 emit debugMessage(msg); 358 emit debugMessage(msg);
359 setExpect(_ifaceppp->data()->modemInitResp()); 359 setExpect(_ifaceppp->data()->modemInitResp());
360 writeline(_ifaceppp->data()->modemNoDialToneDetectionStr()); 360 writeline(_ifaceppp->data()->modemNoDialToneDetectionStr());
361 } 361 }
362 vmain = 1; 362 vmain = 1;
363 return; 363 return;
364 } 364 }
365 } 365 }
366 366
367 // dial the number and wait to connect 367 // dial the number and wait to connect
368 if(vmain == 1) { 368 if(vmain == 1) {
369 if(!expecting) { 369 if(!expecting) {
370 370
371 timeout_timer->stop(); 371 timeout_timer->stop();
372 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); 372 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
373 373
374 QStringList &plist = _ifaceppp->data()->phonenumbers(); 374 QStringList &plist = _ifaceppp->data()->phonenumbers();
375 QString bmarg= _ifaceppp->data()->dialPrefix(); 375 QString bmarg= _ifaceppp->data()->dialPrefix();
376 bmarg += *plist.at(dialnumber); 376 bmarg += *plist.at(dialnumber);
377 QString bm = i18n("Dialing %1").arg(bmarg); 377 QString bm = i18n("Dialing %1").arg(bmarg);
378 messg->setText(bm); 378 messg->setText(bm);
379 emit debugMessage(bm); 379 emit debugMessage(bm);
380 380
381 QString pn = _ifaceppp->data()->modemDialStr(); 381 QString pn = _ifaceppp->data()->modemDialStr();
382 pn += _ifaceppp->data()->dialPrefix(); 382 pn += _ifaceppp->data()->dialPrefix();
383 pn += *plist.at(dialnumber); 383 pn += *plist.at(dialnumber);
384 if(++dialnumber >= plist.count()) 384 if(++dialnumber >= plist.count())
385 dialnumber = 0; 385 dialnumber = 0;
386 writeline(pn); 386 writeline(pn);
387 387
388 setExpect(_ifaceppp->data()->modemConnectResp()); 388 setExpect(_ifaceppp->data()->modemConnectResp());
389 vmain = 100; 389 vmain = 100;
390 return; 390 return;
391 } 391 }
392 } 392 }
393 393
394 // wait for connect, but redial if BUSY or wait for user cancel 394 // wait for connect, but redial if BUSY or wait for user cancel
395 // if NO CARRIER or NO DIALTONE 395 // if NO CARRIER or NO DIALTONE
396 if(vmain == 100) { 396 if(vmain == 100) {
397 if(!expecting) { 397 if(!expecting) {
398 myreadbuffer = _ifaceppp->data()->modemConnectResp(); 398 myreadbuffer = _ifaceppp->data()->modemConnectResp();
399 setExpect("\n"); 399 setExpect("\n");
400 vmain = 101; 400 vmain = 101;
401 return; 401 return;
402 } 402 }
403 403
404 if(readbuffer.contains(_ifaceppp->data()->modemBusyResp())) { 404 if(readbuffer.contains(_ifaceppp->data()->modemBusyResp())) {
405 timeout_timer->stop(); 405 timeout_timer->stop();
406 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); 406 timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000);
407 407
408 messg->setText(i18n("Line busy. Hanging up...")); 408 messg->setText(i18n("Line busy. Hanging up..."));
409 emit debugPutChar('\n'); 409 emit debugPutChar('\n');
410 _ifaceppp->modem()->hangup(); 410 _ifaceppp->modem()->hangup();
411 411
412 if(_ifaceppp->data()->busyWait() > 0) { 412 if(_ifaceppp->data()->busyWait() > 0) {
413 QString bm = i18n("Line busy. Waiting: %1 seconds").arg(_ifaceppp->data()->busyWait()); 413 QString bm = i18n("Line busy. Waiting: %1 seconds").arg(_ifaceppp->data()->busyWait());
414 messg->setText(bm); 414 messg->setText(bm);
415 emit debugMessage(bm); 415 emit debugMessage(bm);
416 416
417 pausing = true; 417 pausing = true;
418 418
419 pausetimer->start(_ifaceppp->data()->busyWait()*1000, true); 419 pausetimer->start(_ifaceppp->data()->busyWait()*1000, true);
420 timeout_timer->stop(); 420 timeout_timer->stop();
421 } 421 }
422 422
423 _ifaceppp->modem()->setDataMode(false); 423 _ifaceppp->modem()->setDataMode(false);
424 vmain = 0; 424 vmain = 0;
425 substate = -1; 425 substate = -1;
426 return; 426 return;
427 } 427 }
428 428
429 if(readbuffer.contains(_ifaceppp->data()->modemNoDialtoneResp())) { 429 if(readbuffer.contains(_ifaceppp->data()->modemNoDialtoneResp())) {
430 timeout_timer->stop(); 430 timeout_timer->stop();
431 431
432 messg->setText(i18n("No Dialtone")); 432 messg->setText(i18n("No Dialtone"));
433 vmain = 20; 433 vmain = 20;
434 _ifaceppp->modem()->unlockdevice(); 434 _ifaceppp->modem()->unlockdevice();
435 return; 435 return;
436 } 436 }
437 437
438 if(readbuffer.contains(_ifaceppp->data()->modemNoCarrierResp())) { 438 if(readbuffer.contains(_ifaceppp->data()->modemNoCarrierResp())) {
439 timeout_timer->stop(); 439 timeout_timer->stop();
440 440
441 messg->setText(i18n("No Carrier")); 441 messg->setText(i18n("No Carrier"));
442 vmain = 20; 442 vmain = 20;
443 _ifaceppp->modem()->unlockdevice(); 443 _ifaceppp->modem()->unlockdevice();
444 return; 444 return;
445 } 445 }
446 } 446 }
447 447
448 // wait for newline after CONNECT response (so we get the speed) 448 // wait for newline after CONNECT response (so we get the speed)
449 if(vmain == 101) { 449 if(vmain == 101) {
450 if(!expecting) { 450 if(!expecting) {
451 _ifaceppp->modem()->setDataMode(true); // modem will no longer respond to AT commands 451 _ifaceppp->modem()->setDataMode(true); // modem will no longer respond to AT commands
452 452
453 emit startAccounting(); 453 emit startAccounting();
454// p_kppp->con_win->startClock(); 454// p_kppp->con_win->startClock();
455 455
456 vmain = 2; 456 vmain = 2;
457 scriptTimeout=_ifaceppp->data()->modemTimeout()*1000; 457 scriptTimeout=_ifaceppp->data()->modemTimeout()*1000;
458 return; 458 return;
459 } 459 }
460 } 460 }
461 461
462 // execute the script 462 // execute the script
463 if(vmain == 2) { 463 if(vmain == 2) {
464 if(!expecting && !pausing && !scanning) { 464 if(!expecting && !pausing && !scanning) {
465 465
466 timeout_timer->stop(); 466 timeout_timer->stop();
467 timeout_timer->start(scriptTimeout); 467 timeout_timer->start(scriptTimeout);
468 468
469 if((unsigned) scriptindex < comlist->count()) { 469 if((unsigned) scriptindex < comlist->count()) {
470 scriptCommand = *(comlist->at(scriptindex)); 470 scriptCommand = *(comlist->at(scriptindex));
471 scriptArgument = *(arglist->at(scriptindex)); 471 scriptArgument = *(arglist->at(scriptindex));
472 } else { 472 } else {
473 qDebug( "End of script" ); 473 qDebug( "End of script" );
474 vmain = 10; 474 vmain = 10;
475 return; 475 return;
476 } 476 }
477 477
478 if (scriptCommand == "Scan") { 478 if (scriptCommand == "Scan") {
479 QString bm = i18n("Scanning %1").arg(scriptArgument); 479 QString bm = i18n("Scanning %1").arg(scriptArgument);
480 messg->setText(bm); 480 messg->setText(bm);
481 emit debugMessage(bm); 481 emit debugMessage(bm);
482 482
483 setScan(scriptArgument); 483 setScan(scriptArgument);
484 scriptindex++; 484 scriptindex++;
485 return; 485 return;
486 } 486 }
487 487
488 if (scriptCommand == "Save") { 488 if (scriptCommand == "Save") {
489 QString bm = i18n("Saving %1").arg(scriptArgument); 489 QString bm = i18n("Saving %1").arg(scriptArgument);
490 messg->setText(bm); 490 messg->setText(bm);
491 emit debugMessage(bm); 491 emit debugMessage(bm);
492 492
493 if (scriptArgument.lower() == "password") { 493 if (scriptArgument.lower() == "password") {
494 _ifaceppp->data()->setPassword(scanvar); 494 _ifaceppp->data()->setPassword(scanvar);
495 // p_kppp->setPW_Edit(scanvar); 495 // p_kppp->setPW_Edit(scanvar);
496 if(_ifaceppp->data()->storePassword()) 496 if(_ifaceppp->data()->storePassword())
497 _ifaceppp->data()->setStoredPassword(scanvar); 497 _ifaceppp->data()->setStoredPassword(scanvar);
498 firstrunPW = true; 498 firstrunPW = true;
499 } 499 }
500 500
501 scriptindex++; 501 scriptindex++;
502 return; 502 return;
503 } 503 }
504 504
505 505
506 if (scriptCommand == "Send" || scriptCommand == "SendNoEcho") { 506 if (scriptCommand == "Send" || scriptCommand == "SendNoEcho") {
507 QString bm = i18n("Sending %1"); 507 QString bm = i18n("Sending %1");
508 508
509 // replace %USERNAME% and %PASSWORD% 509 // replace %USERNAME% and %PASSWORD%
510 QString arg = scriptArgument; 510 QString arg = scriptArgument;
511 QRegExp re1("%USERNAME%"); 511 QRegExp re1("%USERNAME%");
512 QRegExp re2("%PASSWORD%"); 512 QRegExp re2("%PASSWORD%");
513 arg = arg.replace(re1, _ifaceppp->data()->storedUsername()); 513 arg = arg.replace(re1, _ifaceppp->data()->storedUsername());
514 arg = arg.replace(re2, _ifaceppp->data()->storedPassword()); 514 arg = arg.replace(re2, _ifaceppp->data()->storedPassword());
515 515
516 if (scriptCommand == "Send") 516 if (scriptCommand == "Send")
517 bm = bm.arg(scriptArgument); 517 bm = bm.arg(scriptArgument);
518 else { 518 else {
519 for(uint i = 0; i < scriptArgument.length(); i++) 519 for(uint i = 0; i < scriptArgument.length(); i++)
520 bm = bm.arg("*"); 520 bm = bm.arg("*");
521 } 521 }
522 522
523 messg->setText(bm); 523 messg->setText(bm);
524 emit debugMessage(bm); 524 emit debugMessage(bm);
525 525
526 writeline(scriptArgument); 526 writeline(scriptArgument);
527 scriptindex++; 527 scriptindex++;
528 return; 528 return;
529 } 529 }
530 530
531 if (scriptCommand == "Expect") { 531 if (scriptCommand == "Expect") {
532 QString bm = i18n("Expecting %1").arg(scriptArgument); 532 QString bm = i18n("Expecting %1").arg(scriptArgument);
533 messg->setText(bm); 533 messg->setText(bm);
534 emit debugMessage(bm); 534 emit debugMessage(bm);
535 535
536 // The incrementing of the scriptindex MUST be before the 536 // The incrementing of the scriptindex MUST be before the
537 // call to setExpect otherwise the expect will miss a string that is 537 // call to setExpect otherwise the expect will miss a string that is
538 // already in the buffer. 538 // already in the buffer.
539 scriptindex++; 539 scriptindex++;
540 setExpect(scriptArgument); 540 setExpect(scriptArgument);
541 return; 541 return;
542 } 542 }
543 543
544 544
545 if (scriptCommand == "Pause") { 545 if (scriptCommand == "Pause") {
546 QString bm = i18n("Pause %1 seconds").arg(scriptArgument); 546 QString bm = i18n("Pause %1 seconds").arg(scriptArgument);
547 messg->setText(bm); 547 messg->setText(bm);
548 emit debugMessage(bm); 548 emit debugMessage(bm);
549 549
550 pausing = true; 550 pausing = true;
551 551
552 pausetimer->start(scriptArgument.toInt()*1000, true); 552 pausetimer->start(scriptArgument.toInt()*1000, true);
553 timeout_timer->stop(); 553 timeout_timer->stop();
554 554
555 scriptindex++; 555 scriptindex++;
556 return; 556 return;
557 } 557 }
558 558
559 if (scriptCommand == "Timeout") { 559 if (scriptCommand == "Timeout") {
560 560
561 timeout_timer->stop(); 561 timeout_timer->stop();
562 562
563 QString bm = i18n("Timeout %1 seconds").arg(scriptArgument); 563 QString bm = i18n("Timeout %1 seconds").arg(scriptArgument);
564 messg->setText(bm); 564 messg->setText(bm);
565 emit debugMessage(bm); 565 emit debugMessage(bm);
566 566
567 scriptTimeout=scriptArgument.toInt()*1000; 567 scriptTimeout=scriptArgument.toInt()*1000;
568 timeout_timer->start(scriptTimeout); 568 timeout_timer->start(scriptTimeout);
569 569
570 scriptindex++; 570 scriptindex++;
571 return; 571 return;
572 } 572 }
573 573
574 if (scriptCommand == "Hangup") { 574 if (scriptCommand == "Hangup") {
575 messg->setText(i18n("Hangup")); 575 messg->setText(i18n("Hangup"));
576 emit debugMessage(i18n("Hangup")); 576 emit debugMessage(i18n("Hangup"));
577 577
578 writeline(_ifaceppp->data()->modemHangupStr()); 578 writeline(_ifaceppp->data()->modemHangupStr());
579 setExpect(_ifaceppp->data()->modemHangupResp()); 579 setExpect(_ifaceppp->data()->modemHangupResp());
580 580
581 scriptindex++; 581 scriptindex++;
582 return; 582 return;
583 } 583 }
584 584
585 if (scriptCommand == "Answer") { 585 if (scriptCommand == "Answer") {
586 586
587 timeout_timer->stop(); 587 timeout_timer->stop();
588 588
589 messg->setText(i18n("Answer")); 589 messg->setText(i18n("Answer"));
590 emit debugMessage(i18n("Answer")); 590 emit debugMessage(i18n("Answer"));
591 591
592 setExpect(_ifaceppp->data()->modemRingResp()); 592 setExpect(_ifaceppp->data()->modemRingResp());
593 vmain = 150; 593 vmain = 150;
594 return; 594 return;
595 } 595 }
596 596
597 if (scriptCommand == "ID") { 597 if (scriptCommand == "ID") {
598 QString bm = i18n("ID %1").arg(scriptArgument); 598 QString bm = i18n("ID %1").arg(scriptArgument);
599 messg->setText(bm); 599 messg->setText(bm);
600 emit debugMessage(bm); 600 emit debugMessage(bm);
601 601
602 QString idstring = _ifaceppp->data()->storedUsername(); 602 QString idstring = _ifaceppp->data()->password();
603 603
604 if(!idstring.isEmpty() && firstrunID) { 604 if(!idstring.isEmpty() && firstrunID) {
605 // the user entered an Id on the main kppp dialog 605 // the user entered an Id on the main kppp dialog
606 writeline(idstring); 606 writeline(idstring);
607 firstrunID = false; 607 firstrunID = false;
608 scriptindex++; 608 scriptindex++;
609 } 609 }
610 else { 610 else {
611 // the user didn't enter and Id on the main kppp dialog 611 // the user didn't enter and Id on the main kppp dialog
612 // let's query for an ID 612 // let's query for an ID
613 /* if not around yet, then post window... */ 613 /* if not around yet, then post window... */
614 if (prompt->Consumed()) { 614 if (prompt->Consumed()) {
615 if (!(prompt->isVisible())) { 615 if (!(prompt->isVisible())) {
616 prompt->setPrompt(scriptArgument); 616 prompt->setPrompt(scriptArgument);
617 prompt->setEchoModeNormal(); 617 prompt->setEchoModeNormal();
618 prompt->show(); 618 prompt->show();
619 } 619 }
620 } else { 620 } else {
621 /* if prompt withdrawn ... then, */ 621 /* if prompt withdrawn ... then, */
622 if(!(prompt->isVisible())) { 622 if(!(prompt->isVisible())) {
623 writeline(prompt->text()); 623 writeline(prompt->text());
624 prompt->setConsumed(); 624 prompt->setConsumed();
625 scriptindex++; 625 scriptindex++;
626 return; 626 return;
627 } 627 }
628 /* replace timeout value */ 628 /* replace timeout value */
629 } 629 }
630 } 630 }
631 } 631 }
632 632
633 if (scriptCommand == "Password") { 633 if (scriptCommand == "Password") {
634 QString bm = i18n("Password %1").arg(scriptArgument); 634 QString bm = i18n("Password %1").arg(scriptArgument);
635 messg->setText(bm); 635 messg->setText(bm);
636 emit debugMessage(bm); 636 emit debugMessage(bm);
637 637
638 QString pwstring = _ifaceppp->data()->password(); 638 QString pwstring = _ifaceppp->data()->password();
639 639
640 if(!pwstring.isEmpty() && firstrunPW) { 640 if(!pwstring.isEmpty() && firstrunPW) {
641 // the user entered a password on the main kppp dialog 641 // the user entered a password on the main kppp dialog
642 writeline(pwstring); 642 writeline(pwstring);
643 firstrunPW = false; 643 firstrunPW = false;
644 scriptindex++; 644 scriptindex++;
645 } 645 }
646 else { 646 else {
647 // the user didn't enter a password on the main kppp dialog 647 // the user didn't enter a password on the main kppp dialog
648 // let's query for a password 648 // let's query for a password
649 /* if not around yet, then post window... */ 649 /* if not around yet, then post window... */
650 if (prompt->Consumed()) { 650 if (prompt->Consumed()) {
651 if (!(prompt->isVisible())) { 651 if (!(prompt->isVisible())) {
652 prompt->setPrompt(scriptArgument); 652 prompt->setPrompt(scriptArgument);
653 prompt->setEchoModePassword(); 653 prompt->setEchoModePassword();
654 prompt->show(); 654 prompt->show();
655 } 655 }
656 } else { 656 } else {
657 /* if prompt withdrawn ... then, */ 657 /* if prompt withdrawn ... then, */
658 if(!(prompt->isVisible())) { 658 if(!(prompt->isVisible())) {
659 // p_kppp->setPW_Edit(prompt->text()); 659 // p_kppp->setPW_Edit(prompt->text());
660 writeline(prompt->text()); 660 writeline(prompt->text());
661 prompt->setConsumed(); 661 prompt->setConsumed();
662 scriptindex++; 662 scriptindex++;
663 return; 663 return;
664 } 664 }
665 /* replace timeout value */ 665 /* replace timeout value */
666 } 666 }
667 } 667 }
668 } 668 }
669 669
670 if (scriptCommand == "Prompt") { 670 if (scriptCommand == "Prompt") {
671 QString bm = i18n("Prompting %1"); 671 QString bm = i18n("Prompting %1");
672 672
673 // if the scriptindex (aka the prompt text) includes a ## marker 673 // if the scriptindex (aka the prompt text) includes a ## marker
674 // this marker should get substituted with the contents of our stored 674 // this marker should get substituted with the contents of our stored
675 // variable (from the subsequent scan). 675 // variable (from the subsequent scan).
676 676
677 QString ts = scriptArgument; 677 QString ts = scriptArgument;
678 int vstart = ts.find( "##" ); 678 int vstart = ts.find( "##" );
679 if( vstart != -1 ) { 679 if( vstart != -1 ) {
680 ts.remove( vstart, 2 ); 680 ts.remove( vstart, 2 );
681 ts.insert( vstart, scanvar ); 681 ts.insert( vstart, scanvar );
682 } 682 }
683 683
684 bm = bm.arg(ts); 684 bm = bm.arg(ts);
685 messg->setText(bm); 685 messg->setText(bm);
686 emit debugMessage(bm); 686 emit debugMessage(bm);
687 687
688 /* if not around yet, then post window... */ 688 /* if not around yet, then post window... */
689 if (prompt->Consumed()) { 689 if (prompt->Consumed()) {
690 if (!(prompt->isVisible())) { 690 if (!(prompt->isVisible())) {
691 prompt->setPrompt( ts ); 691 prompt->setPrompt( ts );
692 prompt->setEchoModeNormal(); 692 prompt->setEchoModeNormal();
693 prompt->show(); 693 prompt->show();
694 } 694 }
695 } else { 695 } else {
696 /* if prompt withdrawn ... then, */ 696 /* if prompt withdrawn ... then, */
697 if (!(prompt->isVisible())) { 697 if (!(prompt->isVisible())) {
698 writeline(prompt->text()); 698 writeline(prompt->text());
699 prompt->setConsumed(); 699 prompt->setConsumed();
700 scriptindex++; 700 scriptindex++;
701 return; 701 return;
702 } 702 }
703 /* replace timeout value */ 703 /* replace timeout value */
704 } 704 }
705 } 705 }
706 706
707 if (scriptCommand == "PWPrompt") { 707 if (scriptCommand == "PWPrompt") {
708 QString bm = i18n("PW Prompt %1").arg(scriptArgument); 708 QString bm = i18n("PW Prompt %1").arg(scriptArgument);
709 messg->setText(bm); 709 messg->setText(bm);
710 emit debugMessage(bm); 710 emit debugMessage(bm);
711 711
712 /* if not around yet, then post window... */ 712 /* if not around yet, then post window... */
713 if (prompt->Consumed()) { 713 if (prompt->Consumed()) {
714 if (!(prompt->isVisible())) { 714 if (!(prompt->isVisible())) {
715 prompt->setPrompt(scriptArgument); 715 prompt->setPrompt(scriptArgument);
716 prompt->setEchoModePassword(); 716 prompt->setEchoModePassword();
717 prompt->show(); 717 prompt->show();
718 } 718 }
719 } else { 719 } else {
720 /* if prompt withdrawn ... then, */ 720 /* if prompt withdrawn ... then, */
721 if (!(prompt->isVisible())) { 721 if (!(prompt->isVisible())) {
722 writeline(prompt->text()); 722 writeline(prompt->text());
723 prompt->setConsumed(); 723 prompt->setConsumed();
724 scriptindex++; 724 scriptindex++;
725 return; 725 return;
726 } 726 }
727 /* replace timeout value */ 727 /* replace timeout value */
728 } 728 }
729 } 729 }
730 730
731 if (scriptCommand == "LoopStart") { 731 if (scriptCommand == "LoopStart") {
732 732
733 QString bm = i18n("Loop Start %1").arg(scriptArgument); 733 QString bm = i18n("Loop Start %1").arg(scriptArgument);
734 734
735 // The incrementing of the scriptindex MUST be before the 735 // The incrementing of the scriptindex MUST be before the
736 // call to setExpect otherwise the expect will miss a string that is 736 // call to setExpect otherwise the expect will miss a string that is
737 // already in the buffer. 737 // already in the buffer.
738 scriptindex++; 738 scriptindex++;
739 739
740 if ( loopnest > (MAXLOOPNEST-2) ) { 740 if ( loopnest > (MAXLOOPNEST-2) ) {
741 bm += i18n("ERROR: Nested too deep, ignored."); 741 bm += i18n("ERROR: Nested too deep, ignored.");
742 vmain=20; 742 vmain=20;
743 cancelbutton(); 743 cancelbutton();
744 QMessageBox::critical(0, "error", i18n("Loops nested too deeply!")); 744 QMessageBox::critical(0, "error", i18n("Loops nested too deeply!"));
745 } else { 745 } else {
746 setExpect(scriptArgument); 746 setExpect(scriptArgument);
747 loopstartindex[loopnest] = scriptindex; 747 loopstartindex[loopnest] = scriptindex;
748 loopstr[loopnest] = scriptArgument; 748 loopstr[loopnest] = scriptArgument;
749 loopend = false; 749 loopend = false;
750 loopnest++; 750 loopnest++;
751 } 751 }
752 messg->setText(bm); 752 messg->setText(bm);
753 emit debugMessage(bm); 753 emit debugMessage(bm);
754 754
755 } 755 }
756 756
757 if (scriptCommand == "LoopEnd") { 757 if (scriptCommand == "LoopEnd") {
758 QString bm = i18n("Loop End %1").arg(scriptArgument); 758 QString bm = i18n("Loop End %1").arg(scriptArgument);
759 if ( loopnest <= 0 ) { 759 if ( loopnest <= 0 ) {
760 bm = i18n("LoopEnd without matching Start! Line: %1").arg(bm); 760 bm = i18n("LoopEnd without matching Start! Line: %1").arg(bm);
761 vmain=20; 761 vmain=20;
762 cancelbutton(); 762 cancelbutton();
763 QMessageBox::critical(0, "error", bm); 763 QMessageBox::critical(0, "error", bm);
764 return; 764 return;
765 } else { 765 } else {
766 // NB! The incrementing of the scriptindex MUST be before the 766 // NB! The incrementing of the scriptindex MUST be before the
767 // call to setExpect otherwise the expect will miss a string 767 // call to setExpect otherwise the expect will miss a string
768 // that is already in the buffer. 768 // that is already in the buffer.
769 scriptindex++; 769 scriptindex++;
770 setExpect(scriptArgument); 770 setExpect(scriptArgument);
771 loopnest--; 771 loopnest--;
772 loopend = true; 772 loopend = true;
773 } 773 }
774 messg->setText(bm); 774 messg->setText(bm);
775 emit debugMessage(bm); 775 emit debugMessage(bm);
776 776
777 } 777 }
778 } 778 }
779 } 779 }
780 780
781 // this is a subroutine for the "Answer" script option 781 // this is a subroutine for the "Answer" script option
782 782
783 if(vmain == 150) { 783 if(vmain == 150) {
784 if(!expecting) { 784 if(!expecting) {
785 writeline(_ifaceppp->data()->modemAnswerStr()); 785 writeline(_ifaceppp->data()->modemAnswerStr());
786 setExpect(_ifaceppp->data()->modemAnswerResp()); 786 setExpect(_ifaceppp->data()->modemAnswerResp());
787 787
788 vmain = 2; 788 vmain = 2;
789 scriptindex++; 789 scriptindex++;
790 return; 790 return;
791 } 791 }
792 } 792 }
793 793
794 if(vmain == 30) { 794 if(vmain == 30) {
795// if (termwindow->isVisible()) 795// if (termwindow->isVisible())
796// return; 796// return;
797// if (termwindow->pressedContinue()) 797// if (termwindow->pressedContinue())
798// vmain = 10; 798// vmain = 10;
799// else 799// else
800 cancelbutton(); 800 cancelbutton();
801 } 801 }
802 802
803 if(vmain == 10) { 803 if(vmain == 10) {
804 if(!expecting) { 804 if(!expecting) {
805 805
806 int result; 806 int result;
807 807
808 timeout_timer->stop(); 808 timeout_timer->stop();
809 if_timeout_timer->stop(); // better be sure. 809 if_timeout_timer->stop(); // better be sure.
810 810
811 // stop reading of data 811 // stop reading of data
812 _ifaceppp->modem()->stop(); 812 _ifaceppp->modem()->stop();
813 813
814 if(_ifaceppp->data()->authMethod() == AUTH_TERMINAL) { 814 if(_ifaceppp->data()->authMethod() == AUTH_TERMINAL) {
815 // if (termwindow) { 815 // if (termwindow) {
816 // delete termwindow; 816 // delete termwindow;
817 // termwindow = 0L; 817 // termwindow = 0L;
818 // this->show(); 818 // this->show();
819 // } else { 819 // } else {
820 // termwindow = new LoginTerm(0L, 0L); 820 // termwindow = new LoginTerm(0L, 0L);
821 // hide(); 821 // hide();
822 // termwindow->show(); 822 // termwindow->show();
823 // vmain = 30; 823 // vmain = 30;
824 // return; 824 // return;
825 // } 825 // }
826 } 826 }
827 827
828 // Close the tty. This prevents the QTimer::singleShot() in 828 // Close the tty. This prevents the QTimer::singleShot() in
829 // Modem::readtty() from re-enabling the socket notifier. 829 // Modem::readtty() from re-enabling the socket notifier.
830 // The port is still held open by the helper process. 830 // The port is still held open by the helper process.
831 _ifaceppp->modem()->closetty(); 831 _ifaceppp->modem()->closetty();
832 832
833 killTimer( main_timer_ID ); 833 killTimer( main_timer_ID );
834 834
835 if_timeout_timer->start(_ifaceppp->data()->pppdTimeout()*1000); 835 if_timeout_timer->start(_ifaceppp->data()->pppdTimeout()*1000);
836 qDebug( "started if timeout timer with %i", _ifaceppp->data()->pppdTimeout()*1000); 836 qDebug( "started if timeout timer with %i", _ifaceppp->data()->pppdTimeout()*1000);
837 837
838 // find out PPP interface and notify the stats module 838 // find out PPP interface and notify the stats module
839// stats->setUnit(pppInterfaceNumber()); 839// stats->setUnit(pppInterfaceNumber());
840 840
841 qApp->flushX(); 841 qApp->flushX();
842 semaphore = true; 842 semaphore = true;
843 result = execppp(); 843 result = execppp();
844 844
845 emit debugMessage(i18n("Starting pppd...")); 845 emit debugMessage(i18n("Starting pppd..."));
846 qDebug("execppp() returned with return-code %i", result ); 846 qDebug("execppp() returned with return-code %i", result );
847 847
848 if(result) { 848 if(result) {
849 if(!_ifaceppp->data()->autoDNS()) 849 if(!_ifaceppp->data()->autoDNS())
850 adddns( _ifaceppp ); 850 adddns( _ifaceppp );
851 851
852 // O.K we are done here, let's change over to the if_waiting loop 852 // O.K we are done here, let's change over to the if_waiting loop
853 // where we wait for the ppp if (interface) to come up. 853 // where we wait for the ppp if (interface) to come up.
854 854
855 emit if_waiting_signal(); 855 emit if_waiting_signal();
856 } else { 856 } else {
857 857
858 // starting pppd wasn't successful. Error messages were 858 // starting pppd wasn't successful. Error messages were
859 // handled by execppp(); 859 // handled by execppp();
860 if_timeout_timer->stop(); 860 if_timeout_timer->stop();
861 this->hide(); 861 this->hide();
862 messg->setText(""); 862 messg->setText("");
863 //p_kppp->quit_b->setFocus(); 863 //p_kppp->quit_b->setFocus();
864 //p_kppp->show(); 864 //p_kppp->show();
865 qApp->processEvents(); 865 qApp->processEvents();
866 _ifaceppp->modem()->hangup(); 866 _ifaceppp->modem()->hangup();
867 emit stopAccounting(); 867 emit stopAccounting();
868 //p_kppp->con_win->stopClock(); 868 //p_kppp->con_win->stopClock();
869 _ifaceppp->modem()->closetty(); 869 _ifaceppp->modem()->closetty();
870 _ifaceppp->modem()->unlockdevice(); 870 _ifaceppp->modem()->unlockdevice();
871 871
872 } 872 }
873 873
874 return; 874 return;
875 } 875 }
876 } 876 }
877 877
878 // this is a "wait until cancel" entry 878 // this is a "wait until cancel" entry
879 879
880 if(vmain == 20) { 880 if(vmain == 20) {
881 } 881 }
882} 882}
883 883
884 884
885void ConnectWidget::set_con_speed_string() { 885void ConnectWidget::set_con_speed_string() {
886 // Here we are trying to determine the speed at which we are connected. 886 // Here we are trying to determine the speed at which we are connected.
887 // Usually the modem responds after connect with something like 887 // Usually the modem responds after connect with something like
888 // CONNECT 115200, so all we need to do is find the number after CONNECT 888 // CONNECT 115200, so all we need to do is find the number after CONNECT
889 // or whatever the modemConnectResp() is. 889 // or whatever the modemConnectResp() is.
890// p_kppp->con_speed = _ifaceppp->modem()->parseModemSpeed(myreadbuffer); 890// p_kppp->con_speed = _ifaceppp->modem()->parseModemSpeed(myreadbuffer);
891} 891}
892 892
893 893
894 894
895void ConnectWidget::readChar(unsigned char c) { 895void ConnectWidget::readChar(unsigned char c) {
896 if(semaphore) 896 if(semaphore)
897 return; 897 return;
898 898
899 readbuffer += c; 899 readbuffer += c;
900 myreadbuffer += c; 900 myreadbuffer += c;
901 901
902 // While in scanning mode store each char to the scan buffer 902 // While in scanning mode store each char to the scan buffer
903 // for use in the prompt command 903 // for use in the prompt command
904 if( scanning ) 904 if( scanning )
905 scanbuffer += c; 905 scanbuffer += c;
906 906
907 // add to debug window 907 // add to debug window
908 emit debugPutChar(c); 908 emit debugPutChar(c);
909 909
910 checkBuffers(); 910 checkBuffers();
911} 911}
912 912
913 913
914void ConnectWidget::checkBuffers() { 914void ConnectWidget::checkBuffers() {
915 // Let's check if we are finished with scanning: 915 // Let's check if we are finished with scanning:
916 // The scanstring have to be in the buffer and the latest character 916 // The scanstring have to be in the buffer and the latest character
917 // was a carriage return or an linefeed (depending on modem setup) 917 // was a carriage return or an linefeed (depending on modem setup)
918 if( scanning && scanbuffer.contains(scanstr) && 918 if( scanning && scanbuffer.contains(scanstr) &&
919 ( scanbuffer.right(1) == "\n" || scanbuffer.right(1) == "\r") ) { 919 ( scanbuffer.right(1) == "\n" || scanbuffer.right(1) == "\r") ) {
920 scanning = false; 920 scanning = false;
921 921
922 int vstart = scanbuffer.find( scanstr ) + scanstr.length(); 922 int vstart = scanbuffer.find( scanstr ) + scanstr.length();
923 scanvar = scanbuffer.mid( vstart, scanbuffer.length() - vstart); 923 scanvar = scanbuffer.mid( vstart, scanbuffer.length() - vstart);
924 scanvar = scanvar.stripWhiteSpace(); 924 scanvar = scanvar.stripWhiteSpace();
925 925
926 // Show the Variabel content in the debug window 926 // Show the Variabel content in the debug window
927 QString sv = i18n("Scan Var: %1").arg(scanvar); 927 QString sv = i18n("Scan Var: %1").arg(scanvar);
928 emit debugMessage(sv); 928 emit debugMessage(sv);
929 } 929 }
930 930
931 if(expecting) { 931 if(expecting) {
932 if(readbuffer.contains(expectstr)) { 932 if(readbuffer.contains(expectstr)) {
933 expecting = false; 933 expecting = false;
934 // keep everything after the expected string 934 // keep everything after the expected string
935 readbuffer.remove(0, readbuffer.find(expectstr) + expectstr.length()); 935 readbuffer.remove(0, readbuffer.find(expectstr) + expectstr.length());
936 936
937 QString ts = i18n("Found: %1").arg(expectstr); 937 QString ts = i18n("Found: %1").arg(expectstr);
938 emit debugMessage(ts); 938 emit debugMessage(ts);
939 939
940 if (loopend) { 940 if (loopend) {
941 loopend=false; 941 loopend=false;
942 } 942 }
943 } 943 }
944 944
945 if (loopend && readbuffer.contains(loopstr[loopnest])) { 945 if (loopend && readbuffer.contains(loopstr[loopnest])) {
946 expecting = false; 946 expecting = false;
947 readbuffer = ""; 947 readbuffer = "";
948 QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); 948 QString ts = i18n("Looping: %1").arg(loopstr[loopnest]);
949 emit debugMessage(ts); 949 emit debugMessage(ts);
950 scriptindex = loopstartindex[loopnest]; 950 scriptindex = loopstartindex[loopnest];
951 loopend = false; 951 loopend = false;
952 loopnest++; 952 loopnest++;
953 } 953 }
954 // notify event loop if expected string was found 954 // notify event loop if expected string was found
955 if(!expecting) 955 if(!expecting)
956 timerEvent((QTimerEvent *) 0); 956 timerEvent((QTimerEvent *) 0);
957 } 957 }
958} 958}
959 959
960 960
961 961
962void ConnectWidget::pause() { 962void ConnectWidget::pause() {
963 pausing = false; 963 pausing = false;
964 pausetimer->stop(); 964 pausetimer->stop();
965} 965}
966 966
967 967
968void ConnectWidget::cancelbutton() { 968void ConnectWidget::cancelbutton() {
969 _ifaceppp->modem()->stop(); 969 _ifaceppp->modem()->stop();
970 killTimer(main_timer_ID); 970 killTimer(main_timer_ID);
971 timeout_timer->stop(); 971 timeout_timer->stop();
972 if_timer->stop(); 972 if_timer->stop();
973 if_timeout_timer->stop(); 973 if_timeout_timer->stop();
974 974
975// if (termwindow) { 975// if (termwindow) {
976// delete termwindow; 976// delete termwindow;
977// termwindow = 0L; 977// termwindow = 0L;
978// this->show(); 978// this->show();
979// } 979// }
980 980
981 messg->setText(i18n("One moment please...")); 981 messg->setText(i18n("One moment please..."));
982 982
983 // just to be sure 983 // just to be sure
984 _ifaceppp->modem()->removeSecret(AUTH_PAP); 984 _ifaceppp->modem()->removeSecret(AUTH_PAP);
985 _ifaceppp->modem()->removeSecret(AUTH_CHAP); 985 _ifaceppp->modem()->removeSecret(AUTH_CHAP);
986 removedns(_ifaceppp); 986 removedns(_ifaceppp);
987 987
988 qApp->processEvents(); 988 qApp->processEvents();
989 989
990 _ifaceppp->modem()->killPPPDaemon(); 990 _ifaceppp->modem()->killPPPDaemon();
991 _ifaceppp->modem()->hangup(); 991 _ifaceppp->modem()->hangup();
992 992
993 993
994// p_kppp->quit_b->setFocus(); 994// p_kppp->quit_b->setFocus();
995// p_kppp->show(); 995// p_kppp->show();
996 // emit stopAccounting();// just to be sure 996 // emit stopAccounting();// just to be sure
997// p_kppp->con_win->stopClock(); 997// p_kppp->con_win->stopClock();
998 _ifaceppp->modem()->closetty(); 998 _ifaceppp->modem()->closetty();
999 _ifaceppp->modem()->unlockdevice(); 999 _ifaceppp->modem()->unlockdevice();
1000 1000
1001 //abort prompt window... 1001 //abort prompt window...
1002 if (prompt->isVisible()) { 1002 if (prompt->isVisible()) {
1003 prompt->hide(); 1003 prompt->hide();
1004 } 1004 }
1005 prompt->setConsumed(); 1005 prompt->setConsumed();
1006 1006
1007 messg->setText(tr("offline")); 1007 messg->setText(tr("offline"));
1008} 1008}
1009 1009
1010 1010
1011void ConnectWidget::script_timed_out() { 1011void ConnectWidget::script_timed_out() {
1012 if(vmain == 20) { // we are in the 'wait for the user to cancel' state 1012 if(vmain == 20) { // we are in the 'wait for the user to cancel' state
1013 timeout_timer->stop(); 1013 timeout_timer->stop();
1014 emit stopAccounting(); 1014 emit stopAccounting();
1015// p_kppp->con_win->stopClock(); 1015// p_kppp->con_win->stopClock();
1016 return; 1016 return;
1017 } 1017 }
1018 1018
1019 if (prompt->isVisible()) 1019 if (prompt->isVisible())
1020 prompt->hide(); 1020 prompt->hide();
1021 1021
1022 prompt->setConsumed(); 1022 prompt->setConsumed();
1023 messg->setText(i18n("Script timed out!")); 1023 messg->setText(i18n("Script timed out!"));
1024 _ifaceppp->modem()->hangup(); 1024 _ifaceppp->modem()->hangup();
1025 emit stopAccounting(); 1025 emit stopAccounting();
1026// p_kppp->con_win->stopClock(); 1026// p_kppp->con_win->stopClock();
1027 1027
1028 vmain = 0; // let's try again. 1028 vmain = 0; // let's try again.
1029 substate = -1; 1029 substate = -1;
1030} 1030}
1031 1031
1032 1032
1033void ConnectWidget::setScan(const QString &n) { 1033void ConnectWidget::setScan(const QString &n) {
1034 scanning = true; 1034 scanning = true;
1035 scanstr = n; 1035 scanstr = n;
1036 scanbuffer = ""; 1036 scanbuffer = "";
1037 1037
1038 QString ts = i18n("Scanning: %1").arg(n); 1038 QString ts = i18n("Scanning: %1").arg(n);
1039 emit debugMessage(ts); 1039 emit debugMessage(ts);
1040} 1040}
1041 1041
1042 1042
1043void ConnectWidget::setExpect(const QString &n) { 1043void ConnectWidget::setExpect(const QString &n) {
1044 expecting = true; 1044 expecting = true;
1045 expectstr = n; 1045 expectstr = n;
1046 1046
1047 QString ts = i18n("Expecting: %1").arg(n); 1047 QString ts = i18n("Expecting: %1").arg(n);
1048 ts.replace(QRegExp("\n"), "<LF>"); 1048 ts.replace(QRegExp("\n"), "<LF>");
1049 emit debugMessage(ts); 1049 emit debugMessage(ts);
1050 1050
1051 // check if the expected string is in the read buffer already. 1051 // check if the expected string is in the read buffer already.
1052 checkBuffers(); 1052 checkBuffers();
1053} 1053}
1054 1054
1055 1055
1056void ConnectWidget::if_waiting_timed_out() { 1056void ConnectWidget::if_waiting_timed_out() {
1057 if_timer->stop(); 1057 if_timer->stop();
1058 if_timeout_timer->stop(); 1058 if_timeout_timer->stop();
1059 qDebug("if_waiting_timed_out()"); 1059 qDebug("if_waiting_timed_out()");
1060 1060
1061 _ifaceppp->data()->setpppdError(E_IF_TIMEOUT); 1061 _ifaceppp->data()->setpppdError(E_IF_TIMEOUT);
1062 1062
1063 // let's kill the stuck pppd 1063 // let's kill the stuck pppd
1064 _ifaceppp->modem()->killPPPDaemon(); 1064 _ifaceppp->modem()->killPPPDaemon();
1065 1065
1066 emit stopAccounting(); 1066 emit stopAccounting();
1067// p_kppp->con_win->stopClock(); 1067// p_kppp->con_win->stopClock();
1068 1068
1069 1069
1070 // killing ppp will generate a SIGCHLD which will be caught in pppdie() 1070 // killing ppp will generate a SIGCHLD which will be caught in pppdie()
1071 // in main.cpp what happens next will depend on the boolean 1071 // in main.cpp what happens next will depend on the boolean
1072 // reconnect_on_disconnect which is set in ConnectWidget::init(); 1072 // reconnect_on_disconnect which is set in ConnectWidget::init();
1073} 1073}
1074 1074
1075void ConnectWidget::pppdDied() 1075void ConnectWidget::pppdDied()
1076{ 1076{
1077 if_timer->stop(); 1077 if_timer->stop();
1078 if_timeout_timer->stop(); 1078 if_timeout_timer->stop();
1079} 1079}
1080 1080
1081void ConnectWidget::if_waiting_slot() { 1081void ConnectWidget::if_waiting_slot() {
1082 messg->setText(i18n("Logging on to network...")); 1082 messg->setText(i18n("Logging on to network..."));
1083 1083
1084// if(!stats->ifIsUp()) { 1084// if(!stats->ifIsUp()) {
1085 1085
1086// if(_ifaceppp->data()->pppdError() != 0) { 1086// if(_ifaceppp->data()->pppdError() != 0) {
1087// // we are here if pppd died immediately after starting it. 1087// // we are here if pppd died immediately after starting it.
1088// pppdDied(); 1088// pppdDied();
1089// // error message handled in main.cpp: sigPPPDDied() 1089// // error message handled in main.cpp: sigPPPDDied()
1090// return; 1090// return;
1091// } 1091// }
1092 1092
1093// if_timer->start(100, TRUE); // single shot 1093// if_timer->start(100, TRUE); // single shot
1094// return; 1094// return;
1095// } 1095// }
1096 1096
1097 // O.K the ppp interface is up and running 1097 // O.K the ppp interface is up and running
1098 // give it a few time to come up completly (0.2 seconds) 1098 // give it a few time to come up completly (0.2 seconds)
1099 if_timeout_timer->stop(); 1099 if_timeout_timer->stop();
1100 if_timer->stop(); 1100 if_timer->stop();
1101 usleep(200000); 1101 usleep(200000);
1102 1102
1103 if(_ifaceppp->data()->autoDNS()) 1103 if(_ifaceppp->data()->autoDNS())
1104 addpeerdns( _ifaceppp ); 1104 addpeerdns( _ifaceppp );
1105 1105
1106 // Close the debugging window. If we are connected, we 1106 // Close the debugging window. If we are connected, we
1107 // are not really interested in debug output 1107 // are not really interested in debug output
1108 emit closeDebugWindow(); 1108 emit closeDebugWindow();
1109// p_kppp->statdlg->take_stats(); // start taking ppp statistics 1109// p_kppp->statdlg->take_stats(); // start taking ppp statistics
1110 auto_hostname(_ifaceppp); 1110 auto_hostname(_ifaceppp);
1111 1111
1112 if(!_ifaceppp->data()->command_on_connect().isEmpty()) { 1112 if(!_ifaceppp->data()->command_on_connect().isEmpty()) {
1113 messg->setText(i18n("Running startup command...")); 1113 messg->setText(i18n("Running startup command..."));
1114 1114
1115 // make sure that we don't get any async errors 1115 // make sure that we don't get any async errors
1116 qApp->flushX(); 1116 qApp->flushX();
1117 execute_command(_ifaceppp->data()->command_on_connect()); 1117 execute_command(_ifaceppp->data()->command_on_connect());
1118 messg->setText(i18n("Done")); 1118 messg->setText(i18n("Done"));
1119 } 1119 }
1120 1120
1121 // remove the authentication file 1121 // remove the authentication file
1122 _ifaceppp->modem()->removeSecret(AUTH_PAP); 1122 _ifaceppp->modem()->removeSecret(AUTH_PAP);
1123 _ifaceppp->modem()->removeSecret(AUTH_CHAP); 1123 _ifaceppp->modem()->removeSecret(AUTH_CHAP);
1124 1124
1125 emit debugMessage(i18n("Done")); 1125 emit debugMessage(i18n("Done"));
1126 set_con_speed_string(); 1126 set_con_speed_string();
1127 1127
1128// p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed); 1128// p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed);
1129 this->hide(); 1129 this->hide();
1130 messg->setText(""); 1130 messg->setText("");
1131 1131
1132 // prepare the con_win so as to have the right size for 1132 // prepare the con_win so as to have the right size for
1133 // accounting / non-accounting mode 1133 // accounting / non-accounting mode
1134// if(p_kppp->acct != 0) 1134// if(p_kppp->acct != 0)
1135// p_kppp->con_win->accounting(p_kppp->acct->running()); 1135// p_kppp->con_win->accounting(p_kppp->acct->running());
1136// else 1136// else
1137// p_kppp->con_win->accounting(false); 1137// p_kppp->con_win->accounting(false);
1138 1138
1139// if (_ifaceppp->data()->get_dock_into_panel()) { 1139// if (_ifaceppp->data()->get_dock_into_panel()) {
1140// // DockWidget::dock_widget->show(); 1140// // DockWidget::dock_widget->show();
1141// // DockWidget::dock_widget->take_stats(); 1141// // DockWidget::dock_widget->take_stats();
1142// // this->hide(); 1142// // this->hide();
1143// } 1143// }
1144// else { 1144// else {
1145// // p_kppp->con_win->show(); 1145// // p_kppp->con_win->show();
1146 1146
1147// if(_ifaceppp->data()->get_iconify_on_connect()) { 1147// if(_ifaceppp->data()->get_iconify_on_connect()) {
1148// // p_kppp->con_win->showMinimized(); 1148// // p_kppp->con_win->showMinimized();
1149// } 1149// }
1150// } 1150// }
1151 1151
1152 _ifaceppp->modem()->closetty(); 1152 _ifaceppp->modem()->closetty();
1153} 1153}
1154 1154
1155 1155
1156bool ConnectWidget::execppp() { 1156bool ConnectWidget::execppp() {
1157 QString command; 1157 QString command;
1158 1158
1159 command = "pppd"; 1159 command = "pppd";
1160 1160
1161 // as of version 2.3.6 pppd falls back to the real user rights when 1161 // as of version 2.3.6 pppd falls back to the real user rights when
1162 // opening a device given in a command line. To avoid permission conflicts 1162 // opening a device given in a command line. To avoid permission conflicts
1163 // we'll simply leave this argument away. pppd will then use the default tty 1163 // we'll simply leave this argument away. pppd will then use the default tty
1164 // which is the serial port we connected stdin/stdout to in opener.cpp. 1164 // which is the serial port we connected stdin/stdout to in opener.cpp.
1165 // command += " "; 1165 // command += " ";
1166 // command += _ifaceppp->data()->modemDevice(); 1166 // command += _ifaceppp->data()->modemDevice();
1167 1167
1168 command += " " + _ifaceppp->data()->speed(); 1168 command += " " + _ifaceppp->data()->speed();
1169 1169
1170 command += " -detach"; 1170 command += " -detach";
1171 1171
1172 if(_ifaceppp->data()->ipaddr() != "0.0.0.0" || 1172 if(_ifaceppp->data()->ipaddr() != "0.0.0.0" ||
1173 _ifaceppp->data()->gateway() != "0.0.0.0") { 1173 _ifaceppp->data()->gateway() != "0.0.0.0") {
1174 if(_ifaceppp->data()->ipaddr() != "0.0.0.0") { 1174 if(_ifaceppp->data()->ipaddr() != "0.0.0.0") {
1175 command += " "; 1175 command += " ";
1176 command += _ifaceppp->data()->ipaddr(); 1176 command += _ifaceppp->data()->ipaddr();
1177 command += ":"; 1177 command += ":";
1178 } 1178 }
1179 else { 1179 else {
1180 command += " "; 1180 command += " ";
1181 command += ":"; 1181 command += ":";
1182 } 1182 }
1183 1183
1184 if(_ifaceppp->data()->gateway() != "0.0.0.0") 1184 if(_ifaceppp->data()->gateway() != "0.0.0.0")
1185 command += _ifaceppp->data()->gateway(); 1185 command += _ifaceppp->data()->gateway();
1186 } 1186 }
1187 1187
1188 if(_ifaceppp->data()->subnetmask() != "0.0.0.0") 1188 if(_ifaceppp->data()->subnetmask() != "0.0.0.0")
1189 command += " netmask " + _ifaceppp->data()->subnetmask(); 1189 command += " netmask " + _ifaceppp->data()->subnetmask();
1190 1190
1191 if(_ifaceppp->data()->flowcontrol() != "None") { 1191 if(_ifaceppp->data()->flowcontrol() != "None") {
1192 if(_ifaceppp->data()->flowcontrol() == "CRTSCTS") 1192 if(_ifaceppp->data()->flowcontrol() == "CRTSCTS")
1193 command += " crtscts"; 1193 command += " crtscts";
1194 else 1194 else
1195 command += " xonxoff"; 1195 command += " xonxoff";
1196 } 1196 }
1197 1197
1198 if(_ifaceppp->data()->defaultroute()) 1198 if(_ifaceppp->data()->defaultroute())
1199 command += " defaultroute"; 1199 command += " defaultroute";
1200 1200
1201 if(_ifaceppp->data()->autoDNS()) 1201 if(_ifaceppp->data()->autoDNS())
1202 command += " usepeerdns"; 1202 command += " usepeerdns";
1203 1203
1204 QStringList &arglist = _ifaceppp->data()->pppdArgument(); 1204 QStringList &arglist = _ifaceppp->data()->pppdArgument();
1205 for ( QStringList::Iterator it = arglist.begin(); 1205 for ( QStringList::Iterator it = arglist.begin();
1206 it != arglist.end(); 1206 it != arglist.end();
1207 ++it ) 1207 ++it )
1208 { 1208 {
1209 command += " " + *it; 1209 command += " " + *it;
1210 } 1210 }
1211 1211
1212 // PAP settings 1212 // PAP settings
1213 if(_ifaceppp->data()->authMethod() == AUTH_PAP) { 1213 if(_ifaceppp->data()->authMethod() == AUTH_PAP) {
1214 command += " -chap user "; 1214 command += " -chap user ";
1215 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; 1215 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\"";
1216 } 1216 }
1217 1217
1218 // CHAP settings 1218 // CHAP settings
1219 if(_ifaceppp->data()->authMethod() == AUTH_CHAP) { 1219 if(_ifaceppp->data()->authMethod() == AUTH_CHAP) {
1220 command += " -pap user "; 1220 command += " -pap user ";
1221 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; 1221 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\"";
1222 } 1222 }
1223 1223
1224 // PAP/CHAP settings 1224 // PAP/CHAP settings
1225 if(_ifaceppp->data()->authMethod() == AUTH_PAPCHAP) { 1225 if(_ifaceppp->data()->authMethod() == AUTH_PAPCHAP) {
1226 command += " user "; 1226 command += " user ";
1227 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; 1227 command = command + "\"" + _ifaceppp->data()->storedUsername() + "\"";
1228 } 1228 }
1229 1229
1230 // check for debug 1230 // check for debug
1231 if(_ifaceppp->data()->getPPPDebug()) 1231 if(_ifaceppp->data()->getPPPDebug())
1232 command += " debug"; 1232 command += " debug";
1233 1233
1234 if (command.length() > MAX_CMDLEN) { 1234 if (command.length() > MAX_CMDLEN) {
1235 QMessageBox::critical(this, "error", i18n( 1235 QMessageBox::critical(this, "error", i18n(
1236 "pppd command + command-line arguments exceed " 1236 "pppd command + command-line arguments exceed "
1237 "2024 characters in length." 1237 "2024 characters in length."
1238 )); 1238 ));
1239 1239
1240 return false; // nonsensically long command which would bust my buffer buf. 1240 return false; // nonsensically long command which would bust my buffer buf.
1241 } 1241 }
1242 1242
1243 qApp->flushX(); 1243 qApp->flushX();
1244 1244
1245 return _ifaceppp->modem()->execPPPDaemon(command); 1245 return _ifaceppp->modem()->execPPPDaemon(command);
1246} 1246}
1247 1247
1248 1248
1249void ConnectWidget::closeEvent( QCloseEvent *e ) { 1249void ConnectWidget::closeEvent( QCloseEvent *e ) {
1250 e->ignore(); 1250 e->ignore();
1251 emit cancelbutton(); 1251 emit cancelbutton();
1252} 1252}
1253 1253
1254 1254
1255void ConnectWidget::setMsg(const QString &msg) { 1255void ConnectWidget::setMsg(const QString &msg) {
1256 messg->setText(msg); 1256 messg->setText(msg);
1257} 1257}
1258 1258
1259void ConnectWidget::writeline(const QString &s) { 1259void ConnectWidget::writeline(const QString &s) {
1260 _ifaceppp->modem()->writeLine(s.local8Bit()); 1260 _ifaceppp->modem()->writeLine(s.local8Bit());
1261} 1261}
1262 1262
1263// Set the hostname and domain from DNS Server 1263// Set the hostname and domain from DNS Server
1264void auto_hostname(InterfacePPP *_ifaceppp) { 1264void auto_hostname(InterfacePPP *_ifaceppp) {
1265 struct in_addr local_ip; 1265 struct in_addr local_ip;
1266 struct hostent *hostname_entry; 1266 struct hostent *hostname_entry;
1267 QString new_hostname; 1267 QString new_hostname;
1268 int dot; 1268 int dot;
1269 char tmp_str[100]; // buffer overflow safe 1269 char tmp_str[100]; // buffer overflow safe
1270 1270
1271 gethostname(tmp_str, sizeof(tmp_str)); 1271 gethostname(tmp_str, sizeof(tmp_str));
1272 tmp_str[sizeof(tmp_str)-1]=0; // panic 1272 tmp_str[sizeof(tmp_str)-1]=0; // panic
1273 old_hostname=tmp_str; // copy to QString 1273 old_hostname=tmp_str; // copy to QString
1274 1274
1275 // if (!p_kppp->stats->local_ip_address.isEmpty() && _ifaceppp->data()->autoname()) { 1275 // if (!p_kppp->stats->local_ip_address.isEmpty() && _ifaceppp->data()->autoname()) {
1276 if ( _ifaceppp->data()->autoname()) { 1276 if ( _ifaceppp->data()->autoname()) {
1277// local_ip.s_addr=inet_addr(p_kppp->stats->local_ip_address.ascii()); 1277// local_ip.s_addr=inet_addr(p_kppp->stats->local_ip_address.ascii());
1278 hostname_entry=gethostbyaddr((const char *)&local_ip,sizeof(in_addr),AF_INET); 1278 hostname_entry=gethostbyaddr((const char *)&local_ip,sizeof(in_addr),AF_INET);
1279 1279
1280 if (hostname_entry != 0L) { 1280 if (hostname_entry != 0L) {
1281 new_hostname=hostname_entry->h_name; 1281 new_hostname=hostname_entry->h_name;
1282 dot=new_hostname.find('.'); 1282 dot=new_hostname.find('.');
1283 new_hostname=new_hostname.remove(dot,new_hostname.length()-dot); 1283 new_hostname=new_hostname.remove(dot,new_hostname.length()-dot);
1284 _ifaceppp->modem()->setHostname(new_hostname); 1284 _ifaceppp->modem()->setHostname(new_hostname);
1285 modified_hostname = TRUE; 1285 modified_hostname = TRUE;
1286 1286
1287 new_hostname=hostname_entry->h_name; 1287 new_hostname=hostname_entry->h_name;
1288 new_hostname.remove(0,dot+1); 1288 new_hostname.remove(0,dot+1);
1289 1289
1290 add_domain(new_hostname, _ifaceppp); 1290 add_domain(new_hostname, _ifaceppp);
1291 } 1291 }
1292 } 1292 }
1293 1293
1294} 1294}
1295 1295
1296// Replace the DNS domain entry in the /etc/resolv.conf file and 1296// Replace the DNS domain entry in the /etc/resolv.conf file and
1297// disable the nameserver entries if option is enabled 1297// disable the nameserver entries if option is enabled
1298void add_domain(const QString &domain, InterfacePPP *_ifaceppp) { 1298void add_domain(const QString &domain, InterfacePPP *_ifaceppp) {
1299 1299
1300 int fd; 1300 int fd;
1301 char c; 1301 char c;
1302 QString resolv[MAX_RESOLVCONF_LINES]; 1302 QString resolv[MAX_RESOLVCONF_LINES];
1303 1303
1304 if (domain.isEmpty()) 1304 if (domain.isEmpty())
1305 return; 1305 return;
1306 1306
1307 if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) { 1307 if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) {
1308 1308
1309 int i=0; 1309 int i=0;
1310 while((read(fd, &c, 1) == 1) && (i < MAX_RESOLVCONF_LINES)) { 1310 while((read(fd, &c, 1) == 1) && (i < MAX_RESOLVCONF_LINES)) {
1311 if(c == '\n') { 1311 if(c == '\n') {
1312 i++; 1312 i++;
1313 } 1313 }
1314 else { 1314 else {
1315 resolv[i] += c; 1315 resolv[i] += c;
1316 } 1316 }
1317 } 1317 }
1318 close(fd); 1318 close(fd);
1319 if ((c != '\n') && (i < MAX_RESOLVCONF_LINES)) i++; 1319 if ((c != '\n') && (i < MAX_RESOLVCONF_LINES)) i++;
1320 1320
1321 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) { 1321 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) {
1322 QCString tmp = "domain " + domain.local8Bit() + 1322 QCString tmp = "domain " + domain.local8Bit() +
1323 " \t\t#kppp temp entry\n"; 1323 " \t\t#kppp temp entry\n";
1324 write(fd, tmp.data(), tmp.length()); 1324 write(fd, tmp.data(), tmp.length());
1325 1325
1326 for(int j=0; j < i; j++) { 1326 for(int j=0; j < i; j++) {
1327 if((resolv[j].contains("domain") || 1327 if((resolv[j].contains("domain") ||
1328 ( resolv[j].contains("nameserver") 1328 ( resolv[j].contains("nameserver")
1329 && !resolv[j].contains("#kppp temp entry") 1329 && !resolv[j].contains("#kppp temp entry")
1330 && _ifaceppp->data()->exDNSDisabled())) 1330 && _ifaceppp->data()->exDNSDisabled()))
1331 && !resolv[j].contains("#entry disabled by kppp")) { 1331 && !resolv[j].contains("#entry disabled by kppp")) {
1332 QCString tmp = "# " + resolv[j].local8Bit() + 1332 QCString tmp = "# " + resolv[j].local8Bit() +
1333 " \t#entry disabled by kppp\n"; 1333 " \t#entry disabled by kppp\n";
1334 write(fd, tmp, tmp.length()); 1334 write(fd, tmp, tmp.length());
1335 } 1335 }
1336 else { 1336 else {
1337 QCString tmp = resolv[j].local8Bit() + "\n"; 1337 QCString tmp = resolv[j].local8Bit() + "\n";
1338 write(fd, tmp, tmp.length()); 1338 write(fd, tmp, tmp.length());
1339 } 1339 }
1340 } 1340 }
1341 } 1341 }
1342 close(fd); 1342 close(fd);
1343 } 1343 }
1344} 1344}
1345 1345
1346 1346
1347// adds the DNS entries in the /etc/resolv.conf file 1347// adds the DNS entries in the /etc/resolv.conf file
1348void adddns( InterfacePPP *_ifaceppp) 1348void adddns( InterfacePPP *_ifaceppp)
1349{ 1349{
1350 int fd; 1350 int fd;
1351 1351
1352 if ((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_APPEND)) >= 0) { 1352 if ((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_APPEND)) >= 0) {
1353 QStringList &dnslist = _ifaceppp->data()->dns(); 1353 QStringList &dnslist = _ifaceppp->data()->dns();
1354 for ( QStringList::Iterator it = dnslist.begin(); 1354 for ( QStringList::Iterator it = dnslist.begin();
1355 it != dnslist.end(); 1355 it != dnslist.end();
1356 ++it ) 1356 ++it )
1357 { 1357 {
1358 QCString dns = "nameserver " + (*it).local8Bit() + 1358 QCString dns = "nameserver " + (*it).local8Bit() +
1359 " \t#kppp temp entry\n"; 1359 " \t#kppp temp entry\n";
1360 write(fd, dns.data(), dns.length()); 1360 write(fd, dns.data(), dns.length());
1361 } 1361 }
1362 close(fd); 1362 close(fd);
1363 } 1363 }
1364 add_domain(_ifaceppp->data()->domain(), _ifaceppp); 1364 add_domain(_ifaceppp->data()->domain(), _ifaceppp);
1365} 1365}
1366 1366
1367void addpeerdns(InterfacePPP *_ifaceppp) { 1367void addpeerdns(InterfacePPP *_ifaceppp) {
1368 int fd, fd2; 1368 int fd, fd2;
1369 1369
1370 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_APPEND)) >= 0) { 1370 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_APPEND)) >= 0) {
1371 if((fd2 = open("/etc/ppp/resolv.conf", O_RDONLY)) >= 0) { 1371 if((fd2 = open("/etc/ppp/resolv.conf", O_RDONLY)) >= 0) {
1372 char c; 1372 char c;
1373 int i = 0; 1373 int i = 0;
1374 while(i++ < 100 && read(fd2, &c, 1) == 1) { 1374 while(i++ < 100 && read(fd2, &c, 1) == 1) {
1375 if(c == '\n') 1375 if(c == '\n')
1376 write(fd, "\t#kppp temp entry\n", 18); 1376 write(fd, "\t#kppp temp entry\n", 18);
1377 else 1377 else
1378 write(fd, &c, 1); 1378 write(fd, &c, 1);
1379 } 1379 }
1380 close(fd2); 1380 close(fd2);
1381 } else 1381 } else
1382 fprintf(stderr, "failed to read from /etc/ppp/resolv.conf\n"); 1382 fprintf(stderr, "failed to read from /etc/ppp/resolv.conf\n");
1383 close(fd); 1383 close(fd);
1384 } 1384 }
1385 add_domain(_ifaceppp->data()->domain(), _ifaceppp); 1385 add_domain(_ifaceppp->data()->domain(), _ifaceppp);
1386} 1386}
1387 1387
1388// remove the dns entries from the /etc/resolv.conf file 1388// remove the dns entries from the /etc/resolv.conf file
1389void removedns(InterfacePPP *_ifaceppp) { 1389void removedns(InterfacePPP *_ifaceppp) {
1390 1390
1391 int fd; 1391 int fd;
1392 char c; 1392 char c;
1393 QString resolv[MAX_RESOLVCONF_LINES]; 1393 QString resolv[MAX_RESOLVCONF_LINES];
1394 1394
1395 if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) { 1395 if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) {
1396 1396
1397 int i=0; 1397 int i=0;
1398 while(read(fd, &c, 1) == 1 && i < MAX_RESOLVCONF_LINES) { 1398 while(read(fd, &c, 1) == 1 && i < MAX_RESOLVCONF_LINES) {
1399 if(c == '\n') { 1399 if(c == '\n') {
1400 i++; 1400 i++;
1401 } 1401 }
1402 else { 1402 else {
1403 resolv[i] += c; 1403 resolv[i] += c;
1404 } 1404 }
1405 } 1405 }
1406 close(fd); 1406 close(fd);
1407 1407
1408 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) { 1408 if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) {
1409 for(int j=0; j < i; j++) { 1409 for(int j=0; j < i; j++) {
1410 if(resolv[j].contains("#kppp temp entry")) continue; 1410 if(resolv[j].contains("#kppp temp entry")) continue;
1411 if(resolv[j].contains("#entry disabled by kppp")) { 1411 if(resolv[j].contains("#entry disabled by kppp")) {
1412 QCString tmp = resolv[j].local8Bit(); 1412 QCString tmp = resolv[j].local8Bit();
1413 write(fd, tmp.data()+2, tmp.length() - 27); 1413 write(fd, tmp.data()+2, tmp.length() - 27);
1414 write(fd, "\n", 1); 1414 write(fd, "\n", 1);
1415 } 1415 }
1416 else { 1416 else {
1417 QCString tmp = resolv[j].local8Bit() + "\n"; 1417 QCString tmp = resolv[j].local8Bit() + "\n";
1418 write(fd, tmp, tmp.length()); 1418 write(fd, tmp, tmp.length());
1419 } 1419 }
1420 } 1420 }
1421 } 1421 }
1422 close(fd); 1422 close(fd);
1423 1423
1424 } 1424 }
1425 1425
1426 if ( modified_hostname ) { 1426 if ( modified_hostname ) {
1427 _ifaceppp->modem()->setHostname(old_hostname); 1427 _ifaceppp->modem()->setHostname(old_hostname);
1428 modified_hostname = FALSE; 1428 modified_hostname = FALSE;
1429 } 1429 }
1430 1430
1431} 1431}
1432 1432
1433 1433
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 @@
1 1
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#define i18n QObject::tr 3#define i18n QObject::tr
4 4
5#include "auth.h" 5#include "auth.h"
6#include "interfaceppp.h" 6#include "interfaceppp.h"
7#include "modem.h" 7#include "modem.h"
8#include "pppdata.h" 8#include "pppdata.h"
9 9
10InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status) 10InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status)
11 : Interface(parent, name, status), 11 : Interface(parent, name, status),
12 _modemPtr(0), 12 _modemPtr(0),
13 _dataPtr(0) 13 _dataPtr(0)
14{ 14{
15 qDebug("InterfacePPP::InterfacePPP("); 15 qDebug("InterfacePPP::InterfacePPP(");
16} 16}
17 17
18PPPData* InterfacePPP::data() 18PPPData* InterfacePPP::data()
19{ 19{
20 if (!_dataPtr){ 20 if (!_dataPtr){
21 qDebug("creating new Data obj"); 21 qDebug("creating new Data obj");
22 _dataPtr = new PPPData(); 22 _dataPtr = new PPPData();
23 _dataPtr->setModemDevice( getInterfaceName() ); 23 _dataPtr->setModemDevice( getInterfaceName() );
24 _dataPtr->setAccount( getHardwareName() ); 24 _dataPtr->setAccount( getHardwareName() );
25 } 25 }
26 return _dataPtr; 26 return _dataPtr;
27} 27}
28 28
29Modem* InterfacePPP::modem() 29Modem* InterfacePPP::modem()
30{ 30{
31 if (!_modemPtr){ 31 if (!_modemPtr){
32 qDebug("creating new modem obj"); 32 qDebug("creating new modem obj");
33 _modemPtr = new Modem( data() ); 33 _modemPtr = new Modem( data() );
34 } 34 }
35 return _modemPtr; 35 return _modemPtr;
36} 36}
37 37
38bool InterfacePPP::refresh() 38bool InterfacePPP::refresh()
39{ 39{
40 qDebug("InterfacePPP::refresh()"); 40 qDebug("InterfacePPP::refresh()");
41 QMessageBox::information(0,"Not Implemented","This feature is not yet implemneted... ;-("); 41 QMessageBox::information(0,"Not Implemented","This feature is not yet implemneted... ;-(");
42 return false; 42 return false;
43} 43}
44 44
45void InterfacePPP::start() 45void InterfacePPP::start()
46{ 46{
47 qDebug("InterfacePPP::start"); 47 qDebug("InterfacePPP::start");
48 if (data()->password().isEmpty() ){ 48// should work...
49//FIXME: ask for password 49// if (data()->password().isEmpty() ){
50 qDebug("using dummy password"); 50// //FIXME: ask for password
51 QMessageBox::critical( 0, "no password", "you should be prompted for a password, but you are not! ;-)"); 51// qDebug("using dummy password");
52 } 52// QMessageBox::critical( 0, "no password", "you should be prompted for a password, but you are not! ;-)");
53// }
53 54
54 55
55 QFileInfo info(pppdPath()); 56 QFileInfo info(pppdPath());
56 57
57 if(!info.exists()){ 58 if(!info.exists()){
58 QMessageBox::warning(0, tr("Error"), 59 QMessageBox::warning(0, tr("Error"),
59 i18n("<qt>Cannot find the PPP daemon!<br>" 60 i18n("<qt>Cannot find the PPP daemon!<br>"
60 "Make sure that pppd is installed and " 61 "Make sure that pppd is installed and "
61 "that you have entered the correct path.</qt>")); 62 "that you have entered the correct path.</qt>"));
62 return; 63 return;
63 } 64 }
64//#if 0 65//#if 0
65 if(!info.isExecutable()){ 66 if(!info.isExecutable()){
66 67
67 QString string; 68 QString string;
68 string = i18n( "<qt>Cannot execute:<br> %1<br>" 69 string = i18n( "<qt>Cannot execute:<br> %1<br>"
69 "Please make sure that you have given " 70 "Please make sure that you have given "
70 "setuid permission and that " 71 "setuid permission and that "
71 "pppd is executable.<br>").arg(pppdPath()); 72 "pppd is executable.<br>").arg(pppdPath());
72 QMessageBox::warning(0, tr("Error"), string); 73 QMessageBox::warning(0, tr("Error"), string);
73 return; 74 return;
74 75
75 } 76 }
76//#endif 77//#endif
77 78
78 QFileInfo info2(data()->modemDevice()); 79 QFileInfo info2(data()->modemDevice());
79 80
80 if(!info2.exists()){ 81 if(!info2.exists()){
81 QString string; 82 QString string;
82 string = i18n( "<qt>Cannot find:<br> %1<br>" 83 string = i18n( "<qt>Cannot find:<br> %1<br>"
83 "Please make sure you have setup " 84 "Please make sure you have setup "
84 "your modem device properly " 85 "your modem device properly "
85 "and/or adjust the location of the modem device on " 86 "and/or adjust the location of the modem device on "
86 "the modem tab of " 87 "the modem tab of "
87 "the setup dialog.</qt>").arg(data()->modemDevice()); 88 "the setup dialog.</qt>").arg(data()->modemDevice());
88 QMessageBox::warning(0, tr("Error"), string); 89 QMessageBox::warning(0, tr("Error"), string);
89 return; 90 return;
90 } 91 }
91 92
92 // if this is a PAP or CHAP account, ensure that username is 93 // if this is a PAP or CHAP account, ensure that username is
93 // supplied 94 // supplied
94 if(data()->authMethod() == AUTH_PAP || 95 if(data()->authMethod() == AUTH_PAP ||
95 data()->authMethod() == AUTH_CHAP || 96 data()->authMethod() == AUTH_CHAP ||
96 data()->authMethod() == AUTH_PAPCHAP ) { 97 data()->authMethod() == AUTH_PAPCHAP ) {
97 if(false){ //FIXME: ID_Edit->text().isEmpty()) { 98 if(false){ //FIXME: ID_Edit->text().isEmpty()) {
98 QMessageBox::warning(0,tr("Error"), 99 QMessageBox::warning(0,tr("Error"),
99 i18n("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>")); 100 i18n("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>"));
100// FIXME: return; 101// FIXME: return;
101 } else { 102 } else {
102 if(!modem()->setSecret(data()->authMethod(), 103 if(!modem()->setSecret(data()->authMethod(),
103 PPPData::encodeWord(data()->storedUsername()), 104 PPPData::encodeWord(data()->storedUsername()),
104 PPPData::encodeWord(data()->password())) 105 PPPData::encodeWord(data()->password()))
105 ) { 106 ) {
106 QString s; 107 QString s;
107 s = i18n("<qt>Cannot create PAP/CHAP authentication<br>" 108 s = i18n("<qt>Cannot create PAP/CHAP authentication<br>"
108 "file \"%1\"</qt>").arg(PAP_AUTH_FILE); 109 "file \"%1\"</qt>").arg(PAP_AUTH_FILE);
109 QMessageBox::warning(0, tr("Error"), s); 110 QMessageBox::warning(0, tr("Error"), s);
110 return; 111 return;
111 } 112 }
112 } 113 }
113 } 114 }
114 115
115 if (data()->phonenumber().isEmpty()) { 116 if (data()->phonenumber().isEmpty()) {
116 QString s = i18n("You must specify a telephone number!"); 117 QString s = i18n("You must specify a telephone number!");
117 QMessageBox::warning(0, tr("Error"), s); 118 QMessageBox::warning(0, tr("Error"), s);
118 return; 119 return;
119 } 120 }
120 121
121 // SEGFAULTS: 122 // SEGFAULTS:
122// setStatus( true ); 123// setStatus( true );
123// emit updateInterface((Interface*) this); 124// emit updateInterface((Interface*) this);
124 125
125 emit begin_connect(); 126 emit begin_connect();
126 127
127 qDebug("InterfacePPP::start END"); 128 qDebug("InterfacePPP::start END");
128} 129}
129 130
130void InterfacePPP::stop() 131void InterfacePPP::stop()
131{ 132{
132 qDebug("InterfacePPP::stop"); 133 qDebug("InterfacePPP::stop");
133 134
134} 135}
135 136
136void InterfacePPP::save() 137void InterfacePPP::save()
137{ 138{
138 data()->save(); 139 data()->save();
139 emit updateInterface((Interface*) this); 140 emit updateInterface((Interface*) this);
140} 141}