3 * kPPP: A pppd front end for the KDE project
7 * Copyright (C) 1997 Bernd Johannes Wuebben
8 * wuebben@math.cornell.edu
11 * Copyright (C) 1997 Jay Painter
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.
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.
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.
32 #include <sys/types.h>
35 #include <qstringlist.h>
37 #include <ksharedconfig.h>
39 #include "kpppconfig.h"
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
54 // keys for config file
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"
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"
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"
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"
151 #define GENABLED "Enabled"
152 #define GCOLOR_BG "Background"
153 #define GCOLOR_TEXT "Text"
154 #define GCOLOR_IN "InBytes"
155 #define GCOLOR_OUT "OutBytes"
158 #define E_IF_TIMEOUT 1
159 #define E_PPPD_DIED 2
160 #define E_CBCP_WAIT 14
163 #define WINPOS_CONWIN_X "WindowPositionConWinX"
164 #define WINPOS_CONWIN_Y "WindowPositionConWinY"
165 #define WINPOS_STATWIN_X "WindowPositionStatWinX"
166 #define WINPOS_STATWIN_Y "WindowPositionStatWinY"
173 enum { NumInitStrings
= 2 };
179 int access() const; // read/write access
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
&);
189 // return the current account group
190 QString
currentAccountGroup() { return caccountgroup
; }
191 // return the current modem group
192 QString
currentModemGroup() { return cmodemgroup
; }
194 // functions to set/get general kppp info
195 QString
password() const;
196 void setPassword(const QString
&);
198 const QString
defaultAccount();
199 void setDefaultAccount(const QString
&);
201 const QString
defaultModem();
202 void setDefaultModem(const QString
&);
204 void set_xserver_exit_disconnect(bool set
);
205 bool get_xserver_exit_disconnect();
207 void set_redial_on_nocarrier(bool set
);
208 bool get_redial_on_nocarrier();
210 void setPPPDebug(bool set
);
213 void set_quit_on_disconnect(bool);
214 bool quit_on_disconnect();
216 void set_show_clock_on_caption(bool set
);
217 bool get_show_clock_on_caption();
219 void set_show_log_window(bool set
);
220 bool get_show_log_window();
222 void set_automatic_redial(bool set
);
223 bool automatic_redial();
225 void set_iconify_on_connect(bool set
);
226 bool get_iconify_on_connect();
228 void set_dock_into_panel(bool set
);
229 bool get_dock_into_panel();
231 const QString
enter();
232 void setEnter(const QString
&);
234 QString
pppdVersion();
235 bool pppdVersionMin(int ver
, int mod
, int patch
);
238 void setpppdTimeout(int);
240 // functions to set/get account information
241 int modemCount() const;
242 bool setModem(const QString
&);
243 bool setModemByIndex(int);
245 bool isUniqueModname(const QString
&);
248 bool deleteModem(const QString
&);
250 int copymodem(int i
);
252 const QString
modname();
253 void setModname(const QString
&);
257 void setbusyWait(int);
259 bool modemLockFile();
260 void setModemLockFile(bool set
);
262 int modemEscapeGuardTime();
263 void setModemEscapeGuardTime(int i
);
265 void setModemEscapeStr(const QString
&);
266 const QString
modemEscapeStr();
268 void setModemEscapeResp(const QString
&);
269 const QString
modemEscapeResp();
271 const QString
modemDevice();
272 void setModemDevice(const QString
&);
274 QString
flowcontrol();
275 void setFlowcontrol(const QString
&);
278 void setModemTimeout(int);
280 int modemToneDuration();
281 void setModemToneDuration(int);
283 QString
volumeInitString();
287 int waitForDialTone();
288 void setWaitForDialTone(int i
);
290 // modem command strings/responses
291 const QString
modemInitStr(int i
);
292 void setModemInitStr(int i
, const QString
&);
294 const QString
modemInitResp();
295 void setModemInitResp(const QString
&);
297 int modemPreInitDelay();
298 void setModemPreInitDelay(int);
300 int modemInitDelay();
301 void setModemInitDelay(int);
303 QString
modemNoDialToneDetectionStr();
304 void setModemNoDialToneDetectionStr(const QString
&);
306 const QString
modemDialStr();
307 void setModemDialStr(const QString
&);
309 const QString
modemConnectResp();
310 void setModemConnectResp(const QString
&);
312 const QString
modemBusyResp();
313 void setModemBusyResp(const QString
&);
315 const QString
modemNoCarrierResp();
316 void setModemNoCarrierResp(const QString
&);
318 const QString
modemNoDialtoneResp();
319 void setModemNoDialtoneResp(const QString
&);
321 const QString
modemHangupStr();
322 void setModemHangupStr(const QString
&);
324 const QString
modemHangupResp();
325 void setModemHangupResp(const QString
&);
327 QString
modemDLPResp();
328 void setModemDLPResp(const QString
&);
330 const QString
modemAnswerStr();
331 void setModemAnswerStr(const QString
&);
333 const QString
modemRingResp();
334 void setModemRingResp(const QString
&);
336 const QString
modemAnswerResp();
337 void setModemAnswerResp(const QString
&);
340 void setVolumeOff(const QString
&);
342 QString
volumeMedium();
343 void setVolumeMedium(const QString
&);
345 QString
volumeHigh();
346 void setVolumeHigh(const QString
&);
349 void setUseCDLine(const int n
);
353 // functions to set/get account information
354 int accountCount() const;
355 bool setAccount(const QString
&);
356 bool setAccountByIndex(int);
358 bool isUniqueAccname(const QString
&);
360 bool deleteAccount();
361 bool deleteAccount(const QString
&);
363 int copyaccount(int i
);
365 const QString
accname();
366 void setAccname(const QString
&);
368 QStringList
&phonenumbers();
369 const QString
phonenumber();
370 void setPhonenumber(const QString
&);
372 const QString
dialPrefix();
373 void setDialPrefix(const QString
&);
376 void setAuthMethod(int);
378 const QString
storedUsername();
379 void setStoredUsername(const QString
&);
381 const QString
storedPassword();
382 void setStoredPassword(const QString
&);
384 bool storePassword();
385 void setStorePassword(bool);
388 void setCallbackType(int);
390 QString
callbackPhone();
391 void setCallbackPhone(const QString
&);
394 void setWaitCallback(bool);
396 const QString
speed();
397 void setSpeed(const QString
&);
399 const QString
command_before_connect();
400 void setCommand_before_connect(const QString
&);
402 const QString
command_on_connect();
403 void setCommand_on_connect(const QString
&);
405 const QString
command_on_disconnect();
406 void setCommand_on_disconnect(const QString
&);
408 const QString
command_before_disconnect();
409 void setCommand_before_disconnect(const QString
&);
411 const QString
ipaddr();
412 void setIpaddr(const QString
&);
414 const QString
subnetmask();
415 void setSubnetmask(const QString
&);
418 void setAcctEnabled(bool set
);
420 int VolAcctEnabled();
421 void setVolAcctEnabled(int set
);
424 void setAutoDNS(bool set
);
426 bool exDNSDisabled();
427 void setExDNSDisabled(bool set
);
430 void setAutoname(bool set
);
432 const QString
gateway();
433 void setGateway(const QString
&);
436 void setDefaultroute(bool set
);
439 void setDns(QStringList
&);
441 const QString
domain();
442 void setDomain(const QString
&);
444 QStringList
&scriptType();
445 void setScriptType(QStringList
&);
447 QStringList
&script();
448 void setScript(QStringList
&);
450 QStringList
&pppdArgument();
451 void setpppdArgumentDefaults();
452 void setpppdArgument(QStringList
&);
454 //functions to change/set the child pppd process info
455 bool pppdRunning() const;
456 void setpppdRunning(bool set
);
458 int pppdError() const;
459 void setpppdError(int err
);
461 // functions to set/query the accounting info
462 const QString
accountingFile();
463 void setAccountingFile(const QString
&);
465 const QString
totalCosts();
466 void setTotalCosts(const QString
&);
469 void setTotalBytes(int);
472 void setGraphingOptions(bool enabled
,
477 void graphingOptions(bool &enabled
,
482 bool graphingEnabled();
485 void winPosConWin(int &, int &);
486 void setWinPosConWin(int, int);
487 void winPosStatWin(int &, int &);
488 void setWinPosStatWin(int, int);
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
502 int pppderror
; // error encounterd running pppd
503 int pppdVer
, pppdMod
, pppdPatch
; // pppd version
504 bool waitcallback
; // callback waiting flag
506 QStringList phonelist
;
509 extern PPPData gpppdata
;