3 * kPPP: A pppd front end for the KDE project
7 * (c) 1998 Mario Weilguni <mweilguni@kde.org>
9 * Copyright (C) 1997 Bernd Johannes Wuebben
10 * wuebben@math.cornell.edu
13 * Copyright (C) 1997 Jay Painter
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Library General Public
17 * License as published by the Free Software Foundation; either
18 * version 2 of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Library General Public License for more details.
25 * You should have received a copy of the GNU Library General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <qpushbutton.h>
34 #include <QVBoxLayout>
47 #include <kmessagebox.h>
50 #include "requester.h"
54 int PPPL_MakeLog(QStringList
&list
) {
56 char buffer
[1024], *p
;
60 fd
= Requester::rq
->openSysLog();
62 list
.append(i18n("Cannot open any of the following logfiles:"));
63 const char * const * logFile
= &kppp_syslog
[0];
65 list
.append(*logFile
);
71 FILE *f
= fdopen(fd
, "r");
72 while(fgets(buffer
, sizeof(buffer
), f
) != 0) {
74 p
= (char *)strstr(buffer
, "pppd[");
77 pidp
= p
+= strlen("pppd[");
78 while(*p
&& isdigit(*p
))
83 /* find out pid of pppd */
84 sscanf(pidp
, "%d", &newpid
);
89 if(buffer
[strlen(buffer
)-1] == '\n')
90 buffer
[strlen(buffer
)-1] = '\0';
98 /* clear security related info */
100 const char *keyword
[] = {"name = \"",
105 for ( QStringList::Iterator it
= list
.begin(); it
!= list
.end(); ++it
)
107 QByteArray tmp
= (*it
).toLocal8Bit();
108 for(int j
= 0; keyword
[j
] != 0; j
++) {
111 if( (p
= (char *)strstr(tmp
.data(), keyword
[j
])) != 0) {
112 p
+= strlen(keyword
[j
]);
113 while(*p
&& *p
!= '"')
124 void PPPL_AnalyseLog(QStringList
&list
, QStringList
&result
) {
126 const char *rmsg
= "Remote message: ";
130 // setup the analysis database
135 {"Receive serial link is not 8-bit clean",
136 I18N_NOOP("You have launched pppd before the remote server " \
137 "was ready to establish a PPP connection.\n"
138 "Please use the terminal-based login to verify") },
140 {"Serial line is looped back",
141 I18N_NOOP("You have not started the PPP software on the peer system.") },
143 {"AP authentication failed",
144 I18N_NOOP("Check that you supplied the correct username and password.")} ,
147 I18N_NOOP("You should not pass 'lock' as an argument to pppd. "
148 "Check /etc/ppp/options and ~/.ppprc") },
150 {"CP: timeout sending",
151 I18N_NOOP("The remote system does not seem to answer to\n"
152 "configuration request. Contact your provider.") },
154 {"unrecognized option",
155 I18N_NOOP("You have passed an invalid option to pppd. See 'man pppd' "
156 "for a complete list of valid arguments.") },
163 // scan the log for keywords and try to offer any help
164 for ( QStringList::Iterator it
= list
.begin(); it
!= list
.end(); ++it
)
166 // look for remote message
167 int pos
= (*it
).indexOf(rmsg
);
171 str
.remove(0, pos
+ strlen(rmsg
));
173 msg
= i18n("Notice that the remote system has sent the following"
174 " message:\n\"%1\"\nThis may give you a hint why the"
175 " the connection has failed.", str
);
180 // check in the hint database
181 for(uint k
= 0; hints
[k
].regexp
!= 0; k
++) {
182 QRegExp
rx(hints
[k
].regexp
);
185 result
.append(i18n(hints
[k
].answer
));
191 if (result
.isEmpty())
192 result
.append(i18n("Unable to provide help."));
196 void PPPL_ShowLog() {
197 QStringList sl
, result
;
201 bool foundConnect
= false;
202 bool foundLCP
= gpppdata
.getPPPDebug();
203 QString lcp
= QLatin1String("[LCP");
204 QString conn
= QLatin1String("Connect:");
205 QStringList::ConstIterator it
= sl
.begin();
206 for( ; it
!= sl
.end(); it
++) {
207 if((*it
).indexOf(lcp
) >= 0) {
211 if((*it
).contains(conn
))
214 if(foundConnect
&& !foundLCP
) {
215 int result
= KMessageBox::warningYesNo(0,
216 i18n("KPPP could not prepare a PPP log. It is very likely "
217 "that pppd was started without the \"debug\" option.\n"
218 "Without this option it's difficult to find out PPP "
219 "problems, so you should turn on the debug option.\n"
220 "Shall I turn it on now?"), QString(), KGuiItem(i18n("Restart pppd")), KGuiItem(i18n("Do Not Restart")));
222 if(result
== KMessageBox::Yes
) {
223 gpppdata
.setPPPDebug(true);
224 KMessageBox::information(0,
225 i18n("The \"debug\" option has been added. You "
226 "should now try to reconnect. If that fails "
227 "again, you will get a PPP log that may help "
228 "you to track down the connection problem."));
235 PPPL_AnalyseLog(sl
, result
);
237 KDialog
*dlg
= new KDialog();
238 dlg
->setButtons(KDialog::Close
| KDialog::Ok
);
239 dlg
->setWindowTitle(i18n("PPP Log"));
240 dlg
->setButtonText(KDialog::Ok
,i18n("Write to File"));
241 QVBoxLayout
*tl
= new QVBoxLayout(dlg
);
244 QTextEdit
*edit
= new QTextEdit(dlg
);
245 edit
->setReadOnly(true);
246 QLabel
*label
= new QLabel(i18n("kppp's diagnosis (just guessing):"), dlg
);
247 QTextEdit
*diagnosis
= new QTextEdit(dlg
);
248 diagnosis
->setReadOnly(true);
249 edit
->setMinimumSize(600, 250);
250 label
->setMinimumSize(600, 15);
251 diagnosis
->setMinimumSize(600, 60);
253 tl
->addWidget(edit
, 1);
254 tl
->addWidget(label
);
255 tl
->addWidget(diagnosis
, 1);
256 dlg
->setFixedSize(dlg
->sizeHint());
258 for(int i
= 0; i
< sl
.count(); i
++)
259 edit
->append(sl
.at(i
));
260 for(int i
= 0; i
< result
.count(); i
++)
261 diagnosis
->append(result
.at(i
));
264 QDir d
= QDir::home();
265 QString s
= d
.absolutePath() + "/PPP-logfile";
266 int old_umask
= umask(0077);
268 FILE *f
= fopen(QFile::encodeName(s
), "w");
269 for(int i
= 0; i
< sl
.count(); i
++)
270 fprintf(f
, "%s\n", sl
.at(i
).toLocal8Bit().data());
274 QString msg
= i18n("The PPP log has been saved\nas \"%1\".\n\nIf you want to send a bug report, or have\nproblems connecting to the Internet, please\nattach this file. It will help the maintainers\nto find the bug and to improve KPPP", s
);
275 KMessageBox::information(0, msg
);