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