1/*
2 * kPPP: A pppd front end for the KDE project
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
8 *
9 * based on EzPPP:
10 * Copyright (C) 1997 Jay Painter
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26
27#include "pppdata.h"
28#include "runtests.h"
29#include "devices.h"
30#include <klocale.h>
31#include <kconfig.h>
32#include <kconfiggroup.h>
33#include <kmessagebox.h>
34#include <kapplication.h>
35#include <kglobalsettings.h>
36#include <assert.h>
37#include <kglobal.h>
38
39PPPData gpppdata;
40
41
42PPPData::PPPData()
43 : config(0L),
44 accounthighcount(-1), // start out with no account entries
45 caccount(-1), // set the current account index also
46 modemhighcount(-1), // start out with no modem entries
47 cmodem(-1), // set the current modem index also
48 suidprocessid(-1), // process ID of setuid child
49 pppdisrunning(false),
50 pppderror(0),
51 waitcallback(false)
52{
53}
54
55
56//
57// open configuration file
58//
59bool PPPData::open() {
60
61 config = KGlobal::config();
62
63 if (config->accessMode() == KConfig::NoAccess) {
64 KMessageBox::error(0L,
65 i18n("The application-specific config file could not "
66 "be opened in either read-write or read-only mode.\n"
67 "The superuser might have to change its ownership "
68 "by issuing the following command in your home directory:\n"
69 "chown {YourUsername} .kde/share/config/kppprc"),
70 kapp->objectName());
71 return false;
72 }
73
74 // don't expand shell variables
75 accounthighcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
76
77 if (accounthighcount > MAX_ACCOUNTS)
78 accounthighcount = MAX_ACCOUNTS;
79
80 if(accounthighcount >= 0 && defaultAccount().isEmpty()) {
81 setAccountByIndex(0);
82 setDefaultAccount(accname());
83 } else if(!setAccount(defaultAccount()))
84 setDefaultAccount(accname());
85
86 modemhighcount = readNumConfig(GENERAL_GRP, NUMMODEMS_KEY, 0) - 1;
87
88 if (modemhighcount > MAX_MODEMS)
89 modemhighcount = MAX_MODEMS;
90
91 // if there aren't any ModemX set and exists the [Modem] group,
92 // probably it's the first time we are using this new version
93 // with multiple modem profiles.
94 // So we copy the old [Modem] to the new [Modem0]
95 if(modemhighcount < 0 && defaultModem().isEmpty() && config->hasGroup("Modem"))
96 {
97 KConfigGroup cg( config , "Modem");
98
99 QMap <QString, QString> map = config->entryMap("Modem");
100 QMap <QString, QString>::ConstIterator it = map.constBegin();
101
102 newmodem();
103
104 while (it != map.constEnd()) {
105 KConfigGroup cg2( config , cmodemgroup);
106 cg2.writeEntry(it.key(), *it);
107 it++;
108 }
109
110 QString newname("Modem0");
111 setModname(newname);
112 }
113
114 if(modemhighcount >= 0 && defaultModem().isEmpty()) {
115 setModemByIndex(0);
116 setDefaultModem(modname());
117 } else if(!setModem(defaultModem()))
118 setDefaultModem(modname());
119
120
121 // start out with internal debugging disabled
122 // the user is still free to specify `debug' on his own
123 setPPPDebug(false);
124
125 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
126
127 return true;
128}
129
130
131//
132// save configuration
133//
134void PPPData::save() {
135
136 if (config) {
137 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, accountCount());
138 writeConfig(GENERAL_GRP, NUMMODEMS_KEY, modemCount());
139 config->sync();
140 }
141
142}
143
144
145//
146// cancel changes
147//
148void PPPData::cancel() {
149
150 if (config) {
151 config->markAsClean();
152 config->reparseConfiguration();
153 }
154
155}
156
157
158// currently differentiates between READWRITE and NONE only
159int PPPData::access() const {
160
161 return config->accessMode();
162}
163
164
165// functions to read/write date to configuration file
166QString PPPData::readConfig(const QString &group, const QString &key,
167 const QString &defvalue = "")
168{
169 if (config) {
170 return config->group(group).readEntry(key, defvalue);
171 } else
172 return defvalue;
173}
174
175
176int PPPData::readNumConfig(const QString &group, const QString &key,
177 int defvalue) {
178 if (config) {
179 return config->group(group).readEntry(key, defvalue);
180 } else
181 return defvalue;
182
183}
184
185
186bool PPPData::readListConfig(const QString &group, const QString &key,
187 QStringList &list) {
188 list.clear();
189 if (config) {
190 list = config->group(group).readEntry(key, QStringList());
191 return true;
192 } else
193 return false;
194}
195
196
197void PPPData::writeConfig(const QString &group, const QString &key,
198 const QString &value) {
199 if (config) {
200 config->group(group).writeEntry(key, value);
201 }
202}
203
204
205void PPPData::writeConfig(const QString &group, const QString &key, int value) {
206 if (config) {
207 config->group(group).writeEntry(key, value);
208 }
209}
210
211
212void PPPData::writeListConfig(const QString &group, const QString &key,
213 QStringList &list) {
214 if (config) {
215 config->group(group).writeEntry(key, list);
216 }
217}
218
219
220//
221// functions to set/return general information
222//
223QString PPPData::password() const {
224 return passwd;
225}
226
227
228void PPPData::setPassword(const QString &pw) {
229 passwd = pw;
230}
231
232
233const QString PPPData::defaultAccount() {
234 return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY);
235}
236
237
238void PPPData::setDefaultAccount(const QString &n) {
239 writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n);
240
241 //now set the current account index to the default account
242 setAccount(defaultAccount());
243}
244
245
246const QString PPPData::defaultModem() {
247 return readConfig(GENERAL_GRP, DEFAULTMODEM_KEY);
248}
249
250
251void PPPData::setDefaultModem(const QString &n) {
252 writeConfig(GENERAL_GRP, DEFAULTMODEM_KEY, n);
253
254 //now set the current modem index to the default modem
255 setModem(defaultModem());
256}
257
258bool PPPData::get_show_clock_on_caption() {
259 return (bool) readNumConfig(GENERAL_GRP, SHOWCLOCK_KEY, true);
260}
261
262
263void PPPData::set_show_clock_on_caption(bool set) {
264 writeConfig(GENERAL_GRP, SHOWCLOCK_KEY, (int) set);
265}
266
267
268bool PPPData::get_xserver_exit_disconnect() {
269 return (bool) readNumConfig(GENERAL_GRP, DISCONNECT_KEY, true);
270}
271
272bool PPPData::get_redial_on_nocarrier() {
273 return (bool) readNumConfig(GENERAL_GRP, REDIALONNOCARR_KEY, false);
274}
275
276
277void PPPData::setPPPDebug(bool set) {
278 writeConfig(GENERAL_GRP, PPP_DEBUG_OPTION, (int)set);
279}
280
281
282bool PPPData::getPPPDebug() {
283 return (bool)readNumConfig(GENERAL_GRP, PPP_DEBUG_OPTION, false);
284}
285
286
287void PPPData::set_xserver_exit_disconnect(bool set) {
288 writeConfig(GENERAL_GRP, DISCONNECT_KEY, (int) set);
289}
290
291void PPPData::set_redial_on_nocarrier(bool set) {
292 writeConfig(GENERAL_GRP, REDIALONNOCARR_KEY, (int) set);
293}
294
295
296bool PPPData::quit_on_disconnect() {
297 return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false);
298}
299
300
301void PPPData::set_quit_on_disconnect(bool set) {
302 writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set);
303}
304
305
306bool PPPData::get_show_log_window() {
307 return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false);
308}
309
310
311void PPPData::set_show_log_window(bool set) {
312 writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set);
313}
314
315
316bool PPPData::automatic_redial() {
317 return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, false);
318}
319
320
321void PPPData::set_automatic_redial(bool set) {
322 writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set);
323}
324
325
326bool PPPData::get_iconify_on_connect() {
327 return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, true);
328}
329
330
331void PPPData::set_iconify_on_connect(bool set) {
332 writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set);
333}
334
335
336bool PPPData::get_dock_into_panel() {
337 return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false);
338}
339
340
341void PPPData::set_dock_into_panel(bool set) {
342 writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set);
343}
344
345
346QString PPPData::pppdVersion() {
347 return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch);
348}
349
350bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
351 // check if pppd version fulfills minimum requirement
352 return (pppdVer > ver
353 || (pppdVer == ver && pppdMod > mod)
354 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
355}
356
357int PPPData::pppdTimeout() {
358 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
359}
360
361
362void PPPData::setpppdTimeout(int n) {
363 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
364}
365
366//
367// functions to set/return modem information
368//
369
370
371//returns number of modems
372int PPPData::modemCount() const {
373 return modemhighcount + 1;
374}
375
376
377bool PPPData::setModem(const QString &mname) {
378 for(int i = 0; i <= modemhighcount; i++) {
379 setModemByIndex(i);
380 if(modname() == mname) {
381 cmodem = i;
382 return true;
383 }
384 }
385 return false;
386}
387
388
389bool PPPData::setModemByIndex(int i) {
390 if(i >= 0 && i <= modemhighcount) {
391 cmodem = i;
392 cmodemgroup.sprintf("%s%i", MODEM_GRP, i);
393 return true;
394 }
395 return false;
396}
397
398
399bool PPPData::isUniqueModname(const QString &n) {
400 int current = cmodem;
401 for(int i=0; i <= modemhighcount; i++) {
402 setModemByIndex(i);
403 if(modname() == n && i != current) {
404 setModemByIndex(current);
405 return false;
406 }
407 }
408 setModemByIndex(current);
409 return true;
410}
411
412bool PPPData::deleteModem() {
413 if(cmodem < 0)
414 return false;
415
416 QMap <QString, QString> map;
417 QMap <QString, QString>::Iterator it;
418
419 // set all entries of the current modem to ""
420 map = config->entryMap(cmodemgroup);
421 it = map.begin();
422 while (it != map.end()) {
423 config->group(cmodemgroup).writeEntry(it.key(), "");
424 it++;
425 }
426
427 // shift the succeeding modems
428 for(int i = cmodem+1; i <= modemhighcount; i++) {
429 setModemByIndex(i);
430 map = config->entryMap(cmodemgroup);
431 it = map.begin();
432 setModemByIndex(i-1);
433 KConfigGroup cg(config, cmodemgroup);
434 while (it != map.end()) {
435 cg.writeEntry(it.key(), *it);
436 it++;
437 }
438 }
439
440 // make sure the top modem is cleared
441 setModemByIndex(modemhighcount);
442 map = config->entryMap(cmodemgroup);
443 if( !map.isEmpty())
444 {
445 it = map.begin();
446 KConfigGroup cg2(config, cmodemgroup);
447 while (it !=map.end() && !it.key().isEmpty()) {
448 if(!it.key().isEmpty())
449 cg2.writeEntry(it.key(), "");
450 it++;
451 }
452 }
453 modemhighcount--;
454 if(cmodem > modemhighcount)
455 cmodem = modemhighcount;
456
457 setModemByIndex(cmodem);
458
459 return true;
460}
461
462bool PPPData::deleteModem(const QString &mname) {
463 if(!setModem(mname))
464 return false;
465
466 deleteModem();
467
468 return true;
469}
470
471
472int PPPData::newmodem() {
473
474 if(!config || modemhighcount >= MAX_MODEMS)
475 return -1;
476
477 modemhighcount++;
478 setModemByIndex(modemhighcount);
479
480 setpppdArgumentDefaults();
481
482 return cmodem;
483}
484
485int PPPData::copymodem(int i) {
486
487 KConfigGroup group = config->group(cmodemgroup);
488
489 if(modemhighcount >= MAX_MODEMS)
490 return -1;
491
492 setModemByIndex(i);
493
494 QMap <QString, QString> map = group.entryMap();
495 QMap <QString, QString>::ConstIterator it = map.constBegin();
496
497 QString newname = i18n("%1_copy", modname());
498
499 newmodem();
500
501 while (it != map.constEnd()) {
502 group = config->group(cmodemgroup);
503 group.writeEntry(it.key(), *it);
504 it++;
505 }
506
507 setModname(newname);
508
509 return cmodem;
510}
511
512
513const QString PPPData::modname() {
514 return readConfig(cmodemgroup, MOD_NAME_KEY);
515}
516
517void PPPData::setModname(const QString &n) {
518 if(!cmodemgroup.isNull()) {
519 // are we manipulating the default modem's name ? then change it, too.
520 bool def = modname() == defaultModem();
521 writeConfig(cmodemgroup, MOD_NAME_KEY, n);
522 if (def)
523 setDefaultModem(n);
524 }
525}
526
527
528
529
530const QString PPPData::modemDevice() {
531 return readConfig (cmodemgroup, MODEMDEV_KEY, devices[DEV_DEFAULT]);
532}
533
534
535void PPPData::setModemDevice(const QString &n) {
536 writeConfig(cmodemgroup, MODEMDEV_KEY, n);
537}
538
539
540QString PPPData::flowcontrol() {
541 // keep default value in sync with general.cpp
542 return readConfig(cmodemgroup, FLOWCONTROL_KEY, i18n("Hardware [CRTSCTS]"));
543}
544
545
546void PPPData::setFlowcontrol(const QString &n) {
547 writeConfig(cmodemgroup, FLOWCONTROL_KEY, n);
548}
549
550
551const QString PPPData::speed() {
552 QString s = readConfig(cmodemgroup, SPEED_KEY, "57600");
553 // undo the damage of a bug in former versions. It left an empty Speed=
554 // entry in kppprc. kppp did set the serial port to 57600 as default but
555 // pppd wouldn't receive the speed via the command line.
556 if(s.toUInt() == 0)
557 s = "57600";
558 return s;
559}
560
561
562void PPPData::setSpeed(const QString &n) {
563 writeConfig(cmodemgroup, SPEED_KEY, n);
564}
565
566
567#if 0
568void PPPData::setUseCDLine(const int n) {
569 writeConfig(cmodemgroup,USECDLINE_KEY,n);
570}
571
572
573int PPPData::UseCDLine() {
574 return readNumConfig(cmodemgroup,USECDLINE_KEY,0);
575}
576#endif
577
578const QString PPPData::modemEscapeStr() {
579 return readConfig(cmodemgroup,ESCAPESTR_KEY,"+++");
580}
581
582
583void PPPData::setModemEscapeStr(const QString &n) {
584 writeConfig(cmodemgroup,ESCAPESTR_KEY,n);
585}
586
587
588const QString PPPData::modemEscapeResp() {
589 return readConfig(cmodemgroup,ESCAPERESP_KEY,"OK");
590}
591
592
593void PPPData::setModemEscapeResp(const QString &n) {
594 writeConfig(cmodemgroup,ESCAPERESP_KEY,n);
595}
596
597
598int PPPData::modemEscapeGuardTime() {
599 return readNumConfig(cmodemgroup,ESCAPEGUARDTIME_KEY,50);
600}
601
602
603void PPPData::setModemEscapeGuardTime(int n) {
604 writeConfig(cmodemgroup,ESCAPEGUARDTIME_KEY,n);
605}
606
607
608bool PPPData::modemLockFile() {
609 return readNumConfig(cmodemgroup, LOCKFILE_KEY, 1);
610}
611
612
613void PPPData::setModemLockFile(bool set) {
614 writeConfig(cmodemgroup, LOCKFILE_KEY, set);
615}
616
617
618int PPPData::modemTimeout() {
619 return readNumConfig(cmodemgroup, TIMEOUT_KEY, MODEM_TIMEOUT);
620}
621
622
623void PPPData::setModemTimeout(int n) {
624 writeConfig(cmodemgroup, TIMEOUT_KEY, n);
625}
626
627
628int PPPData::modemToneDuration() {
629 return readNumConfig(cmodemgroup, TONEDURATION_KEY,MODEM_TONEDURATION);
630}
631
632
633void PPPData::setModemToneDuration(int n) {
634 writeConfig(cmodemgroup, TONEDURATION_KEY, n);
635}
636
637
638int PPPData::busyWait() {
639 return readNumConfig(cmodemgroup, BUSYWAIT_KEY, BUSY_WAIT);
640}
641
642
643void PPPData::setbusyWait(int n) {
644 writeConfig(cmodemgroup, BUSYWAIT_KEY, n);
645}
646
647
648//
649//Advanced "Modem" dialog
650//
651// defaults: InitString=ATZ, InitString1="" etc.
652const QString PPPData::modemInitStr(int i) {
653 assert(i >= 0 && i < NumInitStrings);
654 if(i == 0)
655 return readConfig(cmodemgroup, INITSTR_KEY, "ATZ");
656 else
657 return readConfig(cmodemgroup, INITSTR_KEY + QString::number(i), "");
658}
659
660
661void PPPData::setModemInitStr(int i, const QString &n) {
662 assert(i >= 0 && i < NumInitStrings);
663 QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : "");
664 writeConfig(cmodemgroup, k, n);
665}
666
667
668const QString PPPData::modemInitResp() {
669 return readConfig(cmodemgroup, INITRESP_KEY, "OK");
670}
671
672
673void PPPData::setModemInitResp(const QString &n) {
674 writeConfig(cmodemgroup, INITRESP_KEY, n);
675}
676
677
678int PPPData::modemPreInitDelay() {
679 return readNumConfig(cmodemgroup, PREINITDELAY_KEY, 50);
680}
681
682
683void PPPData::setModemPreInitDelay(int n) {
684 writeConfig(cmodemgroup, PREINITDELAY_KEY, n);
685}
686
687
688int PPPData::modemInitDelay() {
689 return readNumConfig(cmodemgroup, INITDELAY_KEY, 50);
690}
691
692
693void PPPData::setModemInitDelay(int n) {
694 writeConfig(cmodemgroup, INITDELAY_KEY, n);
695}
696
697QString PPPData::modemNoDialToneDetectionStr() {
698 return readConfig(cmodemgroup, NODTDETECT_KEY, "ATX3");
699}
700
701void PPPData::setModemNoDialToneDetectionStr(const QString &n) {
702 writeConfig(cmodemgroup, NODTDETECT_KEY, n);
703}
704
705const QString PPPData::modemDialStr() {
706 return readConfig(cmodemgroup, DIALSTR_KEY, "ATDT");
707}
708
709
710void PPPData::setModemDialStr(const QString &n) {
711 writeConfig(cmodemgroup, DIALSTR_KEY, n);
712}
713
714
715const QString PPPData::modemConnectResp() {
716 return readConfig(cmodemgroup, CONNECTRESP_KEY, "CONNECT");
717}
718
719
720void PPPData::setModemConnectResp(const QString &n) {
721 writeConfig(cmodemgroup, CONNECTRESP_KEY, n);
722}
723
724
725const QString PPPData::modemBusyResp() {
726 return readConfig(cmodemgroup, BUSYRESP_KEY, "BUSY");
727}
728
729
730void PPPData::setModemBusyResp(const QString &n) {
731 writeConfig(cmodemgroup, BUSYRESP_KEY, n);
732}
733
734
735const QString PPPData::modemNoCarrierResp() {
736 return readConfig(cmodemgroup, NOCARRIERRESP_KEY, "NO CARRIER");
737}
738
739
740void PPPData::setModemNoCarrierResp(const QString &n) {
741 writeConfig(cmodemgroup, NOCARRIERRESP_KEY, n);
742}
743
744
745const QString PPPData::modemNoDialtoneResp() {
746 return readConfig(cmodemgroup, NODIALTONERESP_KEY, "NO DIALTONE");
747}
748
749
750void PPPData::setModemNoDialtoneResp(const QString &n) {
751 writeConfig(cmodemgroup, NODIALTONERESP_KEY, n);
752}
753
754
755const QString PPPData::modemHangupStr() {
756 return readConfig(cmodemgroup, HANGUPSTR_KEY, "+++ATH");
757}
758
759void PPPData::setModemHangupStr(const QString &n) {
760 writeConfig(cmodemgroup, HANGUPSTR_KEY, n);
761}
762
763
764const QString PPPData::modemHangupResp() {
765 return readConfig(cmodemgroup, HANGUPRESP_KEY, "OK");
766}
767
768void PPPData::setModemHangupResp(const QString &n) {
769 writeConfig(cmodemgroup, HANGUPRESP_KEY, n);
770}
771
772
773QString PPPData::modemDLPResp() {
774 return readConfig(cmodemgroup, DLPRESP_KEY, "DIGITAL LINE DETECTED");
775}
776
777void PPPData::setModemDLPResp(const QString &n) {
778 writeConfig(cmodemgroup, DLPRESP_KEY, n);
779}
780
781
782
783
784const QString PPPData::modemAnswerStr() {
785 return readConfig(cmodemgroup, ANSWERSTR_KEY, "ATA");
786}
787
788
789QString PPPData::volumeOff() {
790 return readConfig(cmodemgroup, VOLUME_OFF, "M0L0");
791}
792
793
794void PPPData::setVolumeOff(const QString &s) {
795 writeConfig(cmodemgroup, VOLUME_OFF, s);
796}
797
798
799QString PPPData::volumeMedium() {
800 return readConfig(cmodemgroup, VOLUME_MEDIUM, "M1L1");
801}
802
803
804void PPPData::setVolumeMedium(const QString &s) {
805 writeConfig(cmodemgroup, VOLUME_MEDIUM, s);
806}
807
808
809QString PPPData::volumeHigh() {
810 QString tmp = readConfig(cmodemgroup, VOLUME_HIGH, "M1L3");
811 if(tmp == "M1L4")
812 tmp = "M1L3";
813 return tmp;
814}
815
816
817void PPPData::setVolumeHigh(const QString &s) {
818 writeConfig(cmodemgroup, VOLUME_HIGH, s);
819}
820
821
822QString PPPData::volumeInitString() {
823 QString s;
824
825 switch(volume()) {
826 case 0:
827 s = volumeOff();
828 break;
829 case 1:
830 s = volumeMedium();
831 break;
832 case 2:
833 s = volumeHigh();
834 break;
835 default:
836 s = volumeMedium();
837 }
838
839 return s;
840}
841
842
843int PPPData::volume() {
844 return readNumConfig(cmodemgroup, VOLUME_KEY, 1);
845}
846
847
848void PPPData::setVolume(int i) {
849 writeConfig(cmodemgroup, VOLUME_KEY, i);
850}
851
852int PPPData::waitForDialTone() {
853 return readNumConfig(cmodemgroup, DIALTONEWAIT_KEY, 1);
854}
855
856void PPPData::setWaitForDialTone(int i) {
857 writeConfig(cmodemgroup, DIALTONEWAIT_KEY, i);
858}
859
860void PPPData::setModemAnswerStr(const QString &n) {
861 writeConfig(cmodemgroup, ANSWERSTR_KEY, n);
862}
863
864
865const QString PPPData::modemRingResp() {
866 return readConfig(cmodemgroup, RINGRESP_KEY, "RING");
867}
868
869
870void PPPData::setModemRingResp(const QString &n) {
871 writeConfig(cmodemgroup, RINGRESP_KEY, n);
872}
873
874
875const QString PPPData::modemAnswerResp() {
876 return readConfig(cmodemgroup, ANSWERRESP_KEY, "CONNECT");
877}
878
879
880void PPPData::setModemAnswerResp(const QString &n) {
881 writeConfig(cmodemgroup, ANSWERRESP_KEY, n);
882}
883
884
885const QString PPPData::enter() {
886 return readConfig(cmodemgroup, ENTER_KEY, "CR");
887}
888
889
890void PPPData::setEnter(const QString &n) {
891 writeConfig(cmodemgroup, ENTER_KEY, n);
892}
893
894
895//
896// functions to set/return account information
897//
898
899//returns number of accounts
900int PPPData::accountCount() const {
901 return accounthighcount + 1;
902}
903
904
905bool PPPData::setAccount(const QString &aname) {
906 for(int i = 0; i <= accounthighcount; i++) {
907 setAccountByIndex(i);
908 if(accname() == aname) {
909 caccount = i;
910 return true;
911 }
912 }
913 return false;
914}
915
916
917bool PPPData::setAccountByIndex(int i) {
918 if(i >= 0 && i <= accounthighcount) {
919 caccount = i;
920 caccountgroup.sprintf("%s%i", ACCOUNT_GRP, i);
921 return true;
922 }
923 return false;
924}
925
926
927bool PPPData::isUniqueAccname(const QString &n) {
928 if(n.contains(':'))
929 return false;
930 int current = caccount;
931 for(int i=0; i <= accounthighcount; i++) {
932 setAccountByIndex(i);
933 if(accname() == n && i != current) {
934 setAccountByIndex(current);
935 return false;
936 }
937 }
938 setAccountByIndex(current);
939 return true;
940}
941
942
943bool PPPData::deleteAccount() {
944 if(caccount < 0)
945 return false;
946
947 QMap <QString, QString> map;
948 QMap <QString, QString>::Iterator it;
949
950 // set all entries of the current account to ""
951 map = config->entryMap(caccountgroup);
952 it = map.begin();
953 KConfigGroup cg(config,caccountgroup);
954 while (it != map.end()) {
955 cg.writeEntry(it.key(), "");
956 ++it;
957 }
958
959 // shift the succeeding accounts
960 for(int i = caccount+1; i <= accounthighcount; i++) {
961 setAccountByIndex(i);
962 map = config->entryMap(caccountgroup);
963 it = map.begin();
964 setAccountByIndex(i-1);
965 KConfigGroup cg2(config,caccountgroup);
966 while (it != map.end()) {
967 cg2.writeEntry(it.key(), *it);
968 ++it;
969 }
970 }
971
972 // make sure the top account is cleared
973 setAccountByIndex(accounthighcount);
974 map = config->entryMap(caccountgroup);
975 it = map.begin();
976 KConfigGroup cg3(config,caccountgroup);
977 while (it != map.end() && !it.key().isNull()) {
978 cg3.writeEntry(it.key(), "");
979 ++it;
980 }
981
982 accounthighcount--;
983 if(caccount > accounthighcount)
984 caccount = accounthighcount;
985
986 setAccountByIndex(caccount);
987
988 return true;
989}
990
991bool PPPData::deleteAccount(const QString &aname) {
992 if(!setAccount(aname))
993 return false;
994
995 deleteAccount();
996
997 return true;
998}
999
1000
1001int PPPData::newaccount() {
1002
1003 if(!config || accounthighcount >= MAX_ACCOUNTS)
1004 return -1;
1005
1006 accounthighcount++;
1007 setAccountByIndex(accounthighcount);
1008
1009 setpppdArgumentDefaults();
1010
1011 return caccount;
1012}
1013
1014int PPPData::copyaccount(int i) {
1015
1016 if(accounthighcount >= MAX_ACCOUNTS)
1017 return -1;
1018
1019 setAccountByIndex(i);
1020
1021 QMap <QString, QString> map = config->entryMap(caccountgroup);
1022 QMap <QString, QString>::ConstIterator it = map.constBegin();
1023
1024 QString newname = i18n("%1_copy", accname());
1025
1026 newaccount();
1027
1028 while (it != map.constEnd()) {
1029 KConfigGroup cg2 ( config, caccountgroup);
1030 cg2.writeEntry(it.key(), *it);
1031 it++;
1032 }
1033
1034 setAccname(newname);
1035
1036 return caccount;
1037}
1038
1039
1040const QString PPPData::accname() {
1041 return readConfig(caccountgroup, ACC_NAME_KEY);
1042}
1043
1044void PPPData::setAccname(const QString &n) {
1045 if(!caccountgroup.isNull()) {
1046 // are we manipulating the default account's name ? then change it, too.
1047 bool def = accname() == defaultAccount();
1048 writeConfig(caccountgroup, ACC_NAME_KEY, n);
1049 if (def)
1050 setDefaultAccount(n);
1051 }
1052}
1053
1054
1055#define SEPARATOR_CHAR ':'
1056QStringList &PPPData::phonenumbers() {
1057 phonelist = readConfig(caccountgroup, PHONENUMBER_KEY).split(SEPARATOR_CHAR);
1058 return phonelist;
1059}
1060
1061
1062const QString PPPData::phonenumber() {
1063 return readConfig(caccountgroup, PHONENUMBER_KEY);
1064}
1065
1066
1067void PPPData::setPhonenumber(const QString &n) {
1068 writeConfig(caccountgroup, PHONENUMBER_KEY, n);
1069}
1070
1071
1072const QString PPPData::dialPrefix() {
1073 return readConfig(caccountgroup, DIAL_PREFIX_KEY, "");
1074}
1075
1076
1077void PPPData::setDialPrefix(const QString &s) {
1078 writeConfig(caccountgroup, DIAL_PREFIX_KEY, s);
1079}
1080
1081
1082int PPPData::authMethod() {
1083 return readNumConfig(caccountgroup, AUTH_KEY, 0);
1084}
1085
1086
1087void PPPData::setAuthMethod(int value) {
1088 writeConfig(caccountgroup, AUTH_KEY, value);
1089}
1090
1091
1092const QString PPPData::storedUsername() {
1093 return readConfig(caccountgroup, STORED_USERNAME_KEY, "");
1094}
1095
1096
1097void PPPData::setStoredUsername(const QString &b) {
1098 writeConfig(caccountgroup, STORED_USERNAME_KEY, b);
1099}
1100
1101
1102const QString PPPData::storedPassword() {
1103 return readConfig(caccountgroup, STORED_PASSWORD_KEY, "");
1104}
1105
1106
1107void PPPData::setStoredPassword(const QString &b) {
1108 writeConfig(caccountgroup, STORED_PASSWORD_KEY, b);
1109}
1110
1111
1112bool PPPData::storePassword() {
1113 return (bool)readNumConfig(caccountgroup, STORE_PASSWORD_KEY, 1);
1114}
1115
1116int PPPData::callbackType() {
1117 return readNumConfig(caccountgroup, CALLBACK_TYPE_KEY, 0);
1118}
1119
1120void PPPData::setCallbackType(int value) {
1121 writeConfig(caccountgroup, CALLBACK_TYPE_KEY, value);
1122}
1123
1124QString PPPData::callbackPhone() {
1125 return readConfig(caccountgroup, CALLBACK_PHONE_KEY, "");
1126}
1127
1128void PPPData::setCallbackPhone(const QString &b) {
1129 writeConfig(caccountgroup, CALLBACK_PHONE_KEY, b);
1130}
1131
1132bool PPPData::waitCallback() {
1133 return waitcallback;
1134}
1135
1136void PPPData::setWaitCallback(bool value) {
1137 waitcallback = value;
1138}
1139
1140const QString PPPData::command_before_connect() {
1141 return readConfig(caccountgroup, BEFORE_CONNECT_KEY);
1142}
1143
1144
1145void PPPData::setCommand_before_connect(const QString &n) {
1146 writeConfig(caccountgroup, BEFORE_CONNECT_KEY, n);
1147}
1148
1149
1150void PPPData::setStorePassword(bool b) {
1151 writeConfig(caccountgroup, STORE_PASSWORD_KEY, (int)b);
1152}
1153
1154
1155const QString PPPData::command_on_connect() {
1156 return readConfig(caccountgroup, COMMAND_KEY);
1157}
1158
1159
1160void PPPData::setCommand_on_connect(const QString &n) {
1161 writeConfig(caccountgroup, COMMAND_KEY, n);
1162}
1163
1164
1165const QString PPPData::command_on_disconnect() {
1166 return readConfig(caccountgroup, DISCONNECT_COMMAND_KEY);
1167}
1168
1169
1170void PPPData::setCommand_on_disconnect(const QString &n) {
1171 writeConfig(caccountgroup, DISCONNECT_COMMAND_KEY, n);
1172}
1173
1174
1175const QString PPPData::command_before_disconnect() {
1176 return readConfig(caccountgroup, BEFORE_DISCONNECT_KEY);
1177}
1178
1179
1180void PPPData::setCommand_before_disconnect(const QString &n) {
1181 writeConfig(caccountgroup, BEFORE_DISCONNECT_KEY, n);
1182}
1183
1184
1185const QString PPPData::ipaddr() {
1186 return readConfig(caccountgroup, IPADDR_KEY);
1187}
1188
1189
1190void PPPData::setIpaddr(const QString &n) {
1191 writeConfig(caccountgroup, IPADDR_KEY, n);
1192}
1193
1194
1195const QString PPPData::subnetmask() {
1196 return readConfig(caccountgroup, SUBNETMASK_KEY);
1197}
1198
1199
1200void PPPData::setSubnetmask(const QString &n) {
1201 writeConfig(caccountgroup, SUBNETMASK_KEY, n);
1202}
1203
1204
1205bool PPPData::autoname() {
1206 return (bool) readNumConfig(caccountgroup, AUTONAME_KEY, false);
1207}
1208
1209
1210void PPPData::setAutoname(bool set) {
1211 writeConfig(caccountgroup, AUTONAME_KEY, (int) set);
1212}
1213
1214
1215bool PPPData::AcctEnabled() {
1216 return (bool) readNumConfig(caccountgroup, ACCTENABLED_KEY, false);
1217}
1218
1219
1220void PPPData::setAcctEnabled(bool set) {
1221 writeConfig(caccountgroup, ACCTENABLED_KEY, (int) set);
1222}
1223
1224
1225int PPPData::VolAcctEnabled() {
1226 return readNumConfig(caccountgroup, VOLACCTENABLED_KEY, 0);
1227}
1228
1229
1230void PPPData::setVolAcctEnabled(int set) {
1231 writeConfig(caccountgroup, VOLACCTENABLED_KEY, set);
1232}
1233
1234
1235const QString PPPData::gateway() {
1236 return readConfig(caccountgroup, GATEWAY_KEY);
1237}
1238
1239
1240void PPPData::setGateway(const QString &n ) {
1241 writeConfig(caccountgroup, GATEWAY_KEY, n);
1242}
1243
1244
1245bool PPPData::defaultroute() {
1246 // default route is by default 'on'.
1247 return (bool) readNumConfig(caccountgroup, DEFAULTROUTE_KEY, true);
1248}
1249
1250
1251void PPPData::setDefaultroute(bool set) {
1252 writeConfig(caccountgroup, DEFAULTROUTE_KEY, (int) set);
1253}
1254
1255
1256bool PPPData::autoDNS() {
1257 bool set = (bool) readNumConfig(caccountgroup, AUTODNS_KEY, true);
1258 return (set && gpppdata.pppdVersionMin(2, 3, 7));
1259}
1260
1261
1262void PPPData::setAutoDNS(bool set) {
1263 writeConfig(caccountgroup, AUTODNS_KEY, (int) set);
1264}
1265
1266
1267void PPPData::setExDNSDisabled(bool set) {
1268 writeConfig(caccountgroup, EXDNSDISABLED_KEY, (int) set);
1269}
1270
1271
1272bool PPPData::exDNSDisabled() {
1273 return (bool) readNumConfig(caccountgroup, EXDNSDISABLED_KEY,0);
1274}
1275
1276
1277QStringList &PPPData::dns() {
1278 static QStringList dnslist;
1279
1280 readListConfig(caccountgroup, DNS_KEY, dnslist);
1281 while(dnslist.count() > MAX_DNS_ENTRIES)
1282 dnslist.removeAll(dnslist.last());
1283
1284 return dnslist;
1285}
1286
1287
1288void PPPData::setDns(QStringList &list) {
1289 writeListConfig(caccountgroup, DNS_KEY, list);
1290}
1291
1292
1293const QString PPPData::domain() {
1294 return readConfig(caccountgroup, DOMAIN_KEY);
1295}
1296
1297
1298void PPPData::setDomain(const QString &n ) {
1299 writeConfig(caccountgroup, DOMAIN_KEY, n);
1300}
1301
1302
1303QStringList &PPPData::scriptType() {
1304 static QStringList typelist;
1305
1306 readListConfig(caccountgroup, SCRIPTCOM_KEY, typelist);
1307 while(typelist.count() > MAX_SCRIPT_ENTRIES)
1308 typelist.removeAll(typelist.last());
1309
1310 return typelist;
1311}
1312
1313
1314void PPPData::setScriptType(QStringList &list) {
1315 writeListConfig(caccountgroup, SCRIPTCOM_KEY, list);
1316}
1317
1318
1319QStringList &PPPData::script() {
1320 static QStringList scriptlist;
1321
1322 readListConfig(caccountgroup, SCRIPTARG_KEY, scriptlist);
1323 while(scriptlist.count() > MAX_SCRIPT_ENTRIES)
1324 scriptlist.removeAll(scriptlist.last());
1325
1326 return scriptlist;
1327}
1328
1329
1330void PPPData::setScript(QStringList &list) {
1331 writeListConfig(caccountgroup, SCRIPTARG_KEY, list);
1332}
1333
1334
1335const QString PPPData::accountingFile() {
1336 return readConfig(caccountgroup, ACCTFILE_KEY);
1337}
1338
1339
1340void PPPData::setAccountingFile(const QString &n) {
1341 writeConfig(caccountgroup, ACCTFILE_KEY, n);
1342}
1343
1344
1345const QString PPPData::totalCosts() {
1346 return readConfig(caccountgroup, TOTALCOSTS_KEY);
1347}
1348
1349
1350void PPPData::setTotalCosts(const QString &n) {
1351 writeConfig(caccountgroup, TOTALCOSTS_KEY, n);
1352}
1353
1354
1355int PPPData::totalBytes() {
1356 return readNumConfig(caccountgroup, TOTALBYTES_KEY, 0);
1357}
1358
1359void PPPData::setTotalBytes(int n) {
1360 writeConfig(caccountgroup, TOTALBYTES_KEY, n);
1361}
1362
1363
1364QStringList &PPPData::pppdArgument() {
1365 static QStringList arglist;
1366
1367 while(arglist.count() > MAX_PPPD_ARGUMENTS)
1368 arglist.removeAll(arglist.last());
1369 readListConfig(caccountgroup, PPPDARG_KEY, arglist);
1370
1371 return arglist;
1372}
1373
1374
1375void PPPData::setpppdArgument(QStringList &args) {
1376 writeListConfig(caccountgroup, PPPDARG_KEY, args);
1377}
1378
1379
1380void PPPData::setpppdArgumentDefaults() {
1381 QStringList arg;
1382 setpppdArgument(arg);
1383}
1384
1385
1386// graphing widget
1387void PPPData::setGraphingOptions(bool enable,
1388 QColor bg,
1389 QColor text,
1390 QColor in,
1391 QColor out)
1392{
1393 if(config) {
1394 KConfigGroup group = config->group(GRAPH_GRP);
1395 group.writeEntry(GENABLED, enable);
1396 group.writeEntry(GCOLOR_BG, bg);
1397 group.writeEntry(GCOLOR_TEXT, text);
1398 group.writeEntry(GCOLOR_IN, in);
1399 group.writeEntry(GCOLOR_OUT, out);
1400 }
1401}
1402
1403void PPPData::graphingOptions(bool &enable,
1404 QColor &bg,
1405 QColor &text,
1406 QColor &in,
1407 QColor &out)
1408{
1409 QColor c;
1410
1411 if(config) {
1412 KConfigGroup group = config->group(GRAPH_GRP);
1413 enable = group.readEntry(GENABLED,true);
1414 c = Qt::white;
1415 bg = group.readEntry(GCOLOR_BG, c);
1416 c = Qt::black;
1417 text = group.readEntry(GCOLOR_TEXT, c);
1418 c = Qt::blue;
1419 in = group.readEntry(GCOLOR_IN, c);
1420 c = Qt::red;
1421 out = group.readEntry(GCOLOR_OUT, c);
1422 }
1423}
1424
1425
1426bool PPPData::graphingEnabled() {
1427 if(config) {
1428 return config->group(GRAPH_GRP).readEntry(GENABLED, true);
1429 }
1430 else return true;
1431}
1432
1433
1434
1435//
1436//functions to change/set the child pppd process info
1437//
1438bool PPPData::pppdRunning() const {
1439 return pppdisrunning;
1440}
1441
1442void PPPData::setpppdRunning(bool set) {
1443 pppdisrunning = set;
1444}
1445
1446int PPPData::pppdError() const {
1447 return pppderror;
1448}
1449
1450void PPPData::setpppdError(int err) {
1451 pppderror = err;
1452}
1453
1454
1455//
1456// window position
1457//
1458void PPPData::winPosConWin(int& p_x, int& p_y) {
1459 QRect desk = KGlobalSettings::splashScreenDesktopGeometry();
1460 p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, desk.center().x()-160);
1461 p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, desk.center().y()-55);
1462}
1463
1464void PPPData::setWinPosConWin(int p_x, int p_y) {
1465 writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x);
1466 writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y);
1467}
1468
1469void PPPData::winPosStatWin(int& p_x, int& p_y) {
1470 QRect desk = KGlobalSettings::splashScreenDesktopGeometry();
1471 p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, desk.center().x()-160);
1472 p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, desk.center().y()-55);
1473}
1474
1475void PPPData::setWinPosStatWin(int p_x, int p_y) {
1476 writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x);
1477 writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y);
1478}
1479