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"
46 #define MODEMSTR_SIZE 80
47 #define ACCNAME_SIZE 50
48 #define PHONENUMBER_SIZE 60
49 #define COMMAND_SIZE 255
50 #define IPADDR_SIZE 15
51 #define DOMAIN_SIZE 50
52 #define TIMEOUT_SIZE 60
55 // keys for config file
59 #define GENERAL_GRP "General"
60 #define MODEM_GRP "Modem"
61 #define ACCOUNT_GRP "Account"
62 #define GRAPH_GRP "Graph"
63 #define WINPOS_GRP "WindowPosition"
66 #define DEFAULTACCOUNT_KEY "DefaultAccount"
67 #define DEFAULTMODEM_KEY "DefaultModem"
68 #define PPPDVERSION_KEY "pppdVersion"
69 #define PPPDTIMEOUT_KEY "pppdTimeout"
70 #define SHOWCLOCK_KEY "ShowClock"
71 #define SHOWLOGWIN_KEY "ShowLogWindow"
72 #define AUTOREDIAL_KEY "AutomaticRedial"
73 #define DISCONNECT_KEY "DisconnectOnXServerExit"
74 #define QUITONDISCONNECT_KEY "QuitOnDisconnect"
75 #define NUMACCOUNTS_KEY "NumberOfAccounts"
76 #define NUMMODEMS_KEY "NumberOfModems"
77 #define REDIALONNOCARR_KEY "RedialOnNoCarrier"
81 #define MOD_NAME_KEY "Name"
82 #define MODEMDEV_KEY "Device"
83 #define LOCKFILE_KEY "UseLockFile"
84 #define FLOWCONTROL_KEY "FlowControl"
85 #define SPEED_KEY "Speed"
86 #define TIMEOUT_KEY "Timeout"
87 #define TONEDURATION_KEY "ToneDuration"
88 #define BUSYWAIT_KEY "BusyWait"
89 #define INITSTR_KEY "InitString"
90 #define INITRESP_KEY "InitResponse"
91 #define PREINITDELAY_KEY "PreInitDelay"
92 #define INITDELAY_KEY "InitDelay"
93 #define NODTDETECT_KEY "NoDialToneDetection"
94 #define DIALTONEWAIT_KEY "WaitForDialTone"
95 #define DIALSTR_KEY "DialString"
96 #define CONNECTRESP_KEY "ConnectResponse"
97 #define BUSYRESP_KEY "BusyResponse"
98 #define NOCARRIERRESP_KEY "NoCarrierResponse"
99 #define NODIALTONERESP_KEY "NoDialToneResp"
100 #define HANGUPSTR_KEY "HangupString"
101 #define HANGUPRESP_KEY "HangUpResponse"
102 #define DLPRESP_KEY "DLPResponse"
103 #define ANSWERSTR_KEY "AnswerString"
104 #define RINGRESP_KEY "RingResponse"
105 #define ANSWERRESP_KEY "AnswerResponse"
106 #define ENTER_KEY "Enter"
107 #define ESCAPESTR_KEY "EscapeString"
108 #define ESCAPERESP_KEY "EscapeResponse"
109 #define ESCAPEGUARDTIME_KEY "EscapeGuardTime"
110 #define USECDLINE_KEY "UseCDLine"
111 #define VOLUME_HIGH "VolumeHigh"
112 #define VOLUME_MEDIUM "VolumeMedium"
113 #define VOLUME_OFF "VolumeOff"
114 #define VOLUME_KEY "Volume"
117 #define ACC_NAME_KEY "Name"
118 #define PHONENUMBER_KEY "Phonenumber"
119 #define DIAL_PREFIX_KEY "DialPrefix"
120 #define AUTH_KEY "Authentication"
121 #define STORED_PASSWORD_KEY "Password"
122 #define STORED_USERNAME_KEY "Username"
123 #define STORE_PASSWORD_KEY "StorePassword"
124 #define CALLBACK_TYPE_KEY "CallbackType"
125 #define CALLBACK_PHONE_KEY "CallbackPhone"
126 #define BEFORE_CONNECT_KEY "BeforeConnect"
127 #define COMMAND_KEY "Command"
128 #define DISCONNECT_COMMAND_KEY "DisconnectCommand"
129 #define BEFORE_DISCONNECT_KEY "BeforeDisconnect"
130 #define IPADDR_KEY "IPAddr"
131 #define SUBNETMASK_KEY "SubnetMask"
132 #define ACCTENABLED_KEY "AccountingEnabled"
133 #define VOLACCTENABLED_KEY "VolumeAccountingEnabled"
134 #define ACCTFILE_KEY "AccountingFile"
135 #define AUTONAME_KEY "AutoName"
136 #define GATEWAY_KEY "Gateway"
137 #define DEFAULTROUTE_KEY "DefaultRoute"
138 #define DOMAIN_KEY "Domain"
139 #define DNS_KEY "DNS"
140 #define AUTODNS_KEY "AutoDNS"
141 #define EXDNSDISABLED_KEY "ExDNSDisabled"
142 #define SCRIPTCOM_KEY "ScriptCommands"
143 #define SCRIPTARG_KEY "ScriptArguments"
144 #define PPPDARG_KEY "pppdArguments"
145 #define PPP_DEBUG_OPTION "PPPDebug"
146 #define ICONIFY_ON_CONNECT_KEY "iconifyOnConnect"
147 #define DOCKING_KEY "DockIntoPanel"
148 #define TOTALCOSTS_KEY "TotalCosts"
149 #define TOTALBYTES_KEY "TotalBytes"
152 #define GENABLED "Enabled"
153 #define GCOLOR_BG "Background"
154 #define GCOLOR_TEXT "Text"
155 #define GCOLOR_IN "InBytes"
156 #define GCOLOR_OUT "OutBytes"
159 #define E_IF_TIMEOUT 1
160 #define E_PPPD_DIED 2
161 #define E_CBCP_WAIT 14
164 #define WINPOS_CONWIN_X "WindowPositionConWinX"
165 #define WINPOS_CONWIN_Y "WindowPositionConWinY"
166 #define WINPOS_STATWIN_X "WindowPositionStatWinX"
167 #define WINPOS_STATWIN_Y "WindowPositionStatWinY"
174 enum { NumInitStrings
= 2 };
180 int access() const; // read/write access
182 // function to read/write date to configuration file
183 QString
readConfig(const QString
&, const QString
&, const QString
&);
184 int readNumConfig(const QString
&, const QString
&, int);
185 bool readListConfig(const QString
&, const QString
&,
186 QStringList
&, char sep
= ',');
187 void writeConfig(const QString
&, const QString
&, const QString
&);
188 void writeConfig(const QString
&, const QString
&, int);
189 void writeListConfig(const QString
&, const QString
&,
190 QStringList
&, char sep
= ',');
192 // return the current account group
193 QString
currentAccountGroup() { return caccountgroup
; }
194 // return the current modem group
195 QString
currentModemGroup() { return cmodemgroup
; }
197 // functions to set/get general kppp info
198 QString
password() const;
199 void setPassword(const QString
&);
201 const QString
defaultAccount();
202 void setDefaultAccount(const QString
&);
204 const QString
defaultModem();
205 void setDefaultModem(const QString
&);
207 void set_xserver_exit_disconnect(bool set
);
208 bool get_xserver_exit_disconnect();
210 void set_redial_on_nocarrier(bool set
);
211 bool get_redial_on_nocarrier();
213 void setPPPDebug(bool set
);
216 void set_quit_on_disconnect(bool);
217 bool quit_on_disconnect();
219 void set_show_clock_on_caption(bool set
);
220 bool get_show_clock_on_caption();
222 void set_show_log_window(bool set
);
223 bool get_show_log_window();
225 void set_automatic_redial(bool set
);
226 bool automatic_redial();
228 void set_iconify_on_connect(bool set
);
229 bool get_iconify_on_connect();
231 void set_dock_into_panel(bool set
);
232 bool get_dock_into_panel();
234 const QString
enter();
235 void setEnter(const QString
&);
237 QString
pppdVersion();
238 bool pppdVersionMin(int ver
, int mod
, int patch
);
241 void setpppdTimeout(int);
243 // functions to set/get account information
244 int modemCount() const;
245 bool setModem(const QString
&);
246 bool setModemByIndex(int);
248 bool isUniqueModname(const QString
&);
251 bool deleteModem(const QString
&);
253 int copymodem(int i
);
255 const QString
modname();
256 void setModname(const QString
&);
260 void setbusyWait(int);
262 bool modemLockFile();
263 void setModemLockFile(bool set
);
265 int modemEscapeGuardTime();
266 void setModemEscapeGuardTime(int i
);
268 void setModemEscapeStr(const QString
&);
269 const QString
modemEscapeStr();
271 void setModemEscapeResp(const QString
&);
272 const QString
modemEscapeResp();
274 const QString
modemDevice();
275 void setModemDevice(const QString
&);
277 QString
flowcontrol();
278 void setFlowcontrol(const QString
&);
281 void setModemTimeout(int);
283 int modemToneDuration();
284 void setModemToneDuration(int);
286 QString
volumeInitString();
290 int waitForDialTone();
291 void setWaitForDialTone(int i
);
293 // modem command strings/responses
294 const QString
modemInitStr(int i
);
295 void setModemInitStr(int i
, const QString
&);
297 const QString
modemInitResp();
298 void setModemInitResp(const QString
&);
300 int modemPreInitDelay();
301 void setModemPreInitDelay(int);
303 int modemInitDelay();
304 void setModemInitDelay(int);
306 QString
modemNoDialToneDetectionStr();
307 void setModemNoDialToneDetectionStr(const QString
&);
309 const QString
modemDialStr();
310 void setModemDialStr(const QString
&);
312 const QString
modemConnectResp();
313 void setModemConnectResp(const QString
&);
315 const QString
modemBusyResp();
316 void setModemBusyResp(const QString
&);
318 const QString
modemNoCarrierResp();
319 void setModemNoCarrierResp(const QString
&);
321 const QString
modemNoDialtoneResp();
322 void setModemNoDialtoneResp(const QString
&);
324 const QString
modemHangupStr();
325 void setModemHangupStr(const QString
&);
327 const QString
modemHangupResp();
328 void setModemHangupResp(const QString
&);
330 QString
modemDLPResp();
331 void setModemDLPResp(const QString
&);
333 const QString
modemAnswerStr();
334 void setModemAnswerStr(const QString
&);
336 const QString
modemRingResp();
337 void setModemRingResp(const QString
&);
339 const QString
modemAnswerResp();
340 void setModemAnswerResp(const QString
&);
343 void setVolumeOff(const QString
&);
345 QString
volumeMedium();
346 void setVolumeMedium(const QString
&);
348 QString
volumeHigh();
349 void setVolumeHigh(const QString
&);
352 void setUseCDLine(const int n
);
356 // functions to set/get account information
357 int accountCount() const;
358 bool setAccount(const QString
&);
359 bool setAccountByIndex(int);
361 bool isUniqueAccname(const QString
&);
363 bool deleteAccount();
364 bool deleteAccount(const QString
&);
366 int copyaccount(int i
);
368 const QString
accname();
369 void setAccname(const QString
&);
371 QStringList
&phonenumbers();
372 const QString
phonenumber();
373 void setPhonenumber(const QString
&);
375 const QString
dialPrefix();
376 void setDialPrefix(const QString
&);
379 void setAuthMethod(int);
381 const QString
storedUsername();
382 void setStoredUsername(const QString
&);
384 const QString
storedPassword();
385 void setStoredPassword(const QString
&);
387 bool storePassword();
388 void setStorePassword(bool);
391 void setCallbackType(int);
393 QString
callbackPhone();
394 void setCallbackPhone(const QString
&);
397 void setWaitCallback(bool);
399 const QString
speed();
400 void setSpeed(const QString
&);
402 const QString
command_before_connect();
403 void setCommand_before_connect(const QString
&);
405 const QString
command_on_connect();
406 void setCommand_on_connect(const QString
&);
408 const QString
command_on_disconnect();
409 void setCommand_on_disconnect(const QString
&);
411 const QString
command_before_disconnect();
412 void setCommand_before_disconnect(const QString
&);
414 const QString
ipaddr();
415 void setIpaddr(const QString
&);
417 const QString
subnetmask();
418 void setSubnetmask(const QString
&);
421 void setAcctEnabled(bool set
);
423 int VolAcctEnabled();
424 void setVolAcctEnabled(int set
);
427 void setAutoDNS(bool set
);
429 bool exDNSDisabled();
430 void setExDNSDisabled(bool set
);
433 void setAutoname(bool set
);
435 const QString
gateway();
436 void setGateway(const QString
&);
439 void setDefaultroute(bool set
);
442 void setDns(QStringList
&);
444 const QString
domain();
445 void setDomain(const QString
&);
447 QStringList
&scriptType();
448 void setScriptType(QStringList
&);
450 QStringList
&script();
451 void setScript(QStringList
&);
453 QStringList
&pppdArgument();
454 void setpppdArgumentDefaults();
455 void setpppdArgument(QStringList
&);
457 //functions to change/set the child pppd process info
458 bool pppdRunning() const;
459 void setpppdRunning(bool set
);
461 int pppdError() const;
462 void setpppdError(int err
);
464 // functions to set/query the accounting info
465 const QString
accountingFile();
466 void setAccountingFile(const QString
&);
468 const QString
totalCosts();
469 void setTotalCosts(const QString
&);
472 void setTotalBytes(int);
475 void setGraphingOptions(bool enabled
,
480 void graphingOptions(bool &enabled
,
485 bool graphingEnabled();
488 void winPosConWin(int &, int &);
489 void setWinPosConWin(int, int);
490 void winPosStatWin(int &, int &);
491 void setWinPosStatWin(int, int);
495 KSharedConfig::Ptr config
; // configuration object
496 int accounthighcount
; // index of highest account
497 int caccount
; // index of the current account
498 int modemhighcount
; // index of highest modem
499 int cmodem
; // index of the current modem
500 QString cmodemgroup
; // name of current modem group
501 QString caccountgroup
; // name of current account group
502 pid_t suidprocessid
; // process ID of setuid child
503 bool pppdisrunning
; // pppd process
505 int pppderror
; // error encounterd running pppd
506 int pppdVer
, pppdMod
, pppdPatch
; // pppd version
507 bool waitcallback
; // callback waiting flag
509 QStringList phonelist
;
512 extern PPPData gpppdata
;