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
&,
185 QStringList
&, char sep
= ',');
186 void writeConfig(const QString
&, const QString
&, const QString
&);
187 void writeConfig(const QString
&, const QString
&, int);
188 void writeListConfig(const QString
&, const QString
&,
189 QStringList
&, char sep
= ',');
191 // return the current account group
192 QString
currentAccountGroup() { return caccountgroup
; }
193 // return the current modem group
194 QString
currentModemGroup() { return cmodemgroup
; }
196 // functions to set/get general kppp info
197 QString
password() const;
198 void setPassword(const QString
&);
200 const QString
defaultAccount();
201 void setDefaultAccount(const QString
&);
203 const QString
defaultModem();
204 void setDefaultModem(const QString
&);
206 void set_xserver_exit_disconnect(bool set
);
207 bool get_xserver_exit_disconnect();
209 void set_redial_on_nocarrier(bool set
);
210 bool get_redial_on_nocarrier();
212 void setPPPDebug(bool set
);
215 void set_quit_on_disconnect(bool);
216 bool quit_on_disconnect();
218 void set_show_clock_on_caption(bool set
);
219 bool get_show_clock_on_caption();
221 void set_show_log_window(bool set
);
222 bool get_show_log_window();
224 void set_automatic_redial(bool set
);
225 bool automatic_redial();
227 void set_iconify_on_connect(bool set
);
228 bool get_iconify_on_connect();
230 void set_dock_into_panel(bool set
);
231 bool get_dock_into_panel();
233 const QString
enter();
234 void setEnter(const QString
&);
236 QString
pppdVersion();
237 bool pppdVersionMin(int ver
, int mod
, int patch
);
240 void setpppdTimeout(int);
242 // functions to set/get account information
243 int modemCount() const;
244 bool setModem(const QString
&);
245 bool setModemByIndex(int);
247 bool isUniqueModname(const QString
&);
250 bool deleteModem(const QString
&);
252 int copymodem(int i
);
254 const QString
modname();
255 void setModname(const QString
&);
259 void setbusyWait(int);
261 bool modemLockFile();
262 void setModemLockFile(bool set
);
264 int modemEscapeGuardTime();
265 void setModemEscapeGuardTime(int i
);
267 void setModemEscapeStr(const QString
&);
268 const QString
modemEscapeStr();
270 void setModemEscapeResp(const QString
&);
271 const QString
modemEscapeResp();
273 const QString
modemDevice();
274 void setModemDevice(const QString
&);
276 QString
flowcontrol();
277 void setFlowcontrol(const QString
&);
280 void setModemTimeout(int);
282 int modemToneDuration();
283 void setModemToneDuration(int);
285 QString
volumeInitString();
289 int waitForDialTone();
290 void setWaitForDialTone(int i
);
292 // modem command strings/responses
293 const QString
modemInitStr(int i
);
294 void setModemInitStr(int i
, const QString
&);
296 const QString
modemInitResp();
297 void setModemInitResp(const QString
&);
299 int modemPreInitDelay();
300 void setModemPreInitDelay(int);
302 int modemInitDelay();
303 void setModemInitDelay(int);
305 QString
modemNoDialToneDetectionStr();
306 void setModemNoDialToneDetectionStr(const QString
&);
308 const QString
modemDialStr();
309 void setModemDialStr(const QString
&);
311 const QString
modemConnectResp();
312 void setModemConnectResp(const QString
&);
314 const QString
modemBusyResp();
315 void setModemBusyResp(const QString
&);
317 const QString
modemNoCarrierResp();
318 void setModemNoCarrierResp(const QString
&);
320 const QString
modemNoDialtoneResp();
321 void setModemNoDialtoneResp(const QString
&);
323 const QString
modemHangupStr();
324 void setModemHangupStr(const QString
&);
326 const QString
modemHangupResp();
327 void setModemHangupResp(const QString
&);
329 QString
modemDLPResp();
330 void setModemDLPResp(const QString
&);
332 const QString
modemAnswerStr();
333 void setModemAnswerStr(const QString
&);
335 const QString
modemRingResp();
336 void setModemRingResp(const QString
&);
338 const QString
modemAnswerResp();
339 void setModemAnswerResp(const QString
&);
342 void setVolumeOff(const QString
&);
344 QString
volumeMedium();
345 void setVolumeMedium(const QString
&);
347 QString
volumeHigh();
348 void setVolumeHigh(const QString
&);
351 void setUseCDLine(const int n
);
355 // functions to set/get account information
356 int accountCount() const;
357 bool setAccount(const QString
&);
358 bool setAccountByIndex(int);
360 bool isUniqueAccname(const QString
&);
362 bool deleteAccount();
363 bool deleteAccount(const QString
&);
365 int copyaccount(int i
);
367 const QString
accname();
368 void setAccname(const QString
&);
370 QStringList
&phonenumbers();
371 const QString
phonenumber();
372 void setPhonenumber(const QString
&);
374 const QString
dialPrefix();
375 void setDialPrefix(const QString
&);
378 void setAuthMethod(int);
380 const QString
storedUsername();
381 void setStoredUsername(const QString
&);
383 const QString
storedPassword();
384 void setStoredPassword(const QString
&);
386 bool storePassword();
387 void setStorePassword(bool);
390 void setCallbackType(int);
392 QString
callbackPhone();
393 void setCallbackPhone(const QString
&);
396 void setWaitCallback(bool);
398 const QString
speed();
399 void setSpeed(const QString
&);
401 const QString
command_before_connect();
402 void setCommand_before_connect(const QString
&);
404 const QString
command_on_connect();
405 void setCommand_on_connect(const QString
&);
407 const QString
command_on_disconnect();
408 void setCommand_on_disconnect(const QString
&);
410 const QString
command_before_disconnect();
411 void setCommand_before_disconnect(const QString
&);
413 const QString
ipaddr();
414 void setIpaddr(const QString
&);
416 const QString
subnetmask();
417 void setSubnetmask(const QString
&);
420 void setAcctEnabled(bool set
);
422 int VolAcctEnabled();
423 void setVolAcctEnabled(int set
);
426 void setAutoDNS(bool set
);
428 bool exDNSDisabled();
429 void setExDNSDisabled(bool set
);
432 void setAutoname(bool set
);
434 const QString
gateway();
435 void setGateway(const QString
&);
438 void setDefaultroute(bool set
);
441 void setDns(QStringList
&);
443 const QString
domain();
444 void setDomain(const QString
&);
446 QStringList
&scriptType();
447 void setScriptType(QStringList
&);
449 QStringList
&script();
450 void setScript(QStringList
&);
452 QStringList
&pppdArgument();
453 void setpppdArgumentDefaults();
454 void setpppdArgument(QStringList
&);
456 //functions to change/set the child pppd process info
457 bool pppdRunning() const;
458 void setpppdRunning(bool set
);
460 int pppdError() const;
461 void setpppdError(int err
);
463 // functions to set/query the accounting info
464 const QString
accountingFile();
465 void setAccountingFile(const QString
&);
467 const QString
totalCosts();
468 void setTotalCosts(const QString
&);
471 void setTotalBytes(int);
474 void setGraphingOptions(bool enabled
,
479 void graphingOptions(bool &enabled
,
484 bool graphingEnabled();
487 void winPosConWin(int &, int &);
488 void setWinPosConWin(int, int);
489 void winPosStatWin(int &, int &);
490 void setWinPosStatWin(int, int);
494 KSharedConfig::Ptr config
; // configuration object
495 int accounthighcount
; // index of highest account
496 int caccount
; // index of the current account
497 int modemhighcount
; // index of highest modem
498 int cmodem
; // index of the current modem
499 QString cmodemgroup
; // name of current modem group
500 QString caccountgroup
; // name of current account group
501 pid_t suidprocessid
; // process ID of setuid child
502 bool pppdisrunning
; // pppd process
504 int pppderror
; // error encounterd running pppd
505 int pppdVer
, pppdMod
, pppdPatch
; // pppd version
506 bool waitcallback
; // callback waiting flag
508 QStringList phonelist
;
511 extern PPPData gpppdata
;