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