00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "kpppwidget.h"
00028
00029 #include <qapplication.h>
00030 #include <qcombobox.h>
00031 #include <qdir.h>
00032 #include <qevent.h>
00033 #include <qdialog.h>
00034 #include <qlabel.h>
00035 #include <qpushbutton.h>
00036 #include <qregexp.h>
00037 #include <qtabwidget.h>
00038 #include <qdialog.h>
00039 #include <qwhatsthis.h>
00040 #include <qcheckbox.h>
00041
00042
00043
00044 #include <qbuttongroup.h>
00045 #include <qmessagebox.h>
00046 #include <qpushbutton.h>
00047
00048 #include <stdlib.h>
00049 #include <errno.h>
00050 #include <signal.h>
00051
00052 #include "runtests.h"
00053
00054
00055 #include "auth.h"
00056 #include "modem.h"
00057
00058
00059
00060
00061 #include "pppdata.h"
00062 #include "general.h"
00063 #include "interface.h"
00064
00065 #define execute_command system
00066
00067 KPPPWidget *p_kppp = 0;
00068
00069 KPPPWidget::KPPPWidget(PPPData*pd, Interface *i, QWidget *parent, const char *name, bool modal, WFlags fl )
00070 : QDialog(parent, name, modal, Qt::WStyle_ContextHelp ), _pppdata(pd)
00071 {
00072
00073 p_kppp = this;
00074
00075 if (!_pppdata->setModemDevice( i->getInterfaceName() ))
00076 _pppdata->setModemDevice("/dev/modem");
00077 odebug << "PPPConfigWidget::PPPConfigWidget" << oendl;
00078 odebug << " interface->getHardwareName >" << i->getHardwareName().latin1() << "<" << oendl;
00079 if (!_pppdata->setAccount( i->getHardwareName() ))
00080 _pppdata->setAccount( 0 );
00081
00082 odebug << " _pppdata->accname >" << _pppdata->accname().latin1() << "<" << oendl;
00083 odebug << " _pppdata->currentAccountID() >" << _pppdata->currentAccountID() << "<" << oendl;
00084
00085 int result = runTests();
00086 if(result == TEST_CRITICAL)
00087 exit(4);
00088
00089
00090
00091 QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
00092
00093 QGridLayout *l1 = new QGridLayout(3, 4);
00094 tl->addLayout(l1);
00095 l1->addColSpacing(0, 10);
00096 l1->addColSpacing(3, 10);
00097 l1->setColStretch(1, 3);
00098 l1->setColStretch(2, 4);
00099
00100 label1 = new QLabel(QObject::tr("C&onnect to: "), this);
00101 l1->addWidget(label1, 0, 1);
00102
00103 connectto_c = new QComboBox(false, this);
00104 label1->setBuddy(connectto_c);
00105
00106 connect(connectto_c, SIGNAL(activated(int)),
00107 SLOT(newdefaultaccount(int)));
00108 l1->addWidget(connectto_c, 0, 2);
00109
00110 ID_Label = new QLabel(QObject::tr("&Login ID:"), this);
00111 l1->addWidget(ID_Label, 1, 1);
00112
00113
00114 ID_Edit = new QLineEdit(this);
00115 ID_Label->setBuddy(ID_Edit);
00116 l1->addWidget(ID_Edit, 1, 2);
00117 connect(ID_Edit, SIGNAL(returnPressed()),
00118 this, SLOT(enterPressedInID()));
00119 QString tmp = QObject::tr("<p>Type in the username that you got from your\n"
00120 "ISP. This is especially important for PAP\n"
00121 "and CHAP. You may omit this when you use\n"
00122 "terminal-based or script-based authentication.\n"
00123 "\n"
00124 "<b>Important</b>: case is important here:\n"
00125 "<i>myusername</i> is not the same as <i>MyUserName</i>!");
00126
00127 QWhatsThis::add(ID_Label,tmp);
00128 QWhatsThis::add(ID_Edit,tmp);
00129
00130 PW_Label = new QLabel(QObject::tr("&Password:"), this);
00131 l1->addWidget(PW_Label, 2, 1);
00132
00133 PW_Edit= new QLineEdit(this);
00134 PW_Label->setBuddy(PW_Edit);
00135 PW_Edit->setEchoMode(QLineEdit::Password);
00136 l1->addWidget(PW_Edit, 2, 2);
00137 connect(PW_Edit, SIGNAL(returnPressed()),
00138 this, SLOT(enterPressedInPW()));
00139
00140 tmp = QObject::tr("<p>Type in the password that you got from your\n"
00141 "ISP. This is especially important for PAP\n"
00142 "and CHAP. You may omit this when you use\n"
00143 "terminal-based or script-based authentication.\n"
00144 "\n"
00145 "<b>Important</b>: case is important here:\n"
00146 "<i>mypassword</i> is not the same as <i>MyPassword</i>!");
00147
00148 QWhatsThis::add(PW_Label,tmp);
00149 QWhatsThis::add(PW_Edit,tmp);
00150
00151 QHBoxLayout *l3 = new QHBoxLayout;
00152 tl->addSpacing(5);
00153 tl->addLayout(l3);
00154 tl->addSpacing(5);
00155 l3->addSpacing(10);
00156 log = new QCheckBox(QObject::tr("Show lo&g window"), this);
00157 connect(log, SIGNAL(toggled(bool)),
00158 this, SLOT(log_window_toggled(bool)));
00159 log->setChecked(_pppdata->get_show_log_window());
00160 l3->addWidget(log);
00161
00162 QWhatsThis::add(log,
00163 QObject::tr("<p>This controls whether a log window is shown.\n"
00164 "A log window shows the communication between\n"
00165 "<i>kppp</i> and your modem. This will help you\n"
00166 "in tracking down problems.\n"
00167 "\n"
00168 "Turn it off if <i>kppp</i> routinely connects without\n"
00169 "problems"));
00170
00171
00172
00173
00174 QHBoxLayout *l2 = new QHBoxLayout(this);
00175 tl->addLayout(l2);
00176
00177 int minw = 0;
00178 quit_b = new QPushButton(QObject::tr("&Quit"), this);
00179
00180 connect( quit_b, SIGNAL(clicked()), SLOT(quitbutton()));
00181 if(quit_b->sizeHint().width() > minw)
00182 minw = quit_b->sizeHint().width();
00183
00184 setup_b = new QPushButton(QObject::tr("&Setup..."), this);
00185
00186 connect( setup_b, SIGNAL(clicked()), SLOT(expandbutton()));
00187 if(setup_b->sizeHint().width() > minw)
00188 minw = setup_b->sizeHint().width();
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 connect_b = new QPushButton(QObject::tr("&Connect"), this);
00206 connect_b->setDefault(true);
00207 connect_b->setFocus();
00208 connect(connect_b, SIGNAL(clicked()), SLOT(beginConnect()));
00209 if(connect_b->sizeHint().width() > minw)
00210 minw = connect_b->sizeHint().width();
00211
00212 quit_b->setFixedWidth(minw);
00213 setup_b->setFixedWidth(minw);
00214
00215 connect_b->setFixedWidth(minw);
00216
00217 l2->addWidget(quit_b);
00218 l2->addWidget(setup_b);
00219
00220 l2->addSpacing(20);
00221 l2->addWidget(connect_b);
00222
00223 setFixedSize(sizeHint());
00224
00225 (void)new Modem(_pppdata);
00226
00227
00228
00229 connect(this,SIGNAL(cmdl_start()),this,SLOT(beginConnect()));
00230
00231
00232
00233
00234
00235
00236 con_win = new ConWindow(_pppdata, 0, "conw", this);
00237
00238
00239
00240
00241
00242
00243
00244
00245 con = new ConnectWidget(_pppdata, 0, "con");
00246
00247 connect(this, SIGNAL(begin_connect()),con, SLOT(preinit()));
00248
00249
00250
00251
00252
00253
00254 connect(con, SIGNAL(startAccounting()),
00255 this, SLOT(startAccounting()));
00256 connect(con, SIGNAL(stopAccounting()),
00257 this, SLOT(stopAccounting()));
00258 connect(qApp, SIGNAL(saveYourself()),
00259 this, SLOT(saveMyself()));
00260 connect(qApp, SIGNAL(shutDown()),
00261 this, SLOT(shutDown()));
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 #ifdef KPPP_SHOW_NEWS
00292
00293 if(!m_bCmdlAccount)
00294 showNews();
00295 #endif
00296 }
00297
00298 KPPPWidget::~KPPPWidget()
00299 {
00300 p_kppp = 0;
00301
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 void KPPPWidget::enterPressedInID() {
00337 PW_Edit->setFocus();
00338 }
00339
00340
00341 void KPPPWidget::enterPressedInPW() {
00342 connect_b->setFocus();
00343 }
00344
00345
00346 void KPPPWidget::saveMyself() {
00347 _pppdata->save();
00348 }
00349
00350 void KPPPWidget::shutDown() {
00351 interruptConnection();
00352 saveMyself();
00353 }
00354
00355 void KPPPWidget::log_window_toggled(bool on) {
00356 _pppdata->set_show_log_window(on);
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 void KPPPWidget::interruptConnection() {
00413
00414
00415
00416 if (con->isVisible())
00417 emit con->cancelbutton();
00418
00419
00420 if (_pppdata->pppdRunning())
00421 emit disconnect();
00422 }
00423
00424
00425 void KPPPWidget::sigPPPDDied() {
00426 odebug << "Received a SIGUSR1" << oendl;
00427
00428
00429
00430
00431 if(_pppdata->pppdRunning() || _pppdata->pppdError()) {
00432 odebug << "It was pppd that died" << oendl;
00433
00434
00435
00436
00437
00438
00439
00440 Modem::modem->removeSecret(AUTH_PAP);
00441 Modem::modem->removeSecret(AUTH_CHAP);
00442
00443 _pppdata->setpppdRunning(false);
00444
00445 odebug << "Executing command on disconnect since pppd has died." << oendl;
00446 QApplication::flushX();
00447 execute_command(_pppdata->command_on_disconnect());
00448
00449
00450
00451 con_win->stopClock();
00452
00453
00454
00455 if(!_pppdata->pppdError())
00456 _pppdata->setpppdError(E_PPPD_DIED);
00457 removedns();
00458 Modem::modem->unlockdevice();
00459
00460 con->pppdDied();
00461
00462 if(!_pppdata->automatic_redial()) {
00463 quit_b->setFocus();
00464 show();
00465 con_win->stopClock();
00466
00467 con_win->hide();
00468 con->hide();
00469
00470 _pppdata->setpppdRunning(false);
00471
00472 QString msg;
00473 if (_pppdata->pppdError() == E_IF_TIMEOUT)
00474 msg = QObject::tr("Timeout expired while waiting for the PPP interface "
00475 "to come up!");
00476 else {
00477 msg = QObject::tr("<p>The pppd daemon died unexpectedly!</p>");
00478 Modem::modem->pppdExitStatus();
00479 if (Modem::modem->lastStatus != 99) {
00480 msg += QObject::tr("<p>Exit status: %1").arg(Modem::modem->lastStatus);
00481 msg += QObject::tr("</p><p>See 'man pppd' for an explanation of the error "
00482 "codes or take a look at the kppp FAQ on "
00483 " <a href=http://devel-home.kde.org/~kppp/index.html>"
00484 "http://devel-home.kde.org/~kppp/index.html</a></p>");
00485 }
00486 }
00487
00488
00489
00490
00491 if (false){
00492 odebug << "Trying to reconnect... " << oendl;
00493
00494 if(_pppdata->authMethod() == AUTH_PAP ||
00495 _pppdata->authMethod() == AUTH_CHAP ||
00496 _pppdata->authMethod() == AUTH_PAPCHAP)
00497 Modem::modem->setSecret(_pppdata->authMethod(),
00498 encodeWord(_pppdata->storedUsername()),
00499 encodeWord(_pppdata->password()));
00500
00501 con_win->hide();
00502 con_win->stopClock();
00503
00504 _pppdata->setpppdRunning(false);
00505
00506 emit cmdl_start();
00507 }
00508 }
00509 _pppdata->setpppdError(0);
00510 }
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 void KPPPWidget::newdefaultaccount(int i) {
00530 _pppdata->setDefaultAccount(connectto_c->text(i));
00531 _pppdata->save();
00532 ID_Edit->setText(_pppdata->storedUsername());
00533 PW_Edit->setText(_pppdata->storedPassword());
00534 }
00535
00536
00537
00538
00539 void KPPPWidget::beginConnect() {
00540
00541
00542
00543
00544
00545
00546 _pppdata->setPassword(_pppdata->storedPassword());
00547
00548
00549 QFileInfo info(pppdPath());
00550
00551 if(!info.exists()){
00552 QMessageBox::warning(this, "error", QObject::tr("Cannot find the PPP daemon!\n"
00553 "Make sure that pppd is installed and "
00554 "that you have entered the correct path."));
00555 return;
00556 }
00557 #if 0
00558 if(!info.isExecutable()){
00559
00560 QString string;
00561 string = QObject::tr("kppp cannot execute:\n %1\n"
00562 "Please make sure that you have given kppp "
00563 "setuid permission and that "
00564 "pppd is executable.").arg(_pppdata->pppdPath());
00565 KMessageBox::error(this, string);
00566 return;
00567
00568 }
00569 #endif
00570
00571 QFileInfo info2(_pppdata->modemDevice());
00572
00573 if(!info2.exists()){
00574 QString string;
00575 string = QObject::tr("kppp can not find:\n %1\nPlease make sure you have setup "
00576 "your modem device properly "
00577 "and/or adjust the location of the modem device on "
00578 "the modem tab of "
00579 "the setup dialog.").arg(_pppdata->modemDevice());
00580 QMessageBox::warning(this, "error", string);
00581 return;
00582 }
00583
00584
00585
00586 if(_pppdata->authMethod() == AUTH_PAP ||
00587 _pppdata->authMethod() == AUTH_CHAP ||
00588 _pppdata->authMethod() == AUTH_PAPCHAP ) {
00589 if(ID_Edit->text().isEmpty()) {
00590 QMessageBox::warning(this,"error",
00591 QObject::tr("You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!"));
00592 return;
00593 } else {
00594 if(!Modem::modem->setSecret(_pppdata->authMethod(),
00595 encodeWord(_pppdata->storedUsername()),
00596 encodeWord(_pppdata->password()))) {
00597 QString s;
00598 s = QObject::tr("Cannot create PAP/CHAP authentication\n"
00599 "file \"%1\"").arg(PAP_AUTH_FILE);
00600 QMessageBox::warning(this, "error", s);
00601 return;
00602 }
00603 }
00604 }
00605
00606 if (_pppdata->phonenumber().isEmpty()) {
00607 QString s = QObject::tr("You must specify a telephone number!");
00608 QMessageBox::warning(this, "error", s);
00609 return;
00610 }
00611
00612 this->hide();
00613
00614 QString tit = QObject::tr("Connecting to: %1").arg(_pppdata->accname());
00615
00616
00617
00618
00619
00620 emit begin_connect();
00621 }
00622
00623
00624 void KPPPWidget::disconnect() {
00625 if (!_pppdata->command_before_disconnect().isEmpty()) {
00626 con_win->hide();
00627 con->show();
00628 con->setCaption(QObject::tr("Disconnecting..."));
00629 con->setMsg(QObject::tr("Executing command before disconnection."));
00630
00631 qApp->processEvents();
00632 QApplication::flushX();
00633
00634 execute_command(_pppdata->command_before_disconnect());
00635
00636
00637
00638
00639
00640
00641
00642
00643 con->hide();
00644 }
00645
00646 qApp->processEvents();
00647
00648
00649 Modem::modem->killPPPDaemon();
00650
00651 QApplication::flushX();
00652 execute_command(_pppdata->command_on_disconnect());
00653
00654 Modem::modem->removeSecret(AUTH_PAP);
00655 Modem::modem->removeSecret(AUTH_CHAP);
00656
00657 removedns();
00658 Modem::modem->unlockdevice();
00659
00660 con_win->stopClock();
00661
00662 con_win->hide();
00663
00664
00665
00666
00667
00668
00669
00670 this->quit_b->setFocus();
00671 this->show();
00672
00673 }
00674
00675
00676
00677
00678
00679
00680
00681 void KPPPWidget::quitbutton() {
00682 if(_pppdata->pppdRunning()) {
00683 int ok = QMessageBox::warning(this,
00684 QObject::tr("Exiting kPPP will close your PPP Session."),
00685 QObject::tr("Quit kPPP?"));
00686 if(ok == QMessageBox::Yes) {
00687 Modem::modem->killPPPDaemon();
00688 QApplication::flushX();
00689 execute_command(_pppdata->command_on_disconnect());
00690 removedns();
00691 Modem::modem->unlockdevice();
00692 }
00693 } else {
00694 if (!_pppdata->accname().isEmpty() && !_pppdata->storePassword())
00695 _pppdata->setStoredPassword("");
00696 }
00697 _pppdata->save();
00698 qApp->quit();
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 void KPPPWidget::usernameChanged(const QString &) {
00766
00767 _pppdata->setStoredUsername(ID_Edit->text());
00768 }
00769
00770
00771 void KPPPWidget::passwordChanged(const QString &) {
00772
00773 if(_pppdata->storePassword())
00774 _pppdata->setStoredPassword(PW_Edit->text());
00775 else
00776 _pppdata->setStoredPassword("");
00777 }
00778
00779
00780 void KPPPWidget::setPW_Edit(const QString &pw) {
00781 PW_Edit->setText(pw);
00782 }
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00799 QString KPPPWidget::encodeWord(const QString &s) {
00800 QString r = s;
00801 r.replace(QRegExp("\\"), "\\\\");
00802 return r;
00803 }
00804
00805
00806
00807
00808
00809
00810 void KPPPWidget::showNews() {
00811 #ifdef KPPP_SHOW_NEWS
00812
00813
00814
00815 #define QUICKHELP_HINT "Hint_QuickHelp"
00816 if(_pppdata->readNumConfig(GENERAL_GRP, QUICKHELP_HINT, 0) == 0) {
00817 QDialog dlg(0, 0, true);
00818 dlg.setCaption(QObject::tr("Recent Changes in KPPP"));
00819
00820 QVBoxLayout *tl = new QVBoxLayout(&dlg, 10, 10);
00821 QHBoxLayout *l1 = new QHBoxLayout(10);
00822 QVBoxLayout *l2 = new QVBoxLayout(10);
00823 tl->addLayout(l1);
00824
00825 QLabel *icon = new QLabel(&dlg);
00826 icon->setPixmap(BarIcon("exclamation"));
00827 icon->setFixedSize(icon->sizeHint());
00828 l1->addWidget(icon);
00829 l1->addLayout(l2);
00830
00831 QLabel *l = new QLabel(QObject::tr("From version 1.4.8 on, kppp has a new feature\n"
00832 "called \"Quickhelp\". It's similar to a tooltip,\n"
00833 "but you can activate it whenever you want.\n"
00834 "\n"
00835 "To activate it, simply click on a control like\n"
00836 "a button or a label with the right mouse button.\n"
00837 "If the item supports Quickhelp, a popup menu\n"
00838 "will appear leading to Quickhelp.\n"
00839 "\n"
00840 "To test it, right-click somewhere in this text."),
00841 &dlg);
00842
00843 QCheckBox *cb = new QCheckBox(QObject::tr("Don't show this hint again"), &dlg);
00844 cb->setFixedSize(cb->sizeHint());
00845
00846 KButtonBox *bbox = new KButtonBox(&dlg);
00847 bbox->addStretch(1);
00848 QPushButton *ok = bbox->addButton(QObject::tr("OK"));
00849 ok->setDefault(true);
00850 dlg.connect(ok, SIGNAL(clicked()),
00851 &dlg, SLOT(accept()));
00852 bbox->addStretch(1);
00853 bbox->layout();
00854
00855 l2->addWidget(l);
00856 l2->addWidget(cb);
00857 tl->addWidget(bbox);
00858
00859 QString tmp = QObject::tr("This is an example of <b>QuickHelp</b>.\n"
00860 "This window will stay open until you\n"
00861 "click a mouse button or a press a key.\n");
00862
00863 QWhatsThis::add(cb,tmp);
00864 QWhatsThis::add(l, tmp);
00865
00866 dlg.exec();
00867 if(cb->isChecked()) {
00868 _pppdata->writeConfig(GENERAL_GRP, QUICKHELP_HINT, 1);
00869 _pppdata->save();
00870 }
00871 }
00872 #endif
00873 }
00874
00875
00876
00877