summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/interfaceppp.cpp
blob: f443f3c3bed874d3c8fcf7ccb3483b5ee0613516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

#include <qmessagebox.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlabel.h>

#include "auth.h"
#include "interfaceppp.h"
#include "modem.h"
#include "pppdata.h"

InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status)
    : Interface(parent, name, status),
      _modemPtr(0),
      _dataPtr(0)
{
    qDebug("InterfacePPP::InterfacePPP(");
}

PPPData* InterfacePPP::data()const
{
    if (!_dataPtr){
        qDebug("creating new Data obj");
        _dataPtr = new PPPData();
        _dataPtr->setDevice( getInterfaceName() );
        _dataPtr->setAccount( getHardwareName() );
    }
    return _dataPtr;
}

Modem* InterfacePPP::modem()const
{
    if (!_modemPtr){
        qDebug("creating new modem obj");
        _modemPtr = new Modem( data() );
    }
    return _modemPtr;
}

bool InterfacePPP::refresh()
{
    qDebug("InterfacePPP::refresh()");
    QString old = getInterfaceName();
    setInterfaceName( modem()->pppDevice() );

    (void)Interface::refresh();

    setInterfaceName( old );
    emit updateInterface(this);

    return true;
}

void InterfacePPP::start()
{
    qDebug("InterfacePPP::start");

    if (data()->password().isEmpty() && !data()->storedUsername().isEmpty() ) {

        QDialog mb( 0, "Dialog", true );
        mb.setCaption( tr( "No password" ) );
        QVBoxLayout layout( &mb );
        QLabel text ( &mb  );
        text.setText( tr("Username defined but no password\n Please enter a password") );
        QLineEdit lineedit( &mb );
        lineedit.setEchoMode( QLineEdit::Password );
        layout.addWidget( &text );
        layout.addWidget( &lineedit );
        if ( mb.exec() == QDialog::Accepted )  {
            data()->setPassword( lineedit.text() );
        }
    }

  QFileInfo info(pppdPath());

  if(!info.exists()){
    QMessageBox::warning(0, tr("Error"),
                         QObject::tr("<qt>Cannot find the PPP daemon!<br>"
                              "Make sure that pppd is installed and "
                              "that you have entered the correct path.</qt>"));
    return;
  }
//#if 0
  if(!info.isExecutable()){

    QString string;
    string = QObject::tr( "<qt>Cannot execute:<br> %1<br>"
    		   "Please make sure that you have given "
		   "setuid permission and that "
		   "pppd is executable.<br>").arg(pppdPath());
    QMessageBox::warning(0, tr("Error"), string);
    return;

  }
//#endif

  QFileInfo info2(data()->modemDevice());

  if(!info2.exists()){
    QString string;
    string = QObject::tr( "<qt>Cannot find:<br> %1<br>"
                   "Please make sure you have setup "
		   "your modem device properly "
		   "and/or adjust the location of the modem device on "
		   "the modem tab of "
		   "the setup dialog.</qt>").arg(data()->modemDevice());
    QMessageBox::warning(0, tr("Error"), string);
    return;
  }

  // if this is a PAP or CHAP account, ensure that username is
  // supplied
  if(data()->authMethod() == AUTH_PAP ||
     data()->authMethod() == AUTH_CHAP ||
     data()->authMethod() == AUTH_PAPCHAP ) {
      if(false){ //FIXME: ID_Edit->text().isEmpty()) {
        QMessageBox::warning(0,tr("Error"),
			   QObject::tr("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>"));
// FIXME:      return;
    } else {
      if(!modem()->setSecret(data()->authMethod(),
                             PPPData::encodeWord(data()->storedUsername()),
                             PPPData::encodeWord(data()->password()))
          ) {
	QString s;
	s = QObject::tr("<qt>Cannot create PAP/CHAP authentication<br>"
				     "file \"%1\"</qt>").arg(PAP_AUTH_FILE);
	QMessageBox::warning(0, tr("Error"), s);
	return;
      }
    }
  }

  if (data()->phonenumber().isEmpty()) {
    QString s = QObject::tr("You must specify a telephone number!");
    QMessageBox::warning(0, tr("Error"), s);
    return;
  }

  // SEGFAULTS:
//   setStatus( true );
//   emit updateInterface((Interface*) this);

  emit begin_connect();

  qDebug("InterfacePPP::start END");
}

void InterfacePPP::stop()
{
    qDebug("InterfacePPP::stop");
    // emit hangup_now();
    status = false; // not connected
    setStatus( false );
    emit hangup_now();
    refresh();

}

void InterfacePPP::save()
{
    data()->save();
    emit updateInterface((Interface*) this);
}
QString InterfacePPP::pppDev()const {
    return modem()->pppDevice();
}
pid_t InterfacePPP::pppPID()const{
    return modem()->pppPID();
}
void InterfacePPP::setPPPDpid( pid_t pid) {
    setStatus( true );
    modem()->setPPPDPid( pid );
}