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