1/* -*- C++ -*-
2 *
3 * kPPP: A pppd front end for the KDE project
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997 Bernd Johannes Wuebben
8 * wuebben@math.cornell.edu
9 *
10 * based on EzPPP:
11 * Copyright (C) 1997 Jay Painter
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
22 *
23 * You should have received a copy of the GNU Library General Public
24 * License along with this program; if not, write to the Free
25 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28#ifndef _PPPDATA_H_
29#define _PPPDATA_H_
30
31#include <unistd.h>
32#include <sys/types.h>
33
34#include <qstring.h>
35#include <qstringlist.h>
36#include <qcolor.h>
37#include <ksharedconfig.h>
38
39#include "kpppconfig.h"
40
41
42// string lengths
43
44#define PATH_SIZE 120
45#define MODEMSTR_SIZE 80
46#define ACCNAME_SIZE 50
47#define PHONENUMBER_SIZE 60
48#define COMMAND_SIZE 255
49#define IPADDR_SIZE 15
50#define DOMAIN_SIZE 50
51#define TIMEOUT_SIZE 60
52
53//
54// keys for config file
55//
56
57// groups
58#define GENERAL_GRP "General"
59#define MODEM_GRP "Modem"
60#define ACCOUNT_GRP "Account"
61#define GRAPH_GRP "Graph"
62#define WINPOS_GRP "WindowPosition"
63
64// general
65#define DEFAULTACCOUNT_KEY "DefaultAccount"
66#define DEFAULTMODEM_KEY "DefaultModem"
67#define PPPDVERSION_KEY "pppdVersion"
68#define PPPDTIMEOUT_KEY "pppdTimeout"
69#define SHOWCLOCK_KEY "ShowClock"
70#define SHOWLOGWIN_KEY "ShowLogWindow"
71#define AUTOREDIAL_KEY "AutomaticRedial"
72#define DISCONNECT_KEY "DisconnectOnXServerExit"
73#define QUITONDISCONNECT_KEY "QuitOnDisconnect"
74#define NUMACCOUNTS_KEY "NumberOfAccounts"
75#define NUMMODEMS_KEY "NumberOfModems"
76#define REDIALONNOCARR_KEY "RedialOnNoCarrier"
77#define ID_KEY "ID"
78
79// modem
80#define MOD_NAME_KEY "Name"
81#define MODEMDEV_KEY "Device"
82#define LOCKFILE_KEY "UseLockFile"
83#define FLOWCONTROL_KEY "FlowControl"
84#define SPEED_KEY "Speed"
85#define TIMEOUT_KEY "Timeout"
86#define TONEDURATION_KEY "ToneDuration"
87#define BUSYWAIT_KEY "BusyWait"
88#define INITSTR_KEY "InitString"
89#define INITRESP_KEY "InitResponse"
90#define PREINITDELAY_KEY "PreInitDelay"
91#define INITDELAY_KEY "InitDelay"
92#define NODTDETECT_KEY "NoDialToneDetection"
93#define DIALTONEWAIT_KEY "WaitForDialTone"
94#define DIALSTR_KEY "DialString"
95#define CONNECTRESP_KEY "ConnectResponse"
96#define BUSYRESP_KEY "BusyResponse"
97#define NOCARRIERRESP_KEY "NoCarrierResponse"
98#define NODIALTONERESP_KEY "NoDialToneResp"
99#define HANGUPSTR_KEY "HangupString"
100#define HANGUPRESP_KEY "HangUpResponse"
101#define DLPRESP_KEY "DLPResponse"
102#define ANSWERSTR_KEY "AnswerString"
103#define RINGRESP_KEY "RingResponse"
104#define ANSWERRESP_KEY "AnswerResponse"
105#define ENTER_KEY "Enter"
106#define ESCAPESTR_KEY "EscapeString"
107#define ESCAPERESP_KEY "EscapeResponse"
108#define ESCAPEGUARDTIME_KEY "EscapeGuardTime"
109#define USECDLINE_KEY "UseCDLine"
110#define VOLUME_HIGH "VolumeHigh"
111#define VOLUME_MEDIUM "VolumeMedium"
112#define VOLUME_OFF "VolumeOff"
113#define VOLUME_KEY "Volume"
114
115// account
116#define ACC_NAME_KEY "Name"
117#define PHONENUMBER_KEY "Phonenumber"
118#define DIAL_PREFIX_KEY "DialPrefix"
119#define AUTH_KEY "Authentication"
120#define STORED_PASSWORD_KEY "Password"
121#define STORED_USERNAME_KEY "Username"
122#define STORE_PASSWORD_KEY "StorePassword"
123#define CALLBACK_TYPE_KEY "CallbackType"
124#define CALLBACK_PHONE_KEY "CallbackPhone"
125#define BEFORE_CONNECT_KEY "BeforeConnect"
126#define COMMAND_KEY "Command"
127#define DISCONNECT_COMMAND_KEY "DisconnectCommand"
128#define BEFORE_DISCONNECT_KEY "BeforeDisconnect"
129#define IPADDR_KEY "IPAddr"
130#define SUBNETMASK_KEY "SubnetMask"
131#define ACCTENABLED_KEY "AccountingEnabled"
132#define VOLACCTENABLED_KEY "VolumeAccountingEnabled"
133#define ACCTFILE_KEY "AccountingFile"
134#define AUTONAME_KEY "AutoName"
135#define GATEWAY_KEY "Gateway"
136#define DEFAULTROUTE_KEY "DefaultRoute"
137#define DOMAIN_KEY "Domain"
138#define DNS_KEY "DNS"
139#define AUTODNS_KEY "AutoDNS"
140#define EXDNSDISABLED_KEY "ExDNSDisabled"
141#define SCRIPTCOM_KEY "ScriptCommands"
142#define SCRIPTARG_KEY "ScriptArguments"
143#define PPPDARG_KEY "pppdArguments"
144#define PPP_DEBUG_OPTION "PPPDebug"
145#define ICONIFY_ON_CONNECT_KEY "iconifyOnConnect"
146#define DOCKING_KEY "DockIntoPanel"
147#define TOTALCOSTS_KEY "TotalCosts"
148#define TOTALBYTES_KEY "TotalBytes"
149
150// graph colors
151#define GENABLED "Enabled"
152#define GCOLOR_BG "Background"
153#define GCOLOR_TEXT "Text"
154#define GCOLOR_IN "InBytes"
155#define GCOLOR_OUT "OutBytes"
156
157// pppd errors
158#define E_IF_TIMEOUT 1
159#define E_PPPD_DIED 2
160#define E_CBCP_WAIT 14
161
162// window position
163#define WINPOS_CONWIN_X "WindowPositionConWinX"
164#define WINPOS_CONWIN_Y "WindowPositionConWinY"
165#define WINPOS_STATWIN_X "WindowPositionStatWinX"
166#define WINPOS_STATWIN_Y "WindowPositionStatWinY"
167
168class PPPData {
169public:
170 PPPData();
171 ~PPPData() {}
172
173 enum { NumInitStrings = 2 };
174
175 // general functions
176 bool open();
177 void save();
178 void cancel();
179 int access() const; // read/write access
180
181 // function to read/write date to configuration file
182 QString readConfig(const QString &, const QString &, const QString &);
183 int readNumConfig(const QString &, const QString &, int);
184 bool readListConfig(const QString &, const QString &, QStringList &);
185 void writeConfig(const QString &, const QString &, const QString &);
186 void writeConfig(const QString &, const QString &, int);
187 void writeListConfig(const QString &, const QString &, QStringList &);
188
189 // return the current account group
190 QString currentAccountGroup() { return caccountgroup; }
191 // return the current modem group
192 QString currentModemGroup() { return cmodemgroup; }
193
194 // functions to set/get general kppp info
195 QString password() const;
196 void setPassword(const QString &);
197
198 const QString defaultAccount();
199 void setDefaultAccount(const QString &);
200
201 const QString defaultModem();
202 void setDefaultModem(const QString &);
203
204 void set_xserver_exit_disconnect(bool set);
205 bool get_xserver_exit_disconnect();
206
207 void set_redial_on_nocarrier(bool set);
208 bool get_redial_on_nocarrier();
209
210 void setPPPDebug(bool set);
211 bool getPPPDebug();
212
213 void set_quit_on_disconnect(bool);
214 bool quit_on_disconnect();
215
216 void set_show_clock_on_caption(bool set);
217 bool get_show_clock_on_caption();
218
219 void set_show_log_window(bool set);
220 bool get_show_log_window();
221
222 void set_automatic_redial(bool set);
223 bool automatic_redial();
224
225 void set_iconify_on_connect(bool set);
226 bool get_iconify_on_connect();
227
228 void set_dock_into_panel(bool set);
229 bool get_dock_into_panel();
230
231 const QString enter();
232 void setEnter(const QString &);
233
234 QString pppdVersion();
235 bool pppdVersionMin(int ver, int mod, int patch);
236
237 int pppdTimeout();
238 void setpppdTimeout(int);
239
240 // functions to set/get account information
241 int modemCount() const;
242 bool setModem(const QString &);
243 bool setModemByIndex(int);
244
245 bool isUniqueModname(const QString &);
246
247 bool deleteModem();
248 bool deleteModem(const QString &);
249 int newmodem();
250 int copymodem(int i);
251
252 const QString modname();
253 void setModname(const QString &);
254
255
256 int busyWait();
257 void setbusyWait(int);
258
259 bool modemLockFile();
260 void setModemLockFile(bool set);
261
262 int modemEscapeGuardTime();
263 void setModemEscapeGuardTime(int i);
264
265 void setModemEscapeStr(const QString &);
266 const QString modemEscapeStr();
267
268 void setModemEscapeResp(const QString &);
269 const QString modemEscapeResp();
270
271 const QString modemDevice();
272 void setModemDevice(const QString &);
273
274 QString flowcontrol();
275 void setFlowcontrol(const QString &);
276
277 int modemTimeout();
278 void setModemTimeout(int);
279
280 int modemToneDuration();
281 void setModemToneDuration(int);
282
283 QString volumeInitString();
284 int volume();
285 void setVolume(int);
286
287 int waitForDialTone();
288 void setWaitForDialTone(int i);
289
290 // modem command strings/responses
291 const QString modemInitStr(int i);
292 void setModemInitStr(int i, const QString &);
293
294 const QString modemInitResp();
295 void setModemInitResp(const QString &);
296
297 int modemPreInitDelay();
298 void setModemPreInitDelay(int);
299
300 int modemInitDelay();
301 void setModemInitDelay(int);
302
303 QString modemNoDialToneDetectionStr();
304 void setModemNoDialToneDetectionStr(const QString &);
305
306 const QString modemDialStr();
307 void setModemDialStr(const QString &);
308
309 const QString modemConnectResp();
310 void setModemConnectResp(const QString &);
311
312 const QString modemBusyResp();
313 void setModemBusyResp(const QString &);
314
315 const QString modemNoCarrierResp();
316 void setModemNoCarrierResp(const QString &);
317
318 const QString modemNoDialtoneResp();
319 void setModemNoDialtoneResp(const QString &);
320
321 const QString modemHangupStr();
322 void setModemHangupStr(const QString &);
323
324 const QString modemHangupResp();
325 void setModemHangupResp(const QString &);
326
327 QString modemDLPResp();
328 void setModemDLPResp(const QString &);
329
330 const QString modemAnswerStr();
331 void setModemAnswerStr(const QString &);
332
333 const QString modemRingResp();
334 void setModemRingResp(const QString &);
335
336 const QString modemAnswerResp();
337 void setModemAnswerResp(const QString &);
338
339 QString volumeOff();
340 void setVolumeOff(const QString &);
341
342 QString volumeMedium();
343 void setVolumeMedium(const QString &);
344
345 QString volumeHigh();
346 void setVolumeHigh(const QString &);
347
348#if 0
349 void setUseCDLine(const int n);
350 int UseCDLine();
351#endif
352
353 // functions to set/get account information
354 int accountCount() const;
355 bool setAccount(const QString &);
356 bool setAccountByIndex(int);
357
358 bool isUniqueAccname(const QString &);
359
360 bool deleteAccount();
361 bool deleteAccount(const QString &);
362 int newaccount();
363 int copyaccount(int i);
364
365 const QString accname();
366 void setAccname(const QString &);
367
368 QStringList &phonenumbers();
369 const QString phonenumber();
370 void setPhonenumber(const QString &);
371
372 const QString dialPrefix();
373 void setDialPrefix(const QString &);
374
375 int authMethod();
376 void setAuthMethod(int);
377
378 const QString storedUsername();
379 void setStoredUsername(const QString &);
380
381 const QString storedPassword();
382 void setStoredPassword(const QString &);
383
384 bool storePassword();
385 void setStorePassword(bool);
386
387 int callbackType();
388 void setCallbackType(int);
389
390 QString callbackPhone();
391 void setCallbackPhone(const QString &);
392
393 bool waitCallback();
394 void setWaitCallback(bool);
395
396 const QString speed();
397 void setSpeed(const QString &);
398
399 const QString command_before_connect();
400 void setCommand_before_connect(const QString &);
401
402 const QString command_on_connect();
403 void setCommand_on_connect(const QString &);
404
405 const QString command_on_disconnect();
406 void setCommand_on_disconnect(const QString &);
407
408 const QString command_before_disconnect();
409 void setCommand_before_disconnect(const QString &);
410
411 const QString ipaddr();
412 void setIpaddr(const QString &);
413
414 const QString subnetmask();
415 void setSubnetmask(const QString &);
416
417 bool AcctEnabled();
418 void setAcctEnabled(bool set);
419
420 int VolAcctEnabled();
421 void setVolAcctEnabled(int set);
422
423 bool autoDNS();
424 void setAutoDNS(bool set);
425
426 bool exDNSDisabled();
427 void setExDNSDisabled(bool set);
428
429 bool autoname();
430 void setAutoname(bool set);
431
432 const QString gateway();
433 void setGateway(const QString &);
434
435 bool defaultroute();
436 void setDefaultroute(bool set);
437
438 QStringList &dns();
439 void setDns(QStringList &);
440
441 const QString domain();
442 void setDomain(const QString &);
443
444 QStringList &scriptType();
445 void setScriptType(QStringList &);
446
447 QStringList &script();
448 void setScript(QStringList &);
449
450 QStringList &pppdArgument();
451 void setpppdArgumentDefaults();
452 void setpppdArgument(QStringList &);
453
454 //functions to change/set the child pppd process info
455 bool pppdRunning() const;
456 void setpppdRunning(bool set);
457
458 int pppdError() const;
459 void setpppdError(int err);
460
461 // functions to set/query the accounting info
462 const QString accountingFile();
463 void setAccountingFile(const QString &);
464
465 const QString totalCosts();
466 void setTotalCosts(const QString &);
467
468 int totalBytes();
469 void setTotalBytes(int);
470
471 // graphing widget
472 void setGraphingOptions(bool enabled,
473 QColor bg,
474 QColor text,
475 QColor in,
476 QColor out);
477 void graphingOptions(bool &enabled,
478 QColor &bg,
479 QColor &text,
480 QColor &in,
481 QColor &out);
482 bool graphingEnabled();
483
484 // window positions
485 void winPosConWin(int &, int &);
486 void setWinPosConWin(int, int);
487 void winPosStatWin(int &, int &);
488 void setWinPosStatWin(int, int);
489
490private:
491 QString passwd;
492 KSharedConfig::Ptr config; // configuration object
493 int accounthighcount; // index of highest account
494 int caccount; // index of the current account
495 int modemhighcount; // index of highest modem
496 int cmodem; // index of the current modem
497 QString cmodemgroup; // name of current modem group
498 QString caccountgroup; // name of current account group
499 pid_t suidprocessid; // process ID of setuid child
500 bool pppdisrunning; // pppd process
501 // daemon
502 int pppderror; // error encounterd running pppd
503 int pppdVer, pppdMod, pppdPatch; // pppd version
504 bool waitcallback; // callback waiting flag
505
506 QStringList phonelist;
507};
508
509extern PPPData gpppdata;
510
511#endif
512