author | dwmw2 <dwmw2> | 2003-06-07 17:07:43 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2003-06-07 17:07:43 (UTC) |
commit | 9ae55ad05f06d1bff20ea0e0fae59781b503a79b (patch) (unidiff) | |
tree | b197565219d69cadecca357a978a9319eeb52220 | |
parent | b293babbe1e640705163a95e192461d140f590eb (diff) | |
download | opie-9ae55ad05f06d1bff20ea0e0fae59781b503a79b.zip opie-9ae55ad05f06d1bff20ea0e0fae59781b503a79b.tar.gz opie-9ae55ad05f06d1bff20ea0e0fae59781b503a79b.tar.bz2 |
set/use interface status
-rw-r--r-- | noncore/settings/networksettings/ppp/connect.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/ppp/connect.cpp b/noncore/settings/networksettings/ppp/connect.cpp index 6905d79..2400d7b 100644 --- a/noncore/settings/networksettings/ppp/connect.cpp +++ b/noncore/settings/networksettings/ppp/connect.cpp | |||
@@ -1,308 +1,311 @@ | |||
1 | /* | 1 | /* |
2 | * kPPP: A pppd front end for the KDE project | 2 | * kPPP: A pppd front end for the KDE project |
3 | * | 3 | * |
4 | * | 4 | * |
5 | * Copyright (C) 1997 Bernd Johannes Wuebben | 5 | * Copyright (C) 1997 Bernd Johannes Wuebben |
6 | * wuebben@math.cornell.edu | 6 | * wuebben@math.cornell.edu |
7 | * Copyright (C) 1998-2001 Harri Porten <porten@kde.org> | 7 | * Copyright (C) 1998-2001 Harri Porten <porten@kde.org> |
8 | * | 8 | * |
9 | * based on EzPPP: | 9 | * based on EzPPP: |
10 | * Copyright (C) 1997 Jay Painter | 10 | * Copyright (C) 1997 Jay Painter |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU Library General Public | 13 | * modify it under the terms of the GNU Library General Public |
14 | * License as published by the Free Software Foundation; either | 14 | * License as published by the Free Software Foundation; either |
15 | * version 2 of the License, or (at your option) any later version. | 15 | * version 2 of the License, or (at your option) any later version. |
16 | * | 16 | * |
17 | * This program is distributed in the hope that it will be useful, | 17 | * This program is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * Library General Public License for more details. | 20 | * Library General Public License for more details. |
21 | * | 21 | * |
22 | * You should have received a copy of the GNU Library General Public | 22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with this program; if not, write to the Free | 23 | * License along with this program; if not, write to the Free |
24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | //#include <config.h> | 27 | //#include <config.h> |
28 | 28 | ||
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qregexp.h> | 30 | #include <qregexp.h> |
31 | 31 | ||
32 | #include <qapplication.h> | 32 | #include <qapplication.h> |
33 | //#include <kdebug.h> | 33 | //#include <kdebug.h> |
34 | //#include <klocale.h> | 34 | //#include <klocale.h> |
35 | #define i18n QObject::tr | 35 | #define i18n QObject::tr |
36 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
37 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
38 | 38 | ||
39 | #include <unistd.h> | 39 | #include <unistd.h> |
40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
41 | #include <string.h> | 41 | #include <string.h> |
42 | #include <fcntl.h> | 42 | #include <fcntl.h> |
43 | #include <netdb.h> | 43 | #include <netdb.h> |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <sys/socket.h> | 45 | #include <sys/socket.h> |
46 | #include <arpa/inet.h> | 46 | #include <arpa/inet.h> |
47 | #include <netinet/in.h> | 47 | #include <netinet/in.h> |
48 | #include <sys/ioctl.h> | 48 | #include <sys/ioctl.h> |
49 | #include <assert.h> | 49 | #include <assert.h> |
50 | 50 | ||
51 | #ifdef _XPG4_2 | 51 | #ifdef _XPG4_2 |
52 | #define __xnet_connectconnect | 52 | #define __xnet_connectconnect |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | #include <errno.h> | 55 | #include <errno.h> |
56 | 56 | ||
57 | #ifdef HAVE_SYS_PARAM_H | 57 | #ifdef HAVE_SYS_PARAM_H |
58 | #include <sys/param.h> | 58 | #include <sys/param.h> |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifdef __linux__ | 61 | #ifdef __linux__ |
62 | #include "runtests.h" | 62 | #include "runtests.h" |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #include "auth.h" | 65 | #include "auth.h" |
66 | #include "connect.h" | 66 | #include "connect.h" |
67 | //#include "docking.h" | 67 | //#include "docking.h" |
68 | #include "interfaceppp.h" | 68 | #include "interfaceppp.h" |
69 | #include "modem.h" | 69 | #include "modem.h" |
70 | #include "kpppconfig.h" | 70 | #include "kpppconfig.h" |
71 | #include "pppdata.h" | 71 | #include "pppdata.h" |
72 | #include "kpppwidget.h" | 72 | #include "kpppwidget.h" |
73 | //#include "requester.h" | 73 | //#include "requester.h" |
74 | //#include "utils.h" | 74 | //#include "utils.h" |
75 | #define execute_command system | 75 | #define execute_command system |
76 | 76 | ||
77 | QString old_hostname; | 77 | QString old_hostname; |
78 | bool modified_hostname; | 78 | bool modified_hostname; |
79 | 79 | ||
80 | 80 | ||
81 | ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *name) | 81 | ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *name) |
82 | : QWidget(parent, name), | 82 | : QWidget(parent, name), |
83 | myreadbuffer(""), | 83 | myreadbuffer(""), |
84 | main_timer_ID(0), | 84 | main_timer_ID(0), |
85 | vmain(0), | 85 | vmain(0), |
86 | substate(-1), | 86 | substate(-1), |
87 | scriptindex(0), | 87 | scriptindex(0), |
88 | loopnest(0), | 88 | loopnest(0), |
89 | loopend(false), | 89 | loopend(false), |
90 | semaphore(false), | 90 | semaphore(false), |
91 | expecting(false), | 91 | expecting(false), |
92 | readbuffer(""), | 92 | readbuffer(""), |
93 | scanvar(""), | 93 | scanvar(""), |
94 | scanning(false), | 94 | scanning(false), |
95 | pausing(false), | 95 | pausing(false), |
96 | dialnumber(0), | 96 | dialnumber(0), |
97 | _ifaceppp(ifp) | 97 | _ifaceppp(ifp) |
98 | { | 98 | { |
99 | modified_hostname = false; | 99 | modified_hostname = false; |
100 | 100 | ||
101 | QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); | 101 | QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); |
102 | QString tit = i18n("Connecting to: "); | 102 | QString tit = i18n("Connecting to: "); |
103 | setCaption(tit); | 103 | setCaption(tit); |
104 | 104 | ||
105 | QHBoxLayout *l0 = new QHBoxLayout(10); | 105 | QHBoxLayout *l0 = new QHBoxLayout(10); |
106 | tl->addLayout(l0); | 106 | tl->addLayout(l0); |
107 | l0->addSpacing(10); | 107 | l0->addSpacing(10); |
108 | messg = new QLabel(this, "messg"); | 108 | messg = new QLabel(this, "messg"); |
109 | messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); | 109 | messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); |
110 | messg->setAlignment(AlignCenter); | 110 | messg->setAlignment(AlignCenter); |
111 | messg->setText(i18n("Unable to create modem lock file.")); | 111 | messg->setText(i18n("Unable to create modem lock file.")); |
112 | messg->setMinimumHeight(messg->sizeHint().height() + 5); | 112 | messg->setMinimumHeight(messg->sizeHint().height() + 5); |
113 | // int messw = (messg->sizeHint().width() * 12) / 10; | 113 | // int messw = (messg->sizeHint().width() * 12) / 10; |
114 | // messw = QMAX(messw,280); | 114 | // messw = QMAX(messw,280); |
115 | // messg->setMinimumWidth(messw); | 115 | // messg->setMinimumWidth(messw); |
116 | messg->setText(i18n("Offline")); | 116 | if (_ifaceppp->getStatus()) |
117 | messg->setText(i18n("Online")); | ||
118 | else | ||
119 | messg->setText(i18n("Offline")); | ||
117 | l0->addSpacing(10); | 120 | l0->addSpacing(10); |
118 | l0->addWidget(messg); | 121 | l0->addWidget(messg); |
119 | l0->addSpacing(10); | 122 | l0->addSpacing(10); |
120 | 123 | ||
121 | QHBoxLayout *l1 = new QHBoxLayout(10); | 124 | QHBoxLayout *l1 = new QHBoxLayout(10); |
122 | tl->addLayout(l1); | 125 | tl->addLayout(l1); |
123 | l1->addStretch(1); | 126 | l1->addStretch(1); |
124 | 127 | ||
125 | debug = new QPushButton(i18n("Log"), this); | 128 | debug = new QPushButton(i18n("Log"), this); |
126 | debug->setToggleButton(true); | 129 | debug->setToggleButton(true); |
127 | debug->setEnabled( false ); // FIXME: disable the log button | 130 | debug->setEnabled( false ); // FIXME: disable the log button |
128 | connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); | 131 | connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); |
129 | 132 | ||
130 | cancel = new QPushButton(i18n("Cancel"), this); | 133 | cancel = new QPushButton(i18n("Cancel"), this); |
131 | cancel->setFocus(); | 134 | cancel->setFocus(); |
132 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); | 135 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); |
133 | 136 | ||
134 | // int maxw = QMAX(cancel->sizeHint().width(), | 137 | // int maxw = QMAX(cancel->sizeHint().width(), |
135 | // debug->sizeHint().width()); | 138 | // debug->sizeHint().width()); |
136 | // maxw = QMAX(maxw,65); | 139 | // maxw = QMAX(maxw,65); |
137 | // debug->setFixedWidth(maxw); | 140 | // debug->setFixedWidth(maxw); |
138 | // cancel->setFixedWidth(maxw); | 141 | // cancel->setFixedWidth(maxw); |
139 | l1->addWidget(debug); | 142 | l1->addWidget(debug); |
140 | l1->addWidget(cancel); | 143 | l1->addWidget(cancel); |
141 | 144 | ||
142 | // setFixedSize(sizeHint()); | 145 | // setFixedSize(sizeHint()); |
143 | 146 | ||
144 | pausetimer = new QTimer(this); | 147 | pausetimer = new QTimer(this); |
145 | connect(pausetimer, SIGNAL(timeout()), SLOT(pause())); | 148 | connect(pausetimer, SIGNAL(timeout()), SLOT(pause())); |
146 | 149 | ||
147 | qApp->processEvents(); | 150 | qApp->processEvents(); |
148 | 151 | ||
149 | timeout_timer = new QTimer(this); | 152 | timeout_timer = new QTimer(this); |
150 | connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out())); | 153 | connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out())); |
151 | 154 | ||
152 | inittimer = new QTimer(this); | 155 | inittimer = new QTimer(this); |
153 | connect(inittimer, SIGNAL(timeout()), SLOT(init())); | 156 | connect(inittimer, SIGNAL(timeout()), SLOT(init())); |
154 | 157 | ||
155 | if_timeout_timer = new QTimer(this); | 158 | if_timeout_timer = new QTimer(this); |
156 | connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out())); | 159 | connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out())); |
157 | 160 | ||
158 | connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot())); | 161 | connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot())); |
159 | 162 | ||
160 | prompt = new PWEntry( this, "pw" ); | 163 | prompt = new PWEntry( this, "pw" ); |
161 | if_timer = new QTimer(this); | 164 | if_timer = new QTimer(this); |
162 | connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); | 165 | connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); |
163 | } | 166 | } |
164 | 167 | ||
165 | 168 | ||
166 | ConnectWidget::~ConnectWidget() { | 169 | ConnectWidget::~ConnectWidget() { |
167 | } | 170 | } |
168 | 171 | ||
169 | 172 | ||
170 | void ConnectWidget::preinit() { | 173 | void ConnectWidget::preinit() { |
171 | // this is all just to keep the GUI nice and snappy .... | 174 | // this is all just to keep the GUI nice and snappy .... |
172 | // you have to see to believe ... | 175 | // you have to see to believe ... |
173 | messg->setText(i18n("Looking for modem...")); | 176 | messg->setText(i18n("Looking for modem...")); |
174 | inittimer->start(100); | 177 | inittimer->start(100); |
175 | } | 178 | } |
176 | 179 | ||
177 | 180 | ||
178 | void ConnectWidget::init() { | 181 | void ConnectWidget::init() { |
179 | _ifaceppp->data()->setpppdError(0); | 182 | _ifaceppp->data()->setpppdError(0); |
180 | inittimer->stop(); | 183 | inittimer->stop(); |
181 | vmain = 0; | 184 | vmain = 0; |
182 | substate = -1; | 185 | substate = -1; |
183 | expecting = false; | 186 | expecting = false; |
184 | pausing = false; | 187 | pausing = false; |
185 | scriptindex = 0; | 188 | scriptindex = 0; |
186 | myreadbuffer = ""; | 189 | myreadbuffer = ""; |
187 | scanning = false; | 190 | scanning = false; |
188 | scanvar = ""; | 191 | scanvar = ""; |
189 | firstrunID = true; | 192 | firstrunID = true; |
190 | firstrunPW = true; | 193 | firstrunPW = true; |
191 | // stats->totalbytes = 0; | 194 | // stats->totalbytes = 0; |
192 | dialnumber = 0; | 195 | dialnumber = 0; |
193 | 196 | ||
194 | // p_kppp->con_speed = ""; | 197 | // p_kppp->con_speed = ""; |
195 | 198 | ||
196 | // p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect()); | 199 | // p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect()); |
197 | 200 | ||
198 | comlist = &_ifaceppp->data()->scriptType(); | 201 | comlist = &_ifaceppp->data()->scriptType(); |
199 | arglist = &_ifaceppp->data()->script(); | 202 | arglist = &_ifaceppp->data()->script(); |
200 | 203 | ||
201 | QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname()); | 204 | QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname()); |
202 | setCaption(tit); | 205 | setCaption(tit); |
203 | 206 | ||
204 | qApp->processEvents(); | 207 | qApp->processEvents(); |
205 | 208 | ||
206 | // run the "before-connect" command | 209 | // run the "before-connect" command |
207 | if (!_ifaceppp->data()->command_before_connect().isEmpty()) { | 210 | if (!_ifaceppp->data()->command_before_connect().isEmpty()) { |
208 | messg->setText(i18n("Running pre-startup command...")); | 211 | messg->setText(i18n("Running pre-startup command...")); |
209 | emit debugMessage(i18n("Running pre-startup command...")); | 212 | emit debugMessage(i18n("Running pre-startup command...")); |
210 | 213 | ||
211 | qApp->processEvents(); | 214 | qApp->processEvents(); |
212 | QApplication::flushX(); | 215 | QApplication::flushX(); |
213 | pid_t id = execute_command(_ifaceppp->data()->command_before_connect()); | 216 | pid_t id = execute_command(_ifaceppp->data()->command_before_connect()); |
214 | // int i, status; | 217 | // int i, status; |
215 | 218 | ||
216 | // do { | 219 | // do { |
217 | // qApp->processEvents(); | 220 | // qApp->processEvents(); |
218 | // i = waitpid(id, &status, WNOHANG); | 221 | // i = waitpid(id, &status, WNOHANG); |
219 | // usleep(100000); | 222 | // usleep(100000); |
220 | // } while (i == 0 && errno == 0); | 223 | // } while (i == 0 && errno == 0); |
221 | } | 224 | } |
222 | 225 | ||
223 | int lock = _ifaceppp->modem()->lockdevice(); | 226 | int lock = _ifaceppp->modem()->lockdevice(); |
224 | 227 | ||
225 | if (lock == 1) { | 228 | if (lock == 1) { |
226 | messg->setText(i18n("Modem device is locked.")); | 229 | messg->setText(i18n("Modem device is locked.")); |
227 | vmain = 20; // wait until cancel is pressed | 230 | vmain = 20; // wait until cancel is pressed |
228 | return; | 231 | return; |
229 | } | 232 | } |
230 | 233 | ||
231 | if (lock == -1) { | 234 | if (lock == -1) { |
232 | messg->setText(i18n("Unable to create modem lock file.")); | 235 | messg->setText(i18n("Unable to create modem lock file.")); |
233 | vmain = 20; // wait until cancel is pressed | 236 | vmain = 20; // wait until cancel is pressed |
234 | return; | 237 | return; |
235 | } | 238 | } |
236 | 239 | ||
237 | if(_ifaceppp->modem()->opentty()) { | 240 | if(_ifaceppp->modem()->opentty()) { |
238 | messg->setText(_ifaceppp->modem()->modemMessage()); | 241 | messg->setText(_ifaceppp->modem()->modemMessage()); |
239 | qApp->processEvents(); | 242 | qApp->processEvents(); |
240 | if(_ifaceppp->modem()->hangup()) { | 243 | if(_ifaceppp->modem()->hangup()) { |
241 | 244 | ||
242 | qApp->processEvents(); | 245 | qApp->processEvents(); |
243 | 246 | ||
244 | semaphore = false; | 247 | semaphore = false; |
245 | 248 | ||
246 | _ifaceppp->modem()->stop(); | 249 | _ifaceppp->modem()->stop(); |
247 | _ifaceppp->modem()->notify(this, SLOT(readChar(unsigned char))); | 250 | _ifaceppp->modem()->notify(this, SLOT(readChar(unsigned char))); |
248 | 251 | ||
249 | // if we are stuck anywhere we will time out | 252 | // if we are stuck anywhere we will time out |
250 | timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); | 253 | timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); |
251 | 254 | ||
252 | // this timer will run the script etc. | 255 | // this timer will run the script etc. |
253 | main_timer_ID = startTimer(10); | 256 | main_timer_ID = startTimer(10); |
254 | 257 | ||
255 | return; | 258 | return; |
256 | } | 259 | } |
257 | } | 260 | } |
258 | 261 | ||
259 | // initialization failed | 262 | // initialization failed |
260 | messg->setText(_ifaceppp->modem()->modemMessage()); | 263 | messg->setText(_ifaceppp->modem()->modemMessage()); |
261 | vmain = 20; // wait until cancel is pressed | 264 | vmain = 20; // wait until cancel is pressed |
262 | _ifaceppp->modem()->unlockdevice(); | 265 | _ifaceppp->modem()->unlockdevice(); |
263 | } | 266 | } |
264 | 267 | ||
265 | 268 | ||
266 | void ConnectWidget::timerEvent(QTimerEvent *) { | 269 | void ConnectWidget::timerEvent(QTimerEvent *) { |
267 | if (semaphore || pausing) | 270 | if (semaphore || pausing) |
268 | return; | 271 | return; |
269 | 272 | ||
270 | if(vmain == 0) { | 273 | if(vmain == 0) { |
271 | #ifdef DEBUG_WO_DIALING | 274 | #ifdef DEBUG_WO_DIALING |
272 | vmain = 10; | 275 | vmain = 10; |
273 | return; | 276 | return; |
274 | #endif | 277 | #endif |
275 | 278 | ||
276 | assert(PPPData::NumInitStrings > 0); | 279 | assert(PPPData::NumInitStrings > 0); |
277 | // first init string ? | 280 | // first init string ? |
278 | if(substate == -1) { | 281 | if(substate == -1) { |
279 | messg->setText(i18n("Initializing modem...")); | 282 | messg->setText(i18n("Initializing modem...")); |
280 | emit debugMessage(i18n("Initializing modem...")); | 283 | emit debugMessage(i18n("Initializing modem...")); |
281 | substate = 0; | 284 | substate = 0; |
282 | } | 285 | } |
283 | 286 | ||
284 | QString initStr = _ifaceppp->data()->modemInitStr(substate); | 287 | QString initStr = _ifaceppp->data()->modemInitStr(substate); |
285 | if (!initStr.isEmpty()) { | 288 | if (!initStr.isEmpty()) { |
286 | // send a carriage return and then wait a bit so that the modem will | 289 | // send a carriage return and then wait a bit so that the modem will |
287 | // let us issue commands. | 290 | // let us issue commands. |
288 | if(_ifaceppp->data()->modemPreInitDelay() > 0) { | 291 | if(_ifaceppp->data()->modemPreInitDelay() > 0) { |
289 | usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); | 292 | usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); |
290 | writeline(""); | 293 | writeline(""); |
291 | usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); | 294 | usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); |
292 | } | 295 | } |
293 | setExpect(_ifaceppp->data()->modemInitResp()); | 296 | setExpect(_ifaceppp->data()->modemInitResp()); |
294 | writeline(initStr); | 297 | writeline(initStr); |
295 | usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec | 298 | usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec |
296 | } | 299 | } |
297 | 300 | ||
298 | substate++; | 301 | substate++; |
299 | 302 | ||
300 | /* | 303 | /* |
301 | * FIXME after 3.0: Make it possible to disable ATS11 since it | 304 | * FIXME after 3.0: Make it possible to disable ATS11 since it |
302 | * seems to be incompatible with some ISDN adapters (e.g. DataBox | 305 | * seems to be incompatible with some ISDN adapters (e.g. DataBox |
303 | * Speed Dragon). Even better would be to detect this when doing | 306 | * Speed Dragon). Even better would be to detect this when doing |
304 | * a "Modem Query" | 307 | * a "Modem Query" |
305 | */ | 308 | */ |
306 | if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration()) | 309 | if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration()) |
307 | vmain = 5; | 310 | vmain = 5; |
308 | else | 311 | else |
@@ -943,384 +946,387 @@ void ConnectWidget::checkBuffers() { | |||
943 | if (loopend) { | 946 | if (loopend) { |
944 | loopend=false; | 947 | loopend=false; |
945 | } | 948 | } |
946 | } | 949 | } |
947 | 950 | ||
948 | if (loopend && readbuffer.contains(loopstr[loopnest])) { | 951 | if (loopend && readbuffer.contains(loopstr[loopnest])) { |
949 | expecting = false; | 952 | expecting = false; |
950 | readbuffer = ""; | 953 | readbuffer = ""; |
951 | QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); | 954 | QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); |
952 | emit debugMessage(ts); | 955 | emit debugMessage(ts); |
953 | scriptindex = loopstartindex[loopnest]; | 956 | scriptindex = loopstartindex[loopnest]; |
954 | loopend = false; | 957 | loopend = false; |
955 | loopnest++; | 958 | loopnest++; |
956 | } | 959 | } |
957 | // notify event loop if expected string was found | 960 | // notify event loop if expected string was found |
958 | if(!expecting) | 961 | if(!expecting) |
959 | timerEvent((QTimerEvent *) 0); | 962 | timerEvent((QTimerEvent *) 0); |
960 | } | 963 | } |
961 | } | 964 | } |
962 | 965 | ||
963 | 966 | ||
964 | 967 | ||
965 | void ConnectWidget::pause() { | 968 | void ConnectWidget::pause() { |
966 | pausing = false; | 969 | pausing = false; |
967 | pausetimer->stop(); | 970 | pausetimer->stop(); |
968 | } | 971 | } |
969 | 972 | ||
970 | 973 | ||
971 | void ConnectWidget::cancelbutton() { | 974 | void ConnectWidget::cancelbutton() { |
972 | _ifaceppp->modem()->stop(); | 975 | _ifaceppp->modem()->stop(); |
973 | killTimer(main_timer_ID); | 976 | killTimer(main_timer_ID); |
974 | timeout_timer->stop(); | 977 | timeout_timer->stop(); |
975 | if_timer->stop(); | 978 | if_timer->stop(); |
976 | if_timeout_timer->stop(); | 979 | if_timeout_timer->stop(); |
977 | 980 | ||
978 | // if (termwindow) { | 981 | // if (termwindow) { |
979 | // delete termwindow; | 982 | // delete termwindow; |
980 | // termwindow = 0L; | 983 | // termwindow = 0L; |
981 | // this->show(); | 984 | // this->show(); |
982 | // } | 985 | // } |
983 | 986 | ||
984 | messg->setText(i18n("One moment please...")); | 987 | messg->setText(i18n("One moment please...")); |
985 | 988 | ||
986 | // just to be sure | 989 | // just to be sure |
987 | _ifaceppp->modem()->removeSecret(AUTH_PAP); | 990 | _ifaceppp->modem()->removeSecret(AUTH_PAP); |
988 | _ifaceppp->modem()->removeSecret(AUTH_CHAP); | 991 | _ifaceppp->modem()->removeSecret(AUTH_CHAP); |
989 | removedns(_ifaceppp); | 992 | removedns(_ifaceppp); |
990 | 993 | ||
991 | qApp->processEvents(); | 994 | qApp->processEvents(); |
992 | 995 | ||
993 | _ifaceppp->modem()->killPPPDaemon(); | 996 | _ifaceppp->modem()->killPPPDaemon(); |
994 | _ifaceppp->modem()->hangup(); | 997 | _ifaceppp->modem()->hangup(); |
995 | 998 | ||
996 | 999 | ||
997 | // p_kppp->quit_b->setFocus(); | 1000 | // p_kppp->quit_b->setFocus(); |
998 | // p_kppp->show(); | 1001 | // p_kppp->show(); |
999 | // emit stopAccounting();// just to be sure | 1002 | // emit stopAccounting();// just to be sure |
1000 | // p_kppp->con_win->stopClock(); | 1003 | // p_kppp->con_win->stopClock(); |
1001 | _ifaceppp->modem()->closetty(); | 1004 | _ifaceppp->modem()->closetty(); |
1002 | _ifaceppp->modem()->unlockdevice(); | 1005 | _ifaceppp->modem()->unlockdevice(); |
1003 | 1006 | ||
1004 | //abort prompt window... | 1007 | //abort prompt window... |
1005 | if (prompt->isVisible()) { | 1008 | if (prompt->isVisible()) { |
1006 | prompt->hide(); | 1009 | prompt->hide(); |
1007 | } | 1010 | } |
1008 | prompt->setConsumed(); | 1011 | prompt->setConsumed(); |
1009 | 1012 | ||
1010 | messg->setText(tr("offline")); | 1013 | messg->setText(tr("offline")); |
1011 | } | 1014 | } |
1012 | 1015 | ||
1013 | 1016 | ||
1014 | void ConnectWidget::script_timed_out() { | 1017 | void ConnectWidget::script_timed_out() { |
1015 | if(vmain == 20) { // we are in the 'wait for the user to cancel' state | 1018 | if(vmain == 20) { // we are in the 'wait for the user to cancel' state |
1016 | timeout_timer->stop(); | 1019 | timeout_timer->stop(); |
1017 | emit stopAccounting(); | 1020 | emit stopAccounting(); |
1018 | // p_kppp->con_win->stopClock(); | 1021 | // p_kppp->con_win->stopClock(); |
1019 | return; | 1022 | return; |
1020 | } | 1023 | } |
1021 | 1024 | ||
1022 | if (prompt->isVisible()) | 1025 | if (prompt->isVisible()) |
1023 | prompt->hide(); | 1026 | prompt->hide(); |
1024 | 1027 | ||
1025 | prompt->setConsumed(); | 1028 | prompt->setConsumed(); |
1026 | messg->setText(i18n("Script timed out!")); | 1029 | messg->setText(i18n("Script timed out!")); |
1027 | _ifaceppp->modem()->hangup(); | 1030 | _ifaceppp->modem()->hangup(); |
1028 | emit stopAccounting(); | 1031 | emit stopAccounting(); |
1029 | // p_kppp->con_win->stopClock(); | 1032 | // p_kppp->con_win->stopClock(); |
1030 | 1033 | ||
1031 | vmain = 0; // let's try again. | 1034 | vmain = 0; // let's try again. |
1032 | substate = -1; | 1035 | substate = -1; |
1033 | } | 1036 | } |
1034 | 1037 | ||
1035 | 1038 | ||
1036 | void ConnectWidget::setScan(const QString &n) { | 1039 | void ConnectWidget::setScan(const QString &n) { |
1037 | scanning = true; | 1040 | scanning = true; |
1038 | scanstr = n; | 1041 | scanstr = n; |
1039 | scanbuffer = ""; | 1042 | scanbuffer = ""; |
1040 | 1043 | ||
1041 | QString ts = i18n("Scanning: %1").arg(n); | 1044 | QString ts = i18n("Scanning: %1").arg(n); |
1042 | emit debugMessage(ts); | 1045 | emit debugMessage(ts); |
1043 | } | 1046 | } |
1044 | 1047 | ||
1045 | 1048 | ||
1046 | void ConnectWidget::setExpect(const QString &n) { | 1049 | void ConnectWidget::setExpect(const QString &n) { |
1047 | expecting = true; | 1050 | expecting = true; |
1048 | expectstr = n; | 1051 | expectstr = n; |
1049 | 1052 | ||
1050 | QString ts = i18n("Expecting: %1").arg(n); | 1053 | QString ts = i18n("Expecting: %1").arg(n); |
1051 | ts.replace(QRegExp("\n"), "<LF>"); | 1054 | ts.replace(QRegExp("\n"), "<LF>"); |
1052 | emit debugMessage(ts); | 1055 | emit debugMessage(ts); |
1053 | 1056 | ||
1054 | // check if the expected string is in the read buffer already. | 1057 | // check if the expected string is in the read buffer already. |
1055 | checkBuffers(); | 1058 | checkBuffers(); |
1056 | } | 1059 | } |
1057 | 1060 | ||
1058 | 1061 | ||
1059 | void ConnectWidget::if_waiting_timed_out() { | 1062 | void ConnectWidget::if_waiting_timed_out() { |
1060 | if_timer->stop(); | 1063 | if_timer->stop(); |
1061 | if_timeout_timer->stop(); | 1064 | if_timeout_timer->stop(); |
1062 | qDebug("if_waiting_timed_out()"); | 1065 | qDebug("if_waiting_timed_out()"); |
1063 | 1066 | ||
1064 | _ifaceppp->data()->setpppdError(E_IF_TIMEOUT); | 1067 | _ifaceppp->data()->setpppdError(E_IF_TIMEOUT); |
1065 | 1068 | ||
1066 | // let's kill the stuck pppd | 1069 | // let's kill the stuck pppd |
1067 | _ifaceppp->modem()->killPPPDaemon(); | 1070 | _ifaceppp->modem()->killPPPDaemon(); |
1068 | 1071 | ||
1069 | emit stopAccounting(); | 1072 | emit stopAccounting(); |
1070 | // p_kppp->con_win->stopClock(); | 1073 | // p_kppp->con_win->stopClock(); |
1071 | 1074 | ||
1072 | 1075 | ||
1073 | // killing ppp will generate a SIGCHLD which will be caught in pppdie() | 1076 | // killing ppp will generate a SIGCHLD which will be caught in pppdie() |
1074 | // in main.cpp what happens next will depend on the boolean | 1077 | // in main.cpp what happens next will depend on the boolean |
1075 | // reconnect_on_disconnect which is set in ConnectWidget::init(); | 1078 | // reconnect_on_disconnect which is set in ConnectWidget::init(); |
1076 | } | 1079 | } |
1077 | 1080 | ||
1078 | void ConnectWidget::pppdDied() | 1081 | void ConnectWidget::pppdDied() |
1079 | { | 1082 | { |
1080 | if_timer->stop(); | 1083 | if_timer->stop(); |
1081 | if_timeout_timer->stop(); | 1084 | if_timeout_timer->stop(); |
1082 | } | 1085 | } |
1083 | 1086 | ||
1084 | void ConnectWidget::if_waiting_slot() { | 1087 | void ConnectWidget::if_waiting_slot() { |
1085 | messg->setText(i18n("Logging on to network...")); | 1088 | messg->setText(i18n("Logging on to network...")); |
1086 | 1089 | ||
1087 | // if(!stats->ifIsUp()) { | 1090 | // if(!stats->ifIsUp()) { |
1088 | 1091 | ||
1089 | // if(_ifaceppp->data()->pppdError() != 0) { | 1092 | // if(_ifaceppp->data()->pppdError() != 0) { |
1090 | // // we are here if pppd died immediately after starting it. | 1093 | // // we are here if pppd died immediately after starting it. |
1091 | // pppdDied(); | 1094 | // pppdDied(); |
1092 | // // error message handled in main.cpp: sigPPPDDied() | 1095 | // // error message handled in main.cpp: sigPPPDDied() |
1093 | // return; | 1096 | // return; |
1094 | // } | 1097 | // } |
1095 | 1098 | ||
1096 | // if_timer->start(100, TRUE); // single shot | 1099 | // if_timer->start(100, TRUE); // single shot |
1097 | // return; | 1100 | // return; |
1098 | // } | 1101 | // } |
1099 | 1102 | ||
1100 | // O.K the ppp interface is up and running | 1103 | // O.K the ppp interface is up and running |
1101 | // give it a few time to come up completly (0.2 seconds) | 1104 | // give it a few time to come up completly (0.2 seconds) |
1102 | if_timeout_timer->stop(); | 1105 | if_timeout_timer->stop(); |
1103 | if_timer->stop(); | 1106 | if_timer->stop(); |
1104 | usleep(200000); | 1107 | usleep(200000); |
1105 | 1108 | ||
1106 | if(_ifaceppp->data()->autoDNS()) | 1109 | if(_ifaceppp->data()->autoDNS()) |
1107 | addpeerdns( _ifaceppp ); | 1110 | addpeerdns( _ifaceppp ); |
1108 | 1111 | ||
1109 | // Close the debugging window. If we are connected, we | 1112 | // Close the debugging window. If we are connected, we |
1110 | // are not really interested in debug output | 1113 | // are not really interested in debug output |
1111 | emit closeDebugWindow(); | 1114 | emit closeDebugWindow(); |
1112 | // p_kppp->statdlg->take_stats(); // start taking ppp statistics | 1115 | // p_kppp->statdlg->take_stats(); // start taking ppp statistics |
1113 | auto_hostname(_ifaceppp); | 1116 | auto_hostname(_ifaceppp); |
1114 | 1117 | ||
1115 | if(!_ifaceppp->data()->command_on_connect().isEmpty()) { | 1118 | if(!_ifaceppp->data()->command_on_connect().isEmpty()) { |
1116 | messg->setText(i18n("Running startup command...")); | 1119 | messg->setText(i18n("Running startup command...")); |
1117 | 1120 | ||
1118 | // make sure that we don't get any async errors | 1121 | // make sure that we don't get any async errors |
1119 | qApp->flushX(); | 1122 | qApp->flushX(); |
1120 | execute_command(_ifaceppp->data()->command_on_connect()); | 1123 | execute_command(_ifaceppp->data()->command_on_connect()); |
1121 | messg->setText(i18n("Done")); | 1124 | messg->setText(i18n("Done")); |
1122 | } | 1125 | } |
1123 | 1126 | ||
1124 | // remove the authentication file | 1127 | // remove the authentication file |
1125 | _ifaceppp->modem()->removeSecret(AUTH_PAP); | 1128 | _ifaceppp->modem()->removeSecret(AUTH_PAP); |
1126 | _ifaceppp->modem()->removeSecret(AUTH_CHAP); | 1129 | _ifaceppp->modem()->removeSecret(AUTH_CHAP); |
1127 | 1130 | ||
1128 | emit debugMessage(i18n("Done")); | 1131 | emit debugMessage(i18n("Done")); |
1129 | set_con_speed_string(); | 1132 | set_con_speed_string(); |
1130 | 1133 | ||
1131 | // p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed); | 1134 | // p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed); |
1132 | this->hide(); | 1135 | this->hide(); |
1133 | messg->setText(""); | 1136 | messg->setText(""); |
1134 | 1137 | ||
1138 | _ifaceppp->setStatus( true ); | ||
1139 | // emit _ifaceppp->updateInterface(_ifaceppp); | ||
1140 | |||
1135 | // prepare the con_win so as to have the right size for | 1141 | // prepare the con_win so as to have the right size for |
1136 | // accounting / non-accounting mode | 1142 | // accounting / non-accounting mode |
1137 | // if(p_kppp->acct != 0) | 1143 | // if(p_kppp->acct != 0) |
1138 | // p_kppp->con_win->accounting(p_kppp->acct->running()); | 1144 | // p_kppp->con_win->accounting(p_kppp->acct->running()); |
1139 | // else | 1145 | // else |
1140 | // p_kppp->con_win->accounting(false); | 1146 | // p_kppp->con_win->accounting(false); |
1141 | 1147 | ||
1142 | // if (_ifaceppp->data()->get_dock_into_panel()) { | 1148 | // if (_ifaceppp->data()->get_dock_into_panel()) { |
1143 | // // DockWidget::dock_widget->show(); | 1149 | // // DockWidget::dock_widget->show(); |
1144 | // // DockWidget::dock_widget->take_stats(); | 1150 | // // DockWidget::dock_widget->take_stats(); |
1145 | // // this->hide(); | 1151 | // // this->hide(); |
1146 | // } | 1152 | // } |
1147 | // else { | 1153 | // else { |
1148 | // // p_kppp->con_win->show(); | 1154 | // // p_kppp->con_win->show(); |
1149 | 1155 | ||
1150 | // if(_ifaceppp->data()->get_iconify_on_connect()) { | 1156 | // if(_ifaceppp->data()->get_iconify_on_connect()) { |
1151 | // // p_kppp->con_win->showMinimized(); | 1157 | // // p_kppp->con_win->showMinimized(); |
1152 | // } | 1158 | // } |
1153 | // } | 1159 | // } |
1154 | 1160 | ||
1155 | _ifaceppp->modem()->closetty(); | 1161 | _ifaceppp->modem()->closetty(); |
1156 | } | 1162 | } |
1157 | 1163 | ||
1158 | 1164 | ||
1159 | bool ConnectWidget::execppp() { | 1165 | bool ConnectWidget::execppp() { |
1160 | QString command; | 1166 | QString command; |
1161 | 1167 | ||
1162 | command = "pppd"; | 1168 | command = "pppd"; |
1163 | 1169 | ||
1164 | // as of version 2.3.6 pppd falls back to the real user rights when | 1170 | // as of version 2.3.6 pppd falls back to the real user rights when |
1165 | // opening a device given in a command line. To avoid permission conflicts | 1171 | // opening a device given in a command line. To avoid permission conflicts |
1166 | // we'll simply leave this argument away. pppd will then use the default tty | 1172 | // we'll simply leave this argument away. pppd will then use the default tty |
1167 | // which is the serial port we connected stdin/stdout to in opener.cpp. | 1173 | // which is the serial port we connected stdin/stdout to in opener.cpp. |
1168 | // command += " "; | 1174 | // command += " "; |
1169 | // command += _ifaceppp->data()->modemDevice(); | 1175 | // command += _ifaceppp->data()->modemDevice(); |
1170 | 1176 | ||
1171 | command += " " + _ifaceppp->data()->speed(); | 1177 | command += " " + _ifaceppp->data()->speed(); |
1172 | 1178 | ||
1173 | command += " -detach"; | 1179 | command += " -detach"; |
1174 | 1180 | ||
1175 | if(_ifaceppp->data()->ipaddr() != "0.0.0.0" || | 1181 | if(_ifaceppp->data()->ipaddr() != "0.0.0.0" || |
1176 | _ifaceppp->data()->gateway() != "0.0.0.0") { | 1182 | _ifaceppp->data()->gateway() != "0.0.0.0") { |
1177 | if(_ifaceppp->data()->ipaddr() != "0.0.0.0") { | 1183 | if(_ifaceppp->data()->ipaddr() != "0.0.0.0") { |
1178 | command += " "; | 1184 | command += " "; |
1179 | command += _ifaceppp->data()->ipaddr(); | 1185 | command += _ifaceppp->data()->ipaddr(); |
1180 | command += ":"; | 1186 | command += ":"; |
1181 | } | 1187 | } |
1182 | else { | 1188 | else { |
1183 | command += " "; | 1189 | command += " "; |
1184 | command += ":"; | 1190 | command += ":"; |
1185 | } | 1191 | } |
1186 | 1192 | ||
1187 | if(_ifaceppp->data()->gateway() != "0.0.0.0") | 1193 | if(_ifaceppp->data()->gateway() != "0.0.0.0") |
1188 | command += _ifaceppp->data()->gateway(); | 1194 | command += _ifaceppp->data()->gateway(); |
1189 | } | 1195 | } |
1190 | 1196 | ||
1191 | if(_ifaceppp->data()->subnetmask() != "0.0.0.0") | 1197 | if(_ifaceppp->data()->subnetmask() != "0.0.0.0") |
1192 | command += " netmask " + _ifaceppp->data()->subnetmask(); | 1198 | command += " netmask " + _ifaceppp->data()->subnetmask(); |
1193 | 1199 | ||
1194 | if(_ifaceppp->data()->flowcontrol() != "None") { | 1200 | if(_ifaceppp->data()->flowcontrol() != "None") { |
1195 | if(_ifaceppp->data()->flowcontrol() == "CRTSCTS") | 1201 | if(_ifaceppp->data()->flowcontrol() == "CRTSCTS") |
1196 | command += " crtscts"; | 1202 | command += " crtscts"; |
1197 | else | 1203 | else |
1198 | command += " xonxoff"; | 1204 | command += " xonxoff"; |
1199 | } | 1205 | } |
1200 | 1206 | ||
1201 | if(_ifaceppp->data()->defaultroute()) | 1207 | if(_ifaceppp->data()->defaultroute()) |
1202 | command += " defaultroute"; | 1208 | command += " defaultroute"; |
1203 | 1209 | ||
1204 | if(_ifaceppp->data()->autoDNS()) | 1210 | if(_ifaceppp->data()->autoDNS()) |
1205 | command += " usepeerdns"; | 1211 | command += " usepeerdns"; |
1206 | 1212 | ||
1207 | QStringList &arglist = _ifaceppp->data()->pppdArgument(); | 1213 | QStringList &arglist = _ifaceppp->data()->pppdArgument(); |
1208 | for ( QStringList::Iterator it = arglist.begin(); | 1214 | for ( QStringList::Iterator it = arglist.begin(); |
1209 | it != arglist.end(); | 1215 | it != arglist.end(); |
1210 | ++it ) | 1216 | ++it ) |
1211 | { | 1217 | { |
1212 | command += " " + *it; | 1218 | command += " " + *it; |
1213 | } | 1219 | } |
1214 | 1220 | ||
1215 | // PAP settings | 1221 | // PAP settings |
1216 | if(_ifaceppp->data()->authMethod() == AUTH_PAP) { | 1222 | if(_ifaceppp->data()->authMethod() == AUTH_PAP) { |
1217 | command += " -chap user "; | 1223 | command += " -chap user "; |
1218 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; | 1224 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; |
1219 | } | 1225 | } |
1220 | 1226 | ||
1221 | // CHAP settings | 1227 | // CHAP settings |
1222 | if(_ifaceppp->data()->authMethod() == AUTH_CHAP) { | 1228 | if(_ifaceppp->data()->authMethod() == AUTH_CHAP) { |
1223 | command += " -pap user "; | 1229 | command += " -pap user "; |
1224 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; | 1230 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; |
1225 | } | 1231 | } |
1226 | 1232 | ||
1227 | // PAP/CHAP settings | 1233 | // PAP/CHAP settings |
1228 | if(_ifaceppp->data()->authMethod() == AUTH_PAPCHAP) { | 1234 | if(_ifaceppp->data()->authMethod() == AUTH_PAPCHAP) { |
1229 | command += " user "; | 1235 | command += " user "; |
1230 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; | 1236 | command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; |
1231 | } | 1237 | } |
1232 | 1238 | ||
1233 | // check for debug | 1239 | // check for debug |
1234 | if(_ifaceppp->data()->getPPPDebug()) | 1240 | if(_ifaceppp->data()->getPPPDebug()) |
1235 | command += " debug"; | 1241 | command += " debug"; |
1236 | 1242 | ||
1237 | if (command.length() > MAX_CMDLEN) { | 1243 | if (command.length() > MAX_CMDLEN) { |
1238 | QMessageBox::critical(this, "error", i18n( | 1244 | QMessageBox::critical(this, "error", i18n( |
1239 | "pppd command + command-line arguments exceed " | 1245 | "pppd command + command-line arguments exceed " |
1240 | "2024 characters in length." | 1246 | "2024 characters in length." |
1241 | )); | 1247 | )); |
1242 | 1248 | ||
1243 | return false; // nonsensically long command which would bust my buffer buf. | 1249 | return false; // nonsensically long command which would bust my buffer buf. |
1244 | } | 1250 | } |
1245 | 1251 | ||
1246 | qApp->flushX(); | 1252 | qApp->flushX(); |
1247 | 1253 | ||
1248 | return _ifaceppp->modem()->execPPPDaemon(command); | 1254 | return _ifaceppp->modem()->execPPPDaemon(command); |
1249 | } | 1255 | } |
1250 | 1256 | ||
1251 | 1257 | ||
1252 | void ConnectWidget::closeEvent( QCloseEvent *e ) { | 1258 | void ConnectWidget::closeEvent( QCloseEvent *e ) { |
1253 | e->ignore(); | 1259 | e->ignore(); |
1254 | emit cancelbutton(); | 1260 | emit cancelbutton(); |
1255 | } | 1261 | } |
1256 | 1262 | ||
1257 | 1263 | ||
1258 | void ConnectWidget::setMsg(const QString &msg) { | 1264 | void ConnectWidget::setMsg(const QString &msg) { |
1259 | messg->setText(msg); | 1265 | messg->setText(msg); |
1260 | } | 1266 | } |
1261 | 1267 | ||
1262 | void ConnectWidget::writeline(const QString &s) { | 1268 | void ConnectWidget::writeline(const QString &s) { |
1263 | _ifaceppp->modem()->writeLine(s.local8Bit()); | 1269 | _ifaceppp->modem()->writeLine(s.local8Bit()); |
1264 | } | 1270 | } |
1265 | 1271 | ||
1266 | // Set the hostname and domain from DNS Server | 1272 | // Set the hostname and domain from DNS Server |
1267 | void auto_hostname(InterfacePPP *_ifaceppp) { | 1273 | void auto_hostname(InterfacePPP *_ifaceppp) { |
1268 | struct in_addr local_ip; | 1274 | struct in_addr local_ip; |
1269 | struct hostent *hostname_entry; | 1275 | struct hostent *hostname_entry; |
1270 | QString new_hostname; | 1276 | QString new_hostname; |
1271 | int dot; | 1277 | int dot; |
1272 | char tmp_str[100]; // buffer overflow safe | 1278 | char tmp_str[100]; // buffer overflow safe |
1273 | 1279 | ||
1274 | gethostname(tmp_str, sizeof(tmp_str)); | 1280 | gethostname(tmp_str, sizeof(tmp_str)); |
1275 | tmp_str[sizeof(tmp_str)-1]=0; // panic | 1281 | tmp_str[sizeof(tmp_str)-1]=0; // panic |
1276 | old_hostname=tmp_str; // copy to QString | 1282 | old_hostname=tmp_str; // copy to QString |
1277 | 1283 | ||
1278 | // if (!p_kppp->stats->local_ip_address.isEmpty() && _ifaceppp->data()->autoname()) { | 1284 | // if (!p_kppp->stats->local_ip_address.isEmpty() && _ifaceppp->data()->autoname()) { |
1279 | if ( _ifaceppp->data()->autoname()) { | 1285 | if ( _ifaceppp->data()->autoname()) { |
1280 | // local_ip.s_addr=inet_addr(p_kppp->stats->local_ip_address.ascii()); | 1286 | // local_ip.s_addr=inet_addr(p_kppp->stats->local_ip_address.ascii()); |
1281 | hostname_entry=gethostbyaddr((const char *)&local_ip,sizeof(in_addr),AF_INET); | 1287 | hostname_entry=gethostbyaddr((const char *)&local_ip,sizeof(in_addr),AF_INET); |
1282 | 1288 | ||
1283 | if (hostname_entry != 0L) { | 1289 | if (hostname_entry != 0L) { |
1284 | new_hostname=hostname_entry->h_name; | 1290 | new_hostname=hostname_entry->h_name; |
1285 | dot=new_hostname.find('.'); | 1291 | dot=new_hostname.find('.'); |
1286 | new_hostname=new_hostname.remove(dot,new_hostname.length()-dot); | 1292 | new_hostname=new_hostname.remove(dot,new_hostname.length()-dot); |
1287 | _ifaceppp->modem()->setHostname(new_hostname); | 1293 | _ifaceppp->modem()->setHostname(new_hostname); |
1288 | modified_hostname = TRUE; | 1294 | modified_hostname = TRUE; |
1289 | 1295 | ||
1290 | new_hostname=hostname_entry->h_name; | 1296 | new_hostname=hostname_entry->h_name; |
1291 | new_hostname.remove(0,dot+1); | 1297 | new_hostname.remove(0,dot+1); |
1292 | 1298 | ||
1293 | add_domain(new_hostname, _ifaceppp); | 1299 | add_domain(new_hostname, _ifaceppp); |
1294 | } | 1300 | } |
1295 | } | 1301 | } |
1296 | 1302 | ||
1297 | } | 1303 | } |
1298 | 1304 | ||
1299 | // Replace the DNS domain entry in the /etc/resolv.conf file and | 1305 | // Replace the DNS domain entry in the /etc/resolv.conf file and |
1300 | // disable the nameserver entries if option is enabled | 1306 | // disable the nameserver entries if option is enabled |
1301 | void add_domain(const QString &domain, InterfacePPP *_ifaceppp) { | 1307 | void add_domain(const QString &domain, InterfacePPP *_ifaceppp) { |
1302 | 1308 | ||
1303 | int fd; | 1309 | int fd; |
1304 | char c; | 1310 | char c; |
1305 | QString resolv[MAX_RESOLVCONF_LINES]; | 1311 | QString resolv[MAX_RESOLVCONF_LINES]; |
1306 | 1312 | ||
1307 | if (domain.isEmpty()) | 1313 | if (domain.isEmpty()) |
1308 | return; | 1314 | return; |
1309 | 1315 | ||
1310 | if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) { | 1316 | if((fd = _ifaceppp->modem()->openResolv(O_RDONLY)) >= 0) { |
1311 | 1317 | ||
1312 | int i=0; | 1318 | int i=0; |
1313 | while((read(fd, &c, 1) == 1) && (i < MAX_RESOLVCONF_LINES)) { | 1319 | while((read(fd, &c, 1) == 1) && (i < MAX_RESOLVCONF_LINES)) { |
1314 | if(c == '\n') { | 1320 | if(c == '\n') { |
1315 | i++; | 1321 | i++; |
1316 | } | 1322 | } |
1317 | else { | 1323 | else { |
1318 | resolv[i] += c; | 1324 | resolv[i] += c; |
1319 | } | 1325 | } |
1320 | } | 1326 | } |
1321 | close(fd); | 1327 | close(fd); |
1322 | if ((c != '\n') && (i < MAX_RESOLVCONF_LINES)) i++; | 1328 | if ((c != '\n') && (i < MAX_RESOLVCONF_LINES)) i++; |
1323 | 1329 | ||
1324 | if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) { | 1330 | if((fd = _ifaceppp->modem()->openResolv(O_WRONLY|O_TRUNC)) >= 0) { |
1325 | QCString tmp = "domain " + domain.local8Bit() + | 1331 | QCString tmp = "domain " + domain.local8Bit() + |
1326 | " \t\t#kppp temp entry\n"; | 1332 | " \t\t#kppp temp entry\n"; |